gloox  1.0.1
tlsschannel.h
1 /*
2  * Copyright (c) 2007-2012 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 TLSSCHANNEL_H__
14 #define TLSSCHANNEL_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 SChannel : public TLSBase
39  {
40  public:
46  SChannel( TLSHandler* th, const std::string& server );
47 
51  virtual ~SChannel();
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  { return true; }
58 
59  // reimplemented from TLSBase
60  virtual bool encrypt( const std::string& data );
61 
62  // reimplemented from TLSBase
63  virtual int decrypt( const std::string& data );
64 
65  // reimplemented from TLSBase
66  virtual void cleanup();
67 
68  // reimplemented from TLSBase
69  virtual bool handshake();
70 
71  // reimplemented from TLSBase
72  virtual void setCACerts( const StringList& cacerts );
73 
74  // reimplemented from TLSBase
75  virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts );
76 
77  private:
78  void handshakeStage( const std::string& data );
79  void setSizes();
80 
81  int filetime2int( FILETIME t );
82 
83  void validateCert();
84  void connectionInfos();
85  void certData();
86  void setCertinfos();
87  CredHandle m_credHandle;
88  CtxtHandle m_context;
89 
90  SecPkgContext_StreamSizes m_sizes;
91 
92  size_t m_header_max;
93  size_t m_message_max;
94  size_t m_trailer_max;
95 
96  std::string m_buffer;
97 
98  bool m_cleanedup;
99 
100  // windows error outputs
101 // void print_error( int errorcode, const char* place = 0 );
102 
103  };
104 }
105 
106 #endif // HAVE_WINTLS
107 
108 #endif // TLSSCHANNEL_H__