00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00054 virtual SECURITY_STATUS handshakeLoop(bool fDoInitialRead)=0;
00055
00056 public:
00057 CSecureSocket();
00058 CSecureSocket(SOCKET s);
00059 ~CSecureSocket();
00060
00061
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 }
00100
00101 #endif // OW32_SecureSocket_h