gloox  0.9.9.12
tlsschannel.h
1 /*
2  * Copyright (c) 2007-2008 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 #ifdef _WIN32
19 # include "../config.h.win"
20 #elif defined( _WIN32_WCE )
21 # include "../config.h.win"
22 #else
23 # include "config.h"
24 #endif
25 
26 #ifdef HAVE_WINTLS
27 
28 #include <ctime>
29 
30 #define SECURITY_WIN32
31 #include <windows.h>
32 #include <security.h>
33 #include <schnlsp.h>
34 
35 namespace gloox
36 {
37 
44  class SChannel : public TLSBase
45  {
46  public:
52  SChannel( TLSHandler* th, const std::string& server );
53 
57  virtual ~SChannel();
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__