tlsdefault.cpp
/*
* Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
* This file is part of the gloox library. http://camaya.net/gloox
*
* This software is distributed under a license. The full license
* agreement can be found in the file LICENSE in this distribution.
* This software may not be copied, modified, sold or distributed
* other than expressed in the named license agreement.
*
* This software is distributed without any warranty.
*/
#include "tlsdefault.h"
#include "tlshandler.h"
#include "config.h"
#if defined( HAVE_GNUTLS )
# define HAVE_TLS
# include "tlsgnutlsclient.h"
# include "tlsgnutlsclientanon.h"
# include "tlsgnutlsserveranon.h"
#elif defined( HAVE_OPENSSL )
# define HAVE_TLS
# include "tlsopensslclient.h"
#ifndef __SYMBIAN32__
# include "tlsopensslserver.h"
#endif
#elif defined( HAVE_WINTLS )
# define HAVE_TLS
# include "tlsschannel.h"
#endif
namespace gloox
{
TLSDefault::TLSDefault( TLSHandler* th, const std::string server, Type type )
: TLSBase( th, server ), m_impl( 0 )
{
switch( type )
{
case VerifyingClient:
#ifdef HAVE_GNUTLS
m_impl = new GnuTLSClient( th, server );
#elif defined( HAVE_OPENSSL )
m_impl = new OpenSSLClient( th, server );
#elif defined( HAVE_WINTLS )
m_impl = new SChannel( th, server );
#endif
break;
case AnonymousClient:
#ifdef HAVE_GNUTLS
m_impl = new GnuTLSClientAnon( th );
#endif
break;
case AnonymousServer:
#ifdef HAVE_GNUTLS
m_impl = new GnuTLSServerAnon( th );
#endif
break;
case VerifyingServer:
#ifdef HAVE_OPENSSL
#ifndef __SYMBIAN32__
m_impl = new OpenSSLServer( th );
#endif
#endif
break;
default:
break;
}
}
TLSDefault::~TLSDefault()
{
delete m_impl;
}
bool TLSDefault::init( const std::string& clientKey,
const std::string& clientCerts,
const StringList& cacerts )
{
return m_impl ? m_impl->init( clientKey, clientCerts,
cacerts ) : false;
}
int TLSDefault::types()
{
int types = 0;
#ifdef HAVE_GNUTLS
types |= VerifyingClient;
types |= AnonymousClient;
types |= AnonymousServer;
#elif defined( HAVE_OPENSSL )
types |= VerifyingClient;
types |= VerifyingServer;
#elif defined( HAVE_WINTLS )
types |= VerifyingClient;
#endif
return types;
}
bool TLSDefault::encrypt( const std::string& data )
{
return m_impl ? m_impl->encrypt( data ) : false;
}
int TLSDefault::decrypt( const std::string& data )
{
return m_impl ? m_impl->decrypt( data ) : 0;
}
void TLSDefault::cleanup()
{
if( m_impl )
m_impl->cleanup();
}
bool TLSDefault::handshake()
{
return m_impl ? m_impl->handshake() : false;
}
bool TLSDefault::isSecure() const
{
return m_impl ? m_impl->isSecure() : false;
}
bool TLSDefault::hasChannelBinding() const
{
return m_impl ? m_impl->hasChannelBinding() : false;
}
const std::string TLSDefault::channelBinding() const
{
return m_impl ? m_impl->channelBinding() : EmptyString;
}
const std::string TLSDefault::channelBindingType() const
{
return m_impl ? m_impl->channelBindingType() : "tls-unique";
}
void TLSDefault::setCACerts( const StringList& cacerts )
{
if( m_impl )
m_impl->setCACerts( cacerts );
}
const CertInfo& TLSDefault::fetchTLSInfo() const
{
return m_impl ? m_impl->fetchTLSInfo() : m_certInfo;
}
void TLSDefault::setClientCert( const std::string& clientKey, const std::string& clientCerts )
{
if( m_impl )
m_impl->setClientCert( clientKey, clientCerts );
}
}
gloox::GnuTLSClientAnon
This class implements an anonymous TLS backend using GnuTLS.
Definition tlsgnutlsclientanon.h:39
gloox::GnuTLSClient
This class implements a TLS backend using GnuTLS.
Definition tlsgnutlsclient.h:39
gloox::GnuTLSServerAnon
This class implements (stream) encryption using GnuTLS server-side.
Definition tlsgnutlsserveranon.h:39
gloox::OpenSSLClient
Definition tlsopensslclient.h:36
gloox::OpenSSLServer
Definition tlsopensslserver.h:36
gloox::SChannel
Definition tlsschannel.h:39
gloox::TLSBase::TLSBase
TLSBase(TLSHandler *th, const std::string server)
Definition tlsbase.h:39
gloox::TLSDefault::encrypt
virtual bool encrypt(const std::string &data)
Definition tlsdefault.cpp:103
gloox::TLSDefault::Type
Type
Definition tlsdefault.h:41
gloox::TLSDefault::AnonymousServer
@ AnonymousServer
Definition tlsdefault.h:47
gloox::TLSDefault::VerifyingServer
@ VerifyingServer
Definition tlsdefault.h:46
gloox::TLSDefault::VerifyingClient
@ VerifyingClient
Definition tlsdefault.h:42
gloox::TLSDefault::AnonymousClient
@ AnonymousClient
Definition tlsdefault.h:44
gloox::TLSDefault::fetchTLSInfo
virtual const CertInfo & fetchTLSInfo() const
Definition tlsdefault.cpp:150
gloox::TLSDefault::setCACerts
virtual void setCACerts(const StringList &cacerts)
Definition tlsdefault.cpp:144
gloox::TLSDefault::handshake
virtual bool handshake()
Definition tlsdefault.cpp:119
gloox::TLSDefault::cleanup
virtual void cleanup()
Definition tlsdefault.cpp:113
gloox::TLSDefault::types
static int types()
Definition tlsdefault.cpp:87
gloox::TLSDefault::setClientCert
virtual void setClientCert(const std::string &clientKey, const std::string &clientCerts)
Definition tlsdefault.cpp:155
gloox::TLSDefault::init
virtual bool init(const std::string &clientKey=EmptyString, const std::string &clientCerts=EmptyString, const StringList &cacerts=StringList())
Definition tlsdefault.cpp:79
gloox::TLSDefault::channelBinding
virtual const std::string channelBinding() const
Definition tlsdefault.cpp:134
gloox::TLSDefault::~TLSDefault
virtual ~TLSDefault()
Definition tlsdefault.cpp:74
gloox::TLSDefault::hasChannelBinding
virtual bool hasChannelBinding() const
Definition tlsdefault.cpp:129
gloox::TLSDefault::isSecure
virtual bool isSecure() const
Definition tlsdefault.cpp:124
gloox::TLSDefault::TLSDefault
TLSDefault(TLSHandler *th, const std::string server, Type type=VerifyingClient)
Definition tlsdefault.cpp:38
gloox::TLSDefault::decrypt
virtual int decrypt(const std::string &data)
Definition tlsdefault.cpp:108
gloox::TLSDefault::channelBindingType
virtual const std::string channelBindingType() const
Definition tlsdefault.cpp:139
gloox::TLSHandler
An interface that allows for interacting with TLS implementations derived from TLSBase.
Definition tlshandler.h:35
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::EmptyString
const std::string EmptyString
Definition gloox.cpp:124
gloox::CertInfo
Definition gloox.h:990