gloox 1.0.24
tlsbase.h
1/*
2 Copyright (c) 2007-2019 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
14
15#ifndef TLSBASE_H__
16#define TLSBASE_H__
17
18#include "gloox.h"
19#include "mutex.h"
20#include "tlshandler.h"
21
22namespace gloox
23{
24
31 class GLOOX_API TLSBase
32 {
33 public:
39 TLSBase( TLSHandler* th, const std::string server )
40 : m_handler( th ), m_server( server ), m_secure( false ), m_valid( false ), m_initLib( true )
41 {}
42
46 virtual ~TLSBase() {}
47
57 virtual bool init( const std::string& clientKey = EmptyString,
58 const std::string& clientCerts = EmptyString,
59 const StringList& cacerts = StringList() ) = 0;
60
68 void setInitLib( bool init ) { m_initLib = init; }
69
76 virtual bool encrypt( const std::string& data ) = 0;
77
85 virtual int decrypt( const std::string& data ) = 0;
86
90 virtual void cleanup() = 0;
91
99 virtual bool handshake() = 0;
100
105 virtual bool isSecure() const { return m_secure; }
106
111 virtual bool hasChannelBinding() const { return false; }
112
117 virtual const std::string channelBinding() const { return EmptyString; }
118
124 virtual void setCACerts( const StringList& cacerts ) = 0;
125
130 virtual const CertInfo& fetchTLSInfo() const { return m_certInfo; }
131
143 virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts ) = 0;
144
145 protected:
146 TLSHandler* m_handler;
147 StringList m_cacerts;
148 std::string m_clientKey;
149 std::string m_clientCerts;
150 std::string m_server;
151 CertInfo m_certInfo;
152 util::Mutex m_mutex;
153 bool m_secure;
154 bool m_valid;
155 bool m_initLib;
156
157 };
158
159}
160
161#endif // TLSBASE_H__
An abstract base class for TLS implementations.
Definition: tlsbase.h:32
virtual bool encrypt(const std::string &data)=0
virtual ~TLSBase()
Definition: tlsbase.h:46
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
void setInitLib(bool init)
Definition: tlsbase.h:68
virtual const CertInfo & fetchTLSInfo() const
Definition: tlsbase.h:130
TLSBase(TLSHandler *th, const std::string server)
Definition: tlsbase.h:39
An interface that allows for interacting with TLS implementations derived from TLSBase.
Definition: tlshandler.h:35
A simple implementation of mutex as a wrapper around a pthread mutex or a win32 critical section.
Definition: mutex.h:34
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