tlsopensslbase.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TLSOPENSSLBASE_H__
00016 #define TLSOPENSSLBASE_H__
00017
00018 #include "tlsbase.h"
00019
00020 #include "config.h"
00021
00022 #ifdef HAVE_OPENSSL
00023
00024 #include <openssl/ssl.h>
00025
00026 namespace gloox
00027 {
00028
00036 class OpenSSLBase : public TLSBase
00037 {
00038 public:
00044 OpenSSLBase( TLSHandler* th, const std::string& server = EmptyString );
00045
00049 virtual ~OpenSSLBase();
00050
00051
00052 virtual bool init( const std::string& clientKey = EmptyString,
00053 const std::string& clientCerts = EmptyString,
00054 const StringList& cacerts = StringList() );
00055
00056
00057 virtual bool encrypt( const std::string& data );
00058
00059
00060 virtual int decrypt( const std::string& data );
00061
00062
00063 virtual void cleanup();
00064
00065
00066 virtual bool handshake();
00067
00068
00069 virtual void setCACerts( const StringList& cacerts );
00070
00071
00072 virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts );
00073
00074 protected:
00075 virtual bool setType() = 0;
00076 virtual int handshakeFunction() = 0;
00077
00078 SSL* m_ssl;
00079 SSL_CTX* m_ctx;
00080 BIO* m_ibio;
00081 BIO* m_nbio;
00082
00083 private:
00084 void pushFunc();
00085 virtual bool privateInit() { return true; }
00086
00087 enum TLSOperation
00088 {
00089 TLSHandshake,
00090 TLSWrite,
00091 TLSRead
00092 };
00093
00094 void doTLSOperation( TLSOperation op );
00095 int openSSLTime2UnixTime( const char* time_string );
00096
00097 std::string m_recvBuffer;
00098 std::string m_sendBuffer;
00099 char* m_buf;
00100 const int m_bufsize;
00101
00102 };
00103
00104 }
00105
00106 #endif // HAVE_OPENSSL
00107
00108 #endif // TLSOPENSSLBASE_H__