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.

371 lines
8.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ssl3msg.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 8-02-95 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __SSL3MSG_H__
  18. #define __SSL3MSG_H__
  19. #define CB_SSL3_CHANGE_CIPHER_SPEC (sizeof(SWRAP) + 1)
  20. #define CB_SSL3_CHANGE_CIPHER_SPEC_ONLY 1
  21. #define CB_SSL3_FINISHED_MSG (sizeof(FMWIRE))
  22. #define CB_SSL3_FINISHED_MSG_ONLY (sizeof(SHSH) + CB_MD5_DIGEST_LEN + CB_SHA_DIGEST_LEN)
  23. #define CB_SSL3_ALERT (sizeof(SWRAP) +2)
  24. #define CB_SSL3_ALERT_ONLY 2
  25. #define SSL3_CHANGE_CIPHER_MSG { 0x14, 0x03, 0x00, 0x00, 0x01, 0x01 }
  26. #define FSsl3CipherClient() (0 != pContext->wS3CipherSuiteClient)
  27. #define FSsl3CipherServer() (0 != pContext->wS3CipherSuiteServer)
  28. #define FSsl3Cipher(fClient) ((fClient ? pContext->wS3CipherSuiteClient : pContext->wS3CipherSuiteServer))
  29. #define MS24BOF(x) ((UCHAR) ((x >> 16) & 0xFF) )
  30. //#define CbChecksum(f, cb) (cb + (FSsl3Cipher(f) ? pContext->pCheck->cbCheckSum : 0))
  31. #define CHECK_PCT_RET(Ret) if (PCT_ERR_OK != Ret) \
  32. LOG_RESULT(Ret);
  33. #define CHECK_PCT_RET_BREAK(Ret) if(PCT_ERR_OK != Ret) \
  34. { \
  35. LOG_RESULT(Ret); \
  36. break; \
  37. }
  38. typedef struct _OIDPROVMAP
  39. {
  40. LPSTR szOid;
  41. DWORD dwExchSpec;
  42. DWORD dwCertType; // used for SSL 3.0 client auth
  43. } OIDPROVMAP, *POIDPROVMAP;
  44. extern OIDPROVMAP g_CertTypes[];
  45. extern DWORD g_cCertTypes;
  46. typedef struct _shsh //Structure hand shake header
  47. {
  48. UCHAR typHS;
  49. UCHAR bcb24;
  50. UCHAR bcbMSB;
  51. UCHAR bcbLSB;
  52. } SHSH;
  53. typedef struct _swrap
  54. {
  55. UCHAR bCType;
  56. UCHAR bMajor;
  57. UCHAR bMinor;
  58. UCHAR bcbMSBSize;
  59. UCHAR bcbLSBSize;
  60. // UCHAR rgb[];
  61. } SWRAP;
  62. typedef struct _ssh
  63. {
  64. SHSH;
  65. UCHAR bMajor;
  66. UCHAR bMinor;
  67. UCHAR rgbRandom[CB_SSL3_RANDOM];
  68. UCHAR cbSessionId;
  69. UCHAR rgbSessionId[CB_SSL3_SESSION_ID];
  70. UCHAR wCipherSelectedMSB;
  71. UCHAR wCipherSelectedLSB;
  72. UCHAR bCMSelected;
  73. } SSH;
  74. typedef struct _alrt
  75. {
  76. SWRAP;
  77. UCHAR bAlertLevel;
  78. UCHAR bAlertDesc;
  79. } ALRT;
  80. typedef struct _fm
  81. {
  82. UCHAR rgbMD5[CB_MD5_DIGEST_LEN];
  83. UCHAR rgbSHA[CB_SHA_DIGEST_LEN];
  84. } FM; //finished message
  85. typedef struct _fmwire
  86. {
  87. SWRAP;
  88. SHSH;
  89. FM;
  90. } FMWIRE;
  91. typedef struct _clh
  92. {
  93. SHSH;
  94. UCHAR bMajor;
  95. UCHAR bMinor;
  96. UCHAR rgbRandom[CB_SSL3_RANDOM];
  97. UCHAR cbSessionId;
  98. UCHAR rgbSessionId[CB_SSL3_SESSION_ID];
  99. UCHAR bMSBCipher;
  100. UCHAR bLSBCipher;
  101. // short rgbCipher[0]; // ALignment problem, but never used.
  102. //UCHAR bCM;
  103. //UCHAR rgbCM[bCM];
  104. } CLH ; //CLient Hello
  105. typedef struct _cert
  106. {
  107. SHSH;
  108. UCHAR bcbClist24;
  109. UCHAR bcbMSBClist;
  110. UCHAR bcbLSBClist;
  111. UCHAR bcbCert24;
  112. UCHAR bcbMSBCert;
  113. UCHAR bcbLSBCert;
  114. UCHAR rgbCert[];
  115. /* followed by the real cert */
  116. } CERT;
  117. typedef struct _certReq
  118. {
  119. SHSH;
  120. UCHAR bcbCertType; //This value be just 1 byte
  121. UCHAR bCertType; //This will be Only one for quite sometime
  122. UCHAR bcbMSBList;
  123. UCHAR bcbLSBList;
  124. UCHAR rgbIss[];
  125. } CERTREQ;
  126. typedef struct _shwire
  127. {
  128. PUCHAR pcbCipher;
  129. PUCHAR pCiperSpec;
  130. PUCHAR pcbCompM;
  131. PUCHAR pCompM;
  132. PUCHAR pcbCert;
  133. PUCHAR pCert;
  134. PUCHAR pHelloDone;
  135. } SHWIRE ;
  136. SP_STATUS WINAPI
  137. Ssl3DecryptHandler(
  138. PSPContext pContext,
  139. PSPBuffer pCommInput,
  140. PSPBuffer pAppOutput);
  141. SP_STATUS WINAPI
  142. Ssl3GetHeaderSize(
  143. PSPContext pContext,
  144. PSPBuffer pCommInput,
  145. DWORD * pcbHeaderSize);
  146. SP_STATUS WINAPI
  147. GenerateSsl3ClientHello(
  148. PSPContext pContext,
  149. PSPBuffer pOutput);
  150. SP_STATUS WINAPI
  151. GenerateTls1ClientHello(
  152. PSPContext pContext,
  153. PSPBuffer pOutput,
  154. DWORD dwProtocol);
  155. SP_STATUS
  156. Ssl3PackClientHello(PSPContext pContext,
  157. PSsl2_Client_Hello pCanonical,
  158. PSPBuffer pCommOutput);
  159. SP_STATUS Ssl3CliHandleServerHello(PSPContext pContext,
  160. PUCHAR pSrvHello,
  161. DWORD cbMessage,
  162. PSPBuffer pCommOutput);
  163. SP_STATUS Ssl3HandleServerFinish(PSPContext pContext,
  164. PUCHAR pSrvHello );
  165. SP_STATUS Ssl3SrvHandleCMKey(PSPContext pContext,
  166. PUCHAR pCommInput,
  167. DWORD cbMsg,
  168. PSPBuffer pCommOutput);
  169. BOOL FVerifyFinishedMessage(PSPContext pContext, PUCHAR pb, BOOL fClient);
  170. SP_STATUS
  171. ParseAlertMessage
  172. (
  173. PSPContext pContext,
  174. PUCHAR pSrvHello,
  175. DWORD cbMessage
  176. );
  177. SP_STATUS SPAllocOutMemChk(DWORD cbMessage, PSPBuffer pCommOutput);
  178. SP_STATUS
  179. Ssl3SelectCipher (
  180. PSPContext pContext,
  181. WORD wCipher
  182. );
  183. SP_STATUS
  184. Ssl3SelectCipherEx(
  185. PSPContext pContext,
  186. DWORD *pCipherSpecs,
  187. DWORD cCipherSpecs);
  188. void BuildAlertMessage(PBYTE pb, UCHAR bAlertLevel, UCHAR bAlertDesc);
  189. SP_STATUS
  190. Ssl3BuildFinishMessage(
  191. PSPContext pContext,
  192. BYTE *pbMd5Digest,
  193. BYTE *pbSHADigest,
  194. BOOL fClient);
  195. SP_STATUS
  196. Tls1BuildFinishMessage(
  197. PSPContext pContext, // in
  198. PBYTE pbVerifyData, // out
  199. DWORD cbVerifyData, // in
  200. BOOL fClient); // in
  201. SP_STATUS
  202. SPSetWrap(PSPContext pContext, PUCHAR pb, UCHAR bCType, DWORD wT, BOOL fClient, DWORD *pcbMessage);
  203. void SetHandshake(PUCHAR pb, BYTE bHandshake, PUCHAR pbData, DWORD dwSize);
  204. SP_STATUS
  205. UpdateHandshakeHash(
  206. PSPContext pContext,
  207. PUCHAR pb,
  208. DWORD dwcb,
  209. BOOL fInit);
  210. SP_STATUS
  211. SPBuildS3FinalFinish(PSPContext pContext, PSPBuffer pBuffer, BOOL fClient);
  212. SP_STATUS
  213. VerifyCCSAndFinishMsg(PSPContext pContext, PBYTE pbMsg, DWORD cbMessage, BOOL fClient);
  214. SP_STATUS SPAllocOutMem(DWORD cbMessage, PSPBuffer pCommOutput);
  215. SP_STATUS
  216. Ssl3ComputeCertVerifyHashes(
  217. PSPContext pContext, // in
  218. PBYTE pbMD5, // out
  219. PBYTE pbSHA); // out
  220. SP_STATUS
  221. Tls1ComputeCertVerifyHashes(
  222. PSPContext pContext, // in
  223. PBYTE pbMD5, // out
  224. PBYTE pbSHA); // out
  225. void BuildCertificateMessage(PBYTE pb, PBYTE rgbCert, DWORD dwCert);
  226. SP_STATUS
  227. BuildCCSAndFinishMessage(
  228. PSPContext pContext,
  229. PSPBuffer pBuffer,
  230. BOOL fClient);
  231. SP_STATUS
  232. ProcessCertificateMessage(
  233. PSPContext pContext,
  234. BOOL fServer,
  235. DWORD dwCipher,
  236. CERT * pcert,
  237. DWORD dwCert,
  238. Ssl2_Client_Master_Key *pKey);
  239. void Ssl3GetCipherSpec(
  240. short wCipherSuite, // in
  241. PINT pwKeySize, // out
  242. PINT pwMacSize) ; // out
  243. VOID ComputeServerExchangeHashes(
  244. PSPContext pContext,
  245. PBYTE pbServerParams, // in
  246. INT iServerParamsLen, // in
  247. PBYTE pbMd5HashVal, // out
  248. PBYTE pbShaHashVal) ; // out
  249. DWORD Ssl3CiphertextLen(
  250. PSPContext pContext,
  251. DWORD cbMessage,
  252. BOOL fClientIsSender);
  253. DWORD Ssl3PendingCiphertextLen(
  254. PSPContext pContext,
  255. DWORD cbMessage,
  256. BOOL fClientIsSender);
  257. SP_STATUS
  258. UnwrapSsl3Message
  259. (
  260. PSPContext pContext,
  261. PSPBuffer MsgInput
  262. );
  263. DWORD Ssl3CiphertextLen(
  264. PSPContext pContext,
  265. DWORD cbMessage,
  266. BOOL fClientIsSender);
  267. DWORD Ssl3PendingCiphertextLen(
  268. PSPContext pContext,
  269. DWORD cbMessage,
  270. BOOL fClientIsSender);
  271. void SetWrapNoEncrypt(PUCHAR pb, UCHAR bCType, DWORD wT);
  272. SP_STATUS Ssl3HandleCCS(PSPContext pContext,
  273. PUCHAR pb,
  274. DWORD cbMessage);
  275. SP_STATUS
  276. VerifyFinishMsg(PSPContext pContext, PBYTE pbMsg, DWORD cbMessage, BOOL fClient);
  277. BOOL Ssl3ParseClientHello(
  278. PSPContext pContext,
  279. PBYTE pbMessage,
  280. INT iMessageLen,
  281. BOOL fAttemptRestart,
  282. BOOL * pfRestart);
  283. SP_STATUS
  284. SPBuildTlsAlertMessage(
  285. PSPContext pContext,
  286. PSPBuffer pCommOutput);
  287. void
  288. SetTls1Alert(
  289. PSPContext pContext,
  290. BYTE bAlertLevel,
  291. BYTE bAlertNumber);
  292. SP_STATUS
  293. Ssl3CheckForExistingCred(PSPContext pContext);
  294. #endif //__SSL3MSG_H__