Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

SecureSocket.h

Go to the documentation of this file.
00001 /*  SecureSocket.h - SSL communication through the Schannel API
00002     Copyright (C) 2001-2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
00020 */
00021 
00026 #ifndef OW32_SecureSocket_h
00027 #define OW32_SecureSocket_h
00028 
00029 #include <OW32/Socket.h>
00030 #include <OW32/auto_array_ptr.h>
00031 #include <OW32/OW32Libs.h>
00032 
00033 // Open Win32 namespace
00034 namespace OW32
00035 {
00036 
00037 #ifdef _MSC_VER
00038 #pragma warning(disable: 4251)
00039 #endif
00040 
00044 class OW32_LIB_EXPORT CSecureSocket : 
00045     public CSocket
00046 {
00047 private:
00048     CSecureSocket(const CSecureSocket& );
00049     CSecureSocket& operator= (const CSecureSocket& );
00050     void initialise();
00051 
00052 protected:
00053     // The handshake loop
00054     virtual SECURITY_STATUS handshakeLoop(bool fDoInitialRead)=0;
00055 
00056 public:
00057     CSecureSocket();
00058     CSecureSocket(SOCKET s);
00059     ~CSecureSocket();
00060 
00061     // Handshake, authentication, that sort of thing.
00062     virtual bool negotiate()=0;
00063 
00064     virtual int send(const char* buf, int len);
00065     virtual int recv(char* buf, int len);
00066 
00067     void setCredentials(CredHandle hCreds) { m_hCreds = hCreds; }
00068     void setRequireClientAuth(bool bRequireClientAuth) { m_bRequireClientAuth = bRequireClientAuth; }
00069 
00070     static SECURITY_STATUS createCredentialsFromCertificate(CredHandle* phCreds, PCCERT_CONTEXT pCertContext,
00071             DWORD dwDirection, DWORD dwEnabledProtocols = 0);
00072 
00073     SECURITY_STATUS getRemoteCert(PCCERT_CONTEXT* pRemoteCertContext);
00074 
00075     void freeCredentials();
00076 
00077 protected:
00078     SECURITY_STATUS querySizes();
00079 
00080     SecPkgContext_StreamSizes m_Sizes;
00081     CtxtHandle m_hContext;
00082     CredHandle m_hCreds;
00083 
00084     auto_array_ptr<char> m_Extra;
00085     int m_ExtraCount;
00086     int m_ExtraDecrypted,m_ExtraDecryptedPos;
00087 
00088     auto_array_ptr<char> m_SendBuf;
00089 
00090     bool m_bRequireClientAuth;
00091     bool m_bHandshakeDone;
00092     bool m_ownCredentials;
00093 };
00094 
00095 #ifdef _MSC_VER
00096 #pragma warning(default: 4251)
00097 #endif
00098 
00099 } // namespace OW32
00100 
00101 #endif // OW32_SecureSocket_h

Generated on Sun Jun 5 01:29:18 2005 for OW32 by  doxygen 1.3.9.1