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.

266 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: context.h
  7. //
  8. // Contents: Schannel context declarations.
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 09-23-97 jbanes Ported over SGC stuff from NT 4 tree.
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <sha.h>
  18. #include <md5.h>
  19. #include <ssl3.h>
  20. #define SP_CONTEXT_MAGIC *(DWORD *)"!Tcp"
  21. typedef struct _SPContext
  22. {
  23. DWORD Magic; /* tags structure */
  24. DWORD State; /* the current state the connection is in */
  25. DWORD Flags;
  26. /* data for the context that can be used
  27. * to start a new session */
  28. PSessCacheItem RipeZombie; /* cacheable context that is being used */
  29. PSPCredentialGroup pCredGroup;
  30. PSPCredential pActiveClientCred;
  31. LPWSTR pszTarget;
  32. LPWSTR pszCredentialName;
  33. DWORD dwProtocol;
  34. DWORD dwClientEnabledProtocols;
  35. CRED_THUMBPRINT ContextThumbprint;
  36. // Pointers to cipher info used
  37. // during transmission of bulk data.
  38. PCipherInfo pCipherInfo;
  39. PCipherInfo pReadCipherInfo;
  40. PCipherInfo pWriteCipherInfo;
  41. PHashInfo pHashInfo;
  42. PHashInfo pReadHashInfo;
  43. PHashInfo pWriteHashInfo;
  44. PKeyExchangeInfo pKeyExchInfo;
  45. /* functions pointing to the various handlers for this protocol */
  46. SPDecryptMessageFn Decrypt;
  47. SPEncryptMessageFn Encrypt;
  48. SPProtocolHandlerFn ProtocolHandler;
  49. SPDecryptHandlerFn DecryptHandler;
  50. SPInitiateHelloFn InitiateHello;
  51. SPGetHeaderSizeFn GetHeaderSize;
  52. /* session crypto state */
  53. // encryption key size.
  54. DWORD KeySize;
  55. // Encryption states
  56. HCRYPTPROV hReadProv;
  57. HCRYPTPROV hWriteProv;
  58. HCRYPTKEY hReadKey;
  59. HCRYPTKEY hWriteKey;
  60. HCRYPTKEY hPendingReadKey;
  61. HCRYPTKEY hPendingWriteKey;
  62. HCRYPTKEY hReadMAC;
  63. HCRYPTKEY hWriteMAC;
  64. HCRYPTKEY hPendingReadMAC;
  65. HCRYPTKEY hPendingWriteMAC;
  66. // Packet Sequence counters.
  67. DWORD ReadCounter;
  68. DWORD WriteCounter;
  69. DWORD cbConnectionID;
  70. UCHAR pConnectionID[SP_MAX_CONNECTION_ID];
  71. DWORD cbChallenge;
  72. UCHAR pChallenge[SP_MAX_CHALLENGE];
  73. // Save copy of client hello to hash for verification.
  74. DWORD cbClientHello;
  75. PUCHAR pClientHello;
  76. DWORD dwClientHelloProtocol;
  77. // Pending cipher info, used to generate keys
  78. PCipherInfo pPendingCipherInfo;
  79. PHashInfo pPendingHashInfo;
  80. // SSL3 specific items.
  81. UCHAR bAlertLevel; // Used for SSL3 & TLS1 alert messages
  82. UCHAR bAlertNumber;
  83. BOOL fExchKey; // Did we sent a Exchnage key message
  84. BOOL fCertReq; //Did we request a certificatefor server and Should I need to send a cert for client
  85. BOOL fInsufficientCred; //This will be TRUE when the pCred inside
  86. //pContext doesn't match the CR list. from the server.
  87. HCRYPTHASH hMd5Handshake;
  88. HCRYPTHASH hShaHandshake;
  89. PUCHAR pbIssuerList;
  90. DWORD cbIssuerList;
  91. PUCHAR pbEncryptedKey;
  92. DWORD cbEncryptedKey;
  93. PUCHAR pbServerKeyExchange;
  94. DWORD cbServerKeyExchange;
  95. WORD wS3CipherSuiteClient;
  96. WORD wS3CipherSuiteServer;
  97. DWORD dwPendingCipherSuiteIndex;
  98. UCHAR rgbS3CRandom[CB_SSL3_RANDOM];
  99. UCHAR rgbS3SRandom[CB_SSL3_RANDOM];
  100. DWORD cSsl3ClientCertTypes;
  101. DWORD Ssl3ClientCertTypes[SSL3_MAX_CLIENT_CERTS];
  102. // Server Gated Crypto
  103. DWORD dwRequestedCF;
  104. // Allow cert chains for PCT1
  105. BOOL fCertChainsAllowed;
  106. } SPContext, * PSPContext;
  107. typedef struct _SPPackedContext
  108. {
  109. DWORD Magic;
  110. DWORD State;
  111. DWORD Flags;
  112. DWORD dwProtocol;
  113. CRED_THUMBPRINT ContextThumbprint;
  114. DWORD dwCipherInfo;
  115. DWORD dwHashInfo;
  116. DWORD dwKeyExchInfo;
  117. DWORD dwExchStrength;
  118. DWORD ReadCounter;
  119. DWORD WriteCounter;
  120. ULARGE_INTEGER hMasterProv;
  121. ULARGE_INTEGER hReadKey;
  122. ULARGE_INTEGER hWriteKey;
  123. ULARGE_INTEGER hReadMAC;
  124. ULARGE_INTEGER hWriteMAC;
  125. ULARGE_INTEGER hLocator;
  126. DWORD LocatorStatus;
  127. DWORD cbSessionID;
  128. UCHAR SessionID[SP_MAX_SESSION_ID];
  129. } SPPackedContext, *PSPPackedContext;
  130. /* Flags */
  131. #define CONTEXT_FLAG_CLIENT 0x00000001
  132. #define CONTEXT_FLAG_USE_SUPPLIED_CREDS 0x00000080 // Don't search for default credential.
  133. #define CONTEXT_FLAG_MUTUAL_AUTH 0x00000100
  134. #define CONTEXT_FLAG_EXT_ERR 0x00000200 /* Generate error message on error */
  135. #define CONTEXT_FLAG_NO_INCOMPLETE_CRED_MSG 0x00000400 /* don't generate an INCOMPLETE CREDS message */
  136. #define CONTEXT_FLAG_CONNECTION_MODE 0x00001000 /* as opposed to stream mode */
  137. #define CONTEXT_FLAG_NOCACHE 0x00002000 /* do not look things up in the cache */
  138. #define CONTEXT_FLAG_MANUAL_CRED_VALIDATION 0x00004000 // Don't validate server cert.
  139. #define CONTEXT_FLAG_FULL_HANDSHAKE 0x00008000
  140. #define CONTEXT_FLAG_NO_CERT_MAPPING 0x00010000
  141. #define CONTEXT_FLAG_MAPPED 0x40000000
  142. #define CONTEXT_FLAG_SERIALIZED 0x80000000
  143. #ifdef DBG
  144. PSTR DbgGetNameOfCrypto(DWORD x);
  145. #endif
  146. PSPContext SPContextCreate(LPWSTR pszTarget);
  147. BOOL
  148. SPContextClean(PSPContext pContext);
  149. BOOL SPContextDelete(PSPContext pContext);
  150. SP_STATUS
  151. SPContextSetCredentials(
  152. PSPContext pContext,
  153. PSPCredentialGroup pCred);
  154. SP_STATUS
  155. ContextInitCiphersFromCache(
  156. SPContext *pContext);
  157. SP_STATUS
  158. ContextInitCiphers(
  159. SPContext *pContext,
  160. BOOL fRead,
  161. BOOL fWrite);
  162. SP_STATUS
  163. SPContextDoMapping(
  164. PSPContext pContext);
  165. SP_STATUS
  166. RemoveDuplicateIssuers(
  167. PBYTE pbIssuers,
  168. PDWORD pcbIssuers);
  169. SP_STATUS
  170. SPContextGetIssuers(
  171. PSPCredentialGroup pCredGroup);
  172. SP_STATUS
  173. SPPickClientCertificate(
  174. PSPContext pContext,
  175. DWORD dwExchSpec);
  176. SP_STATUS
  177. SPPickServerCertificate(
  178. PSPContext pContext,
  179. DWORD dwExchSpec);
  180. SP_STATUS DetermineClientCSP(PSPContext pContext);
  181. typedef BOOL
  182. (WINAPI * SERIALIZE_LOCATOR_FN)(
  183. HLOCATOR Locator,
  184. HLOCATOR * NewLocator);
  185. SP_STATUS
  186. SPContextSerialize(
  187. PSPContext pContext,
  188. SERIALIZE_LOCATOR_FN LocatorMove,
  189. PBYTE * ppBuffer,
  190. PDWORD pcbBuffer,
  191. BOOL fDestroyKeys);
  192. SP_STATUS
  193. SPContextDeserialize(
  194. PBYTE pbBuffer,
  195. PSPContext *ppContext);
  196. BOOL
  197. LsaContextDelete(PSPContext pContext);