gloox  0.9.9.12
tlsopenssl.h
1 /*
2  Copyright (c) 2007-2008 by Jakob Schroeter <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 TLSOPENSSL_H__
16 #define TLSOPENSSL_H__
17 
18 #include "tlsbase.h"
19 
20 #ifdef _WIN32
21 # include "../config.h.win"
22 #elif defined( _WIN32_WCE )
23 # include "../config.h.win"
24 #else
25 # include "config.h"
26 #endif
27 
28 #ifdef HAVE_OPENSSL
29 
30 #include <openssl/ssl.h>
31 
32 namespace gloox
33 {
34 
41  class OpenSSL : public TLSBase
42  {
43  public:
49  OpenSSL( TLSHandler *th, const std::string& server );
50 
54  virtual ~OpenSSL();
55 
56  // reimplemented from TLSBase
57  virtual bool encrypt( const std::string& data );
58 
59  // reimplemented from TLSBase
60  virtual int decrypt( const std::string& data );
61 
62  // reimplemented from TLSBase
63  virtual void cleanup();
64 
65  // reimplemented from TLSBase
66  virtual bool handshake();
67 
68  // reimplemented from TLSBase
69  virtual void setCACerts( const StringList& cacerts );
70 
71  // reimplemented from TLSBase
72  virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts );
73 
74  private:
75  void pushFunc();
76 
77  enum TLSOperation
78  {
79  TLSHandshake,
80  TLSWrite,
81  TLSRead
82  };
83 
84  void doTLSOperation( TLSOperation op );
85  int openSSLTime2UnixTime( const char* time_string );
86 
87  SSL *m_ssl;
88  SSL_CTX *m_ctx;
89  BIO *m_ibio;
90  BIO *m_nbio;
91  std::string m_recvBuffer;
92  std::string m_sendBuffer;
93  char *m_buf;
94  const int m_bufsize;
95 
96  };
97 
98 }
99 
100 #endif // HAVE_OPENSSL
101 
102 #endif // TLSOPENSSL_H__