Source code of Windows XP (NT5)
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.

255 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. simssl.h
  5. Abstract:
  6. This module contains class declarations/definitions for
  7. CEncryptCtx (some code stolen from internet server)
  8. Revision History:
  9. --*/
  10. #ifndef _SIMSSL_H_
  11. #define _SIMSSL_H_
  12. class CEncryptCtx
  13. {
  14. private:
  15. //
  16. // is this the client side
  17. //
  18. BOOL m_IsClient;
  19. //
  20. // indicates whether we are starting a new session
  21. //
  22. BOOL m_IsNewSSLSession;
  23. //
  24. // should this session be encypted
  25. //
  26. BOOL m_IsEncrypted;
  27. //
  28. // Handle to user's security context for encryption
  29. //
  30. CtxtHandle m_hSealCtxt;
  31. //
  32. // Pointers to cached credential blocks
  33. //
  34. //
  35. // Array of credential handles - Note this comes form the credential cache
  36. // and should not be deleted. m_phCredInUse is the pointer to the
  37. // credential handle that is in use
  38. //
  39. PVOID m_phCreds;
  40. CredHandle* m_phCredInUse;
  41. DWORD m_iCredInUse;
  42. //
  43. // ecryption header and trailer lengths
  44. //
  45. DWORD m_cbSealHeaderSize;
  46. DWORD m_cbSealTrailerSize;
  47. //
  48. // indicates whether we have context handles opened
  49. //
  50. BOOL m_haveSSLCtxtHandle;
  51. //
  52. // Have we been authenticated, if so did we use the
  53. // anonymous token
  54. //
  55. BOOL m_IsAuthenticated;
  56. //
  57. // Have we been authenticated, if so did we use the
  58. // anonymous token
  59. //
  60. static BOOL m_IsSecureCapable;
  61. //
  62. // static variables used by all class instances
  63. //
  64. static char szServiceName[16];
  65. static char szLsaPrefix[16];
  66. //
  67. // hSecurity - NULL when security.dll/secur32.dll is not loaded
  68. //
  69. static HINSTANCE m_hSecurity;
  70. //
  71. // hLsa - NULL for Win95, set for NT
  72. //
  73. static HINSTANCE m_hLsa;
  74. //
  75. // internal routine to implement public Converse
  76. //
  77. DWORD EncryptConverse(
  78. IN PVOID InBuffer,
  79. IN DWORD InBufferSize,
  80. OUT LPBYTE OutBuffer,
  81. OUT PDWORD OutBufferSize,
  82. OUT PBOOL MoreBlobsExpected,
  83. IN CredHandle* pCredHandle
  84. );
  85. public:
  86. CEncryptCtx( BOOL IsClient = FALSE );
  87. ~CEncryptCtx();
  88. //
  89. // routines used to initialize and terminate use of this class
  90. //
  91. static BOOL WINAPI Initialize( LPSTR pszServiceName,
  92. LPSTR pszLsaPrefix );
  93. static VOID WINAPI Terminate( VOID );
  94. //
  95. // routine to set the magic bits required by the IIS Admin tool
  96. //
  97. static void WINAPI GetAdminInfoEncryptCaps( PDWORD pdwEncCaps );
  98. //
  99. // returns whether sspi packages and credentials have been installed
  100. //
  101. static BOOL IsSecureCapable( void ) { return m_IsSecureCapable; }
  102. //
  103. // returns whether session is encrypted or not
  104. //
  105. BOOL IsEncrypted( void ) { return m_IsEncrypted; }
  106. //
  107. // returns whether session has successfully authenticated
  108. //
  109. BOOL IsAuthenticated( void ) { return m_IsAuthenticated; }
  110. //
  111. // Encryption routines
  112. //
  113. BOOL WINAPI SealMessage(
  114. IN LPBYTE Message,
  115. IN DWORD cbMessage,
  116. OUT LPBYTE pbuffOut,
  117. OUT DWORD *pcbBuffOut
  118. );
  119. BOOL WINAPI UnsealMessage(
  120. IN LPBYTE Message,
  121. IN DWORD cbMessage,
  122. OUT LPBYTE *DecryptedMessage,
  123. OUT PDWORD DecryptedMessageSize,
  124. OUT PDWORD ExpectedMessageSize,
  125. OUT LPBYTE *NextSealMessage = NULL
  126. );
  127. //
  128. // SSL specific routines. This is used for processing SSL negotiation
  129. // packets.
  130. //
  131. DWORD WINAPI Converse(
  132. IN PVOID InBuffer,
  133. IN DWORD InBufferSize,
  134. OUT LPBYTE OutBuffer,
  135. OUT PDWORD OutBufferSize,
  136. OUT PBOOL MoreBlobsExpected,
  137. IN LPSTR LocalIpAddr = "127.0.0.1"
  138. );
  139. //
  140. // resets the user name
  141. //
  142. void WINAPI Reset( void );
  143. //
  144. // returns the size of the encryption header for this session
  145. //
  146. DWORD GetSealHeaderSize( void )
  147. { return m_haveSSLCtxtHandle ? m_cbSealHeaderSize : 0 ; }
  148. //
  149. // returns the size of the encryption trailer for this session
  150. //
  151. DWORD GetSealTrailerSize( void )
  152. { return m_haveSSLCtxtHandle ? m_cbSealTrailerSize : 0 ; }
  153. //
  154. // decrypts read buffer, concatenating all decrypted data at the
  155. // head of the buffer.
  156. //
  157. DWORD WINAPI DecryptInputBuffer(
  158. IN LPBYTE pBuffer,
  159. IN DWORD cbInBuffer,
  160. OUT DWORD* pcbOutBuffer,
  161. OUT DWORD* pcbParsable,
  162. OUT DWORD* pcbExpected
  163. );
  164. //
  165. // verifies the intended host name matches the name contained in the cert
  166. // This function, checks a given hostname against the current certificate
  167. // stored in an active SSPI Context Handle. If the certificate containts
  168. // a common name, and it matches the passed in hostname, this function
  169. // will return TRUE.
  170. //
  171. BOOL CheckCertificateCommonName(
  172. IN LPSTR pszHostName
  173. );
  174. //
  175. // verifies the ccertificate has not expired
  176. // returns TRUE if the cert is valid
  177. //
  178. BOOL CheckCertificateExpired(
  179. void
  180. );
  181. }; // CSslCtx
  182. //
  183. // blkcred.cpp
  184. //
  185. #endif // _SECURITY_H_