connectiontls.h
/*
* 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.
*/
#ifndef CONNECTIONTLS_H__
#define CONNECTIONTLS_H__
#include "gloox.h"
#include "logsink.h"
#include "connectionbase.h"
#include "tlsdefault.h"
#include "connectiondatahandler.h"
#include <string>
namespace gloox
{
class GLOOX_API ConnectionTLS : public TLSHandler, public ConnectionBase, public ConnectionDataHandler
{
public:
ConnectionTLS( ConnectionDataHandler* cdh, ConnectionBase* conn, const LogSink& log );
ConnectionTLS( ConnectionBase* conn, const LogSink& log );
virtual ~ConnectionTLS();
void setCACerts( const StringList& cacerts )
{
m_cacerts = cacerts;
}
const CertInfo& fetchTLSInfo() const { return m_certInfo; }
void setClientCert( const std::string& clientKey, const std::string& clientCerts )
{
m_clientKey = clientKey;
m_clientCerts = clientCerts;
}
void setConnectionImpl( ConnectionBase* connection );
void registerTLSHandler( TLSHandler* th ) { m_tlsHandler = th; }
// reimplemented from ConnectionBase
virtual ConnectionError connect();
// reimplemented from ConnectionBase
virtual ConnectionError recv( int timeout = -1 );
// reimplemented from ConnectionBase
virtual bool send( const std::string& data );
// reimplemented from ConnectionBase
virtual ConnectionError receive();
// reimplemented from ConnectionBase
virtual void disconnect();
// reimplemented from ConnectionBase
virtual void cleanup();
// reimplemented from ConnectionBase
virtual void getStatistics( long int& totalIn, long int& totalOut );
// reimplemented from ConnectionDataHandler
virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
// reimplemented from ConnectionDataHandler
virtual void handleConnect( const ConnectionBase* connection );
// reimplemented from ConnectionDataHandler
virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
// reimplemented from ConnectionDataHandler
virtual ConnectionBase* newInstance() const;
// reimplemented from TLSHandler
virtual void handleEncryptedData( const TLSBase*, const std::string& data );
// reimplemented from TLSHandler
virtual void handleDecryptedData( const TLSBase*, const std::string& data );
// reimplemented from TLSHandler
virtual void handleHandshakeResult( const TLSBase* base, bool success, CertInfo& certinfo );
protected:
virtual TLSBase* getTLSBase( TLSHandler* th, const std::string server )
{
return new TLSDefault( th, server, TLSDefault::VerifyingClient );
}
ConnectionBase* m_connection;
TLSBase* m_tls;
TLSHandler* m_tlsHandler;
CertInfo m_certInfo;
const LogSink& m_log;
StringList m_cacerts;
std::string m_clientCerts;
std::string m_clientKey;
private:
ConnectionTLS& operator=( const ConnectionTLS& );
};
}
#endif // CONNECTIONTLS_H__
gloox::ConnectionBase
An abstract base class for a connection.
Definition connectionbase.h:35
gloox::ConnectionBase::server
const std::string & server() const
Definition connectionbase.h:115
gloox::ConnectionBase::ConnectionBase
ConnectionBase(ConnectionDataHandler *cdh)
Definition connectionbase.h:42
gloox::ConnectionDataHandler
This is an abstract base class to receive events from a ConnectionBase-derived object.
Definition connectiondatahandler.h:36
gloox::ConnectionTLS
This is an implementation of a TLS/SSL connection.
Definition connectiontls.h:52
gloox::ConnectionTLS::ConnectionTLS
ConnectionTLS(ConnectionDataHandler *cdh, ConnectionBase *conn, const LogSink &log)
Definition connectiontls.cpp:22
gloox::ConnectionTLS::fetchTLSInfo
const CertInfo & fetchTLSInfo() const
Definition connectiontls.h:94
gloox::ConnectionTLS::setCACerts
void setCACerts(const StringList &cacerts)
Definition connectiontls.h:84
gloox::ConnectionTLS::setClientCert
void setClientCert(const std::string &clientKey, const std::string &clientCerts)
Definition connectiontls.h:108
gloox::ConnectionTLS::getTLSBase
virtual TLSBase * getTLSBase(TLSHandler *th, const std::string server)
Definition connectiontls.h:179
gloox::ConnectionTLS::registerTLSHandler
void registerTLSHandler(TLSHandler *th)
Definition connectiontls.h:129
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox::TLSBase
An abstract base class for TLS implementations.
Definition tlsbase.h:32
gloox::TLSDefault
This is an abstraction of the various TLS backends.
Definition tlsdefault.h:34
gloox::TLSDefault::VerifyingClient
@ VerifyingClient
Definition tlsdefault.h:42
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::ConnectionError
ConnectionError
Definition gloox.h:684
gloox::StringList
std::list< std::string > StringList
Definition gloox.h:1251
gloox::CertInfo
Definition gloox.h:990