gloox 1.0.28
tlsdefault.cpp
1/*
2 * Copyright (c) 2007-2023 by Jakob Schröter <js@camaya.net>
3 * This file is part of the gloox library. http://camaya.net/gloox
4 *
5 * This software is distributed under a license. The full license
6 * agreement can be found in the file LICENSE in this distribution.
7 * This software may not be copied, modified, sold or distributed
8 * other than expressed in the named license agreement.
9 *
10 * This software is distributed without any warranty.
11 */
12
13#include "tlsdefault.h"
14
15#include "tlshandler.h"
16
17#include "config.h"
18
19#if defined( HAVE_GNUTLS )
20# define HAVE_TLS
21# include "tlsgnutlsclient.h"
22# include "tlsgnutlsclientanon.h"
23# include "tlsgnutlsserveranon.h"
24#elif defined( HAVE_OPENSSL )
25# define HAVE_TLS
26# include "tlsopensslclient.h"
27#ifndef __SYMBIAN32__
28# include "tlsopensslserver.h"
29#endif
30#elif defined( HAVE_WINTLS )
31# define HAVE_TLS
32# include "tlsschannel.h"
33#endif
34
35namespace gloox
36{
37
38 TLSDefault::TLSDefault( TLSHandler* th, const std::string server, Type type )
39 : TLSBase( th, server ), m_impl( 0 )
40 {
41 switch( type )
42 {
43 case VerifyingClient:
44#ifdef HAVE_GNUTLS
45 m_impl = new GnuTLSClient( th, server );
46#elif defined( HAVE_OPENSSL )
47 m_impl = new OpenSSLClient( th, server );
48#elif defined( HAVE_WINTLS )
49 m_impl = new SChannel( th, server );
50#endif
51 break;
52 case AnonymousClient:
53#ifdef HAVE_GNUTLS
54 m_impl = new GnuTLSClientAnon( th );
55#endif
56 break;
57 case AnonymousServer:
58#ifdef HAVE_GNUTLS
59 m_impl = new GnuTLSServerAnon( th );
60#endif
61 break;
62 case VerifyingServer:
63#ifdef HAVE_OPENSSL
64#ifndef __SYMBIAN32__
65 m_impl = new OpenSSLServer( th );
66#endif
67#endif
68 break;
69 default:
70 break;
71 }
72 }
73
75 {
76 delete m_impl;
77 }
78
79 bool TLSDefault::init( const std::string& clientKey,
80 const std::string& clientCerts,
81 const StringList& cacerts )
82 {
83 return m_impl ? m_impl->init( clientKey, clientCerts,
84 cacerts ) : false;
85 }
86
88 {
89 int types = 0;
90#ifdef HAVE_GNUTLS
94#elif defined( HAVE_OPENSSL )
97#elif defined( HAVE_WINTLS )
99#endif
100 return types;
101 }
102
103 bool TLSDefault::encrypt( const std::string& data )
104 {
105 return m_impl ? m_impl->encrypt( data ) : false;
106 }
107
108 int TLSDefault::decrypt( const std::string& data )
109 {
110 return m_impl ? m_impl->decrypt( data ) : 0;
111 }
112
114 {
115 if( m_impl )
116 m_impl->cleanup();
117 }
118
120 {
121 return m_impl ? m_impl->handshake() : false;
122 }
123
125 {
126 return m_impl ? m_impl->isSecure() : false;
127 }
128
130 {
131 return m_impl ? m_impl->hasChannelBinding() : false;
132 }
133
134 const std::string TLSDefault::channelBinding() const
135 {
136 return m_impl ? m_impl->channelBinding() : EmptyString;
137 }
138
139 const std::string TLSDefault::channelBindingType() const
140 {
141 return m_impl ? m_impl->channelBindingType() : "tls-unique";
142 }
143
144 void TLSDefault::setCACerts( const StringList& cacerts )
145 {
146 if( m_impl )
147 m_impl->setCACerts( cacerts );
148 }
149
151 {
152 return m_impl ? m_impl->fetchTLSInfo() : m_certInfo;
153 }
154
155 void TLSDefault::setClientCert( const std::string& clientKey, const std::string& clientCerts )
156 {
157 if( m_impl )
158 m_impl->setClientCert( clientKey, clientCerts );
159 }
160
161}
This class implements an anonymous TLS backend using GnuTLS.
This class implements a TLS backend using GnuTLS.
This class implements (stream) encryption using GnuTLS server-side.
An abstract base class for TLS implementations.
Definition tlsbase.h:32
virtual bool encrypt(const std::string &data)=0
virtual int decrypt(const std::string &data)=0
virtual const std::string channelBinding() const
Definition tlsbase.h:117
virtual void setClientCert(const std::string &clientKey, const std::string &clientCerts)=0
virtual bool hasChannelBinding() const
Definition tlsbase.h:111
virtual bool init(const std::string &clientKey=EmptyString, const std::string &clientCerts=EmptyString, const StringList &cacerts=StringList())=0
virtual bool handshake()=0
virtual void cleanup()=0
virtual bool isSecure() const
Definition tlsbase.h:105
virtual void setCACerts(const StringList &cacerts)=0
virtual const std::string channelBindingType() const
Definition tlsbase.h:123
virtual const CertInfo & fetchTLSInfo() const
Definition tlsbase.h:136
virtual bool encrypt(const std::string &data)
virtual const CertInfo & fetchTLSInfo() const
virtual void setCACerts(const StringList &cacerts)
virtual bool handshake()
virtual void cleanup()
static int types()
virtual void setClientCert(const std::string &clientKey, const std::string &clientCerts)
virtual bool init(const std::string &clientKey=EmptyString, const std::string &clientCerts=EmptyString, const StringList &cacerts=StringList())
virtual const std::string channelBinding() const
virtual ~TLSDefault()
virtual bool hasChannelBinding() const
virtual bool isSecure() const
TLSDefault(TLSHandler *th, const std::string server, Type type=VerifyingClient)
virtual int decrypt(const std::string &data)
virtual const std::string channelBindingType() const
An interface that allows for interacting with TLS implementations derived from TLSBase.
Definition tlshandler.h:35
The namespace for the gloox library.
Definition adhoc.cpp:28
std::list< std::string > StringList
Definition gloox.h:1251
const std::string EmptyString
Definition gloox.cpp:124