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.

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