Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ssocket.hxx
  5. Abstract:
  6. Contains types, manifests, prototypes for Internet Secure Socket Class
  7. (ICSecureSocket) functions and methods (in common\ssocket.cxx)
  8. Author:
  9. Richard L Firth (rfirth) 08-Apr-1997
  10. Revision History:
  11. 08-Apr-1997 rfirth
  12. Created (from ixport.hxx)
  13. --*/
  14. #define SECURITY_WIN32
  15. #include <sspi.h>
  16. #include <issperr.h>
  17. #include <buffer.hxx>
  18. #include <winerror.h>
  19. //
  20. // forward references
  21. //
  22. class CFsm_SecureConnect;
  23. class CFsm_SecureHandshake;
  24. class CFsm_SecureNegotiate;
  25. class CFsm_NegotiateLoop;
  26. class CFsm_SecureSend;
  27. class CFsm_SecureReceive;
  28. //
  29. // classes
  30. //
  31. class ICSecureSocket : public ICSocket {
  32. private:
  33. CtxtHandle m_hContext;
  34. DWORD m_dwProviderIndex;
  35. LPSTR m_lpszHostName;
  36. DBLBUFFER * m_pdblbufBuffer;
  37. DWORD m_dwErrorFlags;
  38. SECURITY_CACHE_LIST_ENTRY *m_pSecurityInfo;
  39. SECURITY_CACHE_LIST_ENTRY **m_ppSecurityInfo;
  40. #if INET_DEBUG
  41. #define SECURE_SOCKET_SIGNATURE 0x534c5353 // "SSLS"
  42. #define SIGN_SECURE_SOCKET() \
  43. m_Signature = SECURE_SOCKET_SIGNATURE
  44. #define CHECK_SECURE_SOCKET() \
  45. INET_ASSERT(m_Signature == SECURE_SOCKET_SIGNATURE)
  46. #else
  47. #define SIGN_SECURE_SOCKET() \
  48. /* NOTHING */
  49. #define CHECK_SECURE_SOCKET() \
  50. /* NOTHING */
  51. #endif
  52. VOID SetNonSecure(VOID)
  53. {
  54. if(m_pSecurityInfo)
  55. {
  56. m_pSecurityInfo->ClearSecureFlags(SECURITY_FLAG_SECURE);
  57. }
  58. }
  59. VOID SetSecure(VOID)
  60. {
  61. SetSecureFlags(SECURITY_FLAG_SECURE);
  62. }
  63. DWORD
  64. EncryptData(
  65. IN LPVOID lpBuffer,
  66. IN DWORD dwInBufferLen,
  67. OUT LPVOID * lplpBuffer,
  68. OUT LPDWORD lpdwOutBufferLen,
  69. OUT LPDWORD lpdwInBufferBytesEncrypted
  70. );
  71. DWORD
  72. DecryptData(
  73. OUT DWORD * lpdwBytesNeeded,
  74. OUT LPBYTE lpOutBuffer,
  75. IN OUT LPDWORD lpdwOutBufferLeft,
  76. IN OUT LPDWORD lpdwOutBufferReceived,
  77. IN OUT LPDWORD lpdwOutBufferBytesRead
  78. );
  79. VOID
  80. TerminateSecConnection(
  81. VOID
  82. );
  83. BOOL
  84. IsValidCacheEntry();
  85. DWORD ReVerifyTrust(
  86. DWORD dwRecheckFlag // either SECURITY_FLAG_CHECK_EXPIRATION or
  87. // SECURITY_FLAG_CHECK_REVOCATION
  88. );
  89. public:
  90. ICSecureSocket(DWORD dwErrorFlags = 0, INTERNET_SCHEME tScheme = INTERNET_SCHEME_DEFAULT);
  91. virtual ~ICSecureSocket(VOID);
  92. DWORD
  93. Connect(
  94. IN LONG Timeout,
  95. IN INT Retries,
  96. IN DWORD dwFlags
  97. );
  98. DWORD
  99. Connect_Fsm(
  100. IN CFsm_SecureConnect * Fsm
  101. );
  102. DWORD
  103. SecureHandshake_Fsm(
  104. IN CFsm_SecureHandshake * Fsm
  105. );
  106. DWORD
  107. SecureNegotiate_Fsm(
  108. IN CFsm_SecureNegotiate * Fsm
  109. );
  110. DWORD
  111. NegotiateLoop_Fsm(
  112. IN CFsm_NegotiateLoop * Fsm
  113. );
  114. DWORD
  115. NegotiateSecConnection(
  116. IN DWORD dwFlags,
  117. OUT LPBOOL lpbAttemptReconnect
  118. );
  119. DWORD
  120. SSPINegotiateLoop(
  121. OUT DBLBUFFER * pDoubleBuffer,
  122. IN DWORD dwFlags,
  123. IN CredHandle hCreds,
  124. IN BOOL fDoInitialRead,
  125. IN BOOL bDoingClientAuth
  126. );
  127. DWORD
  128. Disconnect(
  129. IN DWORD dwFlags
  130. );
  131. DWORD
  132. Send(
  133. IN LPVOID lpBuffer,
  134. IN DWORD dwBufferLength,
  135. IN DWORD dwFlags
  136. );
  137. DWORD
  138. Send_Fsm(
  139. IN CFsm_SecureSend * Fsm
  140. );
  141. DWORD
  142. Receive(
  143. IN OUT LPVOID* lplpBuffer,
  144. IN OUT LPDWORD lpdwBufferLength,
  145. IN OUT LPDWORD lpdwBufferRemaining,
  146. IN OUT LPDWORD lpdwBytesReceived,
  147. IN DWORD dwExtraSpace,
  148. IN DWORD dwFlags,
  149. OUT LPBOOL lpbEof
  150. );
  151. DWORD
  152. Receive_Fsm(
  153. IN CFsm_SecureReceive * Fsm
  154. );
  155. DWORD
  156. SecureHandshakeWithServer(
  157. IN DWORD dwFlags,
  158. OUT LPBOOL lpfAttemptReconnect
  159. );
  160. DWORD
  161. VerifyTrust(
  162. VOID
  163. );
  164. SECURITY_CACHE_LIST_ENTRY * GetSecurityEntry() {
  165. if (m_pSecurityInfo != NULL) {
  166. m_pSecurityInfo->AddRef();
  167. return m_pSecurityInfo;
  168. }
  169. return NULL;
  170. }
  171. VOID SetSecurityEntry(SECURITY_CACHE_LIST_ENTRY **entry) {
  172. if (entry != NULL && *entry) {
  173. (*entry)->AddRef();
  174. }
  175. if (m_pSecurityInfo != NULL) {
  176. m_pSecurityInfo->Release();
  177. }
  178. m_pSecurityInfo = entry ? *entry : NULL;
  179. m_ppSecurityInfo = entry;
  180. }
  181. DWORD
  182. SetHostName(
  183. IN LPSTR lpszHostName
  184. );
  185. LPSTR GetHostName(VOID) const {
  186. INET_ASSERT(IsSecure());
  187. INET_ASSERT(m_lpszHostName != NULL);
  188. return m_lpszHostName;
  189. }
  190. //
  191. // GetCertChainList (and)
  192. // SetCertChainList -
  193. // Sets and Gets Client Authentication Cert Chains.
  194. //
  195. CERT_CONTEXT_ARRAY* GetCertContextArray(VOID) {
  196. if(m_pSecurityInfo)
  197. {
  198. return m_pSecurityInfo->GetCertContextArray();
  199. }
  200. return NULL;
  201. }
  202. VOID SetCertContextArray(CERT_CONTEXT_ARRAY* pNewCertContextArray) {
  203. if(m_pSecurityInfo)
  204. {
  205. m_pSecurityInfo->SetCertContextArray(pNewCertContextArray);
  206. }
  207. }
  208. //
  209. // GetSecureFlags AND SetSecureFlags AND GetCertInfo
  210. // Allows setting and getting of a bitmask which
  211. // stores various data bits on current socket connection.
  212. //
  213. DWORD GetSecurityInfo(LPINTERNET_SECURITY_INFO pInfo) {
  214. if(m_pSecurityInfo)
  215. {
  216. m_pSecurityInfo->CopyOut(*pInfo);
  217. return ERROR_SUCCESS;
  218. }
  219. else
  220. {
  221. return ERROR_INTERNET_INTERNAL_ERROR;
  222. }
  223. }
  224. VOID SetSecureFlags(DWORD Flags) {
  225. if(m_pSecurityInfo)
  226. {
  227. m_pSecurityInfo->SetSecureFlags(Flags);
  228. }
  229. }
  230. DWORD GetSecureFlags(VOID) {
  231. if(m_pSecurityInfo)
  232. {
  233. return m_pSecurityInfo->GetSecureFlags();
  234. }
  235. return 0;
  236. }
  237. DWORD GetProviderIndex(VOID) const {
  238. INET_ASSERT(IsSecure());
  239. return m_dwProviderIndex;
  240. }
  241. VOID SetProviderIndex(DWORD dwIndex) {
  242. INET_ASSERT(IsSecure());
  243. m_dwProviderIndex = dwIndex;
  244. }
  245. BOOL MatchTunnelSemantics(DWORD dwFlags, LPSTR pszHostName = NULL) {
  246. return (((m_dwFlags & SF_TUNNEL) == (dwFlags & SF_TUNNEL)) ? TRUE : FALSE) &&
  247. (!pszHostName || 0 == strcmp(m_lpszHostName, pszHostName));
  248. }
  249. };