ssl2.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* ssl/ssl2.h */
  2. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  3. * All rights reserved.
  4. *
  5. * This package is an SSL implementation written
  6. * by Eric Young (eay@cryptsoft.com).
  7. * The implementation was written so as to conform with Netscapes SSL.
  8. *
  9. * This library is free for commercial and non-commercial use as long as
  10. * the following conditions are aheared to. The following conditions
  11. * apply to all code found in this distribution, be it the RC4, RSA,
  12. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  13. * included with this distribution is covered by the same copyright terms
  14. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  15. *
  16. * Copyright remains Eric Young's, and as such any Copyright notices in
  17. * the code are not to be removed.
  18. * If this package is used in a product, Eric Young should be given attribution
  19. * as the author of the parts of the library used.
  20. * This can be in the form of a textual message at program startup or
  21. * in documentation (online or textual) provided with the package.
  22. *
  23. * Redistribution and use in source and binary forms, with or without
  24. * modification, are permitted provided that the following conditions
  25. * are met:
  26. * 1. Redistributions of source code must retain the copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * 2. Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in the
  30. * documentation and/or other materials provided with the distribution.
  31. * 3. All advertising materials mentioning features or use of this software
  32. * must display the following acknowledgement:
  33. * "This product includes cryptographic software written by
  34. * Eric Young (eay@cryptsoft.com)"
  35. * The word 'cryptographic' can be left out if the rouines from the library
  36. * being used are not cryptographic related :-).
  37. * 4. If you include any Windows specific code (or a derivative thereof) from
  38. * the apps directory (application code) you must include an acknowledgement:
  39. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  42. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  45. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  46. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  47. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  49. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  51. * SUCH DAMAGE.
  52. *
  53. * The licence and distribution terms for any publically available version or
  54. * derivative of this code cannot be changed. i.e. this code cannot simply be
  55. * copied and put under another distribution licence
  56. * [including the GNU Public Licence.]
  57. */
  58. #ifndef HEADER_SSL2_H
  59. #define HEADER_SSL2_H
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. /* Protocol Version Codes */
  64. #define SSL2_VERSION 0x0002
  65. #define SSL2_VERSION_MAJOR 0x00
  66. #define SSL2_VERSION_MINOR 0x02
  67. /* #define SSL2_CLIENT_VERSION 0x0002 */
  68. /* #define SSL2_SERVER_VERSION 0x0002 */
  69. /* Protocol Message Codes */
  70. #define SSL2_MT_ERROR 0
  71. #define SSL2_MT_CLIENT_HELLO 1
  72. #define SSL2_MT_CLIENT_MASTER_KEY 2
  73. #define SSL2_MT_CLIENT_FINISHED 3
  74. #define SSL2_MT_SERVER_HELLO 4
  75. #define SSL2_MT_SERVER_VERIFY 5
  76. #define SSL2_MT_SERVER_FINISHED 6
  77. #define SSL2_MT_REQUEST_CERTIFICATE 7
  78. #define SSL2_MT_CLIENT_CERTIFICATE 8
  79. /* Error Message Codes */
  80. #define SSL2_PE_UNDEFINED_ERROR 0x0000
  81. #define SSL2_PE_NO_CIPHER 0x0001
  82. #define SSL2_PE_NO_CERTIFICATE 0x0002
  83. #define SSL2_PE_BAD_CERTIFICATE 0x0004
  84. #define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
  85. /* Cipher Kind Values */
  86. #define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */
  87. #define SSL2_CK_RC4_128_WITH_MD5 0x02010080
  88. #define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080
  89. #define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080
  90. #define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080
  91. #define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080
  92. #define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040
  93. #define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */
  94. #define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0
  95. #define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */
  96. #define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */
  97. #define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */
  98. #define SSL2_CK_NULL 0x02ff0810 /* SSLeay */
  99. #define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1"
  100. #define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5"
  101. #define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5"
  102. #define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5"
  103. #define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5"
  104. #define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5"
  105. #define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5"
  106. #define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5"
  107. #define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA"
  108. #define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5"
  109. #define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA"
  110. #define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5"
  111. #define SSL2_TXT_NULL "NULL"
  112. /* Flags for the SSL_CIPHER.algorithm2 field */
  113. #define SSL2_CF_5_BYTE_ENC 0x01
  114. #define SSL2_CF_8_BYTE_ENC 0x02
  115. /* Certificate Type Codes */
  116. #define SSL2_CT_X509_CERTIFICATE 0x01
  117. /* Authentication Type Code */
  118. #define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01
  119. #define SSL2_MAX_SSL_SESSION_ID_LENGTH 32
  120. /* Upper/Lower Bounds */
  121. #define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256
  122. #ifdef OPENSSL_SYS_MPE
  123. #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u
  124. #else
  125. #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */
  126. #endif
  127. #define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */
  128. #define SSL2_CHALLENGE_LENGTH 16
  129. /*#define SSL2_CHALLENGE_LENGTH 32 */
  130. #define SSL2_MIN_CHALLENGE_LENGTH 16
  131. #define SSL2_MAX_CHALLENGE_LENGTH 32
  132. #define SSL2_CONNECTION_ID_LENGTH 16
  133. #define SSL2_MAX_CONNECTION_ID_LENGTH 16
  134. #define SSL2_SSL_SESSION_ID_LENGTH 16
  135. #define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
  136. #define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
  137. #define SSL2_MAX_KEY_MATERIAL_LENGTH 24
  138. #ifndef HEADER_SSL_LOCL_H
  139. #define CERT char
  140. #endif
  141. typedef struct ssl2_state_st
  142. {
  143. int three_byte_header;
  144. int clear_text; /* clear text */
  145. int escape; /* not used in SSLv2 */
  146. int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */
  147. /* non-blocking io info, used to make sure the same
  148. * args were passwd */
  149. unsigned int wnum; /* number of bytes sent so far */
  150. int wpend_tot;
  151. const unsigned char *wpend_buf;
  152. int wpend_off; /* offset to data to write */
  153. int wpend_len; /* number of bytes passwd to write */
  154. int wpend_ret; /* number of bytes to return to caller */
  155. /* buffer raw data */
  156. int rbuf_left;
  157. int rbuf_offs;
  158. unsigned char *rbuf;
  159. unsigned char *wbuf;
  160. unsigned char *write_ptr;/* used to point to the start due to
  161. * 2/3 byte header. */
  162. unsigned int padding;
  163. unsigned int rlength; /* passed to ssl2_enc */
  164. int ract_data_length; /* Set when things are encrypted. */
  165. unsigned int wlength; /* passed to ssl2_enc */
  166. int wact_data_length; /* Set when things are decrypted. */
  167. unsigned char *ract_data;
  168. unsigned char *wact_data;
  169. unsigned char *mac_data;
  170. unsigned char *read_key;
  171. unsigned char *write_key;
  172. /* Stuff specifically to do with this SSL session */
  173. unsigned int challenge_length;
  174. unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
  175. unsigned int conn_id_length;
  176. unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
  177. unsigned int key_material_length;
  178. unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
  179. unsigned long read_sequence;
  180. unsigned long write_sequence;
  181. struct {
  182. unsigned int conn_id_length;
  183. unsigned int cert_type;
  184. unsigned int cert_length;
  185. unsigned int csl;
  186. unsigned int clear;
  187. unsigned int enc;
  188. unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
  189. unsigned int cipher_spec_length;
  190. unsigned int session_id_length;
  191. unsigned int clen;
  192. unsigned int rlen;
  193. } tmp;
  194. } SSL2_STATE;
  195. /* SSLv2 */
  196. /* client */
  197. #define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
  198. #define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
  199. #define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
  200. #define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
  201. #define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
  202. #define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
  203. #define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
  204. #define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
  205. #define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
  206. #define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
  207. #define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
  208. #define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
  209. #define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
  210. #define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
  211. #define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
  212. #define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
  213. #define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
  214. #define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
  215. /* server */
  216. #define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
  217. #define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
  218. #define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
  219. #define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
  220. #define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
  221. #define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
  222. #define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
  223. #define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
  224. #define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
  225. #define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
  226. #define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
  227. #define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
  228. #define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
  229. #define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
  230. #define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
  231. #define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
  232. #define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
  233. #define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
  234. #define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
  235. #define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif