tlsdefault.cpp

00001 /*
00002  * Copyright (c) 2007-2008 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 #include "tlsdefault.h"
00014 
00015 #include "tlshandler.h"
00016 
00017 #ifdef _WIN32
00018 # include "../config.h.win"
00019 #elif defined( _WIN32_WCE )
00020 # include "../config.h.win"
00021 #else
00022 # include "config.h"
00023 #endif
00024 
00025 #if defined( HAVE_OPENSSL )
00026 # define HAVE_TLS
00027 # include "tlsopenssl.h"
00028 #elif defined( HAVE_GNUTLS )
00029 # define HAVE_TLS
00030 # include "tlsgnutlsclient.h"
00031 # include "tlsgnutlsclientanon.h"
00032 # include "tlsgnutlsserveranon.h"
00033 #elif defined( HAVE_WINTLS )
00034 # define HAVE_TLS
00035 # include "tlsschannel.h"
00036 #endif
00037 
00038 namespace gloox
00039 {
00040 
00041   TLSDefault::TLSDefault( TLSHandler *th, const std::string server, Type type )
00042     : TLSBase( th, server ), m_impl( 0 )
00043   {
00044     switch( type )
00045     {
00046       case VerifyingClient:
00047 #ifdef HAVE_GNUTLS
00048         m_impl = new GnuTLSClient( th, server );
00049 #elif defined( HAVE_OPENSSL )
00050         m_impl = new OpenSSL( th, server );
00051 #elif defined( HAVE_WINTLS )
00052         m_impl = new SChannel( th, server );
00053 #endif
00054         break;
00055       case AnonymousClient:
00056 #ifdef HAVE_GNUTLS
00057         m_impl = new GnuTLSClientAnon( th );
00058 #endif
00059         break;
00060       case AnonymousServer:
00061 #ifdef HAVE_GNUTLS
00062         m_impl = new GnuTLSServerAnon( th );
00063 #endif
00064         break;
00065       case VerifyingServer:
00066         break;
00067       default:
00068         break;
00069     }
00070   }
00071 
00072   TLSDefault::~TLSDefault()
00073   {
00074     delete m_impl;
00075   }
00076 
00077   int TLSDefault::types()
00078   {
00079     int types = 0;
00080 #ifdef HAVE_GNUTLS
00081     types |= VerifyingClient;
00082     types |= AnonymousClient;
00083     types |= AnonymousServer;
00084 #elif defined( HAVE_OPENSSL )
00085     types |= VerifyingClient;
00086 #elif defined( HAVE_WINTLS )
00087     types |= VerifyingClient;
00088 #endif
00089     return types;
00090   }
00091 
00092   bool TLSDefault::encrypt( const std::string& data )
00093   {
00094     if( m_impl )
00095       return m_impl->encrypt( data );
00096 
00097     return false;
00098   }
00099 
00100   int TLSDefault::decrypt( const std::string& data )
00101   {
00102     if( m_impl )
00103       return m_impl->decrypt( data );
00104 
00105     return 0;
00106   }
00107 
00108   void TLSDefault::cleanup()
00109   {
00110     if( m_impl )
00111       m_impl->cleanup();
00112   }
00113 
00114   bool TLSDefault::handshake()
00115   {
00116     if( m_impl )
00117       return m_impl->handshake();
00118 
00119     return false;
00120   }
00121 
00122   bool TLSDefault::isSecure() const
00123   {
00124     if( m_impl )
00125       return m_impl->isSecure();
00126 
00127     return false;
00128   }
00129 
00130   void TLSDefault::setCACerts( const StringList& cacerts )
00131   {
00132     if( m_impl )
00133       m_impl->setCACerts( cacerts );
00134   }
00135 
00136   const CertInfo& TLSDefault::fetchTLSInfo() const
00137   {
00138     if( m_impl )
00139       return m_impl->fetchTLSInfo();
00140 
00141     return m_certInfo;
00142   }
00143 
00144   void TLSDefault::setClientCert( const std::string& clientKey, const std::string& clientCerts )
00145   {
00146     if( m_impl )
00147       m_impl->setClientCert( clientKey, clientCerts );
00148   }
00149 
00150 }

Generated on Sun Apr 27 11:08:13 2008 for gloox by  doxygen 1.5.5