tlsdefault.cpp

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

Generated by  doxygen 1.6.2