gloox  1.0.16
tlsgnutlsbase.h
1 /*
2  Copyright (c) 2007-2015 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  gnutls_session_t* m_session;
81 
82  std::string m_recvBuffer;
83  char* m_buf;
84  const int m_bufsize;
85 
86  ssize_t pullFunc( void* data, size_t len );
87  static ssize_t pullFunc( gnutls_transport_ptr_t ptr, void* data, size_t len );
88 
89  ssize_t pushFunc( const void* data, size_t len );
90  static ssize_t pushFunc( gnutls_transport_ptr_t ptr, const void* data, size_t len );
91 
92  };
93 
94 }
95 
96 #endif // HAVE_GNUTLS
97 
98 #endif // TLSGNUTLSBASE_H__
virtual const std::string channelBinding() const
GnuTLSBase(TLSHandler *th, const std::string &server=EmptyString)
std::list< std::string > StringList
Definition: gloox.h:1244
virtual int decrypt(const std::string &data)
virtual void setClientCert(const std::string &, const std::string &)
Definition: tlsgnutlsbase.h:75
virtual void cleanup()
virtual bool handshake()
virtual void setCACerts(const StringList &)
Definition: tlsgnutlsbase.h:72
The namespace for the gloox library.
Definition: adhoc.cpp:27
virtual bool hasChannelBinding() const
This is the common base class for (stream) encryption using GnuTLS.
Definition: tlsgnutlsbase.h:38
An abstract base class for TLS implementations.
Definition: tlsbase.h:31
virtual bool encrypt(const std::string &data)
An interface that allows for interacting with TLS implementations derived from TLSBase.
Definition: tlshandler.h:34
const std::string EmptyString
Definition: gloox.cpp:123