gloox 1.0.28
connectiontls.h
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#ifndef CONNECTIONTLS_H__
14#define CONNECTIONTLS_H__
15
16#include "gloox.h"
17#include "logsink.h"
18#include "connectionbase.h"
19#include "tlsdefault.h"
20#include "connectiondatahandler.h"
21
22#include <string>
23
24namespace gloox
25{
26
51 class GLOOX_API ConnectionTLS : public TLSHandler, public ConnectionBase, public ConnectionDataHandler
52 {
53 public:
63
71 ConnectionTLS( ConnectionBase* conn, const LogSink& log );
72
76 virtual ~ConnectionTLS();
77
84 void setCACerts( const StringList& cacerts )
85 {
86 m_cacerts = cacerts;
87 }
88
94 const CertInfo& fetchTLSInfo() const { return m_certInfo; }
95
108 void setClientCert( const std::string& clientKey, const std::string& clientCerts )
109 {
110 m_clientKey = clientKey;
111 m_clientCerts = clientCerts;
112 }
113
119 void setConnectionImpl( ConnectionBase* connection );
120
129 void registerTLSHandler( TLSHandler* th ) { m_tlsHandler = th; }
130
131 // reimplemented from ConnectionBase
132 virtual ConnectionError connect();
133
134 // reimplemented from ConnectionBase
135 virtual ConnectionError recv( int timeout = -1 );
136
137 // reimplemented from ConnectionBase
138 virtual bool send( const std::string& data );
139
140 // reimplemented from ConnectionBase
141 virtual ConnectionError receive();
142
143 // reimplemented from ConnectionBase
144 virtual void disconnect();
145
146 // reimplemented from ConnectionBase
147 virtual void cleanup();
148
149 // reimplemented from ConnectionBase
150 virtual void getStatistics( long int& totalIn, long int& totalOut );
151
152 // reimplemented from ConnectionDataHandler
153 virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
154
155 // reimplemented from ConnectionDataHandler
156 virtual void handleConnect( const ConnectionBase* connection );
157
158 // reimplemented from ConnectionDataHandler
159 virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
160
161 // reimplemented from ConnectionDataHandler
162 virtual ConnectionBase* newInstance() const;
163
164 // reimplemented from TLSHandler
165 virtual void handleEncryptedData( const TLSBase*, const std::string& data );
166
167 // reimplemented from TLSHandler
168 virtual void handleDecryptedData( const TLSBase*, const std::string& data );
169
170 // reimplemented from TLSHandler
171 virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo& certinfo );
172
173 protected:
179 virtual TLSBase* getTLSBase( TLSHandler* th, const std::string server )
180 {
181 return new TLSDefault( th, server, TLSDefault::VerifyingClient );
182 }
183
184 ConnectionBase* m_connection;
185 TLSBase* m_tls;
186 TLSHandler* m_tlsHandler;
187 CertInfo m_certInfo;
188 const LogSink& m_log;
189 StringList m_cacerts;
190 std::string m_clientCerts;
191 std::string m_clientKey;
192
193 private:
194 ConnectionTLS& operator=( const ConnectionTLS& );
195
196 };
197
198}
199
200#endif // CONNECTIONTLS_H__
An abstract base class for a connection.
This is an abstract base class to receive events from a ConnectionBase-derived object.
This is an implementation of a TLS/SSL connection.
const CertInfo & fetchTLSInfo() const
void setCACerts(const StringList &cacerts)
void setClientCert(const std::string &clientKey, const std::string &clientCerts)
virtual TLSBase * getTLSBase(TLSHandler *th, const std::string server)
void registerTLSHandler(TLSHandler *th)
An implementation of log sink and source.
Definition logsink.h:39
An abstract base class for TLS implementations.
Definition tlsbase.h:32
This is an abstraction of the various TLS backends.
Definition tlsdefault.h:34
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
ConnectionError
Definition gloox.h:684
std::list< std::string > StringList
Definition gloox.h:1251