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.

270 lines
7.3 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 fAppProcess;
  84. BOOL fExchKey; // Did we sent a Exchnage key message
  85. BOOL fCertReq; //Did we request a certificatefor server and Should I need to send a cert for client
  86. BOOL fInsufficientCred; //This will be TRUE when the pCred inside
  87. //pContext doesn't match the CR list. from the server.
  88. HCRYPTHASH hMd5Handshake;
  89. HCRYPTHASH hShaHandshake;
  90. PUCHAR pbIssuerList;
  91. DWORD cbIssuerList;
  92. PUCHAR pbEncryptedKey;
  93. DWORD cbEncryptedKey;
  94. PUCHAR pbServerKeyExchange;
  95. DWORD cbServerKeyExchange;
  96. WORD wS3CipherSuiteClient;
  97. WORD wS3CipherSuiteServer;
  98. DWORD dwPendingCipherSuiteIndex;
  99. UCHAR rgbS3CRandom[CB_SSL3_RANDOM];
  100. UCHAR rgbS3SRandom[CB_SSL3_RANDOM];
  101. DWORD cSsl3ClientCertTypes;
  102. DWORD Ssl3ClientCertTypes[SSL3_MAX_CLIENT_CERTS];
  103. // Server Gated Crypto
  104. DWORD dwRequestedCF;
  105. // Allow cert chains for PCT1
  106. BOOL fCertChainsAllowed;
  107. } SPContext, * PSPContext;
  108. typedef struct _SPPackedContext
  109. {
  110. DWORD Magic;
  111. DWORD State;
  112. DWORD Flags;
  113. DWORD dwProtocol;
  114. CRED_THUMBPRINT ContextThumbprint;
  115. DWORD dwCipherInfo;
  116. DWORD dwHashInfo;
  117. DWORD dwKeyExchInfo;
  118. DWORD dwExchStrength;
  119. DWORD ReadCounter;
  120. DWORD WriteCounter;
  121. ULARGE_INTEGER hMasterProv;
  122. ULARGE_INTEGER hReadKey;
  123. ULARGE_INTEGER hWriteKey;
  124. ULARGE_INTEGER hReadMAC;
  125. ULARGE_INTEGER hWriteMAC;
  126. ULARGE_INTEGER hLocator;
  127. DWORD LocatorStatus;
  128. DWORD cbSessionID;
  129. UCHAR SessionID[SP_MAX_SESSION_ID];
  130. } SPPackedContext, *PSPPackedContext;
  131. /* Flags */
  132. #define CONTEXT_FLAG_CLIENT 0x00000001
  133. #define CONTEXT_FLAG_USE_SUPPLIED_CREDS 0x00000080 // Don't search for default credential.
  134. #define CONTEXT_FLAG_MUTUAL_AUTH 0x00000100
  135. #define CONTEXT_FLAG_EXT_ERR 0x00000200 /* Generate error message on error */
  136. #define CONTEXT_FLAG_NO_INCOMPLETE_CRED_MSG 0x00000400 /* don't generate an INCOMPLETE CREDS message */
  137. #define CONTEXT_FLAG_CONNECTION_MODE 0x00001000 /* as opposed to stream mode */
  138. #define CONTEXT_FLAG_NOCACHE 0x00002000 /* do not look things up in the cache */
  139. #define CONTEXT_FLAG_MANUAL_CRED_VALIDATION 0x00004000 // Don't validate server cert.
  140. #define CONTEXT_FLAG_FULL_HANDSHAKE 0x00008000
  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. BOOL FGetServerIssuer(
  173. PBYTE pbIssuer,
  174. DWORD *pdwIssuer);
  175. SP_STATUS
  176. SPPickClientCertificate(
  177. PSPContext pContext,
  178. DWORD dwExchSpec);
  179. SP_STATUS
  180. SPPickServerCertificate(
  181. PSPContext pContext,
  182. DWORD dwExchSpec);
  183. SP_STATUS DetermineClientCSP(PSPContext pContext);
  184. typedef BOOL
  185. (WINAPI * SERIALIZE_LOCATOR_FN)(
  186. HLOCATOR Locator,
  187. HLOCATOR * NewLocator);
  188. SP_STATUS
  189. SPContextSerialize(
  190. PSPContext pContext,
  191. SERIALIZE_LOCATOR_FN LocatorMove,
  192. PBYTE * ppBuffer,
  193. PDWORD pcbBuffer,
  194. BOOL fDestroyKeys);
  195. SP_STATUS
  196. SPContextDeserialize(
  197. PBYTE pbBuffer,
  198. PSPContext *ppContext);
  199. BOOL
  200. LsaContextDelete(PSPContext pContext);