gloox  1.1-svn
tlsbase.h
1 /*
2  Copyright (c) 2007-2009 by Jakob Schroeter <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 
60  virtual bool init( const std::string& clientKey = EmptyString,
61  const std::string& clientCerts = EmptyString,
62  const StringList& cacerts = StringList() ) = 0;
63 
71  void setInitLib( bool init ) { m_initLib = init; }
72 
85  virtual void setSubject( const std::string& subject ) { m_subject = subject; }
86 
93  virtual bool encrypt( const std::string& data ) = 0;
94 
102  virtual int decrypt( const std::string& data ) = 0;
103 
107  virtual void cleanup() = 0;
108 
116  virtual bool handshake() = 0;
117 
122  virtual bool isSecure() const { return m_secure; }
123 
128  virtual const CertInfo& fetchTLSInfo() const { return m_certInfo; }
129 
130  protected:
131  TLSHandler* m_handler;
132  StringList m_cacerts;
133  std::string m_clientKey;
134  std::string m_clientCerts;
135  std::string m_server;
136  std::string m_subject;
137  CertInfo m_certInfo;
138  util::Mutex m_mutex;
139  bool m_secure;
140  bool m_valid;
141  bool m_initLib;
142 
143  };
144 
145 }
146 
147 #endif // TLSBASE_H__