gloox  1.0.28
tlsbase.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 
14 
15 #ifndef TLSBASE_H__
16 #define TLSBASE_H__
17 
18 #include "gloox.h"
19 #include "mutex.h"
20 #include "tlshandler.h"
21 
22 namespace 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 
123  virtual const std::string channelBindingType() const { return "tls-unique"; }
124 
130  virtual void setCACerts( const StringList& cacerts ) = 0;
131 
136  virtual const CertInfo& fetchTLSInfo() const { return m_certInfo; }
137 
149  virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts ) = 0;
150 
151  protected:
152  TLSHandler* m_handler;
153  StringList m_cacerts;
154  std::string m_clientKey;
155  std::string m_clientCerts;
156  std::string m_server;
157  CertInfo m_certInfo;
158  util::Mutex m_mutex;
159  bool m_secure;
160  bool m_valid;
161  bool m_initLib;
162 
163  };
164 
165 }
166 
167 #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 const CertInfo & fetchTLSInfo() const
Definition: tlsbase.h:136
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
void setInitLib(bool init)
Definition: tlsbase.h:68
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