tlsopensslbase.h

00001 /*
00002   Copyright (c) 2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
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       // reimplemented from TLSBase
00052       virtual bool init( const std::string& clientKey = EmptyString,
00053                          const std::string& clientCerts = EmptyString,
00054                          const StringList& cacerts = StringList() );
00055 
00056       // reimplemented from TLSBase
00057       virtual bool encrypt( const std::string& data );
00058 
00059       // reimplemented from TLSBase
00060       virtual int decrypt( const std::string& data );
00061 
00062       // reimplemented from TLSBase
00063       virtual void cleanup();
00064 
00065       // reimplemented from TLSBase
00066       virtual bool handshake();
00067 
00068       // reimplemented from TLSBase
00069       virtual void setCACerts( const StringList& cacerts );
00070 
00071       // reimplemented from TLSBase
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__

Generated by  doxygen 1.6.2