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.

326 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: msgs.h
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 8-02-95 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __SSL2MSG_H__
  18. #define __SSL2MSG_H__
  19. typedef struct _Ssl2_Cipher_Tuple {
  20. UCHAR C1;
  21. UCHAR C2;
  22. UCHAR C3;
  23. } Ssl2_Cipher_Tuple, * PSsl2_Cipher_Tuple;
  24. ///////////////////////////////////////////////////////////////////
  25. //
  26. // Useful Macros
  27. //
  28. ///////////////////////////////////////////////////////////////////
  29. #define LSBOF(x) ((UCHAR) ((x) & 0xFF))
  30. #define MSBOF(x) ((UCHAR) (((x) >> 8) & 0xFF) )
  31. #define COMBINEBYTES(Msb, Lsb) ((DWORD) (((DWORD) (Msb) << 8) | (DWORD) (Lsb)))
  32. ///////////////////////////////////////////////////////////////////
  33. //
  34. // Message Constants
  35. //
  36. ///////////////////////////////////////////////////////////////////
  37. #define SSL2_CLIENT_VERSION 0x0002
  38. #define SSL2_SERVER_VERSION 0x0002
  39. #define SSL2_CLIENT_VERSION_MSB 0x00
  40. #define SSL2_CLIENT_VERSION_LSB 0x02
  41. #define SSL2_SERVER_VERSION_MSB 0x00
  42. #define SSL2_SERVER_VERSION_LSB 0x02
  43. #ifdef DO_PCT_COMPAT
  44. #define PCT_COMPAT_VERSION_MSB 0x83
  45. #define PCT_COMPAT_VERSION_LSB 0x01
  46. #endif
  47. #define SSL2_MT_ERROR 0
  48. #define SSL2_MT_CLIENT_HELLO 1
  49. #define SSL2_MT_CLIENT_MASTER_KEY 2
  50. #define SSL2_MT_CLIENT_FINISHED_V2 3
  51. #define SSL2_MT_SERVER_HELLO 4
  52. #define SSL2_MT_SERVER_VERIFY 5
  53. #define SSL2_MT_SERVER_FINISHED_V2 6
  54. #define SSL2_MT_REQUEST_CERTIFICATE 7
  55. #define SSL2_MT_CLIENT_CERTIFICATE 8
  56. #define SSL2_MT_CLIENT_DH_KEY 9
  57. #define SSL2_MT_CLIENT_SESSION_KEY 10
  58. #define SSL2_MT_CLIENT_FINISHED 11
  59. #define SSL2_MT_SERVER_FINISHED 12
  60. #define SSL_PE_NO_CIPHER 0x0001
  61. #define SSL_PE_NO_CERTIFICATE 0x0002
  62. #define SSL_PE_BAD_CERTIFICATE 0x0004
  63. #define SSL_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
  64. #define SSL_CT_X509_CERTIFICATE 0x01
  65. #define SSL_CT_PKCS7_CERTIFICATE 0x02
  66. #if DBG
  67. #define SSL_CT_DEBUG_CERT 0x80
  68. #endif
  69. #define SSL2_MAX_CHALLENGE_LEN 32 /* max accepted challenge size */
  70. #define SSL2_CHALLENGE_SIZE 16 /* default generated challenge size */
  71. #define SSL2_SESSION_ID_LEN 16
  72. #define SSL2_GEN_CONNECTION_ID_LEN 16 /* Dont change this, netscape requires 16 byte
  73. * id's */
  74. #define SSL2_MAX_CONNECTION_ID_LEN 32
  75. #define SSL3_SESSION_ID_LEN 32
  76. #define SSL2_MAC_LENGTH 16
  77. #define SSL2_MASTER_KEY_SIZE 16
  78. #define SSL2_MAX_KEY_ARGS 8
  79. #define SSL2_MAX_MESSAGE_LENGTH 32768
  80. #define MAX_UNI_CIPHERS 64
  81. #define SSL_MKFAST(a, b, c) (DWORD)(((a)<<16) | ((b)<<8) | (c))
  82. #define SSL_MKSLOW(a) (UCHAR)((a>>16)& 0xff), (UCHAR)((a>>8)& 0xff), (UCHAR)((a)& 0xff)
  83. #define SSL_RSA_WITH_RC4_128_MD5 SSL_MKFAST(0x00, 0x00, 0x04)
  84. #define SSL_RSA_EXPORT_WITH_RC4_40_MD5 SSL_MKFAST(0x00, 0x00, 0x03)
  85. #define SSL_CK_RC4_128_WITH_MD5 SSL_MKFAST(0x01, 0x00, 0x80)
  86. #define SSL_CK_RC4_128_EXPORT40_WITH_MD5 SSL_MKFAST(0x02, 0x00, 0x80)
  87. #define SSL_CK_RC2_128_CBC_WITH_MD5 SSL_MKFAST(0x03, 0x00, 0x80)
  88. #define SSL_CK_RC2_128_CBC_EXPORT40_WITH_MD5 SSL_MKFAST(0x04, 0x00, 0x80)
  89. #define SSL_CK_IDEA_128_CBC_WITH_MD5 SSL_MKFAST(0x05, 0x00, 0x80)
  90. #define SSL_CK_DES_64_CBC_WITH_MD5 SSL_MKFAST(0x06, 0x00, 0x40)
  91. #define SSL_CK_DES_192_EDE3_CBC_WITH_MD5 SSL_MKFAST(0x07, 0x00, 0xC0)
  92. #define SSL_CK_NULL_WITH_MD5 SSL_MKFAST(0x00, 0x00, 0x00)
  93. #define SSL_CK_DES_64_CBC_WITH_SHA SSL_MKFAST(0x06, 0x01, 0x40)
  94. #define SSL_CK_DES_192_EDE3_WITH_SHA SSL_MKFAST(0x07, 0x01, 0xC0)
  95. #define SSL_CK_RC4_128_FINANCE64_WITH_MD5 SSL_MKFAST(0x08, 0x00, 0x80)
  96. #ifdef ENABLE_NONE_CIPHER
  97. #define SSL_CK_NONE SSL_MKFAST(0x09, 0x00, 0x00)
  98. #endif
  99. #define SSL_KEA_RSA {(UCHAR) 0x10, (UCHAR) 0x00, (UCHAR) 0x00}
  100. #define SSL_KEA_RSA_TOKEN_WITH_DES {(UCHAR) 0x10, (UCHAR) 0x01, (UCHAR) 0x00}
  101. #define SSL_KEA_RSA_TOKEN_WITH_DES_EDE3 {(UCHAR) 0x10, (UCHAR) 0x01, (UCHAR) 0x01}
  102. #define SSL_KEA_RSA_TOKEN_WITH_RC4 {(UCHAR) 0x10, (UCHAR) 0x01, (UCHAR) 0x02}
  103. #define SSL_KEA_DH {(UCHAR) 0x11, (UCHAR) 0x00, (UCHAR) 0x00}
  104. #define SSL_KEA_DH_TOKEN_WITH_DES {(UCHAR) 0x11, (UCHAR) 0x01, (UCHAR) 0x00}
  105. #define SSL_KEA_DH_TOKEN_WITH_DES_EDE3 {(UCHAR) 0x11, (UCHAR) 0x01, (UCHAR) 0x01}
  106. #define SSL_KEA_DH_ANON {(UCHAR) 0x12, (UCHAR) 0x00, (UCHAR) 0x00}
  107. #define CRYPTO_RC4_128 0x00010080
  108. #define CRYPTO_RC4_40 0x00020080
  109. #define CRYPTO_RC2_128 0x00030080
  110. #define CRYPTO_RC2_40 0x00040080
  111. #define CRYPTO_IDEA_128 0x00050080
  112. #define CRYPTO_NULL 0x00000000
  113. #define CRYPTO_DES_64 0x00060040
  114. #define CRYPTO_3DES_192 0x000700C0
  115. extern CertTypeMap aSsl2CertEncodingPref[];
  116. extern DWORD cSsl2CertEncodingPref;
  117. typedef DWORD Ssl2_Cipher_Kind;
  118. //typedef struct _Ssl2CipherMap {
  119. // Ssl2_Cipher_Kind Kind;
  120. // ALG_ID aiHash;
  121. // ALG_ID aiCipher;
  122. // DWORD dwStrength;
  123. // ExchSpec KeyExch;
  124. // ALG_ID aiKeyAlg;
  125. //} Ssl2CipherMap, *PSsl2CipherMap;
  126. typedef struct _SSL2_MESSAGE_HEADER {
  127. UCHAR Byte0;
  128. UCHAR Byte1;
  129. } SSL2_MESSAGE_HEADER, * PSSL2_MESSAGE_HEADER;
  130. typedef struct _SSL2_MESSAGE_HEADER_EX {
  131. UCHAR Byte0;
  132. UCHAR Byte1;
  133. UCHAR PaddingSize;
  134. } SSL2_MESSAGE_HEADER_EX, * PSSL2_MESSAGE_HEADER_EX;
  135. typedef struct _SSL2_ERROR {
  136. SSL2_MESSAGE_HEADER Header;
  137. UCHAR MessageId;
  138. UCHAR ErrorMsb;
  139. UCHAR ErrorLsb;
  140. } SSL2_ERROR, * PSSL2_ERROR;
  141. typedef struct _SSL2_CLIENT_HELLO {
  142. SSL2_MESSAGE_HEADER Header;
  143. UCHAR MessageId;
  144. UCHAR VersionMsb;
  145. UCHAR VersionLsb;
  146. UCHAR CipherSpecsLenMsb;
  147. UCHAR CipherSpecsLenLsb;
  148. UCHAR SessionIdLenMsb;
  149. UCHAR SessionIdLenLsb;
  150. UCHAR ChallengeLenMsb;
  151. UCHAR ChallengeLenLsb;
  152. UCHAR VariantData[1];
  153. } SSL2_CLIENT_HELLO, * PSSL2_CLIENT_HELLO;
  154. typedef struct _SSL2_SERVER_HELLO {
  155. SSL2_MESSAGE_HEADER Header;
  156. UCHAR MessageId;
  157. UCHAR SessionIdHit;
  158. UCHAR CertificateType;
  159. UCHAR ServerVersionMsb;
  160. UCHAR ServerVersionLsb;
  161. UCHAR CertificateLenMsb;
  162. UCHAR CertificateLenLsb;
  163. UCHAR CipherSpecsLenMsb;
  164. UCHAR CipherSpecsLenLsb;
  165. UCHAR ConnectionIdLenMsb;
  166. UCHAR ConnectionIdLenLsb;
  167. UCHAR VariantData[1];
  168. } SSL2_SERVER_HELLO, * PSSL2_SERVER_HELLO;
  169. typedef struct _SSL2_CLIENT_MASTER_KEY {
  170. SSL2_MESSAGE_HEADER Header;
  171. UCHAR MessageId;
  172. Ssl2_Cipher_Tuple CipherKind;
  173. UCHAR ClearKeyLenMsb;
  174. UCHAR ClearKeyLenLsb;
  175. UCHAR EncryptedKeyLenMsb;
  176. UCHAR EncryptedKeyLenLsb;
  177. UCHAR KeyArgLenMsb;
  178. UCHAR KeyArgLenLsb;
  179. UCHAR VariantData[1];
  180. } SSL2_CLIENT_MASTER_KEY, * PSSL2_CLIENT_MASTER_KEY;
  181. typedef struct _SSL2_SERVER_VERIFY {
  182. UCHAR MessageId;
  183. UCHAR ChallengeData[SSL2_MAX_CHALLENGE_LEN];
  184. } SSL2_SERVER_VERIFY, * PSSL2_SERVER_VERIFY;
  185. typedef struct _SSL2_CLIENT_FINISHED {
  186. UCHAR MessageId;
  187. UCHAR ConnectionID[SSL2_MAX_CONNECTION_ID_LEN];
  188. } SSL2_CLIENT_FINISHED, * PSSL2_CLIENT_FINISHED;
  189. typedef struct _SSL2_SERVER_FINISHED {
  190. UCHAR MessageId;
  191. UCHAR SessionID[SSL2_SESSION_ID_LEN];
  192. } SSL2_SERVER_FINISHED, * PSSL2_SERVER_FINISHED;
  193. ////////////////////////////////////////////////////
  194. //
  195. // Expanded Form Messages:
  196. //
  197. ////////////////////////////////////////////////////
  198. /* Rules for buffer in expanded form */
  199. /* Only things which are going to be allocated
  200. * anyway, or are created statically are not created
  201. * as arrays */
  202. typedef DWORD CipherSpec;
  203. typedef DWORD * PCipherSpec;
  204. typedef struct _Ssl2_Client_Hello {
  205. DWORD dwVer;
  206. DWORD cCipherSpecs;
  207. DWORD cbSessionID;
  208. DWORD cbChallenge;
  209. UCHAR SessionID[SSL3_SESSION_ID_LEN]; //NOTE: changed to 32 bytes long....
  210. UCHAR Challenge[SSL2_MAX_CHALLENGE_LEN];
  211. Ssl2_Cipher_Kind CipherSpecs[MAX_UNI_CIPHERS]; /* points to static array */
  212. } Ssl2_Client_Hello, * PSsl2_Client_Hello;
  213. typedef struct _Ssl2_Server_Hello {
  214. DWORD SessionIdHit;
  215. DWORD CertificateType;
  216. DWORD cbCertificate;
  217. DWORD cCipherSpecs;
  218. DWORD cbConnectionID;
  219. UCHAR ConnectionID[SSL2_MAX_CONNECTION_ID_LEN];
  220. PUCHAR pCertificate; /* points to pre-created cert */
  221. Ssl2_Cipher_Kind * pCipherSpecs; /* points to static array */
  222. } Ssl2_Server_Hello, * PSsl2_Server_Hello;
  223. typedef struct _Ssl2_Client_Master_Key {
  224. DWORD ClearKeyLen;
  225. DWORD EncryptedKeyLen;
  226. DWORD KeyArgLen;
  227. Ssl2_Cipher_Kind CipherKind;
  228. UCHAR ClearKey[SSL2_MASTER_KEY_SIZE];
  229. UCHAR * pbEncryptedKey;
  230. UCHAR KeyArg[SSL2_MASTER_KEY_SIZE];
  231. } Ssl2_Client_Master_Key, * PSsl2_Client_Master_Key;
  232. ///////////////////////////////////////////////////
  233. //
  234. // Pickling Prototypes
  235. //
  236. ///////////////////////////////////////////////////
  237. SP_STATUS
  238. Ssl2PackClientHello(
  239. PSsl2_Client_Hello pCanonical,
  240. PSPBuffer pCommOutput);
  241. SP_STATUS
  242. Ssl2UnpackClientHello(
  243. PSPBuffer pInput,
  244. PSsl2_Client_Hello * ppClient);
  245. SP_STATUS
  246. Ssl2PackServerHello(
  247. PSsl2_Server_Hello pCanonical,
  248. PSPBuffer pCommOutput);
  249. SP_STATUS
  250. Ssl2UnpackServerHello(
  251. PSPBuffer pInput,
  252. PSsl2_Server_Hello * ppServer);
  253. SP_STATUS
  254. Ssl2PackClientMasterKey(
  255. PSsl2_Client_Master_Key pCanonical,
  256. PSPBuffer pCommOutput);
  257. SP_STATUS
  258. Ssl2UnpackClientMasterKey(
  259. PSPBuffer pInput,
  260. PSsl2_Client_Master_Key * ppClient);
  261. #endif /* __SSL2MSG_H__ */