gloox  1.1-svn
tlsschannelbase.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 #ifndef TLSSCHANNELBASE_H__
14 #define TLSSCHANNELBASE_H__
15 
16 #include "tlsbase.h"
17 
18 #include "config.h"
19 
20 #ifdef HAVE_WINTLS
21 
22 #include <ctime>
23 
24 #define SECURITY_WIN32
25 #include <windows.h>
26 #include <security.h>
27 #include <schnlsp.h>
28 
29 namespace gloox
30 {
31 
38  class SChannelBase : public TLSBase
39  {
40  public:
46  SChannelBase( TLSHandler* th, const std::string& server );
47 
51  virtual ~SChannelBase();
52 
53  // reimplemented from TLSBase
54  virtual bool init( const std::string& clientKey = EmptyString,
55  const std::string& clientCerts = EmptyString,
56  const StringList& cacerts = StringList() );
57 
58  // reimplemented from TLSBase
59  virtual bool encrypt( const std::string& data );
60 
61  // reimplemented from TLSBase
62  virtual int decrypt( const std::string& data );
63 
64  // reimplemented from TLSBase
65  virtual void cleanup();
66 
67  protected:
68  virtual void handshakeStage() = 0;
69  virtual void privateCleanup() {}
70 
71  void setSizes();
72 
73  int filetime2int( FILETIME t );
74 
75  void validateCert();
76  void connectionInfos();
77  void certData();
78  void setCertinfos();
79  CredHandle m_credHandle;
80  CtxtHandle m_context;
81 
82  SecPkgContext_StreamSizes m_sizes;
83 
84  size_t m_header_max;
85  size_t m_message_max;
86  size_t m_trailer_max;
87 
88  std::string m_buffer;
89 
90  bool m_cleanedup;
91  bool m_haveCredentialsHandle;
92 
93  HCERTSTORE m_store;
94  PCCERT_CONTEXT m_cert;
95  SCHANNEL_CRED m_tlsCred;
96 
97  // windows error outputs
98 // void print_error( int errorcode, const char* place = 0 );
99 
100  };
101 }
102 
103 #endif // HAVE_WINTLS
104 
105 #endif // TLSSCHANNELBASE_H__