gloox  1.0
tlsschannel.h
00001 /*
00002  * Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net>
00003  * This file is part of the gloox library. http://camaya.net/gloox
00004  *
00005  * This software is distributed under a license. The full license
00006  * agreement can be found in the file LICENSE in this distribution.
00007  * This software may not be copied, modified, sold or distributed
00008  * other than expressed in the named license agreement.
00009  *
00010  * This software is distributed without any warranty.
00011  */
00012 
00013 #ifndef TLSSCHANNEL_H__
00014 #define TLSSCHANNEL_H__
00015 
00016 #include "tlsbase.h"
00017 
00018 #include "config.h"
00019 
00020 #ifdef HAVE_WINTLS
00021 
00022 #include <ctime>
00023 
00024 #define SECURITY_WIN32
00025 #include <windows.h>
00026 #include <security.h>
00027 #include <schnlsp.h>
00028 
00029 namespace gloox
00030 {
00031 
00038   class SChannel : public TLSBase
00039   {
00040     public:
00046       SChannel( TLSHandler* th, const std::string& server );
00047 
00051       virtual ~SChannel();
00052 
00053       // reimplemented from TLSBase
00054       virtual bool init( const std::string& /*clientKey*/ = EmptyString,
00055                          const std::string& /*clientCerts*/ = EmptyString,
00056                          const StringList& /*cacerts*/ = StringList() )
00057         { return true; }
00058 
00059       // reimplemented from TLSBase
00060       virtual bool encrypt( const std::string& data );
00061 
00062       // reimplemented from TLSBase
00063       virtual int decrypt( const std::string& data );
00064 
00065       // reimplemented from TLSBase
00066       virtual void cleanup();
00067 
00068       // reimplemented from TLSBase
00069       virtual bool handshake();
00070 
00071       // reimplemented from TLSBase
00072       virtual void setCACerts( const StringList& cacerts );
00073 
00074       // reimplemented from TLSBase
00075       virtual void setClientCert( const std::string& clientKey, const std::string& clientCerts );
00076 
00077     private:
00078       void handshakeStage( const std::string& data );
00079       void setSizes();
00080 
00081       int filetime2int( FILETIME t );
00082 
00083       void validateCert();
00084       void connectionInfos();
00085       void certData();
00086       void setCertinfos();
00087       CredHandle m_credHandle;
00088       CtxtHandle m_context;
00089 
00090       SecPkgContext_StreamSizes m_sizes;
00091 
00092       size_t m_header_max;
00093       size_t m_message_max;
00094       size_t m_trailer_max;
00095 
00096       std::string m_buffer;
00097 
00098       bool m_cleanedup;
00099 
00100       // windows error outputs
00101 //       void print_error( int errorcode, const char* place = 0 );
00102 
00103   };
00104 }
00105 
00106 #endif // HAVE_WINTLS
00107 
00108 #endif // TLSSCHANNEL_H__