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