sl@0
|
1 |
/* ssl/s2_lib.c */
|
sl@0
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This package is an SSL implementation written
|
sl@0
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
10 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
13 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
17 |
* the code are not to be removed.
|
sl@0
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
19 |
* as the author of the parts of the library used.
|
sl@0
|
20 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
21 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
24 |
* modification, are permitted provided that the following conditions
|
sl@0
|
25 |
* are met:
|
sl@0
|
26 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
27 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
30 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
32 |
* must display the following acknowledgement:
|
sl@0
|
33 |
* "This product includes cryptographic software written by
|
sl@0
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
36 |
* being used are not cryptographic related :-).
|
sl@0
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
51 |
* SUCH DAMAGE.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
55 |
* copied and put under another distribution licence
|
sl@0
|
56 |
* [including the GNU Public Licence.]
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
/*
|
sl@0
|
59 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
|
sl@0
|
62 |
#include "ssl_locl.h"
|
sl@0
|
63 |
#ifndef OPENSSL_NO_SSL2
|
sl@0
|
64 |
#include <stdio.h>
|
sl@0
|
65 |
#include <openssl/objects.h>
|
sl@0
|
66 |
#include <openssl/evp.h>
|
sl@0
|
67 |
#include <openssl/md5.h>
|
sl@0
|
68 |
|
sl@0
|
69 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
70 |
#include "libssl_wsd.h"
|
sl@0
|
71 |
#endif
|
sl@0
|
72 |
|
sl@0
|
73 |
#ifdef EMULATOR
|
sl@0
|
74 |
|
sl@0
|
75 |
GET_STATIC_VAR_FROM_TLS(sslv2_base_method_data,s2_lib,SSL_METHOD)
|
sl@0
|
76 |
|
sl@0
|
77 |
#define sslv2_base_method_data (*GET_WSD_VAR_NAME(sslv2_base_method_data,s2_lib,s)())
|
sl@0
|
78 |
|
sl@0
|
79 |
#endif
|
sl@0
|
80 |
|
sl@0
|
81 |
const char ssl2_version_str[]="SSLv2" OPENSSL_VERSION_PTEXT;
|
sl@0
|
82 |
|
sl@0
|
83 |
#ifndef EMULATOR
|
sl@0
|
84 |
#define SSL2_NUM_CIPHERS (sizeof(ssl2_ciphers)/sizeof(SSL_CIPHER))
|
sl@0
|
85 |
/* #else */
|
sl@0
|
86 |
/* #define SSL2_NUM_CIPHERS 10 Defined in libssl_wsd.h */
|
sl@0
|
87 |
#endif
|
sl@0
|
88 |
|
sl@0
|
89 |
/* list of available SSLv2 ciphers (sorted by id) */
|
sl@0
|
90 |
|
sl@0
|
91 |
|
sl@0
|
92 |
#ifdef EMULATOR
|
sl@0
|
93 |
|
sl@0
|
94 |
GET_GLOBAL_ARRAY_FROM_TLS(ssl2_ciphers,s2_lib,SSL_CIPHER)
|
sl@0
|
95 |
|
sl@0
|
96 |
#define ssl2_ciphers (GET_WSD_VAR_NAME(ssl2_ciphers,s2_lib,g)())
|
sl@0
|
97 |
|
sl@0
|
98 |
#endif
|
sl@0
|
99 |
|
sl@0
|
100 |
#ifndef EMULATOR
|
sl@0
|
101 |
OPENSSL_GLOBAL SSL_CIPHER ssl2_ciphers[]={
|
sl@0
|
102 |
#else
|
sl@0
|
103 |
OPENSSL_GLOBAL const SSL_CIPHER temp_ssl2_ciphers[]={
|
sl@0
|
104 |
#endif
|
sl@0
|
105 |
/* NULL_WITH_MD5 v3 */
|
sl@0
|
106 |
#if 0
|
sl@0
|
107 |
{
|
sl@0
|
108 |
1,
|
sl@0
|
109 |
SSL2_TXT_NULL_WITH_MD5,
|
sl@0
|
110 |
SSL2_CK_NULL_WITH_MD5,
|
sl@0
|
111 |
SSL_kRSA|SSL_aRSA|SSL_eNULL|SSL_MD5|SSL_SSLV2,
|
sl@0
|
112 |
SSL_EXPORT|SSL_EXP40|SSL_STRONG_NONE,
|
sl@0
|
113 |
0,
|
sl@0
|
114 |
0,
|
sl@0
|
115 |
0,
|
sl@0
|
116 |
SSL_ALL_CIPHERS,
|
sl@0
|
117 |
SSL_ALL_STRENGTHS,
|
sl@0
|
118 |
},
|
sl@0
|
119 |
#endif
|
sl@0
|
120 |
/* RC4_128_WITH_MD5 */
|
sl@0
|
121 |
{
|
sl@0
|
122 |
1,
|
sl@0
|
123 |
SSL2_TXT_RC4_128_WITH_MD5,
|
sl@0
|
124 |
SSL2_CK_RC4_128_WITH_MD5,
|
sl@0
|
125 |
SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
|
sl@0
|
126 |
SSL_NOT_EXP|SSL_MEDIUM,
|
sl@0
|
127 |
0,
|
sl@0
|
128 |
128,
|
sl@0
|
129 |
128,
|
sl@0
|
130 |
SSL_ALL_CIPHERS,
|
sl@0
|
131 |
SSL_ALL_STRENGTHS,
|
sl@0
|
132 |
},
|
sl@0
|
133 |
/* RC4_128_EXPORT40_WITH_MD5 */
|
sl@0
|
134 |
{
|
sl@0
|
135 |
1,
|
sl@0
|
136 |
SSL2_TXT_RC4_128_EXPORT40_WITH_MD5,
|
sl@0
|
137 |
SSL2_CK_RC4_128_EXPORT40_WITH_MD5,
|
sl@0
|
138 |
SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
|
sl@0
|
139 |
SSL_EXPORT|SSL_EXP40,
|
sl@0
|
140 |
SSL2_CF_5_BYTE_ENC,
|
sl@0
|
141 |
40,
|
sl@0
|
142 |
128,
|
sl@0
|
143 |
SSL_ALL_CIPHERS,
|
sl@0
|
144 |
SSL_ALL_STRENGTHS,
|
sl@0
|
145 |
},
|
sl@0
|
146 |
/* RC2_128_CBC_WITH_MD5 */
|
sl@0
|
147 |
{
|
sl@0
|
148 |
1,
|
sl@0
|
149 |
SSL2_TXT_RC2_128_CBC_WITH_MD5,
|
sl@0
|
150 |
SSL2_CK_RC2_128_CBC_WITH_MD5,
|
sl@0
|
151 |
SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_SSLV2,
|
sl@0
|
152 |
SSL_NOT_EXP|SSL_MEDIUM,
|
sl@0
|
153 |
0,
|
sl@0
|
154 |
128,
|
sl@0
|
155 |
128,
|
sl@0
|
156 |
SSL_ALL_CIPHERS,
|
sl@0
|
157 |
SSL_ALL_STRENGTHS,
|
sl@0
|
158 |
},
|
sl@0
|
159 |
/* RC2_128_CBC_EXPORT40_WITH_MD5 */
|
sl@0
|
160 |
{
|
sl@0
|
161 |
1,
|
sl@0
|
162 |
SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5,
|
sl@0
|
163 |
SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5,
|
sl@0
|
164 |
SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_SSLV2,
|
sl@0
|
165 |
SSL_EXPORT|SSL_EXP40,
|
sl@0
|
166 |
SSL2_CF_5_BYTE_ENC,
|
sl@0
|
167 |
40,
|
sl@0
|
168 |
128,
|
sl@0
|
169 |
SSL_ALL_CIPHERS,
|
sl@0
|
170 |
SSL_ALL_STRENGTHS,
|
sl@0
|
171 |
},
|
sl@0
|
172 |
/* IDEA_128_CBC_WITH_MD5 */
|
sl@0
|
173 |
#ifndef OPENSSL_NO_IDEA
|
sl@0
|
174 |
{
|
sl@0
|
175 |
1,
|
sl@0
|
176 |
SSL2_TXT_IDEA_128_CBC_WITH_MD5,
|
sl@0
|
177 |
SSL2_CK_IDEA_128_CBC_WITH_MD5,
|
sl@0
|
178 |
SSL_kRSA|SSL_aRSA|SSL_IDEA|SSL_MD5|SSL_SSLV2,
|
sl@0
|
179 |
SSL_NOT_EXP|SSL_MEDIUM,
|
sl@0
|
180 |
0,
|
sl@0
|
181 |
128,
|
sl@0
|
182 |
128,
|
sl@0
|
183 |
SSL_ALL_CIPHERS,
|
sl@0
|
184 |
SSL_ALL_STRENGTHS,
|
sl@0
|
185 |
},
|
sl@0
|
186 |
#endif
|
sl@0
|
187 |
/* DES_64_CBC_WITH_MD5 */
|
sl@0
|
188 |
{
|
sl@0
|
189 |
1,
|
sl@0
|
190 |
SSL2_TXT_DES_64_CBC_WITH_MD5,
|
sl@0
|
191 |
SSL2_CK_DES_64_CBC_WITH_MD5,
|
sl@0
|
192 |
SSL_kRSA|SSL_aRSA|SSL_DES|SSL_MD5|SSL_SSLV2,
|
sl@0
|
193 |
SSL_NOT_EXP|SSL_LOW,
|
sl@0
|
194 |
0,
|
sl@0
|
195 |
56,
|
sl@0
|
196 |
56,
|
sl@0
|
197 |
SSL_ALL_CIPHERS,
|
sl@0
|
198 |
SSL_ALL_STRENGTHS,
|
sl@0
|
199 |
},
|
sl@0
|
200 |
/* DES_192_EDE3_CBC_WITH_MD5 */
|
sl@0
|
201 |
{
|
sl@0
|
202 |
1,
|
sl@0
|
203 |
SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5,
|
sl@0
|
204 |
SSL2_CK_DES_192_EDE3_CBC_WITH_MD5,
|
sl@0
|
205 |
SSL_kRSA|SSL_aRSA|SSL_3DES|SSL_MD5|SSL_SSLV2,
|
sl@0
|
206 |
SSL_NOT_EXP|SSL_HIGH,
|
sl@0
|
207 |
0,
|
sl@0
|
208 |
168,
|
sl@0
|
209 |
168,
|
sl@0
|
210 |
SSL_ALL_CIPHERS,
|
sl@0
|
211 |
SSL_ALL_STRENGTHS,
|
sl@0
|
212 |
},
|
sl@0
|
213 |
/* RC4_64_WITH_MD5 */
|
sl@0
|
214 |
#if 0
|
sl@0
|
215 |
{
|
sl@0
|
216 |
1,
|
sl@0
|
217 |
SSL2_TXT_RC4_64_WITH_MD5,
|
sl@0
|
218 |
SSL2_CK_RC4_64_WITH_MD5,
|
sl@0
|
219 |
SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_SSLV2,
|
sl@0
|
220 |
SSL_NOT_EXP|SSL_LOW,
|
sl@0
|
221 |
SSL2_CF_8_BYTE_ENC,
|
sl@0
|
222 |
64,
|
sl@0
|
223 |
64,
|
sl@0
|
224 |
SSL_ALL_CIPHERS,
|
sl@0
|
225 |
SSL_ALL_STRENGTHS,
|
sl@0
|
226 |
},
|
sl@0
|
227 |
#endif
|
sl@0
|
228 |
/* NULL SSLeay (testing) */
|
sl@0
|
229 |
#if 0
|
sl@0
|
230 |
{
|
sl@0
|
231 |
0,
|
sl@0
|
232 |
SSL2_TXT_NULL,
|
sl@0
|
233 |
SSL2_CK_NULL,
|
sl@0
|
234 |
0,
|
sl@0
|
235 |
SSL_STRONG_NONE,
|
sl@0
|
236 |
0,
|
sl@0
|
237 |
0,
|
sl@0
|
238 |
0,
|
sl@0
|
239 |
SSL_ALL_CIPHERS,
|
sl@0
|
240 |
SSL_ALL_STRENGTHS,
|
sl@0
|
241 |
},
|
sl@0
|
242 |
#endif
|
sl@0
|
243 |
|
sl@0
|
244 |
/* end of list :-) */
|
sl@0
|
245 |
};
|
sl@0
|
246 |
|
sl@0
|
247 |
long ssl2_default_timeout(void)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
return(300);
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
IMPLEMENT_ssl2_meth_func(sslv2_base_method,
|
sl@0
|
253 |
ssl_undefined_function,
|
sl@0
|
254 |
ssl_undefined_function,
|
sl@0
|
255 |
ssl_bad_method)
|
sl@0
|
256 |
|
sl@0
|
257 |
int ssl2_num_ciphers(void)
|
sl@0
|
258 |
{
|
sl@0
|
259 |
return(SSL2_NUM_CIPHERS);
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
SSL_CIPHER *ssl2_get_cipher(unsigned int u)
|
sl@0
|
263 |
{
|
sl@0
|
264 |
if (u < SSL2_NUM_CIPHERS)
|
sl@0
|
265 |
return(&(ssl2_ciphers[SSL2_NUM_CIPHERS-1-u]));
|
sl@0
|
266 |
else
|
sl@0
|
267 |
return(NULL);
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
int ssl2_pending(const SSL *s)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
return SSL_in_init(s) ? 0 : s->s2->ract_data_length;
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
int ssl2_new(SSL *s)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
SSL2_STATE *s2;
|
sl@0
|
278 |
|
sl@0
|
279 |
if ((s2=OPENSSL_malloc(sizeof *s2)) == NULL) goto err;
|
sl@0
|
280 |
memset(s2,0,sizeof *s2);
|
sl@0
|
281 |
|
sl@0
|
282 |
#if SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER + 3 > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER + 2
|
sl@0
|
283 |
# error "assertion failed"
|
sl@0
|
284 |
#endif
|
sl@0
|
285 |
|
sl@0
|
286 |
if ((s2->rbuf=OPENSSL_malloc(
|
sl@0
|
287 |
SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+2)) == NULL) goto err;
|
sl@0
|
288 |
/* wbuf needs one byte more because when using two-byte headers,
|
sl@0
|
289 |
* we leave the first byte unused in do_ssl_write (s2_pkt.c) */
|
sl@0
|
290 |
if ((s2->wbuf=OPENSSL_malloc(
|
sl@0
|
291 |
SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER+3)) == NULL) goto err;
|
sl@0
|
292 |
s->s2=s2;
|
sl@0
|
293 |
|
sl@0
|
294 |
ssl2_clear(s);
|
sl@0
|
295 |
return(1);
|
sl@0
|
296 |
err:
|
sl@0
|
297 |
if (s2 != NULL)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
if (s2->wbuf != NULL) OPENSSL_free(s2->wbuf);
|
sl@0
|
300 |
if (s2->rbuf != NULL) OPENSSL_free(s2->rbuf);
|
sl@0
|
301 |
OPENSSL_free(s2);
|
sl@0
|
302 |
}
|
sl@0
|
303 |
return(0);
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
void ssl2_free(SSL *s)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
SSL2_STATE *s2;
|
sl@0
|
309 |
|
sl@0
|
310 |
if(s == NULL)
|
sl@0
|
311 |
return;
|
sl@0
|
312 |
|
sl@0
|
313 |
s2=s->s2;
|
sl@0
|
314 |
if (s2->rbuf != NULL) OPENSSL_free(s2->rbuf);
|
sl@0
|
315 |
if (s2->wbuf != NULL) OPENSSL_free(s2->wbuf);
|
sl@0
|
316 |
OPENSSL_cleanse(s2,sizeof *s2);
|
sl@0
|
317 |
OPENSSL_free(s2);
|
sl@0
|
318 |
s->s2=NULL;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
void ssl2_clear(SSL *s)
|
sl@0
|
322 |
{
|
sl@0
|
323 |
SSL2_STATE *s2;
|
sl@0
|
324 |
unsigned char *rbuf,*wbuf;
|
sl@0
|
325 |
|
sl@0
|
326 |
s2=s->s2;
|
sl@0
|
327 |
|
sl@0
|
328 |
rbuf=s2->rbuf;
|
sl@0
|
329 |
wbuf=s2->wbuf;
|
sl@0
|
330 |
|
sl@0
|
331 |
memset(s2,0,sizeof *s2);
|
sl@0
|
332 |
|
sl@0
|
333 |
s2->rbuf=rbuf;
|
sl@0
|
334 |
s2->wbuf=wbuf;
|
sl@0
|
335 |
s2->clear_text=1;
|
sl@0
|
336 |
s->packet=s2->rbuf;
|
sl@0
|
337 |
s->version=SSL2_VERSION;
|
sl@0
|
338 |
s->packet_length=0;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
long ssl2_ctrl(SSL *s, int cmd, long larg, void *parg)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
int ret=0;
|
sl@0
|
344 |
|
sl@0
|
345 |
switch(cmd)
|
sl@0
|
346 |
{
|
sl@0
|
347 |
case SSL_CTRL_GET_SESSION_REUSED:
|
sl@0
|
348 |
ret=s->hit;
|
sl@0
|
349 |
break;
|
sl@0
|
350 |
default:
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
}
|
sl@0
|
353 |
return(ret);
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
long ssl2_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
|
sl@0
|
357 |
{
|
sl@0
|
358 |
return(0);
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
long ssl2_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
return(0);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
long ssl2_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
|
sl@0
|
367 |
{
|
sl@0
|
368 |
return(0);
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
/* This function needs to check if the ciphers required are actually
|
sl@0
|
372 |
* available */
|
sl@0
|
373 |
SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p)
|
sl@0
|
374 |
{
|
sl@0
|
375 |
SSL_CIPHER c,*cp;
|
sl@0
|
376 |
unsigned long id;
|
sl@0
|
377 |
|
sl@0
|
378 |
id=0x02000000L|((unsigned long)p[0]<<16L)|
|
sl@0
|
379 |
((unsigned long)p[1]<<8L)|(unsigned long)p[2];
|
sl@0
|
380 |
c.id=id;
|
sl@0
|
381 |
cp = (SSL_CIPHER *)OBJ_bsearch((char *)&c,
|
sl@0
|
382 |
(char *)ssl2_ciphers,
|
sl@0
|
383 |
SSL2_NUM_CIPHERS,sizeof(SSL_CIPHER),
|
sl@0
|
384 |
FP_ICC ssl_cipher_id_cmp);
|
sl@0
|
385 |
if ((cp == NULL) || (cp->valid == 0))
|
sl@0
|
386 |
return NULL;
|
sl@0
|
387 |
else
|
sl@0
|
388 |
return cp;
|
sl@0
|
389 |
}
|
sl@0
|
390 |
|
sl@0
|
391 |
int ssl2_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
|
sl@0
|
392 |
{
|
sl@0
|
393 |
long l;
|
sl@0
|
394 |
|
sl@0
|
395 |
if (p != NULL)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
l=c->id;
|
sl@0
|
398 |
if ((l & 0xff000000) != 0x02000000) return(0);
|
sl@0
|
399 |
p[0]=((unsigned char)(l>>16L))&0xFF;
|
sl@0
|
400 |
p[1]=((unsigned char)(l>> 8L))&0xFF;
|
sl@0
|
401 |
p[2]=((unsigned char)(l ))&0xFF;
|
sl@0
|
402 |
}
|
sl@0
|
403 |
return(3);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
int ssl2_generate_key_material(SSL *s)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
unsigned int i;
|
sl@0
|
409 |
EVP_MD_CTX ctx;
|
sl@0
|
410 |
unsigned char *km;
|
sl@0
|
411 |
unsigned char c='0';
|
sl@0
|
412 |
const EVP_MD *md5;
|
sl@0
|
413 |
|
sl@0
|
414 |
md5 = EVP_md5();
|
sl@0
|
415 |
|
sl@0
|
416 |
#ifdef CHARSET_EBCDIC
|
sl@0
|
417 |
c = os_toascii['0']; /* Must be an ASCII '0', not EBCDIC '0',
|
sl@0
|
418 |
see SSLv2 docu */
|
sl@0
|
419 |
#endif
|
sl@0
|
420 |
EVP_MD_CTX_init(&ctx);
|
sl@0
|
421 |
km=s->s2->key_material;
|
sl@0
|
422 |
|
sl@0
|
423 |
if (s->session->master_key_length < 0 ||
|
sl@0
|
424 |
s->session->master_key_length > (int)sizeof(s->session->master_key))
|
sl@0
|
425 |
{
|
sl@0
|
426 |
SSLerr(SSL_F_SSL2_GENERATE_KEY_MATERIAL, ERR_R_INTERNAL_ERROR);
|
sl@0
|
427 |
return 0;
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
for (i=0; i<s->s2->key_material_length; i += EVP_MD_size(md5))
|
sl@0
|
431 |
{
|
sl@0
|
432 |
if (((km - s->s2->key_material) + EVP_MD_size(md5)) >
|
sl@0
|
433 |
(int)sizeof(s->s2->key_material))
|
sl@0
|
434 |
{
|
sl@0
|
435 |
/* EVP_DigestFinal_ex() below would write beyond buffer */
|
sl@0
|
436 |
SSLerr(SSL_F_SSL2_GENERATE_KEY_MATERIAL, ERR_R_INTERNAL_ERROR);
|
sl@0
|
437 |
return 0;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
|
sl@0
|
440 |
EVP_DigestInit_ex(&ctx, md5, NULL);
|
sl@0
|
441 |
|
sl@0
|
442 |
OPENSSL_assert(s->session->master_key_length >= 0
|
sl@0
|
443 |
&& s->session->master_key_length
|
sl@0
|
444 |
< (int)sizeof(s->session->master_key));
|
sl@0
|
445 |
EVP_DigestUpdate(&ctx,s->session->master_key,s->session->master_key_length);
|
sl@0
|
446 |
EVP_DigestUpdate(&ctx,&c,1);
|
sl@0
|
447 |
c++;
|
sl@0
|
448 |
EVP_DigestUpdate(&ctx,s->s2->challenge,s->s2->challenge_length);
|
sl@0
|
449 |
EVP_DigestUpdate(&ctx,s->s2->conn_id,s->s2->conn_id_length);
|
sl@0
|
450 |
EVP_DigestFinal_ex(&ctx,km,NULL);
|
sl@0
|
451 |
km += EVP_MD_size(md5);
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
EVP_MD_CTX_cleanup(&ctx);
|
sl@0
|
455 |
return 1;
|
sl@0
|
456 |
}
|
sl@0
|
457 |
|
sl@0
|
458 |
void ssl2_return_error(SSL *s, int err)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
if (!s->error)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
s->error=3;
|
sl@0
|
463 |
s->error_code=err;
|
sl@0
|
464 |
|
sl@0
|
465 |
ssl2_write_error(s);
|
sl@0
|
466 |
}
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
|
sl@0
|
470 |
void ssl2_write_error(SSL *s)
|
sl@0
|
471 |
{
|
sl@0
|
472 |
unsigned char buf[3];
|
sl@0
|
473 |
int i,error;
|
sl@0
|
474 |
|
sl@0
|
475 |
buf[0]=SSL2_MT_ERROR;
|
sl@0
|
476 |
buf[1]=(s->error_code>>8)&0xff;
|
sl@0
|
477 |
buf[2]=(s->error_code)&0xff;
|
sl@0
|
478 |
|
sl@0
|
479 |
/* state=s->rwstate;*/
|
sl@0
|
480 |
|
sl@0
|
481 |
error=s->error; /* number of bytes left to write */
|
sl@0
|
482 |
s->error=0;
|
sl@0
|
483 |
OPENSSL_assert(error >= 0 && error <= (int)sizeof(buf));
|
sl@0
|
484 |
i=ssl2_write(s,&(buf[3-error]),error);
|
sl@0
|
485 |
|
sl@0
|
486 |
/* if (i == error) s->rwstate=state; */
|
sl@0
|
487 |
|
sl@0
|
488 |
if (i < 0)
|
sl@0
|
489 |
s->error=error;
|
sl@0
|
490 |
else
|
sl@0
|
491 |
{
|
sl@0
|
492 |
s->error=error-i;
|
sl@0
|
493 |
|
sl@0
|
494 |
if (s->error == 0)
|
sl@0
|
495 |
if (s->msg_callback)
|
sl@0
|
496 |
s->msg_callback(1, s->version, 0, buf, 3, s, s->msg_callback_arg); /* ERROR */
|
sl@0
|
497 |
}
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
int ssl2_shutdown(SSL *s)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
|
sl@0
|
503 |
return(1);
|
sl@0
|
504 |
}
|
sl@0
|
505 |
#else /* !OPENSSL_NO_SSL2 */
|
sl@0
|
506 |
|
sl@0
|
507 |
# if PEDANTIC
|
sl@0
|
508 |
static void *dummy=&dummy;
|
sl@0
|
509 |
# endif
|
sl@0
|
510 |
|
sl@0
|
511 |
#endif
|