00001 /* SecureSocketServer.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_SecureSocketServer_h 00027 #define OW32_SecureSocketServer_h 00028 00029 #include <OW32/SecureSocket.h> 00030 00031 // Open Win32 namespace 00032 namespace OW32 00033 { 00034 00038 class OW32_LIB_EXPORT CSecureSocketServer : 00039 public CSecureSocket 00040 { 00041 public: 00042 CSecureSocketServer(SOCKET s); 00043 ~CSecureSocketServer(); 00044 00045 virtual bool negotiate(); // server establishing a connection 00046 virtual SECURITY_STATUS handshakeLoop(bool /*fDoInitialRead*/) 00047 { return negotiate() ? SEC_E_OK : GetLastError(); } 00048 00049 // create & store credentials for this server from a certificate context 00050 // see note for createCredentialsFromCertificate 00051 SECURITY_STATUS setServerCertificate(PCCERT_CONTEXT pCertContext, 00052 DWORD dwEnabledProtocols=0); 00053 00054 // Create server credentials from a certificate context 00055 // Basically, if you are accepting a bunch of connections you can 00056 // use this function to manage the Schannel CredHandle for yourself; 00057 // this is faster than calling it each time with a certificate context. 00058 00059 // TODO: think of a neater model - maybe a factory for CSecureSocketServer 00060 // that caches the credentials handle and constructs with it by default? 00061 static SECURITY_STATUS createCredentialsFromCertificate( 00062 CredHandle* phCreds, PCCERT_CONTEXT pCertContext, DWORD dwEnabledProtocols=0) 00063 { 00064 return CSecureSocket::createCredentialsFromCertificate(phCreds, pCertContext, 00065 SECPKG_CRED_INBOUND, dwEnabledProtocols); 00066 } 00067 00068 private: 00069 void disconnectFromClient(); 00070 00071 CSecureSocketServer& operator= (const CSecureSocketServer& ); 00072 CSecureSocketServer(const CSecureSocketServer& ); 00073 }; 00074 00075 } // namespace OW32 00076 00077 #endif // OW32_SecureSocketServer_h