gloox  1.0.28
tlsgnutlsbase.h
1 /*
2  Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef TLSGNUTLSBASE_H__
16 #define TLSGNUTLSBASE_H__
17 
18 #include "tlsbase.h"
19 
20 #include "config.h"
21 
22 #ifdef HAVE_GNUTLS
23 
24 #include <gnutls/gnutls.h>
25 #include <gnutls/x509.h>
26 
27 namespace gloox
28 {
29 
38  class GnuTLSBase : public TLSBase
39  {
40  public:
46  GnuTLSBase( TLSHandler* th, const std::string& server = EmptyString );
47 
51  virtual ~GnuTLSBase();
52 
53  // reimplemented from TLSBase
54  virtual bool encrypt( const std::string& data );
55 
56  // reimplemented from TLSBase
57  virtual int decrypt( const std::string& data );
58 
59  // reimplemented from TLSBase
60  virtual void cleanup();
61 
62  // reimplemented from TLSBase
63  virtual bool handshake();
64 
65  // reimplemented from TLSBase
66  virtual bool hasChannelBinding() const;
67 
68  // reimplemented from TLSBase
69  virtual const std::string channelBinding() const;
70 
71  // reimplemented from TLSBase
72  virtual void setCACerts( const StringList& /*cacerts*/ ) {}
73 
74  // reimplemented from TLSBase
75  virtual void setClientCert( const std::string& /*clientKey*/, const std::string& /*clientCerts*/ ) {}
76 
77  protected:
78  virtual void getCertInfo() {}
79 
80  void getCommonCertInfo();
81 
82  gnutls_session_t* m_session;
83 
84  std::string m_recvBuffer;
85  char* m_buf;
86  const int m_bufsize;
87 
88  ssize_t pullFunc( void* data, size_t len );
89  static ssize_t pullFunc( gnutls_transport_ptr_t ptr, void* data, size_t len );
90 
91  ssize_t pushFunc( const void* data, size_t len );
92  static ssize_t pushFunc( gnutls_transport_ptr_t ptr, const void* data, size_t len );
93 
94  };
95 
96 }
97 
98 #endif // HAVE_GNUTLS
99 
100 #endif // TLSGNUTLSBASE_H__
This is the common base class for (stream) encryption using GnuTLS.
Definition: tlsgnutlsbase.h:39
virtual bool encrypt(const std::string &data)
virtual bool handshake()
virtual void cleanup()
virtual void setClientCert(const std::string &, const std::string &)
Definition: tlsgnutlsbase.h:75
virtual const std::string channelBinding() const
virtual bool hasChannelBinding() const
virtual void setCACerts(const StringList &)
Definition: tlsgnutlsbase.h:72
GnuTLSBase(TLSHandler *th, const std::string &server=EmptyString)
virtual int decrypt(const std::string &data)
An abstract base class for TLS implementations.
Definition: tlsbase.h:32
An interface that allows for interacting with TLS implementations derived from TLSBase.
Definition: tlshandler.h:35
The namespace for the gloox library.
Definition: adhoc.cpp:28
std::list< std::string > StringList
Definition: gloox.h:1251
const std::string EmptyString
Definition: gloox.cpp:124