gloox  1.1-svn
tlsopensslbase.h
1 /*
2  Copyright (c) 2009 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 TLSOPENSSLBASE_H__
16 #define TLSOPENSSLBASE_H__
17 
18 #include "tlsbase.h"
19 
20 #include "config.h"
21 
22 #ifdef HAVE_OPENSSL
23 
24 #include <openssl/ssl.h>
25 
26 namespace gloox
27 {
28 
36  class OpenSSLBase : public TLSBase
37  {
38  public:
44  OpenSSLBase( TLSHandler* th, const std::string& server = EmptyString );
45 
49  virtual ~OpenSSLBase();
50 
51  // reimplemented from TLSBase
52  virtual bool init( const std::string& clientKey = EmptyString,
53  const std::string& clientCerts = EmptyString,
54  const StringList& cacerts = StringList() );
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  protected:
69  virtual bool setType() = 0;
70  virtual int handshakeFunction() = 0;
71 
72  SSL* m_ssl;
73  SSL_CTX* m_ctx;
74  BIO* m_ibio;
75  BIO* m_nbio;
76 
77  private:
78  void pushFunc();
79  virtual bool privateInit() { return true; }
80  virtual void setCACerts( const StringList& cacerts );
81  virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts );
82 
83  enum TLSOperation
84  {
85  TLSHandshake,
86  TLSWrite,
87  TLSRead
88  };
89 
90  void doTLSOperation( TLSOperation op );
91  int openSSLTime2UnixTime( const char* time_string );
92 
93  std::string m_recvBuffer;
94  std::string m_sendBuffer;
95  char* m_buf;
96  const int m_bufsize;
97 
98  };
99 
100 }
101 
102 #endif // HAVE_OPENSSL
103 
104 #endif // TLSOPENSSLBASE_H__