diff options
Diffstat (limited to 'src/lib/libssl')
76 files changed, 0 insertions, 26371 deletions
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE deleted file mode 100644 index e6afecc724..0000000000 --- a/src/lib/libssl/LICENSE +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | |||
2 | LICENSE ISSUES | ||
3 | ============== | ||
4 | |||
5 | The OpenSSL toolkit stays under a dual license, i.e. both the conditions of | ||
6 | the OpenSSL License and the original SSLeay license apply to the toolkit. | ||
7 | See below for the actual license texts. Actually both licenses are BSD-style | ||
8 | Open Source licenses. In case of any license issues related to OpenSSL | ||
9 | please contact openssl-core@openssl.org. | ||
10 | |||
11 | OpenSSL License | ||
12 | --------------- | ||
13 | |||
14 | /* ==================================================================== | ||
15 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. | ||
16 | * | ||
17 | * Redistribution and use in source and binary forms, with or without | ||
18 | * modification, are permitted provided that the following conditions | ||
19 | * are met: | ||
20 | * | ||
21 | * 1. Redistributions of source code must retain the above copyright | ||
22 | * notice, this list of conditions and the following disclaimer. | ||
23 | * | ||
24 | * 2. Redistributions in binary form must reproduce the above copyright | ||
25 | * notice, this list of conditions and the following disclaimer in | ||
26 | * the documentation and/or other materials provided with the | ||
27 | * distribution. | ||
28 | * | ||
29 | * 3. All advertising materials mentioning features or use of this | ||
30 | * software must display the following acknowledgment: | ||
31 | * "This product includes software developed by the OpenSSL Project | ||
32 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
33 | * | ||
34 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
35 | * endorse or promote products derived from this software without | ||
36 | * prior written permission. For written permission, please contact | ||
37 | * openssl-core@openssl.org. | ||
38 | * | ||
39 | * 5. Products derived from this software may not be called "OpenSSL" | ||
40 | * nor may "OpenSSL" appear in their names without prior written | ||
41 | * permission of the OpenSSL Project. | ||
42 | * | ||
43 | * 6. Redistributions of any form whatsoever must retain the following | ||
44 | * acknowledgment: | ||
45 | * "This product includes software developed by the OpenSSL Project | ||
46 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
47 | * | ||
48 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
49 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
51 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
52 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
53 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
55 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
57 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
58 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
59 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
60 | * ==================================================================== | ||
61 | * | ||
62 | * This product includes cryptographic software written by Eric Young | ||
63 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
64 | * Hudson (tjh@cryptsoft.com). | ||
65 | * | ||
66 | */ | ||
67 | |||
68 | Original SSLeay License | ||
69 | ----------------------- | ||
70 | |||
71 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
72 | * All rights reserved. | ||
73 | * | ||
74 | * This package is an SSL implementation written | ||
75 | * by Eric Young (eay@cryptsoft.com). | ||
76 | * The implementation was written so as to conform with Netscapes SSL. | ||
77 | * | ||
78 | * This library is free for commercial and non-commercial use as long as | ||
79 | * the following conditions are aheared to. The following conditions | ||
80 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
81 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
82 | * included with this distribution is covered by the same copyright terms | ||
83 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
84 | * | ||
85 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
86 | * the code are not to be removed. | ||
87 | * If this package is used in a product, Eric Young should be given attribution | ||
88 | * as the author of the parts of the library used. | ||
89 | * This can be in the form of a textual message at program startup or | ||
90 | * in documentation (online or textual) provided with the package. | ||
91 | * | ||
92 | * Redistribution and use in source and binary forms, with or without | ||
93 | * modification, are permitted provided that the following conditions | ||
94 | * are met: | ||
95 | * 1. Redistributions of source code must retain the copyright | ||
96 | * notice, this list of conditions and the following disclaimer. | ||
97 | * 2. Redistributions in binary form must reproduce the above copyright | ||
98 | * notice, this list of conditions and the following disclaimer in the | ||
99 | * documentation and/or other materials provided with the distribution. | ||
100 | * 3. All advertising materials mentioning features or use of this software | ||
101 | * must display the following acknowledgement: | ||
102 | * "This product includes cryptographic software written by | ||
103 | * Eric Young (eay@cryptsoft.com)" | ||
104 | * The word 'cryptographic' can be left out if the rouines from the library | ||
105 | * being used are not cryptographic related :-). | ||
106 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
107 | * the apps directory (application code) you must include an acknowledgement: | ||
108 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
109 | * | ||
110 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
111 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
112 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
113 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
114 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
115 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
116 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
117 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
118 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
119 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
120 | * SUCH DAMAGE. | ||
121 | * | ||
122 | * The licence and distribution terms for any publically available version or | ||
123 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
124 | * copied and put under another distribution licence | ||
125 | * [including the GNU Public Licence.] | ||
126 | */ | ||
127 | |||
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c deleted file mode 100644 index d683ee43e1..0000000000 --- a/src/lib/libssl/bio_ssl.c +++ /dev/null | |||
@@ -1,598 +0,0 @@ | |||
1 | /* ssl/bio_ssl.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <string.h> | ||
62 | #include <errno.h> | ||
63 | #include <openssl/crypto.h> | ||
64 | #include <openssl/bio.h> | ||
65 | #include <openssl/err.h> | ||
66 | #include <openssl/ssl.h> | ||
67 | |||
68 | static int ssl_write(BIO *h, const char *buf, int num); | ||
69 | static int ssl_read(BIO *h, char *buf, int size); | ||
70 | static int ssl_puts(BIO *h, const char *str); | ||
71 | static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
72 | static int ssl_new(BIO *h); | ||
73 | static int ssl_free(BIO *data); | ||
74 | static long ssl_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); | ||
75 | typedef struct bio_ssl_st | ||
76 | { | ||
77 | SSL *ssl; /* The ssl handle :-) */ | ||
78 | /* re-negotiate every time the total number of bytes is this size */ | ||
79 | int num_renegotiates; | ||
80 | unsigned long renegotiate_count; | ||
81 | unsigned long byte_count; | ||
82 | unsigned long renegotiate_timeout; | ||
83 | unsigned long last_time; | ||
84 | } BIO_SSL; | ||
85 | |||
86 | static BIO_METHOD methods_sslp= | ||
87 | { | ||
88 | BIO_TYPE_SSL,"ssl", | ||
89 | ssl_write, | ||
90 | ssl_read, | ||
91 | ssl_puts, | ||
92 | NULL, /* ssl_gets, */ | ||
93 | ssl_ctrl, | ||
94 | ssl_new, | ||
95 | ssl_free, | ||
96 | ssl_callback_ctrl, | ||
97 | }; | ||
98 | |||
99 | BIO_METHOD *BIO_f_ssl(void) | ||
100 | { | ||
101 | return(&methods_sslp); | ||
102 | } | ||
103 | |||
104 | static int ssl_new(BIO *bi) | ||
105 | { | ||
106 | BIO_SSL *bs; | ||
107 | |||
108 | bs=(BIO_SSL *)OPENSSL_malloc(sizeof(BIO_SSL)); | ||
109 | if (bs == NULL) | ||
110 | { | ||
111 | BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | ||
112 | return(0); | ||
113 | } | ||
114 | memset(bs,0,sizeof(BIO_SSL)); | ||
115 | bi->init=0; | ||
116 | bi->ptr=(char *)bs; | ||
117 | bi->flags=0; | ||
118 | return(1); | ||
119 | } | ||
120 | |||
121 | static int ssl_free(BIO *a) | ||
122 | { | ||
123 | BIO_SSL *bs; | ||
124 | |||
125 | if (a == NULL) return(0); | ||
126 | bs=(BIO_SSL *)a->ptr; | ||
127 | if (bs->ssl != NULL) SSL_shutdown(bs->ssl); | ||
128 | if (a->shutdown) | ||
129 | { | ||
130 | if (a->init && (bs->ssl != NULL)) | ||
131 | SSL_free(bs->ssl); | ||
132 | a->init=0; | ||
133 | a->flags=0; | ||
134 | } | ||
135 | if (a->ptr != NULL) | ||
136 | OPENSSL_free(a->ptr); | ||
137 | return(1); | ||
138 | } | ||
139 | |||
140 | static int ssl_read(BIO *b, char *out, int outl) | ||
141 | { | ||
142 | int ret=1; | ||
143 | BIO_SSL *sb; | ||
144 | SSL *ssl; | ||
145 | int retry_reason=0; | ||
146 | int r=0; | ||
147 | |||
148 | if (out == NULL) return(0); | ||
149 | sb=(BIO_SSL *)b->ptr; | ||
150 | ssl=sb->ssl; | ||
151 | |||
152 | BIO_clear_retry_flags(b); | ||
153 | |||
154 | #if 0 | ||
155 | if (!SSL_is_init_finished(ssl)) | ||
156 | { | ||
157 | /* ret=SSL_do_handshake(ssl); */ | ||
158 | if (ret > 0) | ||
159 | { | ||
160 | |||
161 | outflags=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY); | ||
162 | ret= -1; | ||
163 | goto end; | ||
164 | } | ||
165 | } | ||
166 | #endif | ||
167 | /* if (ret > 0) */ | ||
168 | ret=SSL_read(ssl,out,outl); | ||
169 | |||
170 | switch (SSL_get_error(ssl,ret)) | ||
171 | { | ||
172 | case SSL_ERROR_NONE: | ||
173 | if (ret <= 0) break; | ||
174 | if (sb->renegotiate_count > 0) | ||
175 | { | ||
176 | sb->byte_count+=ret; | ||
177 | if (sb->byte_count > sb->renegotiate_count) | ||
178 | { | ||
179 | sb->byte_count=0; | ||
180 | sb->num_renegotiates++; | ||
181 | SSL_renegotiate(ssl); | ||
182 | r=1; | ||
183 | } | ||
184 | } | ||
185 | if ((sb->renegotiate_timeout > 0) && (!r)) | ||
186 | { | ||
187 | unsigned long tm; | ||
188 | |||
189 | tm=(unsigned long)time(NULL); | ||
190 | if (tm > sb->last_time+sb->renegotiate_timeout) | ||
191 | { | ||
192 | sb->last_time=tm; | ||
193 | sb->num_renegotiates++; | ||
194 | SSL_renegotiate(ssl); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | break; | ||
199 | case SSL_ERROR_WANT_READ: | ||
200 | BIO_set_retry_read(b); | ||
201 | break; | ||
202 | case SSL_ERROR_WANT_WRITE: | ||
203 | BIO_set_retry_write(b); | ||
204 | break; | ||
205 | case SSL_ERROR_WANT_X509_LOOKUP: | ||
206 | BIO_set_retry_special(b); | ||
207 | retry_reason=BIO_RR_SSL_X509_LOOKUP; | ||
208 | break; | ||
209 | case SSL_ERROR_WANT_ACCEPT: | ||
210 | BIO_set_retry_special(b); | ||
211 | retry_reason=BIO_RR_ACCEPT; | ||
212 | break; | ||
213 | case SSL_ERROR_WANT_CONNECT: | ||
214 | BIO_set_retry_special(b); | ||
215 | retry_reason=BIO_RR_CONNECT; | ||
216 | break; | ||
217 | case SSL_ERROR_SYSCALL: | ||
218 | case SSL_ERROR_SSL: | ||
219 | case SSL_ERROR_ZERO_RETURN: | ||
220 | default: | ||
221 | break; | ||
222 | } | ||
223 | |||
224 | b->retry_reason=retry_reason; | ||
225 | return(ret); | ||
226 | } | ||
227 | |||
228 | static int ssl_write(BIO *b, const char *out, int outl) | ||
229 | { | ||
230 | int ret,r=0; | ||
231 | int retry_reason=0; | ||
232 | SSL *ssl; | ||
233 | BIO_SSL *bs; | ||
234 | |||
235 | if (out == NULL) return(0); | ||
236 | bs=(BIO_SSL *)b->ptr; | ||
237 | ssl=bs->ssl; | ||
238 | |||
239 | BIO_clear_retry_flags(b); | ||
240 | |||
241 | /* ret=SSL_do_handshake(ssl); | ||
242 | if (ret > 0) */ | ||
243 | ret=SSL_write(ssl,out,outl); | ||
244 | |||
245 | switch (SSL_get_error(ssl,ret)) | ||
246 | { | ||
247 | case SSL_ERROR_NONE: | ||
248 | if (ret <= 0) break; | ||
249 | if (bs->renegotiate_count > 0) | ||
250 | { | ||
251 | bs->byte_count+=ret; | ||
252 | if (bs->byte_count > bs->renegotiate_count) | ||
253 | { | ||
254 | bs->byte_count=0; | ||
255 | bs->num_renegotiates++; | ||
256 | SSL_renegotiate(ssl); | ||
257 | r=1; | ||
258 | } | ||
259 | } | ||
260 | if ((bs->renegotiate_timeout > 0) && (!r)) | ||
261 | { | ||
262 | unsigned long tm; | ||
263 | |||
264 | tm=(unsigned long)time(NULL); | ||
265 | if (tm > bs->last_time+bs->renegotiate_timeout) | ||
266 | { | ||
267 | bs->last_time=tm; | ||
268 | bs->num_renegotiates++; | ||
269 | SSL_renegotiate(ssl); | ||
270 | } | ||
271 | } | ||
272 | break; | ||
273 | case SSL_ERROR_WANT_WRITE: | ||
274 | BIO_set_retry_write(b); | ||
275 | break; | ||
276 | case SSL_ERROR_WANT_READ: | ||
277 | BIO_set_retry_read(b); | ||
278 | break; | ||
279 | case SSL_ERROR_WANT_X509_LOOKUP: | ||
280 | BIO_set_retry_special(b); | ||
281 | retry_reason=BIO_RR_SSL_X509_LOOKUP; | ||
282 | break; | ||
283 | case SSL_ERROR_WANT_CONNECT: | ||
284 | BIO_set_retry_special(b); | ||
285 | retry_reason=BIO_RR_CONNECT; | ||
286 | case SSL_ERROR_SYSCALL: | ||
287 | case SSL_ERROR_SSL: | ||
288 | default: | ||
289 | break; | ||
290 | } | ||
291 | |||
292 | b->retry_reason=retry_reason; | ||
293 | return(ret); | ||
294 | } | ||
295 | |||
296 | static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
297 | { | ||
298 | SSL **sslp,*ssl; | ||
299 | BIO_SSL *bs; | ||
300 | BIO *dbio,*bio; | ||
301 | long ret=1; | ||
302 | |||
303 | bs=(BIO_SSL *)b->ptr; | ||
304 | ssl=bs->ssl; | ||
305 | if ((ssl == NULL) && (cmd != BIO_C_SET_SSL)) | ||
306 | return(0); | ||
307 | switch (cmd) | ||
308 | { | ||
309 | case BIO_CTRL_RESET: | ||
310 | SSL_shutdown(ssl); | ||
311 | |||
312 | if (ssl->handshake_func == ssl->method->ssl_connect) | ||
313 | SSL_set_connect_state(ssl); | ||
314 | else if (ssl->handshake_func == ssl->method->ssl_accept) | ||
315 | SSL_set_accept_state(ssl); | ||
316 | |||
317 | SSL_clear(ssl); | ||
318 | |||
319 | if (b->next_bio != NULL) | ||
320 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
321 | else if (ssl->rbio != NULL) | ||
322 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
323 | else | ||
324 | ret=1; | ||
325 | break; | ||
326 | case BIO_CTRL_INFO: | ||
327 | ret=0; | ||
328 | break; | ||
329 | case BIO_C_SSL_MODE: | ||
330 | if (num) /* client mode */ | ||
331 | SSL_set_connect_state(ssl); | ||
332 | else | ||
333 | SSL_set_accept_state(ssl); | ||
334 | break; | ||
335 | case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT: | ||
336 | ret=bs->renegotiate_timeout; | ||
337 | if (num < 60) num=5; | ||
338 | bs->renegotiate_timeout=(unsigned long)num; | ||
339 | bs->last_time=(unsigned long)time(NULL); | ||
340 | break; | ||
341 | case BIO_C_SET_SSL_RENEGOTIATE_BYTES: | ||
342 | ret=bs->renegotiate_count; | ||
343 | if ((long)num >=512) | ||
344 | bs->renegotiate_count=(unsigned long)num; | ||
345 | break; | ||
346 | case BIO_C_GET_SSL_NUM_RENEGOTIATES: | ||
347 | ret=bs->num_renegotiates; | ||
348 | break; | ||
349 | case BIO_C_SET_SSL: | ||
350 | if (ssl != NULL) | ||
351 | ssl_free(b); | ||
352 | b->shutdown=(int)num; | ||
353 | ssl=(SSL *)ptr; | ||
354 | ((BIO_SSL *)b->ptr)->ssl=ssl; | ||
355 | bio=SSL_get_rbio(ssl); | ||
356 | if (bio != NULL) | ||
357 | { | ||
358 | if (b->next_bio != NULL) | ||
359 | BIO_push(bio,b->next_bio); | ||
360 | b->next_bio=bio; | ||
361 | CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO); | ||
362 | } | ||
363 | b->init=1; | ||
364 | break; | ||
365 | case BIO_C_GET_SSL: | ||
366 | if (ptr != NULL) | ||
367 | { | ||
368 | sslp=(SSL **)ptr; | ||
369 | *sslp=ssl; | ||
370 | } | ||
371 | else | ||
372 | ret=0; | ||
373 | break; | ||
374 | case BIO_CTRL_GET_CLOSE: | ||
375 | ret=b->shutdown; | ||
376 | break; | ||
377 | case BIO_CTRL_SET_CLOSE: | ||
378 | b->shutdown=(int)num; | ||
379 | break; | ||
380 | case BIO_CTRL_WPENDING: | ||
381 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
382 | break; | ||
383 | case BIO_CTRL_PENDING: | ||
384 | ret=SSL_pending(ssl); | ||
385 | if (ret == 0) | ||
386 | ret=BIO_pending(ssl->rbio); | ||
387 | break; | ||
388 | case BIO_CTRL_FLUSH: | ||
389 | BIO_clear_retry_flags(b); | ||
390 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
391 | BIO_copy_next_retry(b); | ||
392 | break; | ||
393 | case BIO_CTRL_PUSH: | ||
394 | if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) | ||
395 | { | ||
396 | SSL_set_bio(ssl,b->next_bio,b->next_bio); | ||
397 | CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | ||
398 | } | ||
399 | break; | ||
400 | case BIO_CTRL_POP: | ||
401 | /* ugly bit of a hack */ | ||
402 | if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */ | ||
403 | { | ||
404 | BIO_free_all(ssl->wbio); | ||
405 | } | ||
406 | if (b->next_bio != NULL) | ||
407 | { | ||
408 | CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | ||
409 | } | ||
410 | ssl->wbio=NULL; | ||
411 | ssl->rbio=NULL; | ||
412 | break; | ||
413 | case BIO_C_DO_STATE_MACHINE: | ||
414 | BIO_clear_retry_flags(b); | ||
415 | |||
416 | b->retry_reason=0; | ||
417 | ret=(int)SSL_do_handshake(ssl); | ||
418 | |||
419 | switch (SSL_get_error(ssl,(int)ret)) | ||
420 | { | ||
421 | case SSL_ERROR_WANT_READ: | ||
422 | BIO_set_flags(b, | ||
423 | BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY); | ||
424 | break; | ||
425 | case SSL_ERROR_WANT_WRITE: | ||
426 | BIO_set_flags(b, | ||
427 | BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY); | ||
428 | break; | ||
429 | case SSL_ERROR_WANT_CONNECT: | ||
430 | BIO_set_flags(b, | ||
431 | BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY); | ||
432 | b->retry_reason=b->next_bio->retry_reason; | ||
433 | break; | ||
434 | default: | ||
435 | break; | ||
436 | } | ||
437 | break; | ||
438 | case BIO_CTRL_DUP: | ||
439 | dbio=(BIO *)ptr; | ||
440 | if (((BIO_SSL *)dbio->ptr)->ssl != NULL) | ||
441 | SSL_free(((BIO_SSL *)dbio->ptr)->ssl); | ||
442 | ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl); | ||
443 | ((BIO_SSL *)dbio->ptr)->renegotiate_count= | ||
444 | ((BIO_SSL *)b->ptr)->renegotiate_count; | ||
445 | ((BIO_SSL *)dbio->ptr)->byte_count= | ||
446 | ((BIO_SSL *)b->ptr)->byte_count; | ||
447 | ((BIO_SSL *)dbio->ptr)->renegotiate_timeout= | ||
448 | ((BIO_SSL *)b->ptr)->renegotiate_timeout; | ||
449 | ((BIO_SSL *)dbio->ptr)->last_time= | ||
450 | ((BIO_SSL *)b->ptr)->last_time; | ||
451 | ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL); | ||
452 | break; | ||
453 | case BIO_C_GET_FD: | ||
454 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
455 | break; | ||
456 | case BIO_CTRL_SET_CALLBACK: | ||
457 | { | ||
458 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | ||
459 | BIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
460 | ret = -1; | ||
461 | #else | ||
462 | ret=0; | ||
463 | #endif | ||
464 | } | ||
465 | break; | ||
466 | case BIO_CTRL_GET_CALLBACK: | ||
467 | { | ||
468 | void (**fptr)(); | ||
469 | |||
470 | fptr=(void (**)())ptr; | ||
471 | *fptr=SSL_get_info_callback(ssl); | ||
472 | } | ||
473 | break; | ||
474 | default: | ||
475 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
476 | break; | ||
477 | } | ||
478 | return(ret); | ||
479 | } | ||
480 | |||
481 | static long ssl_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | ||
482 | { | ||
483 | SSL *ssl; | ||
484 | BIO_SSL *bs; | ||
485 | long ret=1; | ||
486 | |||
487 | bs=(BIO_SSL *)b->ptr; | ||
488 | ssl=bs->ssl; | ||
489 | switch (cmd) | ||
490 | { | ||
491 | case BIO_CTRL_SET_CALLBACK: | ||
492 | { | ||
493 | /* FIXME: setting this via a completely different prototype | ||
494 | seems like a crap idea */ | ||
495 | SSL_set_info_callback(ssl,(void (*)(const SSL *,int,int))fp); | ||
496 | } | ||
497 | break; | ||
498 | default: | ||
499 | ret=BIO_callback_ctrl(ssl->rbio,cmd,fp); | ||
500 | break; | ||
501 | } | ||
502 | return(ret); | ||
503 | } | ||
504 | |||
505 | static int ssl_puts(BIO *bp, const char *str) | ||
506 | { | ||
507 | int n,ret; | ||
508 | |||
509 | n=strlen(str); | ||
510 | ret=BIO_write(bp,str,n); | ||
511 | return(ret); | ||
512 | } | ||
513 | |||
514 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) | ||
515 | { | ||
516 | #ifndef OPENSSL_NO_SOCK | ||
517 | BIO *ret=NULL,*buf=NULL,*ssl=NULL; | ||
518 | |||
519 | if ((buf=BIO_new(BIO_f_buffer())) == NULL) | ||
520 | return(NULL); | ||
521 | if ((ssl=BIO_new_ssl_connect(ctx)) == NULL) | ||
522 | goto err; | ||
523 | if ((ret=BIO_push(buf,ssl)) == NULL) | ||
524 | goto err; | ||
525 | return(ret); | ||
526 | err: | ||
527 | if (buf != NULL) BIO_free(buf); | ||
528 | if (ssl != NULL) BIO_free(ssl); | ||
529 | #endif | ||
530 | return(NULL); | ||
531 | } | ||
532 | |||
533 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx) | ||
534 | { | ||
535 | BIO *ret=NULL,*con=NULL,*ssl=NULL; | ||
536 | |||
537 | if ((con=BIO_new(BIO_s_connect())) == NULL) | ||
538 | return(NULL); | ||
539 | if ((ssl=BIO_new_ssl(ctx,1)) == NULL) | ||
540 | goto err; | ||
541 | if ((ret=BIO_push(ssl,con)) == NULL) | ||
542 | goto err; | ||
543 | return(ret); | ||
544 | err: | ||
545 | if (con != NULL) BIO_free(con); | ||
546 | if (ret != NULL) BIO_free(ret); | ||
547 | return(NULL); | ||
548 | } | ||
549 | |||
550 | BIO *BIO_new_ssl(SSL_CTX *ctx, int client) | ||
551 | { | ||
552 | BIO *ret; | ||
553 | SSL *ssl; | ||
554 | |||
555 | if ((ret=BIO_new(BIO_f_ssl())) == NULL) | ||
556 | return(NULL); | ||
557 | if ((ssl=SSL_new(ctx)) == NULL) | ||
558 | { | ||
559 | BIO_free(ret); | ||
560 | return(NULL); | ||
561 | } | ||
562 | if (client) | ||
563 | SSL_set_connect_state(ssl); | ||
564 | else | ||
565 | SSL_set_accept_state(ssl); | ||
566 | |||
567 | BIO_set_ssl(ret,ssl,BIO_CLOSE); | ||
568 | return(ret); | ||
569 | } | ||
570 | |||
571 | int BIO_ssl_copy_session_id(BIO *t, BIO *f) | ||
572 | { | ||
573 | t=BIO_find_type(t,BIO_TYPE_SSL); | ||
574 | f=BIO_find_type(f,BIO_TYPE_SSL); | ||
575 | if ((t == NULL) || (f == NULL)) | ||
576 | return(0); | ||
577 | if ( (((BIO_SSL *)t->ptr)->ssl == NULL) || | ||
578 | (((BIO_SSL *)f->ptr)->ssl == NULL)) | ||
579 | return(0); | ||
580 | SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl); | ||
581 | return(1); | ||
582 | } | ||
583 | |||
584 | void BIO_ssl_shutdown(BIO *b) | ||
585 | { | ||
586 | SSL *s; | ||
587 | |||
588 | while (b != NULL) | ||
589 | { | ||
590 | if (b->method->type == BIO_TYPE_SSL) | ||
591 | { | ||
592 | s=((BIO_SSL *)b->ptr)->ssl; | ||
593 | SSL_shutdown(s); | ||
594 | break; | ||
595 | } | ||
596 | b=b->next_bio; | ||
597 | } | ||
598 | } | ||
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf deleted file mode 100644 index 4c1d595b0a..0000000000 --- a/src/lib/libssl/doc/openssl.cnf +++ /dev/null | |||
@@ -1,313 +0,0 @@ | |||
1 | # | ||
2 | # OpenSSL example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | # This definition stops the following lines choking if HOME isn't | ||
7 | # defined. | ||
8 | HOME = . | ||
9 | RANDFILE = $ENV::HOME/.rnd | ||
10 | |||
11 | # Extra OBJECT IDENTIFIER info: | ||
12 | #oid_file = $ENV::HOME/.oid | ||
13 | oid_section = new_oids | ||
14 | |||
15 | # To use this configuration file with the "-extfile" option of the | ||
16 | # "openssl x509" utility, name here the section containing the | ||
17 | # X.509v3 extensions to use: | ||
18 | # extensions = | ||
19 | # (Alternatively, use a configuration file that has only | ||
20 | # X.509v3 extensions in its main [= default] section.) | ||
21 | |||
22 | [ new_oids ] | ||
23 | |||
24 | # We can add new OIDs in here for use by 'ca' and 'req'. | ||
25 | # Add a simple OID like this: | ||
26 | # testoid1=1.2.3.4 | ||
27 | # Or use config file substitution like this: | ||
28 | # testoid2=${testoid1}.5.6 | ||
29 | |||
30 | #################################################################### | ||
31 | [ ca ] | ||
32 | default_ca = CA_default # The default ca section | ||
33 | |||
34 | #################################################################### | ||
35 | [ CA_default ] | ||
36 | |||
37 | dir = ./demoCA # Where everything is kept | ||
38 | certs = $dir/certs # Where the issued certs are kept | ||
39 | crl_dir = $dir/crl # Where the issued crl are kept | ||
40 | database = $dir/index.txt # database index file. | ||
41 | #unique_subject = no # Set to 'no' to allow creation of | ||
42 | # several ctificates with same subject. | ||
43 | new_certs_dir = $dir/newcerts # default place for new certs. | ||
44 | |||
45 | certificate = $dir/cacert.pem # The CA certificate | ||
46 | serial = $dir/serial # The current serial number | ||
47 | #crlnumber = $dir/crlnumber # the current crl number must be | ||
48 | # commented out to leave a V1 CRL | ||
49 | crl = $dir/crl.pem # The current CRL | ||
50 | private_key = $dir/private/cakey.pem# The private key | ||
51 | RANDFILE = $dir/private/.rand # private random number file | ||
52 | |||
53 | x509_extensions = usr_cert # The extentions to add to the cert | ||
54 | |||
55 | # Comment out the following two lines for the "traditional" | ||
56 | # (and highly broken) format. | ||
57 | name_opt = ca_default # Subject Name options | ||
58 | cert_opt = ca_default # Certificate field options | ||
59 | |||
60 | # Extension copying option: use with caution. | ||
61 | # copy_extensions = copy | ||
62 | |||
63 | # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs | ||
64 | # so this is commented out by default to leave a V1 CRL. | ||
65 | # crlnumber must also be commented out to leave a V1 CRL. | ||
66 | # crl_extensions = crl_ext | ||
67 | |||
68 | default_days = 365 # how long to certify for | ||
69 | default_crl_days= 30 # how long before next CRL | ||
70 | default_md = md5 # which md to use. | ||
71 | preserve = no # keep passed DN ordering | ||
72 | |||
73 | # A few difference way of specifying how similar the request should look | ||
74 | # For type CA, the listed attributes must be the same, and the optional | ||
75 | # and supplied fields are just that :-) | ||
76 | policy = policy_match | ||
77 | |||
78 | # For the CA policy | ||
79 | [ policy_match ] | ||
80 | countryName = match | ||
81 | stateOrProvinceName = match | ||
82 | organizationName = match | ||
83 | organizationalUnitName = optional | ||
84 | commonName = supplied | ||
85 | emailAddress = optional | ||
86 | |||
87 | # For the 'anything' policy | ||
88 | # At this point in time, you must list all acceptable 'object' | ||
89 | # types. | ||
90 | [ policy_anything ] | ||
91 | countryName = optional | ||
92 | stateOrProvinceName = optional | ||
93 | localityName = optional | ||
94 | organizationName = optional | ||
95 | organizationalUnitName = optional | ||
96 | commonName = supplied | ||
97 | emailAddress = optional | ||
98 | |||
99 | #################################################################### | ||
100 | [ req ] | ||
101 | default_bits = 1024 | ||
102 | default_keyfile = privkey.pem | ||
103 | distinguished_name = req_distinguished_name | ||
104 | attributes = req_attributes | ||
105 | x509_extensions = v3_ca # The extentions to add to the self signed cert | ||
106 | |||
107 | # Passwords for private keys if not present they will be prompted for | ||
108 | # input_password = secret | ||
109 | # output_password = secret | ||
110 | |||
111 | # This sets a mask for permitted string types. There are several options. | ||
112 | # default: PrintableString, T61String, BMPString. | ||
113 | # pkix : PrintableString, BMPString. | ||
114 | # utf8only: only UTF8Strings. | ||
115 | # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). | ||
116 | # MASK:XXXX a literal mask value. | ||
117 | # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings | ||
118 | # so use this option with caution! | ||
119 | string_mask = nombstr | ||
120 | |||
121 | # req_extensions = v3_req # The extensions to add to a certificate request | ||
122 | |||
123 | [ req_distinguished_name ] | ||
124 | countryName = Country Name (2 letter code) | ||
125 | countryName_default = AU | ||
126 | countryName_min = 2 | ||
127 | countryName_max = 2 | ||
128 | |||
129 | stateOrProvinceName = State or Province Name (full name) | ||
130 | stateOrProvinceName_default = Some-State | ||
131 | |||
132 | localityName = Locality Name (eg, city) | ||
133 | |||
134 | 0.organizationName = Organization Name (eg, company) | ||
135 | 0.organizationName_default = Internet Widgits Pty Ltd | ||
136 | |||
137 | # we can do this but it is not needed normally :-) | ||
138 | #1.organizationName = Second Organization Name (eg, company) | ||
139 | #1.organizationName_default = World Wide Web Pty Ltd | ||
140 | |||
141 | organizationalUnitName = Organizational Unit Name (eg, section) | ||
142 | #organizationalUnitName_default = | ||
143 | |||
144 | commonName = Common Name (eg, YOUR name) | ||
145 | commonName_max = 64 | ||
146 | |||
147 | emailAddress = Email Address | ||
148 | emailAddress_max = 64 | ||
149 | |||
150 | # SET-ex3 = SET extension number 3 | ||
151 | |||
152 | [ req_attributes ] | ||
153 | challengePassword = A challenge password | ||
154 | challengePassword_min = 4 | ||
155 | challengePassword_max = 20 | ||
156 | |||
157 | unstructuredName = An optional company name | ||
158 | |||
159 | [ usr_cert ] | ||
160 | |||
161 | # These extensions are added when 'ca' signs a request. | ||
162 | |||
163 | # This goes against PKIX guidelines but some CAs do it and some software | ||
164 | # requires this to avoid interpreting an end user certificate as a CA. | ||
165 | |||
166 | basicConstraints=CA:FALSE | ||
167 | |||
168 | # Here are some examples of the usage of nsCertType. If it is omitted | ||
169 | # the certificate can be used for anything *except* object signing. | ||
170 | |||
171 | # This is OK for an SSL server. | ||
172 | # nsCertType = server | ||
173 | |||
174 | # For an object signing certificate this would be used. | ||
175 | # nsCertType = objsign | ||
176 | |||
177 | # For normal client use this is typical | ||
178 | # nsCertType = client, email | ||
179 | |||
180 | # and for everything including object signing: | ||
181 | # nsCertType = client, email, objsign | ||
182 | |||
183 | # This is typical in keyUsage for a client certificate. | ||
184 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
185 | |||
186 | # This will be displayed in Netscape's comment listbox. | ||
187 | nsComment = "OpenSSL Generated Certificate" | ||
188 | |||
189 | # PKIX recommendations harmless if included in all certificates. | ||
190 | subjectKeyIdentifier=hash | ||
191 | authorityKeyIdentifier=keyid,issuer:always | ||
192 | |||
193 | # This stuff is for subjectAltName and issuerAltname. | ||
194 | # Import the email address. | ||
195 | # subjectAltName=email:copy | ||
196 | # An alternative to produce certificates that aren't | ||
197 | # deprecated according to PKIX. | ||
198 | # subjectAltName=email:move | ||
199 | |||
200 | # Copy subject details | ||
201 | # issuerAltName=issuer:copy | ||
202 | |||
203 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem | ||
204 | #nsBaseUrl | ||
205 | #nsRevocationUrl | ||
206 | #nsRenewalUrl | ||
207 | #nsCaPolicyUrl | ||
208 | #nsSslServerName | ||
209 | |||
210 | [ v3_req ] | ||
211 | |||
212 | # Extensions to add to a certificate request | ||
213 | |||
214 | basicConstraints = CA:FALSE | ||
215 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
216 | |||
217 | [ v3_ca ] | ||
218 | |||
219 | |||
220 | # Extensions for a typical CA | ||
221 | |||
222 | |||
223 | # PKIX recommendation. | ||
224 | |||
225 | subjectKeyIdentifier=hash | ||
226 | |||
227 | authorityKeyIdentifier=keyid:always,issuer:always | ||
228 | |||
229 | # This is what PKIX recommends but some broken software chokes on critical | ||
230 | # extensions. | ||
231 | #basicConstraints = critical,CA:true | ||
232 | # So we do this instead. | ||
233 | basicConstraints = CA:true | ||
234 | |||
235 | # Key usage: this is typical for a CA certificate. However since it will | ||
236 | # prevent it being used as an test self-signed certificate it is best | ||
237 | # left out by default. | ||
238 | # keyUsage = cRLSign, keyCertSign | ||
239 | |||
240 | # Some might want this also | ||
241 | # nsCertType = sslCA, emailCA | ||
242 | |||
243 | # Include email address in subject alt name: another PKIX recommendation | ||
244 | # subjectAltName=email:copy | ||
245 | # Copy issuer details | ||
246 | # issuerAltName=issuer:copy | ||
247 | |||
248 | # DER hex encoding of an extension: beware experts only! | ||
249 | # obj=DER:02:03 | ||
250 | # Where 'obj' is a standard or added object | ||
251 | # You can even override a supported extension: | ||
252 | # basicConstraints= critical, DER:30:03:01:01:FF | ||
253 | |||
254 | [ crl_ext ] | ||
255 | |||
256 | # CRL extensions. | ||
257 | # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. | ||
258 | |||
259 | # issuerAltName=issuer:copy | ||
260 | authorityKeyIdentifier=keyid:always,issuer:always | ||
261 | |||
262 | [ proxy_cert_ext ] | ||
263 | # These extensions should be added when creating a proxy certificate | ||
264 | |||
265 | # This goes against PKIX guidelines but some CAs do it and some software | ||
266 | # requires this to avoid interpreting an end user certificate as a CA. | ||
267 | |||
268 | basicConstraints=CA:FALSE | ||
269 | |||
270 | # Here are some examples of the usage of nsCertType. If it is omitted | ||
271 | # the certificate can be used for anything *except* object signing. | ||
272 | |||
273 | # This is OK for an SSL server. | ||
274 | # nsCertType = server | ||
275 | |||
276 | # For an object signing certificate this would be used. | ||
277 | # nsCertType = objsign | ||
278 | |||
279 | # For normal client use this is typical | ||
280 | # nsCertType = client, email | ||
281 | |||
282 | # and for everything including object signing: | ||
283 | # nsCertType = client, email, objsign | ||
284 | |||
285 | # This is typical in keyUsage for a client certificate. | ||
286 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
287 | |||
288 | # This will be displayed in Netscape's comment listbox. | ||
289 | nsComment = "OpenSSL Generated Certificate" | ||
290 | |||
291 | # PKIX recommendations harmless if included in all certificates. | ||
292 | subjectKeyIdentifier=hash | ||
293 | authorityKeyIdentifier=keyid,issuer:always | ||
294 | |||
295 | # This stuff is for subjectAltName and issuerAltname. | ||
296 | # Import the email address. | ||
297 | # subjectAltName=email:copy | ||
298 | # An alternative to produce certificates that aren't | ||
299 | # deprecated according to PKIX. | ||
300 | # subjectAltName=email:move | ||
301 | |||
302 | # Copy subject details | ||
303 | # issuerAltName=issuer:copy | ||
304 | |||
305 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem | ||
306 | #nsBaseUrl | ||
307 | #nsRevocationUrl | ||
308 | #nsRenewalUrl | ||
309 | #nsCaPolicyUrl | ||
310 | #nsSslServerName | ||
311 | |||
312 | # This really needs to be in place for it to be a proxy certificate. | ||
313 | proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo | ||
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt deleted file mode 100644 index 432a17b66c..0000000000 --- a/src/lib/libssl/doc/openssl.txt +++ /dev/null | |||
@@ -1,1235 +0,0 @@ | |||
1 | |||
2 | This is some preliminary documentation for OpenSSL. | ||
3 | |||
4 | Contents: | ||
5 | |||
6 | OpenSSL X509V3 extension configuration | ||
7 | X509V3 Extension code: programmers guide | ||
8 | PKCS#12 Library | ||
9 | |||
10 | |||
11 | ============================================================================== | ||
12 | OpenSSL X509V3 extension configuration | ||
13 | ============================================================================== | ||
14 | |||
15 | OpenSSL X509V3 extension configuration: preliminary documentation. | ||
16 | |||
17 | INTRODUCTION. | ||
18 | |||
19 | For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now | ||
20 | possible to add and print out common X509 V3 certificate and CRL extensions. | ||
21 | |||
22 | BEGINNERS NOTE | ||
23 | |||
24 | For most simple applications you don't need to know too much about extensions: | ||
25 | the default openssl.cnf values will usually do sensible things. | ||
26 | |||
27 | If you want to know more you can initially quickly look through the sections | ||
28 | describing how the standard OpenSSL utilities display and add extensions and | ||
29 | then the list of supported extensions. | ||
30 | |||
31 | For more technical information about the meaning of extensions see: | ||
32 | |||
33 | http://www.imc.org/ietf-pkix/ | ||
34 | http://home.netscape.com/eng/security/certs.html | ||
35 | |||
36 | PRINTING EXTENSIONS. | ||
37 | |||
38 | Extension values are automatically printed out for supported extensions. | ||
39 | |||
40 | openssl x509 -in cert.pem -text | ||
41 | openssl crl -in crl.pem -text | ||
42 | |||
43 | will give information in the extension printout, for example: | ||
44 | |||
45 | X509v3 extensions: | ||
46 | X509v3 Basic Constraints: | ||
47 | CA:TRUE | ||
48 | X509v3 Subject Key Identifier: | ||
49 | 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15 | ||
50 | X509v3 Authority Key Identifier: | ||
51 | keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00 | ||
52 | X509v3 Key Usage: | ||
53 | Certificate Sign, CRL Sign | ||
54 | X509v3 Subject Alternative Name: | ||
55 | email:email@1.address, email:email@2.address | ||
56 | |||
57 | CONFIGURATION FILES. | ||
58 | |||
59 | The OpenSSL utilities 'ca' and 'req' can now have extension sections listing | ||
60 | which certificate extensions to include. In each case a line: | ||
61 | |||
62 | x509_extensions = extension_section | ||
63 | |||
64 | indicates which section contains the extensions. In the case of 'req' the | ||
65 | extension section is used when the -x509 option is present to create a | ||
66 | self signed root certificate. | ||
67 | |||
68 | The 'x509' utility also supports extensions when it signs a certificate. | ||
69 | The -extfile option is used to set the configuration file containing the | ||
70 | extensions. In this case a line with: | ||
71 | |||
72 | extensions = extension_section | ||
73 | |||
74 | in the nameless (default) section is used. If no such line is included then | ||
75 | it uses the default section. | ||
76 | |||
77 | You can also add extensions to CRLs: a line | ||
78 | |||
79 | crl_extensions = crl_extension_section | ||
80 | |||
81 | will include extensions when the -gencrl option is used with the 'ca' utility. | ||
82 | You can add any extension to a CRL but of the supported extensions only | ||
83 | issuerAltName and authorityKeyIdentifier make any real sense. Note: these are | ||
84 | CRL extensions NOT CRL *entry* extensions which cannot currently be generated. | ||
85 | CRL entry extensions can be displayed. | ||
86 | |||
87 | NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL | ||
88 | you should not include a crl_extensions line in the configuration file. | ||
89 | |||
90 | As with all configuration files you can use the inbuilt environment expansion | ||
91 | to allow the values to be passed in the environment. Therefore if you have | ||
92 | several extension sections used for different purposes you can have a line: | ||
93 | |||
94 | x509_extensions = $ENV::ENV_EXT | ||
95 | |||
96 | and set the ENV_EXT environment variable before calling the relevant utility. | ||
97 | |||
98 | EXTENSION SYNTAX. | ||
99 | |||
100 | Extensions have the basic form: | ||
101 | |||
102 | extension_name=[critical,] extension_options | ||
103 | |||
104 | the use of the critical option makes the extension critical. Extreme caution | ||
105 | should be made when using the critical flag. If an extension is marked | ||
106 | as critical then any client that does not understand the extension should | ||
107 | reject it as invalid. Some broken software will reject certificates which | ||
108 | have *any* critical extensions (these violates PKIX but we have to live | ||
109 | with it). | ||
110 | |||
111 | There are three main types of extension: string extensions, multi-valued | ||
112 | extensions, and raw extensions. | ||
113 | |||
114 | String extensions simply have a string which contains either the value itself | ||
115 | or how it is obtained. | ||
116 | |||
117 | For example: | ||
118 | |||
119 | nsComment="This is a Comment" | ||
120 | |||
121 | Multi-valued extensions have a short form and a long form. The short form | ||
122 | is a list of names and values: | ||
123 | |||
124 | basicConstraints=critical,CA:true,pathlen:1 | ||
125 | |||
126 | The long form allows the values to be placed in a separate section: | ||
127 | |||
128 | basicConstraints=critical,@bs_section | ||
129 | |||
130 | [bs_section] | ||
131 | |||
132 | CA=true | ||
133 | pathlen=1 | ||
134 | |||
135 | Both forms are equivalent. However it should be noted that in some cases the | ||
136 | same name can appear multiple times, for example, | ||
137 | |||
138 | subjectAltName=email:steve@here,email:steve@there | ||
139 | |||
140 | in this case an equivalent long form is: | ||
141 | |||
142 | subjectAltName=@alt_section | ||
143 | |||
144 | [alt_section] | ||
145 | |||
146 | email.1=steve@here | ||
147 | email.2=steve@there | ||
148 | |||
149 | This is because the configuration file code cannot handle the same name | ||
150 | occurring twice in the same section. | ||
151 | |||
152 | The syntax of raw extensions is governed by the extension code: it can | ||
153 | for example contain data in multiple sections. The correct syntax to | ||
154 | use is defined by the extension code itself: check out the certificate | ||
155 | policies extension for an example. | ||
156 | |||
157 | In addition it is also possible to use the word DER to include arbitrary | ||
158 | data in any extension. | ||
159 | |||
160 | 1.2.3.4=critical,DER:01:02:03:04 | ||
161 | 1.2.3.4=DER:01020304 | ||
162 | |||
163 | The value following DER is a hex dump of the DER encoding of the extension | ||
164 | Any extension can be placed in this form to override the default behaviour. | ||
165 | For example: | ||
166 | |||
167 | basicConstraints=critical,DER:00:01:02:03 | ||
168 | |||
169 | WARNING: DER should be used with caution. It is possible to create totally | ||
170 | invalid extensions unless care is taken. | ||
171 | |||
172 | CURRENTLY SUPPORTED EXTENSIONS. | ||
173 | |||
174 | If you aren't sure about extensions then they can be largely ignored: its only | ||
175 | when you want to do things like restrict certificate usage when you need to | ||
176 | worry about them. | ||
177 | |||
178 | The only extension that a beginner might want to look at is Basic Constraints. | ||
179 | If in addition you want to try Netscape object signing the you should also | ||
180 | look at Netscape Certificate Type. | ||
181 | |||
182 | Literal String extensions. | ||
183 | |||
184 | In each case the 'value' of the extension is placed directly in the | ||
185 | extension. Currently supported extensions in this category are: nsBaseUrl, | ||
186 | nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl, | ||
187 | nsSslServerName and nsComment. | ||
188 | |||
189 | For example: | ||
190 | |||
191 | nsComment="This is a test comment" | ||
192 | |||
193 | Bit Strings. | ||
194 | |||
195 | Bit string extensions just consist of a list of supported bits, currently | ||
196 | two extensions are in this category: PKIX keyUsage and the Netscape specific | ||
197 | nsCertType. | ||
198 | |||
199 | nsCertType (netscape certificate type) takes the flags: client, server, email, | ||
200 | objsign, reserved, sslCA, emailCA, objCA. | ||
201 | |||
202 | keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation, | ||
203 | keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign, | ||
204 | encipherOnly, decipherOnly. | ||
205 | |||
206 | For example: | ||
207 | |||
208 | nsCertType=server | ||
209 | |||
210 | keyUsage=digitalSignature, nonRepudiation | ||
211 | |||
212 | Hints on Netscape Certificate Type. | ||
213 | |||
214 | Other than Basic Constraints this is the only extension a beginner might | ||
215 | want to use, if you want to try Netscape object signing, otherwise it can | ||
216 | be ignored. | ||
217 | |||
218 | If you want a certificate that can be used just for object signing then: | ||
219 | |||
220 | nsCertType=objsign | ||
221 | |||
222 | will do the job. If you want to use it as a normal end user and server | ||
223 | certificate as well then | ||
224 | |||
225 | nsCertType=objsign,email,server | ||
226 | |||
227 | is more appropriate. You cannot use a self signed certificate for object | ||
228 | signing (well Netscape signtool can but it cheats!) so you need to create | ||
229 | a CA certificate and sign an end user certificate with it. | ||
230 | |||
231 | Side note: If you want to conform to the Netscape specifications then you | ||
232 | should really also set: | ||
233 | |||
234 | nsCertType=objCA | ||
235 | |||
236 | in the *CA* certificate for just an object signing CA and | ||
237 | |||
238 | nsCertType=objCA,emailCA,sslCA | ||
239 | |||
240 | for everything. Current Netscape software doesn't enforce this so it can | ||
241 | be omitted. | ||
242 | |||
243 | Basic Constraints. | ||
244 | |||
245 | This is generally the only extension you need to worry about for simple | ||
246 | applications. If you want your certificate to be usable as a CA certificate | ||
247 | (in addition to an end user certificate) then you set this to: | ||
248 | |||
249 | basicConstraints=CA:TRUE | ||
250 | |||
251 | if you want to be certain the certificate cannot be used as a CA then do: | ||
252 | |||
253 | basicConstraints=CA:FALSE | ||
254 | |||
255 | The rest of this section describes more advanced usage. | ||
256 | |||
257 | Basic constraints is a multi-valued extension that supports a CA and an | ||
258 | optional pathlen option. The CA option takes the values true and false and | ||
259 | pathlen takes an integer. Note if the CA option is false the pathlen option | ||
260 | should be omitted. | ||
261 | |||
262 | The pathlen parameter indicates the maximum number of CAs that can appear | ||
263 | below this one in a chain. So if you have a CA with a pathlen of zero it can | ||
264 | only be used to sign end user certificates and not further CAs. This all | ||
265 | assumes that the software correctly interprets this extension of course. | ||
266 | |||
267 | Examples: | ||
268 | |||
269 | basicConstraints=CA:TRUE | ||
270 | basicConstraints=critical,CA:TRUE, pathlen:0 | ||
271 | |||
272 | NOTE: for a CA to be considered valid it must have the CA option set to | ||
273 | TRUE. An end user certificate MUST NOT have the CA value set to true. | ||
274 | According to PKIX recommendations it should exclude the extension entirely, | ||
275 | however some software may require CA set to FALSE for end entity certificates. | ||
276 | |||
277 | Extended Key Usage. | ||
278 | |||
279 | This extensions consists of a list of usages. | ||
280 | |||
281 | These can either be object short names of the dotted numerical form of OIDs. | ||
282 | While any OID can be used only certain values make sense. In particular the | ||
283 | following PKIX, NS and MS values are meaningful: | ||
284 | |||
285 | Value Meaning | ||
286 | ----- ------- | ||
287 | serverAuth SSL/TLS Web Server Authentication. | ||
288 | clientAuth SSL/TLS Web Client Authentication. | ||
289 | codeSigning Code signing. | ||
290 | emailProtection E-mail Protection (S/MIME). | ||
291 | timeStamping Trusted Timestamping | ||
292 | msCodeInd Microsoft Individual Code Signing (authenticode) | ||
293 | msCodeCom Microsoft Commercial Code Signing (authenticode) | ||
294 | msCTLSign Microsoft Trust List Signing | ||
295 | msSGC Microsoft Server Gated Crypto | ||
296 | msEFS Microsoft Encrypted File System | ||
297 | nsSGC Netscape Server Gated Crypto | ||
298 | |||
299 | For example, under IE5 a CA can be used for any purpose: by including a list | ||
300 | of the above usages the CA can be restricted to only authorised uses. | ||
301 | |||
302 | Note: software packages may place additional interpretations on certificate | ||
303 | use, in particular some usages may only work for selected CAs. Don't for example | ||
304 | expect just including msSGC or nsSGC will automatically mean that a certificate | ||
305 | can be used for SGC ("step up" encryption) otherwise anyone could use it. | ||
306 | |||
307 | Examples: | ||
308 | |||
309 | extendedKeyUsage=critical,codeSigning,1.2.3.4 | ||
310 | extendedKeyUsage=nsSGC,msSGC | ||
311 | |||
312 | Subject Key Identifier. | ||
313 | |||
314 | This is really a string extension and can take two possible values. Either | ||
315 | a hex string giving details of the extension value to include or the word | ||
316 | 'hash' which then automatically follow PKIX guidelines in selecting and | ||
317 | appropriate key identifier. The use of the hex string is strongly discouraged. | ||
318 | |||
319 | Example: subjectKeyIdentifier=hash | ||
320 | |||
321 | Authority Key Identifier. | ||
322 | |||
323 | The authority key identifier extension permits two options. keyid and issuer: | ||
324 | both can take the optional value "always". | ||
325 | |||
326 | If the keyid option is present an attempt is made to copy the subject key | ||
327 | identifier from the parent certificate. If the value "always" is present | ||
328 | then an error is returned if the option fails. | ||
329 | |||
330 | The issuer option copies the issuer and serial number from the issuer | ||
331 | certificate. Normally this will only be done if the keyid option fails or | ||
332 | is not included: the "always" flag will always include the value. | ||
333 | |||
334 | Subject Alternative Name. | ||
335 | |||
336 | The subject alternative name extension allows various literal values to be | ||
337 | included in the configuration file. These include "email" (an email address) | ||
338 | "URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a | ||
339 | registered ID: OBJECT IDENTIFIER) and IP (and IP address). | ||
340 | |||
341 | Also the email option include a special 'copy' value. This will automatically | ||
342 | include and email addresses contained in the certificate subject name in | ||
343 | the extension. | ||
344 | |||
345 | Examples: | ||
346 | |||
347 | subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/ | ||
348 | subjectAltName=email:my@other.address,RID:1.2.3.4 | ||
349 | |||
350 | Issuer Alternative Name. | ||
351 | |||
352 | The issuer alternative name option supports all the literal options of | ||
353 | subject alternative name. It does *not* support the email:copy option because | ||
354 | that would not make sense. It does support an additional issuer:copy option | ||
355 | that will copy all the subject alternative name values from the issuer | ||
356 | certificate (if possible). | ||
357 | |||
358 | Example: | ||
359 | |||
360 | issuserAltName = issuer:copy | ||
361 | |||
362 | Authority Info Access. | ||
363 | |||
364 | The authority information access extension gives details about how to access | ||
365 | certain information relating to the CA. Its syntax is accessOID;location | ||
366 | where 'location' has the same syntax as subject alternative name (except | ||
367 | that email:copy is not supported). accessOID can be any valid OID but only | ||
368 | certain values are meaningful for example OCSP and caIssuers. OCSP gives the | ||
369 | location of an OCSP responder: this is used by Netscape PSM and other software. | ||
370 | |||
371 | Example: | ||
372 | |||
373 | authorityInfoAccess = OCSP;URI:http://ocsp.my.host/ | ||
374 | authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html | ||
375 | |||
376 | CRL distribution points. | ||
377 | |||
378 | This is a multi-valued extension that supports all the literal options of | ||
379 | subject alternative name. Of the few software packages that currently interpret | ||
380 | this extension most only interpret the URI option. | ||
381 | |||
382 | Currently each option will set a new DistributionPoint with the fullName | ||
383 | field set to the given value. | ||
384 | |||
385 | Other fields like cRLissuer and reasons cannot currently be set or displayed: | ||
386 | at this time no examples were available that used these fields. | ||
387 | |||
388 | If you see this extension with <UNSUPPORTED> when you attempt to print it out | ||
389 | or it doesn't appear to display correctly then let me know, including the | ||
390 | certificate (mail me at steve@openssl.org) . | ||
391 | |||
392 | Examples: | ||
393 | |||
394 | crlDistributionPoints=URI:http://www.myhost.com/myca.crl | ||
395 | crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl | ||
396 | |||
397 | Certificate Policies. | ||
398 | |||
399 | This is a RAW extension. It attempts to display the contents of this extension: | ||
400 | unfortunately this extension is often improperly encoded. | ||
401 | |||
402 | The certificate policies extension will rarely be used in practice: few | ||
403 | software packages interpret it correctly or at all. IE5 does partially | ||
404 | support this extension: but it needs the 'ia5org' option because it will | ||
405 | only correctly support a broken encoding. Of the options below only the | ||
406 | policy OID, explicitText and CPS options are displayed with IE5. | ||
407 | |||
408 | All the fields of this extension can be set by using the appropriate syntax. | ||
409 | |||
410 | If you follow the PKIX recommendations of not including any qualifiers and just | ||
411 | using only one OID then you just include the value of that OID. Multiple OIDs | ||
412 | can be set separated by commas, for example: | ||
413 | |||
414 | certificatePolicies= 1.2.4.5, 1.1.3.4 | ||
415 | |||
416 | If you wish to include qualifiers then the policy OID and qualifiers need to | ||
417 | be specified in a separate section: this is done by using the @section syntax | ||
418 | instead of a literal OID value. | ||
419 | |||
420 | The section referred to must include the policy OID using the name | ||
421 | policyIdentifier, cPSuri qualifiers can be included using the syntax: | ||
422 | |||
423 | CPS.nnn=value | ||
424 | |||
425 | userNotice qualifiers can be set using the syntax: | ||
426 | |||
427 | userNotice.nnn=@notice | ||
428 | |||
429 | The value of the userNotice qualifier is specified in the relevant section. | ||
430 | This section can include explicitText, organization and noticeNumbers | ||
431 | options. explicitText and organization are text strings, noticeNumbers is a | ||
432 | comma separated list of numbers. The organization and noticeNumbers options | ||
433 | (if included) must BOTH be present. If you use the userNotice option with IE5 | ||
434 | then you need the 'ia5org' option at the top level to modify the encoding: | ||
435 | otherwise it will not be interpreted properly. | ||
436 | |||
437 | Example: | ||
438 | |||
439 | certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect | ||
440 | |||
441 | [polsect] | ||
442 | |||
443 | policyIdentifier = 1.3.5.8 | ||
444 | CPS.1="http://my.host.name/" | ||
445 | CPS.2="http://my.your.name/" | ||
446 | userNotice.1=@notice | ||
447 | |||
448 | [notice] | ||
449 | |||
450 | explicitText="Explicit Text Here" | ||
451 | organization="Organisation Name" | ||
452 | noticeNumbers=1,2,3,4 | ||
453 | |||
454 | TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field, | ||
455 | according to PKIX it should be of type DisplayText but Verisign uses an | ||
456 | IA5STRING and IE5 needs this too. | ||
457 | |||
458 | Display only extensions. | ||
459 | |||
460 | Some extensions are only partially supported and currently are only displayed | ||
461 | but cannot be set. These include private key usage period, CRL number, and | ||
462 | CRL reason. | ||
463 | |||
464 | ============================================================================== | ||
465 | X509V3 Extension code: programmers guide | ||
466 | ============================================================================== | ||
467 | |||
468 | The purpose of the extension code is twofold. It allows an extension to be | ||
469 | created from a string or structure describing its contents and it prints out an | ||
470 | extension in a human or machine readable form. | ||
471 | |||
472 | 1. Initialisation and cleanup. | ||
473 | |||
474 | No special initialisation is needed before calling the extension functions. | ||
475 | You used to have to call X509V3_add_standard_extensions(); but this is no longer | ||
476 | required and this function no longer does anything. | ||
477 | |||
478 | void X509V3_EXT_cleanup(void); | ||
479 | |||
480 | This function should be called to cleanup the extension code if any custom | ||
481 | extensions have been added. If no custom extensions have been added then this | ||
482 | call does nothing. After this call all custom extension code is freed up but | ||
483 | you can still use the standard extensions. | ||
484 | |||
485 | 2. Printing and parsing extensions. | ||
486 | |||
487 | The simplest way to print out extensions is via the standard X509 printing | ||
488 | routines: if you use the standard X509_print() function, the supported | ||
489 | extensions will be printed out automatically. | ||
490 | |||
491 | The following functions allow finer control over extension display: | ||
492 | |||
493 | int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent); | ||
494 | int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); | ||
495 | |||
496 | These two functions print out an individual extension to a BIO or FILE pointer. | ||
497 | Currently the flag argument is unused and should be set to 0. The 'indent' | ||
498 | argument is the number of spaces to indent each line. | ||
499 | |||
500 | void *X509V3_EXT_d2i(X509_EXTENSION *ext); | ||
501 | |||
502 | This function parses an extension and returns its internal structure. The | ||
503 | precise structure you get back depends on the extension being parsed. If the | ||
504 | extension if basicConstraints you will get back a pointer to a | ||
505 | BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more | ||
506 | details about the structures returned. The returned structure should be freed | ||
507 | after use using the relevant free function, BASIC_CONSTRAINTS_free() for | ||
508 | example. | ||
509 | |||
510 | void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx); | ||
511 | void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx); | ||
512 | void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx); | ||
513 | void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx); | ||
514 | |||
515 | These functions combine the operations of searching for extensions and | ||
516 | parsing them. They search a certificate, a CRL a CRL entry or a stack | ||
517 | of extensions respectively for extension whose NID is 'nid' and return | ||
518 | the parsed result of NULL if an error occurred. For example: | ||
519 | |||
520 | BASIC_CONSTRAINTS *bs; | ||
521 | bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL); | ||
522 | |||
523 | This will search for the basicConstraints extension and either return | ||
524 | it value or NULL. NULL can mean either the extension was not found, it | ||
525 | occurred more than once or it could not be parsed. | ||
526 | |||
527 | If 'idx' is NULL then an extension is only parsed if it occurs precisely | ||
528 | once. This is standard behaviour because extensions normally cannot occur | ||
529 | more than once. If however more than one extension of the same type can | ||
530 | occur it can be used to parse successive extensions for example: | ||
531 | |||
532 | int i; | ||
533 | void *ext; | ||
534 | |||
535 | i = -1; | ||
536 | for(;;) { | ||
537 | ext = X509_get_ext_d2i(x, nid, crit, &idx); | ||
538 | if(ext == NULL) break; | ||
539 | /* Do something with ext */ | ||
540 | } | ||
541 | |||
542 | If 'crit' is not NULL and the extension was found then the int it points to | ||
543 | is set to 1 for critical extensions and 0 for non critical. Therefore if the | ||
544 | function returns NULL but 'crit' is set to 0 or 1 then the extension was | ||
545 | found but it could not be parsed. | ||
546 | |||
547 | The int pointed to by crit will be set to -1 if the extension was not found | ||
548 | and -2 if the extension occurred more than once (this will only happen if | ||
549 | idx is NULL). In both cases the function will return NULL. | ||
550 | |||
551 | 3. Generating extensions. | ||
552 | |||
553 | An extension will typically be generated from a configuration file, or some | ||
554 | other kind of configuration database. | ||
555 | |||
556 | int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, | ||
557 | X509 *cert); | ||
558 | int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, | ||
559 | X509_CRL *crl); | ||
560 | |||
561 | These functions add all the extensions in the given section to the given | ||
562 | certificate or CRL. They will normally be called just before the certificate | ||
563 | or CRL is due to be signed. Both return 0 on error on non zero for success. | ||
564 | |||
565 | In each case 'conf' is the LHASH pointer of the configuration file to use | ||
566 | and 'section' is the section containing the extension details. | ||
567 | |||
568 | See the 'context functions' section for a description of the ctx parameter. | ||
569 | |||
570 | |||
571 | X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, | ||
572 | char *value); | ||
573 | |||
574 | This function returns an extension based on a name and value pair, if the | ||
575 | pair will not need to access other sections in a config file (or there is no | ||
576 | config file) then the 'conf' parameter can be set to NULL. | ||
577 | |||
578 | X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid, | ||
579 | char *value); | ||
580 | |||
581 | This function creates an extension in the same way as X509V3_EXT_conf() but | ||
582 | takes the NID of the extension rather than its name. | ||
583 | |||
584 | For example to produce basicConstraints with the CA flag and a path length of | ||
585 | 10: | ||
586 | |||
587 | x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10"); | ||
588 | |||
589 | |||
590 | X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); | ||
591 | |||
592 | This function sets up an extension from its internal structure. The ext_nid | ||
593 | parameter is the NID of the extension and 'crit' is the critical flag. | ||
594 | |||
595 | 4. Context functions. | ||
596 | |||
597 | The following functions set and manipulate an extension context structure. | ||
598 | The purpose of the extension context is to allow the extension code to | ||
599 | access various structures relating to the "environment" of the certificate: | ||
600 | for example the issuers certificate or the certificate request. | ||
601 | |||
602 | void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, | ||
603 | X509_REQ *req, X509_CRL *crl, int flags); | ||
604 | |||
605 | This function sets up an X509V3_CTX structure with details of the certificate | ||
606 | environment: specifically the issuers certificate, the subject certificate, | ||
607 | the certificate request and the CRL: if these are not relevant or not | ||
608 | available then they can be set to NULL. The 'flags' parameter should be set | ||
609 | to zero. | ||
610 | |||
611 | X509V3_set_ctx_test(ctx) | ||
612 | |||
613 | This macro is used to set the 'ctx' structure to a 'test' value: this is to | ||
614 | allow the syntax of an extension (or configuration file) to be tested. | ||
615 | |||
616 | X509V3_set_ctx_nodb(ctx) | ||
617 | |||
618 | This macro is used when no configuration database is present. | ||
619 | |||
620 | void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash); | ||
621 | |||
622 | This function is used to set the configuration database when it is an LHASH | ||
623 | structure: typically a configuration file. | ||
624 | |||
625 | The following functions are used to access a configuration database: they | ||
626 | should only be used in RAW extensions. | ||
627 | |||
628 | char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section); | ||
629 | |||
630 | This function returns the value of the parameter "name" in "section", or NULL | ||
631 | if there has been an error. | ||
632 | |||
633 | void X509V3_string_free(X509V3_CTX *ctx, char *str); | ||
634 | |||
635 | This function frees up the string returned by the above function. | ||
636 | |||
637 | STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section); | ||
638 | |||
639 | This function returns a whole section as a STACK_OF(CONF_VALUE) . | ||
640 | |||
641 | void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); | ||
642 | |||
643 | This function frees up the STACK returned by the above function. | ||
644 | |||
645 | Note: it is possible to use the extension code with a custom configuration | ||
646 | database. To do this the "db_meth" element of the X509V3_CTX structure should | ||
647 | be set to an X509V3_CTX_METHOD structure. This structure contains the following | ||
648 | function pointers: | ||
649 | |||
650 | char * (*get_string)(void *db, char *section, char *value); | ||
651 | STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section); | ||
652 | void (*free_string)(void *db, char * string); | ||
653 | void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section); | ||
654 | |||
655 | these will be called and passed the 'db' element in the X509V3_CTX structure | ||
656 | to access the database. If a given function is not implemented or not required | ||
657 | it can be set to NULL. | ||
658 | |||
659 | 5. String helper functions. | ||
660 | |||
661 | There are several "i2s" and "s2i" functions that convert structures to and | ||
662 | from ASCII strings. In all the "i2s" cases the returned string should be | ||
663 | freed using Free() after use. Since some of these are part of other extension | ||
664 | code they may take a 'method' parameter. Unless otherwise stated it can be | ||
665 | safely set to NULL. | ||
666 | |||
667 | char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct); | ||
668 | |||
669 | This returns a hex string from an ASN1_OCTET_STRING. | ||
670 | |||
671 | char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint); | ||
672 | char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); | ||
673 | |||
674 | These return a string decimal representations of an ASN1_INTEGER and an | ||
675 | ASN1_ENUMERATED type, respectively. | ||
676 | |||
677 | ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, | ||
678 | X509V3_CTX *ctx, char *str); | ||
679 | |||
680 | This converts an ASCII hex string to an ASN1_OCTET_STRING. | ||
681 | |||
682 | ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value); | ||
683 | |||
684 | This converts a decimal ASCII string into an ASN1_INTEGER. | ||
685 | |||
686 | 6. Multi valued extension helper functions. | ||
687 | |||
688 | The following functions can be used to manipulate STACKs of CONF_VALUE | ||
689 | structures, as used by multi valued extensions. | ||
690 | |||
691 | int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool); | ||
692 | |||
693 | This function expects a boolean value in 'value' and sets 'asn1_bool' to | ||
694 | it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following | ||
695 | strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE" | ||
696 | "false", "N", "n", "NO" or "no". | ||
697 | |||
698 | int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint); | ||
699 | |||
700 | This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER. | ||
701 | |||
702 | int X509V3_add_value(const char *name, const char *value, | ||
703 | STACK_OF(CONF_VALUE) **extlist); | ||
704 | |||
705 | This simply adds a string name and value pair. | ||
706 | |||
707 | int X509V3_add_value_uchar(const char *name, const unsigned char *value, | ||
708 | STACK_OF(CONF_VALUE) **extlist); | ||
709 | |||
710 | The same as above but for an unsigned character value. | ||
711 | |||
712 | int X509V3_add_value_bool(const char *name, int asn1_bool, | ||
713 | STACK_OF(CONF_VALUE) **extlist); | ||
714 | |||
715 | This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool' | ||
716 | |||
717 | int X509V3_add_value_bool_nf(char *name, int asn1_bool, | ||
718 | STACK_OF(CONF_VALUE) **extlist); | ||
719 | |||
720 | This is the same as above except it adds nothing if asn1_bool is FALSE. | ||
721 | |||
722 | int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, | ||
723 | STACK_OF(CONF_VALUE) **extlist); | ||
724 | |||
725 | This function adds the value of the ASN1_INTEGER in decimal form. | ||
726 | |||
727 | 7. Other helper functions. | ||
728 | |||
729 | <to be added> | ||
730 | |||
731 | ADDING CUSTOM EXTENSIONS. | ||
732 | |||
733 | Currently there are three types of supported extensions. | ||
734 | |||
735 | String extensions are simple strings where the value is placed directly in the | ||
736 | extensions, and the string returned is printed out. | ||
737 | |||
738 | Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs | ||
739 | or return a STACK_OF(CONF_VALUE). | ||
740 | |||
741 | Raw extensions are just passed a BIO or a value and it is the extensions | ||
742 | responsibility to handle all the necessary printing. | ||
743 | |||
744 | There are two ways to add an extension. One is simply as an alias to an already | ||
745 | existing extension. An alias is an extension that is identical in ASN1 structure | ||
746 | to an existing extension but has a different OBJECT IDENTIFIER. This can be | ||
747 | done by calling: | ||
748 | |||
749 | int X509V3_EXT_add_alias(int nid_to, int nid_from); | ||
750 | |||
751 | 'nid_to' is the new extension NID and 'nid_from' is the already existing | ||
752 | extension NID. | ||
753 | |||
754 | Alternatively an extension can be written from scratch. This involves writing | ||
755 | the ASN1 code to encode and decode the extension and functions to print out and | ||
756 | generate the extension from strings. The relevant functions are then placed in | ||
757 | a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext); | ||
758 | called. | ||
759 | |||
760 | The X509V3_EXT_METHOD structure is described below. | ||
761 | |||
762 | strut { | ||
763 | int ext_nid; | ||
764 | int ext_flags; | ||
765 | X509V3_EXT_NEW ext_new; | ||
766 | X509V3_EXT_FREE ext_free; | ||
767 | X509V3_EXT_D2I d2i; | ||
768 | X509V3_EXT_I2D i2d; | ||
769 | X509V3_EXT_I2S i2s; | ||
770 | X509V3_EXT_S2I s2i; | ||
771 | X509V3_EXT_I2V i2v; | ||
772 | X509V3_EXT_V2I v2i; | ||
773 | X509V3_EXT_R2I r2i; | ||
774 | X509V3_EXT_I2R i2r; | ||
775 | |||
776 | void *usr_data; | ||
777 | }; | ||
778 | |||
779 | The elements have the following meanings. | ||
780 | |||
781 | ext_nid is the NID of the object identifier of the extension. | ||
782 | |||
783 | ext_flags is set of flags. Currently the only external flag is | ||
784 | X509V3_EXT_MULTILINE which means a multi valued extensions | ||
785 | should be printed on separate lines. | ||
786 | |||
787 | usr_data is an extension specific pointer to any relevant data. This | ||
788 | allows extensions to share identical code but have different | ||
789 | uses. An example of this is the bit string extension which uses | ||
790 | usr_data to contain a list of the bit names. | ||
791 | |||
792 | All the remaining elements are function pointers. | ||
793 | |||
794 | ext_new is a pointer to a function that allocates memory for the | ||
795 | extension ASN1 structure: for example ASN1_OBJECT_new(). | ||
796 | |||
797 | ext_free is a pointer to a function that free up memory of the extension | ||
798 | ASN1 structure: for example ASN1_OBJECT_free(). | ||
799 | |||
800 | d2i is the standard ASN1 function that converts a DER buffer into | ||
801 | the internal ASN1 structure: for example d2i_ASN1_IA5STRING(). | ||
802 | |||
803 | i2d is the standard ASN1 function that converts the internal | ||
804 | structure into the DER representation: for example | ||
805 | i2d_ASN1_IA5STRING(). | ||
806 | |||
807 | The remaining functions are depend on the type of extension. One i2X and | ||
808 | one X2i should be set and the rest set to NULL. The types set do not need | ||
809 | to match up, for example the extension could be set using the multi valued | ||
810 | v2i function and printed out using the raw i2r. | ||
811 | |||
812 | All functions have the X509V3_EXT_METHOD passed to them in the 'method' | ||
813 | parameter and an X509V3_CTX structure. Extension code can then access the | ||
814 | parent structure via the 'method' parameter to for example make use of the value | ||
815 | of usr_data. If the code needs to use detail relating to the request it can | ||
816 | use the 'ctx' parameter. | ||
817 | |||
818 | A note should be given here about the 'flags' member of the 'ctx' parameter. | ||
819 | If it has the value CTX_TEST then the configuration syntax is being checked | ||
820 | and no actual certificate or CRL exists. Therefore any attempt in the config | ||
821 | file to access such information should silently succeed. If the syntax is OK | ||
822 | then it should simply return a (possibly bogus) extension, otherwise it | ||
823 | should return NULL. | ||
824 | |||
825 | char *i2s(struct v3_ext_method *method, void *ext); | ||
826 | |||
827 | This function takes the internal structure in the ext parameter and returns | ||
828 | a Malloc'ed string representing its value. | ||
829 | |||
830 | void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); | ||
831 | |||
832 | This function takes the string representation in the ext parameter and returns | ||
833 | an allocated internal structure: ext_free() will be used on this internal | ||
834 | structure after use. | ||
835 | |||
836 | i2v and v2i handle a STACK_OF(CONF_VALUE): | ||
837 | |||
838 | typedef struct | ||
839 | { | ||
840 | char *section; | ||
841 | char *name; | ||
842 | char *value; | ||
843 | } CONF_VALUE; | ||
844 | |||
845 | Only the name and value members are currently used. | ||
846 | |||
847 | STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext); | ||
848 | |||
849 | This function is passed the internal structure in the ext parameter and | ||
850 | returns a STACK of CONF_VALUE structures. The values of name, value, | ||
851 | section and the structure itself will be freed up with Free after use. | ||
852 | Several helper functions are available to add values to this STACK. | ||
853 | |||
854 | void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, | ||
855 | STACK_OF(CONF_VALUE) *values); | ||
856 | |||
857 | This function takes a STACK_OF(CONF_VALUE) structures and should set the | ||
858 | values of the external structure. This typically uses the name element to | ||
859 | determine which structure element to set and the value element to determine | ||
860 | what to set it to. Several helper functions are available for this | ||
861 | purpose (see above). | ||
862 | |||
863 | int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent); | ||
864 | |||
865 | This function is passed the internal extension structure in the ext parameter | ||
866 | and sends out a human readable version of the extension to out. The 'indent' | ||
867 | parameter should be noted to determine the necessary amount of indentation | ||
868 | needed on the output. | ||
869 | |||
870 | void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); | ||
871 | |||
872 | This is just passed the string representation of the extension. It is intended | ||
873 | to be used for more elaborate extensions where the standard single and multi | ||
874 | valued options are insufficient. They can use the 'ctx' parameter to parse the | ||
875 | configuration database themselves. See the context functions section for details | ||
876 | of how to do this. | ||
877 | |||
878 | Note: although this type takes the same parameters as the "r2s" function there | ||
879 | is a subtle difference. Whereas an "r2i" function can access a configuration | ||
880 | database an "s2i" function MUST NOT. This is so the internal code can safely | ||
881 | assume that an "s2i" function will work without a configuration database. | ||
882 | |||
883 | ============================================================================== | ||
884 | PKCS#12 Library | ||
885 | ============================================================================== | ||
886 | |||
887 | This section describes the internal PKCS#12 support. There are very few | ||
888 | differences between the old external library and the new internal code at | ||
889 | present. This may well change because the external library will not be updated | ||
890 | much in future. | ||
891 | |||
892 | This version now includes a couple of high level PKCS#12 functions which | ||
893 | generally "do the right thing" and should make it much easier to handle PKCS#12 | ||
894 | structures. | ||
895 | |||
896 | HIGH LEVEL FUNCTIONS. | ||
897 | |||
898 | For most applications you only need concern yourself with the high level | ||
899 | functions. They can parse and generate simple PKCS#12 files as produced by | ||
900 | Netscape and MSIE or indeed any compliant PKCS#12 file containing a single | ||
901 | private key and certificate pair. | ||
902 | |||
903 | 1. Initialisation and cleanup. | ||
904 | |||
905 | No special initialisation is needed for the internal PKCS#12 library: the | ||
906 | standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to | ||
907 | add all algorithms (you should at least add SHA1 though) then you can manually | ||
908 | initialise the PKCS#12 library with: | ||
909 | |||
910 | PKCS12_PBE_add(); | ||
911 | |||
912 | The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is | ||
913 | called or it can be directly freed with: | ||
914 | |||
915 | EVP_PBE_cleanup(); | ||
916 | |||
917 | after this call (or EVP_cleanup() ) no more PKCS#12 library functions should | ||
918 | be called. | ||
919 | |||
920 | 2. I/O functions. | ||
921 | |||
922 | i2d_PKCS12_bio(bp, p12) | ||
923 | |||
924 | This writes out a PKCS12 structure to a BIO. | ||
925 | |||
926 | i2d_PKCS12_fp(fp, p12) | ||
927 | |||
928 | This is the same but for a FILE pointer. | ||
929 | |||
930 | d2i_PKCS12_bio(bp, p12) | ||
931 | |||
932 | This reads in a PKCS12 structure from a BIO. | ||
933 | |||
934 | d2i_PKCS12_fp(fp, p12) | ||
935 | |||
936 | This is the same but for a FILE pointer. | ||
937 | |||
938 | 3. High level functions. | ||
939 | |||
940 | 3.1 Parsing with PKCS12_parse(). | ||
941 | |||
942 | int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert, | ||
943 | STACK **ca); | ||
944 | |||
945 | This function takes a PKCS12 structure and a password (ASCII, null terminated) | ||
946 | and returns the private key, the corresponding certificate and any CA | ||
947 | certificates. If any of these is not required it can be passed as a NULL. | ||
948 | The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK | ||
949 | structure. Typically to read in a PKCS#12 file you might do: | ||
950 | |||
951 | p12 = d2i_PKCS12_fp(fp, NULL); | ||
952 | PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */ | ||
953 | PKCS12_free(p12); | ||
954 | |||
955 | 3.2 PKCS#12 creation with PKCS12_create(). | ||
956 | |||
957 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
958 | STACK *ca, int nid_key, int nid_cert, int iter, | ||
959 | int mac_iter, int keytype); | ||
960 | |||
961 | This function will create a PKCS12 structure from a given password, name, | ||
962 | private key, certificate and optional STACK of CA certificates. The remaining | ||
963 | 5 parameters can be set to 0 and sensible defaults will be used. | ||
964 | |||
965 | The parameters nid_key and nid_cert are the key and certificate encryption | ||
966 | algorithms, iter is the encryption iteration count, mac_iter is the MAC | ||
967 | iteration count and keytype is the type of private key. If you really want | ||
968 | to know what these last 5 parameters do then read the low level section. | ||
969 | |||
970 | Typically to create a PKCS#12 file the following could be used: | ||
971 | |||
972 | p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0); | ||
973 | i2d_PKCS12_fp(fp, p12); | ||
974 | PKCS12_free(p12); | ||
975 | |||
976 | 3.3 Changing a PKCS#12 structure password. | ||
977 | |||
978 | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass); | ||
979 | |||
980 | This changes the password of an already existing PKCS#12 structure. oldpass | ||
981 | is the old password and newpass is the new one. An error occurs if the old | ||
982 | password is incorrect. | ||
983 | |||
984 | LOW LEVEL FUNCTIONS. | ||
985 | |||
986 | In some cases the high level functions do not provide the necessary | ||
987 | functionality. For example if you want to generate or parse more complex | ||
988 | PKCS#12 files. The sample pkcs12 application uses the low level functions | ||
989 | to display details about the internal structure of a PKCS#12 file. | ||
990 | |||
991 | Introduction. | ||
992 | |||
993 | This is a brief description of how a PKCS#12 file is represented internally: | ||
994 | some knowledge of PKCS#12 is assumed. | ||
995 | |||
996 | A PKCS#12 object contains several levels. | ||
997 | |||
998 | At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a | ||
999 | CRL, a private key, encrypted or unencrypted, a set of safebags (so the | ||
1000 | structure can be nested) or other secrets (not documented at present). | ||
1001 | A safebag can optionally have attributes, currently these are: a unicode | ||
1002 | friendlyName (a Unicode string) or a localKeyID (a string of bytes). | ||
1003 | |||
1004 | At the next level is an authSafe which is a set of safebags collected into | ||
1005 | a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself. | ||
1006 | |||
1007 | At the top level is the PKCS12 structure itself which contains a set of | ||
1008 | authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it | ||
1009 | contains a MAC which is a kind of password protected digest to preserve | ||
1010 | integrity (so any unencrypted stuff below can't be tampered with). | ||
1011 | |||
1012 | The reason for these levels is so various objects can be encrypted in various | ||
1013 | ways. For example you might want to encrypt a set of private keys with | ||
1014 | triple-DES and then include the related certificates either unencrypted or | ||
1015 | with lower encryption. Yes it's the dreaded crypto laws at work again which | ||
1016 | allow strong encryption on private keys and only weak encryption on other | ||
1017 | stuff. | ||
1018 | |||
1019 | To build one of these things you turn all certificates and keys into safebags | ||
1020 | (with optional attributes). You collect the safebags into (one or more) STACKS | ||
1021 | and convert these into authsafes (encrypted or unencrypted). The authsafes | ||
1022 | are collected into a STACK and added to a PKCS12 structure. Finally a MAC | ||
1023 | inserted. | ||
1024 | |||
1025 | Pulling one apart is basically the reverse process. The MAC is verified against | ||
1026 | the given password. The authsafes are extracted and each authsafe split into | ||
1027 | a set of safebags (possibly involving decryption). Finally the safebags are | ||
1028 | decomposed into the original keys and certificates and the attributes used to | ||
1029 | match up private key and certificate pairs. | ||
1030 | |||
1031 | Anyway here are the functions that do the dirty work. | ||
1032 | |||
1033 | 1. Construction functions. | ||
1034 | |||
1035 | 1.1 Safebag functions. | ||
1036 | |||
1037 | M_PKCS12_x5092certbag(x509) | ||
1038 | |||
1039 | This macro takes an X509 structure and returns a certificate bag. The | ||
1040 | X509 structure can be freed up after calling this function. | ||
1041 | |||
1042 | M_PKCS12_x509crl2certbag(crl) | ||
1043 | |||
1044 | As above but for a CRL. | ||
1045 | |||
1046 | PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey) | ||
1047 | |||
1048 | Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure. | ||
1049 | Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo | ||
1050 | structure contains a private key data in plain text form it should be free'd | ||
1051 | up as soon as it has been encrypted for security reasons (freeing up the | ||
1052 | structure zeros out the sensitive data). This can be done with | ||
1053 | PKCS8_PRIV_KEY_INFO_free(). | ||
1054 | |||
1055 | PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) | ||
1056 | |||
1057 | This sets the key type when a key is imported into MSIE or Outlook 98. Two | ||
1058 | values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type | ||
1059 | key that can also be used for signing but its size is limited in the export | ||
1060 | versions of MS software to 512 bits, it is also the default. KEY_SIG is a | ||
1061 | signing only key but the keysize is unlimited (well 16K is supposed to work). | ||
1062 | If you are using the domestic version of MSIE then you can ignore this because | ||
1063 | KEY_EX is not limited and can be used for both. | ||
1064 | |||
1065 | PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8) | ||
1066 | |||
1067 | Convert a PKCS8 private key structure into a keybag. This routine embeds the | ||
1068 | p8 structure in the keybag so p8 should not be freed up or used after it is | ||
1069 | called. The p8 structure will be freed up when the safebag is freed. | ||
1070 | |||
1071 | PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8) | ||
1072 | |||
1073 | Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not | ||
1074 | embedded and can be freed up after use. | ||
1075 | |||
1076 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen) | ||
1077 | int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen) | ||
1078 | |||
1079 | Add a local key id or a friendlyname to a safebag. | ||
1080 | |||
1081 | 1.2 Authsafe functions. | ||
1082 | |||
1083 | PKCS7 *PKCS12_pack_p7data(STACK *sk) | ||
1084 | Take a stack of safebags and convert them into an unencrypted authsafe. The | ||
1085 | stack of safebags can be freed up after calling this function. | ||
1086 | |||
1087 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags); | ||
1088 | |||
1089 | As above but encrypted. | ||
1090 | |||
1091 | 1.3 PKCS12 functions. | ||
1092 | |||
1093 | PKCS12 *PKCS12_init(int mode) | ||
1094 | |||
1095 | Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data). | ||
1096 | |||
1097 | M_PKCS12_pack_authsafes(p12, safes) | ||
1098 | |||
1099 | This macro takes a STACK of authsafes and adds them to a PKCS#12 structure. | ||
1100 | |||
1101 | int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type); | ||
1102 | |||
1103 | Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests | ||
1104 | that SHA-1 should be used. | ||
1105 | |||
1106 | 2. Extraction Functions. | ||
1107 | |||
1108 | 2.1 Safebags. | ||
1109 | |||
1110 | M_PKCS12_bag_type(bag) | ||
1111 | |||
1112 | Return the type of "bag". Returns one of the following | ||
1113 | |||
1114 | NID_keyBag | ||
1115 | NID_pkcs8ShroudedKeyBag 7 | ||
1116 | NID_certBag 8 | ||
1117 | NID_crlBag 9 | ||
1118 | NID_secretBag 10 | ||
1119 | NID_safeContentsBag 11 | ||
1120 | |||
1121 | M_PKCS12_cert_bag_type(bag) | ||
1122 | |||
1123 | Returns type of certificate bag, following are understood. | ||
1124 | |||
1125 | NID_x509Certificate 14 | ||
1126 | NID_sdsiCertificate 15 | ||
1127 | |||
1128 | M_PKCS12_crl_bag_type(bag) | ||
1129 | |||
1130 | Returns crl bag type, currently only NID_crlBag is recognised. | ||
1131 | |||
1132 | M_PKCS12_certbag2x509(bag) | ||
1133 | |||
1134 | This macro extracts an X509 certificate from a certificate bag. | ||
1135 | |||
1136 | M_PKCS12_certbag2x509crl(bag) | ||
1137 | |||
1138 | As above but for a CRL. | ||
1139 | |||
1140 | EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) | ||
1141 | |||
1142 | Extract a private key from a PKCS8 private key info structure. | ||
1143 | |||
1144 | M_PKCS12_decrypt_skey(bag, pass, passlen) | ||
1145 | |||
1146 | Decrypt a shrouded key bag and return a PKCS8 private key info structure. | ||
1147 | Works with both RSA and DSA keys | ||
1148 | |||
1149 | char *PKCS12_get_friendlyname(bag) | ||
1150 | |||
1151 | Returns the friendlyName of a bag if present or NULL if none. The returned | ||
1152 | string is a null terminated ASCII string allocated with Malloc(). It should | ||
1153 | thus be freed up with Free() after use. | ||
1154 | |||
1155 | 2.2 AuthSafe functions. | ||
1156 | |||
1157 | M_PKCS12_unpack_p7data(p7) | ||
1158 | |||
1159 | Extract a STACK of safe bags from a PKCS#7 data ContentInfo. | ||
1160 | |||
1161 | #define M_PKCS12_unpack_p7encdata(p7, pass, passlen) | ||
1162 | |||
1163 | As above but for an encrypted content info. | ||
1164 | |||
1165 | 2.3 PKCS12 functions. | ||
1166 | |||
1167 | M_PKCS12_unpack_authsafes(p12) | ||
1168 | |||
1169 | Extract a STACK of authsafes from a PKCS12 structure. | ||
1170 | |||
1171 | M_PKCS12_mac_present(p12) | ||
1172 | |||
1173 | Check to see if a MAC is present. | ||
1174 | |||
1175 | int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen) | ||
1176 | |||
1177 | Verify a MAC on a PKCS12 structure. Returns an error if MAC not present. | ||
1178 | |||
1179 | |||
1180 | Notes. | ||
1181 | |||
1182 | 1. All the function return 0 or NULL on error. | ||
1183 | 2. Encryption based functions take a common set of parameters. These are | ||
1184 | described below. | ||
1185 | |||
1186 | pass, passlen | ||
1187 | ASCII password and length. The password on the MAC is called the "integrity | ||
1188 | password" the encryption password is called the "privacy password" in the | ||
1189 | PKCS#12 documentation. The passwords do not have to be the same. If -1 is | ||
1190 | passed for the length it is worked out by the function itself (currently | ||
1191 | this is sometimes done whatever is passed as the length but that may change). | ||
1192 | |||
1193 | salt, saltlen | ||
1194 | A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a | ||
1195 | default length is used. | ||
1196 | |||
1197 | iter | ||
1198 | Iteration count. This is a measure of how many times an internal function is | ||
1199 | called to encrypt the data. The larger this value is the longer it takes, it | ||
1200 | makes dictionary attacks on passwords harder. NOTE: Some implementations do | ||
1201 | not support an iteration count on the MAC. If the password for the MAC and | ||
1202 | encryption is the same then there is no point in having a high iteration | ||
1203 | count for encryption if the MAC has no count. The MAC could be attacked | ||
1204 | and the password used for the main decryption. | ||
1205 | |||
1206 | pbe_nid | ||
1207 | This is the NID of the password based encryption method used. The following are | ||
1208 | supported. | ||
1209 | NID_pbe_WithSHA1And128BitRC4 | ||
1210 | NID_pbe_WithSHA1And40BitRC4 | ||
1211 | NID_pbe_WithSHA1And3_Key_TripleDES_CBC | ||
1212 | NID_pbe_WithSHA1And2_Key_TripleDES_CBC | ||
1213 | NID_pbe_WithSHA1And128BitRC2_CBC | ||
1214 | NID_pbe_WithSHA1And40BitRC2_CBC | ||
1215 | |||
1216 | Which you use depends on the implementation you are exporting to. "Export | ||
1217 | grade" (i.e. cryptographically challenged) products cannot support all | ||
1218 | algorithms. Typically you may be able to use any encryption on shrouded key | ||
1219 | bags but they must then be placed in an unencrypted authsafe. Other authsafes | ||
1220 | may only support 40bit encryption. Of course if you are using SSLeay | ||
1221 | throughout you can strongly encrypt everything and have high iteration counts | ||
1222 | on everything. | ||
1223 | |||
1224 | 3. For decryption routines only the password and length are needed. | ||
1225 | |||
1226 | 4. Unlike the external version the nid's of objects are the values of the | ||
1227 | constants: that is NID_certBag is the real nid, therefore there is no | ||
1228 | PKCS12_obj_offset() function. Note the object constants are not the same as | ||
1229 | those of the external version. If you use these constants then you will need | ||
1230 | to recompile your code. | ||
1231 | |||
1232 | 5. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or | ||
1233 | macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be | ||
1234 | reused or freed up safely. | ||
1235 | |||
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt deleted file mode 100644 index f6675b574b..0000000000 --- a/src/lib/libssl/doc/standards.txt +++ /dev/null | |||
@@ -1,261 +0,0 @@ | |||
1 | Standards related to OpenSSL | ||
2 | ============================ | ||
3 | |||
4 | [Please, this is currently a draft. I made a first try at finding | ||
5 | documents that describe parts of what OpenSSL implements. There are | ||
6 | big gaps, and I've most certainly done something wrong. Please | ||
7 | correct whatever is... Also, this note should be removed when this | ||
8 | file is reaching a somewhat correct state. -- Richard Levitte] | ||
9 | |||
10 | |||
11 | All pointers in here will be either URL's or blobs of text borrowed | ||
12 | from miscellaneous indexes, like rfc-index.txt (index of RFCs), | ||
13 | 1id-index.txt (index of Internet drafts) and the like. | ||
14 | |||
15 | To find the latest possible RFCs, it's recommended to either browse | ||
16 | ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and | ||
17 | use the search mechanism found there. | ||
18 | To find the latest possible Internet drafts, it's recommended to | ||
19 | browse ftp://ftp.isi.edu/internet-drafts/. | ||
20 | To find the latest possible PKCS, it's recommended to browse | ||
21 | http://www.rsasecurity.com/rsalabs/pkcs/. | ||
22 | |||
23 | |||
24 | Implemented: | ||
25 | ------------ | ||
26 | |||
27 | These are documents that describe things that are implemented (in | ||
28 | whole or at least great parts) in OpenSSL. | ||
29 | |||
30 | 1319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992. | ||
31 | (Format: TXT=25661 bytes) (Status: INFORMATIONAL) | ||
32 | |||
33 | 1320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format: | ||
34 | TXT=32407 bytes) (Status: INFORMATIONAL) | ||
35 | |||
36 | 1321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format: | ||
37 | TXT=35222 bytes) (Status: INFORMATIONAL) | ||
38 | |||
39 | 2246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999. | ||
40 | (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD) | ||
41 | |||
42 | 2268 A Description of the RC2(r) Encryption Algorithm. R. Rivest. | ||
43 | January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL) | ||
44 | |||
45 | 2315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski. | ||
46 | March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL) | ||
47 | |||
48 | PKCS#8: Private-Key Information Syntax Standard | ||
49 | |||
50 | PKCS#12: Personal Information Exchange Syntax Standard, version 1.0. | ||
51 | |||
52 | 2560 X.509 Internet Public Key Infrastructure Online Certificate | ||
53 | Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin, | ||
54 | C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED | ||
55 | STANDARD) | ||
56 | |||
57 | 2712 Addition of Kerberos Cipher Suites to Transport Layer Security | ||
58 | (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes) | ||
59 | (Status: PROPOSED STANDARD) | ||
60 | |||
61 | 2898 PKCS #5: Password-Based Cryptography Specification Version 2.0. | ||
62 | B. Kaliski. September 2000. (Format: TXT=68692 bytes) (Status: | ||
63 | INFORMATIONAL) | ||
64 | |||
65 | 2986 PKCS #10: Certification Request Syntax Specification Version 1.7. | ||
66 | M. Nystrom, B. Kaliski. November 2000. (Format: TXT=27794 bytes) | ||
67 | (Obsoletes RFC2314) (Status: INFORMATIONAL) | ||
68 | |||
69 | 3174 US Secure Hash Algorithm 1 (SHA1). D. Eastlake 3rd, P. Jones. | ||
70 | September 2001. (Format: TXT=35525 bytes) (Status: INFORMATIONAL) | ||
71 | |||
72 | 3268 Advanced Encryption Standard (AES) Ciphersuites for Transport | ||
73 | Layer Security (TLS). P. Chown. June 2002. (Format: TXT=13530 bytes) | ||
74 | (Status: PROPOSED STANDARD) | ||
75 | |||
76 | 3279 Algorithms and Identifiers for the Internet X.509 Public Key | ||
77 | Infrastructure Certificate and Certificate Revocation List (CRL) | ||
78 | Profile. L. Bassham, W. Polk, R. Housley. April 2002. (Format: | ||
79 | TXT=53833 bytes) (Status: PROPOSED STANDARD) | ||
80 | |||
81 | 3280 Internet X.509 Public Key Infrastructure Certificate and | ||
82 | Certificate Revocation List (CRL) Profile. R. Housley, W. Polk, W. | ||
83 | Ford, D. Solo. April 2002. (Format: TXT=295556 bytes) (Obsoletes | ||
84 | RFC2459) (Status: PROPOSED STANDARD) | ||
85 | |||
86 | 3447 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography | ||
87 | Specifications Version 2.1. J. Jonsson, B. Kaliski. February 2003. | ||
88 | (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status: | ||
89 | INFORMATIONAL) | ||
90 | |||
91 | 3820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate | ||
92 | Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson. | ||
93 | June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD) | ||
94 | |||
95 | |||
96 | Related: | ||
97 | -------- | ||
98 | |||
99 | These are documents that are close to OpenSSL, for example the | ||
100 | STARTTLS documents. | ||
101 | |||
102 | 1421 Privacy Enhancement for Internet Electronic Mail: Part I: Message | ||
103 | Encryption and Authentication Procedures. J. Linn. February 1993. | ||
104 | (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED | ||
105 | STANDARD) | ||
106 | |||
107 | 1422 Privacy Enhancement for Internet Electronic Mail: Part II: | ||
108 | Certificate-Based Key Management. S. Kent. February 1993. (Format: | ||
109 | TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD) | ||
110 | |||
111 | 1423 Privacy Enhancement for Internet Electronic Mail: Part III: | ||
112 | Algorithms, Modes, and Identifiers. D. Balenson. February 1993. | ||
113 | (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED | ||
114 | STANDARD) | ||
115 | |||
116 | 1424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key | ||
117 | Certification and Related Services. B. Kaliski. February 1993. | ||
118 | (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD) | ||
119 | |||
120 | 2025 The Simple Public-Key GSS-API Mechanism (SPKM). C. Adams. October | ||
121 | 1996. (Format: TXT=101692 bytes) (Status: PROPOSED STANDARD) | ||
122 | |||
123 | 2510 Internet X.509 Public Key Infrastructure Certificate Management | ||
124 | Protocols. C. Adams, S. Farrell. March 1999. (Format: TXT=158178 | ||
125 | bytes) (Status: PROPOSED STANDARD) | ||
126 | |||
127 | 2511 Internet X.509 Certificate Request Message Format. M. Myers, C. | ||
128 | Adams, D. Solo, D. Kemp. March 1999. (Format: TXT=48278 bytes) | ||
129 | (Status: PROPOSED STANDARD) | ||
130 | |||
131 | 2527 Internet X.509 Public Key Infrastructure Certificate Policy and | ||
132 | Certification Practices Framework. S. Chokhani, W. Ford. March 1999. | ||
133 | (Format: TXT=91860 bytes) (Status: INFORMATIONAL) | ||
134 | |||
135 | 2538 Storing Certificates in the Domain Name System (DNS). D. Eastlake | ||
136 | 3rd, O. Gudmundsson. March 1999. (Format: TXT=19857 bytes) (Status: | ||
137 | PROPOSED STANDARD) | ||
138 | |||
139 | 2539 Storage of Diffie-Hellman Keys in the Domain Name System (DNS). | ||
140 | D. Eastlake 3rd. March 1999. (Format: TXT=21049 bytes) (Status: | ||
141 | PROPOSED STANDARD) | ||
142 | |||
143 | 2559 Internet X.509 Public Key Infrastructure Operational Protocols - | ||
144 | LDAPv2. S. Boeyen, T. Howes, P. Richard. April 1999. (Format: | ||
145 | TXT=22889 bytes) (Updates RFC1778) (Status: PROPOSED STANDARD) | ||
146 | |||
147 | 2585 Internet X.509 Public Key Infrastructure Operational Protocols: | ||
148 | FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813 | ||
149 | bytes) (Status: PROPOSED STANDARD) | ||
150 | |||
151 | 2587 Internet X.509 Public Key Infrastructure LDAPv2 Schema. S. | ||
152 | Boeyen, T. Howes, P. Richard. June 1999. (Format: TXT=15102 bytes) | ||
153 | (Status: PROPOSED STANDARD) | ||
154 | |||
155 | 2595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999. | ||
156 | (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD) | ||
157 | |||
158 | 2631 Diffie-Hellman Key Agreement Method. E. Rescorla. June 1999. | ||
159 | (Format: TXT=25932 bytes) (Status: PROPOSED STANDARD) | ||
160 | |||
161 | 2632 S/MIME Version 3 Certificate Handling. B. Ramsdell, Ed.. June | ||
162 | 1999. (Format: TXT=27925 bytes) (Status: PROPOSED STANDARD) | ||
163 | |||
164 | 2716 PPP EAP TLS Authentication Protocol. B. Aboba, D. Simon. October | ||
165 | 1999. (Format: TXT=50108 bytes) (Status: EXPERIMENTAL) | ||
166 | |||
167 | 2773 Encryption using KEA and SKIPJACK. R. Housley, P. Yee, W. Nace. | ||
168 | February 2000. (Format: TXT=20008 bytes) (Updates RFC0959) (Status: | ||
169 | EXPERIMENTAL) | ||
170 | |||
171 | 2797 Certificate Management Messages over CMS. M. Myers, X. Liu, J. | ||
172 | Schaad, J. Weinstein. April 2000. (Format: TXT=103357 bytes) (Status: | ||
173 | PROPOSED STANDARD) | ||
174 | |||
175 | 2817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May | ||
176 | 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED | ||
177 | STANDARD) | ||
178 | |||
179 | 2818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes) | ||
180 | (Status: INFORMATIONAL) | ||
181 | |||
182 | 2876 Use of the KEA and SKIPJACK Algorithms in CMS. J. Pawling. July | ||
183 | 2000. (Format: TXT=29265 bytes) (Status: INFORMATIONAL) | ||
184 | |||
185 | 2984 Use of the CAST-128 Encryption Algorithm in CMS. C. Adams. | ||
186 | October 2000. (Format: TXT=11591 bytes) (Status: PROPOSED STANDARD) | ||
187 | |||
188 | 2985 PKCS #9: Selected Object Classes and Attribute Types Version 2.0. | ||
189 | M. Nystrom, B. Kaliski. November 2000. (Format: TXT=70703 bytes) | ||
190 | (Status: INFORMATIONAL) | ||
191 | |||
192 | 3029 Internet X.509 Public Key Infrastructure Data Validation and | ||
193 | Certification Server Protocols. C. Adams, P. Sylvester, M. Zolotarev, | ||
194 | R. Zuccherato. February 2001. (Format: TXT=107347 bytes) (Status: | ||
195 | EXPERIMENTAL) | ||
196 | |||
197 | 3039 Internet X.509 Public Key Infrastructure Qualified Certificates | ||
198 | Profile. S. Santesson, W. Polk, P. Barzin, M. Nystrom. January 2001. | ||
199 | (Format: TXT=67619 bytes) (Status: PROPOSED STANDARD) | ||
200 | |||
201 | 3058 Use of the IDEA Encryption Algorithm in CMS. S. Teiwes, P. | ||
202 | Hartmann, D. Kuenzi. February 2001. (Format: TXT=17257 bytes) | ||
203 | (Status: INFORMATIONAL) | ||
204 | |||
205 | 3161 Internet X.509 Public Key Infrastructure Time-Stamp Protocol | ||
206 | (TSP). C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001. | ||
207 | (Format: TXT=54585 bytes) (Status: PROPOSED STANDARD) | ||
208 | |||
209 | 3185 Reuse of CMS Content Encryption Keys. S. Farrell, S. Turner. | ||
210 | October 2001. (Format: TXT=20404 bytes) (Status: PROPOSED STANDARD) | ||
211 | |||
212 | 3207 SMTP Service Extension for Secure SMTP over Transport Layer | ||
213 | Security. P. Hoffman. February 2002. (Format: TXT=18679 bytes) | ||
214 | (Obsoletes RFC2487) (Status: PROPOSED STANDARD) | ||
215 | |||
216 | 3217 Triple-DES and RC2 Key Wrapping. R. Housley. December 2001. | ||
217 | (Format: TXT=19855 bytes) (Status: INFORMATIONAL) | ||
218 | |||
219 | 3274 Compressed Data Content Type for Cryptographic Message Syntax | ||
220 | (CMS). P. Gutmann. June 2002. (Format: TXT=11276 bytes) (Status: | ||
221 | PROPOSED STANDARD) | ||
222 | |||
223 | 3278 Use of Elliptic Curve Cryptography (ECC) Algorithms in | ||
224 | Cryptographic Message Syntax (CMS). S. Blake-Wilson, D. Brown, P. | ||
225 | Lambert. April 2002. (Format: TXT=33779 bytes) (Status: | ||
226 | INFORMATIONAL) | ||
227 | |||
228 | 3281 An Internet Attribute Certificate Profile for Authorization. S. | ||
229 | Farrell, R. Housley. April 2002. (Format: TXT=90580 bytes) (Status: | ||
230 | PROPOSED STANDARD) | ||
231 | |||
232 | 3369 Cryptographic Message Syntax (CMS). R. Housley. August 2002. | ||
233 | (Format: TXT=113975 bytes) (Obsoletes RFC2630, RFC3211) (Status: | ||
234 | PROPOSED STANDARD) | ||
235 | |||
236 | 3370 Cryptographic Message Syntax (CMS) Algorithms. R. Housley. August | ||
237 | 2002. (Format: TXT=51001 bytes) (Obsoletes RFC2630, RFC3211) (Status: | ||
238 | PROPOSED STANDARD) | ||
239 | |||
240 | 3377 Lightweight Directory Access Protocol (v3): Technical | ||
241 | Specification. J. Hodges, R. Morgan. September 2002. (Format: | ||
242 | TXT=9981 bytes) (Updates RFC2251, RFC2252, RFC2253, RFC2254, RFC2255, | ||
243 | RFC2256, RFC2829, RFC2830) (Status: PROPOSED STANDARD) | ||
244 | |||
245 | 3394 Advanced Encryption Standard (AES) Key Wrap Algorithm. J. Schaad, | ||
246 | R. Housley. September 2002. (Format: TXT=73072 bytes) (Status: | ||
247 | INFORMATIONAL) | ||
248 | |||
249 | 3436 Transport Layer Security over Stream Control Transmission | ||
250 | Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002. | ||
251 | (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD) | ||
252 | |||
253 | "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt> | ||
254 | |||
255 | |||
256 | To be implemented: | ||
257 | ------------------ | ||
258 | |||
259 | These are documents that describe things that are planed to be | ||
260 | implemented in the hopefully short future. | ||
261 | |||
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c deleted file mode 100644 index 86356731ea..0000000000 --- a/src/lib/libssl/s23_clnt.c +++ /dev/null | |||
@@ -1,616 +0,0 @@ | |||
1 | /* ssl/s23_clnt.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include "ssl_locl.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/evp.h> | ||
65 | |||
66 | static SSL_METHOD *ssl23_get_client_method(int ver); | ||
67 | static int ssl23_client_hello(SSL *s); | ||
68 | static int ssl23_get_server_hello(SSL *s); | ||
69 | static SSL_METHOD *ssl23_get_client_method(int ver) | ||
70 | { | ||
71 | #ifndef OPENSSL_NO_SSL2 | ||
72 | if (ver == SSL2_VERSION) | ||
73 | return(SSLv2_client_method()); | ||
74 | #endif | ||
75 | if (ver == SSL3_VERSION) | ||
76 | return(SSLv3_client_method()); | ||
77 | else if (ver == TLS1_VERSION) | ||
78 | return(TLSv1_client_method()); | ||
79 | else | ||
80 | return(NULL); | ||
81 | } | ||
82 | |||
83 | SSL_METHOD *SSLv23_client_method(void) | ||
84 | { | ||
85 | static int init=1; | ||
86 | static SSL_METHOD SSLv23_client_data; | ||
87 | |||
88 | if (init) | ||
89 | { | ||
90 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
91 | |||
92 | if (init) | ||
93 | { | ||
94 | memcpy((char *)&SSLv23_client_data, | ||
95 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
96 | SSLv23_client_data.ssl_connect=ssl23_connect; | ||
97 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | ||
98 | init=0; | ||
99 | } | ||
100 | |||
101 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
102 | } | ||
103 | return(&SSLv23_client_data); | ||
104 | } | ||
105 | |||
106 | int ssl23_connect(SSL *s) | ||
107 | { | ||
108 | BUF_MEM *buf=NULL; | ||
109 | unsigned long Time=(unsigned long)time(NULL); | ||
110 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
111 | int ret= -1; | ||
112 | int new_state,state; | ||
113 | |||
114 | RAND_add(&Time,sizeof(Time),0); | ||
115 | ERR_clear_error(); | ||
116 | clear_sys_error(); | ||
117 | |||
118 | if (s->info_callback != NULL) | ||
119 | cb=s->info_callback; | ||
120 | else if (s->ctx->info_callback != NULL) | ||
121 | cb=s->ctx->info_callback; | ||
122 | |||
123 | s->in_handshake++; | ||
124 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
125 | |||
126 | for (;;) | ||
127 | { | ||
128 | state=s->state; | ||
129 | |||
130 | switch(s->state) | ||
131 | { | ||
132 | case SSL_ST_BEFORE: | ||
133 | case SSL_ST_CONNECT: | ||
134 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
135 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
136 | |||
137 | if (s->session != NULL) | ||
138 | { | ||
139 | SSLerr(SSL_F_SSL23_CONNECT,SSL_R_SSL23_DOING_SESSION_ID_REUSE); | ||
140 | ret= -1; | ||
141 | goto end; | ||
142 | } | ||
143 | s->server=0; | ||
144 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
145 | |||
146 | /* s->version=TLS1_VERSION; */ | ||
147 | s->type=SSL_ST_CONNECT; | ||
148 | |||
149 | if (s->init_buf == NULL) | ||
150 | { | ||
151 | if ((buf=BUF_MEM_new()) == NULL) | ||
152 | { | ||
153 | ret= -1; | ||
154 | goto end; | ||
155 | } | ||
156 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
157 | { | ||
158 | ret= -1; | ||
159 | goto end; | ||
160 | } | ||
161 | s->init_buf=buf; | ||
162 | buf=NULL; | ||
163 | } | ||
164 | |||
165 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
166 | |||
167 | ssl3_init_finished_mac(s); | ||
168 | |||
169 | s->state=SSL23_ST_CW_CLNT_HELLO_A; | ||
170 | s->ctx->stats.sess_connect++; | ||
171 | s->init_num=0; | ||
172 | break; | ||
173 | |||
174 | case SSL23_ST_CW_CLNT_HELLO_A: | ||
175 | case SSL23_ST_CW_CLNT_HELLO_B: | ||
176 | |||
177 | s->shutdown=0; | ||
178 | ret=ssl23_client_hello(s); | ||
179 | if (ret <= 0) goto end; | ||
180 | s->state=SSL23_ST_CR_SRVR_HELLO_A; | ||
181 | s->init_num=0; | ||
182 | |||
183 | break; | ||
184 | |||
185 | case SSL23_ST_CR_SRVR_HELLO_A: | ||
186 | case SSL23_ST_CR_SRVR_HELLO_B: | ||
187 | ret=ssl23_get_server_hello(s); | ||
188 | if (ret >= 0) cb=NULL; | ||
189 | goto end; | ||
190 | /* break; */ | ||
191 | |||
192 | default: | ||
193 | SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE); | ||
194 | ret= -1; | ||
195 | goto end; | ||
196 | /* break; */ | ||
197 | } | ||
198 | |||
199 | if (s->debug) { (void)BIO_flush(s->wbio); } | ||
200 | |||
201 | if ((cb != NULL) && (s->state != state)) | ||
202 | { | ||
203 | new_state=s->state; | ||
204 | s->state=state; | ||
205 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
206 | s->state=new_state; | ||
207 | } | ||
208 | } | ||
209 | end: | ||
210 | s->in_handshake--; | ||
211 | if (buf != NULL) | ||
212 | BUF_MEM_free(buf); | ||
213 | if (cb != NULL) | ||
214 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
215 | return(ret); | ||
216 | } | ||
217 | |||
218 | |||
219 | static int ssl23_client_hello(SSL *s) | ||
220 | { | ||
221 | unsigned char *buf; | ||
222 | unsigned char *p,*d; | ||
223 | int i,j,ch_len; | ||
224 | unsigned long Time,l; | ||
225 | int ssl2_compat; | ||
226 | int version = 0, version_major, version_minor; | ||
227 | SSL_COMP *comp; | ||
228 | int ret; | ||
229 | |||
230 | ssl2_compat = (s->options & SSL_OP_NO_SSLv2) ? 0 : 1; | ||
231 | |||
232 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
233 | { | ||
234 | version = TLS1_VERSION; | ||
235 | } | ||
236 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
237 | { | ||
238 | version = SSL3_VERSION; | ||
239 | } | ||
240 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
241 | { | ||
242 | version = SSL2_VERSION; | ||
243 | } | ||
244 | |||
245 | buf=(unsigned char *)s->init_buf->data; | ||
246 | if (s->state == SSL23_ST_CW_CLNT_HELLO_A) | ||
247 | { | ||
248 | #if 0 | ||
249 | /* don't reuse session-id's */ | ||
250 | if (!ssl_get_new_session(s,0)) | ||
251 | { | ||
252 | return(-1); | ||
253 | } | ||
254 | #endif | ||
255 | |||
256 | p=s->s3->client_random; | ||
257 | Time=(unsigned long)time(NULL); /* Time */ | ||
258 | l2n(Time,p); | ||
259 | if (RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | ||
260 | return -1; | ||
261 | |||
262 | if (version == TLS1_VERSION) | ||
263 | { | ||
264 | version_major = TLS1_VERSION_MAJOR; | ||
265 | version_minor = TLS1_VERSION_MINOR; | ||
266 | } | ||
267 | #ifdef OPENSSL_FIPS | ||
268 | else if(FIPS_mode()) | ||
269 | { | ||
270 | SSLerr(SSL_F_SSL23_CLIENT_HELLO, | ||
271 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
272 | return -1; | ||
273 | } | ||
274 | #endif | ||
275 | else if (version == SSL3_VERSION) | ||
276 | { | ||
277 | version_major = SSL3_VERSION_MAJOR; | ||
278 | version_minor = SSL3_VERSION_MINOR; | ||
279 | } | ||
280 | else if (version == SSL2_VERSION) | ||
281 | { | ||
282 | version_major = SSL2_VERSION_MAJOR; | ||
283 | version_minor = SSL2_VERSION_MINOR; | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE); | ||
288 | return(-1); | ||
289 | } | ||
290 | |||
291 | s->client_version = version; | ||
292 | |||
293 | if (ssl2_compat) | ||
294 | { | ||
295 | /* create SSL 2.0 compatible Client Hello */ | ||
296 | |||
297 | /* two byte record header will be written last */ | ||
298 | d = &(buf[2]); | ||
299 | p = d + 9; /* leave space for message type, version, individual length fields */ | ||
300 | |||
301 | *(d++) = SSL2_MT_CLIENT_HELLO; | ||
302 | *(d++) = version_major; | ||
303 | *(d++) = version_minor; | ||
304 | |||
305 | /* Ciphers supported */ | ||
306 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p,0); | ||
307 | if (i == 0) | ||
308 | { | ||
309 | /* no ciphers */ | ||
310 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
311 | return -1; | ||
312 | } | ||
313 | s2n(i,d); | ||
314 | p+=i; | ||
315 | |||
316 | /* put in the session-id length (zero since there is no reuse) */ | ||
317 | #if 0 | ||
318 | s->session->session_id_length=0; | ||
319 | #endif | ||
320 | s2n(0,d); | ||
321 | |||
322 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
323 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
324 | else | ||
325 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
326 | |||
327 | /* write out sslv2 challenge */ | ||
328 | if (SSL3_RANDOM_SIZE < ch_len) | ||
329 | i=SSL3_RANDOM_SIZE; | ||
330 | else | ||
331 | i=ch_len; | ||
332 | s2n(i,d); | ||
333 | memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE); | ||
334 | if (RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i) <= 0) | ||
335 | return -1; | ||
336 | |||
337 | memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
338 | p+=i; | ||
339 | |||
340 | i= p- &(buf[2]); | ||
341 | buf[0]=((i>>8)&0xff)|0x80; | ||
342 | buf[1]=(i&0xff); | ||
343 | |||
344 | /* number of bytes to write */ | ||
345 | s->init_num=i+2; | ||
346 | s->init_off=0; | ||
347 | |||
348 | ssl3_finish_mac(s,&(buf[2]),i); | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | /* create Client Hello in SSL 3.0/TLS 1.0 format */ | ||
353 | |||
354 | /* do the record header (5 bytes) and handshake message header (4 bytes) last */ | ||
355 | d = p = &(buf[9]); | ||
356 | |||
357 | *(p++) = version_major; | ||
358 | *(p++) = version_minor; | ||
359 | |||
360 | /* Random stuff */ | ||
361 | memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE); | ||
362 | p += SSL3_RANDOM_SIZE; | ||
363 | |||
364 | /* Session ID (zero since there is no reuse) */ | ||
365 | *(p++) = 0; | ||
366 | |||
367 | /* Ciphers supported (using SSL 3.0/TLS 1.0 format) */ | ||
368 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),ssl3_put_cipher_by_char); | ||
369 | if (i == 0) | ||
370 | { | ||
371 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
372 | return -1; | ||
373 | } | ||
374 | s2n(i,p); | ||
375 | p+=i; | ||
376 | |||
377 | /* COMPRESSION */ | ||
378 | if (s->ctx->comp_methods == NULL) | ||
379 | j=0; | ||
380 | else | ||
381 | j=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
382 | *(p++)=1+j; | ||
383 | for (i=0; i<j; i++) | ||
384 | { | ||
385 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | ||
386 | *(p++)=comp->id; | ||
387 | } | ||
388 | *(p++)=0; /* Add the NULL method */ | ||
389 | |||
390 | l = p-d; | ||
391 | *p = 42; | ||
392 | |||
393 | /* fill in 4-byte handshake header */ | ||
394 | d=&(buf[5]); | ||
395 | *(d++)=SSL3_MT_CLIENT_HELLO; | ||
396 | l2n3(l,d); | ||
397 | |||
398 | l += 4; | ||
399 | |||
400 | if (l > SSL3_RT_MAX_PLAIN_LENGTH) | ||
401 | { | ||
402 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,ERR_R_INTERNAL_ERROR); | ||
403 | return -1; | ||
404 | } | ||
405 | |||
406 | /* fill in 5-byte record header */ | ||
407 | d=buf; | ||
408 | *(d++) = SSL3_RT_HANDSHAKE; | ||
409 | *(d++) = version_major; | ||
410 | *(d++) = version_minor; /* arguably we should send the *lowest* suported version here | ||
411 | * (indicating, e.g., TLS 1.0 in "SSL 3.0 format") */ | ||
412 | s2n((int)l,d); | ||
413 | |||
414 | /* number of bytes to write */ | ||
415 | s->init_num=p-buf; | ||
416 | s->init_off=0; | ||
417 | |||
418 | ssl3_finish_mac(s,&(buf[5]), s->init_num - 5); | ||
419 | } | ||
420 | |||
421 | s->state=SSL23_ST_CW_CLNT_HELLO_B; | ||
422 | s->init_off=0; | ||
423 | } | ||
424 | |||
425 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
426 | ret = ssl23_write_bytes(s); | ||
427 | |||
428 | if ((ret >= 2) && s->msg_callback) | ||
429 | { | ||
430 | /* Client Hello has been sent; tell msg_callback */ | ||
431 | |||
432 | if (ssl2_compat) | ||
433 | s->msg_callback(1, SSL2_VERSION, 0, s->init_buf->data+2, ret-2, s, s->msg_callback_arg); | ||
434 | else | ||
435 | s->msg_callback(1, version, SSL3_RT_HANDSHAKE, s->init_buf->data+5, ret-5, s, s->msg_callback_arg); | ||
436 | } | ||
437 | |||
438 | return ret; | ||
439 | } | ||
440 | |||
441 | static int ssl23_get_server_hello(SSL *s) | ||
442 | { | ||
443 | char buf[8]; | ||
444 | unsigned char *p; | ||
445 | int i; | ||
446 | int n; | ||
447 | |||
448 | n=ssl23_read_bytes(s,7); | ||
449 | |||
450 | if (n != 7) return(n); | ||
451 | p=s->packet; | ||
452 | |||
453 | memcpy(buf,p,n); | ||
454 | |||
455 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) && | ||
456 | (p[5] == 0x00) && (p[6] == 0x02)) | ||
457 | { | ||
458 | #ifdef OPENSSL_NO_SSL2 | ||
459 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
460 | goto err; | ||
461 | #else | ||
462 | /* we are talking sslv2 */ | ||
463 | /* we need to clean up the SSLv3 setup and put in the | ||
464 | * sslv2 stuff. */ | ||
465 | int ch_len; | ||
466 | |||
467 | if (s->options & SSL_OP_NO_SSLv2) | ||
468 | { | ||
469 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
470 | goto err; | ||
471 | } | ||
472 | if (s->s2 == NULL) | ||
473 | { | ||
474 | if (!ssl2_new(s)) | ||
475 | goto err; | ||
476 | } | ||
477 | else | ||
478 | ssl2_clear(s); | ||
479 | |||
480 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
481 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
482 | else | ||
483 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
484 | |||
485 | /* write out sslv2 challenge */ | ||
486 | i=(SSL3_RANDOM_SIZE < ch_len) | ||
487 | ?SSL3_RANDOM_SIZE:ch_len; | ||
488 | s->s2->challenge_length=i; | ||
489 | memcpy(s->s2->challenge, | ||
490 | &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
491 | |||
492 | if (s->s3 != NULL) ssl3_free(s); | ||
493 | |||
494 | if (!BUF_MEM_grow_clean(s->init_buf, | ||
495 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
496 | { | ||
497 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB); | ||
498 | goto err; | ||
499 | } | ||
500 | |||
501 | s->state=SSL2_ST_GET_SERVER_HELLO_A; | ||
502 | if (!(s->client_version == SSL2_VERSION)) | ||
503 | /* use special padding (SSL 3.0 draft/RFC 2246, App. E.2) */ | ||
504 | s->s2->ssl2_rollback=1; | ||
505 | |||
506 | /* setup the 5 bytes we have read so we get them from | ||
507 | * the sslv2 buffer */ | ||
508 | s->rstate=SSL_ST_READ_HEADER; | ||
509 | s->packet_length=n; | ||
510 | s->packet= &(s->s2->rbuf[0]); | ||
511 | memcpy(s->packet,buf,n); | ||
512 | s->s2->rbuf_left=n; | ||
513 | s->s2->rbuf_offs=0; | ||
514 | |||
515 | /* we have already written one */ | ||
516 | s->s2->write_sequence=1; | ||
517 | |||
518 | s->method=SSLv2_client_method(); | ||
519 | s->handshake_func=s->method->ssl_connect; | ||
520 | #endif | ||
521 | } | ||
522 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
523 | (p[1] == SSL3_VERSION_MAJOR) && | ||
524 | ((p[2] == SSL3_VERSION_MINOR) || | ||
525 | (p[2] == TLS1_VERSION_MINOR)) && | ||
526 | (p[5] == SSL3_MT_SERVER_HELLO)) | ||
527 | { | ||
528 | /* we have sslv3 or tls1 */ | ||
529 | |||
530 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
531 | |||
532 | /* we are in this state */ | ||
533 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
534 | |||
535 | /* put the 5 bytes we have read into the input buffer | ||
536 | * for SSLv3 */ | ||
537 | s->rstate=SSL_ST_READ_HEADER; | ||
538 | s->packet_length=n; | ||
539 | s->packet= &(s->s3->rbuf.buf[0]); | ||
540 | memcpy(s->packet,buf,n); | ||
541 | s->s3->rbuf.left=n; | ||
542 | s->s3->rbuf.offset=0; | ||
543 | |||
544 | if ((p[2] == SSL3_VERSION_MINOR) && | ||
545 | !(s->options & SSL_OP_NO_SSLv3)) | ||
546 | { | ||
547 | #ifdef OPENSSL_FIPS | ||
548 | if(FIPS_mode()) | ||
549 | { | ||
550 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO, | ||
551 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
552 | goto err; | ||
553 | } | ||
554 | #endif | ||
555 | s->version=SSL3_VERSION; | ||
556 | s->method=SSLv3_client_method(); | ||
557 | } | ||
558 | else if ((p[2] == TLS1_VERSION_MINOR) && | ||
559 | !(s->options & SSL_OP_NO_TLSv1)) | ||
560 | { | ||
561 | s->version=TLS1_VERSION; | ||
562 | s->method=TLSv1_client_method(); | ||
563 | } | ||
564 | else | ||
565 | { | ||
566 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
567 | goto err; | ||
568 | } | ||
569 | |||
570 | s->handshake_func=s->method->ssl_connect; | ||
571 | } | ||
572 | else if ((p[0] == SSL3_RT_ALERT) && | ||
573 | (p[1] == SSL3_VERSION_MAJOR) && | ||
574 | ((p[2] == SSL3_VERSION_MINOR) || | ||
575 | (p[2] == TLS1_VERSION_MINOR)) && | ||
576 | (p[3] == 0) && | ||
577 | (p[4] == 2)) | ||
578 | { | ||
579 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
580 | int j; | ||
581 | |||
582 | /* An alert */ | ||
583 | if (s->info_callback != NULL) | ||
584 | cb=s->info_callback; | ||
585 | else if (s->ctx->info_callback != NULL) | ||
586 | cb=s->ctx->info_callback; | ||
587 | |||
588 | i=p[5]; | ||
589 | if (cb != NULL) | ||
590 | { | ||
591 | j=(i<<8)|p[6]; | ||
592 | cb(s,SSL_CB_READ_ALERT,j); | ||
593 | } | ||
594 | |||
595 | s->rwstate=SSL_NOTHING; | ||
596 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]); | ||
597 | goto err; | ||
598 | } | ||
599 | else | ||
600 | { | ||
601 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
602 | goto err; | ||
603 | } | ||
604 | s->init_num=0; | ||
605 | |||
606 | /* Since, if we are sending a ssl23 client hello, we are not | ||
607 | * reusing a session-id */ | ||
608 | if (!ssl_get_new_session(s,0)) | ||
609 | goto err; | ||
610 | |||
611 | s->first_packet=1; | ||
612 | return(SSL_connect(s)); | ||
613 | err: | ||
614 | return(-1); | ||
615 | } | ||
616 | |||
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c deleted file mode 100644 index 8d7dbcf569..0000000000 --- a/src/lib/libssl/s23_lib.c +++ /dev/null | |||
@@ -1,236 +0,0 @@ | |||
1 | /* ssl/s23_lib.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/objects.h> | ||
61 | #include "ssl_locl.h" | ||
62 | |||
63 | static int ssl23_num_ciphers(void ); | ||
64 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u); | ||
65 | static int ssl23_read(SSL *s, void *buf, int len); | ||
66 | static int ssl23_peek(SSL *s, void *buf, int len); | ||
67 | static int ssl23_write(SSL *s, const void *buf, int len); | ||
68 | static long ssl23_default_timeout(void ); | ||
69 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p); | ||
70 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p); | ||
71 | const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT; | ||
72 | |||
73 | static SSL_METHOD SSLv23_data= { | ||
74 | TLS1_VERSION, | ||
75 | tls1_new, | ||
76 | tls1_clear, | ||
77 | tls1_free, | ||
78 | ssl_undefined_function, | ||
79 | ssl_undefined_function, | ||
80 | ssl23_read, | ||
81 | ssl23_peek, | ||
82 | ssl23_write, | ||
83 | ssl_undefined_function, | ||
84 | ssl_undefined_function, | ||
85 | ssl_ok, | ||
86 | ssl3_ctrl, | ||
87 | ssl3_ctx_ctrl, | ||
88 | ssl23_get_cipher_by_char, | ||
89 | ssl23_put_cipher_by_char, | ||
90 | ssl_undefined_const_function, | ||
91 | ssl23_num_ciphers, | ||
92 | ssl23_get_cipher, | ||
93 | ssl_bad_method, | ||
94 | ssl23_default_timeout, | ||
95 | &ssl3_undef_enc_method, | ||
96 | ssl_undefined_function, | ||
97 | ssl3_callback_ctrl, | ||
98 | ssl3_ctx_callback_ctrl, | ||
99 | }; | ||
100 | |||
101 | static long ssl23_default_timeout(void) | ||
102 | { | ||
103 | return(300); | ||
104 | } | ||
105 | |||
106 | SSL_METHOD *sslv23_base_method(void) | ||
107 | { | ||
108 | return(&SSLv23_data); | ||
109 | } | ||
110 | |||
111 | static int ssl23_num_ciphers(void) | ||
112 | { | ||
113 | return(ssl3_num_ciphers() | ||
114 | #ifndef OPENSSL_NO_SSL2 | ||
115 | + ssl2_num_ciphers() | ||
116 | #endif | ||
117 | ); | ||
118 | } | ||
119 | |||
120 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u) | ||
121 | { | ||
122 | unsigned int uu=ssl3_num_ciphers(); | ||
123 | |||
124 | if (u < uu) | ||
125 | return(ssl3_get_cipher(u)); | ||
126 | else | ||
127 | #ifndef OPENSSL_NO_SSL2 | ||
128 | return(ssl2_get_cipher(u-uu)); | ||
129 | #else | ||
130 | return(NULL); | ||
131 | #endif | ||
132 | } | ||
133 | |||
134 | /* This function needs to check if the ciphers required are actually | ||
135 | * available */ | ||
136 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) | ||
137 | { | ||
138 | SSL_CIPHER c,*cp; | ||
139 | unsigned long id; | ||
140 | int n; | ||
141 | |||
142 | n=ssl3_num_ciphers(); | ||
143 | id=0x03000000|((unsigned long)p[0]<<16L)| | ||
144 | ((unsigned long)p[1]<<8L)|(unsigned long)p[2]; | ||
145 | c.id=id; | ||
146 | cp=ssl3_get_cipher_by_char(p); | ||
147 | #ifndef OPENSSL_NO_SSL2 | ||
148 | if (cp == NULL) | ||
149 | cp=ssl2_get_cipher_by_char(p); | ||
150 | #endif | ||
151 | return(cp); | ||
152 | } | ||
153 | |||
154 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | ||
155 | { | ||
156 | long l; | ||
157 | |||
158 | /* We can write SSLv2 and SSLv3 ciphers */ | ||
159 | if (p != NULL) | ||
160 | { | ||
161 | l=c->id; | ||
162 | p[0]=((unsigned char)(l>>16L))&0xFF; | ||
163 | p[1]=((unsigned char)(l>> 8L))&0xFF; | ||
164 | p[2]=((unsigned char)(l ))&0xFF; | ||
165 | } | ||
166 | return(3); | ||
167 | } | ||
168 | |||
169 | static int ssl23_read(SSL *s, void *buf, int len) | ||
170 | { | ||
171 | int n; | ||
172 | |||
173 | clear_sys_error(); | ||
174 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
175 | { | ||
176 | n=s->handshake_func(s); | ||
177 | if (n < 0) return(n); | ||
178 | if (n == 0) | ||
179 | { | ||
180 | SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
181 | return(-1); | ||
182 | } | ||
183 | return(SSL_read(s,buf,len)); | ||
184 | } | ||
185 | else | ||
186 | { | ||
187 | ssl_undefined_function(s); | ||
188 | return(-1); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | static int ssl23_peek(SSL *s, void *buf, int len) | ||
193 | { | ||
194 | int n; | ||
195 | |||
196 | clear_sys_error(); | ||
197 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
198 | { | ||
199 | n=s->handshake_func(s); | ||
200 | if (n < 0) return(n); | ||
201 | if (n == 0) | ||
202 | { | ||
203 | SSLerr(SSL_F_SSL23_PEEK,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
204 | return(-1); | ||
205 | } | ||
206 | return(SSL_peek(s,buf,len)); | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | ssl_undefined_function(s); | ||
211 | return(-1); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | static int ssl23_write(SSL *s, const void *buf, int len) | ||
216 | { | ||
217 | int n; | ||
218 | |||
219 | clear_sys_error(); | ||
220 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
221 | { | ||
222 | n=s->handshake_func(s); | ||
223 | if (n < 0) return(n); | ||
224 | if (n == 0) | ||
225 | { | ||
226 | SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
227 | return(-1); | ||
228 | } | ||
229 | return(SSL_write(s,buf,len)); | ||
230 | } | ||
231 | else | ||
232 | { | ||
233 | ssl_undefined_function(s); | ||
234 | return(-1); | ||
235 | } | ||
236 | } | ||
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c deleted file mode 100644 index 4ca6a1b258..0000000000 --- a/src/lib/libssl/s23_pkt.c +++ /dev/null | |||
@@ -1,117 +0,0 @@ | |||
1 | /* ssl/s23_pkt.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <errno.h> | ||
61 | #define USE_SOCKETS | ||
62 | #include "ssl_locl.h" | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/buffer.h> | ||
65 | |||
66 | int ssl23_write_bytes(SSL *s) | ||
67 | { | ||
68 | int i,num,tot; | ||
69 | char *buf; | ||
70 | |||
71 | buf=s->init_buf->data; | ||
72 | tot=s->init_off; | ||
73 | num=s->init_num; | ||
74 | for (;;) | ||
75 | { | ||
76 | s->rwstate=SSL_WRITING; | ||
77 | i=BIO_write(s->wbio,&(buf[tot]),num); | ||
78 | if (i <= 0) | ||
79 | { | ||
80 | s->init_off=tot; | ||
81 | s->init_num=num; | ||
82 | return(i); | ||
83 | } | ||
84 | s->rwstate=SSL_NOTHING; | ||
85 | if (i == num) return(tot+i); | ||
86 | |||
87 | num-=i; | ||
88 | tot+=i; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /* return regularly only when we have read (at least) 'n' bytes */ | ||
93 | int ssl23_read_bytes(SSL *s, int n) | ||
94 | { | ||
95 | unsigned char *p; | ||
96 | int j; | ||
97 | |||
98 | if (s->packet_length < (unsigned int)n) | ||
99 | { | ||
100 | p=s->packet; | ||
101 | |||
102 | for (;;) | ||
103 | { | ||
104 | s->rwstate=SSL_READING; | ||
105 | j=BIO_read(s->rbio,(char *)&(p[s->packet_length]), | ||
106 | n-s->packet_length); | ||
107 | if (j <= 0) | ||
108 | return(j); | ||
109 | s->rwstate=SSL_NOTHING; | ||
110 | s->packet_length+=j; | ||
111 | if (s->packet_length >= (unsigned int)n) | ||
112 | return(s->packet_length); | ||
113 | } | ||
114 | } | ||
115 | return(n); | ||
116 | } | ||
117 | |||
diff --git a/src/lib/libssl/s23_srvr.c b/src/lib/libssl/s23_srvr.c deleted file mode 100644 index b73abc448f..0000000000 --- a/src/lib/libssl/s23_srvr.c +++ /dev/null | |||
@@ -1,600 +0,0 @@ | |||
1 | /* ssl/s23_srvr.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include "ssl_locl.h" | ||
114 | #include <openssl/buffer.h> | ||
115 | #include <openssl/rand.h> | ||
116 | #include <openssl/objects.h> | ||
117 | #include <openssl/evp.h> | ||
118 | |||
119 | static SSL_METHOD *ssl23_get_server_method(int ver); | ||
120 | int ssl23_get_client_hello(SSL *s); | ||
121 | static SSL_METHOD *ssl23_get_server_method(int ver) | ||
122 | { | ||
123 | #ifndef OPENSSL_NO_SSL2 | ||
124 | if (ver == SSL2_VERSION) | ||
125 | return(SSLv2_server_method()); | ||
126 | #endif | ||
127 | if (ver == SSL3_VERSION) | ||
128 | return(SSLv3_server_method()); | ||
129 | else if (ver == TLS1_VERSION) | ||
130 | return(TLSv1_server_method()); | ||
131 | else | ||
132 | return(NULL); | ||
133 | } | ||
134 | |||
135 | SSL_METHOD *SSLv23_server_method(void) | ||
136 | { | ||
137 | static int init=1; | ||
138 | static SSL_METHOD SSLv23_server_data; | ||
139 | |||
140 | if (init) | ||
141 | { | ||
142 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
143 | |||
144 | if (init) | ||
145 | { | ||
146 | memcpy((char *)&SSLv23_server_data, | ||
147 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
148 | SSLv23_server_data.ssl_accept=ssl23_accept; | ||
149 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | ||
150 | init=0; | ||
151 | } | ||
152 | |||
153 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
154 | } | ||
155 | return(&SSLv23_server_data); | ||
156 | } | ||
157 | |||
158 | int ssl23_accept(SSL *s) | ||
159 | { | ||
160 | BUF_MEM *buf; | ||
161 | unsigned long Time=(unsigned long)time(NULL); | ||
162 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
163 | int ret= -1; | ||
164 | int new_state,state; | ||
165 | |||
166 | RAND_add(&Time,sizeof(Time),0); | ||
167 | ERR_clear_error(); | ||
168 | clear_sys_error(); | ||
169 | |||
170 | if (s->info_callback != NULL) | ||
171 | cb=s->info_callback; | ||
172 | else if (s->ctx->info_callback != NULL) | ||
173 | cb=s->ctx->info_callback; | ||
174 | |||
175 | s->in_handshake++; | ||
176 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
177 | |||
178 | for (;;) | ||
179 | { | ||
180 | state=s->state; | ||
181 | |||
182 | switch(s->state) | ||
183 | { | ||
184 | case SSL_ST_BEFORE: | ||
185 | case SSL_ST_ACCEPT: | ||
186 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
187 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
188 | |||
189 | s->server=1; | ||
190 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
191 | |||
192 | /* s->version=SSL3_VERSION; */ | ||
193 | s->type=SSL_ST_ACCEPT; | ||
194 | |||
195 | if (s->init_buf == NULL) | ||
196 | { | ||
197 | if ((buf=BUF_MEM_new()) == NULL) | ||
198 | { | ||
199 | ret= -1; | ||
200 | goto end; | ||
201 | } | ||
202 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
203 | { | ||
204 | ret= -1; | ||
205 | goto end; | ||
206 | } | ||
207 | s->init_buf=buf; | ||
208 | } | ||
209 | |||
210 | ssl3_init_finished_mac(s); | ||
211 | |||
212 | s->state=SSL23_ST_SR_CLNT_HELLO_A; | ||
213 | s->ctx->stats.sess_accept++; | ||
214 | s->init_num=0; | ||
215 | break; | ||
216 | |||
217 | case SSL23_ST_SR_CLNT_HELLO_A: | ||
218 | case SSL23_ST_SR_CLNT_HELLO_B: | ||
219 | |||
220 | s->shutdown=0; | ||
221 | ret=ssl23_get_client_hello(s); | ||
222 | if (ret >= 0) cb=NULL; | ||
223 | goto end; | ||
224 | /* break; */ | ||
225 | |||
226 | default: | ||
227 | SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
228 | ret= -1; | ||
229 | goto end; | ||
230 | /* break; */ | ||
231 | } | ||
232 | |||
233 | if ((cb != NULL) && (s->state != state)) | ||
234 | { | ||
235 | new_state=s->state; | ||
236 | s->state=state; | ||
237 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
238 | s->state=new_state; | ||
239 | } | ||
240 | } | ||
241 | end: | ||
242 | s->in_handshake--; | ||
243 | if (cb != NULL) | ||
244 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
245 | return(ret); | ||
246 | } | ||
247 | |||
248 | |||
249 | int ssl23_get_client_hello(SSL *s) | ||
250 | { | ||
251 | char buf_space[11]; /* Request this many bytes in initial read. | ||
252 | * We can detect SSL 3.0/TLS 1.0 Client Hellos | ||
253 | * ('type == 3') correctly only when the following | ||
254 | * is in a single record, which is not guaranteed by | ||
255 | * the protocol specification: | ||
256 | * Byte Content | ||
257 | * 0 type \ | ||
258 | * 1/2 version > record header | ||
259 | * 3/4 length / | ||
260 | * 5 msg_type \ | ||
261 | * 6-8 length > Client Hello message | ||
262 | * 9/10 client_version / | ||
263 | */ | ||
264 | char *buf= &(buf_space[0]); | ||
265 | unsigned char *p,*d,*d_len,*dd; | ||
266 | unsigned int i; | ||
267 | unsigned int csl,sil,cl; | ||
268 | int n=0,j; | ||
269 | int type=0; | ||
270 | int v[2]; | ||
271 | |||
272 | if (s->state == SSL23_ST_SR_CLNT_HELLO_A) | ||
273 | { | ||
274 | /* read the initial header */ | ||
275 | v[0]=v[1]=0; | ||
276 | |||
277 | if (!ssl3_setup_buffers(s)) goto err; | ||
278 | |||
279 | n=ssl23_read_bytes(s, sizeof buf_space); | ||
280 | if (n != sizeof buf_space) return(n); /* n == -1 || n == 0 */ | ||
281 | |||
282 | p=s->packet; | ||
283 | |||
284 | memcpy(buf,p,n); | ||
285 | |||
286 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) | ||
287 | { | ||
288 | /* | ||
289 | * SSLv2 header | ||
290 | */ | ||
291 | if ((p[3] == 0x00) && (p[4] == 0x02)) | ||
292 | { | ||
293 | v[0]=p[3]; v[1]=p[4]; | ||
294 | /* SSLv2 */ | ||
295 | if (!(s->options & SSL_OP_NO_SSLv2)) | ||
296 | type=1; | ||
297 | } | ||
298 | else if (p[3] == SSL3_VERSION_MAJOR) | ||
299 | { | ||
300 | v[0]=p[3]; v[1]=p[4]; | ||
301 | /* SSLv3/TLSv1 */ | ||
302 | if (p[4] >= TLS1_VERSION_MINOR) | ||
303 | { | ||
304 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
305 | { | ||
306 | s->version=TLS1_VERSION; | ||
307 | /* type=2; */ /* done later to survive restarts */ | ||
308 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
309 | } | ||
310 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
311 | { | ||
312 | s->version=SSL3_VERSION; | ||
313 | /* type=2; */ | ||
314 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
315 | } | ||
316 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
317 | { | ||
318 | type=1; | ||
319 | } | ||
320 | } | ||
321 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
322 | { | ||
323 | s->version=SSL3_VERSION; | ||
324 | /* type=2; */ | ||
325 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
326 | } | ||
327 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
328 | type=1; | ||
329 | |||
330 | } | ||
331 | } | ||
332 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
333 | (p[1] == SSL3_VERSION_MAJOR) && | ||
334 | (p[5] == SSL3_MT_CLIENT_HELLO) && | ||
335 | ((p[3] == 0 && p[4] < 5 /* silly record length? */) | ||
336 | || (p[9] == p[1]))) | ||
337 | { | ||
338 | /* | ||
339 | * SSLv3 or tls1 header | ||
340 | */ | ||
341 | |||
342 | v[0]=p[1]; /* major version (= SSL3_VERSION_MAJOR) */ | ||
343 | /* We must look at client_version inside the Client Hello message | ||
344 | * to get the correct minor version. | ||
345 | * However if we have only a pathologically small fragment of the | ||
346 | * Client Hello message, this would be difficult, and we'd have | ||
347 | * to read more records to find out. | ||
348 | * No known SSL 3.0 client fragments ClientHello like this, | ||
349 | * so we simply assume TLS 1.0 to avoid protocol version downgrade | ||
350 | * attacks. */ | ||
351 | if (p[3] == 0 && p[4] < 6) | ||
352 | { | ||
353 | #if 0 | ||
354 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL); | ||
355 | goto err; | ||
356 | #else | ||
357 | v[1] = TLS1_VERSION_MINOR; | ||
358 | #endif | ||
359 | } | ||
360 | else | ||
361 | v[1]=p[10]; /* minor version according to client_version */ | ||
362 | if (v[1] >= TLS1_VERSION_MINOR) | ||
363 | { | ||
364 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
365 | { | ||
366 | s->version=TLS1_VERSION; | ||
367 | type=3; | ||
368 | } | ||
369 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
370 | { | ||
371 | s->version=SSL3_VERSION; | ||
372 | type=3; | ||
373 | } | ||
374 | } | ||
375 | else | ||
376 | { | ||
377 | /* client requests SSL 3.0 */ | ||
378 | if (!(s->options & SSL_OP_NO_SSLv3)) | ||
379 | { | ||
380 | s->version=SSL3_VERSION; | ||
381 | type=3; | ||
382 | } | ||
383 | else if (!(s->options & SSL_OP_NO_TLSv1)) | ||
384 | { | ||
385 | /* we won't be able to use TLS of course, | ||
386 | * but this will send an appropriate alert */ | ||
387 | s->version=TLS1_VERSION; | ||
388 | type=3; | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | else if ((strncmp("GET ", (char *)p,4) == 0) || | ||
393 | (strncmp("POST ",(char *)p,5) == 0) || | ||
394 | (strncmp("HEAD ",(char *)p,5) == 0) || | ||
395 | (strncmp("PUT ", (char *)p,4) == 0)) | ||
396 | { | ||
397 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST); | ||
398 | goto err; | ||
399 | } | ||
400 | else if (strncmp("CONNECT",(char *)p,7) == 0) | ||
401 | { | ||
402 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST); | ||
403 | goto err; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | #ifdef OPENSSL_FIPS | ||
408 | if (FIPS_mode() && (s->version < TLS1_VERSION)) | ||
409 | { | ||
410 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO, | ||
411 | SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
412 | goto err; | ||
413 | } | ||
414 | #endif | ||
415 | |||
416 | if (s->state == SSL23_ST_SR_CLNT_HELLO_B) | ||
417 | { | ||
418 | /* we have SSLv3/TLSv1 in an SSLv2 header | ||
419 | * (other cases skip this state) */ | ||
420 | |||
421 | type=2; | ||
422 | p=s->packet; | ||
423 | v[0] = p[3]; /* == SSL3_VERSION_MAJOR */ | ||
424 | v[1] = p[4]; | ||
425 | |||
426 | n=((p[0]&0x7f)<<8)|p[1]; | ||
427 | if (n > (1024*4)) | ||
428 | { | ||
429 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE); | ||
430 | goto err; | ||
431 | } | ||
432 | |||
433 | j=ssl23_read_bytes(s,n+2); | ||
434 | if (j <= 0) return(j); | ||
435 | |||
436 | ssl3_finish_mac(s, s->packet+2, s->packet_length-2); | ||
437 | if (s->msg_callback) | ||
438 | s->msg_callback(0, SSL2_VERSION, 0, s->packet+2, s->packet_length-2, s, s->msg_callback_arg); /* CLIENT-HELLO */ | ||
439 | |||
440 | p=s->packet; | ||
441 | p+=5; | ||
442 | n2s(p,csl); | ||
443 | n2s(p,sil); | ||
444 | n2s(p,cl); | ||
445 | d=(unsigned char *)s->init_buf->data; | ||
446 | if ((csl+sil+cl+11) != s->packet_length) | ||
447 | { | ||
448 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH); | ||
449 | goto err; | ||
450 | } | ||
451 | |||
452 | /* record header: msg_type ... */ | ||
453 | *(d++) = SSL3_MT_CLIENT_HELLO; | ||
454 | /* ... and length (actual value will be written later) */ | ||
455 | d_len = d; | ||
456 | d += 3; | ||
457 | |||
458 | /* client_version */ | ||
459 | *(d++) = SSL3_VERSION_MAJOR; /* == v[0] */ | ||
460 | *(d++) = v[1]; | ||
461 | |||
462 | /* lets populate the random area */ | ||
463 | /* get the challenge_length */ | ||
464 | i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl; | ||
465 | memset(d,0,SSL3_RANDOM_SIZE); | ||
466 | memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i); | ||
467 | d+=SSL3_RANDOM_SIZE; | ||
468 | |||
469 | /* no session-id reuse */ | ||
470 | *(d++)=0; | ||
471 | |||
472 | /* ciphers */ | ||
473 | j=0; | ||
474 | dd=d; | ||
475 | d+=2; | ||
476 | for (i=0; i<csl; i+=3) | ||
477 | { | ||
478 | if (p[i] != 0) continue; | ||
479 | *(d++)=p[i+1]; | ||
480 | *(d++)=p[i+2]; | ||
481 | j+=2; | ||
482 | } | ||
483 | s2n(j,dd); | ||
484 | |||
485 | /* COMPRESSION */ | ||
486 | *(d++)=1; | ||
487 | *(d++)=0; | ||
488 | |||
489 | i = (d-(unsigned char *)s->init_buf->data) - 4; | ||
490 | l2n3((long)i, d_len); | ||
491 | |||
492 | /* get the data reused from the init_buf */ | ||
493 | s->s3->tmp.reuse_message=1; | ||
494 | s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO; | ||
495 | s->s3->tmp.message_size=i; | ||
496 | } | ||
497 | |||
498 | /* imaginary new state (for program structure): */ | ||
499 | /* s->state = SSL23_SR_CLNT_HELLO_C */ | ||
500 | |||
501 | if (type == 1) | ||
502 | { | ||
503 | #ifdef OPENSSL_NO_SSL2 | ||
504 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
505 | goto err; | ||
506 | #else | ||
507 | /* we are talking sslv2 */ | ||
508 | /* we need to clean up the SSLv3/TLSv1 setup and put in the | ||
509 | * sslv2 stuff. */ | ||
510 | |||
511 | if (s->s2 == NULL) | ||
512 | { | ||
513 | if (!ssl2_new(s)) | ||
514 | goto err; | ||
515 | } | ||
516 | else | ||
517 | ssl2_clear(s); | ||
518 | |||
519 | if (s->s3 != NULL) ssl3_free(s); | ||
520 | |||
521 | if (!BUF_MEM_grow_clean(s->init_buf, | ||
522 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
523 | { | ||
524 | goto err; | ||
525 | } | ||
526 | |||
527 | s->state=SSL2_ST_GET_CLIENT_HELLO_A; | ||
528 | if (s->options & SSL_OP_NO_TLSv1 && s->options & SSL_OP_NO_SSLv3) | ||
529 | s->s2->ssl2_rollback=0; | ||
530 | else | ||
531 | /* reject SSL 2.0 session if client supports SSL 3.0 or TLS 1.0 | ||
532 | * (SSL 3.0 draft/RFC 2246, App. E.2) */ | ||
533 | s->s2->ssl2_rollback=1; | ||
534 | |||
535 | /* setup the n bytes we have read so we get them from | ||
536 | * the sslv2 buffer */ | ||
537 | s->rstate=SSL_ST_READ_HEADER; | ||
538 | s->packet_length=n; | ||
539 | s->packet= &(s->s2->rbuf[0]); | ||
540 | memcpy(s->packet,buf,n); | ||
541 | s->s2->rbuf_left=n; | ||
542 | s->s2->rbuf_offs=0; | ||
543 | |||
544 | s->method=SSLv2_server_method(); | ||
545 | s->handshake_func=s->method->ssl_accept; | ||
546 | #endif | ||
547 | } | ||
548 | |||
549 | if ((type == 2) || (type == 3)) | ||
550 | { | ||
551 | /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */ | ||
552 | |||
553 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
554 | |||
555 | /* we are in this state */ | ||
556 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
557 | |||
558 | if (type == 3) | ||
559 | { | ||
560 | /* put the 'n' bytes we have read into the input buffer | ||
561 | * for SSLv3 */ | ||
562 | s->rstate=SSL_ST_READ_HEADER; | ||
563 | s->packet_length=n; | ||
564 | s->packet= &(s->s3->rbuf.buf[0]); | ||
565 | memcpy(s->packet,buf,n); | ||
566 | s->s3->rbuf.left=n; | ||
567 | s->s3->rbuf.offset=0; | ||
568 | } | ||
569 | else | ||
570 | { | ||
571 | s->packet_length=0; | ||
572 | s->s3->rbuf.left=0; | ||
573 | s->s3->rbuf.offset=0; | ||
574 | } | ||
575 | |||
576 | if (s->version == TLS1_VERSION) | ||
577 | s->method = TLSv1_server_method(); | ||
578 | else | ||
579 | s->method = SSLv3_server_method(); | ||
580 | #if 0 /* ssl3_get_client_hello does this */ | ||
581 | s->client_version=(v[0]<<8)|v[1]; | ||
582 | #endif | ||
583 | s->handshake_func=s->method->ssl_accept; | ||
584 | } | ||
585 | |||
586 | if ((type < 1) || (type > 3)) | ||
587 | { | ||
588 | /* bad, very bad */ | ||
589 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
590 | goto err; | ||
591 | } | ||
592 | s->init_num=0; | ||
593 | |||
594 | if (buf != buf_space) OPENSSL_free(buf); | ||
595 | s->first_packet=1; | ||
596 | return(SSL_accept(s)); | ||
597 | err: | ||
598 | if (buf != buf_space) OPENSSL_free(buf); | ||
599 | return(-1); | ||
600 | } | ||
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c deleted file mode 100644 index 64d317b7ac..0000000000 --- a/src/lib/libssl/s3_both.c +++ /dev/null | |||
@@ -1,635 +0,0 @@ | |||
1 | /* ssl/s3_both.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <limits.h> | ||
113 | #include <string.h> | ||
114 | #include <stdio.h> | ||
115 | #include "ssl_locl.h" | ||
116 | #include <openssl/buffer.h> | ||
117 | #include <openssl/rand.h> | ||
118 | #include <openssl/objects.h> | ||
119 | #include <openssl/evp.h> | ||
120 | #include <openssl/x509.h> | ||
121 | |||
122 | /* send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */ | ||
123 | int ssl3_do_write(SSL *s, int type) | ||
124 | { | ||
125 | int ret; | ||
126 | |||
127 | ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off], | ||
128 | s->init_num); | ||
129 | if (ret < 0) return(-1); | ||
130 | if (type == SSL3_RT_HANDSHAKE) | ||
131 | /* should not be done for 'Hello Request's, but in that case | ||
132 | * we'll ignore the result anyway */ | ||
133 | ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret); | ||
134 | |||
135 | if (ret == s->init_num) | ||
136 | { | ||
137 | if (s->msg_callback) | ||
138 | s->msg_callback(1, s->version, type, s->init_buf->data, (size_t)(s->init_off + s->init_num), s, s->msg_callback_arg); | ||
139 | return(1); | ||
140 | } | ||
141 | s->init_off+=ret; | ||
142 | s->init_num-=ret; | ||
143 | return(0); | ||
144 | } | ||
145 | |||
146 | int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen) | ||
147 | { | ||
148 | unsigned char *p,*d; | ||
149 | int i; | ||
150 | unsigned long l; | ||
151 | |||
152 | if (s->state == a) | ||
153 | { | ||
154 | d=(unsigned char *)s->init_buf->data; | ||
155 | p= &(d[4]); | ||
156 | |||
157 | i=s->method->ssl3_enc->final_finish_mac(s, | ||
158 | &(s->s3->finish_dgst1), | ||
159 | &(s->s3->finish_dgst2), | ||
160 | sender,slen,s->s3->tmp.finish_md); | ||
161 | s->s3->tmp.finish_md_len = i; | ||
162 | memcpy(p, s->s3->tmp.finish_md, i); | ||
163 | p+=i; | ||
164 | l=i; | ||
165 | |||
166 | #ifdef OPENSSL_SYS_WIN16 | ||
167 | /* MSVC 1.5 does not clear the top bytes of the word unless | ||
168 | * I do this. | ||
169 | */ | ||
170 | l&=0xffff; | ||
171 | #endif | ||
172 | |||
173 | *(d++)=SSL3_MT_FINISHED; | ||
174 | l2n3(l,d); | ||
175 | s->init_num=(int)l+4; | ||
176 | s->init_off=0; | ||
177 | |||
178 | s->state=b; | ||
179 | } | ||
180 | |||
181 | /* SSL3_ST_SEND_xxxxxx_HELLO_B */ | ||
182 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
183 | } | ||
184 | |||
185 | int ssl3_get_finished(SSL *s, int a, int b) | ||
186 | { | ||
187 | int al,i,ok; | ||
188 | long n; | ||
189 | unsigned char *p; | ||
190 | |||
191 | /* the mac has already been generated when we received the | ||
192 | * change cipher spec message and is in s->s3->tmp.peer_finish_md | ||
193 | */ | ||
194 | |||
195 | n=ssl3_get_message(s, | ||
196 | a, | ||
197 | b, | ||
198 | SSL3_MT_FINISHED, | ||
199 | 64, /* should actually be 36+4 :-) */ | ||
200 | &ok); | ||
201 | |||
202 | if (!ok) return((int)n); | ||
203 | |||
204 | /* If this occurs, we have missed a message */ | ||
205 | if (!s->s3->change_cipher_spec) | ||
206 | { | ||
207 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
208 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS); | ||
209 | goto f_err; | ||
210 | } | ||
211 | s->s3->change_cipher_spec=0; | ||
212 | |||
213 | p = (unsigned char *)s->init_msg; | ||
214 | i = s->s3->tmp.peer_finish_md_len; | ||
215 | |||
216 | if (i != n) | ||
217 | { | ||
218 | al=SSL_AD_DECODE_ERROR; | ||
219 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH); | ||
220 | goto f_err; | ||
221 | } | ||
222 | |||
223 | if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0) | ||
224 | { | ||
225 | al=SSL_AD_DECRYPT_ERROR; | ||
226 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED); | ||
227 | goto f_err; | ||
228 | } | ||
229 | |||
230 | return(1); | ||
231 | f_err: | ||
232 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
233 | return(0); | ||
234 | } | ||
235 | |||
236 | /* for these 2 messages, we need to | ||
237 | * ssl->enc_read_ctx re-init | ||
238 | * ssl->s3->read_sequence zero | ||
239 | * ssl->s3->read_mac_secret re-init | ||
240 | * ssl->session->read_sym_enc assign | ||
241 | * ssl->session->read_compression assign | ||
242 | * ssl->session->read_hash assign | ||
243 | */ | ||
244 | int ssl3_send_change_cipher_spec(SSL *s, int a, int b) | ||
245 | { | ||
246 | unsigned char *p; | ||
247 | |||
248 | if (s->state == a) | ||
249 | { | ||
250 | p=(unsigned char *)s->init_buf->data; | ||
251 | *p=SSL3_MT_CCS; | ||
252 | s->init_num=1; | ||
253 | s->init_off=0; | ||
254 | |||
255 | s->state=b; | ||
256 | } | ||
257 | |||
258 | /* SSL3_ST_CW_CHANGE_B */ | ||
259 | return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC)); | ||
260 | } | ||
261 | |||
262 | unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | ||
263 | { | ||
264 | unsigned char *p; | ||
265 | int n,i; | ||
266 | unsigned long l=7; | ||
267 | BUF_MEM *buf; | ||
268 | X509_STORE_CTX xs_ctx; | ||
269 | X509_OBJECT obj; | ||
270 | |||
271 | int no_chain; | ||
272 | |||
273 | if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs) | ||
274 | no_chain = 1; | ||
275 | else | ||
276 | no_chain = 0; | ||
277 | |||
278 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ | ||
279 | buf=s->init_buf; | ||
280 | if (!BUF_MEM_grow_clean(buf,10)) | ||
281 | { | ||
282 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
283 | return(0); | ||
284 | } | ||
285 | if (x != NULL) | ||
286 | { | ||
287 | if(!no_chain && !X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL)) | ||
288 | { | ||
289 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB); | ||
290 | return(0); | ||
291 | } | ||
292 | |||
293 | for (;;) | ||
294 | { | ||
295 | n=i2d_X509(x,NULL); | ||
296 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) | ||
297 | { | ||
298 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
299 | return(0); | ||
300 | } | ||
301 | p=(unsigned char *)&(buf->data[l]); | ||
302 | l2n3(n,p); | ||
303 | i2d_X509(x,&p); | ||
304 | l+=n+3; | ||
305 | |||
306 | if (no_chain) | ||
307 | break; | ||
308 | |||
309 | if (X509_NAME_cmp(X509_get_subject_name(x), | ||
310 | X509_get_issuer_name(x)) == 0) break; | ||
311 | |||
312 | i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509, | ||
313 | X509_get_issuer_name(x),&obj); | ||
314 | if (i <= 0) break; | ||
315 | x=obj.data.x509; | ||
316 | /* Count is one too high since the X509_STORE_get uped the | ||
317 | * ref count */ | ||
318 | X509_free(x); | ||
319 | } | ||
320 | if (!no_chain) | ||
321 | X509_STORE_CTX_cleanup(&xs_ctx); | ||
322 | } | ||
323 | |||
324 | /* Thawte special :-) */ | ||
325 | if (s->ctx->extra_certs != NULL) | ||
326 | for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++) | ||
327 | { | ||
328 | x=sk_X509_value(s->ctx->extra_certs,i); | ||
329 | n=i2d_X509(x,NULL); | ||
330 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) | ||
331 | { | ||
332 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
333 | return(0); | ||
334 | } | ||
335 | p=(unsigned char *)&(buf->data[l]); | ||
336 | l2n3(n,p); | ||
337 | i2d_X509(x,&p); | ||
338 | l+=n+3; | ||
339 | } | ||
340 | |||
341 | l-=7; | ||
342 | p=(unsigned char *)&(buf->data[4]); | ||
343 | l2n3(l,p); | ||
344 | l+=3; | ||
345 | p=(unsigned char *)&(buf->data[0]); | ||
346 | *(p++)=SSL3_MT_CERTIFICATE; | ||
347 | l2n3(l,p); | ||
348 | l+=4; | ||
349 | return(l); | ||
350 | } | ||
351 | |||
352 | /* Obtain handshake message of message type 'mt' (any if mt == -1), | ||
353 | * maximum acceptable body length 'max'. | ||
354 | * The first four bytes (msg_type and length) are read in state 'st1', | ||
355 | * the body is read in state 'stn'. | ||
356 | */ | ||
357 | long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | ||
358 | { | ||
359 | unsigned char *p; | ||
360 | unsigned long l; | ||
361 | long n; | ||
362 | int i,al; | ||
363 | |||
364 | if (s->s3->tmp.reuse_message) | ||
365 | { | ||
366 | s->s3->tmp.reuse_message=0; | ||
367 | if ((mt >= 0) && (s->s3->tmp.message_type != mt)) | ||
368 | { | ||
369 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
370 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
371 | goto f_err; | ||
372 | } | ||
373 | *ok=1; | ||
374 | s->init_msg = s->init_buf->data + 4; | ||
375 | s->init_num = (int)s->s3->tmp.message_size; | ||
376 | return s->init_num; | ||
377 | } | ||
378 | |||
379 | p=(unsigned char *)s->init_buf->data; | ||
380 | |||
381 | if (s->state == st1) /* s->init_num < 4 */ | ||
382 | { | ||
383 | int skip_message; | ||
384 | |||
385 | do | ||
386 | { | ||
387 | while (s->init_num < 4) | ||
388 | { | ||
389 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num], | ||
390 | 4 - s->init_num, 0); | ||
391 | if (i <= 0) | ||
392 | { | ||
393 | s->rwstate=SSL_READING; | ||
394 | *ok = 0; | ||
395 | return i; | ||
396 | } | ||
397 | s->init_num+=i; | ||
398 | } | ||
399 | |||
400 | skip_message = 0; | ||
401 | if (!s->server) | ||
402 | if (p[0] == SSL3_MT_HELLO_REQUEST) | ||
403 | /* The server may always send 'Hello Request' messages -- | ||
404 | * we are doing a handshake anyway now, so ignore them | ||
405 | * if their format is correct. Does not count for | ||
406 | * 'Finished' MAC. */ | ||
407 | if (p[1] == 0 && p[2] == 0 &&p[3] == 0) | ||
408 | { | ||
409 | s->init_num = 0; | ||
410 | skip_message = 1; | ||
411 | |||
412 | if (s->msg_callback) | ||
413 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, 4, s, s->msg_callback_arg); | ||
414 | } | ||
415 | } | ||
416 | while (skip_message); | ||
417 | |||
418 | /* s->init_num == 4 */ | ||
419 | |||
420 | if ((mt >= 0) && (*p != mt)) | ||
421 | { | ||
422 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
423 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
424 | goto f_err; | ||
425 | } | ||
426 | if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) && | ||
427 | (st1 == SSL3_ST_SR_CERT_A) && | ||
428 | (stn == SSL3_ST_SR_CERT_B)) | ||
429 | { | ||
430 | /* At this point we have got an MS SGC second client | ||
431 | * hello (maybe we should always allow the client to | ||
432 | * start a new handshake?). We need to restart the mac. | ||
433 | * Don't increment {num,total}_renegotiations because | ||
434 | * we have not completed the handshake. */ | ||
435 | ssl3_init_finished_mac(s); | ||
436 | } | ||
437 | |||
438 | s->s3->tmp.message_type= *(p++); | ||
439 | |||
440 | n2l3(p,l); | ||
441 | if (l > (unsigned long)max) | ||
442 | { | ||
443 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
444 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
445 | goto f_err; | ||
446 | } | ||
447 | if (l > (INT_MAX-4)) /* BUF_MEM_grow takes an 'int' parameter */ | ||
448 | { | ||
449 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
450 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
451 | goto f_err; | ||
452 | } | ||
453 | if (l && !BUF_MEM_grow_clean(s->init_buf,(int)l+4)) | ||
454 | { | ||
455 | SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); | ||
456 | goto err; | ||
457 | } | ||
458 | s->s3->tmp.message_size=l; | ||
459 | s->state=stn; | ||
460 | |||
461 | s->init_msg = s->init_buf->data + 4; | ||
462 | s->init_num = 0; | ||
463 | } | ||
464 | |||
465 | /* next state (stn) */ | ||
466 | p = s->init_msg; | ||
467 | n = s->s3->tmp.message_size - s->init_num; | ||
468 | while (n > 0) | ||
469 | { | ||
470 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0); | ||
471 | if (i <= 0) | ||
472 | { | ||
473 | s->rwstate=SSL_READING; | ||
474 | *ok = 0; | ||
475 | return i; | ||
476 | } | ||
477 | s->init_num += i; | ||
478 | n -= i; | ||
479 | } | ||
480 | ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4); | ||
481 | if (s->msg_callback) | ||
482 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, (size_t)s->init_num + 4, s, s->msg_callback_arg); | ||
483 | *ok=1; | ||
484 | return s->init_num; | ||
485 | f_err: | ||
486 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
487 | err: | ||
488 | *ok=0; | ||
489 | return(-1); | ||
490 | } | ||
491 | |||
492 | int ssl_cert_type(X509 *x, EVP_PKEY *pkey) | ||
493 | { | ||
494 | EVP_PKEY *pk; | ||
495 | int ret= -1,i,j; | ||
496 | |||
497 | if (pkey == NULL) | ||
498 | pk=X509_get_pubkey(x); | ||
499 | else | ||
500 | pk=pkey; | ||
501 | if (pk == NULL) goto err; | ||
502 | |||
503 | i=pk->type; | ||
504 | if (i == EVP_PKEY_RSA) | ||
505 | { | ||
506 | ret=SSL_PKEY_RSA_ENC; | ||
507 | if (x != NULL) | ||
508 | { | ||
509 | j=X509_get_ext_count(x); | ||
510 | /* check to see if this is a signing only certificate */ | ||
511 | /* EAY EAY EAY EAY */ | ||
512 | } | ||
513 | } | ||
514 | else if (i == EVP_PKEY_DSA) | ||
515 | { | ||
516 | ret=SSL_PKEY_DSA_SIGN; | ||
517 | } | ||
518 | else if (i == EVP_PKEY_DH) | ||
519 | { | ||
520 | /* if we just have a key, we needs to be guess */ | ||
521 | |||
522 | if (x == NULL) | ||
523 | ret=SSL_PKEY_DH_DSA; | ||
524 | else | ||
525 | { | ||
526 | j=X509_get_signature_type(x); | ||
527 | if (j == EVP_PKEY_RSA) | ||
528 | ret=SSL_PKEY_DH_RSA; | ||
529 | else if (j== EVP_PKEY_DSA) | ||
530 | ret=SSL_PKEY_DH_DSA; | ||
531 | else ret= -1; | ||
532 | } | ||
533 | } | ||
534 | else | ||
535 | ret= -1; | ||
536 | |||
537 | err: | ||
538 | if(!pkey) EVP_PKEY_free(pk); | ||
539 | return(ret); | ||
540 | } | ||
541 | |||
542 | int ssl_verify_alarm_type(long type) | ||
543 | { | ||
544 | int al; | ||
545 | |||
546 | switch(type) | ||
547 | { | ||
548 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
549 | case X509_V_ERR_UNABLE_TO_GET_CRL: | ||
550 | case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: | ||
551 | al=SSL_AD_UNKNOWN_CA; | ||
552 | break; | ||
553 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: | ||
554 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: | ||
555 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: | ||
556 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
557 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
558 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: | ||
559 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: | ||
560 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
561 | case X509_V_ERR_CRL_NOT_YET_VALID: | ||
562 | case X509_V_ERR_CERT_UNTRUSTED: | ||
563 | case X509_V_ERR_CERT_REJECTED: | ||
564 | al=SSL_AD_BAD_CERTIFICATE; | ||
565 | break; | ||
566 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: | ||
567 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: | ||
568 | al=SSL_AD_DECRYPT_ERROR; | ||
569 | break; | ||
570 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
571 | case X509_V_ERR_CRL_HAS_EXPIRED: | ||
572 | al=SSL_AD_CERTIFICATE_EXPIRED; | ||
573 | break; | ||
574 | case X509_V_ERR_CERT_REVOKED: | ||
575 | al=SSL_AD_CERTIFICATE_REVOKED; | ||
576 | break; | ||
577 | case X509_V_ERR_OUT_OF_MEM: | ||
578 | al=SSL_AD_INTERNAL_ERROR; | ||
579 | break; | ||
580 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
581 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | ||
582 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: | ||
583 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: | ||
584 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: | ||
585 | case X509_V_ERR_PATH_LENGTH_EXCEEDED: | ||
586 | case X509_V_ERR_INVALID_CA: | ||
587 | al=SSL_AD_UNKNOWN_CA; | ||
588 | break; | ||
589 | case X509_V_ERR_APPLICATION_VERIFICATION: | ||
590 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
591 | break; | ||
592 | case X509_V_ERR_INVALID_PURPOSE: | ||
593 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; | ||
594 | break; | ||
595 | default: | ||
596 | al=SSL_AD_CERTIFICATE_UNKNOWN; | ||
597 | break; | ||
598 | } | ||
599 | return(al); | ||
600 | } | ||
601 | |||
602 | int ssl3_setup_buffers(SSL *s) | ||
603 | { | ||
604 | unsigned char *p; | ||
605 | unsigned int extra; | ||
606 | size_t len; | ||
607 | |||
608 | if (s->s3->rbuf.buf == NULL) | ||
609 | { | ||
610 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
611 | extra=SSL3_RT_MAX_EXTRA; | ||
612 | else | ||
613 | extra=0; | ||
614 | len = SSL3_RT_MAX_PACKET_SIZE + extra; | ||
615 | if ((p=OPENSSL_malloc(len)) == NULL) | ||
616 | goto err; | ||
617 | s->s3->rbuf.buf = p; | ||
618 | s->s3->rbuf.len = len; | ||
619 | } | ||
620 | |||
621 | if (s->s3->wbuf.buf == NULL) | ||
622 | { | ||
623 | len = SSL3_RT_MAX_PACKET_SIZE; | ||
624 | len += SSL3_RT_HEADER_LENGTH + 256; /* extra space for empty fragment */ | ||
625 | if ((p=OPENSSL_malloc(len)) == NULL) | ||
626 | goto err; | ||
627 | s->s3->wbuf.buf = p; | ||
628 | s->s3->wbuf.len = len; | ||
629 | } | ||
630 | s->packet= &(s->s3->rbuf.buf[0]); | ||
631 | return(1); | ||
632 | err: | ||
633 | SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); | ||
634 | return(0); | ||
635 | } | ||
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c deleted file mode 100644 index 4163d97944..0000000000 --- a/src/lib/libssl/s3_clnt.c +++ /dev/null | |||
@@ -1,1985 +0,0 @@ | |||
1 | /* ssl/s3_clnt.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include "ssl_locl.h" | ||
114 | #include "kssl_lcl.h" | ||
115 | #include <openssl/buffer.h> | ||
116 | #include <openssl/rand.h> | ||
117 | #include <openssl/objects.h> | ||
118 | #include <openssl/evp.h> | ||
119 | #include <openssl/md5.h> | ||
120 | #include <openssl/fips.h> | ||
121 | |||
122 | static SSL_METHOD *ssl3_get_client_method(int ver); | ||
123 | static int ssl3_client_hello(SSL *s); | ||
124 | static int ssl3_get_server_hello(SSL *s); | ||
125 | static int ssl3_get_certificate_request(SSL *s); | ||
126 | static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b); | ||
127 | static int ssl3_get_server_done(SSL *s); | ||
128 | static int ssl3_send_client_verify(SSL *s); | ||
129 | static int ssl3_send_client_certificate(SSL *s); | ||
130 | static int ssl3_send_client_key_exchange(SSL *s); | ||
131 | static int ssl3_get_key_exchange(SSL *s); | ||
132 | static int ssl3_get_server_certificate(SSL *s); | ||
133 | static int ssl3_check_cert_and_algorithm(SSL *s); | ||
134 | static SSL_METHOD *ssl3_get_client_method(int ver) | ||
135 | { | ||
136 | if (ver == SSL3_VERSION) | ||
137 | return(SSLv3_client_method()); | ||
138 | else | ||
139 | return(NULL); | ||
140 | } | ||
141 | |||
142 | SSL_METHOD *SSLv3_client_method(void) | ||
143 | { | ||
144 | static int init=1; | ||
145 | static SSL_METHOD SSLv3_client_data; | ||
146 | |||
147 | if (init) | ||
148 | { | ||
149 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
150 | |||
151 | if (init) | ||
152 | { | ||
153 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | ||
154 | sizeof(SSL_METHOD)); | ||
155 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
156 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
157 | init=0; | ||
158 | } | ||
159 | |||
160 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
161 | } | ||
162 | return(&SSLv3_client_data); | ||
163 | } | ||
164 | |||
165 | int ssl3_connect(SSL *s) | ||
166 | { | ||
167 | BUF_MEM *buf=NULL; | ||
168 | unsigned long Time=(unsigned long)time(NULL),l; | ||
169 | long num1; | ||
170 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
171 | int ret= -1; | ||
172 | int new_state,state,skip=0; | ||
173 | |||
174 | RAND_add(&Time,sizeof(Time),0); | ||
175 | ERR_clear_error(); | ||
176 | clear_sys_error(); | ||
177 | |||
178 | if (s->info_callback != NULL) | ||
179 | cb=s->info_callback; | ||
180 | else if (s->ctx->info_callback != NULL) | ||
181 | cb=s->ctx->info_callback; | ||
182 | |||
183 | s->in_handshake++; | ||
184 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
185 | |||
186 | for (;;) | ||
187 | { | ||
188 | state=s->state; | ||
189 | |||
190 | switch(s->state) | ||
191 | { | ||
192 | case SSL_ST_RENEGOTIATE: | ||
193 | s->new_session=1; | ||
194 | s->state=SSL_ST_CONNECT; | ||
195 | s->ctx->stats.sess_connect_renegotiate++; | ||
196 | /* break */ | ||
197 | case SSL_ST_BEFORE: | ||
198 | case SSL_ST_CONNECT: | ||
199 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
200 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
201 | |||
202 | s->server=0; | ||
203 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
204 | |||
205 | if ((s->version & 0xff00 ) != 0x0300) | ||
206 | { | ||
207 | SSLerr(SSL_F_SSL3_CONNECT, ERR_R_INTERNAL_ERROR); | ||
208 | ret = -1; | ||
209 | goto end; | ||
210 | } | ||
211 | |||
212 | /* s->version=SSL3_VERSION; */ | ||
213 | s->type=SSL_ST_CONNECT; | ||
214 | |||
215 | if (s->init_buf == NULL) | ||
216 | { | ||
217 | if ((buf=BUF_MEM_new()) == NULL) | ||
218 | { | ||
219 | ret= -1; | ||
220 | goto end; | ||
221 | } | ||
222 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
223 | { | ||
224 | ret= -1; | ||
225 | goto end; | ||
226 | } | ||
227 | s->init_buf=buf; | ||
228 | buf=NULL; | ||
229 | } | ||
230 | |||
231 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
232 | |||
233 | /* setup buffing BIO */ | ||
234 | if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; } | ||
235 | |||
236 | /* don't push the buffering BIO quite yet */ | ||
237 | |||
238 | ssl3_init_finished_mac(s); | ||
239 | |||
240 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | ||
241 | s->ctx->stats.sess_connect++; | ||
242 | s->init_num=0; | ||
243 | break; | ||
244 | |||
245 | case SSL3_ST_CW_CLNT_HELLO_A: | ||
246 | case SSL3_ST_CW_CLNT_HELLO_B: | ||
247 | |||
248 | s->shutdown=0; | ||
249 | ret=ssl3_client_hello(s); | ||
250 | if (ret <= 0) goto end; | ||
251 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
252 | s->init_num=0; | ||
253 | |||
254 | /* turn on buffering for the next lot of output */ | ||
255 | if (s->bbio != s->wbio) | ||
256 | s->wbio=BIO_push(s->bbio,s->wbio); | ||
257 | |||
258 | break; | ||
259 | |||
260 | case SSL3_ST_CR_SRVR_HELLO_A: | ||
261 | case SSL3_ST_CR_SRVR_HELLO_B: | ||
262 | ret=ssl3_get_server_hello(s); | ||
263 | if (ret <= 0) goto end; | ||
264 | if (s->hit) | ||
265 | s->state=SSL3_ST_CR_FINISHED_A; | ||
266 | else | ||
267 | s->state=SSL3_ST_CR_CERT_A; | ||
268 | s->init_num=0; | ||
269 | break; | ||
270 | |||
271 | case SSL3_ST_CR_CERT_A: | ||
272 | case SSL3_ST_CR_CERT_B: | ||
273 | /* Check if it is anon DH */ | ||
274 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
275 | { | ||
276 | ret=ssl3_get_server_certificate(s); | ||
277 | if (ret <= 0) goto end; | ||
278 | } | ||
279 | else | ||
280 | skip=1; | ||
281 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
282 | s->init_num=0; | ||
283 | break; | ||
284 | |||
285 | case SSL3_ST_CR_KEY_EXCH_A: | ||
286 | case SSL3_ST_CR_KEY_EXCH_B: | ||
287 | ret=ssl3_get_key_exchange(s); | ||
288 | if (ret <= 0) goto end; | ||
289 | s->state=SSL3_ST_CR_CERT_REQ_A; | ||
290 | s->init_num=0; | ||
291 | |||
292 | /* at this point we check that we have the | ||
293 | * required stuff from the server */ | ||
294 | if (!ssl3_check_cert_and_algorithm(s)) | ||
295 | { | ||
296 | ret= -1; | ||
297 | goto end; | ||
298 | } | ||
299 | break; | ||
300 | |||
301 | case SSL3_ST_CR_CERT_REQ_A: | ||
302 | case SSL3_ST_CR_CERT_REQ_B: | ||
303 | ret=ssl3_get_certificate_request(s); | ||
304 | if (ret <= 0) goto end; | ||
305 | s->state=SSL3_ST_CR_SRVR_DONE_A; | ||
306 | s->init_num=0; | ||
307 | break; | ||
308 | |||
309 | case SSL3_ST_CR_SRVR_DONE_A: | ||
310 | case SSL3_ST_CR_SRVR_DONE_B: | ||
311 | ret=ssl3_get_server_done(s); | ||
312 | if (ret <= 0) goto end; | ||
313 | if (s->s3->tmp.cert_req) | ||
314 | s->state=SSL3_ST_CW_CERT_A; | ||
315 | else | ||
316 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
317 | s->init_num=0; | ||
318 | |||
319 | break; | ||
320 | |||
321 | case SSL3_ST_CW_CERT_A: | ||
322 | case SSL3_ST_CW_CERT_B: | ||
323 | case SSL3_ST_CW_CERT_C: | ||
324 | case SSL3_ST_CW_CERT_D: | ||
325 | ret=ssl3_send_client_certificate(s); | ||
326 | if (ret <= 0) goto end; | ||
327 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
328 | s->init_num=0; | ||
329 | break; | ||
330 | |||
331 | case SSL3_ST_CW_KEY_EXCH_A: | ||
332 | case SSL3_ST_CW_KEY_EXCH_B: | ||
333 | ret=ssl3_send_client_key_exchange(s); | ||
334 | if (ret <= 0) goto end; | ||
335 | l=s->s3->tmp.new_cipher->algorithms; | ||
336 | /* EAY EAY EAY need to check for DH fix cert | ||
337 | * sent back */ | ||
338 | /* For TLS, cert_req is set to 2, so a cert chain | ||
339 | * of nothing is sent, but no verify packet is sent */ | ||
340 | if (s->s3->tmp.cert_req == 1) | ||
341 | { | ||
342 | s->state=SSL3_ST_CW_CERT_VRFY_A; | ||
343 | } | ||
344 | else | ||
345 | { | ||
346 | s->state=SSL3_ST_CW_CHANGE_A; | ||
347 | s->s3->change_cipher_spec=0; | ||
348 | } | ||
349 | |||
350 | s->init_num=0; | ||
351 | break; | ||
352 | |||
353 | case SSL3_ST_CW_CERT_VRFY_A: | ||
354 | case SSL3_ST_CW_CERT_VRFY_B: | ||
355 | ret=ssl3_send_client_verify(s); | ||
356 | if (ret <= 0) goto end; | ||
357 | s->state=SSL3_ST_CW_CHANGE_A; | ||
358 | s->init_num=0; | ||
359 | s->s3->change_cipher_spec=0; | ||
360 | break; | ||
361 | |||
362 | case SSL3_ST_CW_CHANGE_A: | ||
363 | case SSL3_ST_CW_CHANGE_B: | ||
364 | ret=ssl3_send_change_cipher_spec(s, | ||
365 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); | ||
366 | if (ret <= 0) goto end; | ||
367 | s->state=SSL3_ST_CW_FINISHED_A; | ||
368 | s->init_num=0; | ||
369 | |||
370 | s->session->cipher=s->s3->tmp.new_cipher; | ||
371 | if (s->s3->tmp.new_compression == NULL) | ||
372 | s->session->compress_meth=0; | ||
373 | else | ||
374 | s->session->compress_meth= | ||
375 | s->s3->tmp.new_compression->id; | ||
376 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
377 | { | ||
378 | ret= -1; | ||
379 | goto end; | ||
380 | } | ||
381 | |||
382 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
383 | SSL3_CHANGE_CIPHER_CLIENT_WRITE)) | ||
384 | { | ||
385 | ret= -1; | ||
386 | goto end; | ||
387 | } | ||
388 | |||
389 | break; | ||
390 | |||
391 | case SSL3_ST_CW_FINISHED_A: | ||
392 | case SSL3_ST_CW_FINISHED_B: | ||
393 | ret=ssl3_send_finished(s, | ||
394 | SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B, | ||
395 | s->method->ssl3_enc->client_finished_label, | ||
396 | s->method->ssl3_enc->client_finished_label_len); | ||
397 | if (ret <= 0) goto end; | ||
398 | s->state=SSL3_ST_CW_FLUSH; | ||
399 | |||
400 | /* clear flags */ | ||
401 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
402 | if (s->hit) | ||
403 | { | ||
404 | s->s3->tmp.next_state=SSL_ST_OK; | ||
405 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) | ||
406 | { | ||
407 | s->state=SSL_ST_OK; | ||
408 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; | ||
409 | s->s3->delay_buf_pop_ret=0; | ||
410 | } | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; | ||
415 | } | ||
416 | s->init_num=0; | ||
417 | break; | ||
418 | |||
419 | case SSL3_ST_CR_FINISHED_A: | ||
420 | case SSL3_ST_CR_FINISHED_B: | ||
421 | |||
422 | ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A, | ||
423 | SSL3_ST_CR_FINISHED_B); | ||
424 | if (ret <= 0) goto end; | ||
425 | |||
426 | if (s->hit) | ||
427 | s->state=SSL3_ST_CW_CHANGE_A; | ||
428 | else | ||
429 | s->state=SSL_ST_OK; | ||
430 | s->init_num=0; | ||
431 | break; | ||
432 | |||
433 | case SSL3_ST_CW_FLUSH: | ||
434 | /* number of bytes to be flushed */ | ||
435 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
436 | if (num1 > 0) | ||
437 | { | ||
438 | s->rwstate=SSL_WRITING; | ||
439 | num1=BIO_flush(s->wbio); | ||
440 | if (num1 <= 0) { ret= -1; goto end; } | ||
441 | s->rwstate=SSL_NOTHING; | ||
442 | } | ||
443 | |||
444 | s->state=s->s3->tmp.next_state; | ||
445 | break; | ||
446 | |||
447 | case SSL_ST_OK: | ||
448 | /* clean a few things up */ | ||
449 | ssl3_cleanup_key_block(s); | ||
450 | |||
451 | if (s->init_buf != NULL) | ||
452 | { | ||
453 | BUF_MEM_free(s->init_buf); | ||
454 | s->init_buf=NULL; | ||
455 | } | ||
456 | |||
457 | /* If we are not 'joining' the last two packets, | ||
458 | * remove the buffering now */ | ||
459 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
460 | ssl_free_wbio_buffer(s); | ||
461 | /* else do it later in ssl3_write */ | ||
462 | |||
463 | s->init_num=0; | ||
464 | s->new_session=0; | ||
465 | |||
466 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | ||
467 | if (s->hit) s->ctx->stats.sess_hit++; | ||
468 | |||
469 | ret=1; | ||
470 | /* s->server=0; */ | ||
471 | s->handshake_func=ssl3_connect; | ||
472 | s->ctx->stats.sess_connect_good++; | ||
473 | |||
474 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
475 | |||
476 | goto end; | ||
477 | /* break; */ | ||
478 | |||
479 | default: | ||
480 | SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE); | ||
481 | ret= -1; | ||
482 | goto end; | ||
483 | /* break; */ | ||
484 | } | ||
485 | |||
486 | /* did we do anything */ | ||
487 | if (!s->s3->tmp.reuse_message && !skip) | ||
488 | { | ||
489 | if (s->debug) | ||
490 | { | ||
491 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
492 | goto end; | ||
493 | } | ||
494 | |||
495 | if ((cb != NULL) && (s->state != state)) | ||
496 | { | ||
497 | new_state=s->state; | ||
498 | s->state=state; | ||
499 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
500 | s->state=new_state; | ||
501 | } | ||
502 | } | ||
503 | skip=0; | ||
504 | } | ||
505 | end: | ||
506 | s->in_handshake--; | ||
507 | if (buf != NULL) | ||
508 | BUF_MEM_free(buf); | ||
509 | if (cb != NULL) | ||
510 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
511 | return(ret); | ||
512 | } | ||
513 | |||
514 | |||
515 | static int ssl3_client_hello(SSL *s) | ||
516 | { | ||
517 | unsigned char *buf; | ||
518 | unsigned char *p,*d; | ||
519 | int i,j; | ||
520 | unsigned long Time,l; | ||
521 | SSL_COMP *comp; | ||
522 | |||
523 | buf=(unsigned char *)s->init_buf->data; | ||
524 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | ||
525 | { | ||
526 | if ((s->session == NULL) || | ||
527 | (s->session->ssl_version != s->version) || | ||
528 | (s->session->not_resumable)) | ||
529 | { | ||
530 | if (!ssl_get_new_session(s,0)) | ||
531 | goto err; | ||
532 | } | ||
533 | /* else use the pre-loaded session */ | ||
534 | |||
535 | p=s->s3->client_random; | ||
536 | Time=(unsigned long)time(NULL); /* Time */ | ||
537 | l2n(Time,p); | ||
538 | if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | ||
539 | goto err; | ||
540 | |||
541 | /* Do the message type and length last */ | ||
542 | d=p= &(buf[4]); | ||
543 | |||
544 | *(p++)=s->version>>8; | ||
545 | *(p++)=s->version&0xff; | ||
546 | s->client_version=s->version; | ||
547 | |||
548 | /* Random stuff */ | ||
549 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
550 | p+=SSL3_RANDOM_SIZE; | ||
551 | |||
552 | /* Session ID */ | ||
553 | if (s->new_session) | ||
554 | i=0; | ||
555 | else | ||
556 | i=s->session->session_id_length; | ||
557 | *(p++)=i; | ||
558 | if (i != 0) | ||
559 | { | ||
560 | if (i > sizeof s->session->session_id) | ||
561 | { | ||
562 | SSLerr(SSL_F_SSL3_CLIENT_HELLO, ERR_R_INTERNAL_ERROR); | ||
563 | goto err; | ||
564 | } | ||
565 | memcpy(p,s->session->session_id,i); | ||
566 | p+=i; | ||
567 | } | ||
568 | |||
569 | /* Ciphers supported */ | ||
570 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]),0); | ||
571 | if (i == 0) | ||
572 | { | ||
573 | SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
574 | goto err; | ||
575 | } | ||
576 | s2n(i,p); | ||
577 | p+=i; | ||
578 | |||
579 | /* COMPRESSION */ | ||
580 | if (s->ctx->comp_methods == NULL) | ||
581 | j=0; | ||
582 | else | ||
583 | j=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
584 | *(p++)=1+j; | ||
585 | for (i=0; i<j; i++) | ||
586 | { | ||
587 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | ||
588 | *(p++)=comp->id; | ||
589 | } | ||
590 | *(p++)=0; /* Add the NULL method */ | ||
591 | |||
592 | l=(p-d); | ||
593 | d=buf; | ||
594 | *(d++)=SSL3_MT_CLIENT_HELLO; | ||
595 | l2n3(l,d); | ||
596 | |||
597 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
598 | /* number of bytes to write */ | ||
599 | s->init_num=p-buf; | ||
600 | s->init_off=0; | ||
601 | } | ||
602 | |||
603 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
604 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
605 | err: | ||
606 | return(-1); | ||
607 | } | ||
608 | |||
609 | static int ssl3_get_server_hello(SSL *s) | ||
610 | { | ||
611 | STACK_OF(SSL_CIPHER) *sk; | ||
612 | SSL_CIPHER *c; | ||
613 | unsigned char *p,*d; | ||
614 | int i,al,ok; | ||
615 | unsigned int j; | ||
616 | long n; | ||
617 | SSL_COMP *comp; | ||
618 | |||
619 | n=ssl3_get_message(s, | ||
620 | SSL3_ST_CR_SRVR_HELLO_A, | ||
621 | SSL3_ST_CR_SRVR_HELLO_B, | ||
622 | SSL3_MT_SERVER_HELLO, | ||
623 | 300, /* ?? */ | ||
624 | &ok); | ||
625 | |||
626 | if (!ok) return((int)n); | ||
627 | d=p=(unsigned char *)s->init_msg; | ||
628 | |||
629 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff))) | ||
630 | { | ||
631 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION); | ||
632 | s->version=(s->version&0xff00)|p[1]; | ||
633 | al=SSL_AD_PROTOCOL_VERSION; | ||
634 | goto f_err; | ||
635 | } | ||
636 | p+=2; | ||
637 | |||
638 | /* load the server hello data */ | ||
639 | /* load the server random */ | ||
640 | memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE); | ||
641 | p+=SSL3_RANDOM_SIZE; | ||
642 | |||
643 | /* get the session-id */ | ||
644 | j= *(p++); | ||
645 | |||
646 | if ((j > sizeof s->session->session_id) || (j > SSL3_SESSION_ID_SIZE)) | ||
647 | { | ||
648 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
649 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG); | ||
650 | goto f_err; | ||
651 | } | ||
652 | |||
653 | if (j != 0 && j == s->session->session_id_length | ||
654 | && memcmp(p,s->session->session_id,j) == 0) | ||
655 | { | ||
656 | if(s->sid_ctx_length != s->session->sid_ctx_length | ||
657 | || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length)) | ||
658 | { | ||
659 | /* actually a client application bug */ | ||
660 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
661 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | ||
662 | goto f_err; | ||
663 | } | ||
664 | s->hit=1; | ||
665 | } | ||
666 | else /* a miss or crap from the other end */ | ||
667 | { | ||
668 | /* If we were trying for session-id reuse, make a new | ||
669 | * SSL_SESSION so we don't stuff up other people */ | ||
670 | s->hit=0; | ||
671 | if (s->session->session_id_length > 0) | ||
672 | { | ||
673 | if (!ssl_get_new_session(s,0)) | ||
674 | { | ||
675 | al=SSL_AD_INTERNAL_ERROR; | ||
676 | goto f_err; | ||
677 | } | ||
678 | } | ||
679 | s->session->session_id_length=j; | ||
680 | memcpy(s->session->session_id,p,j); /* j could be 0 */ | ||
681 | } | ||
682 | p+=j; | ||
683 | c=ssl_get_cipher_by_char(s,p); | ||
684 | if (c == NULL) | ||
685 | { | ||
686 | /* unknown cipher */ | ||
687 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
688 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED); | ||
689 | goto f_err; | ||
690 | } | ||
691 | p+=ssl_put_cipher_by_char(s,NULL,NULL); | ||
692 | |||
693 | sk=ssl_get_ciphers_by_id(s); | ||
694 | i=sk_SSL_CIPHER_find(sk,c); | ||
695 | if (i < 0) | ||
696 | { | ||
697 | /* we did not say we would use this cipher */ | ||
698 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
699 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED); | ||
700 | goto f_err; | ||
701 | } | ||
702 | |||
703 | /* Depending on the session caching (internal/external), the cipher | ||
704 | and/or cipher_id values may not be set. Make sure that | ||
705 | cipher_id is set and use it for comparison. */ | ||
706 | if (s->session->cipher) | ||
707 | s->session->cipher_id = s->session->cipher->id; | ||
708 | if (s->hit && (s->session->cipher_id != c->id)) | ||
709 | { | ||
710 | if (!(s->options & | ||
711 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) | ||
712 | { | ||
713 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
714 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED); | ||
715 | goto f_err; | ||
716 | } | ||
717 | } | ||
718 | s->s3->tmp.new_cipher=c; | ||
719 | |||
720 | /* lets get the compression algorithm */ | ||
721 | /* COMPRESSION */ | ||
722 | j= *(p++); | ||
723 | if (j == 0) | ||
724 | comp=NULL; | ||
725 | else | ||
726 | comp=ssl3_comp_find(s->ctx->comp_methods,j); | ||
727 | |||
728 | if ((j != 0) && (comp == NULL)) | ||
729 | { | ||
730 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
731 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | ||
732 | goto f_err; | ||
733 | } | ||
734 | else | ||
735 | { | ||
736 | s->s3->tmp.new_compression=comp; | ||
737 | } | ||
738 | |||
739 | if (p != (d+n)) | ||
740 | { | ||
741 | /* wrong packet length */ | ||
742 | al=SSL_AD_DECODE_ERROR; | ||
743 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH); | ||
744 | goto err; | ||
745 | } | ||
746 | |||
747 | return(1); | ||
748 | f_err: | ||
749 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
750 | err: | ||
751 | return(-1); | ||
752 | } | ||
753 | |||
754 | static int ssl3_get_server_certificate(SSL *s) | ||
755 | { | ||
756 | int al,i,ok,ret= -1; | ||
757 | unsigned long n,nc,llen,l; | ||
758 | X509 *x=NULL; | ||
759 | unsigned char *p,*d,*q; | ||
760 | STACK_OF(X509) *sk=NULL; | ||
761 | SESS_CERT *sc; | ||
762 | EVP_PKEY *pkey=NULL; | ||
763 | int need_cert = 1; /* VRS: 0=> will allow null cert if auth == KRB5 */ | ||
764 | |||
765 | n=ssl3_get_message(s, | ||
766 | SSL3_ST_CR_CERT_A, | ||
767 | SSL3_ST_CR_CERT_B, | ||
768 | -1, | ||
769 | s->max_cert_list, | ||
770 | &ok); | ||
771 | |||
772 | if (!ok) return((int)n); | ||
773 | |||
774 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) | ||
775 | { | ||
776 | s->s3->tmp.reuse_message=1; | ||
777 | return(1); | ||
778 | } | ||
779 | |||
780 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
781 | { | ||
782 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
783 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE); | ||
784 | goto f_err; | ||
785 | } | ||
786 | d=p=(unsigned char *)s->init_msg; | ||
787 | |||
788 | if ((sk=sk_X509_new_null()) == NULL) | ||
789 | { | ||
790 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
791 | goto err; | ||
792 | } | ||
793 | |||
794 | n2l3(p,llen); | ||
795 | if (llen+3 != n) | ||
796 | { | ||
797 | al=SSL_AD_DECODE_ERROR; | ||
798 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
799 | goto f_err; | ||
800 | } | ||
801 | for (nc=0; nc<llen; ) | ||
802 | { | ||
803 | n2l3(p,l); | ||
804 | if ((l+nc+3) > llen) | ||
805 | { | ||
806 | al=SSL_AD_DECODE_ERROR; | ||
807 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
808 | goto f_err; | ||
809 | } | ||
810 | |||
811 | q=p; | ||
812 | x=d2i_X509(NULL,&q,l); | ||
813 | if (x == NULL) | ||
814 | { | ||
815 | al=SSL_AD_BAD_CERTIFICATE; | ||
816 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB); | ||
817 | goto f_err; | ||
818 | } | ||
819 | if (q != (p+l)) | ||
820 | { | ||
821 | al=SSL_AD_DECODE_ERROR; | ||
822 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
823 | goto f_err; | ||
824 | } | ||
825 | if (!sk_X509_push(sk,x)) | ||
826 | { | ||
827 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
828 | goto err; | ||
829 | } | ||
830 | x=NULL; | ||
831 | nc+=l+3; | ||
832 | p=q; | ||
833 | } | ||
834 | |||
835 | i=ssl_verify_cert_chain(s,sk); | ||
836 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i) | ||
837 | #ifndef OPENSSL_NO_KRB5 | ||
838 | && (s->s3->tmp.new_cipher->algorithms & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | ||
839 | != (SSL_aKRB5|SSL_kKRB5) | ||
840 | #endif /* OPENSSL_NO_KRB5 */ | ||
841 | ) | ||
842 | { | ||
843 | al=ssl_verify_alarm_type(s->verify_result); | ||
844 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); | ||
845 | goto f_err; | ||
846 | } | ||
847 | ERR_clear_error(); /* but we keep s->verify_result */ | ||
848 | |||
849 | sc=ssl_sess_cert_new(); | ||
850 | if (sc == NULL) goto err; | ||
851 | |||
852 | if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert); | ||
853 | s->session->sess_cert=sc; | ||
854 | |||
855 | sc->cert_chain=sk; | ||
856 | /* Inconsistency alert: cert_chain does include the peer's | ||
857 | * certificate, which we don't include in s3_srvr.c */ | ||
858 | x=sk_X509_value(sk,0); | ||
859 | sk=NULL; | ||
860 | /* VRS 19990621: possible memory leak; sk=null ==> !sk_pop_free() @end*/ | ||
861 | |||
862 | pkey=X509_get_pubkey(x); | ||
863 | |||
864 | /* VRS: allow null cert if auth == KRB5 */ | ||
865 | need_cert = ((s->s3->tmp.new_cipher->algorithms | ||
866 | & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | ||
867 | == (SSL_aKRB5|SSL_kKRB5))? 0: 1; | ||
868 | |||
869 | #ifdef KSSL_DEBUG | ||
870 | printf("pkey,x = %p, %p\n", pkey,x); | ||
871 | printf("ssl_cert_type(x,pkey) = %d\n", ssl_cert_type(x,pkey)); | ||
872 | printf("cipher, alg, nc = %s, %lx, %d\n", s->s3->tmp.new_cipher->name, | ||
873 | s->s3->tmp.new_cipher->algorithms, need_cert); | ||
874 | #endif /* KSSL_DEBUG */ | ||
875 | |||
876 | if (need_cert && ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))) | ||
877 | { | ||
878 | x=NULL; | ||
879 | al=SSL3_AL_FATAL; | ||
880 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE, | ||
881 | SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS); | ||
882 | goto f_err; | ||
883 | } | ||
884 | |||
885 | i=ssl_cert_type(x,pkey); | ||
886 | if (need_cert && i < 0) | ||
887 | { | ||
888 | x=NULL; | ||
889 | al=SSL3_AL_FATAL; | ||
890 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE, | ||
891 | SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
892 | goto f_err; | ||
893 | } | ||
894 | |||
895 | if (need_cert) | ||
896 | { | ||
897 | sc->peer_cert_type=i; | ||
898 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
899 | /* Why would the following ever happen? | ||
900 | * We just created sc a couple of lines ago. */ | ||
901 | if (sc->peer_pkeys[i].x509 != NULL) | ||
902 | X509_free(sc->peer_pkeys[i].x509); | ||
903 | sc->peer_pkeys[i].x509=x; | ||
904 | sc->peer_key= &(sc->peer_pkeys[i]); | ||
905 | |||
906 | if (s->session->peer != NULL) | ||
907 | X509_free(s->session->peer); | ||
908 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
909 | s->session->peer=x; | ||
910 | } | ||
911 | else | ||
912 | { | ||
913 | sc->peer_cert_type=i; | ||
914 | sc->peer_key= NULL; | ||
915 | |||
916 | if (s->session->peer != NULL) | ||
917 | X509_free(s->session->peer); | ||
918 | s->session->peer=NULL; | ||
919 | } | ||
920 | s->session->verify_result = s->verify_result; | ||
921 | |||
922 | x=NULL; | ||
923 | ret=1; | ||
924 | |||
925 | if (0) | ||
926 | { | ||
927 | f_err: | ||
928 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
929 | } | ||
930 | err: | ||
931 | EVP_PKEY_free(pkey); | ||
932 | X509_free(x); | ||
933 | sk_X509_pop_free(sk,X509_free); | ||
934 | return(ret); | ||
935 | } | ||
936 | |||
937 | static int ssl3_get_key_exchange(SSL *s) | ||
938 | { | ||
939 | #ifndef OPENSSL_NO_RSA | ||
940 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; | ||
941 | #endif | ||
942 | EVP_MD_CTX md_ctx; | ||
943 | unsigned char *param,*p; | ||
944 | int al,i,j,param_len,ok; | ||
945 | long n,alg; | ||
946 | EVP_PKEY *pkey=NULL; | ||
947 | #ifndef OPENSSL_NO_RSA | ||
948 | RSA *rsa=NULL; | ||
949 | #endif | ||
950 | #ifndef OPENSSL_NO_DH | ||
951 | DH *dh=NULL; | ||
952 | #endif | ||
953 | |||
954 | /* use same message size as in ssl3_get_certificate_request() | ||
955 | * as ServerKeyExchange message may be skipped */ | ||
956 | n=ssl3_get_message(s, | ||
957 | SSL3_ST_CR_KEY_EXCH_A, | ||
958 | SSL3_ST_CR_KEY_EXCH_B, | ||
959 | -1, | ||
960 | s->max_cert_list, | ||
961 | &ok); | ||
962 | |||
963 | if (!ok) return((int)n); | ||
964 | |||
965 | if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) | ||
966 | { | ||
967 | s->s3->tmp.reuse_message=1; | ||
968 | return(1); | ||
969 | } | ||
970 | |||
971 | param=p=(unsigned char *)s->init_msg; | ||
972 | |||
973 | if (s->session->sess_cert != NULL) | ||
974 | { | ||
975 | #ifndef OPENSSL_NO_RSA | ||
976 | if (s->session->sess_cert->peer_rsa_tmp != NULL) | ||
977 | { | ||
978 | RSA_free(s->session->sess_cert->peer_rsa_tmp); | ||
979 | s->session->sess_cert->peer_rsa_tmp=NULL; | ||
980 | } | ||
981 | #endif | ||
982 | #ifndef OPENSSL_NO_DH | ||
983 | if (s->session->sess_cert->peer_dh_tmp) | ||
984 | { | ||
985 | DH_free(s->session->sess_cert->peer_dh_tmp); | ||
986 | s->session->sess_cert->peer_dh_tmp=NULL; | ||
987 | } | ||
988 | #endif | ||
989 | } | ||
990 | else | ||
991 | { | ||
992 | s->session->sess_cert=ssl_sess_cert_new(); | ||
993 | } | ||
994 | |||
995 | param_len=0; | ||
996 | alg=s->s3->tmp.new_cipher->algorithms; | ||
997 | EVP_MD_CTX_init(&md_ctx); | ||
998 | |||
999 | #ifndef OPENSSL_NO_RSA | ||
1000 | if (alg & SSL_kRSA) | ||
1001 | { | ||
1002 | if ((rsa=RSA_new()) == NULL) | ||
1003 | { | ||
1004 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
1005 | goto err; | ||
1006 | } | ||
1007 | n2s(p,i); | ||
1008 | param_len=i+2; | ||
1009 | if (param_len > n) | ||
1010 | { | ||
1011 | al=SSL_AD_DECODE_ERROR; | ||
1012 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH); | ||
1013 | goto f_err; | ||
1014 | } | ||
1015 | if (!(rsa->n=BN_bin2bn(p,i,rsa->n))) | ||
1016 | { | ||
1017 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
1018 | goto err; | ||
1019 | } | ||
1020 | p+=i; | ||
1021 | |||
1022 | n2s(p,i); | ||
1023 | param_len+=i+2; | ||
1024 | if (param_len > n) | ||
1025 | { | ||
1026 | al=SSL_AD_DECODE_ERROR; | ||
1027 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH); | ||
1028 | goto f_err; | ||
1029 | } | ||
1030 | if (!(rsa->e=BN_bin2bn(p,i,rsa->e))) | ||
1031 | { | ||
1032 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
1033 | goto err; | ||
1034 | } | ||
1035 | p+=i; | ||
1036 | n-=param_len; | ||
1037 | |||
1038 | /* this should be because we are using an export cipher */ | ||
1039 | if (alg & SSL_aRSA) | ||
1040 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
1041 | else | ||
1042 | { | ||
1043 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
1044 | goto err; | ||
1045 | } | ||
1046 | s->session->sess_cert->peer_rsa_tmp=rsa; | ||
1047 | rsa=NULL; | ||
1048 | } | ||
1049 | #else /* OPENSSL_NO_RSA */ | ||
1050 | if (0) | ||
1051 | ; | ||
1052 | #endif | ||
1053 | #ifndef OPENSSL_NO_DH | ||
1054 | else if (alg & SSL_kEDH) | ||
1055 | { | ||
1056 | if ((dh=DH_new()) == NULL) | ||
1057 | { | ||
1058 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1059 | goto err; | ||
1060 | } | ||
1061 | n2s(p,i); | ||
1062 | param_len=i+2; | ||
1063 | if (param_len > n) | ||
1064 | { | ||
1065 | al=SSL_AD_DECODE_ERROR; | ||
1066 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH); | ||
1067 | goto f_err; | ||
1068 | } | ||
1069 | if (!(dh->p=BN_bin2bn(p,i,NULL))) | ||
1070 | { | ||
1071 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
1072 | goto err; | ||
1073 | } | ||
1074 | p+=i; | ||
1075 | |||
1076 | n2s(p,i); | ||
1077 | param_len+=i+2; | ||
1078 | if (param_len > n) | ||
1079 | { | ||
1080 | al=SSL_AD_DECODE_ERROR; | ||
1081 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH); | ||
1082 | goto f_err; | ||
1083 | } | ||
1084 | if (!(dh->g=BN_bin2bn(p,i,NULL))) | ||
1085 | { | ||
1086 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
1087 | goto err; | ||
1088 | } | ||
1089 | p+=i; | ||
1090 | |||
1091 | n2s(p,i); | ||
1092 | param_len+=i+2; | ||
1093 | if (param_len > n) | ||
1094 | { | ||
1095 | al=SSL_AD_DECODE_ERROR; | ||
1096 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH); | ||
1097 | goto f_err; | ||
1098 | } | ||
1099 | if (!(dh->pub_key=BN_bin2bn(p,i,NULL))) | ||
1100 | { | ||
1101 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
1102 | goto err; | ||
1103 | } | ||
1104 | p+=i; | ||
1105 | n-=param_len; | ||
1106 | |||
1107 | #ifndef OPENSSL_NO_RSA | ||
1108 | if (alg & SSL_aRSA) | ||
1109 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
1110 | #else | ||
1111 | if (0) | ||
1112 | ; | ||
1113 | #endif | ||
1114 | #ifndef OPENSSL_NO_DSA | ||
1115 | else if (alg & SSL_aDSS) | ||
1116 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509); | ||
1117 | #endif | ||
1118 | /* else anonymous DH, so no certificate or pkey. */ | ||
1119 | |||
1120 | s->session->sess_cert->peer_dh_tmp=dh; | ||
1121 | dh=NULL; | ||
1122 | } | ||
1123 | else if ((alg & SSL_kDHr) || (alg & SSL_kDHd)) | ||
1124 | { | ||
1125 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1126 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
1127 | goto f_err; | ||
1128 | } | ||
1129 | #endif /* !OPENSSL_NO_DH */ | ||
1130 | if (alg & SSL_aFZA) | ||
1131 | { | ||
1132 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1133 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
1134 | goto f_err; | ||
1135 | } | ||
1136 | |||
1137 | |||
1138 | /* p points to the next byte, there are 'n' bytes left */ | ||
1139 | |||
1140 | |||
1141 | /* if it was signed, check the signature */ | ||
1142 | if (pkey != NULL) | ||
1143 | { | ||
1144 | n2s(p,i); | ||
1145 | n-=2; | ||
1146 | j=EVP_PKEY_size(pkey); | ||
1147 | |||
1148 | if ((i != n) || (n > j) || (n <= 0)) | ||
1149 | { | ||
1150 | /* wrong packet length */ | ||
1151 | al=SSL_AD_DECODE_ERROR; | ||
1152 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH); | ||
1153 | goto f_err; | ||
1154 | } | ||
1155 | |||
1156 | #ifndef OPENSSL_NO_RSA | ||
1157 | if (pkey->type == EVP_PKEY_RSA) | ||
1158 | { | ||
1159 | int num; | ||
1160 | |||
1161 | j=0; | ||
1162 | q=md_buf; | ||
1163 | for (num=2; num > 0; num--) | ||
1164 | { | ||
1165 | EVP_MD_CTX_set_flags(&md_ctx, | ||
1166 | EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
1167 | EVP_DigestInit_ex(&md_ctx,(num == 2) | ||
1168 | ?s->ctx->md5:s->ctx->sha1, NULL); | ||
1169 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1170 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1171 | EVP_DigestUpdate(&md_ctx,param,param_len); | ||
1172 | |||
1173 | EVP_DigestFinal_ex(&md_ctx,q,(unsigned int *)&i); | ||
1174 | q+=i; | ||
1175 | j+=i; | ||
1176 | } | ||
1177 | i=RSA_verify(NID_md5_sha1, md_buf, j, p, n, | ||
1178 | pkey->pkey.rsa); | ||
1179 | if (i < 0) | ||
1180 | { | ||
1181 | al=SSL_AD_DECRYPT_ERROR; | ||
1182 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | ||
1183 | goto f_err; | ||
1184 | } | ||
1185 | if (i == 0) | ||
1186 | { | ||
1187 | /* bad signature */ | ||
1188 | al=SSL_AD_DECRYPT_ERROR; | ||
1189 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
1190 | goto f_err; | ||
1191 | } | ||
1192 | } | ||
1193 | else | ||
1194 | #endif | ||
1195 | #ifndef OPENSSL_NO_DSA | ||
1196 | if (pkey->type == EVP_PKEY_DSA) | ||
1197 | { | ||
1198 | /* lets do DSS */ | ||
1199 | EVP_VerifyInit_ex(&md_ctx,EVP_dss1(), NULL); | ||
1200 | EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1201 | EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1202 | EVP_VerifyUpdate(&md_ctx,param,param_len); | ||
1203 | if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey)) | ||
1204 | { | ||
1205 | /* bad signature */ | ||
1206 | al=SSL_AD_DECRYPT_ERROR; | ||
1207 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
1208 | goto f_err; | ||
1209 | } | ||
1210 | } | ||
1211 | else | ||
1212 | #endif | ||
1213 | { | ||
1214 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
1215 | goto err; | ||
1216 | } | ||
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | /* still data left over */ | ||
1221 | if (!(alg & SSL_aNULL)) | ||
1222 | { | ||
1223 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
1224 | goto err; | ||
1225 | } | ||
1226 | if (n != 0) | ||
1227 | { | ||
1228 | al=SSL_AD_DECODE_ERROR; | ||
1229 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE); | ||
1230 | goto f_err; | ||
1231 | } | ||
1232 | } | ||
1233 | EVP_PKEY_free(pkey); | ||
1234 | EVP_MD_CTX_cleanup(&md_ctx); | ||
1235 | return(1); | ||
1236 | f_err: | ||
1237 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1238 | err: | ||
1239 | EVP_PKEY_free(pkey); | ||
1240 | #ifndef OPENSSL_NO_RSA | ||
1241 | if (rsa != NULL) | ||
1242 | RSA_free(rsa); | ||
1243 | #endif | ||
1244 | #ifndef OPENSSL_NO_DH | ||
1245 | if (dh != NULL) | ||
1246 | DH_free(dh); | ||
1247 | #endif | ||
1248 | EVP_MD_CTX_cleanup(&md_ctx); | ||
1249 | return(-1); | ||
1250 | } | ||
1251 | |||
1252 | static int ssl3_get_certificate_request(SSL *s) | ||
1253 | { | ||
1254 | int ok,ret=0; | ||
1255 | unsigned long n,nc,l; | ||
1256 | unsigned int llen,ctype_num,i; | ||
1257 | X509_NAME *xn=NULL; | ||
1258 | unsigned char *p,*d,*q; | ||
1259 | STACK_OF(X509_NAME) *ca_sk=NULL; | ||
1260 | |||
1261 | n=ssl3_get_message(s, | ||
1262 | SSL3_ST_CR_CERT_REQ_A, | ||
1263 | SSL3_ST_CR_CERT_REQ_B, | ||
1264 | -1, | ||
1265 | s->max_cert_list, | ||
1266 | &ok); | ||
1267 | |||
1268 | if (!ok) return((int)n); | ||
1269 | |||
1270 | s->s3->tmp.cert_req=0; | ||
1271 | |||
1272 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE) | ||
1273 | { | ||
1274 | s->s3->tmp.reuse_message=1; | ||
1275 | return(1); | ||
1276 | } | ||
1277 | |||
1278 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) | ||
1279 | { | ||
1280 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
1281 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE); | ||
1282 | goto err; | ||
1283 | } | ||
1284 | |||
1285 | /* TLS does not like anon-DH with client cert */ | ||
1286 | if (s->version > SSL3_VERSION) | ||
1287 | { | ||
1288 | l=s->s3->tmp.new_cipher->algorithms; | ||
1289 | if (l & SSL_aNULL) | ||
1290 | { | ||
1291 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
1292 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER); | ||
1293 | goto err; | ||
1294 | } | ||
1295 | } | ||
1296 | |||
1297 | d=p=(unsigned char *)s->init_msg; | ||
1298 | |||
1299 | if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL) | ||
1300 | { | ||
1301 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
1302 | goto err; | ||
1303 | } | ||
1304 | |||
1305 | /* get the certificate types */ | ||
1306 | ctype_num= *(p++); | ||
1307 | if (ctype_num > SSL3_CT_NUMBER) | ||
1308 | ctype_num=SSL3_CT_NUMBER; | ||
1309 | for (i=0; i<ctype_num; i++) | ||
1310 | s->s3->tmp.ctype[i]= p[i]; | ||
1311 | p+=ctype_num; | ||
1312 | |||
1313 | /* get the CA RDNs */ | ||
1314 | n2s(p,llen); | ||
1315 | #if 0 | ||
1316 | { | ||
1317 | FILE *out; | ||
1318 | out=fopen("/tmp/vsign.der","w"); | ||
1319 | fwrite(p,1,llen,out); | ||
1320 | fclose(out); | ||
1321 | } | ||
1322 | #endif | ||
1323 | |||
1324 | if ((llen+ctype_num+2+1) != n) | ||
1325 | { | ||
1326 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1327 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH); | ||
1328 | goto err; | ||
1329 | } | ||
1330 | |||
1331 | for (nc=0; nc<llen; ) | ||
1332 | { | ||
1333 | n2s(p,l); | ||
1334 | if ((l+nc+2) > llen) | ||
1335 | { | ||
1336 | if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
1337 | goto cont; /* netscape bugs */ | ||
1338 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1339 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG); | ||
1340 | goto err; | ||
1341 | } | ||
1342 | |||
1343 | q=p; | ||
1344 | |||
1345 | if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL) | ||
1346 | { | ||
1347 | /* If netscape tolerance is on, ignore errors */ | ||
1348 | if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG) | ||
1349 | goto cont; | ||
1350 | else | ||
1351 | { | ||
1352 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1353 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB); | ||
1354 | goto err; | ||
1355 | } | ||
1356 | } | ||
1357 | |||
1358 | if (q != (p+l)) | ||
1359 | { | ||
1360 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1361 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH); | ||
1362 | goto err; | ||
1363 | } | ||
1364 | if (!sk_X509_NAME_push(ca_sk,xn)) | ||
1365 | { | ||
1366 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
1367 | goto err; | ||
1368 | } | ||
1369 | |||
1370 | p+=l; | ||
1371 | nc+=l+2; | ||
1372 | } | ||
1373 | |||
1374 | if (0) | ||
1375 | { | ||
1376 | cont: | ||
1377 | ERR_clear_error(); | ||
1378 | } | ||
1379 | |||
1380 | /* we should setup a certificate to return.... */ | ||
1381 | s->s3->tmp.cert_req=1; | ||
1382 | s->s3->tmp.ctype_num=ctype_num; | ||
1383 | if (s->s3->tmp.ca_names != NULL) | ||
1384 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
1385 | s->s3->tmp.ca_names=ca_sk; | ||
1386 | ca_sk=NULL; | ||
1387 | |||
1388 | ret=1; | ||
1389 | err: | ||
1390 | if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free); | ||
1391 | return(ret); | ||
1392 | } | ||
1393 | |||
1394 | static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b) | ||
1395 | { | ||
1396 | return(X509_NAME_cmp(*a,*b)); | ||
1397 | } | ||
1398 | |||
1399 | static int ssl3_get_server_done(SSL *s) | ||
1400 | { | ||
1401 | int ok,ret=0; | ||
1402 | long n; | ||
1403 | |||
1404 | n=ssl3_get_message(s, | ||
1405 | SSL3_ST_CR_SRVR_DONE_A, | ||
1406 | SSL3_ST_CR_SRVR_DONE_B, | ||
1407 | SSL3_MT_SERVER_DONE, | ||
1408 | 30, /* should be very small, like 0 :-) */ | ||
1409 | &ok); | ||
1410 | |||
1411 | if (!ok) return((int)n); | ||
1412 | if (n > 0) | ||
1413 | { | ||
1414 | /* should contain no data */ | ||
1415 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1416 | SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH); | ||
1417 | return -1; | ||
1418 | } | ||
1419 | ret=1; | ||
1420 | return(ret); | ||
1421 | } | ||
1422 | |||
1423 | static int ssl3_send_client_key_exchange(SSL *s) | ||
1424 | { | ||
1425 | unsigned char *p,*d; | ||
1426 | int n; | ||
1427 | unsigned long l; | ||
1428 | #ifndef OPENSSL_NO_RSA | ||
1429 | unsigned char *q; | ||
1430 | EVP_PKEY *pkey=NULL; | ||
1431 | #endif | ||
1432 | #ifndef OPENSSL_NO_KRB5 | ||
1433 | KSSL_ERR kssl_err; | ||
1434 | #endif /* OPENSSL_NO_KRB5 */ | ||
1435 | |||
1436 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | ||
1437 | { | ||
1438 | d=(unsigned char *)s->init_buf->data; | ||
1439 | p= &(d[4]); | ||
1440 | |||
1441 | l=s->s3->tmp.new_cipher->algorithms; | ||
1442 | |||
1443 | /* Fool emacs indentation */ | ||
1444 | if (0) {} | ||
1445 | #ifndef OPENSSL_NO_RSA | ||
1446 | else if (l & SSL_kRSA) | ||
1447 | { | ||
1448 | RSA *rsa; | ||
1449 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; | ||
1450 | |||
1451 | if (s->session->sess_cert->peer_rsa_tmp != NULL) | ||
1452 | rsa=s->session->sess_cert->peer_rsa_tmp; | ||
1453 | else | ||
1454 | { | ||
1455 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
1456 | if ((pkey == NULL) || | ||
1457 | (pkey->type != EVP_PKEY_RSA) || | ||
1458 | (pkey->pkey.rsa == NULL)) | ||
1459 | { | ||
1460 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
1461 | goto err; | ||
1462 | } | ||
1463 | rsa=pkey->pkey.rsa; | ||
1464 | EVP_PKEY_free(pkey); | ||
1465 | } | ||
1466 | |||
1467 | tmp_buf[0]=s->client_version>>8; | ||
1468 | tmp_buf[1]=s->client_version&0xff; | ||
1469 | if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0) | ||
1470 | goto err; | ||
1471 | |||
1472 | s->session->master_key_length=sizeof tmp_buf; | ||
1473 | |||
1474 | q=p; | ||
1475 | /* Fix buf for TLS and beyond */ | ||
1476 | if (s->version > SSL3_VERSION) | ||
1477 | p+=2; | ||
1478 | n=RSA_public_encrypt(sizeof tmp_buf, | ||
1479 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | ||
1480 | #ifdef PKCS1_CHECK | ||
1481 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | ||
1482 | if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70; | ||
1483 | #endif | ||
1484 | if (n <= 0) | ||
1485 | { | ||
1486 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); | ||
1487 | goto err; | ||
1488 | } | ||
1489 | |||
1490 | /* Fix buf for TLS and beyond */ | ||
1491 | if (s->version > SSL3_VERSION) | ||
1492 | { | ||
1493 | s2n(n,q); | ||
1494 | n+=2; | ||
1495 | } | ||
1496 | |||
1497 | s->session->master_key_length= | ||
1498 | s->method->ssl3_enc->generate_master_secret(s, | ||
1499 | s->session->master_key, | ||
1500 | tmp_buf,sizeof tmp_buf); | ||
1501 | OPENSSL_cleanse(tmp_buf,sizeof tmp_buf); | ||
1502 | } | ||
1503 | #endif | ||
1504 | #ifndef OPENSSL_NO_KRB5 | ||
1505 | else if (l & SSL_kKRB5) | ||
1506 | { | ||
1507 | krb5_error_code krb5rc; | ||
1508 | KSSL_CTX *kssl_ctx = s->kssl_ctx; | ||
1509 | /* krb5_data krb5_ap_req; */ | ||
1510 | krb5_data *enc_ticket; | ||
1511 | krb5_data authenticator, *authp = NULL; | ||
1512 | EVP_CIPHER_CTX ciph_ctx; | ||
1513 | EVP_CIPHER *enc = NULL; | ||
1514 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
1515 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; | ||
1516 | unsigned char epms[SSL_MAX_MASTER_KEY_LENGTH | ||
1517 | + EVP_MAX_IV_LENGTH]; | ||
1518 | int padl, outl = sizeof(epms); | ||
1519 | |||
1520 | EVP_CIPHER_CTX_init(&ciph_ctx); | ||
1521 | |||
1522 | #ifdef KSSL_DEBUG | ||
1523 | printf("ssl3_send_client_key_exchange(%lx & %lx)\n", | ||
1524 | l, SSL_kKRB5); | ||
1525 | #endif /* KSSL_DEBUG */ | ||
1526 | |||
1527 | authp = NULL; | ||
1528 | #ifdef KRB5SENDAUTH | ||
1529 | if (KRB5SENDAUTH) authp = &authenticator; | ||
1530 | #endif /* KRB5SENDAUTH */ | ||
1531 | |||
1532 | krb5rc = kssl_cget_tkt(kssl_ctx, &enc_ticket, authp, | ||
1533 | &kssl_err); | ||
1534 | enc = kssl_map_enc(kssl_ctx->enctype); | ||
1535 | if (enc == NULL) | ||
1536 | goto err; | ||
1537 | #ifdef KSSL_DEBUG | ||
1538 | { | ||
1539 | printf("kssl_cget_tkt rtn %d\n", krb5rc); | ||
1540 | if (krb5rc && kssl_err.text) | ||
1541 | printf("kssl_cget_tkt kssl_err=%s\n", kssl_err.text); | ||
1542 | } | ||
1543 | #endif /* KSSL_DEBUG */ | ||
1544 | |||
1545 | if (krb5rc) | ||
1546 | { | ||
1547 | ssl3_send_alert(s,SSL3_AL_FATAL, | ||
1548 | SSL_AD_HANDSHAKE_FAILURE); | ||
1549 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
1550 | kssl_err.reason); | ||
1551 | goto err; | ||
1552 | } | ||
1553 | |||
1554 | /* 20010406 VRS - Earlier versions used KRB5 AP_REQ | ||
1555 | ** in place of RFC 2712 KerberosWrapper, as in: | ||
1556 | ** | ||
1557 | ** Send ticket (copy to *p, set n = length) | ||
1558 | ** n = krb5_ap_req.length; | ||
1559 | ** memcpy(p, krb5_ap_req.data, krb5_ap_req.length); | ||
1560 | ** if (krb5_ap_req.data) | ||
1561 | ** kssl_krb5_free_data_contents(NULL,&krb5_ap_req); | ||
1562 | ** | ||
1563 | ** Now using real RFC 2712 KerberosWrapper | ||
1564 | ** (Thanks to Simon Wilkinson <sxw@sxw.org.uk>) | ||
1565 | ** Note: 2712 "opaque" types are here replaced | ||
1566 | ** with a 2-byte length followed by the value. | ||
1567 | ** Example: | ||
1568 | ** KerberosWrapper= xx xx asn1ticket 0 0 xx xx encpms | ||
1569 | ** Where "xx xx" = length bytes. Shown here with | ||
1570 | ** optional authenticator omitted. | ||
1571 | */ | ||
1572 | |||
1573 | /* KerberosWrapper.Ticket */ | ||
1574 | s2n(enc_ticket->length,p); | ||
1575 | memcpy(p, enc_ticket->data, enc_ticket->length); | ||
1576 | p+= enc_ticket->length; | ||
1577 | n = enc_ticket->length + 2; | ||
1578 | |||
1579 | /* KerberosWrapper.Authenticator */ | ||
1580 | if (authp && authp->length) | ||
1581 | { | ||
1582 | s2n(authp->length,p); | ||
1583 | memcpy(p, authp->data, authp->length); | ||
1584 | p+= authp->length; | ||
1585 | n+= authp->length + 2; | ||
1586 | |||
1587 | free(authp->data); | ||
1588 | authp->data = NULL; | ||
1589 | authp->length = 0; | ||
1590 | } | ||
1591 | else | ||
1592 | { | ||
1593 | s2n(0,p);/* null authenticator length */ | ||
1594 | n+=2; | ||
1595 | } | ||
1596 | |||
1597 | if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0) | ||
1598 | goto err; | ||
1599 | |||
1600 | /* 20010420 VRS. Tried it this way; failed. | ||
1601 | ** EVP_EncryptInit_ex(&ciph_ctx,enc, NULL,NULL); | ||
1602 | ** EVP_CIPHER_CTX_set_key_length(&ciph_ctx, | ||
1603 | ** kssl_ctx->length); | ||
1604 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); | ||
1605 | */ | ||
1606 | |||
1607 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ | ||
1608 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, | ||
1609 | kssl_ctx->key,iv); | ||
1610 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, | ||
1611 | sizeof tmp_buf); | ||
1612 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); | ||
1613 | outl += padl; | ||
1614 | if (outl > sizeof epms) | ||
1615 | { | ||
1616 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
1617 | goto err; | ||
1618 | } | ||
1619 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); | ||
1620 | |||
1621 | /* KerberosWrapper.EncryptedPreMasterSecret */ | ||
1622 | s2n(outl,p); | ||
1623 | memcpy(p, epms, outl); | ||
1624 | p+=outl; | ||
1625 | n+=outl + 2; | ||
1626 | |||
1627 | s->session->master_key_length= | ||
1628 | s->method->ssl3_enc->generate_master_secret(s, | ||
1629 | s->session->master_key, | ||
1630 | tmp_buf, sizeof tmp_buf); | ||
1631 | |||
1632 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); | ||
1633 | OPENSSL_cleanse(epms, outl); | ||
1634 | } | ||
1635 | #endif | ||
1636 | #ifndef OPENSSL_NO_DH | ||
1637 | else if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1638 | { | ||
1639 | DH *dh_srvr,*dh_clnt; | ||
1640 | |||
1641 | if (s->session->sess_cert->peer_dh_tmp != NULL) | ||
1642 | dh_srvr=s->session->sess_cert->peer_dh_tmp; | ||
1643 | else | ||
1644 | { | ||
1645 | /* we get them from the cert */ | ||
1646 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1647 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS); | ||
1648 | goto err; | ||
1649 | } | ||
1650 | |||
1651 | /* generate a new random key */ | ||
1652 | if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL) | ||
1653 | { | ||
1654 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1655 | goto err; | ||
1656 | } | ||
1657 | if (!DH_generate_key(dh_clnt)) | ||
1658 | { | ||
1659 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1660 | goto err; | ||
1661 | } | ||
1662 | |||
1663 | /* use the 'p' output buffer for the DH key, but | ||
1664 | * make sure to clear it out afterwards */ | ||
1665 | |||
1666 | n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt); | ||
1667 | |||
1668 | if (n <= 0) | ||
1669 | { | ||
1670 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1671 | goto err; | ||
1672 | } | ||
1673 | |||
1674 | /* generate master key from the result */ | ||
1675 | s->session->master_key_length= | ||
1676 | s->method->ssl3_enc->generate_master_secret(s, | ||
1677 | s->session->master_key,p,n); | ||
1678 | /* clean up */ | ||
1679 | memset(p,0,n); | ||
1680 | |||
1681 | /* send off the data */ | ||
1682 | n=BN_num_bytes(dh_clnt->pub_key); | ||
1683 | s2n(n,p); | ||
1684 | BN_bn2bin(dh_clnt->pub_key,p); | ||
1685 | n+=2; | ||
1686 | |||
1687 | DH_free(dh_clnt); | ||
1688 | |||
1689 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ | ||
1690 | } | ||
1691 | #endif | ||
1692 | else | ||
1693 | { | ||
1694 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1695 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_INTERNAL_ERROR); | ||
1696 | goto err; | ||
1697 | } | ||
1698 | |||
1699 | *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE; | ||
1700 | l2n3(n,d); | ||
1701 | |||
1702 | s->state=SSL3_ST_CW_KEY_EXCH_B; | ||
1703 | /* number of bytes to write */ | ||
1704 | s->init_num=n+4; | ||
1705 | s->init_off=0; | ||
1706 | } | ||
1707 | |||
1708 | /* SSL3_ST_CW_KEY_EXCH_B */ | ||
1709 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1710 | err: | ||
1711 | return(-1); | ||
1712 | } | ||
1713 | |||
1714 | static int ssl3_send_client_verify(SSL *s) | ||
1715 | { | ||
1716 | unsigned char *p,*d; | ||
1717 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
1718 | EVP_PKEY *pkey; | ||
1719 | #ifndef OPENSSL_NO_RSA | ||
1720 | unsigned u=0; | ||
1721 | #endif | ||
1722 | unsigned long n; | ||
1723 | #ifndef OPENSSL_NO_DSA | ||
1724 | int j; | ||
1725 | #endif | ||
1726 | |||
1727 | if (s->state == SSL3_ST_CW_CERT_VRFY_A) | ||
1728 | { | ||
1729 | d=(unsigned char *)s->init_buf->data; | ||
1730 | p= &(d[4]); | ||
1731 | pkey=s->cert->key->privatekey; | ||
1732 | |||
1733 | s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2), | ||
1734 | &(data[MD5_DIGEST_LENGTH])); | ||
1735 | |||
1736 | #ifndef OPENSSL_NO_RSA | ||
1737 | if (pkey->type == EVP_PKEY_RSA) | ||
1738 | { | ||
1739 | s->method->ssl3_enc->cert_verify_mac(s, | ||
1740 | &(s->s3->finish_dgst1),&(data[0])); | ||
1741 | if (RSA_sign(NID_md5_sha1, data, | ||
1742 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
1743 | &(p[2]), &u, pkey->pkey.rsa) <= 0 ) | ||
1744 | { | ||
1745 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB); | ||
1746 | goto err; | ||
1747 | } | ||
1748 | s2n(u,p); | ||
1749 | n=u+2; | ||
1750 | } | ||
1751 | else | ||
1752 | #endif | ||
1753 | #ifndef OPENSSL_NO_DSA | ||
1754 | if (pkey->type == EVP_PKEY_DSA) | ||
1755 | { | ||
1756 | if (!DSA_sign(pkey->save_type, | ||
1757 | &(data[MD5_DIGEST_LENGTH]), | ||
1758 | SHA_DIGEST_LENGTH,&(p[2]), | ||
1759 | (unsigned int *)&j,pkey->pkey.dsa)) | ||
1760 | { | ||
1761 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB); | ||
1762 | goto err; | ||
1763 | } | ||
1764 | s2n(j,p); | ||
1765 | n=j+2; | ||
1766 | } | ||
1767 | else | ||
1768 | #endif | ||
1769 | { | ||
1770 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_INTERNAL_ERROR); | ||
1771 | goto err; | ||
1772 | } | ||
1773 | *(d++)=SSL3_MT_CERTIFICATE_VERIFY; | ||
1774 | l2n3(n,d); | ||
1775 | |||
1776 | s->state=SSL3_ST_CW_CERT_VRFY_B; | ||
1777 | s->init_num=(int)n+4; | ||
1778 | s->init_off=0; | ||
1779 | } | ||
1780 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1781 | err: | ||
1782 | return(-1); | ||
1783 | } | ||
1784 | |||
1785 | static int ssl3_send_client_certificate(SSL *s) | ||
1786 | { | ||
1787 | X509 *x509=NULL; | ||
1788 | EVP_PKEY *pkey=NULL; | ||
1789 | int i; | ||
1790 | unsigned long l; | ||
1791 | |||
1792 | if (s->state == SSL3_ST_CW_CERT_A) | ||
1793 | { | ||
1794 | if ((s->cert == NULL) || | ||
1795 | (s->cert->key->x509 == NULL) || | ||
1796 | (s->cert->key->privatekey == NULL)) | ||
1797 | s->state=SSL3_ST_CW_CERT_B; | ||
1798 | else | ||
1799 | s->state=SSL3_ST_CW_CERT_C; | ||
1800 | } | ||
1801 | |||
1802 | /* We need to get a client cert */ | ||
1803 | if (s->state == SSL3_ST_CW_CERT_B) | ||
1804 | { | ||
1805 | /* If we get an error, we need to | ||
1806 | * ssl->rwstate=SSL_X509_LOOKUP; return(-1); | ||
1807 | * We then get retied later */ | ||
1808 | i=0; | ||
1809 | if (s->ctx->client_cert_cb != NULL) | ||
1810 | i=s->ctx->client_cert_cb(s,&(x509),&(pkey)); | ||
1811 | if (i < 0) | ||
1812 | { | ||
1813 | s->rwstate=SSL_X509_LOOKUP; | ||
1814 | return(-1); | ||
1815 | } | ||
1816 | s->rwstate=SSL_NOTHING; | ||
1817 | if ((i == 1) && (pkey != NULL) && (x509 != NULL)) | ||
1818 | { | ||
1819 | s->state=SSL3_ST_CW_CERT_B; | ||
1820 | if ( !SSL_use_certificate(s,x509) || | ||
1821 | !SSL_use_PrivateKey(s,pkey)) | ||
1822 | i=0; | ||
1823 | } | ||
1824 | else if (i == 1) | ||
1825 | { | ||
1826 | i=0; | ||
1827 | SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK); | ||
1828 | } | ||
1829 | |||
1830 | if (x509 != NULL) X509_free(x509); | ||
1831 | if (pkey != NULL) EVP_PKEY_free(pkey); | ||
1832 | if (i == 0) | ||
1833 | { | ||
1834 | if (s->version == SSL3_VERSION) | ||
1835 | { | ||
1836 | s->s3->tmp.cert_req=0; | ||
1837 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE); | ||
1838 | return(1); | ||
1839 | } | ||
1840 | else | ||
1841 | { | ||
1842 | s->s3->tmp.cert_req=2; | ||
1843 | } | ||
1844 | } | ||
1845 | |||
1846 | /* Ok, we have a cert */ | ||
1847 | s->state=SSL3_ST_CW_CERT_C; | ||
1848 | } | ||
1849 | |||
1850 | if (s->state == SSL3_ST_CW_CERT_C) | ||
1851 | { | ||
1852 | s->state=SSL3_ST_CW_CERT_D; | ||
1853 | l=ssl3_output_cert_chain(s, | ||
1854 | (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509); | ||
1855 | s->init_num=(int)l; | ||
1856 | s->init_off=0; | ||
1857 | } | ||
1858 | /* SSL3_ST_CW_CERT_D */ | ||
1859 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1860 | } | ||
1861 | |||
1862 | #define has_bits(i,m) (((i)&(m)) == (m)) | ||
1863 | |||
1864 | static int ssl3_check_cert_and_algorithm(SSL *s) | ||
1865 | { | ||
1866 | int i,idx; | ||
1867 | long algs; | ||
1868 | EVP_PKEY *pkey=NULL; | ||
1869 | SESS_CERT *sc; | ||
1870 | #ifndef OPENSSL_NO_RSA | ||
1871 | RSA *rsa; | ||
1872 | #endif | ||
1873 | #ifndef OPENSSL_NO_DH | ||
1874 | DH *dh; | ||
1875 | #endif | ||
1876 | |||
1877 | sc=s->session->sess_cert; | ||
1878 | |||
1879 | if (sc == NULL) | ||
1880 | { | ||
1881 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR); | ||
1882 | goto err; | ||
1883 | } | ||
1884 | |||
1885 | algs=s->s3->tmp.new_cipher->algorithms; | ||
1886 | |||
1887 | /* we don't have a certificate */ | ||
1888 | if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5)) | ||
1889 | return(1); | ||
1890 | |||
1891 | #ifndef OPENSSL_NO_RSA | ||
1892 | rsa=s->session->sess_cert->peer_rsa_tmp; | ||
1893 | #endif | ||
1894 | #ifndef OPENSSL_NO_DH | ||
1895 | dh=s->session->sess_cert->peer_dh_tmp; | ||
1896 | #endif | ||
1897 | |||
1898 | /* This is the passed certificate */ | ||
1899 | |||
1900 | idx=sc->peer_cert_type; | ||
1901 | pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); | ||
1902 | i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); | ||
1903 | EVP_PKEY_free(pkey); | ||
1904 | |||
1905 | |||
1906 | /* Check that we have a certificate if we require one */ | ||
1907 | if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN)) | ||
1908 | { | ||
1909 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT); | ||
1910 | goto f_err; | ||
1911 | } | ||
1912 | #ifndef OPENSSL_NO_DSA | ||
1913 | else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN)) | ||
1914 | { | ||
1915 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT); | ||
1916 | goto f_err; | ||
1917 | } | ||
1918 | #endif | ||
1919 | #ifndef OPENSSL_NO_RSA | ||
1920 | if ((algs & SSL_kRSA) && | ||
1921 | !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) | ||
1922 | { | ||
1923 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); | ||
1924 | goto f_err; | ||
1925 | } | ||
1926 | #endif | ||
1927 | #ifndef OPENSSL_NO_DH | ||
1928 | if ((algs & SSL_kEDH) && | ||
1929 | !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) | ||
1930 | { | ||
1931 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); | ||
1932 | goto f_err; | ||
1933 | } | ||
1934 | else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA)) | ||
1935 | { | ||
1936 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT); | ||
1937 | goto f_err; | ||
1938 | } | ||
1939 | #ifndef OPENSSL_NO_DSA | ||
1940 | else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA)) | ||
1941 | { | ||
1942 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT); | ||
1943 | goto f_err; | ||
1944 | } | ||
1945 | #endif | ||
1946 | #endif | ||
1947 | |||
1948 | if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP)) | ||
1949 | { | ||
1950 | #ifndef OPENSSL_NO_RSA | ||
1951 | if (algs & SSL_kRSA) | ||
1952 | { | ||
1953 | if (rsa == NULL | ||
1954 | || RSA_size(rsa)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) | ||
1955 | { | ||
1956 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); | ||
1957 | goto f_err; | ||
1958 | } | ||
1959 | } | ||
1960 | else | ||
1961 | #endif | ||
1962 | #ifndef OPENSSL_NO_DH | ||
1963 | if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1964 | { | ||
1965 | if (dh == NULL | ||
1966 | || DH_size(dh)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) | ||
1967 | { | ||
1968 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); | ||
1969 | goto f_err; | ||
1970 | } | ||
1971 | } | ||
1972 | else | ||
1973 | #endif | ||
1974 | { | ||
1975 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
1976 | goto f_err; | ||
1977 | } | ||
1978 | } | ||
1979 | return(1); | ||
1980 | f_err: | ||
1981 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1982 | err: | ||
1983 | return(0); | ||
1984 | } | ||
1985 | |||
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c deleted file mode 100644 index a77588e725..0000000000 --- a/src/lib/libssl/s3_lib.c +++ /dev/null | |||
@@ -1,1799 +0,0 @@ | |||
1 | /* ssl/s3_lib.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include <openssl/objects.h> | ||
114 | #include "ssl_locl.h" | ||
115 | #include "kssl_lcl.h" | ||
116 | #include <openssl/md5.h> | ||
117 | |||
118 | const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT; | ||
119 | |||
120 | #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER)) | ||
121 | |||
122 | static long ssl3_default_timeout(void ); | ||
123 | |||
124 | OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | ||
125 | /* The RSA ciphers */ | ||
126 | /* Cipher 01 */ | ||
127 | { | ||
128 | 1, | ||
129 | SSL3_TXT_RSA_NULL_MD5, | ||
130 | SSL3_CK_RSA_NULL_MD5, | ||
131 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3, | ||
132 | SSL_NOT_EXP|SSL_STRONG_NONE, | ||
133 | 0, | ||
134 | 0, | ||
135 | 0, | ||
136 | SSL_ALL_CIPHERS, | ||
137 | SSL_ALL_STRENGTHS, | ||
138 | }, | ||
139 | /* Cipher 02 */ | ||
140 | { | ||
141 | 1, | ||
142 | SSL3_TXT_RSA_NULL_SHA, | ||
143 | SSL3_CK_RSA_NULL_SHA, | ||
144 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3, | ||
145 | SSL_NOT_EXP|SSL_STRONG_NONE|SSL_FIPS, | ||
146 | 0, | ||
147 | 0, | ||
148 | 0, | ||
149 | SSL_ALL_CIPHERS, | ||
150 | SSL_ALL_STRENGTHS, | ||
151 | }, | ||
152 | |||
153 | /* anon DH */ | ||
154 | /* Cipher 17 */ | ||
155 | { | ||
156 | 1, | ||
157 | SSL3_TXT_ADH_RC4_40_MD5, | ||
158 | SSL3_CK_ADH_RC4_40_MD5, | ||
159 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
160 | SSL_EXPORT|SSL_EXP40, | ||
161 | 0, | ||
162 | 40, | ||
163 | 128, | ||
164 | SSL_ALL_CIPHERS, | ||
165 | SSL_ALL_STRENGTHS, | ||
166 | }, | ||
167 | /* Cipher 18 */ | ||
168 | { | ||
169 | 1, | ||
170 | SSL3_TXT_ADH_RC4_128_MD5, | ||
171 | SSL3_CK_ADH_RC4_128_MD5, | ||
172 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
173 | SSL_NOT_EXP|SSL_MEDIUM, | ||
174 | 0, | ||
175 | 128, | ||
176 | 128, | ||
177 | SSL_ALL_CIPHERS, | ||
178 | SSL_ALL_STRENGTHS, | ||
179 | }, | ||
180 | /* Cipher 19 */ | ||
181 | { | ||
182 | 1, | ||
183 | SSL3_TXT_ADH_DES_40_CBC_SHA, | ||
184 | SSL3_CK_ADH_DES_40_CBC_SHA, | ||
185 | SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
186 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
187 | 0, | ||
188 | 40, | ||
189 | 128, | ||
190 | SSL_ALL_CIPHERS, | ||
191 | SSL_ALL_STRENGTHS, | ||
192 | }, | ||
193 | /* Cipher 1A */ | ||
194 | { | ||
195 | 1, | ||
196 | SSL3_TXT_ADH_DES_64_CBC_SHA, | ||
197 | SSL3_CK_ADH_DES_64_CBC_SHA, | ||
198 | SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
199 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
200 | 0, | ||
201 | 56, | ||
202 | 56, | ||
203 | SSL_ALL_CIPHERS, | ||
204 | SSL_ALL_STRENGTHS, | ||
205 | }, | ||
206 | /* Cipher 1B */ | ||
207 | { | ||
208 | 1, | ||
209 | SSL3_TXT_ADH_DES_192_CBC_SHA, | ||
210 | SSL3_CK_ADH_DES_192_CBC_SHA, | ||
211 | SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
212 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
213 | 0, | ||
214 | 168, | ||
215 | 168, | ||
216 | SSL_ALL_CIPHERS, | ||
217 | SSL_ALL_STRENGTHS, | ||
218 | }, | ||
219 | |||
220 | /* RSA again */ | ||
221 | /* Cipher 03 */ | ||
222 | { | ||
223 | 1, | ||
224 | SSL3_TXT_RSA_RC4_40_MD5, | ||
225 | SSL3_CK_RSA_RC4_40_MD5, | ||
226 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
227 | SSL_EXPORT|SSL_EXP40, | ||
228 | 0, | ||
229 | 40, | ||
230 | 128, | ||
231 | SSL_ALL_CIPHERS, | ||
232 | SSL_ALL_STRENGTHS, | ||
233 | }, | ||
234 | /* Cipher 04 */ | ||
235 | { | ||
236 | 1, | ||
237 | SSL3_TXT_RSA_RC4_128_MD5, | ||
238 | SSL3_CK_RSA_RC4_128_MD5, | ||
239 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3, | ||
240 | SSL_NOT_EXP|SSL_MEDIUM, | ||
241 | 0, | ||
242 | 128, | ||
243 | 128, | ||
244 | SSL_ALL_CIPHERS, | ||
245 | SSL_ALL_STRENGTHS, | ||
246 | }, | ||
247 | /* Cipher 05 */ | ||
248 | { | ||
249 | 1, | ||
250 | SSL3_TXT_RSA_RC4_128_SHA, | ||
251 | SSL3_CK_RSA_RC4_128_SHA, | ||
252 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3, | ||
253 | SSL_NOT_EXP|SSL_MEDIUM, | ||
254 | 0, | ||
255 | 128, | ||
256 | 128, | ||
257 | SSL_ALL_CIPHERS, | ||
258 | SSL_ALL_STRENGTHS, | ||
259 | }, | ||
260 | /* Cipher 06 */ | ||
261 | { | ||
262 | 1, | ||
263 | SSL3_TXT_RSA_RC2_40_MD5, | ||
264 | SSL3_CK_RSA_RC2_40_MD5, | ||
265 | SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3, | ||
266 | SSL_EXPORT|SSL_EXP40, | ||
267 | 0, | ||
268 | 40, | ||
269 | 128, | ||
270 | SSL_ALL_CIPHERS, | ||
271 | SSL_ALL_STRENGTHS, | ||
272 | }, | ||
273 | /* Cipher 07 */ | ||
274 | #ifndef OPENSSL_NO_IDEA | ||
275 | { | ||
276 | 1, | ||
277 | SSL3_TXT_RSA_IDEA_128_SHA, | ||
278 | SSL3_CK_RSA_IDEA_128_SHA, | ||
279 | SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3, | ||
280 | SSL_NOT_EXP|SSL_MEDIUM, | ||
281 | 0, | ||
282 | 128, | ||
283 | 128, | ||
284 | SSL_ALL_CIPHERS, | ||
285 | SSL_ALL_STRENGTHS, | ||
286 | }, | ||
287 | #endif | ||
288 | /* Cipher 08 */ | ||
289 | { | ||
290 | 1, | ||
291 | SSL3_TXT_RSA_DES_40_CBC_SHA, | ||
292 | SSL3_CK_RSA_DES_40_CBC_SHA, | ||
293 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
294 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
295 | 0, | ||
296 | 40, | ||
297 | 56, | ||
298 | SSL_ALL_CIPHERS, | ||
299 | SSL_ALL_STRENGTHS, | ||
300 | }, | ||
301 | /* Cipher 09 */ | ||
302 | { | ||
303 | 1, | ||
304 | SSL3_TXT_RSA_DES_64_CBC_SHA, | ||
305 | SSL3_CK_RSA_DES_64_CBC_SHA, | ||
306 | SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
307 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
308 | 0, | ||
309 | 56, | ||
310 | 56, | ||
311 | SSL_ALL_CIPHERS, | ||
312 | SSL_ALL_STRENGTHS, | ||
313 | }, | ||
314 | /* Cipher 0A */ | ||
315 | { | ||
316 | 1, | ||
317 | SSL3_TXT_RSA_DES_192_CBC3_SHA, | ||
318 | SSL3_CK_RSA_DES_192_CBC3_SHA, | ||
319 | SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
320 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
321 | 0, | ||
322 | 168, | ||
323 | 168, | ||
324 | SSL_ALL_CIPHERS, | ||
325 | SSL_ALL_STRENGTHS, | ||
326 | }, | ||
327 | |||
328 | /* The DH ciphers */ | ||
329 | /* Cipher 0B */ | ||
330 | { | ||
331 | 0, | ||
332 | SSL3_TXT_DH_DSS_DES_40_CBC_SHA, | ||
333 | SSL3_CK_DH_DSS_DES_40_CBC_SHA, | ||
334 | SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
335 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
336 | 0, | ||
337 | 40, | ||
338 | 56, | ||
339 | SSL_ALL_CIPHERS, | ||
340 | SSL_ALL_STRENGTHS, | ||
341 | }, | ||
342 | /* Cipher 0C */ | ||
343 | { | ||
344 | 0, | ||
345 | SSL3_TXT_DH_DSS_DES_64_CBC_SHA, | ||
346 | SSL3_CK_DH_DSS_DES_64_CBC_SHA, | ||
347 | SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
348 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
349 | 0, | ||
350 | 56, | ||
351 | 56, | ||
352 | SSL_ALL_CIPHERS, | ||
353 | SSL_ALL_STRENGTHS, | ||
354 | }, | ||
355 | /* Cipher 0D */ | ||
356 | { | ||
357 | 0, | ||
358 | SSL3_TXT_DH_DSS_DES_192_CBC3_SHA, | ||
359 | SSL3_CK_DH_DSS_DES_192_CBC3_SHA, | ||
360 | SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
361 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
362 | 0, | ||
363 | 168, | ||
364 | 168, | ||
365 | SSL_ALL_CIPHERS, | ||
366 | SSL_ALL_STRENGTHS, | ||
367 | }, | ||
368 | /* Cipher 0E */ | ||
369 | { | ||
370 | 0, | ||
371 | SSL3_TXT_DH_RSA_DES_40_CBC_SHA, | ||
372 | SSL3_CK_DH_RSA_DES_40_CBC_SHA, | ||
373 | SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
374 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
375 | 0, | ||
376 | 40, | ||
377 | 56, | ||
378 | SSL_ALL_CIPHERS, | ||
379 | SSL_ALL_STRENGTHS, | ||
380 | }, | ||
381 | /* Cipher 0F */ | ||
382 | { | ||
383 | 0, | ||
384 | SSL3_TXT_DH_RSA_DES_64_CBC_SHA, | ||
385 | SSL3_CK_DH_RSA_DES_64_CBC_SHA, | ||
386 | SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
387 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
388 | 0, | ||
389 | 56, | ||
390 | 56, | ||
391 | SSL_ALL_CIPHERS, | ||
392 | SSL_ALL_STRENGTHS, | ||
393 | }, | ||
394 | /* Cipher 10 */ | ||
395 | { | ||
396 | 0, | ||
397 | SSL3_TXT_DH_RSA_DES_192_CBC3_SHA, | ||
398 | SSL3_CK_DH_RSA_DES_192_CBC3_SHA, | ||
399 | SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
400 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
401 | 0, | ||
402 | 168, | ||
403 | 168, | ||
404 | SSL_ALL_CIPHERS, | ||
405 | SSL_ALL_STRENGTHS, | ||
406 | }, | ||
407 | |||
408 | /* The Ephemeral DH ciphers */ | ||
409 | /* Cipher 11 */ | ||
410 | { | ||
411 | 1, | ||
412 | SSL3_TXT_EDH_DSS_DES_40_CBC_SHA, | ||
413 | SSL3_CK_EDH_DSS_DES_40_CBC_SHA, | ||
414 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
415 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
416 | 0, | ||
417 | 40, | ||
418 | 56, | ||
419 | SSL_ALL_CIPHERS, | ||
420 | SSL_ALL_STRENGTHS, | ||
421 | }, | ||
422 | /* Cipher 12 */ | ||
423 | { | ||
424 | 1, | ||
425 | SSL3_TXT_EDH_DSS_DES_64_CBC_SHA, | ||
426 | SSL3_CK_EDH_DSS_DES_64_CBC_SHA, | ||
427 | SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
428 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
429 | 0, | ||
430 | 56, | ||
431 | 56, | ||
432 | SSL_ALL_CIPHERS, | ||
433 | SSL_ALL_STRENGTHS, | ||
434 | }, | ||
435 | /* Cipher 13 */ | ||
436 | { | ||
437 | 1, | ||
438 | SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA, | ||
439 | SSL3_CK_EDH_DSS_DES_192_CBC3_SHA, | ||
440 | SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
441 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
442 | 0, | ||
443 | 168, | ||
444 | 168, | ||
445 | SSL_ALL_CIPHERS, | ||
446 | SSL_ALL_STRENGTHS, | ||
447 | }, | ||
448 | /* Cipher 14 */ | ||
449 | { | ||
450 | 1, | ||
451 | SSL3_TXT_EDH_RSA_DES_40_CBC_SHA, | ||
452 | SSL3_CK_EDH_RSA_DES_40_CBC_SHA, | ||
453 | SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
454 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
455 | 0, | ||
456 | 40, | ||
457 | 56, | ||
458 | SSL_ALL_CIPHERS, | ||
459 | SSL_ALL_STRENGTHS, | ||
460 | }, | ||
461 | /* Cipher 15 */ | ||
462 | { | ||
463 | 1, | ||
464 | SSL3_TXT_EDH_RSA_DES_64_CBC_SHA, | ||
465 | SSL3_CK_EDH_RSA_DES_64_CBC_SHA, | ||
466 | SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
467 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
468 | 0, | ||
469 | 56, | ||
470 | 56, | ||
471 | SSL_ALL_CIPHERS, | ||
472 | SSL_ALL_STRENGTHS, | ||
473 | }, | ||
474 | /* Cipher 16 */ | ||
475 | { | ||
476 | 1, | ||
477 | SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA, | ||
478 | SSL3_CK_EDH_RSA_DES_192_CBC3_SHA, | ||
479 | SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
480 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
481 | 0, | ||
482 | 168, | ||
483 | 168, | ||
484 | SSL_ALL_CIPHERS, | ||
485 | SSL_ALL_STRENGTHS, | ||
486 | }, | ||
487 | |||
488 | /* Fortezza */ | ||
489 | /* Cipher 1C */ | ||
490 | { | ||
491 | 0, | ||
492 | SSL3_TXT_FZA_DMS_NULL_SHA, | ||
493 | SSL3_CK_FZA_DMS_NULL_SHA, | ||
494 | SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3, | ||
495 | SSL_NOT_EXP|SSL_STRONG_NONE, | ||
496 | 0, | ||
497 | 0, | ||
498 | 0, | ||
499 | SSL_ALL_CIPHERS, | ||
500 | SSL_ALL_STRENGTHS, | ||
501 | }, | ||
502 | |||
503 | /* Cipher 1D */ | ||
504 | { | ||
505 | 0, | ||
506 | SSL3_TXT_FZA_DMS_FZA_SHA, | ||
507 | SSL3_CK_FZA_DMS_FZA_SHA, | ||
508 | SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3, | ||
509 | SSL_NOT_EXP|SSL_STRONG_NONE, | ||
510 | 0, | ||
511 | 0, | ||
512 | 0, | ||
513 | SSL_ALL_CIPHERS, | ||
514 | SSL_ALL_STRENGTHS, | ||
515 | }, | ||
516 | |||
517 | #if 0 | ||
518 | /* Cipher 1E */ | ||
519 | { | ||
520 | 0, | ||
521 | SSL3_TXT_FZA_DMS_RC4_SHA, | ||
522 | SSL3_CK_FZA_DMS_RC4_SHA, | ||
523 | SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3, | ||
524 | SSL_NOT_EXP|SSL_MEDIUM, | ||
525 | 0, | ||
526 | 128, | ||
527 | 128, | ||
528 | SSL_ALL_CIPHERS, | ||
529 | SSL_ALL_STRENGTHS, | ||
530 | }, | ||
531 | #endif | ||
532 | |||
533 | #ifndef OPENSSL_NO_KRB5 | ||
534 | /* The Kerberos ciphers | ||
535 | ** 20000107 VRS: And the first shall be last, | ||
536 | ** in hopes of avoiding the lynx ssl renegotiation problem. | ||
537 | */ | ||
538 | /* Cipher 1E VRS */ | ||
539 | { | ||
540 | 1, | ||
541 | SSL3_TXT_KRB5_DES_64_CBC_SHA, | ||
542 | SSL3_CK_KRB5_DES_64_CBC_SHA, | ||
543 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | ||
544 | SSL_NOT_EXP|SSL_LOW|SSL_FIPS, | ||
545 | 0, | ||
546 | 56, | ||
547 | 56, | ||
548 | SSL_ALL_CIPHERS, | ||
549 | SSL_ALL_STRENGTHS, | ||
550 | }, | ||
551 | |||
552 | /* Cipher 1F VRS */ | ||
553 | { | ||
554 | 1, | ||
555 | SSL3_TXT_KRB5_DES_192_CBC3_SHA, | ||
556 | SSL3_CK_KRB5_DES_192_CBC3_SHA, | ||
557 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3, | ||
558 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
559 | 0, | ||
560 | 112, | ||
561 | 168, | ||
562 | SSL_ALL_CIPHERS, | ||
563 | SSL_ALL_STRENGTHS, | ||
564 | }, | ||
565 | |||
566 | /* Cipher 20 VRS */ | ||
567 | { | ||
568 | 1, | ||
569 | SSL3_TXT_KRB5_RC4_128_SHA, | ||
570 | SSL3_CK_KRB5_RC4_128_SHA, | ||
571 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, | ||
572 | SSL_NOT_EXP|SSL_MEDIUM, | ||
573 | 0, | ||
574 | 128, | ||
575 | 128, | ||
576 | SSL_ALL_CIPHERS, | ||
577 | SSL_ALL_STRENGTHS, | ||
578 | }, | ||
579 | |||
580 | /* Cipher 21 VRS */ | ||
581 | { | ||
582 | 1, | ||
583 | SSL3_TXT_KRB5_IDEA_128_CBC_SHA, | ||
584 | SSL3_CK_KRB5_IDEA_128_CBC_SHA, | ||
585 | SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_SHA1 |SSL_SSLV3, | ||
586 | SSL_NOT_EXP|SSL_MEDIUM, | ||
587 | 0, | ||
588 | 128, | ||
589 | 128, | ||
590 | SSL_ALL_CIPHERS, | ||
591 | SSL_ALL_STRENGTHS, | ||
592 | }, | ||
593 | |||
594 | /* Cipher 22 VRS */ | ||
595 | { | ||
596 | 1, | ||
597 | SSL3_TXT_KRB5_DES_64_CBC_MD5, | ||
598 | SSL3_CK_KRB5_DES_64_CBC_MD5, | ||
599 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3, | ||
600 | SSL_NOT_EXP|SSL_LOW, | ||
601 | 0, | ||
602 | 56, | ||
603 | 56, | ||
604 | SSL_ALL_CIPHERS, | ||
605 | SSL_ALL_STRENGTHS, | ||
606 | }, | ||
607 | |||
608 | /* Cipher 23 VRS */ | ||
609 | { | ||
610 | 1, | ||
611 | SSL3_TXT_KRB5_DES_192_CBC3_MD5, | ||
612 | SSL3_CK_KRB5_DES_192_CBC3_MD5, | ||
613 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3, | ||
614 | SSL_NOT_EXP|SSL_HIGH, | ||
615 | 0, | ||
616 | 112, | ||
617 | 168, | ||
618 | SSL_ALL_CIPHERS, | ||
619 | SSL_ALL_STRENGTHS, | ||
620 | }, | ||
621 | |||
622 | /* Cipher 24 VRS */ | ||
623 | { | ||
624 | 1, | ||
625 | SSL3_TXT_KRB5_RC4_128_MD5, | ||
626 | SSL3_CK_KRB5_RC4_128_MD5, | ||
627 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, | ||
628 | SSL_NOT_EXP|SSL_MEDIUM, | ||
629 | 0, | ||
630 | 128, | ||
631 | 128, | ||
632 | SSL_ALL_CIPHERS, | ||
633 | SSL_ALL_STRENGTHS, | ||
634 | }, | ||
635 | |||
636 | /* Cipher 25 VRS */ | ||
637 | { | ||
638 | 1, | ||
639 | SSL3_TXT_KRB5_IDEA_128_CBC_MD5, | ||
640 | SSL3_CK_KRB5_IDEA_128_CBC_MD5, | ||
641 | SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_MD5 |SSL_SSLV3, | ||
642 | SSL_NOT_EXP|SSL_MEDIUM, | ||
643 | 0, | ||
644 | 128, | ||
645 | 128, | ||
646 | SSL_ALL_CIPHERS, | ||
647 | SSL_ALL_STRENGTHS, | ||
648 | }, | ||
649 | |||
650 | /* Cipher 26 VRS */ | ||
651 | { | ||
652 | 1, | ||
653 | SSL3_TXT_KRB5_DES_40_CBC_SHA, | ||
654 | SSL3_CK_KRB5_DES_40_CBC_SHA, | ||
655 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | ||
656 | SSL_EXPORT|SSL_EXP40|SSL_FIPS, | ||
657 | 0, | ||
658 | 40, | ||
659 | 56, | ||
660 | SSL_ALL_CIPHERS, | ||
661 | SSL_ALL_STRENGTHS, | ||
662 | }, | ||
663 | |||
664 | /* Cipher 27 VRS */ | ||
665 | { | ||
666 | 1, | ||
667 | SSL3_TXT_KRB5_RC2_40_CBC_SHA, | ||
668 | SSL3_CK_KRB5_RC2_40_CBC_SHA, | ||
669 | SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_SHA1 |SSL_SSLV3, | ||
670 | SSL_EXPORT|SSL_EXP40, | ||
671 | 0, | ||
672 | 40, | ||
673 | 128, | ||
674 | SSL_ALL_CIPHERS, | ||
675 | SSL_ALL_STRENGTHS, | ||
676 | }, | ||
677 | |||
678 | /* Cipher 28 VRS */ | ||
679 | { | ||
680 | 1, | ||
681 | SSL3_TXT_KRB5_RC4_40_SHA, | ||
682 | SSL3_CK_KRB5_RC4_40_SHA, | ||
683 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, | ||
684 | SSL_EXPORT|SSL_EXP40, | ||
685 | 0, | ||
686 | 128, | ||
687 | 128, | ||
688 | SSL_ALL_CIPHERS, | ||
689 | SSL_ALL_STRENGTHS, | ||
690 | }, | ||
691 | |||
692 | /* Cipher 29 VRS */ | ||
693 | { | ||
694 | 1, | ||
695 | SSL3_TXT_KRB5_DES_40_CBC_MD5, | ||
696 | SSL3_CK_KRB5_DES_40_CBC_MD5, | ||
697 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3, | ||
698 | SSL_EXPORT|SSL_EXP40, | ||
699 | 0, | ||
700 | 40, | ||
701 | 56, | ||
702 | SSL_ALL_CIPHERS, | ||
703 | SSL_ALL_STRENGTHS, | ||
704 | }, | ||
705 | |||
706 | /* Cipher 2A VRS */ | ||
707 | { | ||
708 | 1, | ||
709 | SSL3_TXT_KRB5_RC2_40_CBC_MD5, | ||
710 | SSL3_CK_KRB5_RC2_40_CBC_MD5, | ||
711 | SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_MD5 |SSL_SSLV3, | ||
712 | SSL_EXPORT|SSL_EXP40, | ||
713 | 0, | ||
714 | 40, | ||
715 | 128, | ||
716 | SSL_ALL_CIPHERS, | ||
717 | SSL_ALL_STRENGTHS, | ||
718 | }, | ||
719 | |||
720 | /* Cipher 2B VRS */ | ||
721 | { | ||
722 | 1, | ||
723 | SSL3_TXT_KRB5_RC4_40_MD5, | ||
724 | SSL3_CK_KRB5_RC4_40_MD5, | ||
725 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, | ||
726 | SSL_EXPORT|SSL_EXP40, | ||
727 | 0, | ||
728 | 128, | ||
729 | 128, | ||
730 | SSL_ALL_CIPHERS, | ||
731 | SSL_ALL_STRENGTHS, | ||
732 | }, | ||
733 | #endif /* OPENSSL_NO_KRB5 */ | ||
734 | |||
735 | |||
736 | #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES | ||
737 | /* New TLS Export CipherSuites */ | ||
738 | /* Cipher 60 */ | ||
739 | { | ||
740 | 1, | ||
741 | TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5, | ||
742 | TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5, | ||
743 | SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1, | ||
744 | SSL_EXPORT|SSL_EXP56, | ||
745 | 0, | ||
746 | 56, | ||
747 | 128, | ||
748 | SSL_ALL_CIPHERS, | ||
749 | SSL_ALL_STRENGTHS, | ||
750 | }, | ||
751 | /* Cipher 61 */ | ||
752 | { | ||
753 | 1, | ||
754 | TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5, | ||
755 | TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5, | ||
756 | SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1, | ||
757 | SSL_EXPORT|SSL_EXP56, | ||
758 | 0, | ||
759 | 56, | ||
760 | 128, | ||
761 | SSL_ALL_CIPHERS, | ||
762 | SSL_ALL_STRENGTHS, | ||
763 | }, | ||
764 | /* Cipher 62 */ | ||
765 | { | ||
766 | 1, | ||
767 | TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA, | ||
768 | TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA, | ||
769 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1, | ||
770 | SSL_EXPORT|SSL_EXP56|SSL_FIPS, | ||
771 | 0, | ||
772 | 56, | ||
773 | 56, | ||
774 | SSL_ALL_CIPHERS, | ||
775 | SSL_ALL_STRENGTHS, | ||
776 | }, | ||
777 | /* Cipher 63 */ | ||
778 | { | ||
779 | 1, | ||
780 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | ||
781 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | ||
782 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1, | ||
783 | SSL_EXPORT|SSL_EXP56|SSL_FIPS, | ||
784 | 0, | ||
785 | 56, | ||
786 | 56, | ||
787 | SSL_ALL_CIPHERS, | ||
788 | SSL_ALL_STRENGTHS, | ||
789 | }, | ||
790 | /* Cipher 64 */ | ||
791 | { | ||
792 | 1, | ||
793 | TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA, | ||
794 | TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA, | ||
795 | SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
796 | SSL_EXPORT|SSL_EXP56, | ||
797 | 0, | ||
798 | 56, | ||
799 | 128, | ||
800 | SSL_ALL_CIPHERS, | ||
801 | SSL_ALL_STRENGTHS, | ||
802 | }, | ||
803 | /* Cipher 65 */ | ||
804 | { | ||
805 | 1, | ||
806 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA, | ||
807 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA, | ||
808 | SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
809 | SSL_EXPORT|SSL_EXP56, | ||
810 | 0, | ||
811 | 56, | ||
812 | 128, | ||
813 | SSL_ALL_CIPHERS, | ||
814 | SSL_ALL_STRENGTHS, | ||
815 | }, | ||
816 | /* Cipher 66 */ | ||
817 | { | ||
818 | 1, | ||
819 | TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA, | ||
820 | TLS1_CK_DHE_DSS_WITH_RC4_128_SHA, | ||
821 | SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
822 | SSL_NOT_EXP|SSL_MEDIUM, | ||
823 | 0, | ||
824 | 128, | ||
825 | 128, | ||
826 | SSL_ALL_CIPHERS, | ||
827 | SSL_ALL_STRENGTHS | ||
828 | }, | ||
829 | #endif | ||
830 | /* New AES ciphersuites */ | ||
831 | |||
832 | /* Cipher 2F */ | ||
833 | { | ||
834 | 1, | ||
835 | TLS1_TXT_RSA_WITH_AES_128_SHA, | ||
836 | TLS1_CK_RSA_WITH_AES_128_SHA, | ||
837 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | ||
838 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
839 | 0, | ||
840 | 128, | ||
841 | 128, | ||
842 | SSL_ALL_CIPHERS, | ||
843 | SSL_ALL_STRENGTHS, | ||
844 | }, | ||
845 | /* Cipher 30 */ | ||
846 | { | ||
847 | 0, | ||
848 | TLS1_TXT_DH_DSS_WITH_AES_128_SHA, | ||
849 | TLS1_CK_DH_DSS_WITH_AES_128_SHA, | ||
850 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
851 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
852 | 0, | ||
853 | 128, | ||
854 | 128, | ||
855 | SSL_ALL_CIPHERS, | ||
856 | SSL_ALL_STRENGTHS, | ||
857 | }, | ||
858 | /* Cipher 31 */ | ||
859 | { | ||
860 | 0, | ||
861 | TLS1_TXT_DH_RSA_WITH_AES_128_SHA, | ||
862 | TLS1_CK_DH_RSA_WITH_AES_128_SHA, | ||
863 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
864 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
865 | 0, | ||
866 | 128, | ||
867 | 128, | ||
868 | SSL_ALL_CIPHERS, | ||
869 | SSL_ALL_STRENGTHS, | ||
870 | }, | ||
871 | /* Cipher 32 */ | ||
872 | { | ||
873 | 1, | ||
874 | TLS1_TXT_DHE_DSS_WITH_AES_128_SHA, | ||
875 | TLS1_CK_DHE_DSS_WITH_AES_128_SHA, | ||
876 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
877 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
878 | 0, | ||
879 | 128, | ||
880 | 128, | ||
881 | SSL_ALL_CIPHERS, | ||
882 | SSL_ALL_STRENGTHS, | ||
883 | }, | ||
884 | /* Cipher 33 */ | ||
885 | { | ||
886 | 1, | ||
887 | TLS1_TXT_DHE_RSA_WITH_AES_128_SHA, | ||
888 | TLS1_CK_DHE_RSA_WITH_AES_128_SHA, | ||
889 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
890 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
891 | 0, | ||
892 | 128, | ||
893 | 128, | ||
894 | SSL_ALL_CIPHERS, | ||
895 | SSL_ALL_STRENGTHS, | ||
896 | }, | ||
897 | /* Cipher 34 */ | ||
898 | { | ||
899 | 1, | ||
900 | TLS1_TXT_ADH_WITH_AES_128_SHA, | ||
901 | TLS1_CK_ADH_WITH_AES_128_SHA, | ||
902 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
903 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
904 | 0, | ||
905 | 128, | ||
906 | 128, | ||
907 | SSL_ALL_CIPHERS, | ||
908 | SSL_ALL_STRENGTHS, | ||
909 | }, | ||
910 | |||
911 | /* Cipher 35 */ | ||
912 | { | ||
913 | 1, | ||
914 | TLS1_TXT_RSA_WITH_AES_256_SHA, | ||
915 | TLS1_CK_RSA_WITH_AES_256_SHA, | ||
916 | SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1, | ||
917 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
918 | 0, | ||
919 | 256, | ||
920 | 256, | ||
921 | SSL_ALL_CIPHERS, | ||
922 | SSL_ALL_STRENGTHS, | ||
923 | }, | ||
924 | /* Cipher 36 */ | ||
925 | { | ||
926 | 0, | ||
927 | TLS1_TXT_DH_DSS_WITH_AES_256_SHA, | ||
928 | TLS1_CK_DH_DSS_WITH_AES_256_SHA, | ||
929 | SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
930 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
931 | 0, | ||
932 | 256, | ||
933 | 256, | ||
934 | SSL_ALL_CIPHERS, | ||
935 | SSL_ALL_STRENGTHS, | ||
936 | }, | ||
937 | /* Cipher 37 */ | ||
938 | { | ||
939 | 0, | ||
940 | TLS1_TXT_DH_RSA_WITH_AES_256_SHA, | ||
941 | TLS1_CK_DH_RSA_WITH_AES_256_SHA, | ||
942 | SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
943 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
944 | 0, | ||
945 | 256, | ||
946 | 256, | ||
947 | SSL_ALL_CIPHERS, | ||
948 | SSL_ALL_STRENGTHS, | ||
949 | }, | ||
950 | /* Cipher 38 */ | ||
951 | { | ||
952 | 1, | ||
953 | TLS1_TXT_DHE_DSS_WITH_AES_256_SHA, | ||
954 | TLS1_CK_DHE_DSS_WITH_AES_256_SHA, | ||
955 | SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
956 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
957 | 0, | ||
958 | 256, | ||
959 | 256, | ||
960 | SSL_ALL_CIPHERS, | ||
961 | SSL_ALL_STRENGTHS, | ||
962 | }, | ||
963 | /* Cipher 39 */ | ||
964 | { | ||
965 | 1, | ||
966 | TLS1_TXT_DHE_RSA_WITH_AES_256_SHA, | ||
967 | TLS1_CK_DHE_RSA_WITH_AES_256_SHA, | ||
968 | SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
969 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
970 | 0, | ||
971 | 256, | ||
972 | 256, | ||
973 | SSL_ALL_CIPHERS, | ||
974 | SSL_ALL_STRENGTHS, | ||
975 | }, | ||
976 | /* Cipher 3A */ | ||
977 | { | ||
978 | 1, | ||
979 | TLS1_TXT_ADH_WITH_AES_256_SHA, | ||
980 | TLS1_CK_ADH_WITH_AES_256_SHA, | ||
981 | SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1, | ||
982 | SSL_NOT_EXP|SSL_HIGH|SSL_FIPS, | ||
983 | 0, | ||
984 | 256, | ||
985 | 256, | ||
986 | SSL_ALL_CIPHERS, | ||
987 | SSL_ALL_STRENGTHS, | ||
988 | }, | ||
989 | |||
990 | /* end of list */ | ||
991 | }; | ||
992 | |||
993 | static SSL3_ENC_METHOD SSLv3_enc_data={ | ||
994 | ssl3_enc, | ||
995 | ssl3_mac, | ||
996 | ssl3_setup_key_block, | ||
997 | ssl3_generate_master_secret, | ||
998 | ssl3_change_cipher_state, | ||
999 | ssl3_final_finish_mac, | ||
1000 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
1001 | ssl3_cert_verify_mac, | ||
1002 | SSL3_MD_CLIENT_FINISHED_CONST,4, | ||
1003 | SSL3_MD_SERVER_FINISHED_CONST,4, | ||
1004 | ssl3_alert_code, | ||
1005 | }; | ||
1006 | |||
1007 | static SSL_METHOD SSLv3_data= { | ||
1008 | SSL3_VERSION, | ||
1009 | ssl3_new, | ||
1010 | ssl3_clear, | ||
1011 | ssl3_free, | ||
1012 | ssl_undefined_function, | ||
1013 | ssl_undefined_function, | ||
1014 | ssl3_read, | ||
1015 | ssl3_peek, | ||
1016 | ssl3_write, | ||
1017 | ssl3_shutdown, | ||
1018 | ssl3_renegotiate, | ||
1019 | ssl3_renegotiate_check, | ||
1020 | ssl3_ctrl, | ||
1021 | ssl3_ctx_ctrl, | ||
1022 | ssl3_get_cipher_by_char, | ||
1023 | ssl3_put_cipher_by_char, | ||
1024 | ssl3_pending, | ||
1025 | ssl3_num_ciphers, | ||
1026 | ssl3_get_cipher, | ||
1027 | ssl_bad_method, | ||
1028 | ssl3_default_timeout, | ||
1029 | &SSLv3_enc_data, | ||
1030 | ssl_undefined_function, | ||
1031 | ssl3_callback_ctrl, | ||
1032 | ssl3_ctx_callback_ctrl, | ||
1033 | }; | ||
1034 | |||
1035 | static long ssl3_default_timeout(void) | ||
1036 | { | ||
1037 | /* 2 hours, the 24 hours mentioned in the SSLv3 spec | ||
1038 | * is way too long for http, the cache would over fill */ | ||
1039 | return(60*60*2); | ||
1040 | } | ||
1041 | |||
1042 | SSL_METHOD *sslv3_base_method(void) | ||
1043 | { | ||
1044 | return(&SSLv3_data); | ||
1045 | } | ||
1046 | |||
1047 | int ssl3_num_ciphers(void) | ||
1048 | { | ||
1049 | return(SSL3_NUM_CIPHERS); | ||
1050 | } | ||
1051 | |||
1052 | SSL_CIPHER *ssl3_get_cipher(unsigned int u) | ||
1053 | { | ||
1054 | if (u < SSL3_NUM_CIPHERS) | ||
1055 | return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u])); | ||
1056 | else | ||
1057 | return(NULL); | ||
1058 | } | ||
1059 | |||
1060 | int ssl3_pending(const SSL *s) | ||
1061 | { | ||
1062 | if (s->rstate == SSL_ST_READ_BODY) | ||
1063 | return 0; | ||
1064 | |||
1065 | return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0; | ||
1066 | } | ||
1067 | |||
1068 | int ssl3_new(SSL *s) | ||
1069 | { | ||
1070 | SSL3_STATE *s3; | ||
1071 | |||
1072 | if ((s3=OPENSSL_malloc(sizeof *s3)) == NULL) goto err; | ||
1073 | memset(s3,0,sizeof *s3); | ||
1074 | EVP_MD_CTX_init(&s3->finish_dgst1); | ||
1075 | EVP_MD_CTX_init(&s3->finish_dgst2); | ||
1076 | |||
1077 | s->s3=s3; | ||
1078 | |||
1079 | s->method->ssl_clear(s); | ||
1080 | return(1); | ||
1081 | err: | ||
1082 | return(0); | ||
1083 | } | ||
1084 | |||
1085 | void ssl3_free(SSL *s) | ||
1086 | { | ||
1087 | if(s == NULL) | ||
1088 | return; | ||
1089 | |||
1090 | ssl3_cleanup_key_block(s); | ||
1091 | if (s->s3->rbuf.buf != NULL) | ||
1092 | OPENSSL_free(s->s3->rbuf.buf); | ||
1093 | if (s->s3->wbuf.buf != NULL) | ||
1094 | OPENSSL_free(s->s3->wbuf.buf); | ||
1095 | if (s->s3->rrec.comp != NULL) | ||
1096 | OPENSSL_free(s->s3->rrec.comp); | ||
1097 | #ifndef OPENSSL_NO_DH | ||
1098 | if (s->s3->tmp.dh != NULL) | ||
1099 | DH_free(s->s3->tmp.dh); | ||
1100 | #endif | ||
1101 | if (s->s3->tmp.ca_names != NULL) | ||
1102 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
1103 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); | ||
1104 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); | ||
1105 | OPENSSL_cleanse(s->s3,sizeof *s->s3); | ||
1106 | OPENSSL_free(s->s3); | ||
1107 | s->s3=NULL; | ||
1108 | } | ||
1109 | |||
1110 | void ssl3_clear(SSL *s) | ||
1111 | { | ||
1112 | unsigned char *rp,*wp; | ||
1113 | size_t rlen, wlen; | ||
1114 | |||
1115 | ssl3_cleanup_key_block(s); | ||
1116 | if (s->s3->tmp.ca_names != NULL) | ||
1117 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
1118 | |||
1119 | if (s->s3->rrec.comp != NULL) | ||
1120 | { | ||
1121 | OPENSSL_free(s->s3->rrec.comp); | ||
1122 | s->s3->rrec.comp=NULL; | ||
1123 | } | ||
1124 | #ifndef OPENSSL_NO_DH | ||
1125 | if (s->s3->tmp.dh != NULL) | ||
1126 | DH_free(s->s3->tmp.dh); | ||
1127 | #endif | ||
1128 | |||
1129 | rp = s->s3->rbuf.buf; | ||
1130 | wp = s->s3->wbuf.buf; | ||
1131 | rlen = s->s3->rbuf.len; | ||
1132 | wlen = s->s3->wbuf.len; | ||
1133 | |||
1134 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); | ||
1135 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); | ||
1136 | |||
1137 | memset(s->s3,0,sizeof *s->s3); | ||
1138 | s->s3->rbuf.buf = rp; | ||
1139 | s->s3->wbuf.buf = wp; | ||
1140 | s->s3->rbuf.len = rlen; | ||
1141 | s->s3->wbuf.len = wlen; | ||
1142 | |||
1143 | ssl_free_wbio_buffer(s); | ||
1144 | |||
1145 | s->packet_length=0; | ||
1146 | s->s3->renegotiate=0; | ||
1147 | s->s3->total_renegotiations=0; | ||
1148 | s->s3->num_renegotiations=0; | ||
1149 | s->s3->in_read_app_data=0; | ||
1150 | s->version=SSL3_VERSION; | ||
1151 | } | ||
1152 | |||
1153 | long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) | ||
1154 | { | ||
1155 | int ret=0; | ||
1156 | |||
1157 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA) | ||
1158 | if ( | ||
1159 | #ifndef OPENSSL_NO_RSA | ||
1160 | cmd == SSL_CTRL_SET_TMP_RSA || | ||
1161 | cmd == SSL_CTRL_SET_TMP_RSA_CB || | ||
1162 | #endif | ||
1163 | #ifndef OPENSSL_NO_DSA | ||
1164 | cmd == SSL_CTRL_SET_TMP_DH || | ||
1165 | cmd == SSL_CTRL_SET_TMP_DH_CB || | ||
1166 | #endif | ||
1167 | 0) | ||
1168 | { | ||
1169 | if (!ssl_cert_inst(&s->cert)) | ||
1170 | { | ||
1171 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE); | ||
1172 | return(0); | ||
1173 | } | ||
1174 | } | ||
1175 | #endif | ||
1176 | |||
1177 | switch (cmd) | ||
1178 | { | ||
1179 | case SSL_CTRL_GET_SESSION_REUSED: | ||
1180 | ret=s->hit; | ||
1181 | break; | ||
1182 | case SSL_CTRL_GET_CLIENT_CERT_REQUEST: | ||
1183 | break; | ||
1184 | case SSL_CTRL_GET_NUM_RENEGOTIATIONS: | ||
1185 | ret=s->s3->num_renegotiations; | ||
1186 | break; | ||
1187 | case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS: | ||
1188 | ret=s->s3->num_renegotiations; | ||
1189 | s->s3->num_renegotiations=0; | ||
1190 | break; | ||
1191 | case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS: | ||
1192 | ret=s->s3->total_renegotiations; | ||
1193 | break; | ||
1194 | case SSL_CTRL_GET_FLAGS: | ||
1195 | ret=(int)(s->s3->flags); | ||
1196 | break; | ||
1197 | #ifndef OPENSSL_NO_RSA | ||
1198 | case SSL_CTRL_NEED_TMP_RSA: | ||
1199 | if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) && | ||
1200 | ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) || | ||
1201 | (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))) | ||
1202 | ret = 1; | ||
1203 | break; | ||
1204 | case SSL_CTRL_SET_TMP_RSA: | ||
1205 | { | ||
1206 | RSA *rsa = (RSA *)parg; | ||
1207 | if (rsa == NULL) | ||
1208 | { | ||
1209 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER); | ||
1210 | return(ret); | ||
1211 | } | ||
1212 | if ((rsa = RSAPrivateKey_dup(rsa)) == NULL) | ||
1213 | { | ||
1214 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB); | ||
1215 | return(ret); | ||
1216 | } | ||
1217 | if (s->cert->rsa_tmp != NULL) | ||
1218 | RSA_free(s->cert->rsa_tmp); | ||
1219 | s->cert->rsa_tmp = rsa; | ||
1220 | ret = 1; | ||
1221 | } | ||
1222 | break; | ||
1223 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
1224 | { | ||
1225 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1226 | return(ret); | ||
1227 | } | ||
1228 | break; | ||
1229 | #endif | ||
1230 | #ifndef OPENSSL_NO_DH | ||
1231 | case SSL_CTRL_SET_TMP_DH: | ||
1232 | { | ||
1233 | DH *dh = (DH *)parg; | ||
1234 | if (dh == NULL) | ||
1235 | { | ||
1236 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER); | ||
1237 | return(ret); | ||
1238 | } | ||
1239 | if ((dh = DHparams_dup(dh)) == NULL) | ||
1240 | { | ||
1241 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB); | ||
1242 | return(ret); | ||
1243 | } | ||
1244 | if (!(s->options & SSL_OP_SINGLE_DH_USE)) | ||
1245 | { | ||
1246 | if (!DH_generate_key(dh)) | ||
1247 | { | ||
1248 | DH_free(dh); | ||
1249 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB); | ||
1250 | return(ret); | ||
1251 | } | ||
1252 | } | ||
1253 | if (s->cert->dh_tmp != NULL) | ||
1254 | DH_free(s->cert->dh_tmp); | ||
1255 | s->cert->dh_tmp = dh; | ||
1256 | ret = 1; | ||
1257 | } | ||
1258 | break; | ||
1259 | case SSL_CTRL_SET_TMP_DH_CB: | ||
1260 | { | ||
1261 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1262 | return(ret); | ||
1263 | } | ||
1264 | break; | ||
1265 | #endif | ||
1266 | default: | ||
1267 | break; | ||
1268 | } | ||
1269 | return(ret); | ||
1270 | } | ||
1271 | |||
1272 | long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)()) | ||
1273 | { | ||
1274 | int ret=0; | ||
1275 | |||
1276 | #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA) | ||
1277 | if ( | ||
1278 | #ifndef OPENSSL_NO_RSA | ||
1279 | cmd == SSL_CTRL_SET_TMP_RSA_CB || | ||
1280 | #endif | ||
1281 | #ifndef OPENSSL_NO_DSA | ||
1282 | cmd == SSL_CTRL_SET_TMP_DH_CB || | ||
1283 | #endif | ||
1284 | 0) | ||
1285 | { | ||
1286 | if (!ssl_cert_inst(&s->cert)) | ||
1287 | { | ||
1288 | SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE); | ||
1289 | return(0); | ||
1290 | } | ||
1291 | } | ||
1292 | #endif | ||
1293 | |||
1294 | switch (cmd) | ||
1295 | { | ||
1296 | #ifndef OPENSSL_NO_RSA | ||
1297 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
1298 | { | ||
1299 | s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp; | ||
1300 | } | ||
1301 | break; | ||
1302 | #endif | ||
1303 | #ifndef OPENSSL_NO_DH | ||
1304 | case SSL_CTRL_SET_TMP_DH_CB: | ||
1305 | { | ||
1306 | s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp; | ||
1307 | } | ||
1308 | break; | ||
1309 | #endif | ||
1310 | default: | ||
1311 | break; | ||
1312 | } | ||
1313 | return(ret); | ||
1314 | } | ||
1315 | |||
1316 | long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg) | ||
1317 | { | ||
1318 | CERT *cert; | ||
1319 | |||
1320 | cert=ctx->cert; | ||
1321 | |||
1322 | switch (cmd) | ||
1323 | { | ||
1324 | #ifndef OPENSSL_NO_RSA | ||
1325 | case SSL_CTRL_NEED_TMP_RSA: | ||
1326 | if ( (cert->rsa_tmp == NULL) && | ||
1327 | ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) || | ||
1328 | (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))) | ||
1329 | ) | ||
1330 | return(1); | ||
1331 | else | ||
1332 | return(0); | ||
1333 | /* break; */ | ||
1334 | case SSL_CTRL_SET_TMP_RSA: | ||
1335 | { | ||
1336 | RSA *rsa; | ||
1337 | int i; | ||
1338 | |||
1339 | rsa=(RSA *)parg; | ||
1340 | i=1; | ||
1341 | if (rsa == NULL) | ||
1342 | i=0; | ||
1343 | else | ||
1344 | { | ||
1345 | if ((rsa=RSAPrivateKey_dup(rsa)) == NULL) | ||
1346 | i=0; | ||
1347 | } | ||
1348 | if (!i) | ||
1349 | { | ||
1350 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB); | ||
1351 | return(0); | ||
1352 | } | ||
1353 | else | ||
1354 | { | ||
1355 | if (cert->rsa_tmp != NULL) | ||
1356 | RSA_free(cert->rsa_tmp); | ||
1357 | cert->rsa_tmp=rsa; | ||
1358 | return(1); | ||
1359 | } | ||
1360 | } | ||
1361 | /* break; */ | ||
1362 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
1363 | { | ||
1364 | SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1365 | return(0); | ||
1366 | } | ||
1367 | break; | ||
1368 | #endif | ||
1369 | #ifndef OPENSSL_NO_DH | ||
1370 | case SSL_CTRL_SET_TMP_DH: | ||
1371 | { | ||
1372 | DH *new=NULL,*dh; | ||
1373 | |||
1374 | dh=(DH *)parg; | ||
1375 | if ((new=DHparams_dup(dh)) == NULL) | ||
1376 | { | ||
1377 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB); | ||
1378 | return 0; | ||
1379 | } | ||
1380 | if (!(ctx->options & SSL_OP_SINGLE_DH_USE)) | ||
1381 | { | ||
1382 | if (!DH_generate_key(new)) | ||
1383 | { | ||
1384 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB); | ||
1385 | DH_free(new); | ||
1386 | return 0; | ||
1387 | } | ||
1388 | } | ||
1389 | if (cert->dh_tmp != NULL) | ||
1390 | DH_free(cert->dh_tmp); | ||
1391 | cert->dh_tmp=new; | ||
1392 | return 1; | ||
1393 | } | ||
1394 | /*break; */ | ||
1395 | case SSL_CTRL_SET_TMP_DH_CB: | ||
1396 | { | ||
1397 | SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1398 | return(0); | ||
1399 | } | ||
1400 | break; | ||
1401 | #endif | ||
1402 | /* A Thawte special :-) */ | ||
1403 | case SSL_CTRL_EXTRA_CHAIN_CERT: | ||
1404 | if (ctx->extra_certs == NULL) | ||
1405 | { | ||
1406 | if ((ctx->extra_certs=sk_X509_new_null()) == NULL) | ||
1407 | return(0); | ||
1408 | } | ||
1409 | sk_X509_push(ctx->extra_certs,(X509 *)parg); | ||
1410 | break; | ||
1411 | |||
1412 | default: | ||
1413 | return(0); | ||
1414 | } | ||
1415 | return(1); | ||
1416 | } | ||
1417 | |||
1418 | long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | ||
1419 | { | ||
1420 | CERT *cert; | ||
1421 | |||
1422 | cert=ctx->cert; | ||
1423 | |||
1424 | switch (cmd) | ||
1425 | { | ||
1426 | #ifndef OPENSSL_NO_RSA | ||
1427 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
1428 | { | ||
1429 | cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp; | ||
1430 | } | ||
1431 | break; | ||
1432 | #endif | ||
1433 | #ifndef OPENSSL_NO_DH | ||
1434 | case SSL_CTRL_SET_TMP_DH_CB: | ||
1435 | { | ||
1436 | cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp; | ||
1437 | } | ||
1438 | break; | ||
1439 | #endif | ||
1440 | default: | ||
1441 | return(0); | ||
1442 | } | ||
1443 | return(1); | ||
1444 | } | ||
1445 | |||
1446 | /* This function needs to check if the ciphers required are actually | ||
1447 | * available */ | ||
1448 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p) | ||
1449 | { | ||
1450 | static int init=1; | ||
1451 | static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS]; | ||
1452 | SSL_CIPHER c,*cp= &c,**cpp; | ||
1453 | unsigned long id; | ||
1454 | int i; | ||
1455 | |||
1456 | if (init) | ||
1457 | { | ||
1458 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
1459 | |||
1460 | if (init) | ||
1461 | { | ||
1462 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | ||
1463 | sorted[i]= &(ssl3_ciphers[i]); | ||
1464 | |||
1465 | qsort(sorted, | ||
1466 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
1467 | FP_ICC ssl_cipher_ptr_id_cmp); | ||
1468 | |||
1469 | init=0; | ||
1470 | } | ||
1471 | |||
1472 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
1473 | } | ||
1474 | |||
1475 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; | ||
1476 | c.id=id; | ||
1477 | cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp, | ||
1478 | (char *)sorted, | ||
1479 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
1480 | FP_ICC ssl_cipher_ptr_id_cmp); | ||
1481 | if ((cpp == NULL) || !(*cpp)->valid) | ||
1482 | return(NULL); | ||
1483 | else | ||
1484 | return(*cpp); | ||
1485 | } | ||
1486 | |||
1487 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | ||
1488 | { | ||
1489 | long l; | ||
1490 | |||
1491 | if (p != NULL) | ||
1492 | { | ||
1493 | l=c->id; | ||
1494 | if ((l & 0xff000000) != 0x03000000) return(0); | ||
1495 | p[0]=((unsigned char)(l>> 8L))&0xFF; | ||
1496 | p[1]=((unsigned char)(l ))&0xFF; | ||
1497 | } | ||
1498 | return(2); | ||
1499 | } | ||
1500 | |||
1501 | SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt, | ||
1502 | STACK_OF(SSL_CIPHER) *srvr) | ||
1503 | { | ||
1504 | SSL_CIPHER *c,*ret=NULL; | ||
1505 | STACK_OF(SSL_CIPHER) *prio, *allow; | ||
1506 | int i,j,ok; | ||
1507 | CERT *cert; | ||
1508 | unsigned long alg,mask,emask; | ||
1509 | |||
1510 | /* Let's see which ciphers we can support */ | ||
1511 | cert=s->cert; | ||
1512 | |||
1513 | #if 0 | ||
1514 | /* Do not set the compare functions, because this may lead to a | ||
1515 | * reordering by "id". We want to keep the original ordering. | ||
1516 | * We may pay a price in performance during sk_SSL_CIPHER_find(), | ||
1517 | * but would have to pay with the price of sk_SSL_CIPHER_dup(). | ||
1518 | */ | ||
1519 | sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp); | ||
1520 | sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp); | ||
1521 | #endif | ||
1522 | |||
1523 | #ifdef CIPHER_DEBUG | ||
1524 | printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr); | ||
1525 | for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i) | ||
1526 | { | ||
1527 | c=sk_SSL_CIPHER_value(srvr,i); | ||
1528 | printf("%p:%s\n",c,c->name); | ||
1529 | } | ||
1530 | printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt); | ||
1531 | for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i) | ||
1532 | { | ||
1533 | c=sk_SSL_CIPHER_value(clnt,i); | ||
1534 | printf("%p:%s\n",c,c->name); | ||
1535 | } | ||
1536 | #endif | ||
1537 | |||
1538 | if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) | ||
1539 | { | ||
1540 | prio = srvr; | ||
1541 | allow = clnt; | ||
1542 | } | ||
1543 | else | ||
1544 | { | ||
1545 | prio = clnt; | ||
1546 | allow = srvr; | ||
1547 | } | ||
1548 | |||
1549 | for (i=0; i<sk_SSL_CIPHER_num(prio); i++) | ||
1550 | { | ||
1551 | c=sk_SSL_CIPHER_value(prio,i); | ||
1552 | |||
1553 | ssl_set_cert_masks(cert,c); | ||
1554 | mask=cert->mask; | ||
1555 | emask=cert->export_mask; | ||
1556 | |||
1557 | #ifdef KSSL_DEBUG | ||
1558 | printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms); | ||
1559 | #endif /* KSSL_DEBUG */ | ||
1560 | |||
1561 | alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
1562 | #ifndef OPENSSL_NO_KRB5 | ||
1563 | if (alg & SSL_KRB5) | ||
1564 | { | ||
1565 | if ( !kssl_keytab_is_available(s->kssl_ctx) ) | ||
1566 | continue; | ||
1567 | } | ||
1568 | #endif /* OPENSSL_NO_KRB5 */ | ||
1569 | if (SSL_C_IS_EXPORT(c)) | ||
1570 | { | ||
1571 | ok=((alg & emask) == alg)?1:0; | ||
1572 | #ifdef CIPHER_DEBUG | ||
1573 | printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask, | ||
1574 | c,c->name); | ||
1575 | #endif | ||
1576 | } | ||
1577 | else | ||
1578 | { | ||
1579 | ok=((alg & mask) == alg)?1:0; | ||
1580 | #ifdef CIPHER_DEBUG | ||
1581 | printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c, | ||
1582 | c->name); | ||
1583 | #endif | ||
1584 | } | ||
1585 | |||
1586 | if (!ok) continue; | ||
1587 | |||
1588 | j=sk_SSL_CIPHER_find(allow,c); | ||
1589 | if (j >= 0) | ||
1590 | { | ||
1591 | ret=sk_SSL_CIPHER_value(allow,j); | ||
1592 | break; | ||
1593 | } | ||
1594 | } | ||
1595 | return(ret); | ||
1596 | } | ||
1597 | |||
1598 | int ssl3_get_req_cert_type(SSL *s, unsigned char *p) | ||
1599 | { | ||
1600 | int ret=0; | ||
1601 | unsigned long alg; | ||
1602 | |||
1603 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1604 | |||
1605 | #ifndef OPENSSL_NO_DH | ||
1606 | if (alg & (SSL_kDHr|SSL_kEDH)) | ||
1607 | { | ||
1608 | # ifndef OPENSSL_NO_RSA | ||
1609 | p[ret++]=SSL3_CT_RSA_FIXED_DH; | ||
1610 | # endif | ||
1611 | # ifndef OPENSSL_NO_DSA | ||
1612 | p[ret++]=SSL3_CT_DSS_FIXED_DH; | ||
1613 | # endif | ||
1614 | } | ||
1615 | if ((s->version == SSL3_VERSION) && | ||
1616 | (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr))) | ||
1617 | { | ||
1618 | # ifndef OPENSSL_NO_RSA | ||
1619 | p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH; | ||
1620 | # endif | ||
1621 | # ifndef OPENSSL_NO_DSA | ||
1622 | p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH; | ||
1623 | # endif | ||
1624 | } | ||
1625 | #endif /* !OPENSSL_NO_DH */ | ||
1626 | #ifndef OPENSSL_NO_RSA | ||
1627 | p[ret++]=SSL3_CT_RSA_SIGN; | ||
1628 | #endif | ||
1629 | #ifndef OPENSSL_NO_DSA | ||
1630 | p[ret++]=SSL3_CT_DSS_SIGN; | ||
1631 | #endif | ||
1632 | return(ret); | ||
1633 | } | ||
1634 | |||
1635 | int ssl3_shutdown(SSL *s) | ||
1636 | { | ||
1637 | |||
1638 | /* Don't do anything much if we have not done the handshake or | ||
1639 | * we don't want to send messages :-) */ | ||
1640 | if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE)) | ||
1641 | { | ||
1642 | s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
1643 | return(1); | ||
1644 | } | ||
1645 | |||
1646 | if (!(s->shutdown & SSL_SENT_SHUTDOWN)) | ||
1647 | { | ||
1648 | s->shutdown|=SSL_SENT_SHUTDOWN; | ||
1649 | #if 1 | ||
1650 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY); | ||
1651 | #endif | ||
1652 | /* our shutdown alert has been sent now, and if it still needs | ||
1653 | * to be written, s->s3->alert_dispatch will be true */ | ||
1654 | } | ||
1655 | else if (s->s3->alert_dispatch) | ||
1656 | { | ||
1657 | /* resend it if not sent */ | ||
1658 | #if 1 | ||
1659 | ssl3_dispatch_alert(s); | ||
1660 | #endif | ||
1661 | } | ||
1662 | else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) | ||
1663 | { | ||
1664 | /* If we are waiting for a close from our peer, we are closed */ | ||
1665 | ssl3_read_bytes(s,0,NULL,0,0); | ||
1666 | } | ||
1667 | |||
1668 | if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && | ||
1669 | !s->s3->alert_dispatch) | ||
1670 | return(1); | ||
1671 | else | ||
1672 | return(0); | ||
1673 | } | ||
1674 | |||
1675 | int ssl3_write(SSL *s, const void *buf, int len) | ||
1676 | { | ||
1677 | int ret,n; | ||
1678 | |||
1679 | #if 0 | ||
1680 | if (s->shutdown & SSL_SEND_SHUTDOWN) | ||
1681 | { | ||
1682 | s->rwstate=SSL_NOTHING; | ||
1683 | return(0); | ||
1684 | } | ||
1685 | #endif | ||
1686 | clear_sys_error(); | ||
1687 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
1688 | |||
1689 | /* This is an experimental flag that sends the | ||
1690 | * last handshake message in the same packet as the first | ||
1691 | * use data - used to see if it helps the TCP protocol during | ||
1692 | * session-id reuse */ | ||
1693 | /* The second test is because the buffer may have been removed */ | ||
1694 | if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio)) | ||
1695 | { | ||
1696 | /* First time through, we write into the buffer */ | ||
1697 | if (s->s3->delay_buf_pop_ret == 0) | ||
1698 | { | ||
1699 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
1700 | buf,len); | ||
1701 | if (ret <= 0) return(ret); | ||
1702 | |||
1703 | s->s3->delay_buf_pop_ret=ret; | ||
1704 | } | ||
1705 | |||
1706 | s->rwstate=SSL_WRITING; | ||
1707 | n=BIO_flush(s->wbio); | ||
1708 | if (n <= 0) return(n); | ||
1709 | s->rwstate=SSL_NOTHING; | ||
1710 | |||
1711 | /* We have flushed the buffer, so remove it */ | ||
1712 | ssl_free_wbio_buffer(s); | ||
1713 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
1714 | |||
1715 | ret=s->s3->delay_buf_pop_ret; | ||
1716 | s->s3->delay_buf_pop_ret=0; | ||
1717 | } | ||
1718 | else | ||
1719 | { | ||
1720 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
1721 | buf,len); | ||
1722 | if (ret <= 0) return(ret); | ||
1723 | } | ||
1724 | |||
1725 | return(ret); | ||
1726 | } | ||
1727 | |||
1728 | static int ssl3_read_internal(SSL *s, void *buf, int len, int peek) | ||
1729 | { | ||
1730 | int ret; | ||
1731 | |||
1732 | clear_sys_error(); | ||
1733 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
1734 | s->s3->in_read_app_data=1; | ||
1735 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); | ||
1736 | if ((ret == -1) && (s->s3->in_read_app_data == 2)) | ||
1737 | { | ||
1738 | /* ssl3_read_bytes decided to call s->handshake_func, which | ||
1739 | * called ssl3_read_bytes to read handshake data. | ||
1740 | * However, ssl3_read_bytes actually found application data | ||
1741 | * and thinks that application data makes sense here; so disable | ||
1742 | * handshake processing and try to read application data again. */ | ||
1743 | s->in_handshake++; | ||
1744 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek); | ||
1745 | s->in_handshake--; | ||
1746 | } | ||
1747 | else | ||
1748 | s->s3->in_read_app_data=0; | ||
1749 | |||
1750 | return(ret); | ||
1751 | } | ||
1752 | |||
1753 | int ssl3_read(SSL *s, void *buf, int len) | ||
1754 | { | ||
1755 | return ssl3_read_internal(s, buf, len, 0); | ||
1756 | } | ||
1757 | |||
1758 | int ssl3_peek(SSL *s, void *buf, int len) | ||
1759 | { | ||
1760 | return ssl3_read_internal(s, buf, len, 1); | ||
1761 | } | ||
1762 | |||
1763 | int ssl3_renegotiate(SSL *s) | ||
1764 | { | ||
1765 | if (s->handshake_func == NULL) | ||
1766 | return(1); | ||
1767 | |||
1768 | if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) | ||
1769 | return(0); | ||
1770 | |||
1771 | s->s3->renegotiate=1; | ||
1772 | return(1); | ||
1773 | } | ||
1774 | |||
1775 | int ssl3_renegotiate_check(SSL *s) | ||
1776 | { | ||
1777 | int ret=0; | ||
1778 | |||
1779 | if (s->s3->renegotiate) | ||
1780 | { | ||
1781 | if ( (s->s3->rbuf.left == 0) && | ||
1782 | (s->s3->wbuf.left == 0) && | ||
1783 | !SSL_in_init(s)) | ||
1784 | { | ||
1785 | /* | ||
1786 | if we are the server, and we have sent a 'RENEGOTIATE' message, we | ||
1787 | need to go to SSL_ST_ACCEPT. | ||
1788 | */ | ||
1789 | /* SSL_ST_ACCEPT */ | ||
1790 | s->state=SSL_ST_RENEGOTIATE; | ||
1791 | s->s3->renegotiate=0; | ||
1792 | s->s3->num_renegotiations++; | ||
1793 | s->s3->total_renegotiations++; | ||
1794 | ret=1; | ||
1795 | } | ||
1796 | } | ||
1797 | return(ret); | ||
1798 | } | ||
1799 | |||
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c deleted file mode 100644 index cb0b12b400..0000000000 --- a/src/lib/libssl/s3_pkt.c +++ /dev/null | |||
@@ -1,1310 +0,0 @@ | |||
1 | /* ssl/s3_pkt.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include <errno.h> | ||
114 | #define USE_SOCKETS | ||
115 | #include "ssl_locl.h" | ||
116 | #include <openssl/evp.h> | ||
117 | #include <openssl/buffer.h> | ||
118 | |||
119 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | ||
120 | unsigned int len, int create_empty_fragment); | ||
121 | static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | ||
122 | unsigned int len); | ||
123 | static int ssl3_get_record(SSL *s); | ||
124 | static int do_compress(SSL *ssl); | ||
125 | static int do_uncompress(SSL *ssl); | ||
126 | static int do_change_cipher_spec(SSL *ssl); | ||
127 | |||
128 | /* used only by ssl3_get_record */ | ||
129 | static int ssl3_read_n(SSL *s, int n, int max, int extend) | ||
130 | { | ||
131 | /* If extend == 0, obtain new n-byte packet; if extend == 1, increase | ||
132 | * packet by another n bytes. | ||
133 | * The packet will be in the sub-array of s->s3->rbuf.buf specified | ||
134 | * by s->packet and s->packet_length. | ||
135 | * (If s->read_ahead is set, 'max' bytes may be stored in rbuf | ||
136 | * [plus s->packet_length bytes if extend == 1].) | ||
137 | */ | ||
138 | int i,off,newb; | ||
139 | |||
140 | if (!extend) | ||
141 | { | ||
142 | /* start with empty packet ... */ | ||
143 | if (s->s3->rbuf.left == 0) | ||
144 | s->s3->rbuf.offset = 0; | ||
145 | s->packet = s->s3->rbuf.buf + s->s3->rbuf.offset; | ||
146 | s->packet_length = 0; | ||
147 | /* ... now we can act as if 'extend' was set */ | ||
148 | } | ||
149 | |||
150 | /* if there is enough in the buffer from a previous read, take some */ | ||
151 | if (s->s3->rbuf.left >= (int)n) | ||
152 | { | ||
153 | s->packet_length+=n; | ||
154 | s->s3->rbuf.left-=n; | ||
155 | s->s3->rbuf.offset+=n; | ||
156 | return(n); | ||
157 | } | ||
158 | |||
159 | /* else we need to read more data */ | ||
160 | if (!s->read_ahead) | ||
161 | max=n; | ||
162 | |||
163 | { | ||
164 | /* avoid buffer overflow */ | ||
165 | int max_max = s->s3->rbuf.len - s->packet_length; | ||
166 | if (max > max_max) | ||
167 | max = max_max; | ||
168 | } | ||
169 | if (n > max) /* does not happen */ | ||
170 | { | ||
171 | SSLerr(SSL_F_SSL3_READ_N,ERR_R_INTERNAL_ERROR); | ||
172 | return -1; | ||
173 | } | ||
174 | |||
175 | off = s->packet_length; | ||
176 | newb = s->s3->rbuf.left; | ||
177 | /* Move any available bytes to front of buffer: | ||
178 | * 'off' bytes already pointed to by 'packet', | ||
179 | * 'newb' extra ones at the end */ | ||
180 | if (s->packet != s->s3->rbuf.buf) | ||
181 | { | ||
182 | /* off > 0 */ | ||
183 | memmove(s->s3->rbuf.buf, s->packet, off+newb); | ||
184 | s->packet = s->s3->rbuf.buf; | ||
185 | } | ||
186 | |||
187 | while (newb < n) | ||
188 | { | ||
189 | /* Now we have off+newb bytes at the front of s->s3->rbuf.buf and need | ||
190 | * to read in more until we have off+n (up to off+max if possible) */ | ||
191 | |||
192 | clear_sys_error(); | ||
193 | if (s->rbio != NULL) | ||
194 | { | ||
195 | s->rwstate=SSL_READING; | ||
196 | i=BIO_read(s->rbio, &(s->s3->rbuf.buf[off+newb]), max-newb); | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET); | ||
201 | i = -1; | ||
202 | } | ||
203 | |||
204 | if (i <= 0) | ||
205 | { | ||
206 | s->s3->rbuf.left = newb; | ||
207 | return(i); | ||
208 | } | ||
209 | newb+=i; | ||
210 | } | ||
211 | |||
212 | /* done reading, now the book-keeping */ | ||
213 | s->s3->rbuf.offset = off + n; | ||
214 | s->s3->rbuf.left = newb - n; | ||
215 | s->packet_length += n; | ||
216 | s->rwstate=SSL_NOTHING; | ||
217 | return(n); | ||
218 | } | ||
219 | |||
220 | /* Call this to get a new input record. | ||
221 | * It will return <= 0 if more data is needed, normally due to an error | ||
222 | * or non-blocking IO. | ||
223 | * When it finishes, one packet has been decoded and can be found in | ||
224 | * ssl->s3->rrec.type - is the type of record | ||
225 | * ssl->s3->rrec.data, - data | ||
226 | * ssl->s3->rrec.length, - number of bytes | ||
227 | */ | ||
228 | /* used only by ssl3_read_bytes */ | ||
229 | static int ssl3_get_record(SSL *s) | ||
230 | { | ||
231 | int ssl_major,ssl_minor,al; | ||
232 | int enc_err,n,i,ret= -1; | ||
233 | SSL3_RECORD *rr; | ||
234 | SSL_SESSION *sess; | ||
235 | unsigned char *p; | ||
236 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
237 | short version; | ||
238 | unsigned int mac_size; | ||
239 | int clear=0; | ||
240 | size_t extra; | ||
241 | int decryption_failed_or_bad_record_mac = 0; | ||
242 | unsigned char *mac = NULL; | ||
243 | |||
244 | rr= &(s->s3->rrec); | ||
245 | sess=s->session; | ||
246 | |||
247 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
248 | extra=SSL3_RT_MAX_EXTRA; | ||
249 | else | ||
250 | extra=0; | ||
251 | if (extra != s->s3->rbuf.len - SSL3_RT_MAX_PACKET_SIZE) | ||
252 | { | ||
253 | /* actually likely an application error: SLS_OP_MICROSOFT_BIG_SSLV3_BUFFER | ||
254 | * set after ssl3_setup_buffers() was done */ | ||
255 | SSLerr(SSL_F_SSL3_GET_RECORD, ERR_R_INTERNAL_ERROR); | ||
256 | return -1; | ||
257 | } | ||
258 | |||
259 | again: | ||
260 | /* check if we have the header */ | ||
261 | if ( (s->rstate != SSL_ST_READ_BODY) || | ||
262 | (s->packet_length < SSL3_RT_HEADER_LENGTH)) | ||
263 | { | ||
264 | n=ssl3_read_n(s, SSL3_RT_HEADER_LENGTH, s->s3->rbuf.len, 0); | ||
265 | if (n <= 0) return(n); /* error or non-blocking */ | ||
266 | s->rstate=SSL_ST_READ_BODY; | ||
267 | |||
268 | p=s->packet; | ||
269 | |||
270 | /* Pull apart the header into the SSL3_RECORD */ | ||
271 | rr->type= *(p++); | ||
272 | ssl_major= *(p++); | ||
273 | ssl_minor= *(p++); | ||
274 | version=(ssl_major<<8)|ssl_minor; | ||
275 | n2s(p,rr->length); | ||
276 | |||
277 | /* Lets check version */ | ||
278 | if (s->first_packet) | ||
279 | { | ||
280 | s->first_packet=0; | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | if (version != s->version) | ||
285 | { | ||
286 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
287 | /* Send back error using their | ||
288 | * version number :-) */ | ||
289 | s->version=version; | ||
290 | al=SSL_AD_PROTOCOL_VERSION; | ||
291 | goto f_err; | ||
292 | } | ||
293 | } | ||
294 | |||
295 | if ((version>>8) != SSL3_VERSION_MAJOR) | ||
296 | { | ||
297 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
298 | goto err; | ||
299 | } | ||
300 | |||
301 | if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
302 | { | ||
303 | al=SSL_AD_RECORD_OVERFLOW; | ||
304 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG); | ||
305 | goto f_err; | ||
306 | } | ||
307 | |||
308 | /* now s->rstate == SSL_ST_READ_BODY */ | ||
309 | } | ||
310 | |||
311 | /* s->rstate == SSL_ST_READ_BODY, get and decode the data */ | ||
312 | |||
313 | if (rr->length > s->packet_length-SSL3_RT_HEADER_LENGTH) | ||
314 | { | ||
315 | /* now s->packet_length == SSL3_RT_HEADER_LENGTH */ | ||
316 | i=rr->length; | ||
317 | n=ssl3_read_n(s,i,i,1); | ||
318 | if (n <= 0) return(n); /* error or non-blocking io */ | ||
319 | /* now n == rr->length, | ||
320 | * and s->packet_length == SSL3_RT_HEADER_LENGTH + rr->length */ | ||
321 | } | ||
322 | |||
323 | s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */ | ||
324 | |||
325 | /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length, | ||
326 | * and we have that many bytes in s->packet | ||
327 | */ | ||
328 | rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]); | ||
329 | |||
330 | /* ok, we can now read from 's->packet' data into 'rr' | ||
331 | * rr->input points at rr->length bytes, which | ||
332 | * need to be copied into rr->data by either | ||
333 | * the decryption or by the decompression | ||
334 | * When the data is 'copied' into the rr->data buffer, | ||
335 | * rr->input will be pointed at the new buffer */ | ||
336 | |||
337 | /* We now have - encrypted [ MAC [ compressed [ plain ] ] ] | ||
338 | * rr->length bytes of encrypted compressed stuff. */ | ||
339 | |||
340 | /* check is not needed I believe */ | ||
341 | if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
342 | { | ||
343 | al=SSL_AD_RECORD_OVERFLOW; | ||
344 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG); | ||
345 | goto f_err; | ||
346 | } | ||
347 | |||
348 | /* decrypt in place in 'rr->input' */ | ||
349 | rr->data=rr->input; | ||
350 | |||
351 | enc_err = s->method->ssl3_enc->enc(s,0); | ||
352 | if (enc_err <= 0) | ||
353 | { | ||
354 | if (enc_err == 0) | ||
355 | /* SSLerr() and ssl3_send_alert() have been called */ | ||
356 | goto err; | ||
357 | |||
358 | /* Otherwise enc_err == -1, which indicates bad padding | ||
359 | * (rec->length has not been changed in this case). | ||
360 | * To minimize information leaked via timing, we will perform | ||
361 | * the MAC computation anyway. */ | ||
362 | decryption_failed_or_bad_record_mac = 1; | ||
363 | } | ||
364 | |||
365 | #ifdef TLS_DEBUG | ||
366 | printf("dec %d\n",rr->length); | ||
367 | { unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); } | ||
368 | printf("\n"); | ||
369 | #endif | ||
370 | |||
371 | /* r->length is now the compressed data plus mac */ | ||
372 | if ( (sess == NULL) || | ||
373 | (s->enc_read_ctx == NULL) || | ||
374 | (s->read_hash == NULL)) | ||
375 | clear=1; | ||
376 | |||
377 | if (!clear) | ||
378 | { | ||
379 | mac_size=EVP_MD_size(s->read_hash); | ||
380 | |||
381 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size) | ||
382 | { | ||
383 | #if 0 /* OK only for stream ciphers (then rr->length is visible from ciphertext anyway) */ | ||
384 | al=SSL_AD_RECORD_OVERFLOW; | ||
385 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); | ||
386 | goto f_err; | ||
387 | #else | ||
388 | decryption_failed_or_bad_record_mac = 1; | ||
389 | #endif | ||
390 | } | ||
391 | /* check the MAC for rr->input (it's in mac_size bytes at the tail) */ | ||
392 | if (rr->length >= mac_size) | ||
393 | { | ||
394 | rr->length -= mac_size; | ||
395 | mac = &rr->data[rr->length]; | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | /* record (minus padding) is too short to contain a MAC */ | ||
400 | #if 0 /* OK only for stream ciphers */ | ||
401 | al=SSL_AD_DECODE_ERROR; | ||
402 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT); | ||
403 | goto f_err; | ||
404 | #else | ||
405 | decryption_failed_or_bad_record_mac = 1; | ||
406 | rr->length = 0; | ||
407 | #endif | ||
408 | } | ||
409 | i=s->method->ssl3_enc->mac(s,md,0); | ||
410 | if (mac == NULL || memcmp(md, mac, mac_size) != 0) | ||
411 | { | ||
412 | decryption_failed_or_bad_record_mac = 1; | ||
413 | } | ||
414 | } | ||
415 | |||
416 | if (decryption_failed_or_bad_record_mac) | ||
417 | { | ||
418 | /* A separate 'decryption_failed' alert was introduced with TLS 1.0, | ||
419 | * SSL 3.0 only has 'bad_record_mac'. But unless a decryption | ||
420 | * failure is directly visible from the ciphertext anyway, | ||
421 | * we should not reveal which kind of error occured -- this | ||
422 | * might become visible to an attacker (e.g. via a logfile) */ | ||
423 | al=SSL_AD_BAD_RECORD_MAC; | ||
424 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); | ||
425 | goto f_err; | ||
426 | } | ||
427 | |||
428 | /* r->length is now just compressed */ | ||
429 | if (s->expand != NULL) | ||
430 | { | ||
431 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra) | ||
432 | { | ||
433 | al=SSL_AD_RECORD_OVERFLOW; | ||
434 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); | ||
435 | goto f_err; | ||
436 | } | ||
437 | if (!do_uncompress(s)) | ||
438 | { | ||
439 | al=SSL_AD_DECOMPRESSION_FAILURE; | ||
440 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION); | ||
441 | goto f_err; | ||
442 | } | ||
443 | } | ||
444 | |||
445 | if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH+extra) | ||
446 | { | ||
447 | al=SSL_AD_RECORD_OVERFLOW; | ||
448 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG); | ||
449 | goto f_err; | ||
450 | } | ||
451 | |||
452 | rr->off=0; | ||
453 | /* So at this point the following is true | ||
454 | * ssl->s3->rrec.type is the type of record | ||
455 | * ssl->s3->rrec.length == number of bytes in record | ||
456 | * ssl->s3->rrec.off == offset to first valid byte | ||
457 | * ssl->s3->rrec.data == where to take bytes from, increment | ||
458 | * after use :-). | ||
459 | */ | ||
460 | |||
461 | /* we have pulled in a full packet so zero things */ | ||
462 | s->packet_length=0; | ||
463 | |||
464 | /* just read a 0 length packet */ | ||
465 | if (rr->length == 0) goto again; | ||
466 | |||
467 | return(1); | ||
468 | |||
469 | f_err: | ||
470 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
471 | err: | ||
472 | return(ret); | ||
473 | } | ||
474 | |||
475 | static int do_uncompress(SSL *ssl) | ||
476 | { | ||
477 | int i; | ||
478 | SSL3_RECORD *rr; | ||
479 | |||
480 | rr= &(ssl->s3->rrec); | ||
481 | i=COMP_expand_block(ssl->expand,rr->comp, | ||
482 | SSL3_RT_MAX_PLAIN_LENGTH,rr->data,(int)rr->length); | ||
483 | if (i < 0) | ||
484 | return(0); | ||
485 | else | ||
486 | rr->length=i; | ||
487 | rr->data=rr->comp; | ||
488 | |||
489 | return(1); | ||
490 | } | ||
491 | |||
492 | static int do_compress(SSL *ssl) | ||
493 | { | ||
494 | int i; | ||
495 | SSL3_RECORD *wr; | ||
496 | |||
497 | wr= &(ssl->s3->wrec); | ||
498 | i=COMP_compress_block(ssl->compress,wr->data, | ||
499 | SSL3_RT_MAX_COMPRESSED_LENGTH, | ||
500 | wr->input,(int)wr->length); | ||
501 | if (i < 0) | ||
502 | return(0); | ||
503 | else | ||
504 | wr->length=i; | ||
505 | |||
506 | wr->input=wr->data; | ||
507 | return(1); | ||
508 | } | ||
509 | |||
510 | /* Call this to write data in records of type 'type' | ||
511 | * It will return <= 0 if not all data has been sent or non-blocking IO. | ||
512 | */ | ||
513 | int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len) | ||
514 | { | ||
515 | const unsigned char *buf=buf_; | ||
516 | unsigned int tot,n,nw; | ||
517 | int i; | ||
518 | |||
519 | s->rwstate=SSL_NOTHING; | ||
520 | tot=s->s3->wnum; | ||
521 | s->s3->wnum=0; | ||
522 | |||
523 | if (SSL_in_init(s) && !s->in_handshake) | ||
524 | { | ||
525 | i=s->handshake_func(s); | ||
526 | if (i < 0) return(i); | ||
527 | if (i == 0) | ||
528 | { | ||
529 | SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
530 | return -1; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | n=(len-tot); | ||
535 | for (;;) | ||
536 | { | ||
537 | if (n > SSL3_RT_MAX_PLAIN_LENGTH) | ||
538 | nw=SSL3_RT_MAX_PLAIN_LENGTH; | ||
539 | else | ||
540 | nw=n; | ||
541 | |||
542 | i=do_ssl3_write(s, type, &(buf[tot]), nw, 0); | ||
543 | if (i <= 0) | ||
544 | { | ||
545 | s->s3->wnum=tot; | ||
546 | return i; | ||
547 | } | ||
548 | |||
549 | if ((i == (int)n) || | ||
550 | (type == SSL3_RT_APPLICATION_DATA && | ||
551 | (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE))) | ||
552 | { | ||
553 | /* next chunk of data should get another prepended empty fragment | ||
554 | * in ciphersuites with known-IV weakness: */ | ||
555 | s->s3->empty_fragment_done = 0; | ||
556 | |||
557 | return tot+i; | ||
558 | } | ||
559 | |||
560 | n-=i; | ||
561 | tot+=i; | ||
562 | } | ||
563 | } | ||
564 | |||
565 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | ||
566 | unsigned int len, int create_empty_fragment) | ||
567 | { | ||
568 | unsigned char *p,*plen; | ||
569 | int i,mac_size,clear=0; | ||
570 | int prefix_len = 0; | ||
571 | SSL3_RECORD *wr; | ||
572 | SSL3_BUFFER *wb; | ||
573 | SSL_SESSION *sess; | ||
574 | |||
575 | /* first check if there is a SSL3_BUFFER still being written | ||
576 | * out. This will happen with non blocking IO */ | ||
577 | if (s->s3->wbuf.left != 0) | ||
578 | return(ssl3_write_pending(s,type,buf,len)); | ||
579 | |||
580 | /* If we have an alert to send, lets send it */ | ||
581 | if (s->s3->alert_dispatch) | ||
582 | { | ||
583 | i=ssl3_dispatch_alert(s); | ||
584 | if (i <= 0) | ||
585 | return(i); | ||
586 | /* if it went, fall through and send more stuff */ | ||
587 | } | ||
588 | |||
589 | if (len == 0 && !create_empty_fragment) | ||
590 | return 0; | ||
591 | |||
592 | wr= &(s->s3->wrec); | ||
593 | wb= &(s->s3->wbuf); | ||
594 | sess=s->session; | ||
595 | |||
596 | if ( (sess == NULL) || | ||
597 | (s->enc_write_ctx == NULL) || | ||
598 | (s->write_hash == NULL)) | ||
599 | clear=1; | ||
600 | |||
601 | if (clear) | ||
602 | mac_size=0; | ||
603 | else | ||
604 | mac_size=EVP_MD_size(s->write_hash); | ||
605 | |||
606 | /* 'create_empty_fragment' is true only when this function calls itself */ | ||
607 | if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done) | ||
608 | { | ||
609 | /* countermeasure against known-IV weakness in CBC ciphersuites | ||
610 | * (see http://www.openssl.org/~bodo/tls-cbc.txt) */ | ||
611 | |||
612 | if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA) | ||
613 | { | ||
614 | /* recursive function call with 'create_empty_fragment' set; | ||
615 | * this prepares and buffers the data for an empty fragment | ||
616 | * (these 'prefix_len' bytes are sent out later | ||
617 | * together with the actual payload) */ | ||
618 | prefix_len = do_ssl3_write(s, type, buf, 0, 1); | ||
619 | if (prefix_len <= 0) | ||
620 | goto err; | ||
621 | |||
622 | if (s->s3->wbuf.len < (size_t)prefix_len + SSL3_RT_MAX_PACKET_SIZE) | ||
623 | { | ||
624 | /* insufficient space */ | ||
625 | SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR); | ||
626 | goto err; | ||
627 | } | ||
628 | } | ||
629 | |||
630 | s->s3->empty_fragment_done = 1; | ||
631 | } | ||
632 | |||
633 | p = wb->buf + prefix_len; | ||
634 | |||
635 | /* write the header */ | ||
636 | |||
637 | *(p++)=type&0xff; | ||
638 | wr->type=type; | ||
639 | |||
640 | *(p++)=(s->version>>8); | ||
641 | *(p++)=s->version&0xff; | ||
642 | |||
643 | /* field where we are to write out packet length */ | ||
644 | plen=p; | ||
645 | p+=2; | ||
646 | |||
647 | /* lets setup the record stuff. */ | ||
648 | wr->data=p; | ||
649 | wr->length=(int)len; | ||
650 | wr->input=(unsigned char *)buf; | ||
651 | |||
652 | /* we now 'read' from wr->input, wr->length bytes into | ||
653 | * wr->data */ | ||
654 | |||
655 | /* first we compress */ | ||
656 | if (s->compress != NULL) | ||
657 | { | ||
658 | if (!do_compress(s)) | ||
659 | { | ||
660 | SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE); | ||
661 | goto err; | ||
662 | } | ||
663 | } | ||
664 | else | ||
665 | { | ||
666 | memcpy(wr->data,wr->input,wr->length); | ||
667 | wr->input=wr->data; | ||
668 | } | ||
669 | |||
670 | /* we should still have the output to wr->data and the input | ||
671 | * from wr->input. Length should be wr->length. | ||
672 | * wr->data still points in the wb->buf */ | ||
673 | |||
674 | if (mac_size != 0) | ||
675 | { | ||
676 | s->method->ssl3_enc->mac(s,&(p[wr->length]),1); | ||
677 | wr->length+=mac_size; | ||
678 | wr->input=p; | ||
679 | wr->data=p; | ||
680 | } | ||
681 | |||
682 | /* ssl3_enc can only have an error on read */ | ||
683 | s->method->ssl3_enc->enc(s,1); | ||
684 | |||
685 | /* record length after mac and block padding */ | ||
686 | s2n(wr->length,plen); | ||
687 | |||
688 | /* we should now have | ||
689 | * wr->data pointing to the encrypted data, which is | ||
690 | * wr->length long */ | ||
691 | wr->type=type; /* not needed but helps for debugging */ | ||
692 | wr->length+=SSL3_RT_HEADER_LENGTH; | ||
693 | |||
694 | if (create_empty_fragment) | ||
695 | { | ||
696 | /* we are in a recursive call; | ||
697 | * just return the length, don't write out anything here | ||
698 | */ | ||
699 | return wr->length; | ||
700 | } | ||
701 | |||
702 | /* now let's set up wb */ | ||
703 | wb->left = prefix_len + wr->length; | ||
704 | wb->offset = 0; | ||
705 | |||
706 | /* memorize arguments so that ssl3_write_pending can detect bad write retries later */ | ||
707 | s->s3->wpend_tot=len; | ||
708 | s->s3->wpend_buf=buf; | ||
709 | s->s3->wpend_type=type; | ||
710 | s->s3->wpend_ret=len; | ||
711 | |||
712 | /* we now just need to write the buffer */ | ||
713 | return ssl3_write_pending(s,type,buf,len); | ||
714 | err: | ||
715 | return -1; | ||
716 | } | ||
717 | |||
718 | /* if s->s3->wbuf.left != 0, we need to call this */ | ||
719 | static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | ||
720 | unsigned int len) | ||
721 | { | ||
722 | int i; | ||
723 | |||
724 | /* XXXX */ | ||
725 | if ((s->s3->wpend_tot > (int)len) | ||
726 | || ((s->s3->wpend_buf != buf) && | ||
727 | !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)) | ||
728 | || (s->s3->wpend_type != type)) | ||
729 | { | ||
730 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY); | ||
731 | return(-1); | ||
732 | } | ||
733 | |||
734 | for (;;) | ||
735 | { | ||
736 | clear_sys_error(); | ||
737 | if (s->wbio != NULL) | ||
738 | { | ||
739 | s->rwstate=SSL_WRITING; | ||
740 | i=BIO_write(s->wbio, | ||
741 | (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]), | ||
742 | (unsigned int)s->s3->wbuf.left); | ||
743 | } | ||
744 | else | ||
745 | { | ||
746 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET); | ||
747 | i= -1; | ||
748 | } | ||
749 | if (i == s->s3->wbuf.left) | ||
750 | { | ||
751 | s->s3->wbuf.left=0; | ||
752 | s->rwstate=SSL_NOTHING; | ||
753 | return(s->s3->wpend_ret); | ||
754 | } | ||
755 | else if (i <= 0) | ||
756 | return(i); | ||
757 | s->s3->wbuf.offset+=i; | ||
758 | s->s3->wbuf.left-=i; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | /* Return up to 'len' payload bytes received in 'type' records. | ||
763 | * 'type' is one of the following: | ||
764 | * | ||
765 | * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us) | ||
766 | * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us) | ||
767 | * - 0 (during a shutdown, no data has to be returned) | ||
768 | * | ||
769 | * If we don't have stored data to work from, read a SSL/TLS record first | ||
770 | * (possibly multiple records if we still don't have anything to return). | ||
771 | * | ||
772 | * This function must handle any surprises the peer may have for us, such as | ||
773 | * Alert records (e.g. close_notify), ChangeCipherSpec records (not really | ||
774 | * a surprise, but handled as if it were), or renegotiation requests. | ||
775 | * Also if record payloads contain fragments too small to process, we store | ||
776 | * them until there is enough for the respective protocol (the record protocol | ||
777 | * may use arbitrary fragmentation and even interleaving): | ||
778 | * Change cipher spec protocol | ||
779 | * just 1 byte needed, no need for keeping anything stored | ||
780 | * Alert protocol | ||
781 | * 2 bytes needed (AlertLevel, AlertDescription) | ||
782 | * Handshake protocol | ||
783 | * 4 bytes needed (HandshakeType, uint24 length) -- we just have | ||
784 | * to detect unexpected Client Hello and Hello Request messages | ||
785 | * here, anything else is handled by higher layers | ||
786 | * Application data protocol | ||
787 | * none of our business | ||
788 | */ | ||
789 | int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) | ||
790 | { | ||
791 | int al,i,j,ret; | ||
792 | unsigned int n; | ||
793 | SSL3_RECORD *rr; | ||
794 | void (*cb)(const SSL *ssl,int type2,int val)=NULL; | ||
795 | |||
796 | if (s->s3->rbuf.buf == NULL) /* Not initialized yet */ | ||
797 | if (!ssl3_setup_buffers(s)) | ||
798 | return(-1); | ||
799 | |||
800 | if ((type && (type != SSL3_RT_APPLICATION_DATA) && (type != SSL3_RT_HANDSHAKE) && type) || | ||
801 | (peek && (type != SSL3_RT_APPLICATION_DATA))) | ||
802 | { | ||
803 | SSLerr(SSL_F_SSL3_READ_BYTES, ERR_R_INTERNAL_ERROR); | ||
804 | return -1; | ||
805 | } | ||
806 | |||
807 | if ((type == SSL3_RT_HANDSHAKE) && (s->s3->handshake_fragment_len > 0)) | ||
808 | /* (partially) satisfy request from storage */ | ||
809 | { | ||
810 | unsigned char *src = s->s3->handshake_fragment; | ||
811 | unsigned char *dst = buf; | ||
812 | unsigned int k; | ||
813 | |||
814 | /* peek == 0 */ | ||
815 | n = 0; | ||
816 | while ((len > 0) && (s->s3->handshake_fragment_len > 0)) | ||
817 | { | ||
818 | *dst++ = *src++; | ||
819 | len--; s->s3->handshake_fragment_len--; | ||
820 | n++; | ||
821 | } | ||
822 | /* move any remaining fragment bytes: */ | ||
823 | for (k = 0; k < s->s3->handshake_fragment_len; k++) | ||
824 | s->s3->handshake_fragment[k] = *src++; | ||
825 | return n; | ||
826 | } | ||
827 | |||
828 | /* Now s->s3->handshake_fragment_len == 0 if type == SSL3_RT_HANDSHAKE. */ | ||
829 | |||
830 | if (!s->in_handshake && SSL_in_init(s)) | ||
831 | { | ||
832 | /* type == SSL3_RT_APPLICATION_DATA */ | ||
833 | i=s->handshake_func(s); | ||
834 | if (i < 0) return(i); | ||
835 | if (i == 0) | ||
836 | { | ||
837 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
838 | return(-1); | ||
839 | } | ||
840 | } | ||
841 | start: | ||
842 | s->rwstate=SSL_NOTHING; | ||
843 | |||
844 | /* s->s3->rrec.type - is the type of record | ||
845 | * s->s3->rrec.data, - data | ||
846 | * s->s3->rrec.off, - offset into 'data' for next read | ||
847 | * s->s3->rrec.length, - number of bytes. */ | ||
848 | rr = &(s->s3->rrec); | ||
849 | |||
850 | /* get new packet if necessary */ | ||
851 | if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) | ||
852 | { | ||
853 | ret=ssl3_get_record(s); | ||
854 | if (ret <= 0) return(ret); | ||
855 | } | ||
856 | |||
857 | /* we now have a packet which can be read and processed */ | ||
858 | |||
859 | if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec, | ||
860 | * reset by ssl3_get_finished */ | ||
861 | && (rr->type != SSL3_RT_HANDSHAKE)) | ||
862 | { | ||
863 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
864 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED); | ||
865 | goto f_err; | ||
866 | } | ||
867 | |||
868 | /* If the other end has shut down, throw anything we read away | ||
869 | * (even in 'peek' mode) */ | ||
870 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
871 | { | ||
872 | rr->length=0; | ||
873 | s->rwstate=SSL_NOTHING; | ||
874 | return(0); | ||
875 | } | ||
876 | |||
877 | |||
878 | if (type == rr->type) /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */ | ||
879 | { | ||
880 | /* make sure that we are not getting application data when we | ||
881 | * are doing a handshake for the first time */ | ||
882 | if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) && | ||
883 | (s->enc_read_ctx == NULL)) | ||
884 | { | ||
885 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
886 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE); | ||
887 | goto f_err; | ||
888 | } | ||
889 | |||
890 | if (len <= 0) return(len); | ||
891 | |||
892 | if ((unsigned int)len > rr->length) | ||
893 | n = rr->length; | ||
894 | else | ||
895 | n = (unsigned int)len; | ||
896 | |||
897 | memcpy(buf,&(rr->data[rr->off]),n); | ||
898 | if (!peek) | ||
899 | { | ||
900 | rr->length-=n; | ||
901 | rr->off+=n; | ||
902 | if (rr->length == 0) | ||
903 | { | ||
904 | s->rstate=SSL_ST_READ_HEADER; | ||
905 | rr->off=0; | ||
906 | } | ||
907 | } | ||
908 | return(n); | ||
909 | } | ||
910 | |||
911 | |||
912 | /* If we get here, then type != rr->type; if we have a handshake | ||
913 | * message, then it was unexpected (Hello Request or Client Hello). */ | ||
914 | |||
915 | /* In case of record types for which we have 'fragment' storage, | ||
916 | * fill that so that we can process the data at a fixed place. | ||
917 | */ | ||
918 | { | ||
919 | unsigned int dest_maxlen = 0; | ||
920 | unsigned char *dest = NULL; | ||
921 | unsigned int *dest_len = NULL; | ||
922 | |||
923 | if (rr->type == SSL3_RT_HANDSHAKE) | ||
924 | { | ||
925 | dest_maxlen = sizeof s->s3->handshake_fragment; | ||
926 | dest = s->s3->handshake_fragment; | ||
927 | dest_len = &s->s3->handshake_fragment_len; | ||
928 | } | ||
929 | else if (rr->type == SSL3_RT_ALERT) | ||
930 | { | ||
931 | dest_maxlen = sizeof s->s3->alert_fragment; | ||
932 | dest = s->s3->alert_fragment; | ||
933 | dest_len = &s->s3->alert_fragment_len; | ||
934 | } | ||
935 | |||
936 | if (dest_maxlen > 0) | ||
937 | { | ||
938 | n = dest_maxlen - *dest_len; /* available space in 'dest' */ | ||
939 | if (rr->length < n) | ||
940 | n = rr->length; /* available bytes */ | ||
941 | |||
942 | /* now move 'n' bytes: */ | ||
943 | while (n-- > 0) | ||
944 | { | ||
945 | dest[(*dest_len)++] = rr->data[rr->off++]; | ||
946 | rr->length--; | ||
947 | } | ||
948 | |||
949 | if (*dest_len < dest_maxlen) | ||
950 | goto start; /* fragment was too small */ | ||
951 | } | ||
952 | } | ||
953 | |||
954 | /* s->s3->handshake_fragment_len == 4 iff rr->type == SSL3_RT_HANDSHAKE; | ||
955 | * s->s3->alert_fragment_len == 2 iff rr->type == SSL3_RT_ALERT. | ||
956 | * (Possibly rr is 'empty' now, i.e. rr->length may be 0.) */ | ||
957 | |||
958 | /* If we are a client, check for an incoming 'Hello Request': */ | ||
959 | if ((!s->server) && | ||
960 | (s->s3->handshake_fragment_len >= 4) && | ||
961 | (s->s3->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) && | ||
962 | (s->session != NULL) && (s->session->cipher != NULL)) | ||
963 | { | ||
964 | s->s3->handshake_fragment_len = 0; | ||
965 | |||
966 | if ((s->s3->handshake_fragment[1] != 0) || | ||
967 | (s->s3->handshake_fragment[2] != 0) || | ||
968 | (s->s3->handshake_fragment[3] != 0)) | ||
969 | { | ||
970 | al=SSL_AD_DECODE_ERROR; | ||
971 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_HELLO_REQUEST); | ||
972 | goto f_err; | ||
973 | } | ||
974 | |||
975 | if (s->msg_callback) | ||
976 | s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->s3->handshake_fragment, 4, s, s->msg_callback_arg); | ||
977 | |||
978 | if (SSL_is_init_finished(s) && | ||
979 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | ||
980 | !s->s3->renegotiate) | ||
981 | { | ||
982 | ssl3_renegotiate(s); | ||
983 | if (ssl3_renegotiate_check(s)) | ||
984 | { | ||
985 | i=s->handshake_func(s); | ||
986 | if (i < 0) return(i); | ||
987 | if (i == 0) | ||
988 | { | ||
989 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
990 | return(-1); | ||
991 | } | ||
992 | |||
993 | if (!(s->mode & SSL_MODE_AUTO_RETRY)) | ||
994 | { | ||
995 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
996 | { | ||
997 | BIO *bio; | ||
998 | /* In the case where we try to read application data, | ||
999 | * but we trigger an SSL handshake, we return -1 with | ||
1000 | * the retry option set. Otherwise renegotiation may | ||
1001 | * cause nasty problems in the blocking world */ | ||
1002 | s->rwstate=SSL_READING; | ||
1003 | bio=SSL_get_rbio(s); | ||
1004 | BIO_clear_retry_flags(bio); | ||
1005 | BIO_set_retry_read(bio); | ||
1006 | return(-1); | ||
1007 | } | ||
1008 | } | ||
1009 | } | ||
1010 | } | ||
1011 | /* we either finished a handshake or ignored the request, | ||
1012 | * now try again to obtain the (application) data we were asked for */ | ||
1013 | goto start; | ||
1014 | } | ||
1015 | |||
1016 | if (s->s3->alert_fragment_len >= 2) | ||
1017 | { | ||
1018 | int alert_level = s->s3->alert_fragment[0]; | ||
1019 | int alert_descr = s->s3->alert_fragment[1]; | ||
1020 | |||
1021 | s->s3->alert_fragment_len = 0; | ||
1022 | |||
1023 | if (s->msg_callback) | ||
1024 | s->msg_callback(0, s->version, SSL3_RT_ALERT, s->s3->alert_fragment, 2, s, s->msg_callback_arg); | ||
1025 | |||
1026 | if (s->info_callback != NULL) | ||
1027 | cb=s->info_callback; | ||
1028 | else if (s->ctx->info_callback != NULL) | ||
1029 | cb=s->ctx->info_callback; | ||
1030 | |||
1031 | if (cb != NULL) | ||
1032 | { | ||
1033 | j = (alert_level << 8) | alert_descr; | ||
1034 | cb(s, SSL_CB_READ_ALERT, j); | ||
1035 | } | ||
1036 | |||
1037 | if (alert_level == 1) /* warning */ | ||
1038 | { | ||
1039 | s->s3->warn_alert = alert_descr; | ||
1040 | if (alert_descr == SSL_AD_CLOSE_NOTIFY) | ||
1041 | { | ||
1042 | s->shutdown |= SSL_RECEIVED_SHUTDOWN; | ||
1043 | return(0); | ||
1044 | } | ||
1045 | } | ||
1046 | else if (alert_level == 2) /* fatal */ | ||
1047 | { | ||
1048 | char tmp[16]; | ||
1049 | |||
1050 | s->rwstate=SSL_NOTHING; | ||
1051 | s->s3->fatal_alert = alert_descr; | ||
1052 | SSLerr(SSL_F_SSL3_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr); | ||
1053 | BIO_snprintf(tmp,sizeof tmp,"%d",alert_descr); | ||
1054 | ERR_add_error_data(2,"SSL alert number ",tmp); | ||
1055 | s->shutdown|=SSL_RECEIVED_SHUTDOWN; | ||
1056 | SSL_CTX_remove_session(s->ctx,s->session); | ||
1057 | return(0); | ||
1058 | } | ||
1059 | else | ||
1060 | { | ||
1061 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1062 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE); | ||
1063 | goto f_err; | ||
1064 | } | ||
1065 | |||
1066 | goto start; | ||
1067 | } | ||
1068 | |||
1069 | if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */ | ||
1070 | { | ||
1071 | s->rwstate=SSL_NOTHING; | ||
1072 | rr->length=0; | ||
1073 | return(0); | ||
1074 | } | ||
1075 | |||
1076 | if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
1077 | { | ||
1078 | /* 'Change Cipher Spec' is just a single byte, so we know | ||
1079 | * exactly what the record payload has to look like */ | ||
1080 | if ( (rr->length != 1) || (rr->off != 0) || | ||
1081 | (rr->data[0] != SSL3_MT_CCS)) | ||
1082 | { | ||
1083 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1084 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC); | ||
1085 | goto f_err; | ||
1086 | } | ||
1087 | |||
1088 | /* Check we have a cipher to change to */ | ||
1089 | if (s->s3->tmp.new_cipher == NULL) | ||
1090 | { | ||
1091 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1092 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY); | ||
1093 | goto f_err; | ||
1094 | } | ||
1095 | |||
1096 | rr->length=0; | ||
1097 | |||
1098 | if (s->msg_callback) | ||
1099 | s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC, rr->data, 1, s, s->msg_callback_arg); | ||
1100 | |||
1101 | s->s3->change_cipher_spec=1; | ||
1102 | if (!do_change_cipher_spec(s)) | ||
1103 | goto err; | ||
1104 | else | ||
1105 | goto start; | ||
1106 | } | ||
1107 | |||
1108 | /* Unexpected handshake message (Client Hello, or protocol violation) */ | ||
1109 | if ((s->s3->handshake_fragment_len >= 4) && !s->in_handshake) | ||
1110 | { | ||
1111 | if (((s->state&SSL_ST_MASK) == SSL_ST_OK) && | ||
1112 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) | ||
1113 | { | ||
1114 | #if 0 /* worked only because C operator preferences are not as expected (and | ||
1115 | * because this is not really needed for clients except for detecting | ||
1116 | * protocol violations): */ | ||
1117 | s->state=SSL_ST_BEFORE|(s->server) | ||
1118 | ?SSL_ST_ACCEPT | ||
1119 | :SSL_ST_CONNECT; | ||
1120 | #else | ||
1121 | s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT; | ||
1122 | #endif | ||
1123 | s->new_session=1; | ||
1124 | } | ||
1125 | i=s->handshake_func(s); | ||
1126 | if (i < 0) return(i); | ||
1127 | if (i == 0) | ||
1128 | { | ||
1129 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
1130 | return(-1); | ||
1131 | } | ||
1132 | |||
1133 | if (!(s->mode & SSL_MODE_AUTO_RETRY)) | ||
1134 | { | ||
1135 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
1136 | { | ||
1137 | BIO *bio; | ||
1138 | /* In the case where we try to read application data, | ||
1139 | * but we trigger an SSL handshake, we return -1 with | ||
1140 | * the retry option set. Otherwise renegotiation may | ||
1141 | * cause nasty problems in the blocking world */ | ||
1142 | s->rwstate=SSL_READING; | ||
1143 | bio=SSL_get_rbio(s); | ||
1144 | BIO_clear_retry_flags(bio); | ||
1145 | BIO_set_retry_read(bio); | ||
1146 | return(-1); | ||
1147 | } | ||
1148 | } | ||
1149 | goto start; | ||
1150 | } | ||
1151 | |||
1152 | switch (rr->type) | ||
1153 | { | ||
1154 | default: | ||
1155 | #ifndef OPENSSL_NO_TLS | ||
1156 | /* TLS just ignores unknown message types */ | ||
1157 | if (s->version == TLS1_VERSION) | ||
1158 | { | ||
1159 | rr->length = 0; | ||
1160 | goto start; | ||
1161 | } | ||
1162 | #endif | ||
1163 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1164 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
1165 | goto f_err; | ||
1166 | case SSL3_RT_CHANGE_CIPHER_SPEC: | ||
1167 | case SSL3_RT_ALERT: | ||
1168 | case SSL3_RT_HANDSHAKE: | ||
1169 | /* we already handled all of these, with the possible exception | ||
1170 | * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that | ||
1171 | * should not happen when type != rr->type */ | ||
1172 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1173 | SSLerr(SSL_F_SSL3_READ_BYTES,ERR_R_INTERNAL_ERROR); | ||
1174 | goto f_err; | ||
1175 | case SSL3_RT_APPLICATION_DATA: | ||
1176 | /* At this point, we were expecting handshake data, | ||
1177 | * but have application data. If the library was | ||
1178 | * running inside ssl3_read() (i.e. in_read_app_data | ||
1179 | * is set) and it makes sense to read application data | ||
1180 | * at this point (session renegotiation not yet started), | ||
1181 | * we will indulge it. | ||
1182 | */ | ||
1183 | if (s->s3->in_read_app_data && | ||
1184 | (s->s3->total_renegotiations != 0) && | ||
1185 | (( | ||
1186 | (s->state & SSL_ST_CONNECT) && | ||
1187 | (s->state >= SSL3_ST_CW_CLNT_HELLO_A) && | ||
1188 | (s->state <= SSL3_ST_CR_SRVR_HELLO_A) | ||
1189 | ) || ( | ||
1190 | (s->state & SSL_ST_ACCEPT) && | ||
1191 | (s->state <= SSL3_ST_SW_HELLO_REQ_A) && | ||
1192 | (s->state >= SSL3_ST_SR_CLNT_HELLO_A) | ||
1193 | ) | ||
1194 | )) | ||
1195 | { | ||
1196 | s->s3->in_read_app_data=2; | ||
1197 | return(-1); | ||
1198 | } | ||
1199 | else | ||
1200 | { | ||
1201 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1202 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
1203 | goto f_err; | ||
1204 | } | ||
1205 | } | ||
1206 | /* not reached */ | ||
1207 | |||
1208 | f_err: | ||
1209 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1210 | err: | ||
1211 | return(-1); | ||
1212 | } | ||
1213 | |||
1214 | static int do_change_cipher_spec(SSL *s) | ||
1215 | { | ||
1216 | int i; | ||
1217 | const char *sender; | ||
1218 | int slen; | ||
1219 | |||
1220 | if (s->state & SSL_ST_ACCEPT) | ||
1221 | i=SSL3_CHANGE_CIPHER_SERVER_READ; | ||
1222 | else | ||
1223 | i=SSL3_CHANGE_CIPHER_CLIENT_READ; | ||
1224 | |||
1225 | if (s->s3->tmp.key_block == NULL) | ||
1226 | { | ||
1227 | s->session->cipher=s->s3->tmp.new_cipher; | ||
1228 | if (!s->method->ssl3_enc->setup_key_block(s)) return(0); | ||
1229 | } | ||
1230 | |||
1231 | if (!s->method->ssl3_enc->change_cipher_state(s,i)) | ||
1232 | return(0); | ||
1233 | |||
1234 | /* we have to record the message digest at | ||
1235 | * this point so we can get it before we read | ||
1236 | * the finished message */ | ||
1237 | if (s->state & SSL_ST_CONNECT) | ||
1238 | { | ||
1239 | sender=s->method->ssl3_enc->server_finished_label; | ||
1240 | slen=s->method->ssl3_enc->server_finished_label_len; | ||
1241 | } | ||
1242 | else | ||
1243 | { | ||
1244 | sender=s->method->ssl3_enc->client_finished_label; | ||
1245 | slen=s->method->ssl3_enc->client_finished_label_len; | ||
1246 | } | ||
1247 | |||
1248 | s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s, | ||
1249 | &(s->s3->finish_dgst1), | ||
1250 | &(s->s3->finish_dgst2), | ||
1251 | sender,slen,s->s3->tmp.peer_finish_md); | ||
1252 | |||
1253 | return(1); | ||
1254 | } | ||
1255 | |||
1256 | void ssl3_send_alert(SSL *s, int level, int desc) | ||
1257 | { | ||
1258 | /* Map tls/ssl alert value to correct one */ | ||
1259 | desc=s->method->ssl3_enc->alert_value(desc); | ||
1260 | if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION) | ||
1261 | desc = SSL_AD_HANDSHAKE_FAILURE; /* SSL 3.0 does not have protocol_version alerts */ | ||
1262 | if (desc < 0) return; | ||
1263 | /* If a fatal one, remove from cache */ | ||
1264 | if ((level == 2) && (s->session != NULL)) | ||
1265 | SSL_CTX_remove_session(s->ctx,s->session); | ||
1266 | |||
1267 | s->s3->alert_dispatch=1; | ||
1268 | s->s3->send_alert[0]=level; | ||
1269 | s->s3->send_alert[1]=desc; | ||
1270 | if (s->s3->wbuf.left == 0) /* data still being written out? */ | ||
1271 | ssl3_dispatch_alert(s); | ||
1272 | /* else data is still being written out, we will get written | ||
1273 | * some time in the future */ | ||
1274 | } | ||
1275 | |||
1276 | int ssl3_dispatch_alert(SSL *s) | ||
1277 | { | ||
1278 | int i,j; | ||
1279 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
1280 | |||
1281 | s->s3->alert_dispatch=0; | ||
1282 | i = do_ssl3_write(s, SSL3_RT_ALERT, &s->s3->send_alert[0], 2, 0); | ||
1283 | if (i <= 0) | ||
1284 | { | ||
1285 | s->s3->alert_dispatch=1; | ||
1286 | } | ||
1287 | else | ||
1288 | { | ||
1289 | /* Alert sent to BIO. If it is important, flush it now. | ||
1290 | * If the message does not get sent due to non-blocking IO, | ||
1291 | * we will not worry too much. */ | ||
1292 | if (s->s3->send_alert[0] == SSL3_AL_FATAL) | ||
1293 | (void)BIO_flush(s->wbio); | ||
1294 | |||
1295 | if (s->msg_callback) | ||
1296 | s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3->send_alert, 2, s, s->msg_callback_arg); | ||
1297 | |||
1298 | if (s->info_callback != NULL) | ||
1299 | cb=s->info_callback; | ||
1300 | else if (s->ctx->info_callback != NULL) | ||
1301 | cb=s->ctx->info_callback; | ||
1302 | |||
1303 | if (cb != NULL) | ||
1304 | { | ||
1305 | j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1]; | ||
1306 | cb(s,SSL_CB_WRITE_ALERT,j); | ||
1307 | } | ||
1308 | } | ||
1309 | return(i); | ||
1310 | } | ||
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c deleted file mode 100644 index 36fc39d7f8..0000000000 --- a/src/lib/libssl/s3_srvr.c +++ /dev/null | |||
@@ -1,2082 +0,0 @@ | |||
1 | /* ssl/s3_srvr.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #define REUSE_CIPHER_BUG | ||
113 | #define NETSCAPE_HANG_BUG | ||
114 | |||
115 | |||
116 | #include <stdio.h> | ||
117 | #include "ssl_locl.h" | ||
118 | #include "kssl_lcl.h" | ||
119 | #include <openssl/buffer.h> | ||
120 | #include <openssl/rand.h> | ||
121 | #include <openssl/objects.h> | ||
122 | #include <openssl/evp.h> | ||
123 | #include <openssl/x509.h> | ||
124 | #ifndef OPENSSL_NO_KRB5 | ||
125 | #include <openssl/krb5_asn.h> | ||
126 | #endif | ||
127 | #include <openssl/md5.h> | ||
128 | #include <openssl/fips.h> | ||
129 | |||
130 | static SSL_METHOD *ssl3_get_server_method(int ver); | ||
131 | static int ssl3_get_client_hello(SSL *s); | ||
132 | static int ssl3_check_client_hello(SSL *s); | ||
133 | static int ssl3_send_server_hello(SSL *s); | ||
134 | static int ssl3_send_server_key_exchange(SSL *s); | ||
135 | static int ssl3_send_certificate_request(SSL *s); | ||
136 | static int ssl3_send_server_done(SSL *s); | ||
137 | static int ssl3_get_client_key_exchange(SSL *s); | ||
138 | static int ssl3_get_client_certificate(SSL *s); | ||
139 | static int ssl3_get_cert_verify(SSL *s); | ||
140 | static int ssl3_send_hello_request(SSL *s); | ||
141 | |||
142 | static SSL_METHOD *ssl3_get_server_method(int ver) | ||
143 | { | ||
144 | if (ver == SSL3_VERSION) | ||
145 | return(SSLv3_server_method()); | ||
146 | else | ||
147 | return(NULL); | ||
148 | } | ||
149 | |||
150 | SSL_METHOD *SSLv3_server_method(void) | ||
151 | { | ||
152 | static int init=1; | ||
153 | static SSL_METHOD SSLv3_server_data; | ||
154 | |||
155 | if (init) | ||
156 | { | ||
157 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
158 | |||
159 | if (init) | ||
160 | { | ||
161 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), | ||
162 | sizeof(SSL_METHOD)); | ||
163 | SSLv3_server_data.ssl_accept=ssl3_accept; | ||
164 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | ||
165 | init=0; | ||
166 | } | ||
167 | |||
168 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
169 | } | ||
170 | return(&SSLv3_server_data); | ||
171 | } | ||
172 | |||
173 | int ssl3_accept(SSL *s) | ||
174 | { | ||
175 | BUF_MEM *buf; | ||
176 | unsigned long l,Time=(unsigned long)time(NULL); | ||
177 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | ||
178 | long num1; | ||
179 | int ret= -1; | ||
180 | int new_state,state,skip=0; | ||
181 | |||
182 | RAND_add(&Time,sizeof(Time),0); | ||
183 | ERR_clear_error(); | ||
184 | clear_sys_error(); | ||
185 | |||
186 | if (s->info_callback != NULL) | ||
187 | cb=s->info_callback; | ||
188 | else if (s->ctx->info_callback != NULL) | ||
189 | cb=s->ctx->info_callback; | ||
190 | |||
191 | /* init things to blank */ | ||
192 | s->in_handshake++; | ||
193 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
194 | |||
195 | if (s->cert == NULL) | ||
196 | { | ||
197 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET); | ||
198 | return(-1); | ||
199 | } | ||
200 | |||
201 | for (;;) | ||
202 | { | ||
203 | state=s->state; | ||
204 | |||
205 | switch (s->state) | ||
206 | { | ||
207 | case SSL_ST_RENEGOTIATE: | ||
208 | s->new_session=1; | ||
209 | /* s->state=SSL_ST_ACCEPT; */ | ||
210 | |||
211 | case SSL_ST_BEFORE: | ||
212 | case SSL_ST_ACCEPT: | ||
213 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
214 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
215 | |||
216 | s->server=1; | ||
217 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
218 | |||
219 | if ((s->version>>8) != 3) | ||
220 | { | ||
221 | SSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR); | ||
222 | return -1; | ||
223 | } | ||
224 | s->type=SSL_ST_ACCEPT; | ||
225 | |||
226 | if (s->init_buf == NULL) | ||
227 | { | ||
228 | if ((buf=BUF_MEM_new()) == NULL) | ||
229 | { | ||
230 | ret= -1; | ||
231 | goto end; | ||
232 | } | ||
233 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
234 | { | ||
235 | ret= -1; | ||
236 | goto end; | ||
237 | } | ||
238 | s->init_buf=buf; | ||
239 | } | ||
240 | |||
241 | if (!ssl3_setup_buffers(s)) | ||
242 | { | ||
243 | ret= -1; | ||
244 | goto end; | ||
245 | } | ||
246 | |||
247 | s->init_num=0; | ||
248 | |||
249 | if (s->state != SSL_ST_RENEGOTIATE) | ||
250 | { | ||
251 | /* Ok, we now need to push on a buffering BIO so that | ||
252 | * the output is sent in a way that TCP likes :-) | ||
253 | */ | ||
254 | if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; } | ||
255 | |||
256 | ssl3_init_finished_mac(s); | ||
257 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
258 | s->ctx->stats.sess_accept++; | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | /* s->state == SSL_ST_RENEGOTIATE, | ||
263 | * we will just send a HelloRequest */ | ||
264 | s->ctx->stats.sess_accept_renegotiate++; | ||
265 | s->state=SSL3_ST_SW_HELLO_REQ_A; | ||
266 | } | ||
267 | break; | ||
268 | |||
269 | case SSL3_ST_SW_HELLO_REQ_A: | ||
270 | case SSL3_ST_SW_HELLO_REQ_B: | ||
271 | |||
272 | s->shutdown=0; | ||
273 | ret=ssl3_send_hello_request(s); | ||
274 | if (ret <= 0) goto end; | ||
275 | s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C; | ||
276 | s->state=SSL3_ST_SW_FLUSH; | ||
277 | s->init_num=0; | ||
278 | |||
279 | ssl3_init_finished_mac(s); | ||
280 | break; | ||
281 | |||
282 | case SSL3_ST_SW_HELLO_REQ_C: | ||
283 | s->state=SSL_ST_OK; | ||
284 | break; | ||
285 | |||
286 | case SSL3_ST_SR_CLNT_HELLO_A: | ||
287 | case SSL3_ST_SR_CLNT_HELLO_B: | ||
288 | case SSL3_ST_SR_CLNT_HELLO_C: | ||
289 | |||
290 | s->shutdown=0; | ||
291 | ret=ssl3_get_client_hello(s); | ||
292 | if (ret <= 0) goto end; | ||
293 | s->new_session = 2; | ||
294 | s->state=SSL3_ST_SW_SRVR_HELLO_A; | ||
295 | s->init_num=0; | ||
296 | break; | ||
297 | |||
298 | case SSL3_ST_SW_SRVR_HELLO_A: | ||
299 | case SSL3_ST_SW_SRVR_HELLO_B: | ||
300 | ret=ssl3_send_server_hello(s); | ||
301 | if (ret <= 0) goto end; | ||
302 | |||
303 | if (s->hit) | ||
304 | s->state=SSL3_ST_SW_CHANGE_A; | ||
305 | else | ||
306 | s->state=SSL3_ST_SW_CERT_A; | ||
307 | s->init_num=0; | ||
308 | break; | ||
309 | |||
310 | case SSL3_ST_SW_CERT_A: | ||
311 | case SSL3_ST_SW_CERT_B: | ||
312 | /* Check if it is anon DH */ | ||
313 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
314 | { | ||
315 | ret=ssl3_send_server_certificate(s); | ||
316 | if (ret <= 0) goto end; | ||
317 | } | ||
318 | else | ||
319 | skip=1; | ||
320 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
321 | s->init_num=0; | ||
322 | break; | ||
323 | |||
324 | case SSL3_ST_SW_KEY_EXCH_A: | ||
325 | case SSL3_ST_SW_KEY_EXCH_B: | ||
326 | l=s->s3->tmp.new_cipher->algorithms; | ||
327 | |||
328 | /* clear this, it may get reset by | ||
329 | * send_server_key_exchange */ | ||
330 | if ((s->options & SSL_OP_EPHEMERAL_RSA) | ||
331 | #ifndef OPENSSL_NO_KRB5 | ||
332 | && !(l & SSL_KRB5) | ||
333 | #endif /* OPENSSL_NO_KRB5 */ | ||
334 | ) | ||
335 | /* option SSL_OP_EPHEMERAL_RSA sends temporary RSA key | ||
336 | * even when forbidden by protocol specs | ||
337 | * (handshake may fail as clients are not required to | ||
338 | * be able to handle this) */ | ||
339 | s->s3->tmp.use_rsa_tmp=1; | ||
340 | else | ||
341 | s->s3->tmp.use_rsa_tmp=0; | ||
342 | |||
343 | /* only send if a DH key exchange, fortezza or | ||
344 | * RSA but we have a sign only certificate */ | ||
345 | if (s->s3->tmp.use_rsa_tmp | ||
346 | || (l & (SSL_DH|SSL_kFZA)) | ||
347 | || ((l & SSL_kRSA) | ||
348 | && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL | ||
349 | || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) | ||
350 | && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher) | ||
351 | ) | ||
352 | ) | ||
353 | ) | ||
354 | ) | ||
355 | { | ||
356 | ret=ssl3_send_server_key_exchange(s); | ||
357 | if (ret <= 0) goto end; | ||
358 | } | ||
359 | else | ||
360 | skip=1; | ||
361 | |||
362 | s->state=SSL3_ST_SW_CERT_REQ_A; | ||
363 | s->init_num=0; | ||
364 | break; | ||
365 | |||
366 | case SSL3_ST_SW_CERT_REQ_A: | ||
367 | case SSL3_ST_SW_CERT_REQ_B: | ||
368 | if (/* don't request cert unless asked for it: */ | ||
369 | !(s->verify_mode & SSL_VERIFY_PEER) || | ||
370 | /* if SSL_VERIFY_CLIENT_ONCE is set, | ||
371 | * don't request cert during re-negotiation: */ | ||
372 | ((s->session->peer != NULL) && | ||
373 | (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) || | ||
374 | /* never request cert in anonymous ciphersuites | ||
375 | * (see section "Certificate request" in SSL 3 drafts | ||
376 | * and in RFC 2246): */ | ||
377 | ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) && | ||
378 | /* ... except when the application insists on verification | ||
379 | * (against the specs, but s3_clnt.c accepts this for SSL 3) */ | ||
380 | !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) || | ||
381 | /* never request cert in Kerberos ciphersuites */ | ||
382 | (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5)) | ||
383 | { | ||
384 | /* no cert request */ | ||
385 | skip=1; | ||
386 | s->s3->tmp.cert_request=0; | ||
387 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
388 | } | ||
389 | else | ||
390 | { | ||
391 | s->s3->tmp.cert_request=1; | ||
392 | ret=ssl3_send_certificate_request(s); | ||
393 | if (ret <= 0) goto end; | ||
394 | #ifndef NETSCAPE_HANG_BUG | ||
395 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
396 | #else | ||
397 | s->state=SSL3_ST_SW_FLUSH; | ||
398 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
399 | #endif | ||
400 | s->init_num=0; | ||
401 | } | ||
402 | break; | ||
403 | |||
404 | case SSL3_ST_SW_SRVR_DONE_A: | ||
405 | case SSL3_ST_SW_SRVR_DONE_B: | ||
406 | ret=ssl3_send_server_done(s); | ||
407 | if (ret <= 0) goto end; | ||
408 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
409 | s->state=SSL3_ST_SW_FLUSH; | ||
410 | s->init_num=0; | ||
411 | break; | ||
412 | |||
413 | case SSL3_ST_SW_FLUSH: | ||
414 | /* number of bytes to be flushed */ | ||
415 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
416 | if (num1 > 0) | ||
417 | { | ||
418 | s->rwstate=SSL_WRITING; | ||
419 | num1=BIO_flush(s->wbio); | ||
420 | if (num1 <= 0) { ret= -1; goto end; } | ||
421 | s->rwstate=SSL_NOTHING; | ||
422 | } | ||
423 | |||
424 | s->state=s->s3->tmp.next_state; | ||
425 | break; | ||
426 | |||
427 | case SSL3_ST_SR_CERT_A: | ||
428 | case SSL3_ST_SR_CERT_B: | ||
429 | /* Check for second client hello (MS SGC) */ | ||
430 | ret = ssl3_check_client_hello(s); | ||
431 | if (ret <= 0) | ||
432 | goto end; | ||
433 | if (ret == 2) | ||
434 | s->state = SSL3_ST_SR_CLNT_HELLO_C; | ||
435 | else { | ||
436 | if (s->s3->tmp.cert_request) | ||
437 | { | ||
438 | ret=ssl3_get_client_certificate(s); | ||
439 | if (ret <= 0) goto end; | ||
440 | } | ||
441 | s->init_num=0; | ||
442 | s->state=SSL3_ST_SR_KEY_EXCH_A; | ||
443 | } | ||
444 | break; | ||
445 | |||
446 | case SSL3_ST_SR_KEY_EXCH_A: | ||
447 | case SSL3_ST_SR_KEY_EXCH_B: | ||
448 | ret=ssl3_get_client_key_exchange(s); | ||
449 | if (ret <= 0) goto end; | ||
450 | s->state=SSL3_ST_SR_CERT_VRFY_A; | ||
451 | s->init_num=0; | ||
452 | |||
453 | /* We need to get hashes here so if there is | ||
454 | * a client cert, it can be verified */ | ||
455 | s->method->ssl3_enc->cert_verify_mac(s, | ||
456 | &(s->s3->finish_dgst1), | ||
457 | &(s->s3->tmp.cert_verify_md[0])); | ||
458 | s->method->ssl3_enc->cert_verify_mac(s, | ||
459 | &(s->s3->finish_dgst2), | ||
460 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH])); | ||
461 | |||
462 | break; | ||
463 | |||
464 | case SSL3_ST_SR_CERT_VRFY_A: | ||
465 | case SSL3_ST_SR_CERT_VRFY_B: | ||
466 | |||
467 | /* we should decide if we expected this one */ | ||
468 | ret=ssl3_get_cert_verify(s); | ||
469 | if (ret <= 0) goto end; | ||
470 | |||
471 | s->state=SSL3_ST_SR_FINISHED_A; | ||
472 | s->init_num=0; | ||
473 | break; | ||
474 | |||
475 | case SSL3_ST_SR_FINISHED_A: | ||
476 | case SSL3_ST_SR_FINISHED_B: | ||
477 | ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A, | ||
478 | SSL3_ST_SR_FINISHED_B); | ||
479 | if (ret <= 0) goto end; | ||
480 | if (s->hit) | ||
481 | s->state=SSL_ST_OK; | ||
482 | else | ||
483 | s->state=SSL3_ST_SW_CHANGE_A; | ||
484 | s->init_num=0; | ||
485 | break; | ||
486 | |||
487 | case SSL3_ST_SW_CHANGE_A: | ||
488 | case SSL3_ST_SW_CHANGE_B: | ||
489 | |||
490 | s->session->cipher=s->s3->tmp.new_cipher; | ||
491 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
492 | { ret= -1; goto end; } | ||
493 | |||
494 | ret=ssl3_send_change_cipher_spec(s, | ||
495 | SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B); | ||
496 | |||
497 | if (ret <= 0) goto end; | ||
498 | s->state=SSL3_ST_SW_FINISHED_A; | ||
499 | s->init_num=0; | ||
500 | |||
501 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
502 | SSL3_CHANGE_CIPHER_SERVER_WRITE)) | ||
503 | { | ||
504 | ret= -1; | ||
505 | goto end; | ||
506 | } | ||
507 | |||
508 | break; | ||
509 | |||
510 | case SSL3_ST_SW_FINISHED_A: | ||
511 | case SSL3_ST_SW_FINISHED_B: | ||
512 | ret=ssl3_send_finished(s, | ||
513 | SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B, | ||
514 | s->method->ssl3_enc->server_finished_label, | ||
515 | s->method->ssl3_enc->server_finished_label_len); | ||
516 | if (ret <= 0) goto end; | ||
517 | s->state=SSL3_ST_SW_FLUSH; | ||
518 | if (s->hit) | ||
519 | s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A; | ||
520 | else | ||
521 | s->s3->tmp.next_state=SSL_ST_OK; | ||
522 | s->init_num=0; | ||
523 | break; | ||
524 | |||
525 | case SSL_ST_OK: | ||
526 | /* clean a few things up */ | ||
527 | ssl3_cleanup_key_block(s); | ||
528 | |||
529 | BUF_MEM_free(s->init_buf); | ||
530 | s->init_buf=NULL; | ||
531 | |||
532 | /* remove buffering on output */ | ||
533 | ssl_free_wbio_buffer(s); | ||
534 | |||
535 | s->init_num=0; | ||
536 | |||
537 | if (s->new_session == 2) /* skipped if we just sent a HelloRequest */ | ||
538 | { | ||
539 | /* actually not necessarily a 'new' session unless | ||
540 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */ | ||
541 | |||
542 | s->new_session=0; | ||
543 | |||
544 | ssl_update_cache(s,SSL_SESS_CACHE_SERVER); | ||
545 | |||
546 | s->ctx->stats.sess_accept_good++; | ||
547 | /* s->server=1; */ | ||
548 | s->handshake_func=ssl3_accept; | ||
549 | |||
550 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
551 | } | ||
552 | |||
553 | ret = 1; | ||
554 | goto end; | ||
555 | /* break; */ | ||
556 | |||
557 | default: | ||
558 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
559 | ret= -1; | ||
560 | goto end; | ||
561 | /* break; */ | ||
562 | } | ||
563 | |||
564 | if (!s->s3->tmp.reuse_message && !skip) | ||
565 | { | ||
566 | if (s->debug) | ||
567 | { | ||
568 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
569 | goto end; | ||
570 | } | ||
571 | |||
572 | |||
573 | if ((cb != NULL) && (s->state != state)) | ||
574 | { | ||
575 | new_state=s->state; | ||
576 | s->state=state; | ||
577 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
578 | s->state=new_state; | ||
579 | } | ||
580 | } | ||
581 | skip=0; | ||
582 | } | ||
583 | end: | ||
584 | /* BIO_flush(s->wbio); */ | ||
585 | |||
586 | s->in_handshake--; | ||
587 | if (cb != NULL) | ||
588 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
589 | return(ret); | ||
590 | } | ||
591 | |||
592 | static int ssl3_send_hello_request(SSL *s) | ||
593 | { | ||
594 | unsigned char *p; | ||
595 | |||
596 | if (s->state == SSL3_ST_SW_HELLO_REQ_A) | ||
597 | { | ||
598 | p=(unsigned char *)s->init_buf->data; | ||
599 | *(p++)=SSL3_MT_HELLO_REQUEST; | ||
600 | *(p++)=0; | ||
601 | *(p++)=0; | ||
602 | *(p++)=0; | ||
603 | |||
604 | s->state=SSL3_ST_SW_HELLO_REQ_B; | ||
605 | /* number of bytes to write */ | ||
606 | s->init_num=4; | ||
607 | s->init_off=0; | ||
608 | } | ||
609 | |||
610 | /* SSL3_ST_SW_HELLO_REQ_B */ | ||
611 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
612 | } | ||
613 | |||
614 | static int ssl3_check_client_hello(SSL *s) | ||
615 | { | ||
616 | int ok; | ||
617 | long n; | ||
618 | |||
619 | /* this function is called when we really expect a Certificate message, | ||
620 | * so permit appropriate message length */ | ||
621 | n=ssl3_get_message(s, | ||
622 | SSL3_ST_SR_CERT_A, | ||
623 | SSL3_ST_SR_CERT_B, | ||
624 | -1, | ||
625 | s->max_cert_list, | ||
626 | &ok); | ||
627 | if (!ok) return((int)n); | ||
628 | s->s3->tmp.reuse_message = 1; | ||
629 | if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO) | ||
630 | { | ||
631 | /* Throw away what we have done so far in the current handshake, | ||
632 | * which will now be aborted. (A full SSL_clear would be too much.) | ||
633 | * I hope that tmp.dh is the only thing that may need to be cleared | ||
634 | * when a handshake is not completed ... */ | ||
635 | #ifndef OPENSSL_NO_DH | ||
636 | if (s->s3->tmp.dh != NULL) | ||
637 | { | ||
638 | DH_free(s->s3->tmp.dh); | ||
639 | s->s3->tmp.dh = NULL; | ||
640 | } | ||
641 | #endif | ||
642 | return 2; | ||
643 | } | ||
644 | return 1; | ||
645 | } | ||
646 | |||
647 | static int ssl3_get_client_hello(SSL *s) | ||
648 | { | ||
649 | int i,j,ok,al,ret= -1; | ||
650 | long n; | ||
651 | unsigned long id; | ||
652 | unsigned char *p,*d,*q; | ||
653 | SSL_CIPHER *c; | ||
654 | SSL_COMP *comp=NULL; | ||
655 | STACK_OF(SSL_CIPHER) *ciphers=NULL; | ||
656 | |||
657 | /* We do this so that we will respond with our native type. | ||
658 | * If we are TLSv1 and we get SSLv3, we will respond with TLSv1, | ||
659 | * This down switching should be handled by a different method. | ||
660 | * If we are SSLv3, we will respond with SSLv3, even if prompted with | ||
661 | * TLSv1. | ||
662 | */ | ||
663 | if (s->state == SSL3_ST_SR_CLNT_HELLO_A) | ||
664 | { | ||
665 | s->first_packet=1; | ||
666 | s->state=SSL3_ST_SR_CLNT_HELLO_B; | ||
667 | } | ||
668 | n=ssl3_get_message(s, | ||
669 | SSL3_ST_SR_CLNT_HELLO_B, | ||
670 | SSL3_ST_SR_CLNT_HELLO_C, | ||
671 | SSL3_MT_CLIENT_HELLO, | ||
672 | SSL3_RT_MAX_PLAIN_LENGTH, | ||
673 | &ok); | ||
674 | |||
675 | if (!ok) return((int)n); | ||
676 | d=p=(unsigned char *)s->init_msg; | ||
677 | |||
678 | /* use version from inside client hello, not from record header | ||
679 | * (may differ: see RFC 2246, Appendix E, second paragraph) */ | ||
680 | s->client_version=(((int)p[0])<<8)|(int)p[1]; | ||
681 | p+=2; | ||
682 | |||
683 | if (s->client_version < s->version) | ||
684 | { | ||
685 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER); | ||
686 | if ((s->client_version>>8) == SSL3_VERSION_MAJOR) | ||
687 | { | ||
688 | /* similar to ssl3_get_record, send alert using remote version number */ | ||
689 | s->version = s->client_version; | ||
690 | } | ||
691 | al = SSL_AD_PROTOCOL_VERSION; | ||
692 | goto f_err; | ||
693 | } | ||
694 | |||
695 | /* load the client random */ | ||
696 | memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE); | ||
697 | p+=SSL3_RANDOM_SIZE; | ||
698 | |||
699 | /* get the session-id */ | ||
700 | j= *(p++); | ||
701 | |||
702 | s->hit=0; | ||
703 | /* Versions before 0.9.7 always allow session reuse during renegotiation | ||
704 | * (i.e. when s->new_session is true), option | ||
705 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is new with 0.9.7. | ||
706 | * Maybe this optional behaviour should always have been the default, | ||
707 | * but we cannot safely change the default behaviour (or new applications | ||
708 | * might be written that become totally unsecure when compiled with | ||
709 | * an earlier library version) | ||
710 | */ | ||
711 | if (j == 0 || (s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) | ||
712 | { | ||
713 | if (!ssl_get_new_session(s,1)) | ||
714 | goto err; | ||
715 | } | ||
716 | else | ||
717 | { | ||
718 | i=ssl_get_prev_session(s,p,j); | ||
719 | if (i == 1) | ||
720 | { /* previous session */ | ||
721 | s->hit=1; | ||
722 | } | ||
723 | else if (i == -1) | ||
724 | goto err; | ||
725 | else /* i == 0 */ | ||
726 | { | ||
727 | if (!ssl_get_new_session(s,1)) | ||
728 | goto err; | ||
729 | } | ||
730 | } | ||
731 | |||
732 | p+=j; | ||
733 | n2s(p,i); | ||
734 | if ((i == 0) && (j != 0)) | ||
735 | { | ||
736 | /* we need a cipher if we are not resuming a session */ | ||
737 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
738 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED); | ||
739 | goto f_err; | ||
740 | } | ||
741 | if ((p+i) >= (d+n)) | ||
742 | { | ||
743 | /* not enough data */ | ||
744 | al=SSL_AD_DECODE_ERROR; | ||
745 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
746 | goto f_err; | ||
747 | } | ||
748 | if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers)) | ||
749 | == NULL)) | ||
750 | { | ||
751 | goto err; | ||
752 | } | ||
753 | p+=i; | ||
754 | |||
755 | /* If it is a hit, check that the cipher is in the list */ | ||
756 | if ((s->hit) && (i > 0)) | ||
757 | { | ||
758 | j=0; | ||
759 | id=s->session->cipher->id; | ||
760 | |||
761 | #ifdef CIPHER_DEBUG | ||
762 | printf("client sent %d ciphers\n",sk_num(ciphers)); | ||
763 | #endif | ||
764 | for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++) | ||
765 | { | ||
766 | c=sk_SSL_CIPHER_value(ciphers,i); | ||
767 | #ifdef CIPHER_DEBUG | ||
768 | printf("client [%2d of %2d]:%s\n", | ||
769 | i,sk_num(ciphers),SSL_CIPHER_get_name(c)); | ||
770 | #endif | ||
771 | if (c->id == id) | ||
772 | { | ||
773 | j=1; | ||
774 | break; | ||
775 | } | ||
776 | } | ||
777 | if (j == 0) | ||
778 | { | ||
779 | if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1)) | ||
780 | { | ||
781 | /* Very bad for multi-threading.... */ | ||
782 | s->session->cipher=sk_SSL_CIPHER_value(ciphers, | ||
783 | 0); | ||
784 | } | ||
785 | else | ||
786 | { | ||
787 | /* we need to have the cipher in the cipher | ||
788 | * list if we are asked to reuse it */ | ||
789 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
790 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING); | ||
791 | goto f_err; | ||
792 | } | ||
793 | } | ||
794 | } | ||
795 | |||
796 | /* compression */ | ||
797 | i= *(p++); | ||
798 | if ((p+i) > (d+n)) | ||
799 | { | ||
800 | /* not enough data */ | ||
801 | al=SSL_AD_DECODE_ERROR; | ||
802 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
803 | goto f_err; | ||
804 | } | ||
805 | q=p; | ||
806 | for (j=0; j<i; j++) | ||
807 | { | ||
808 | if (p[j] == 0) break; | ||
809 | } | ||
810 | |||
811 | p+=i; | ||
812 | if (j >= i) | ||
813 | { | ||
814 | /* no compress */ | ||
815 | al=SSL_AD_DECODE_ERROR; | ||
816 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED); | ||
817 | goto f_err; | ||
818 | } | ||
819 | |||
820 | /* Worst case, we will use the NULL compression, but if we have other | ||
821 | * options, we will now look for them. We have i-1 compression | ||
822 | * algorithms from the client, starting at q. */ | ||
823 | s->s3->tmp.new_compression=NULL; | ||
824 | if (s->ctx->comp_methods != NULL) | ||
825 | { /* See if we have a match */ | ||
826 | int m,nn,o,v,done=0; | ||
827 | |||
828 | nn=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
829 | for (m=0; m<nn; m++) | ||
830 | { | ||
831 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,m); | ||
832 | v=comp->id; | ||
833 | for (o=0; o<i; o++) | ||
834 | { | ||
835 | if (v == q[o]) | ||
836 | { | ||
837 | done=1; | ||
838 | break; | ||
839 | } | ||
840 | } | ||
841 | if (done) break; | ||
842 | } | ||
843 | if (done) | ||
844 | s->s3->tmp.new_compression=comp; | ||
845 | else | ||
846 | comp=NULL; | ||
847 | } | ||
848 | |||
849 | /* TLS does not mind if there is extra stuff */ | ||
850 | #if 0 /* SSL 3.0 does not mind either, so we should disable this test | ||
851 | * (was enabled in 0.9.6d through 0.9.6j and 0.9.7 through 0.9.7b, | ||
852 | * in earlier SSLeay/OpenSSL releases this test existed but was buggy) */ | ||
853 | if (s->version == SSL3_VERSION) | ||
854 | { | ||
855 | if (p < (d+n)) | ||
856 | { | ||
857 | /* wrong number of bytes, | ||
858 | * there could be more to follow */ | ||
859 | al=SSL_AD_DECODE_ERROR; | ||
860 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
861 | goto f_err; | ||
862 | } | ||
863 | } | ||
864 | #endif | ||
865 | |||
866 | /* Given s->session->ciphers and SSL_get_ciphers, we must | ||
867 | * pick a cipher */ | ||
868 | |||
869 | if (!s->hit) | ||
870 | { | ||
871 | s->session->compress_meth=(comp == NULL)?0:comp->id; | ||
872 | if (s->session->ciphers != NULL) | ||
873 | sk_SSL_CIPHER_free(s->session->ciphers); | ||
874 | s->session->ciphers=ciphers; | ||
875 | if (ciphers == NULL) | ||
876 | { | ||
877 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
878 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED); | ||
879 | goto f_err; | ||
880 | } | ||
881 | ciphers=NULL; | ||
882 | c=ssl3_choose_cipher(s,s->session->ciphers, | ||
883 | SSL_get_ciphers(s)); | ||
884 | |||
885 | if (c == NULL) | ||
886 | { | ||
887 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
888 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER); | ||
889 | goto f_err; | ||
890 | } | ||
891 | s->s3->tmp.new_cipher=c; | ||
892 | } | ||
893 | else | ||
894 | { | ||
895 | /* Session-id reuse */ | ||
896 | #ifdef REUSE_CIPHER_BUG | ||
897 | STACK_OF(SSL_CIPHER) *sk; | ||
898 | SSL_CIPHER *nc=NULL; | ||
899 | SSL_CIPHER *ec=NULL; | ||
900 | |||
901 | if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG) | ||
902 | { | ||
903 | sk=s->session->ciphers; | ||
904 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
905 | { | ||
906 | c=sk_SSL_CIPHER_value(sk,i); | ||
907 | if (c->algorithms & SSL_eNULL) | ||
908 | nc=c; | ||
909 | if (SSL_C_IS_EXPORT(c)) | ||
910 | ec=c; | ||
911 | } | ||
912 | if (nc != NULL) | ||
913 | s->s3->tmp.new_cipher=nc; | ||
914 | else if (ec != NULL) | ||
915 | s->s3->tmp.new_cipher=ec; | ||
916 | else | ||
917 | s->s3->tmp.new_cipher=s->session->cipher; | ||
918 | } | ||
919 | else | ||
920 | #endif | ||
921 | s->s3->tmp.new_cipher=s->session->cipher; | ||
922 | } | ||
923 | |||
924 | /* we now have the following setup. | ||
925 | * client_random | ||
926 | * cipher_list - our prefered list of ciphers | ||
927 | * ciphers - the clients prefered list of ciphers | ||
928 | * compression - basically ignored right now | ||
929 | * ssl version is set - sslv3 | ||
930 | * s->session - The ssl session has been setup. | ||
931 | * s->hit - session reuse flag | ||
932 | * s->tmp.new_cipher - the new cipher to use. | ||
933 | */ | ||
934 | |||
935 | ret=1; | ||
936 | if (0) | ||
937 | { | ||
938 | f_err: | ||
939 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
940 | } | ||
941 | err: | ||
942 | if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers); | ||
943 | return(ret); | ||
944 | } | ||
945 | |||
946 | static int ssl3_send_server_hello(SSL *s) | ||
947 | { | ||
948 | unsigned char *buf; | ||
949 | unsigned char *p,*d; | ||
950 | int i,sl; | ||
951 | unsigned long l,Time; | ||
952 | |||
953 | if (s->state == SSL3_ST_SW_SRVR_HELLO_A) | ||
954 | { | ||
955 | buf=(unsigned char *)s->init_buf->data; | ||
956 | p=s->s3->server_random; | ||
957 | Time=(unsigned long)time(NULL); /* Time */ | ||
958 | l2n(Time,p); | ||
959 | if(RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-4) <= 0) | ||
960 | return -1; | ||
961 | /* Do the message type and length last */ | ||
962 | d=p= &(buf[4]); | ||
963 | |||
964 | *(p++)=s->version>>8; | ||
965 | *(p++)=s->version&0xff; | ||
966 | |||
967 | /* Random stuff */ | ||
968 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
969 | p+=SSL3_RANDOM_SIZE; | ||
970 | |||
971 | /* now in theory we have 3 options to sending back the | ||
972 | * session id. If it is a re-use, we send back the | ||
973 | * old session-id, if it is a new session, we send | ||
974 | * back the new session-id or we send back a 0 length | ||
975 | * session-id if we want it to be single use. | ||
976 | * Currently I will not implement the '0' length session-id | ||
977 | * 12-Jan-98 - I'll now support the '0' length stuff. | ||
978 | */ | ||
979 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) | ||
980 | s->session->session_id_length=0; | ||
981 | |||
982 | sl=s->session->session_id_length; | ||
983 | if (sl > sizeof s->session->session_id) | ||
984 | { | ||
985 | SSLerr(SSL_F_SSL3_SEND_SERVER_HELLO, ERR_R_INTERNAL_ERROR); | ||
986 | return -1; | ||
987 | } | ||
988 | *(p++)=sl; | ||
989 | memcpy(p,s->session->session_id,sl); | ||
990 | p+=sl; | ||
991 | |||
992 | /* put the cipher */ | ||
993 | i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p); | ||
994 | p+=i; | ||
995 | |||
996 | /* put the compression method */ | ||
997 | if (s->s3->tmp.new_compression == NULL) | ||
998 | *(p++)=0; | ||
999 | else | ||
1000 | *(p++)=s->s3->tmp.new_compression->id; | ||
1001 | |||
1002 | /* do the header */ | ||
1003 | l=(p-d); | ||
1004 | d=buf; | ||
1005 | *(d++)=SSL3_MT_SERVER_HELLO; | ||
1006 | l2n3(l,d); | ||
1007 | |||
1008 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
1009 | /* number of bytes to write */ | ||
1010 | s->init_num=p-buf; | ||
1011 | s->init_off=0; | ||
1012 | } | ||
1013 | |||
1014 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
1015 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1016 | } | ||
1017 | |||
1018 | static int ssl3_send_server_done(SSL *s) | ||
1019 | { | ||
1020 | unsigned char *p; | ||
1021 | |||
1022 | if (s->state == SSL3_ST_SW_SRVR_DONE_A) | ||
1023 | { | ||
1024 | p=(unsigned char *)s->init_buf->data; | ||
1025 | |||
1026 | /* do the header */ | ||
1027 | *(p++)=SSL3_MT_SERVER_DONE; | ||
1028 | *(p++)=0; | ||
1029 | *(p++)=0; | ||
1030 | *(p++)=0; | ||
1031 | |||
1032 | s->state=SSL3_ST_SW_SRVR_DONE_B; | ||
1033 | /* number of bytes to write */ | ||
1034 | s->init_num=4; | ||
1035 | s->init_off=0; | ||
1036 | } | ||
1037 | |||
1038 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
1039 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1040 | } | ||
1041 | |||
1042 | static int ssl3_send_server_key_exchange(SSL *s) | ||
1043 | { | ||
1044 | #ifndef OPENSSL_NO_RSA | ||
1045 | unsigned char *q; | ||
1046 | int j,num; | ||
1047 | RSA *rsa; | ||
1048 | unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
1049 | unsigned int u; | ||
1050 | #endif | ||
1051 | #ifndef OPENSSL_NO_DH | ||
1052 | DH *dh=NULL,*dhp; | ||
1053 | #endif | ||
1054 | EVP_PKEY *pkey; | ||
1055 | unsigned char *p,*d; | ||
1056 | int al,i; | ||
1057 | unsigned long type; | ||
1058 | int n; | ||
1059 | CERT *cert; | ||
1060 | BIGNUM *r[4]; | ||
1061 | int nr[4],kn; | ||
1062 | BUF_MEM *buf; | ||
1063 | EVP_MD_CTX md_ctx; | ||
1064 | |||
1065 | EVP_MD_CTX_init(&md_ctx); | ||
1066 | if (s->state == SSL3_ST_SW_KEY_EXCH_A) | ||
1067 | { | ||
1068 | type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK; | ||
1069 | cert=s->cert; | ||
1070 | |||
1071 | buf=s->init_buf; | ||
1072 | |||
1073 | r[0]=r[1]=r[2]=r[3]=NULL; | ||
1074 | n=0; | ||
1075 | #ifndef OPENSSL_NO_RSA | ||
1076 | if (type & SSL_kRSA) | ||
1077 | { | ||
1078 | rsa=cert->rsa_tmp; | ||
1079 | if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL)) | ||
1080 | { | ||
1081 | rsa=s->cert->rsa_tmp_cb(s, | ||
1082 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
1083 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
1084 | if(rsa == NULL) | ||
1085 | { | ||
1086 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1087 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY); | ||
1088 | goto f_err; | ||
1089 | } | ||
1090 | RSA_up_ref(rsa); | ||
1091 | cert->rsa_tmp=rsa; | ||
1092 | } | ||
1093 | if (rsa == NULL) | ||
1094 | { | ||
1095 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1096 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY); | ||
1097 | goto f_err; | ||
1098 | } | ||
1099 | r[0]=rsa->n; | ||
1100 | r[1]=rsa->e; | ||
1101 | s->s3->tmp.use_rsa_tmp=1; | ||
1102 | } | ||
1103 | else | ||
1104 | #endif | ||
1105 | #ifndef OPENSSL_NO_DH | ||
1106 | if (type & SSL_kEDH) | ||
1107 | { | ||
1108 | dhp=cert->dh_tmp; | ||
1109 | if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL)) | ||
1110 | dhp=s->cert->dh_tmp_cb(s, | ||
1111 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
1112 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
1113 | if (dhp == NULL) | ||
1114 | { | ||
1115 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1116 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
1117 | goto f_err; | ||
1118 | } | ||
1119 | |||
1120 | if (s->s3->tmp.dh != NULL) | ||
1121 | { | ||
1122 | DH_free(dh); | ||
1123 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); | ||
1124 | goto err; | ||
1125 | } | ||
1126 | |||
1127 | if ((dh=DHparams_dup(dhp)) == NULL) | ||
1128 | { | ||
1129 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1130 | goto err; | ||
1131 | } | ||
1132 | |||
1133 | s->s3->tmp.dh=dh; | ||
1134 | if ((dhp->pub_key == NULL || | ||
1135 | dhp->priv_key == NULL || | ||
1136 | (s->options & SSL_OP_SINGLE_DH_USE))) | ||
1137 | { | ||
1138 | if(!DH_generate_key(dh)) | ||
1139 | { | ||
1140 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, | ||
1141 | ERR_R_DH_LIB); | ||
1142 | goto err; | ||
1143 | } | ||
1144 | } | ||
1145 | else | ||
1146 | { | ||
1147 | dh->pub_key=BN_dup(dhp->pub_key); | ||
1148 | dh->priv_key=BN_dup(dhp->priv_key); | ||
1149 | if ((dh->pub_key == NULL) || | ||
1150 | (dh->priv_key == NULL)) | ||
1151 | { | ||
1152 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1153 | goto err; | ||
1154 | } | ||
1155 | } | ||
1156 | r[0]=dh->p; | ||
1157 | r[1]=dh->g; | ||
1158 | r[2]=dh->pub_key; | ||
1159 | } | ||
1160 | else | ||
1161 | #endif | ||
1162 | { | ||
1163 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1164 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
1165 | goto f_err; | ||
1166 | } | ||
1167 | for (i=0; r[i] != NULL; i++) | ||
1168 | { | ||
1169 | nr[i]=BN_num_bytes(r[i]); | ||
1170 | n+=2+nr[i]; | ||
1171 | } | ||
1172 | |||
1173 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
1174 | { | ||
1175 | if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher)) | ||
1176 | == NULL) | ||
1177 | { | ||
1178 | al=SSL_AD_DECODE_ERROR; | ||
1179 | goto f_err; | ||
1180 | } | ||
1181 | kn=EVP_PKEY_size(pkey); | ||
1182 | } | ||
1183 | else | ||
1184 | { | ||
1185 | pkey=NULL; | ||
1186 | kn=0; | ||
1187 | } | ||
1188 | |||
1189 | if (!BUF_MEM_grow_clean(buf,n+4+kn)) | ||
1190 | { | ||
1191 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); | ||
1192 | goto err; | ||
1193 | } | ||
1194 | d=(unsigned char *)s->init_buf->data; | ||
1195 | p= &(d[4]); | ||
1196 | |||
1197 | for (i=0; r[i] != NULL; i++) | ||
1198 | { | ||
1199 | s2n(nr[i],p); | ||
1200 | BN_bn2bin(r[i],p); | ||
1201 | p+=nr[i]; | ||
1202 | } | ||
1203 | |||
1204 | /* not anonymous */ | ||
1205 | if (pkey != NULL) | ||
1206 | { | ||
1207 | /* n is the length of the params, they start at &(d[4]) | ||
1208 | * and p points to the space at the end. */ | ||
1209 | #ifndef OPENSSL_NO_RSA | ||
1210 | if (pkey->type == EVP_PKEY_RSA) | ||
1211 | { | ||
1212 | q=md_buf; | ||
1213 | j=0; | ||
1214 | for (num=2; num > 0; num--) | ||
1215 | { | ||
1216 | EVP_MD_CTX_set_flags(&md_ctx, | ||
1217 | EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
1218 | EVP_DigestInit_ex(&md_ctx,(num == 2) | ||
1219 | ?s->ctx->md5:s->ctx->sha1, NULL); | ||
1220 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1221 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1222 | EVP_DigestUpdate(&md_ctx,&(d[4]),n); | ||
1223 | EVP_DigestFinal_ex(&md_ctx,q, | ||
1224 | (unsigned int *)&i); | ||
1225 | q+=i; | ||
1226 | j+=i; | ||
1227 | } | ||
1228 | if (RSA_sign(NID_md5_sha1, md_buf, j, | ||
1229 | &(p[2]), &u, pkey->pkey.rsa) <= 0) | ||
1230 | { | ||
1231 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA); | ||
1232 | goto err; | ||
1233 | } | ||
1234 | s2n(u,p); | ||
1235 | n+=u+2; | ||
1236 | } | ||
1237 | else | ||
1238 | #endif | ||
1239 | #if !defined(OPENSSL_NO_DSA) | ||
1240 | if (pkey->type == EVP_PKEY_DSA) | ||
1241 | { | ||
1242 | /* lets do DSS */ | ||
1243 | EVP_SignInit_ex(&md_ctx,EVP_dss1(), NULL); | ||
1244 | EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1245 | EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1246 | EVP_SignUpdate(&md_ctx,&(d[4]),n); | ||
1247 | if (!EVP_SignFinal(&md_ctx,&(p[2]), | ||
1248 | (unsigned int *)&i,pkey)) | ||
1249 | { | ||
1250 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA); | ||
1251 | goto err; | ||
1252 | } | ||
1253 | s2n(i,p); | ||
1254 | n+=i+2; | ||
1255 | } | ||
1256 | else | ||
1257 | #endif | ||
1258 | { | ||
1259 | /* Is this error check actually needed? */ | ||
1260 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1261 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE); | ||
1262 | goto f_err; | ||
1263 | } | ||
1264 | } | ||
1265 | |||
1266 | *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE; | ||
1267 | l2n3(n,d); | ||
1268 | |||
1269 | /* we should now have things packed up, so lets send | ||
1270 | * it off */ | ||
1271 | s->init_num=n+4; | ||
1272 | s->init_off=0; | ||
1273 | } | ||
1274 | |||
1275 | s->state = SSL3_ST_SW_KEY_EXCH_B; | ||
1276 | EVP_MD_CTX_cleanup(&md_ctx); | ||
1277 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1278 | f_err: | ||
1279 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1280 | err: | ||
1281 | EVP_MD_CTX_cleanup(&md_ctx); | ||
1282 | return(-1); | ||
1283 | } | ||
1284 | |||
1285 | static int ssl3_send_certificate_request(SSL *s) | ||
1286 | { | ||
1287 | unsigned char *p,*d; | ||
1288 | int i,j,nl,off,n; | ||
1289 | STACK_OF(X509_NAME) *sk=NULL; | ||
1290 | X509_NAME *name; | ||
1291 | BUF_MEM *buf; | ||
1292 | |||
1293 | if (s->state == SSL3_ST_SW_CERT_REQ_A) | ||
1294 | { | ||
1295 | buf=s->init_buf; | ||
1296 | |||
1297 | d=p=(unsigned char *)&(buf->data[4]); | ||
1298 | |||
1299 | /* get the list of acceptable cert types */ | ||
1300 | p++; | ||
1301 | n=ssl3_get_req_cert_type(s,p); | ||
1302 | d[0]=n; | ||
1303 | p+=n; | ||
1304 | n++; | ||
1305 | |||
1306 | off=n; | ||
1307 | p+=2; | ||
1308 | n+=2; | ||
1309 | |||
1310 | sk=SSL_get_client_CA_list(s); | ||
1311 | nl=0; | ||
1312 | if (sk != NULL) | ||
1313 | { | ||
1314 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
1315 | { | ||
1316 | name=sk_X509_NAME_value(sk,i); | ||
1317 | j=i2d_X509_NAME(name,NULL); | ||
1318 | if (!BUF_MEM_grow_clean(buf,4+n+j+2)) | ||
1319 | { | ||
1320 | SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); | ||
1321 | goto err; | ||
1322 | } | ||
1323 | p=(unsigned char *)&(buf->data[4+n]); | ||
1324 | if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
1325 | { | ||
1326 | s2n(j,p); | ||
1327 | i2d_X509_NAME(name,&p); | ||
1328 | n+=2+j; | ||
1329 | nl+=2+j; | ||
1330 | } | ||
1331 | else | ||
1332 | { | ||
1333 | d=p; | ||
1334 | i2d_X509_NAME(name,&p); | ||
1335 | j-=2; s2n(j,d); j+=2; | ||
1336 | n+=j; | ||
1337 | nl+=j; | ||
1338 | } | ||
1339 | } | ||
1340 | } | ||
1341 | /* else no CA names */ | ||
1342 | p=(unsigned char *)&(buf->data[4+off]); | ||
1343 | s2n(nl,p); | ||
1344 | |||
1345 | d=(unsigned char *)buf->data; | ||
1346 | *(d++)=SSL3_MT_CERTIFICATE_REQUEST; | ||
1347 | l2n3(n,d); | ||
1348 | |||
1349 | /* we should now have things packed up, so lets send | ||
1350 | * it off */ | ||
1351 | |||
1352 | s->init_num=n+4; | ||
1353 | s->init_off=0; | ||
1354 | #ifdef NETSCAPE_HANG_BUG | ||
1355 | p=(unsigned char *)s->init_buf->data + s->init_num; | ||
1356 | |||
1357 | /* do the header */ | ||
1358 | *(p++)=SSL3_MT_SERVER_DONE; | ||
1359 | *(p++)=0; | ||
1360 | *(p++)=0; | ||
1361 | *(p++)=0; | ||
1362 | s->init_num += 4; | ||
1363 | #endif | ||
1364 | |||
1365 | s->state = SSL3_ST_SW_CERT_REQ_B; | ||
1366 | } | ||
1367 | |||
1368 | /* SSL3_ST_SW_CERT_REQ_B */ | ||
1369 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1370 | err: | ||
1371 | return(-1); | ||
1372 | } | ||
1373 | |||
1374 | static int ssl3_get_client_key_exchange(SSL *s) | ||
1375 | { | ||
1376 | int i,al,ok; | ||
1377 | long n; | ||
1378 | unsigned long l; | ||
1379 | unsigned char *p; | ||
1380 | #ifndef OPENSSL_NO_RSA | ||
1381 | RSA *rsa=NULL; | ||
1382 | EVP_PKEY *pkey=NULL; | ||
1383 | #endif | ||
1384 | #ifndef OPENSSL_NO_DH | ||
1385 | BIGNUM *pub=NULL; | ||
1386 | DH *dh_srvr; | ||
1387 | #endif | ||
1388 | #ifndef OPENSSL_NO_KRB5 | ||
1389 | KSSL_ERR kssl_err; | ||
1390 | #endif /* OPENSSL_NO_KRB5 */ | ||
1391 | |||
1392 | n=ssl3_get_message(s, | ||
1393 | SSL3_ST_SR_KEY_EXCH_A, | ||
1394 | SSL3_ST_SR_KEY_EXCH_B, | ||
1395 | SSL3_MT_CLIENT_KEY_EXCHANGE, | ||
1396 | 2048, /* ??? */ | ||
1397 | &ok); | ||
1398 | |||
1399 | if (!ok) return((int)n); | ||
1400 | p=(unsigned char *)s->init_msg; | ||
1401 | |||
1402 | l=s->s3->tmp.new_cipher->algorithms; | ||
1403 | |||
1404 | #ifndef OPENSSL_NO_RSA | ||
1405 | if (l & SSL_kRSA) | ||
1406 | { | ||
1407 | /* FIX THIS UP EAY EAY EAY EAY */ | ||
1408 | if (s->s3->tmp.use_rsa_tmp) | ||
1409 | { | ||
1410 | if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL)) | ||
1411 | rsa=s->cert->rsa_tmp; | ||
1412 | /* Don't do a callback because rsa_tmp should | ||
1413 | * be sent already */ | ||
1414 | if (rsa == NULL) | ||
1415 | { | ||
1416 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1417 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY); | ||
1418 | goto f_err; | ||
1419 | |||
1420 | } | ||
1421 | } | ||
1422 | else | ||
1423 | { | ||
1424 | pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey; | ||
1425 | if ( (pkey == NULL) || | ||
1426 | (pkey->type != EVP_PKEY_RSA) || | ||
1427 | (pkey->pkey.rsa == NULL)) | ||
1428 | { | ||
1429 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1430 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE); | ||
1431 | goto f_err; | ||
1432 | } | ||
1433 | rsa=pkey->pkey.rsa; | ||
1434 | } | ||
1435 | |||
1436 | /* TLS */ | ||
1437 | if (s->version > SSL3_VERSION) | ||
1438 | { | ||
1439 | n2s(p,i); | ||
1440 | if (n != i+2) | ||
1441 | { | ||
1442 | if (!(s->options & SSL_OP_TLS_D5_BUG)) | ||
1443 | { | ||
1444 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG); | ||
1445 | goto err; | ||
1446 | } | ||
1447 | else | ||
1448 | p-=2; | ||
1449 | } | ||
1450 | else | ||
1451 | n=i; | ||
1452 | } | ||
1453 | |||
1454 | i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING); | ||
1455 | |||
1456 | al = -1; | ||
1457 | |||
1458 | if (i != SSL_MAX_MASTER_KEY_LENGTH) | ||
1459 | { | ||
1460 | al=SSL_AD_DECODE_ERROR; | ||
1461 | /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */ | ||
1462 | } | ||
1463 | |||
1464 | if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff)))) | ||
1465 | { | ||
1466 | /* The premaster secret must contain the same version number as the | ||
1467 | * ClientHello to detect version rollback attacks (strangely, the | ||
1468 | * protocol does not offer such protection for DH ciphersuites). | ||
1469 | * However, buggy clients exist that send the negotiated protocol | ||
1470 | * version instead if the server does not support the requested | ||
1471 | * protocol version. | ||
1472 | * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */ | ||
1473 | if (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) && | ||
1474 | (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff)))) | ||
1475 | { | ||
1476 | al=SSL_AD_DECODE_ERROR; | ||
1477 | /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */ | ||
1478 | |||
1479 | /* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack | ||
1480 | * (http://eprint.iacr.org/2003/052/) exploits the version | ||
1481 | * number check as a "bad version oracle" -- an alert would | ||
1482 | * reveal that the plaintext corresponding to some ciphertext | ||
1483 | * made up by the adversary is properly formatted except | ||
1484 | * that the version number is wrong. To avoid such attacks, | ||
1485 | * we should treat this just like any other decryption error. */ | ||
1486 | } | ||
1487 | } | ||
1488 | |||
1489 | if (al != -1) | ||
1490 | { | ||
1491 | /* Some decryption failure -- use random value instead as countermeasure | ||
1492 | * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding | ||
1493 | * (see RFC 2246, section 7.4.7.1). */ | ||
1494 | ERR_clear_error(); | ||
1495 | i = SSL_MAX_MASTER_KEY_LENGTH; | ||
1496 | p[0] = s->client_version >> 8; | ||
1497 | p[1] = s->client_version & 0xff; | ||
1498 | if(RAND_pseudo_bytes(p+2, i-2) <= 0) /* should be RAND_bytes, but we cannot work around a failure */ | ||
1499 | goto err; | ||
1500 | } | ||
1501 | |||
1502 | s->session->master_key_length= | ||
1503 | s->method->ssl3_enc->generate_master_secret(s, | ||
1504 | s->session->master_key, | ||
1505 | p,i); | ||
1506 | OPENSSL_cleanse(p,i); | ||
1507 | } | ||
1508 | else | ||
1509 | #endif | ||
1510 | #ifndef OPENSSL_NO_DH | ||
1511 | if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1512 | { | ||
1513 | n2s(p,i); | ||
1514 | if (n != i+2) | ||
1515 | { | ||
1516 | if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG)) | ||
1517 | { | ||
1518 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG); | ||
1519 | goto err; | ||
1520 | } | ||
1521 | else | ||
1522 | { | ||
1523 | p-=2; | ||
1524 | i=(int)n; | ||
1525 | } | ||
1526 | } | ||
1527 | |||
1528 | if (n == 0L) /* the parameters are in the cert */ | ||
1529 | { | ||
1530 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1531 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS); | ||
1532 | goto f_err; | ||
1533 | } | ||
1534 | else | ||
1535 | { | ||
1536 | if (s->s3->tmp.dh == NULL) | ||
1537 | { | ||
1538 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1539 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
1540 | goto f_err; | ||
1541 | } | ||
1542 | else | ||
1543 | dh_srvr=s->s3->tmp.dh; | ||
1544 | } | ||
1545 | |||
1546 | pub=BN_bin2bn(p,i,NULL); | ||
1547 | if (pub == NULL) | ||
1548 | { | ||
1549 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB); | ||
1550 | goto err; | ||
1551 | } | ||
1552 | |||
1553 | i=DH_compute_key(p,pub,dh_srvr); | ||
1554 | |||
1555 | if (i <= 0) | ||
1556 | { | ||
1557 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1558 | goto err; | ||
1559 | } | ||
1560 | |||
1561 | DH_free(s->s3->tmp.dh); | ||
1562 | s->s3->tmp.dh=NULL; | ||
1563 | |||
1564 | BN_clear_free(pub); | ||
1565 | pub=NULL; | ||
1566 | s->session->master_key_length= | ||
1567 | s->method->ssl3_enc->generate_master_secret(s, | ||
1568 | s->session->master_key,p,i); | ||
1569 | OPENSSL_cleanse(p,i); | ||
1570 | } | ||
1571 | else | ||
1572 | #endif | ||
1573 | #ifndef OPENSSL_NO_KRB5 | ||
1574 | if (l & SSL_kKRB5) | ||
1575 | { | ||
1576 | krb5_error_code krb5rc; | ||
1577 | krb5_data enc_ticket; | ||
1578 | krb5_data authenticator; | ||
1579 | krb5_data enc_pms; | ||
1580 | KSSL_CTX *kssl_ctx = s->kssl_ctx; | ||
1581 | EVP_CIPHER_CTX ciph_ctx; | ||
1582 | EVP_CIPHER *enc = NULL; | ||
1583 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
1584 | unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH | ||
1585 | + EVP_MAX_BLOCK_LENGTH]; | ||
1586 | int padl, outl; | ||
1587 | krb5_timestamp authtime = 0; | ||
1588 | krb5_ticket_times ttimes; | ||
1589 | |||
1590 | EVP_CIPHER_CTX_init(&ciph_ctx); | ||
1591 | |||
1592 | if (!kssl_ctx) kssl_ctx = kssl_ctx_new(); | ||
1593 | |||
1594 | n2s(p,i); | ||
1595 | enc_ticket.length = i; | ||
1596 | |||
1597 | if (n < (long)enc_ticket.length + 6) | ||
1598 | { | ||
1599 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1600 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1601 | goto err; | ||
1602 | } | ||
1603 | |||
1604 | enc_ticket.data = (char *)p; | ||
1605 | p+=enc_ticket.length; | ||
1606 | |||
1607 | n2s(p,i); | ||
1608 | authenticator.length = i; | ||
1609 | |||
1610 | if (n < (long)(enc_ticket.length + authenticator.length + 6)) | ||
1611 | { | ||
1612 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1613 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1614 | goto err; | ||
1615 | } | ||
1616 | |||
1617 | authenticator.data = (char *)p; | ||
1618 | p+=authenticator.length; | ||
1619 | |||
1620 | n2s(p,i); | ||
1621 | enc_pms.length = i; | ||
1622 | enc_pms.data = (char *)p; | ||
1623 | p+=enc_pms.length; | ||
1624 | |||
1625 | /* Note that the length is checked again below, | ||
1626 | ** after decryption | ||
1627 | */ | ||
1628 | if(enc_pms.length > sizeof pms) | ||
1629 | { | ||
1630 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1631 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1632 | goto err; | ||
1633 | } | ||
1634 | |||
1635 | if (n != (long)(enc_ticket.length + authenticator.length + | ||
1636 | enc_pms.length + 6)) | ||
1637 | { | ||
1638 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1639 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1640 | goto err; | ||
1641 | } | ||
1642 | |||
1643 | if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes, | ||
1644 | &kssl_err)) != 0) | ||
1645 | { | ||
1646 | #ifdef KSSL_DEBUG | ||
1647 | printf("kssl_sget_tkt rtn %d [%d]\n", | ||
1648 | krb5rc, kssl_err.reason); | ||
1649 | if (kssl_err.text) | ||
1650 | printf("kssl_err text= %s\n", kssl_err.text); | ||
1651 | #endif /* KSSL_DEBUG */ | ||
1652 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
1653 | kssl_err.reason); | ||
1654 | goto err; | ||
1655 | } | ||
1656 | |||
1657 | /* Note: no authenticator is not considered an error, | ||
1658 | ** but will return authtime == 0. | ||
1659 | */ | ||
1660 | if ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator, | ||
1661 | &authtime, &kssl_err)) != 0) | ||
1662 | { | ||
1663 | #ifdef KSSL_DEBUG | ||
1664 | printf("kssl_check_authent rtn %d [%d]\n", | ||
1665 | krb5rc, kssl_err.reason); | ||
1666 | if (kssl_err.text) | ||
1667 | printf("kssl_err text= %s\n", kssl_err.text); | ||
1668 | #endif /* KSSL_DEBUG */ | ||
1669 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, | ||
1670 | kssl_err.reason); | ||
1671 | goto err; | ||
1672 | } | ||
1673 | |||
1674 | if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0) | ||
1675 | { | ||
1676 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, krb5rc); | ||
1677 | goto err; | ||
1678 | } | ||
1679 | |||
1680 | #ifdef KSSL_DEBUG | ||
1681 | kssl_ctx_show(kssl_ctx); | ||
1682 | #endif /* KSSL_DEBUG */ | ||
1683 | |||
1684 | enc = kssl_map_enc(kssl_ctx->enctype); | ||
1685 | if (enc == NULL) | ||
1686 | goto err; | ||
1687 | |||
1688 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ | ||
1689 | |||
1690 | if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv)) | ||
1691 | { | ||
1692 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1693 | SSL_R_DECRYPTION_FAILED); | ||
1694 | goto err; | ||
1695 | } | ||
1696 | if (!EVP_DecryptUpdate(&ciph_ctx, pms,&outl, | ||
1697 | (unsigned char *)enc_pms.data, enc_pms.length)) | ||
1698 | { | ||
1699 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1700 | SSL_R_DECRYPTION_FAILED); | ||
1701 | goto err; | ||
1702 | } | ||
1703 | if (outl > SSL_MAX_MASTER_KEY_LENGTH) | ||
1704 | { | ||
1705 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1706 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1707 | goto err; | ||
1708 | } | ||
1709 | if (!EVP_DecryptFinal_ex(&ciph_ctx,&(pms[outl]),&padl)) | ||
1710 | { | ||
1711 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1712 | SSL_R_DECRYPTION_FAILED); | ||
1713 | goto err; | ||
1714 | } | ||
1715 | outl += padl; | ||
1716 | if (outl > SSL_MAX_MASTER_KEY_LENGTH) | ||
1717 | { | ||
1718 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1719 | SSL_R_DATA_LENGTH_TOO_LONG); | ||
1720 | goto err; | ||
1721 | } | ||
1722 | EVP_CIPHER_CTX_cleanup(&ciph_ctx); | ||
1723 | |||
1724 | s->session->master_key_length= | ||
1725 | s->method->ssl3_enc->generate_master_secret(s, | ||
1726 | s->session->master_key, pms, outl); | ||
1727 | |||
1728 | if (kssl_ctx->client_princ) | ||
1729 | { | ||
1730 | int len = strlen(kssl_ctx->client_princ); | ||
1731 | if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) | ||
1732 | { | ||
1733 | s->session->krb5_client_princ_len = len; | ||
1734 | memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len); | ||
1735 | } | ||
1736 | } | ||
1737 | |||
1738 | |||
1739 | /* Was doing kssl_ctx_free() here, | ||
1740 | ** but it caused problems for apache. | ||
1741 | ** kssl_ctx = kssl_ctx_free(kssl_ctx); | ||
1742 | ** if (s->kssl_ctx) s->kssl_ctx = NULL; | ||
1743 | */ | ||
1744 | } | ||
1745 | else | ||
1746 | #endif /* OPENSSL_NO_KRB5 */ | ||
1747 | { | ||
1748 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1749 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, | ||
1750 | SSL_R_UNKNOWN_CIPHER_TYPE); | ||
1751 | goto f_err; | ||
1752 | } | ||
1753 | |||
1754 | return(1); | ||
1755 | f_err: | ||
1756 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1757 | #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) | ||
1758 | err: | ||
1759 | #endif | ||
1760 | return(-1); | ||
1761 | } | ||
1762 | |||
1763 | static int ssl3_get_cert_verify(SSL *s) | ||
1764 | { | ||
1765 | EVP_PKEY *pkey=NULL; | ||
1766 | unsigned char *p; | ||
1767 | int al,ok,ret=0; | ||
1768 | long n; | ||
1769 | int type=0,i,j; | ||
1770 | X509 *peer; | ||
1771 | |||
1772 | n=ssl3_get_message(s, | ||
1773 | SSL3_ST_SR_CERT_VRFY_A, | ||
1774 | SSL3_ST_SR_CERT_VRFY_B, | ||
1775 | -1, | ||
1776 | 514, /* 514? */ | ||
1777 | &ok); | ||
1778 | |||
1779 | if (!ok) return((int)n); | ||
1780 | |||
1781 | if (s->session->peer != NULL) | ||
1782 | { | ||
1783 | peer=s->session->peer; | ||
1784 | pkey=X509_get_pubkey(peer); | ||
1785 | type=X509_certificate_type(peer,pkey); | ||
1786 | } | ||
1787 | else | ||
1788 | { | ||
1789 | peer=NULL; | ||
1790 | pkey=NULL; | ||
1791 | } | ||
1792 | |||
1793 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY) | ||
1794 | { | ||
1795 | s->s3->tmp.reuse_message=1; | ||
1796 | if ((peer != NULL) && (type | EVP_PKT_SIGN)) | ||
1797 | { | ||
1798 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1799 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE); | ||
1800 | goto f_err; | ||
1801 | } | ||
1802 | ret=1; | ||
1803 | goto end; | ||
1804 | } | ||
1805 | |||
1806 | if (peer == NULL) | ||
1807 | { | ||
1808 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED); | ||
1809 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1810 | goto f_err; | ||
1811 | } | ||
1812 | |||
1813 | if (!(type & EVP_PKT_SIGN)) | ||
1814 | { | ||
1815 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE); | ||
1816 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1817 | goto f_err; | ||
1818 | } | ||
1819 | |||
1820 | if (s->s3->change_cipher_spec) | ||
1821 | { | ||
1822 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY); | ||
1823 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1824 | goto f_err; | ||
1825 | } | ||
1826 | |||
1827 | /* we now have a signature that we need to verify */ | ||
1828 | p=(unsigned char *)s->init_msg; | ||
1829 | n2s(p,i); | ||
1830 | n-=2; | ||
1831 | if (i > n) | ||
1832 | { | ||
1833 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH); | ||
1834 | al=SSL_AD_DECODE_ERROR; | ||
1835 | goto f_err; | ||
1836 | } | ||
1837 | |||
1838 | j=EVP_PKEY_size(pkey); | ||
1839 | if ((i > j) || (n > j) || (n <= 0)) | ||
1840 | { | ||
1841 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE); | ||
1842 | al=SSL_AD_DECODE_ERROR; | ||
1843 | goto f_err; | ||
1844 | } | ||
1845 | |||
1846 | #ifndef OPENSSL_NO_RSA | ||
1847 | if (pkey->type == EVP_PKEY_RSA) | ||
1848 | { | ||
1849 | i=RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md, | ||
1850 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, p, i, | ||
1851 | pkey->pkey.rsa); | ||
1852 | if (i < 0) | ||
1853 | { | ||
1854 | al=SSL_AD_DECRYPT_ERROR; | ||
1855 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT); | ||
1856 | goto f_err; | ||
1857 | } | ||
1858 | if (i == 0) | ||
1859 | { | ||
1860 | al=SSL_AD_DECRYPT_ERROR; | ||
1861 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE); | ||
1862 | goto f_err; | ||
1863 | } | ||
1864 | } | ||
1865 | else | ||
1866 | #endif | ||
1867 | #ifndef OPENSSL_NO_DSA | ||
1868 | if (pkey->type == EVP_PKEY_DSA) | ||
1869 | { | ||
1870 | j=DSA_verify(pkey->save_type, | ||
1871 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]), | ||
1872 | SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa); | ||
1873 | if (j <= 0) | ||
1874 | { | ||
1875 | /* bad signature */ | ||
1876 | al=SSL_AD_DECRYPT_ERROR; | ||
1877 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE); | ||
1878 | goto f_err; | ||
1879 | } | ||
1880 | } | ||
1881 | else | ||
1882 | #endif | ||
1883 | { | ||
1884 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,ERR_R_INTERNAL_ERROR); | ||
1885 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; | ||
1886 | goto f_err; | ||
1887 | } | ||
1888 | |||
1889 | |||
1890 | ret=1; | ||
1891 | if (0) | ||
1892 | { | ||
1893 | f_err: | ||
1894 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1895 | } | ||
1896 | end: | ||
1897 | EVP_PKEY_free(pkey); | ||
1898 | return(ret); | ||
1899 | } | ||
1900 | |||
1901 | static int ssl3_get_client_certificate(SSL *s) | ||
1902 | { | ||
1903 | int i,ok,al,ret= -1; | ||
1904 | X509 *x=NULL; | ||
1905 | unsigned long l,nc,llen,n; | ||
1906 | unsigned char *p,*d,*q; | ||
1907 | STACK_OF(X509) *sk=NULL; | ||
1908 | |||
1909 | n=ssl3_get_message(s, | ||
1910 | SSL3_ST_SR_CERT_A, | ||
1911 | SSL3_ST_SR_CERT_B, | ||
1912 | -1, | ||
1913 | s->max_cert_list, | ||
1914 | &ok); | ||
1915 | |||
1916 | if (!ok) return((int)n); | ||
1917 | |||
1918 | if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) | ||
1919 | { | ||
1920 | if ( (s->verify_mode & SSL_VERIFY_PEER) && | ||
1921 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
1922 | { | ||
1923 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
1924 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1925 | goto f_err; | ||
1926 | } | ||
1927 | /* If tls asked for a client cert, the client must return a 0 list */ | ||
1928 | if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request) | ||
1929 | { | ||
1930 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST); | ||
1931 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1932 | goto f_err; | ||
1933 | } | ||
1934 | s->s3->tmp.reuse_message=1; | ||
1935 | return(1); | ||
1936 | } | ||
1937 | |||
1938 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
1939 | { | ||
1940 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1941 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE); | ||
1942 | goto f_err; | ||
1943 | } | ||
1944 | d=p=(unsigned char *)s->init_msg; | ||
1945 | |||
1946 | if ((sk=sk_X509_new_null()) == NULL) | ||
1947 | { | ||
1948 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
1949 | goto err; | ||
1950 | } | ||
1951 | |||
1952 | n2l3(p,llen); | ||
1953 | if (llen+3 != n) | ||
1954 | { | ||
1955 | al=SSL_AD_DECODE_ERROR; | ||
1956 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
1957 | goto f_err; | ||
1958 | } | ||
1959 | for (nc=0; nc<llen; ) | ||
1960 | { | ||
1961 | n2l3(p,l); | ||
1962 | if ((l+nc+3) > llen) | ||
1963 | { | ||
1964 | al=SSL_AD_DECODE_ERROR; | ||
1965 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
1966 | goto f_err; | ||
1967 | } | ||
1968 | |||
1969 | q=p; | ||
1970 | x=d2i_X509(NULL,&p,l); | ||
1971 | if (x == NULL) | ||
1972 | { | ||
1973 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB); | ||
1974 | goto err; | ||
1975 | } | ||
1976 | if (p != (q+l)) | ||
1977 | { | ||
1978 | al=SSL_AD_DECODE_ERROR; | ||
1979 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
1980 | goto f_err; | ||
1981 | } | ||
1982 | if (!sk_X509_push(sk,x)) | ||
1983 | { | ||
1984 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
1985 | goto err; | ||
1986 | } | ||
1987 | x=NULL; | ||
1988 | nc+=l+3; | ||
1989 | } | ||
1990 | |||
1991 | if (sk_X509_num(sk) <= 0) | ||
1992 | { | ||
1993 | /* TLS does not mind 0 certs returned */ | ||
1994 | if (s->version == SSL3_VERSION) | ||
1995 | { | ||
1996 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1997 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED); | ||
1998 | goto f_err; | ||
1999 | } | ||
2000 | /* Fail for TLS only if we required a certificate */ | ||
2001 | else if ((s->verify_mode & SSL_VERIFY_PEER) && | ||
2002 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
2003 | { | ||
2004 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
2005 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
2006 | goto f_err; | ||
2007 | } | ||
2008 | } | ||
2009 | else | ||
2010 | { | ||
2011 | i=ssl_verify_cert_chain(s,sk); | ||
2012 | if (!i) | ||
2013 | { | ||
2014 | al=ssl_verify_alarm_type(s->verify_result); | ||
2015 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED); | ||
2016 | goto f_err; | ||
2017 | } | ||
2018 | } | ||
2019 | |||
2020 | if (s->session->peer != NULL) /* This should not be needed */ | ||
2021 | X509_free(s->session->peer); | ||
2022 | s->session->peer=sk_X509_shift(sk); | ||
2023 | s->session->verify_result = s->verify_result; | ||
2024 | |||
2025 | /* With the current implementation, sess_cert will always be NULL | ||
2026 | * when we arrive here. */ | ||
2027 | if (s->session->sess_cert == NULL) | ||
2028 | { | ||
2029 | s->session->sess_cert = ssl_sess_cert_new(); | ||
2030 | if (s->session->sess_cert == NULL) | ||
2031 | { | ||
2032 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE); | ||
2033 | goto err; | ||
2034 | } | ||
2035 | } | ||
2036 | if (s->session->sess_cert->cert_chain != NULL) | ||
2037 | sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free); | ||
2038 | s->session->sess_cert->cert_chain=sk; | ||
2039 | /* Inconsistency alert: cert_chain does *not* include the | ||
2040 | * peer's own certificate, while we do include it in s3_clnt.c */ | ||
2041 | |||
2042 | sk=NULL; | ||
2043 | |||
2044 | ret=1; | ||
2045 | if (0) | ||
2046 | { | ||
2047 | f_err: | ||
2048 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
2049 | } | ||
2050 | err: | ||
2051 | if (x != NULL) X509_free(x); | ||
2052 | if (sk != NULL) sk_X509_pop_free(sk,X509_free); | ||
2053 | return(ret); | ||
2054 | } | ||
2055 | |||
2056 | int ssl3_send_server_certificate(SSL *s) | ||
2057 | { | ||
2058 | unsigned long l; | ||
2059 | X509 *x; | ||
2060 | |||
2061 | if (s->state == SSL3_ST_SW_CERT_A) | ||
2062 | { | ||
2063 | x=ssl_get_server_send_cert(s); | ||
2064 | if (x == NULL && | ||
2065 | /* VRS: allow null cert if auth == KRB5 */ | ||
2066 | (s->s3->tmp.new_cipher->algorithms | ||
2067 | & (SSL_MKEY_MASK|SSL_AUTH_MASK)) | ||
2068 | != (SSL_aKRB5|SSL_kKRB5)) | ||
2069 | { | ||
2070 | SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR); | ||
2071 | return(0); | ||
2072 | } | ||
2073 | |||
2074 | l=ssl3_output_cert_chain(s,x); | ||
2075 | s->state=SSL3_ST_SW_CERT_B; | ||
2076 | s->init_num=(int)l; | ||
2077 | s->init_off=0; | ||
2078 | } | ||
2079 | |||
2080 | /* SSL3_ST_SW_CERT_B */ | ||
2081 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
2082 | } | ||
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version deleted file mode 100644 index f461c53390..0000000000 --- a/src/lib/libssl/shlib_version +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | major=11 | ||
2 | minor=0 | ||
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h deleted file mode 100644 index 99e188086b..0000000000 --- a/src/lib/libssl/ssl.h +++ /dev/null | |||
@@ -1,1853 +0,0 @@ | |||
1 | /* ssl/ssl.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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | /* ==================================================================== | ||
112 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
113 | * | ||
114 | * Redistribution and use in source and binary forms, with or without | ||
115 | * modification, are permitted provided that the following conditions | ||
116 | * are met: | ||
117 | * | ||
118 | * 1. Redistributions of source code must retain the above copyright | ||
119 | * notice, this list of conditions and the following disclaimer. | ||
120 | * | ||
121 | * 2. Redistributions in binary form must reproduce the above copyright | ||
122 | * notice, this list of conditions and the following disclaimer in | ||
123 | * the documentation and/or other materials provided with the | ||
124 | * distribution. | ||
125 | * | ||
126 | * 3. All advertising materials mentioning features or use of this | ||
127 | * software must display the following acknowledgment: | ||
128 | * "This product includes software developed by the OpenSSL Project | ||
129 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
130 | * | ||
131 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
132 | * endorse or promote products derived from this software without | ||
133 | * prior written permission. For written permission, please contact | ||
134 | * openssl-core@openssl.org. | ||
135 | * | ||
136 | * 5. Products derived from this software may not be called "OpenSSL" | ||
137 | * nor may "OpenSSL" appear in their names without prior written | ||
138 | * permission of the OpenSSL Project. | ||
139 | * | ||
140 | * 6. Redistributions of any form whatsoever must retain the following | ||
141 | * acknowledgment: | ||
142 | * "This product includes software developed by the OpenSSL Project | ||
143 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
144 | * | ||
145 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
146 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
147 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
148 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
149 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
150 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
151 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
152 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
153 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
154 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
155 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
156 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
157 | * ==================================================================== | ||
158 | * | ||
159 | * This product includes cryptographic software written by Eric Young | ||
160 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
161 | * Hudson (tjh@cryptsoft.com). | ||
162 | * | ||
163 | */ | ||
164 | |||
165 | #ifndef HEADER_SSL_H | ||
166 | #define HEADER_SSL_H | ||
167 | |||
168 | #include <openssl/e_os2.h> | ||
169 | |||
170 | #ifndef OPENSSL_NO_COMP | ||
171 | #include <openssl/comp.h> | ||
172 | #endif | ||
173 | #ifndef OPENSSL_NO_BIO | ||
174 | #include <openssl/bio.h> | ||
175 | #endif | ||
176 | #ifndef OPENSSL_NO_X509 | ||
177 | #include <openssl/x509.h> | ||
178 | #endif | ||
179 | #include <openssl/kssl.h> | ||
180 | #include <openssl/safestack.h> | ||
181 | #include <openssl/symhacks.h> | ||
182 | |||
183 | #ifdef __cplusplus | ||
184 | extern "C" { | ||
185 | #endif | ||
186 | |||
187 | /* SSLeay version number for ASN.1 encoding of the session information */ | ||
188 | /* Version 0 - initial version | ||
189 | * Version 1 - added the optional peer certificate | ||
190 | */ | ||
191 | #define SSL_SESSION_ASN1_VERSION 0x0001 | ||
192 | |||
193 | /* text strings for the ciphers */ | ||
194 | #define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5 | ||
195 | #define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5 | ||
196 | #define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 | ||
197 | #define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5 | ||
198 | #define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 | ||
199 | #define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5 | ||
200 | #define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5 | ||
201 | #define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA | ||
202 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 | ||
203 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA | ||
204 | |||
205 | /* VRS Additional Kerberos5 entries | ||
206 | */ | ||
207 | #define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA | ||
208 | #define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA | ||
209 | #define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA | ||
210 | #define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA | ||
211 | #define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5 | ||
212 | #define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5 | ||
213 | #define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5 | ||
214 | #define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5 | ||
215 | |||
216 | #define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA | ||
217 | #define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA | ||
218 | #define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA | ||
219 | #define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 | ||
220 | #define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5 | ||
221 | #define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5 | ||
222 | |||
223 | #define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA | ||
224 | #define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 | ||
225 | #define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA | ||
226 | #define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5 | ||
227 | #define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA | ||
228 | #define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5 | ||
229 | #define SSL_MAX_KRB5_PRINCIPAL_LENGTH 256 | ||
230 | |||
231 | #define SSL_MAX_SSL_SESSION_ID_LENGTH 32 | ||
232 | #define SSL_MAX_SID_CTX_LENGTH 32 | ||
233 | |||
234 | #define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) | ||
235 | #define SSL_MAX_KEY_ARG_LENGTH 8 | ||
236 | #define SSL_MAX_MASTER_KEY_LENGTH 48 | ||
237 | |||
238 | /* These are used to specify which ciphers to use and not to use */ | ||
239 | #define SSL_TXT_LOW "LOW" | ||
240 | #define SSL_TXT_MEDIUM "MEDIUM" | ||
241 | #define SSL_TXT_HIGH "HIGH" | ||
242 | #define SSL_TXT_FIPS "FIPS" | ||
243 | #define SSL_TXT_kFZA "kFZA" | ||
244 | #define SSL_TXT_aFZA "aFZA" | ||
245 | #define SSL_TXT_eFZA "eFZA" | ||
246 | #define SSL_TXT_FZA "FZA" | ||
247 | |||
248 | #define SSL_TXT_aNULL "aNULL" | ||
249 | #define SSL_TXT_eNULL "eNULL" | ||
250 | #define SSL_TXT_NULL "NULL" | ||
251 | |||
252 | #define SSL_TXT_kKRB5 "kKRB5" | ||
253 | #define SSL_TXT_aKRB5 "aKRB5" | ||
254 | #define SSL_TXT_KRB5 "KRB5" | ||
255 | |||
256 | #define SSL_TXT_kRSA "kRSA" | ||
257 | #define SSL_TXT_kDHr "kDHr" | ||
258 | #define SSL_TXT_kDHd "kDHd" | ||
259 | #define SSL_TXT_kEDH "kEDH" | ||
260 | #define SSL_TXT_aRSA "aRSA" | ||
261 | #define SSL_TXT_aDSS "aDSS" | ||
262 | #define SSL_TXT_aDH "aDH" | ||
263 | #define SSL_TXT_DSS "DSS" | ||
264 | #define SSL_TXT_DH "DH" | ||
265 | #define SSL_TXT_EDH "EDH" | ||
266 | #define SSL_TXT_ADH "ADH" | ||
267 | #define SSL_TXT_RSA "RSA" | ||
268 | #define SSL_TXT_DES "DES" | ||
269 | #define SSL_TXT_3DES "3DES" | ||
270 | #define SSL_TXT_RC4 "RC4" | ||
271 | #define SSL_TXT_RC2 "RC2" | ||
272 | #define SSL_TXT_IDEA "IDEA" | ||
273 | #define SSL_TXT_AES "AES" | ||
274 | #define SSL_TXT_MD5 "MD5" | ||
275 | #define SSL_TXT_SHA1 "SHA1" | ||
276 | #define SSL_TXT_SHA "SHA" | ||
277 | #define SSL_TXT_EXP "EXP" | ||
278 | #define SSL_TXT_EXPORT "EXPORT" | ||
279 | #define SSL_TXT_EXP40 "EXPORT40" | ||
280 | #define SSL_TXT_EXP56 "EXPORT56" | ||
281 | #define SSL_TXT_SSLV2 "SSLv2" | ||
282 | #define SSL_TXT_SSLV3 "SSLv3" | ||
283 | #define SSL_TXT_TLSV1 "TLSv1" | ||
284 | #define SSL_TXT_ALL "ALL" | ||
285 | |||
286 | /* | ||
287 | * COMPLEMENTOF* definitions. These identifiers are used to (de-select) | ||
288 | * ciphers normally not being used. | ||
289 | * Example: "RC4" will activate all ciphers using RC4 including ciphers | ||
290 | * without authentication, which would normally disabled by DEFAULT (due | ||
291 | * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT" | ||
292 | * will make sure that it is also disabled in the specific selection. | ||
293 | * COMPLEMENTOF* identifiers are portable between version, as adjustments | ||
294 | * to the default cipher setup will also be included here. | ||
295 | * | ||
296 | * COMPLEMENTOFDEFAULT does not experience the same special treatment that | ||
297 | * DEFAULT gets, as only selection is being done and no sorting as needed | ||
298 | * for DEFAULT. | ||
299 | */ | ||
300 | #define SSL_TXT_CMPALL "COMPLEMENTOFALL" | ||
301 | #define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT" | ||
302 | |||
303 | /* The following cipher list is used by default. | ||
304 | * It also is substituted when an application-defined cipher list string | ||
305 | * starts with 'DEFAULT'. */ | ||
306 | #define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:+RC4:@STRENGTH" /* low priority for RC4 */ | ||
307 | |||
308 | /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ | ||
309 | #define SSL_SENT_SHUTDOWN 1 | ||
310 | #define SSL_RECEIVED_SHUTDOWN 2 | ||
311 | |||
312 | #ifdef __cplusplus | ||
313 | } | ||
314 | #endif | ||
315 | |||
316 | #include <openssl/crypto.h> | ||
317 | #include <openssl/lhash.h> | ||
318 | #include <openssl/buffer.h> | ||
319 | #include <openssl/pem.h> | ||
320 | |||
321 | #ifdef __cplusplus | ||
322 | extern "C" { | ||
323 | #endif | ||
324 | |||
325 | #if (defined(OPENSSL_NO_RSA) || defined(OPENSSL_NO_MD5)) && !defined(OPENSSL_NO_SSL2) | ||
326 | #define OPENSSL_NO_SSL2 | ||
327 | #endif | ||
328 | |||
329 | #define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 | ||
330 | #define SSL_FILETYPE_PEM X509_FILETYPE_PEM | ||
331 | |||
332 | /* This is needed to stop compilers complaining about the | ||
333 | * 'struct ssl_st *' function parameters used to prototype callbacks | ||
334 | * in SSL_CTX. */ | ||
335 | typedef struct ssl_st *ssl_crock_st; | ||
336 | |||
337 | /* used to hold info on the particular ciphers used */ | ||
338 | typedef struct ssl_cipher_st | ||
339 | { | ||
340 | int valid; | ||
341 | const char *name; /* text name */ | ||
342 | unsigned long id; /* id, 4 bytes, first is version */ | ||
343 | unsigned long algorithms; /* what ciphers are used */ | ||
344 | unsigned long algo_strength; /* strength and export flags */ | ||
345 | unsigned long algorithm2; /* Extra flags */ | ||
346 | int strength_bits; /* Number of bits really used */ | ||
347 | int alg_bits; /* Number of bits for algorithm */ | ||
348 | unsigned long mask; /* used for matching */ | ||
349 | unsigned long mask_strength; /* also used for matching */ | ||
350 | } SSL_CIPHER; | ||
351 | |||
352 | DECLARE_STACK_OF(SSL_CIPHER) | ||
353 | |||
354 | typedef struct ssl_st SSL; | ||
355 | typedef struct ssl_ctx_st SSL_CTX; | ||
356 | |||
357 | /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */ | ||
358 | typedef struct ssl_method_st | ||
359 | { | ||
360 | int version; | ||
361 | int (*ssl_new)(SSL *s); | ||
362 | void (*ssl_clear)(SSL *s); | ||
363 | void (*ssl_free)(SSL *s); | ||
364 | int (*ssl_accept)(SSL *s); | ||
365 | int (*ssl_connect)(SSL *s); | ||
366 | int (*ssl_read)(SSL *s,void *buf,int len); | ||
367 | int (*ssl_peek)(SSL *s,void *buf,int len); | ||
368 | int (*ssl_write)(SSL *s,const void *buf,int len); | ||
369 | int (*ssl_shutdown)(SSL *s); | ||
370 | int (*ssl_renegotiate)(SSL *s); | ||
371 | int (*ssl_renegotiate_check)(SSL *s); | ||
372 | long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg); | ||
373 | long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg); | ||
374 | SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); | ||
375 | int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr); | ||
376 | int (*ssl_pending)(const SSL *s); | ||
377 | int (*num_ciphers)(void); | ||
378 | SSL_CIPHER *(*get_cipher)(unsigned ncipher); | ||
379 | struct ssl_method_st *(*get_ssl_method)(int version); | ||
380 | long (*get_timeout)(void); | ||
381 | struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ | ||
382 | int (*ssl_version)(); | ||
383 | long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)()); | ||
384 | long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)()); | ||
385 | } SSL_METHOD; | ||
386 | |||
387 | /* Lets make this into an ASN.1 type structure as follows | ||
388 | * SSL_SESSION_ID ::= SEQUENCE { | ||
389 | * version INTEGER, -- structure version number | ||
390 | * SSLversion INTEGER, -- SSL version number | ||
391 | * Cipher OCTET_STRING, -- the 3 byte cipher ID | ||
392 | * Session_ID OCTET_STRING, -- the Session ID | ||
393 | * Master_key OCTET_STRING, -- the master key | ||
394 | * KRB5_principal OCTET_STRING -- optional Kerberos principal | ||
395 | * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument | ||
396 | * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time | ||
397 | * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds | ||
398 | * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate | ||
399 | * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context | ||
400 | * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer' | ||
401 | * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX | ||
402 | * } | ||
403 | * Look in ssl/ssl_asn1.c for more details | ||
404 | * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-). | ||
405 | */ | ||
406 | typedef struct ssl_session_st | ||
407 | { | ||
408 | int ssl_version; /* what ssl version session info is | ||
409 | * being kept in here? */ | ||
410 | |||
411 | /* only really used in SSLv2 */ | ||
412 | unsigned int key_arg_length; | ||
413 | unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH]; | ||
414 | int master_key_length; | ||
415 | unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH]; | ||
416 | /* session_id - valid? */ | ||
417 | unsigned int session_id_length; | ||
418 | unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH]; | ||
419 | /* this is used to determine whether the session is being reused in | ||
420 | * the appropriate context. It is up to the application to set this, | ||
421 | * via SSL_new */ | ||
422 | unsigned int sid_ctx_length; | ||
423 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
424 | |||
425 | #ifndef OPENSSL_NO_KRB5 | ||
426 | unsigned int krb5_client_princ_len; | ||
427 | unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH]; | ||
428 | #endif /* OPENSSL_NO_KRB5 */ | ||
429 | |||
430 | int not_resumable; | ||
431 | |||
432 | /* The cert is the certificate used to establish this connection */ | ||
433 | struct sess_cert_st /* SESS_CERT */ *sess_cert; | ||
434 | |||
435 | /* This is the cert for the other end. | ||
436 | * On clients, it will be the same as sess_cert->peer_key->x509 | ||
437 | * (the latter is not enough as sess_cert is not retained | ||
438 | * in the external representation of sessions, see ssl_asn1.c). */ | ||
439 | X509 *peer; | ||
440 | /* when app_verify_callback accepts a session where the peer's certificate | ||
441 | * is not ok, we must remember the error for session reuse: */ | ||
442 | long verify_result; /* only for servers */ | ||
443 | |||
444 | int references; | ||
445 | long timeout; | ||
446 | long time; | ||
447 | |||
448 | int compress_meth; /* Need to lookup the method */ | ||
449 | |||
450 | SSL_CIPHER *cipher; | ||
451 | unsigned long cipher_id; /* when ASN.1 loaded, this | ||
452 | * needs to be used to load | ||
453 | * the 'cipher' structure */ | ||
454 | |||
455 | STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */ | ||
456 | |||
457 | CRYPTO_EX_DATA ex_data; /* application specific data */ | ||
458 | |||
459 | /* These are used to make removal of session-ids more | ||
460 | * efficient and to implement a maximum cache size. */ | ||
461 | struct ssl_session_st *prev,*next; | ||
462 | } SSL_SESSION; | ||
463 | |||
464 | |||
465 | #define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L | ||
466 | #define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L | ||
467 | #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L | ||
468 | #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L | ||
469 | #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L | ||
470 | #define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L /* no effect since 0.9.7h and 0.9.8b */ | ||
471 | #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L | ||
472 | #define SSL_OP_TLS_D5_BUG 0x00000100L | ||
473 | #define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L | ||
474 | |||
475 | /* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added | ||
476 | * in OpenSSL 0.9.6d. Usually (depending on the application protocol) | ||
477 | * the workaround is not needed. Unfortunately some broken SSL/TLS | ||
478 | * implementations cannot handle it at all, which is why we include | ||
479 | * it in SSL_OP_ALL. */ | ||
480 | #define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L /* added in 0.9.6e */ | ||
481 | |||
482 | /* SSL_OP_ALL: various bug workarounds that should be rather harmless. | ||
483 | * This used to be 0x000FFFFFL before 0.9.7. */ | ||
484 | #define SSL_OP_ALL 0x00000FFFL | ||
485 | |||
486 | /* As server, disallow session resumption on renegotiation */ | ||
487 | #define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L | ||
488 | /* If set, always create a new key when using tmp_dh parameters */ | ||
489 | #define SSL_OP_SINGLE_DH_USE 0x00100000L | ||
490 | /* Set to always use the tmp_rsa key when doing RSA operations, | ||
491 | * even when this violates protocol specs */ | ||
492 | #define SSL_OP_EPHEMERAL_RSA 0x00200000L | ||
493 | /* Set on servers to choose the cipher according to the server's | ||
494 | * preferences */ | ||
495 | #define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L | ||
496 | /* If set, a server will allow a client to issue a SSLv3.0 version number | ||
497 | * as latest version supported in the premaster secret, even when TLSv1.0 | ||
498 | * (version 3.1) was announced in the client hello. Normally this is | ||
499 | * forbidden to prevent version rollback attacks. */ | ||
500 | #define SSL_OP_TLS_ROLLBACK_BUG 0x00800000L | ||
501 | |||
502 | #define SSL_OP_NO_SSLv2 0x01000000L | ||
503 | #define SSL_OP_NO_SSLv3 0x02000000L | ||
504 | #define SSL_OP_NO_TLSv1 0x04000000L | ||
505 | |||
506 | /* The next flag deliberately changes the ciphertest, this is a check | ||
507 | * for the PKCS#1 attack */ | ||
508 | #define SSL_OP_PKCS1_CHECK_1 0x08000000L | ||
509 | #define SSL_OP_PKCS1_CHECK_2 0x10000000L | ||
510 | #define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L | ||
511 | #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x40000000L | ||
512 | |||
513 | |||
514 | /* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success | ||
515 | * when just a single record has been written): */ | ||
516 | #define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L | ||
517 | /* Make it possible to retry SSL_write() with changed buffer location | ||
518 | * (buffer contents must stay the same!); this is not the default to avoid | ||
519 | * the misconception that non-blocking SSL_write() behaves like | ||
520 | * non-blocking write(): */ | ||
521 | #define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L | ||
522 | /* Never bother the application with retries if the transport | ||
523 | * is blocking: */ | ||
524 | #define SSL_MODE_AUTO_RETRY 0x00000004L | ||
525 | /* Don't attempt to automatically build certificate chain */ | ||
526 | #define SSL_MODE_NO_AUTO_CHAIN 0x00000008L | ||
527 | |||
528 | |||
529 | /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, | ||
530 | * they cannot be used to clear bits. */ | ||
531 | |||
532 | #define SSL_CTX_set_options(ctx,op) \ | ||
533 | SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL) | ||
534 | #define SSL_CTX_get_options(ctx) \ | ||
535 | SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL) | ||
536 | #define SSL_set_options(ssl,op) \ | ||
537 | SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL) | ||
538 | #define SSL_get_options(ssl) \ | ||
539 | SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL) | ||
540 | |||
541 | #define SSL_CTX_set_mode(ctx,op) \ | ||
542 | SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) | ||
543 | #define SSL_CTX_get_mode(ctx) \ | ||
544 | SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL) | ||
545 | #define SSL_set_mode(ssl,op) \ | ||
546 | SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) | ||
547 | #define SSL_get_mode(ssl) \ | ||
548 | SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL) | ||
549 | |||
550 | |||
551 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); | ||
552 | void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)); | ||
553 | #define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) | ||
554 | #define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg)) | ||
555 | |||
556 | |||
557 | |||
558 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) | ||
559 | #define SSL_MAX_CERT_LIST_DEFAULT 1024*30 /* 30k max cert list :-) */ | ||
560 | #else | ||
561 | #define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */ | ||
562 | #endif | ||
563 | |||
564 | #define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) | ||
565 | |||
566 | /* This callback type is used inside SSL_CTX, SSL, and in the functions that set | ||
567 | * them. It is used to override the generation of SSL/TLS session IDs in a | ||
568 | * server. Return value should be zero on an error, non-zero to proceed. Also, | ||
569 | * callbacks should themselves check if the id they generate is unique otherwise | ||
570 | * the SSL handshake will fail with an error - callbacks can do this using the | ||
571 | * 'ssl' value they're passed by; | ||
572 | * SSL_has_matching_session_id(ssl, id, *id_len) | ||
573 | * The length value passed in is set at the maximum size the session ID can be. | ||
574 | * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback | ||
575 | * can alter this length to be less if desired, but under SSLv2 session IDs are | ||
576 | * supposed to be fixed at 16 bytes so the id will be padded after the callback | ||
577 | * returns in this case. It is also an error for the callback to set the size to | ||
578 | * zero. */ | ||
579 | typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id, | ||
580 | unsigned int *id_len); | ||
581 | |||
582 | typedef struct ssl_comp_st | ||
583 | { | ||
584 | int id; | ||
585 | char *name; | ||
586 | #ifndef OPENSSL_NO_COMP | ||
587 | COMP_METHOD *method; | ||
588 | #else | ||
589 | char *method; | ||
590 | #endif | ||
591 | } SSL_COMP; | ||
592 | |||
593 | DECLARE_STACK_OF(SSL_COMP) | ||
594 | |||
595 | struct ssl_ctx_st | ||
596 | { | ||
597 | SSL_METHOD *method; | ||
598 | |||
599 | STACK_OF(SSL_CIPHER) *cipher_list; | ||
600 | /* same as above but sorted for lookup */ | ||
601 | STACK_OF(SSL_CIPHER) *cipher_list_by_id; | ||
602 | |||
603 | struct x509_store_st /* X509_STORE */ *cert_store; | ||
604 | struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */ | ||
605 | /* Most session-ids that will be cached, default is | ||
606 | * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */ | ||
607 | unsigned long session_cache_size; | ||
608 | struct ssl_session_st *session_cache_head; | ||
609 | struct ssl_session_st *session_cache_tail; | ||
610 | |||
611 | /* This can have one of 2 values, ored together, | ||
612 | * SSL_SESS_CACHE_CLIENT, | ||
613 | * SSL_SESS_CACHE_SERVER, | ||
614 | * Default is SSL_SESSION_CACHE_SERVER, which means only | ||
615 | * SSL_accept which cache SSL_SESSIONS. */ | ||
616 | int session_cache_mode; | ||
617 | |||
618 | /* If timeout is not 0, it is the default timeout value set | ||
619 | * when SSL_new() is called. This has been put in to make | ||
620 | * life easier to set things up */ | ||
621 | long session_timeout; | ||
622 | |||
623 | /* If this callback is not null, it will be called each | ||
624 | * time a session id is added to the cache. If this function | ||
625 | * returns 1, it means that the callback will do a | ||
626 | * SSL_SESSION_free() when it has finished using it. Otherwise, | ||
627 | * on 0, it means the callback has finished with it. | ||
628 | * If remove_session_cb is not null, it will be called when | ||
629 | * a session-id is removed from the cache. After the call, | ||
630 | * OpenSSL will SSL_SESSION_free() it. */ | ||
631 | int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess); | ||
632 | void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess); | ||
633 | SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, | ||
634 | unsigned char *data,int len,int *copy); | ||
635 | |||
636 | struct | ||
637 | { | ||
638 | int sess_connect; /* SSL new conn - started */ | ||
639 | int sess_connect_renegotiate;/* SSL reneg - requested */ | ||
640 | int sess_connect_good; /* SSL new conne/reneg - finished */ | ||
641 | int sess_accept; /* SSL new accept - started */ | ||
642 | int sess_accept_renegotiate;/* SSL reneg - requested */ | ||
643 | int sess_accept_good; /* SSL accept/reneg - finished */ | ||
644 | int sess_miss; /* session lookup misses */ | ||
645 | int sess_timeout; /* reuse attempt on timeouted session */ | ||
646 | int sess_cache_full; /* session removed due to full cache */ | ||
647 | int sess_hit; /* session reuse actually done */ | ||
648 | int sess_cb_hit; /* session-id that was not | ||
649 | * in the cache was | ||
650 | * passed back via the callback. This | ||
651 | * indicates that the application is | ||
652 | * supplying session-id's from other | ||
653 | * processes - spooky :-) */ | ||
654 | } stats; | ||
655 | |||
656 | int references; | ||
657 | |||
658 | /* if defined, these override the X509_verify_cert() calls */ | ||
659 | int (*app_verify_callback)(X509_STORE_CTX *, void *); | ||
660 | void *app_verify_arg; | ||
661 | /* before OpenSSL 0.9.7, 'app_verify_arg' was ignored | ||
662 | * ('app_verify_callback' was called with just one argument) */ | ||
663 | |||
664 | /* Default password callback. */ | ||
665 | pem_password_cb *default_passwd_callback; | ||
666 | |||
667 | /* Default password callback user data. */ | ||
668 | void *default_passwd_callback_userdata; | ||
669 | |||
670 | /* get client cert callback */ | ||
671 | int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey); | ||
672 | |||
673 | CRYPTO_EX_DATA ex_data; | ||
674 | |||
675 | const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ | ||
676 | const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */ | ||
677 | const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */ | ||
678 | |||
679 | STACK_OF(X509) *extra_certs; | ||
680 | STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */ | ||
681 | |||
682 | |||
683 | /* Default values used when no per-SSL value is defined follow */ | ||
684 | |||
685 | void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */ | ||
686 | |||
687 | /* what we put in client cert requests */ | ||
688 | STACK_OF(X509_NAME) *client_CA; | ||
689 | |||
690 | |||
691 | /* Default values to use in SSL structures follow (these are copied by SSL_new) */ | ||
692 | |||
693 | unsigned long options; | ||
694 | unsigned long mode; | ||
695 | long max_cert_list; | ||
696 | |||
697 | struct cert_st /* CERT */ *cert; | ||
698 | int read_ahead; | ||
699 | |||
700 | /* callback that allows applications to peek at protocol messages */ | ||
701 | void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg); | ||
702 | void *msg_callback_arg; | ||
703 | |||
704 | int verify_mode; | ||
705 | int verify_depth; | ||
706 | unsigned int sid_ctx_length; | ||
707 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
708 | int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */ | ||
709 | |||
710 | /* Default generate session ID callback. */ | ||
711 | GEN_SESSION_CB generate_session_id; | ||
712 | |||
713 | int purpose; /* Purpose setting */ | ||
714 | int trust; /* Trust setting */ | ||
715 | |||
716 | int quiet_shutdown; | ||
717 | }; | ||
718 | |||
719 | #define SSL_SESS_CACHE_OFF 0x0000 | ||
720 | #define SSL_SESS_CACHE_CLIENT 0x0001 | ||
721 | #define SSL_SESS_CACHE_SERVER 0x0002 | ||
722 | #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) | ||
723 | #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 | ||
724 | /* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ | ||
725 | #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 | ||
726 | #define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 | ||
727 | #define SSL_SESS_CACHE_NO_INTERNAL \ | ||
728 | (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) | ||
729 | |||
730 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx); | ||
731 | #define SSL_CTX_sess_number(ctx) \ | ||
732 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) | ||
733 | #define SSL_CTX_sess_connect(ctx) \ | ||
734 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) | ||
735 | #define SSL_CTX_sess_connect_good(ctx) \ | ||
736 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) | ||
737 | #define SSL_CTX_sess_connect_renegotiate(ctx) \ | ||
738 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) | ||
739 | #define SSL_CTX_sess_accept(ctx) \ | ||
740 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) | ||
741 | #define SSL_CTX_sess_accept_renegotiate(ctx) \ | ||
742 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) | ||
743 | #define SSL_CTX_sess_accept_good(ctx) \ | ||
744 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) | ||
745 | #define SSL_CTX_sess_hits(ctx) \ | ||
746 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) | ||
747 | #define SSL_CTX_sess_cb_hits(ctx) \ | ||
748 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) | ||
749 | #define SSL_CTX_sess_misses(ctx) \ | ||
750 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) | ||
751 | #define SSL_CTX_sess_timeouts(ctx) \ | ||
752 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) | ||
753 | #define SSL_CTX_sess_cache_full(ctx) \ | ||
754 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) | ||
755 | |||
756 | #define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb)) | ||
757 | #define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb) | ||
758 | #define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb)) | ||
759 | #define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb) | ||
760 | #define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb)) | ||
761 | #define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb) | ||
762 | #define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb)) | ||
763 | #define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback) | ||
764 | #define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb)) | ||
765 | #define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb) | ||
766 | |||
767 | #define SSL_NOTHING 1 | ||
768 | #define SSL_WRITING 2 | ||
769 | #define SSL_READING 3 | ||
770 | #define SSL_X509_LOOKUP 4 | ||
771 | |||
772 | /* These will only be used when doing non-blocking IO */ | ||
773 | #define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) | ||
774 | #define SSL_want_read(s) (SSL_want(s) == SSL_READING) | ||
775 | #define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) | ||
776 | #define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) | ||
777 | |||
778 | struct ssl_st | ||
779 | { | ||
780 | /* protocol version | ||
781 | * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION) | ||
782 | */ | ||
783 | int version; | ||
784 | int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ | ||
785 | |||
786 | SSL_METHOD *method; /* SSLv3 */ | ||
787 | |||
788 | /* There are 2 BIO's even though they are normally both the | ||
789 | * same. This is so data can be read and written to different | ||
790 | * handlers */ | ||
791 | |||
792 | #ifndef OPENSSL_NO_BIO | ||
793 | BIO *rbio; /* used by SSL_read */ | ||
794 | BIO *wbio; /* used by SSL_write */ | ||
795 | BIO *bbio; /* used during session-id reuse to concatenate | ||
796 | * messages */ | ||
797 | #else | ||
798 | char *rbio; /* used by SSL_read */ | ||
799 | char *wbio; /* used by SSL_write */ | ||
800 | char *bbio; | ||
801 | #endif | ||
802 | /* This holds a variable that indicates what we were doing | ||
803 | * when a 0 or -1 is returned. This is needed for | ||
804 | * non-blocking IO so we know what request needs re-doing when | ||
805 | * in SSL_accept or SSL_connect */ | ||
806 | int rwstate; | ||
807 | |||
808 | /* true when we are actually in SSL_accept() or SSL_connect() */ | ||
809 | int in_handshake; | ||
810 | int (*handshake_func)(); | ||
811 | |||
812 | /* Imagine that here's a boolean member "init" that is | ||
813 | * switched as soon as SSL_set_{accept/connect}_state | ||
814 | * is called for the first time, so that "state" and | ||
815 | * "handshake_func" are properly initialized. But as | ||
816 | * handshake_func is == 0 until then, we use this | ||
817 | * test instead of an "init" member. | ||
818 | */ | ||
819 | |||
820 | int server; /* are we the server side? - mostly used by SSL_clear*/ | ||
821 | |||
822 | int new_session;/* 1 if we are to use a new session. | ||
823 | * 2 if we are a server and are inside a handshake | ||
824 | * (i.e. not just sending a HelloRequest) | ||
825 | * NB: For servers, the 'new' session may actually be a previously | ||
826 | * cached session or even the previous session unless | ||
827 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */ | ||
828 | int quiet_shutdown;/* don't send shutdown packets */ | ||
829 | int shutdown; /* we have shut things down, 0x01 sent, 0x02 | ||
830 | * for received */ | ||
831 | int state; /* where we are */ | ||
832 | int rstate; /* where we are when reading */ | ||
833 | |||
834 | BUF_MEM *init_buf; /* buffer used during init */ | ||
835 | void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */ | ||
836 | int init_num; /* amount read/written */ | ||
837 | int init_off; /* amount read/written */ | ||
838 | |||
839 | /* used internally to point at a raw packet */ | ||
840 | unsigned char *packet; | ||
841 | unsigned int packet_length; | ||
842 | |||
843 | struct ssl2_state_st *s2; /* SSLv2 variables */ | ||
844 | struct ssl3_state_st *s3; /* SSLv3 variables */ | ||
845 | |||
846 | int read_ahead; /* Read as many input bytes as possible | ||
847 | * (for non-blocking reads) */ | ||
848 | |||
849 | /* callback that allows applications to peek at protocol messages */ | ||
850 | void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg); | ||
851 | void *msg_callback_arg; | ||
852 | |||
853 | int hit; /* reusing a previous session */ | ||
854 | |||
855 | int purpose; /* Purpose setting */ | ||
856 | int trust; /* Trust setting */ | ||
857 | |||
858 | /* crypto */ | ||
859 | STACK_OF(SSL_CIPHER) *cipher_list; | ||
860 | STACK_OF(SSL_CIPHER) *cipher_list_by_id; | ||
861 | |||
862 | /* These are the ones being used, the ones in SSL_SESSION are | ||
863 | * the ones to be 'copied' into these ones */ | ||
864 | |||
865 | EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */ | ||
866 | const EVP_MD *read_hash; /* used for mac generation */ | ||
867 | #ifndef OPENSSL_NO_COMP | ||
868 | COMP_CTX *expand; /* uncompress */ | ||
869 | #else | ||
870 | char *expand; | ||
871 | #endif | ||
872 | |||
873 | EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */ | ||
874 | const EVP_MD *write_hash; /* used for mac generation */ | ||
875 | #ifndef OPENSSL_NO_COMP | ||
876 | COMP_CTX *compress; /* compression */ | ||
877 | #else | ||
878 | char *compress; | ||
879 | #endif | ||
880 | |||
881 | /* session info */ | ||
882 | |||
883 | /* client cert? */ | ||
884 | /* This is used to hold the server certificate used */ | ||
885 | struct cert_st /* CERT */ *cert; | ||
886 | |||
887 | /* the session_id_context is used to ensure sessions are only reused | ||
888 | * in the appropriate context */ | ||
889 | unsigned int sid_ctx_length; | ||
890 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
891 | |||
892 | /* This can also be in the session once a session is established */ | ||
893 | SSL_SESSION *session; | ||
894 | |||
895 | /* Default generate session ID callback. */ | ||
896 | GEN_SESSION_CB generate_session_id; | ||
897 | |||
898 | /* Used in SSL2 and SSL3 */ | ||
899 | int verify_mode; /* 0 don't care about verify failure. | ||
900 | * 1 fail if verify fails */ | ||
901 | int verify_depth; | ||
902 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ | ||
903 | |||
904 | void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */ | ||
905 | |||
906 | int error; /* error bytes to be written */ | ||
907 | int error_code; /* actual code */ | ||
908 | |||
909 | #ifndef OPENSSL_NO_KRB5 | ||
910 | KSSL_CTX *kssl_ctx; /* Kerberos 5 context */ | ||
911 | #endif /* OPENSSL_NO_KRB5 */ | ||
912 | |||
913 | SSL_CTX *ctx; | ||
914 | /* set this flag to 1 and a sleep(1) is put into all SSL_read() | ||
915 | * and SSL_write() calls, good for nbio debuging :-) */ | ||
916 | int debug; | ||
917 | |||
918 | /* extra application data */ | ||
919 | long verify_result; | ||
920 | CRYPTO_EX_DATA ex_data; | ||
921 | |||
922 | /* for server side, keep the list of CA_dn we can use */ | ||
923 | STACK_OF(X509_NAME) *client_CA; | ||
924 | |||
925 | int references; | ||
926 | unsigned long options; /* protocol behaviour */ | ||
927 | unsigned long mode; /* API behaviour */ | ||
928 | long max_cert_list; | ||
929 | int first_packet; | ||
930 | int client_version; /* what was passed, used for | ||
931 | * SSLv3/TLS rollback check */ | ||
932 | }; | ||
933 | |||
934 | #ifdef __cplusplus | ||
935 | } | ||
936 | #endif | ||
937 | |||
938 | #include <openssl/ssl2.h> | ||
939 | #include <openssl/ssl3.h> | ||
940 | #include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */ | ||
941 | #include <openssl/ssl23.h> | ||
942 | |||
943 | #ifdef __cplusplus | ||
944 | extern "C" { | ||
945 | #endif | ||
946 | |||
947 | /* compatibility */ | ||
948 | #define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg)) | ||
949 | #define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) | ||
950 | #define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a)) | ||
951 | #define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) | ||
952 | #define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) | ||
953 | #define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg)) | ||
954 | |||
955 | /* The following are the possible values for ssl->state are are | ||
956 | * used to indicate where we are up to in the SSL connection establishment. | ||
957 | * The macros that follow are about the only things you should need to use | ||
958 | * and even then, only when using non-blocking IO. | ||
959 | * It can also be useful to work out where you were when the connection | ||
960 | * failed */ | ||
961 | |||
962 | #define SSL_ST_CONNECT 0x1000 | ||
963 | #define SSL_ST_ACCEPT 0x2000 | ||
964 | #define SSL_ST_MASK 0x0FFF | ||
965 | #define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT) | ||
966 | #define SSL_ST_BEFORE 0x4000 | ||
967 | #define SSL_ST_OK 0x03 | ||
968 | #define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT) | ||
969 | |||
970 | #define SSL_CB_LOOP 0x01 | ||
971 | #define SSL_CB_EXIT 0x02 | ||
972 | #define SSL_CB_READ 0x04 | ||
973 | #define SSL_CB_WRITE 0x08 | ||
974 | #define SSL_CB_ALERT 0x4000 /* used in callback */ | ||
975 | #define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) | ||
976 | #define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) | ||
977 | #define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) | ||
978 | #define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) | ||
979 | #define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) | ||
980 | #define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) | ||
981 | #define SSL_CB_HANDSHAKE_START 0x10 | ||
982 | #define SSL_CB_HANDSHAKE_DONE 0x20 | ||
983 | |||
984 | /* Is the SSL_connection established? */ | ||
985 | #define SSL_get_state(a) SSL_state(a) | ||
986 | #define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK) | ||
987 | #define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT) | ||
988 | #define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE) | ||
989 | #define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT) | ||
990 | #define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT) | ||
991 | |||
992 | /* The following 2 states are kept in ssl->rstate when reads fail, | ||
993 | * you should not need these */ | ||
994 | #define SSL_ST_READ_HEADER 0xF0 | ||
995 | #define SSL_ST_READ_BODY 0xF1 | ||
996 | #define SSL_ST_READ_DONE 0xF2 | ||
997 | |||
998 | /* Obtain latest Finished message | ||
999 | * -- that we sent (SSL_get_finished) | ||
1000 | * -- that we expected from peer (SSL_get_peer_finished). | ||
1001 | * Returns length (0 == no Finished so far), copies up to 'count' bytes. */ | ||
1002 | size_t SSL_get_finished(const SSL *s, void *buf, size_t count); | ||
1003 | size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count); | ||
1004 | |||
1005 | /* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options | ||
1006 | * are 'ored' with SSL_VERIFY_PEER if they are desired */ | ||
1007 | #define SSL_VERIFY_NONE 0x00 | ||
1008 | #define SSL_VERIFY_PEER 0x01 | ||
1009 | #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 | ||
1010 | #define SSL_VERIFY_CLIENT_ONCE 0x04 | ||
1011 | |||
1012 | #define OpenSSL_add_ssl_algorithms() SSL_library_init() | ||
1013 | #define SSLeay_add_ssl_algorithms() SSL_library_init() | ||
1014 | |||
1015 | /* this is for backward compatibility */ | ||
1016 | #if 0 /* NEW_SSLEAY */ | ||
1017 | #define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c) | ||
1018 | #define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n) | ||
1019 | #define SSL_add_session(a,b) SSL_CTX_add_session((a),(b)) | ||
1020 | #define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b)) | ||
1021 | #define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b)) | ||
1022 | #endif | ||
1023 | /* More backward compatibility */ | ||
1024 | #define SSL_get_cipher(s) \ | ||
1025 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
1026 | #define SSL_get_cipher_bits(s,np) \ | ||
1027 | SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) | ||
1028 | #define SSL_get_cipher_version(s) \ | ||
1029 | SSL_CIPHER_get_version(SSL_get_current_cipher(s)) | ||
1030 | #define SSL_get_cipher_name(s) \ | ||
1031 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
1032 | #define SSL_get_time(a) SSL_SESSION_get_time(a) | ||
1033 | #define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) | ||
1034 | #define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) | ||
1035 | #define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) | ||
1036 | |||
1037 | #if 1 /*SSLEAY_MACROS*/ | ||
1038 | #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \ | ||
1039 | (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \ | ||
1040 | (bp),(unsigned char **)(s_id)) | ||
1041 | #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \ | ||
1042 | bp,(unsigned char *)s_id) | ||
1043 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ | ||
1044 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) | ||
1045 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
1046 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) | ||
1047 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
1048 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
1049 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
1050 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
1051 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
1052 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
1053 | #endif | ||
1054 | |||
1055 | #define SSL_AD_REASON_OFFSET 1000 | ||
1056 | /* These alert types are for SSLv3 and TLSv1 */ | ||
1057 | #define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY | ||
1058 | #define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */ | ||
1059 | #define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */ | ||
1060 | #define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED | ||
1061 | #define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW | ||
1062 | #define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */ | ||
1063 | #define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */ | ||
1064 | #define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */ | ||
1065 | #define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE | ||
1066 | #define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE | ||
1067 | #define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED | ||
1068 | #define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED | ||
1069 | #define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN | ||
1070 | #define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */ | ||
1071 | #define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */ | ||
1072 | #define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */ | ||
1073 | #define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */ | ||
1074 | #define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR | ||
1075 | #define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */ | ||
1076 | #define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */ | ||
1077 | #define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */ | ||
1078 | #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ | ||
1079 | #define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED | ||
1080 | #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION | ||
1081 | |||
1082 | #define SSL_ERROR_NONE 0 | ||
1083 | #define SSL_ERROR_SSL 1 | ||
1084 | #define SSL_ERROR_WANT_READ 2 | ||
1085 | #define SSL_ERROR_WANT_WRITE 3 | ||
1086 | #define SSL_ERROR_WANT_X509_LOOKUP 4 | ||
1087 | #define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */ | ||
1088 | #define SSL_ERROR_ZERO_RETURN 6 | ||
1089 | #define SSL_ERROR_WANT_CONNECT 7 | ||
1090 | #define SSL_ERROR_WANT_ACCEPT 8 | ||
1091 | |||
1092 | #define SSL_CTRL_NEED_TMP_RSA 1 | ||
1093 | #define SSL_CTRL_SET_TMP_RSA 2 | ||
1094 | #define SSL_CTRL_SET_TMP_DH 3 | ||
1095 | #define SSL_CTRL_SET_TMP_RSA_CB 4 | ||
1096 | #define SSL_CTRL_SET_TMP_DH_CB 5 | ||
1097 | |||
1098 | #define SSL_CTRL_GET_SESSION_REUSED 6 | ||
1099 | #define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7 | ||
1100 | #define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8 | ||
1101 | #define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9 | ||
1102 | #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10 | ||
1103 | #define SSL_CTRL_GET_FLAGS 11 | ||
1104 | #define SSL_CTRL_EXTRA_CHAIN_CERT 12 | ||
1105 | |||
1106 | #define SSL_CTRL_SET_MSG_CALLBACK 13 | ||
1107 | #define SSL_CTRL_SET_MSG_CALLBACK_ARG 14 | ||
1108 | |||
1109 | /* Stats */ | ||
1110 | #define SSL_CTRL_SESS_NUMBER 20 | ||
1111 | #define SSL_CTRL_SESS_CONNECT 21 | ||
1112 | #define SSL_CTRL_SESS_CONNECT_GOOD 22 | ||
1113 | #define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 | ||
1114 | #define SSL_CTRL_SESS_ACCEPT 24 | ||
1115 | #define SSL_CTRL_SESS_ACCEPT_GOOD 25 | ||
1116 | #define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 | ||
1117 | #define SSL_CTRL_SESS_HIT 27 | ||
1118 | #define SSL_CTRL_SESS_CB_HIT 28 | ||
1119 | #define SSL_CTRL_SESS_MISSES 29 | ||
1120 | #define SSL_CTRL_SESS_TIMEOUTS 30 | ||
1121 | #define SSL_CTRL_SESS_CACHE_FULL 31 | ||
1122 | #define SSL_CTRL_OPTIONS 32 | ||
1123 | #define SSL_CTRL_MODE 33 | ||
1124 | |||
1125 | #define SSL_CTRL_GET_READ_AHEAD 40 | ||
1126 | #define SSL_CTRL_SET_READ_AHEAD 41 | ||
1127 | #define SSL_CTRL_SET_SESS_CACHE_SIZE 42 | ||
1128 | #define SSL_CTRL_GET_SESS_CACHE_SIZE 43 | ||
1129 | #define SSL_CTRL_SET_SESS_CACHE_MODE 44 | ||
1130 | #define SSL_CTRL_GET_SESS_CACHE_MODE 45 | ||
1131 | |||
1132 | #define SSL_CTRL_GET_MAX_CERT_LIST 50 | ||
1133 | #define SSL_CTRL_SET_MAX_CERT_LIST 51 | ||
1134 | |||
1135 | #define SSL_session_reused(ssl) \ | ||
1136 | SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) | ||
1137 | #define SSL_num_renegotiations(ssl) \ | ||
1138 | SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) | ||
1139 | #define SSL_clear_num_renegotiations(ssl) \ | ||
1140 | SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) | ||
1141 | #define SSL_total_renegotiations(ssl) \ | ||
1142 | SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) | ||
1143 | |||
1144 | #define SSL_CTX_need_tmp_RSA(ctx) \ | ||
1145 | SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL) | ||
1146 | #define SSL_CTX_set_tmp_rsa(ctx,rsa) \ | ||
1147 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | ||
1148 | #define SSL_CTX_set_tmp_dh(ctx,dh) \ | ||
1149 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | ||
1150 | |||
1151 | #define SSL_need_tmp_RSA(ssl) \ | ||
1152 | SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL) | ||
1153 | #define SSL_set_tmp_rsa(ssl,rsa) \ | ||
1154 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | ||
1155 | #define SSL_set_tmp_dh(ssl,dh) \ | ||
1156 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | ||
1157 | |||
1158 | #define SSL_CTX_add_extra_chain_cert(ctx,x509) \ | ||
1159 | SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) | ||
1160 | |||
1161 | #ifndef OPENSSL_NO_BIO | ||
1162 | BIO_METHOD *BIO_f_ssl(void); | ||
1163 | BIO *BIO_new_ssl(SSL_CTX *ctx,int client); | ||
1164 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx); | ||
1165 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); | ||
1166 | int BIO_ssl_copy_session_id(BIO *to,BIO *from); | ||
1167 | void BIO_ssl_shutdown(BIO *ssl_bio); | ||
1168 | |||
1169 | #endif | ||
1170 | |||
1171 | int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str); | ||
1172 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth); | ||
1173 | void SSL_CTX_free(SSL_CTX *); | ||
1174 | long SSL_CTX_set_timeout(SSL_CTX *ctx,long t); | ||
1175 | long SSL_CTX_get_timeout(const SSL_CTX *ctx); | ||
1176 | X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *); | ||
1177 | void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *); | ||
1178 | int SSL_want(const SSL *s); | ||
1179 | int SSL_clear(SSL *s); | ||
1180 | |||
1181 | void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm); | ||
1182 | |||
1183 | SSL_CIPHER *SSL_get_current_cipher(const SSL *s); | ||
1184 | int SSL_CIPHER_get_bits(const SSL_CIPHER *c,int *alg_bits); | ||
1185 | char * SSL_CIPHER_get_version(const SSL_CIPHER *c); | ||
1186 | const char * SSL_CIPHER_get_name(const SSL_CIPHER *c); | ||
1187 | |||
1188 | int SSL_get_fd(const SSL *s); | ||
1189 | int SSL_get_rfd(const SSL *s); | ||
1190 | int SSL_get_wfd(const SSL *s); | ||
1191 | const char * SSL_get_cipher_list(const SSL *s,int n); | ||
1192 | char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len); | ||
1193 | int SSL_get_read_ahead(const SSL * s); | ||
1194 | int SSL_pending(const SSL *s); | ||
1195 | #ifndef OPENSSL_NO_SOCK | ||
1196 | int SSL_set_fd(SSL *s, int fd); | ||
1197 | int SSL_set_rfd(SSL *s, int fd); | ||
1198 | int SSL_set_wfd(SSL *s, int fd); | ||
1199 | #endif | ||
1200 | #ifndef OPENSSL_NO_BIO | ||
1201 | void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio); | ||
1202 | BIO * SSL_get_rbio(const SSL *s); | ||
1203 | BIO * SSL_get_wbio(const SSL *s); | ||
1204 | #endif | ||
1205 | int SSL_set_cipher_list(SSL *s, const char *str); | ||
1206 | void SSL_set_read_ahead(SSL *s, int yes); | ||
1207 | int SSL_get_verify_mode(const SSL *s); | ||
1208 | int SSL_get_verify_depth(const SSL *s); | ||
1209 | int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *); | ||
1210 | void SSL_set_verify(SSL *s, int mode, | ||
1211 | int (*callback)(int ok,X509_STORE_CTX *ctx)); | ||
1212 | void SSL_set_verify_depth(SSL *s, int depth); | ||
1213 | #ifndef OPENSSL_NO_RSA | ||
1214 | int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); | ||
1215 | #endif | ||
1216 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); | ||
1217 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); | ||
1218 | int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len); | ||
1219 | int SSL_use_certificate(SSL *ssl, X509 *x); | ||
1220 | int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len); | ||
1221 | |||
1222 | #ifndef OPENSSL_NO_STDIO | ||
1223 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); | ||
1224 | int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); | ||
1225 | int SSL_use_certificate_file(SSL *ssl, const char *file, int type); | ||
1226 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); | ||
1227 | int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); | ||
1228 | int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); | ||
1229 | int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */ | ||
1230 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); | ||
1231 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | ||
1232 | const char *file); | ||
1233 | #ifndef OPENSSL_SYS_VMS | ||
1234 | #ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */ | ||
1235 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | ||
1236 | const char *dir); | ||
1237 | #endif | ||
1238 | #endif | ||
1239 | |||
1240 | #endif | ||
1241 | |||
1242 | void SSL_load_error_strings(void ); | ||
1243 | const char *SSL_state_string(const SSL *s); | ||
1244 | const char *SSL_rstate_string(const SSL *s); | ||
1245 | const char *SSL_state_string_long(const SSL *s); | ||
1246 | const char *SSL_rstate_string_long(const SSL *s); | ||
1247 | long SSL_SESSION_get_time(const SSL_SESSION *s); | ||
1248 | long SSL_SESSION_set_time(SSL_SESSION *s, long t); | ||
1249 | long SSL_SESSION_get_timeout(const SSL_SESSION *s); | ||
1250 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); | ||
1251 | void SSL_copy_session_id(SSL *to,const SSL *from); | ||
1252 | |||
1253 | SSL_SESSION *SSL_SESSION_new(void); | ||
1254 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a); | ||
1255 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b); | ||
1256 | #ifndef OPENSSL_NO_FP_API | ||
1257 | int SSL_SESSION_print_fp(FILE *fp,const SSL_SESSION *ses); | ||
1258 | #endif | ||
1259 | #ifndef OPENSSL_NO_BIO | ||
1260 | int SSL_SESSION_print(BIO *fp,const SSL_SESSION *ses); | ||
1261 | #endif | ||
1262 | void SSL_SESSION_free(SSL_SESSION *ses); | ||
1263 | int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp); | ||
1264 | int SSL_set_session(SSL *to, SSL_SESSION *session); | ||
1265 | int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c); | ||
1266 | int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c); | ||
1267 | int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB); | ||
1268 | int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB); | ||
1269 | int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | ||
1270 | unsigned int id_len); | ||
1271 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,const unsigned char * const *pp, | ||
1272 | long length); | ||
1273 | |||
1274 | #ifdef HEADER_X509_H | ||
1275 | X509 * SSL_get_peer_certificate(const SSL *s); | ||
1276 | #endif | ||
1277 | |||
1278 | STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s); | ||
1279 | |||
1280 | int SSL_CTX_get_verify_mode(const SSL_CTX *ctx); | ||
1281 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx); | ||
1282 | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *); | ||
1283 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode, | ||
1284 | int (*callback)(int, X509_STORE_CTX *)); | ||
1285 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth); | ||
1286 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg); | ||
1287 | #ifndef OPENSSL_NO_RSA | ||
1288 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); | ||
1289 | #endif | ||
1290 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len); | ||
1291 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); | ||
1292 | int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, | ||
1293 | unsigned char *d, long len); | ||
1294 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); | ||
1295 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d); | ||
1296 | |||
1297 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); | ||
1298 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); | ||
1299 | |||
1300 | int SSL_CTX_check_private_key(const SSL_CTX *ctx); | ||
1301 | int SSL_check_private_key(const SSL *ctx); | ||
1302 | |||
1303 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, | ||
1304 | unsigned int sid_ctx_len); | ||
1305 | |||
1306 | SSL * SSL_new(SSL_CTX *ctx); | ||
1307 | int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, | ||
1308 | unsigned int sid_ctx_len); | ||
1309 | |||
1310 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose); | ||
1311 | int SSL_set_purpose(SSL *s, int purpose); | ||
1312 | int SSL_CTX_set_trust(SSL_CTX *s, int trust); | ||
1313 | int SSL_set_trust(SSL *s, int trust); | ||
1314 | |||
1315 | void SSL_free(SSL *ssl); | ||
1316 | int SSL_accept(SSL *ssl); | ||
1317 | int SSL_connect(SSL *ssl); | ||
1318 | int SSL_read(SSL *ssl,void *buf,int num); | ||
1319 | int SSL_peek(SSL *ssl,void *buf,int num); | ||
1320 | int SSL_write(SSL *ssl,const void *buf,int num); | ||
1321 | long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg); | ||
1322 | long SSL_callback_ctrl(SSL *, int, void (*)()); | ||
1323 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg); | ||
1324 | long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)()); | ||
1325 | |||
1326 | int SSL_get_error(const SSL *s,int ret_code); | ||
1327 | const char *SSL_get_version(const SSL *s); | ||
1328 | |||
1329 | /* This sets the 'default' SSL version that SSL_new() will create */ | ||
1330 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth); | ||
1331 | |||
1332 | SSL_METHOD *SSLv2_method(void); /* SSLv2 */ | ||
1333 | SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */ | ||
1334 | SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */ | ||
1335 | |||
1336 | SSL_METHOD *SSLv3_method(void); /* SSLv3 */ | ||
1337 | SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */ | ||
1338 | SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */ | ||
1339 | |||
1340 | SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */ | ||
1341 | SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */ | ||
1342 | SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */ | ||
1343 | |||
1344 | SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ | ||
1345 | SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ | ||
1346 | SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ | ||
1347 | |||
1348 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s); | ||
1349 | |||
1350 | int SSL_do_handshake(SSL *s); | ||
1351 | int SSL_renegotiate(SSL *s); | ||
1352 | int SSL_renegotiate_pending(SSL *s); | ||
1353 | int SSL_shutdown(SSL *s); | ||
1354 | |||
1355 | SSL_METHOD *SSL_get_ssl_method(SSL *s); | ||
1356 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *method); | ||
1357 | const char *SSL_alert_type_string_long(int value); | ||
1358 | const char *SSL_alert_type_string(int value); | ||
1359 | const char *SSL_alert_desc_string_long(int value); | ||
1360 | const char *SSL_alert_desc_string(int value); | ||
1361 | |||
1362 | void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list); | ||
1363 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list); | ||
1364 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s); | ||
1365 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s); | ||
1366 | int SSL_add_client_CA(SSL *ssl,X509 *x); | ||
1367 | int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x); | ||
1368 | |||
1369 | void SSL_set_connect_state(SSL *s); | ||
1370 | void SSL_set_accept_state(SSL *s); | ||
1371 | |||
1372 | long SSL_get_default_timeout(const SSL *s); | ||
1373 | |||
1374 | int SSL_library_init(void ); | ||
1375 | |||
1376 | char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size); | ||
1377 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk); | ||
1378 | |||
1379 | SSL *SSL_dup(SSL *ssl); | ||
1380 | |||
1381 | X509 *SSL_get_certificate(const SSL *ssl); | ||
1382 | /* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl); | ||
1383 | |||
1384 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode); | ||
1385 | int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx); | ||
1386 | void SSL_set_quiet_shutdown(SSL *ssl,int mode); | ||
1387 | int SSL_get_quiet_shutdown(const SSL *ssl); | ||
1388 | void SSL_set_shutdown(SSL *ssl,int mode); | ||
1389 | int SSL_get_shutdown(const SSL *ssl); | ||
1390 | int SSL_version(const SSL *ssl); | ||
1391 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); | ||
1392 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | ||
1393 | const char *CApath); | ||
1394 | #define SSL_get0_session SSL_get_session /* just peek at pointer */ | ||
1395 | SSL_SESSION *SSL_get_session(const SSL *ssl); | ||
1396 | SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ | ||
1397 | SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl); | ||
1398 | void SSL_set_info_callback(SSL *ssl, | ||
1399 | void (*cb)(const SSL *ssl,int type,int val)); | ||
1400 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val); | ||
1401 | int SSL_state(const SSL *ssl); | ||
1402 | |||
1403 | void SSL_set_verify_result(SSL *ssl,long v); | ||
1404 | long SSL_get_verify_result(const SSL *ssl); | ||
1405 | |||
1406 | int SSL_set_ex_data(SSL *ssl,int idx,void *data); | ||
1407 | void *SSL_get_ex_data(const SSL *ssl,int idx); | ||
1408 | int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1409 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1410 | |||
1411 | int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data); | ||
1412 | void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss,int idx); | ||
1413 | int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1414 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1415 | |||
1416 | int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data); | ||
1417 | void *SSL_CTX_get_ex_data(const SSL_CTX *ssl,int idx); | ||
1418 | int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1419 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1420 | |||
1421 | int SSL_get_ex_data_X509_STORE_CTX_idx(void ); | ||
1422 | |||
1423 | #define SSL_CTX_sess_set_cache_size(ctx,t) \ | ||
1424 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) | ||
1425 | #define SSL_CTX_sess_get_cache_size(ctx) \ | ||
1426 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) | ||
1427 | #define SSL_CTX_set_session_cache_mode(ctx,m) \ | ||
1428 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) | ||
1429 | #define SSL_CTX_get_session_cache_mode(ctx) \ | ||
1430 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) | ||
1431 | |||
1432 | #define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) | ||
1433 | #define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) | ||
1434 | #define SSL_CTX_get_read_ahead(ctx) \ | ||
1435 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) | ||
1436 | #define SSL_CTX_set_read_ahead(ctx,m) \ | ||
1437 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL) | ||
1438 | #define SSL_CTX_get_max_cert_list(ctx) \ | ||
1439 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) | ||
1440 | #define SSL_CTX_set_max_cert_list(ctx,m) \ | ||
1441 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) | ||
1442 | #define SSL_get_max_cert_list(ssl) \ | ||
1443 | SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL) | ||
1444 | #define SSL_set_max_cert_list(ssl,m) \ | ||
1445 | SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL) | ||
1446 | |||
1447 | /* NB: the keylength is only applicable when is_export is true */ | ||
1448 | #ifndef OPENSSL_NO_RSA | ||
1449 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, | ||
1450 | RSA *(*cb)(SSL *ssl,int is_export, | ||
1451 | int keylength)); | ||
1452 | |||
1453 | void SSL_set_tmp_rsa_callback(SSL *ssl, | ||
1454 | RSA *(*cb)(SSL *ssl,int is_export, | ||
1455 | int keylength)); | ||
1456 | #endif | ||
1457 | #ifndef OPENSSL_NO_DH | ||
1458 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, | ||
1459 | DH *(*dh)(SSL *ssl,int is_export, | ||
1460 | int keylength)); | ||
1461 | void SSL_set_tmp_dh_callback(SSL *ssl, | ||
1462 | DH *(*dh)(SSL *ssl,int is_export, | ||
1463 | int keylength)); | ||
1464 | #endif | ||
1465 | |||
1466 | #ifndef OPENSSL_NO_COMP | ||
1467 | int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm); | ||
1468 | #else | ||
1469 | int SSL_COMP_add_compression_method(int id,char *cm); | ||
1470 | #endif | ||
1471 | |||
1472 | /* BEGIN ERROR CODES */ | ||
1473 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
1474 | * made after this point may be overwritten when the script is next run. | ||
1475 | */ | ||
1476 | void ERR_load_SSL_strings(void); | ||
1477 | |||
1478 | /* Error codes for the SSL functions. */ | ||
1479 | |||
1480 | /* Function codes. */ | ||
1481 | #define SSL_F_CLIENT_CERTIFICATE 100 | ||
1482 | #define SSL_F_CLIENT_FINISHED 238 | ||
1483 | #define SSL_F_CLIENT_HELLO 101 | ||
1484 | #define SSL_F_CLIENT_MASTER_KEY 102 | ||
1485 | #define SSL_F_D2I_SSL_SESSION 103 | ||
1486 | #define SSL_F_DO_SSL3_WRITE 104 | ||
1487 | #define SSL_F_GET_CLIENT_FINISHED 105 | ||
1488 | #define SSL_F_GET_CLIENT_HELLO 106 | ||
1489 | #define SSL_F_GET_CLIENT_MASTER_KEY 107 | ||
1490 | #define SSL_F_GET_SERVER_FINISHED 108 | ||
1491 | #define SSL_F_GET_SERVER_HELLO 109 | ||
1492 | #define SSL_F_GET_SERVER_VERIFY 110 | ||
1493 | #define SSL_F_I2D_SSL_SESSION 111 | ||
1494 | #define SSL_F_READ_N 112 | ||
1495 | #define SSL_F_REQUEST_CERTIFICATE 113 | ||
1496 | #define SSL_F_SERVER_FINISH 239 | ||
1497 | #define SSL_F_SERVER_HELLO 114 | ||
1498 | #define SSL_F_SERVER_VERIFY 240 | ||
1499 | #define SSL_F_SSL23_ACCEPT 115 | ||
1500 | #define SSL_F_SSL23_CLIENT_HELLO 116 | ||
1501 | #define SSL_F_SSL23_CONNECT 117 | ||
1502 | #define SSL_F_SSL23_GET_CLIENT_HELLO 118 | ||
1503 | #define SSL_F_SSL23_GET_SERVER_HELLO 119 | ||
1504 | #define SSL_F_SSL23_PEEK 237 | ||
1505 | #define SSL_F_SSL23_READ 120 | ||
1506 | #define SSL_F_SSL23_WRITE 121 | ||
1507 | #define SSL_F_SSL2_ACCEPT 122 | ||
1508 | #define SSL_F_SSL2_CONNECT 123 | ||
1509 | #define SSL_F_SSL2_ENC_INIT 124 | ||
1510 | #define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241 | ||
1511 | #define SSL_F_SSL2_PEEK 234 | ||
1512 | #define SSL_F_SSL2_READ 125 | ||
1513 | #define SSL_F_SSL2_READ_INTERNAL 236 | ||
1514 | #define SSL_F_SSL2_SET_CERTIFICATE 126 | ||
1515 | #define SSL_F_SSL2_WRITE 127 | ||
1516 | #define SSL_F_SSL3_ACCEPT 128 | ||
1517 | #define SSL_F_SSL3_CALLBACK_CTRL 233 | ||
1518 | #define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 | ||
1519 | #define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 | ||
1520 | #define SSL_F_SSL3_CLIENT_HELLO 131 | ||
1521 | #define SSL_F_SSL3_CONNECT 132 | ||
1522 | #define SSL_F_SSL3_CTRL 213 | ||
1523 | #define SSL_F_SSL3_CTX_CTRL 133 | ||
1524 | #define SSL_F_SSL3_ENC 134 | ||
1525 | #define SSL_F_SSL3_GENERATE_KEY_BLOCK 238 | ||
1526 | #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 | ||
1527 | #define SSL_F_SSL3_GET_CERT_VERIFY 136 | ||
1528 | #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 | ||
1529 | #define SSL_F_SSL3_GET_CLIENT_HELLO 138 | ||
1530 | #define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139 | ||
1531 | #define SSL_F_SSL3_GET_FINISHED 140 | ||
1532 | #define SSL_F_SSL3_GET_KEY_EXCHANGE 141 | ||
1533 | #define SSL_F_SSL3_GET_MESSAGE 142 | ||
1534 | #define SSL_F_SSL3_GET_RECORD 143 | ||
1535 | #define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 | ||
1536 | #define SSL_F_SSL3_GET_SERVER_DONE 145 | ||
1537 | #define SSL_F_SSL3_GET_SERVER_HELLO 146 | ||
1538 | #define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 | ||
1539 | #define SSL_F_SSL3_PEEK 235 | ||
1540 | #define SSL_F_SSL3_READ_BYTES 148 | ||
1541 | #define SSL_F_SSL3_READ_N 149 | ||
1542 | #define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150 | ||
1543 | #define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151 | ||
1544 | #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 | ||
1545 | #define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 | ||
1546 | #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 | ||
1547 | #define SSL_F_SSL3_SEND_SERVER_HELLO 242 | ||
1548 | #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 | ||
1549 | #define SSL_F_SSL3_SETUP_BUFFERS 156 | ||
1550 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 | ||
1551 | #define SSL_F_SSL3_WRITE_BYTES 158 | ||
1552 | #define SSL_F_SSL3_WRITE_PENDING 159 | ||
1553 | #define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 | ||
1554 | #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 | ||
1555 | #define SSL_F_SSL_BAD_METHOD 160 | ||
1556 | #define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 | ||
1557 | #define SSL_F_SSL_CERT_DUP 221 | ||
1558 | #define SSL_F_SSL_CERT_INST 222 | ||
1559 | #define SSL_F_SSL_CERT_INSTANTIATE 214 | ||
1560 | #define SSL_F_SSL_CERT_NEW 162 | ||
1561 | #define SSL_F_SSL_CHECK_PRIVATE_KEY 163 | ||
1562 | #define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 | ||
1563 | #define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 | ||
1564 | #define SSL_F_SSL_CLEAR 164 | ||
1565 | #define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165 | ||
1566 | #define SSL_F_SSL_CREATE_CIPHER_LIST 166 | ||
1567 | #define SSL_F_SSL_CTRL 232 | ||
1568 | #define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168 | ||
1569 | #define SSL_F_SSL_CTX_NEW 169 | ||
1570 | #define SSL_F_SSL_CTX_SET_CIPHER_LIST 269 | ||
1571 | #define SSL_F_SSL_CTX_SET_PURPOSE 226 | ||
1572 | #define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219 | ||
1573 | #define SSL_F_SSL_CTX_SET_SSL_VERSION 170 | ||
1574 | #define SSL_F_SSL_CTX_SET_TRUST 229 | ||
1575 | #define SSL_F_SSL_CTX_USE_CERTIFICATE 171 | ||
1576 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172 | ||
1577 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220 | ||
1578 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173 | ||
1579 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY 174 | ||
1580 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175 | ||
1581 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176 | ||
1582 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177 | ||
1583 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178 | ||
1584 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179 | ||
1585 | #define SSL_F_SSL_DO_HANDSHAKE 180 | ||
1586 | #define SSL_F_SSL_GET_NEW_SESSION 181 | ||
1587 | #define SSL_F_SSL_GET_PREV_SESSION 217 | ||
1588 | #define SSL_F_SSL_GET_SERVER_SEND_CERT 182 | ||
1589 | #define SSL_F_SSL_GET_SIGN_PKEY 183 | ||
1590 | #define SSL_F_SSL_INIT_WBIO_BUFFER 184 | ||
1591 | #define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 | ||
1592 | #define SSL_F_SSL_NEW 186 | ||
1593 | #define SSL_F_SSL_READ 223 | ||
1594 | #define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187 | ||
1595 | #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188 | ||
1596 | #define SSL_F_SSL_SESSION_NEW 189 | ||
1597 | #define SSL_F_SSL_SESSION_PRINT_FP 190 | ||
1598 | #define SSL_F_SSL_SESS_CERT_NEW 225 | ||
1599 | #define SSL_F_SSL_SET_CERT 191 | ||
1600 | #define SSL_F_SSL_SET_CIPHER_LIST 271 | ||
1601 | #define SSL_F_SSL_SET_FD 192 | ||
1602 | #define SSL_F_SSL_SET_PKEY 193 | ||
1603 | #define SSL_F_SSL_SET_PURPOSE 227 | ||
1604 | #define SSL_F_SSL_SET_RFD 194 | ||
1605 | #define SSL_F_SSL_SET_SESSION 195 | ||
1606 | #define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218 | ||
1607 | #define SSL_F_SSL_SET_TRUST 228 | ||
1608 | #define SSL_F_SSL_SET_WFD 196 | ||
1609 | #define SSL_F_SSL_SHUTDOWN 224 | ||
1610 | #define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243 | ||
1611 | #define SSL_F_SSL_UNDEFINED_FUNCTION 197 | ||
1612 | #define SSL_F_SSL_USE_CERTIFICATE 198 | ||
1613 | #define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 | ||
1614 | #define SSL_F_SSL_USE_CERTIFICATE_FILE 200 | ||
1615 | #define SSL_F_SSL_USE_PRIVATEKEY 201 | ||
1616 | #define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202 | ||
1617 | #define SSL_F_SSL_USE_PRIVATEKEY_FILE 203 | ||
1618 | #define SSL_F_SSL_USE_RSAPRIVATEKEY 204 | ||
1619 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205 | ||
1620 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206 | ||
1621 | #define SSL_F_SSL_VERIFY_CERT_CHAIN 207 | ||
1622 | #define SSL_F_SSL_WRITE 208 | ||
1623 | #define SSL_F_TLS1_CHANGE_CIPHER_STATE 209 | ||
1624 | #define SSL_F_TLS1_ENC 210 | ||
1625 | #define SSL_F_TLS1_SETUP_KEY_BLOCK 211 | ||
1626 | #define SSL_F_WRITE_PENDING 212 | ||
1627 | |||
1628 | /* Reason codes. */ | ||
1629 | #define SSL_R_APP_DATA_IN_HANDSHAKE 100 | ||
1630 | #define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272 | ||
1631 | #define SSL_R_BAD_ALERT_RECORD 101 | ||
1632 | #define SSL_R_BAD_AUTHENTICATION_TYPE 102 | ||
1633 | #define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 | ||
1634 | #define SSL_R_BAD_CHECKSUM 104 | ||
1635 | #define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 | ||
1636 | #define SSL_R_BAD_DECOMPRESSION 107 | ||
1637 | #define SSL_R_BAD_DH_G_LENGTH 108 | ||
1638 | #define SSL_R_BAD_DH_PUB_KEY_LENGTH 109 | ||
1639 | #define SSL_R_BAD_DH_P_LENGTH 110 | ||
1640 | #define SSL_R_BAD_DIGEST_LENGTH 111 | ||
1641 | #define SSL_R_BAD_DSA_SIGNATURE 112 | ||
1642 | #define SSL_R_BAD_HELLO_REQUEST 105 | ||
1643 | #define SSL_R_BAD_LENGTH 271 | ||
1644 | #define SSL_R_BAD_MAC_DECODE 113 | ||
1645 | #define SSL_R_BAD_MESSAGE_TYPE 114 | ||
1646 | #define SSL_R_BAD_PACKET_LENGTH 115 | ||
1647 | #define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 | ||
1648 | #define SSL_R_BAD_RESPONSE_ARGUMENT 117 | ||
1649 | #define SSL_R_BAD_RSA_DECRYPT 118 | ||
1650 | #define SSL_R_BAD_RSA_ENCRYPT 119 | ||
1651 | #define SSL_R_BAD_RSA_E_LENGTH 120 | ||
1652 | #define SSL_R_BAD_RSA_MODULUS_LENGTH 121 | ||
1653 | #define SSL_R_BAD_RSA_SIGNATURE 122 | ||
1654 | #define SSL_R_BAD_SIGNATURE 123 | ||
1655 | #define SSL_R_BAD_SSL_FILETYPE 124 | ||
1656 | #define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125 | ||
1657 | #define SSL_R_BAD_STATE 126 | ||
1658 | #define SSL_R_BAD_WRITE_RETRY 127 | ||
1659 | #define SSL_R_BIO_NOT_SET 128 | ||
1660 | #define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 | ||
1661 | #define SSL_R_BN_LIB 130 | ||
1662 | #define SSL_R_CA_DN_LENGTH_MISMATCH 131 | ||
1663 | #define SSL_R_CA_DN_TOO_LONG 132 | ||
1664 | #define SSL_R_CCS_RECEIVED_EARLY 133 | ||
1665 | #define SSL_R_CERTIFICATE_VERIFY_FAILED 134 | ||
1666 | #define SSL_R_CERT_LENGTH_MISMATCH 135 | ||
1667 | #define SSL_R_CHALLENGE_IS_DIFFERENT 136 | ||
1668 | #define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 | ||
1669 | #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 | ||
1670 | #define SSL_R_CIPHER_TABLE_SRC_ERROR 139 | ||
1671 | #define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 | ||
1672 | #define SSL_R_COMPRESSION_FAILURE 141 | ||
1673 | #define SSL_R_COMPRESSION_LIBRARY_ERROR 142 | ||
1674 | #define SSL_R_CONNECTION_ID_IS_DIFFERENT 143 | ||
1675 | #define SSL_R_CONNECTION_TYPE_NOT_SET 144 | ||
1676 | #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 | ||
1677 | #define SSL_R_DATA_LENGTH_TOO_LONG 146 | ||
1678 | #define SSL_R_DECRYPTION_FAILED 147 | ||
1679 | #define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281 | ||
1680 | #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 | ||
1681 | #define SSL_R_DIGEST_CHECK_FAILED 149 | ||
1682 | #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 | ||
1683 | #define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282 | ||
1684 | #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 | ||
1685 | #define SSL_R_EXCESSIVE_MESSAGE_SIZE 152 | ||
1686 | #define SSL_R_EXTRA_DATA_IN_MESSAGE 153 | ||
1687 | #define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154 | ||
1688 | #define SSL_R_HTTPS_PROXY_REQUEST 155 | ||
1689 | #define SSL_R_HTTP_REQUEST 156 | ||
1690 | #define SSL_R_ILLEGAL_PADDING 283 | ||
1691 | #define SSL_R_INVALID_CHALLENGE_LENGTH 158 | ||
1692 | #define SSL_R_INVALID_COMMAND 280 | ||
1693 | #define SSL_R_INVALID_PURPOSE 278 | ||
1694 | #define SSL_R_INVALID_TRUST 279 | ||
1695 | #define SSL_R_KEY_ARG_TOO_LONG 284 | ||
1696 | #define SSL_R_KRB5 285 | ||
1697 | #define SSL_R_KRB5_C_CC_PRINC 286 | ||
1698 | #define SSL_R_KRB5_C_GET_CRED 287 | ||
1699 | #define SSL_R_KRB5_C_INIT 288 | ||
1700 | #define SSL_R_KRB5_C_MK_REQ 289 | ||
1701 | #define SSL_R_KRB5_S_BAD_TICKET 290 | ||
1702 | #define SSL_R_KRB5_S_INIT 291 | ||
1703 | #define SSL_R_KRB5_S_RD_REQ 292 | ||
1704 | #define SSL_R_KRB5_S_TKT_EXPIRED 293 | ||
1705 | #define SSL_R_KRB5_S_TKT_NYV 294 | ||
1706 | #define SSL_R_KRB5_S_TKT_SKEW 295 | ||
1707 | #define SSL_R_LENGTH_MISMATCH 159 | ||
1708 | #define SSL_R_LENGTH_TOO_SHORT 160 | ||
1709 | #define SSL_R_LIBRARY_BUG 274 | ||
1710 | #define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 | ||
1711 | #define SSL_R_MESSAGE_TOO_LONG 296 | ||
1712 | #define SSL_R_MISSING_DH_DSA_CERT 162 | ||
1713 | #define SSL_R_MISSING_DH_KEY 163 | ||
1714 | #define SSL_R_MISSING_DH_RSA_CERT 164 | ||
1715 | #define SSL_R_MISSING_DSA_SIGNING_CERT 165 | ||
1716 | #define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166 | ||
1717 | #define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167 | ||
1718 | #define SSL_R_MISSING_RSA_CERTIFICATE 168 | ||
1719 | #define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 | ||
1720 | #define SSL_R_MISSING_RSA_SIGNING_CERT 170 | ||
1721 | #define SSL_R_MISSING_TMP_DH_KEY 171 | ||
1722 | #define SSL_R_MISSING_TMP_RSA_KEY 172 | ||
1723 | #define SSL_R_MISSING_TMP_RSA_PKEY 173 | ||
1724 | #define SSL_R_MISSING_VERIFY_MESSAGE 174 | ||
1725 | #define SSL_R_NON_SSLV2_INITIAL_PACKET 175 | ||
1726 | #define SSL_R_NO_CERTIFICATES_RETURNED 176 | ||
1727 | #define SSL_R_NO_CERTIFICATE_ASSIGNED 177 | ||
1728 | #define SSL_R_NO_CERTIFICATE_RETURNED 178 | ||
1729 | #define SSL_R_NO_CERTIFICATE_SET 179 | ||
1730 | #define SSL_R_NO_CERTIFICATE_SPECIFIED 180 | ||
1731 | #define SSL_R_NO_CIPHERS_AVAILABLE 181 | ||
1732 | #define SSL_R_NO_CIPHERS_PASSED 182 | ||
1733 | #define SSL_R_NO_CIPHERS_SPECIFIED 183 | ||
1734 | #define SSL_R_NO_CIPHER_LIST 184 | ||
1735 | #define SSL_R_NO_CIPHER_MATCH 185 | ||
1736 | #define SSL_R_NO_CLIENT_CERT_RECEIVED 186 | ||
1737 | #define SSL_R_NO_COMPRESSION_SPECIFIED 187 | ||
1738 | #define SSL_R_NO_METHOD_SPECIFIED 188 | ||
1739 | #define SSL_R_NO_PRIVATEKEY 189 | ||
1740 | #define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 | ||
1741 | #define SSL_R_NO_PROTOCOLS_AVAILABLE 191 | ||
1742 | #define SSL_R_NO_PUBLICKEY 192 | ||
1743 | #define SSL_R_NO_SHARED_CIPHER 193 | ||
1744 | #define SSL_R_NO_VERIFY_CALLBACK 194 | ||
1745 | #define SSL_R_NULL_SSL_CTX 195 | ||
1746 | #define SSL_R_NULL_SSL_METHOD_PASSED 196 | ||
1747 | #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 | ||
1748 | #define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297 | ||
1749 | #define SSL_R_PACKET_LENGTH_TOO_LONG 198 | ||
1750 | #define SSL_R_PATH_TOO_LONG 270 | ||
1751 | #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 | ||
1752 | #define SSL_R_PEER_ERROR 200 | ||
1753 | #define SSL_R_PEER_ERROR_CERTIFICATE 201 | ||
1754 | #define SSL_R_PEER_ERROR_NO_CERTIFICATE 202 | ||
1755 | #define SSL_R_PEER_ERROR_NO_CIPHER 203 | ||
1756 | #define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204 | ||
1757 | #define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205 | ||
1758 | #define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206 | ||
1759 | #define SSL_R_PROTOCOL_IS_SHUTDOWN 207 | ||
1760 | #define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208 | ||
1761 | #define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209 | ||
1762 | #define SSL_R_PUBLIC_KEY_NOT_RSA 210 | ||
1763 | #define SSL_R_READ_BIO_NOT_SET 211 | ||
1764 | #define SSL_R_READ_WRONG_PACKET_TYPE 212 | ||
1765 | #define SSL_R_RECORD_LENGTH_MISMATCH 213 | ||
1766 | #define SSL_R_RECORD_TOO_LARGE 214 | ||
1767 | #define SSL_R_RECORD_TOO_SMALL 298 | ||
1768 | #define SSL_R_REQUIRED_CIPHER_MISSING 215 | ||
1769 | #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216 | ||
1770 | #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217 | ||
1771 | #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218 | ||
1772 | #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 | ||
1773 | #define SSL_R_SHORT_READ 219 | ||
1774 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 | ||
1775 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 | ||
1776 | #define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299 | ||
1777 | #define SSL_R_SSL3_SESSION_ID_TOO_LONG 300 | ||
1778 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 | ||
1779 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 | ||
1780 | #define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 | ||
1781 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 | ||
1782 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 | ||
1783 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 | ||
1784 | #define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 | ||
1785 | #define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 | ||
1786 | #define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 | ||
1787 | #define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 | ||
1788 | #define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 | ||
1789 | #define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 | ||
1790 | #define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228 | ||
1791 | #define SSL_R_SSL_HANDSHAKE_FAILURE 229 | ||
1792 | #define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230 | ||
1793 | #define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301 | ||
1794 | #define SSL_R_SSL_SESSION_ID_CONFLICT 302 | ||
1795 | #define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273 | ||
1796 | #define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303 | ||
1797 | #define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231 | ||
1798 | #define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 | ||
1799 | #define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 | ||
1800 | #define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 | ||
1801 | #define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 | ||
1802 | #define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060 | ||
1803 | #define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 | ||
1804 | #define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 | ||
1805 | #define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 | ||
1806 | #define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 | ||
1807 | #define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 | ||
1808 | #define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 | ||
1809 | #define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 | ||
1810 | #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232 | ||
1811 | #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233 | ||
1812 | #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234 | ||
1813 | #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235 | ||
1814 | #define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236 | ||
1815 | #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237 | ||
1816 | #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238 | ||
1817 | #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 | ||
1818 | #define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240 | ||
1819 | #define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241 | ||
1820 | #define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242 | ||
1821 | #define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243 | ||
1822 | #define SSL_R_UNEXPECTED_MESSAGE 244 | ||
1823 | #define SSL_R_UNEXPECTED_RECORD 245 | ||
1824 | #define SSL_R_UNINITIALIZED 276 | ||
1825 | #define SSL_R_UNKNOWN_ALERT_TYPE 246 | ||
1826 | #define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247 | ||
1827 | #define SSL_R_UNKNOWN_CIPHER_RETURNED 248 | ||
1828 | #define SSL_R_UNKNOWN_CIPHER_TYPE 249 | ||
1829 | #define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250 | ||
1830 | #define SSL_R_UNKNOWN_PKEY_TYPE 251 | ||
1831 | #define SSL_R_UNKNOWN_PROTOCOL 252 | ||
1832 | #define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253 | ||
1833 | #define SSL_R_UNKNOWN_SSL_VERSION 254 | ||
1834 | #define SSL_R_UNKNOWN_STATE 255 | ||
1835 | #define SSL_R_UNSUPPORTED_CIPHER 256 | ||
1836 | #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 | ||
1837 | #define SSL_R_UNSUPPORTED_PROTOCOL 258 | ||
1838 | #define SSL_R_UNSUPPORTED_SSL_VERSION 259 | ||
1839 | #define SSL_R_WRITE_BIO_NOT_SET 260 | ||
1840 | #define SSL_R_WRONG_CIPHER_RETURNED 261 | ||
1841 | #define SSL_R_WRONG_MESSAGE_TYPE 262 | ||
1842 | #define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263 | ||
1843 | #define SSL_R_WRONG_SIGNATURE_LENGTH 264 | ||
1844 | #define SSL_R_WRONG_SIGNATURE_SIZE 265 | ||
1845 | #define SSL_R_WRONG_SSL_VERSION 266 | ||
1846 | #define SSL_R_WRONG_VERSION_NUMBER 267 | ||
1847 | #define SSL_R_X509_LIB 268 | ||
1848 | #define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 | ||
1849 | |||
1850 | #ifdef __cplusplus | ||
1851 | } | ||
1852 | #endif | ||
1853 | #endif | ||
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h deleted file mode 100644 index 99a52ea0dd..0000000000 --- a/src/lib/libssl/ssl2.h +++ /dev/null | |||
@@ -1,268 +0,0 @@ | |||
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 | |||
59 | #ifndef HEADER_SSL2_H | ||
60 | #define HEADER_SSL2_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | /* Protocol Version Codes */ | ||
67 | #define SSL2_VERSION 0x0002 | ||
68 | #define SSL2_VERSION_MAJOR 0x00 | ||
69 | #define SSL2_VERSION_MINOR 0x02 | ||
70 | /* #define SSL2_CLIENT_VERSION 0x0002 */ | ||
71 | /* #define SSL2_SERVER_VERSION 0x0002 */ | ||
72 | |||
73 | /* Protocol Message Codes */ | ||
74 | #define SSL2_MT_ERROR 0 | ||
75 | #define SSL2_MT_CLIENT_HELLO 1 | ||
76 | #define SSL2_MT_CLIENT_MASTER_KEY 2 | ||
77 | #define SSL2_MT_CLIENT_FINISHED 3 | ||
78 | #define SSL2_MT_SERVER_HELLO 4 | ||
79 | #define SSL2_MT_SERVER_VERIFY 5 | ||
80 | #define SSL2_MT_SERVER_FINISHED 6 | ||
81 | #define SSL2_MT_REQUEST_CERTIFICATE 7 | ||
82 | #define SSL2_MT_CLIENT_CERTIFICATE 8 | ||
83 | |||
84 | /* Error Message Codes */ | ||
85 | #define SSL2_PE_UNDEFINED_ERROR 0x0000 | ||
86 | #define SSL2_PE_NO_CIPHER 0x0001 | ||
87 | #define SSL2_PE_NO_CERTIFICATE 0x0002 | ||
88 | #define SSL2_PE_BAD_CERTIFICATE 0x0004 | ||
89 | #define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006 | ||
90 | |||
91 | /* Cipher Kind Values */ | ||
92 | #define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */ | ||
93 | #define SSL2_CK_RC4_128_WITH_MD5 0x02010080 | ||
94 | #define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080 | ||
95 | #define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080 | ||
96 | #define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080 | ||
97 | #define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080 | ||
98 | #define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040 | ||
99 | #define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */ | ||
100 | #define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0 | ||
101 | #define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */ | ||
102 | #define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */ | ||
103 | |||
104 | #define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */ | ||
105 | #define SSL2_CK_NULL 0x02ff0810 /* SSLeay */ | ||
106 | |||
107 | #define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1" | ||
108 | #define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5" | ||
109 | #define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5" | ||
110 | #define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5" | ||
111 | #define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5" | ||
112 | #define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5" | ||
113 | #define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5" | ||
114 | #define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5" | ||
115 | #define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA" | ||
116 | #define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5" | ||
117 | #define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA" | ||
118 | #define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5" | ||
119 | |||
120 | #define SSL2_TXT_NULL "NULL" | ||
121 | |||
122 | /* Flags for the SSL_CIPHER.algorithm2 field */ | ||
123 | #define SSL2_CF_5_BYTE_ENC 0x01 | ||
124 | #define SSL2_CF_8_BYTE_ENC 0x02 | ||
125 | |||
126 | /* Certificate Type Codes */ | ||
127 | #define SSL2_CT_X509_CERTIFICATE 0x01 | ||
128 | |||
129 | /* Authentication Type Code */ | ||
130 | #define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01 | ||
131 | |||
132 | #define SSL2_MAX_SSL_SESSION_ID_LENGTH 32 | ||
133 | |||
134 | /* Upper/Lower Bounds */ | ||
135 | #define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256 | ||
136 | #ifdef OPENSSL_SYS_MPE | ||
137 | #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u | ||
138 | #else | ||
139 | #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */ | ||
140 | #endif | ||
141 | #define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */ | ||
142 | |||
143 | #define SSL2_CHALLENGE_LENGTH 16 | ||
144 | /*#define SSL2_CHALLENGE_LENGTH 32 */ | ||
145 | #define SSL2_MIN_CHALLENGE_LENGTH 16 | ||
146 | #define SSL2_MAX_CHALLENGE_LENGTH 32 | ||
147 | #define SSL2_CONNECTION_ID_LENGTH 16 | ||
148 | #define SSL2_MAX_CONNECTION_ID_LENGTH 16 | ||
149 | #define SSL2_SSL_SESSION_ID_LENGTH 16 | ||
150 | #define SSL2_MAX_CERT_CHALLENGE_LENGTH 32 | ||
151 | #define SSL2_MIN_CERT_CHALLENGE_LENGTH 16 | ||
152 | #define SSL2_MAX_KEY_MATERIAL_LENGTH 24 | ||
153 | |||
154 | #ifndef HEADER_SSL_LOCL_H | ||
155 | #define CERT char | ||
156 | #endif | ||
157 | |||
158 | typedef struct ssl2_state_st | ||
159 | { | ||
160 | int three_byte_header; | ||
161 | int clear_text; /* clear text */ | ||
162 | int escape; /* not used in SSLv2 */ | ||
163 | int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */ | ||
164 | |||
165 | /* non-blocking io info, used to make sure the same | ||
166 | * args were passwd */ | ||
167 | unsigned int wnum; /* number of bytes sent so far */ | ||
168 | int wpend_tot; | ||
169 | const unsigned char *wpend_buf; | ||
170 | |||
171 | int wpend_off; /* offset to data to write */ | ||
172 | int wpend_len; /* number of bytes passwd to write */ | ||
173 | int wpend_ret; /* number of bytes to return to caller */ | ||
174 | |||
175 | /* buffer raw data */ | ||
176 | int rbuf_left; | ||
177 | int rbuf_offs; | ||
178 | unsigned char *rbuf; | ||
179 | unsigned char *wbuf; | ||
180 | |||
181 | unsigned char *write_ptr;/* used to point to the start due to | ||
182 | * 2/3 byte header. */ | ||
183 | |||
184 | unsigned int padding; | ||
185 | unsigned int rlength; /* passed to ssl2_enc */ | ||
186 | int ract_data_length; /* Set when things are encrypted. */ | ||
187 | unsigned int wlength; /* passed to ssl2_enc */ | ||
188 | int wact_data_length; /* Set when things are decrypted. */ | ||
189 | unsigned char *ract_data; | ||
190 | unsigned char *wact_data; | ||
191 | unsigned char *mac_data; | ||
192 | |||
193 | unsigned char *read_key; | ||
194 | unsigned char *write_key; | ||
195 | |||
196 | /* Stuff specifically to do with this SSL session */ | ||
197 | unsigned int challenge_length; | ||
198 | unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH]; | ||
199 | unsigned int conn_id_length; | ||
200 | unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH]; | ||
201 | unsigned int key_material_length; | ||
202 | unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2]; | ||
203 | |||
204 | unsigned long read_sequence; | ||
205 | unsigned long write_sequence; | ||
206 | |||
207 | struct { | ||
208 | unsigned int conn_id_length; | ||
209 | unsigned int cert_type; | ||
210 | unsigned int cert_length; | ||
211 | unsigned int csl; | ||
212 | unsigned int clear; | ||
213 | unsigned int enc; | ||
214 | unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH]; | ||
215 | unsigned int cipher_spec_length; | ||
216 | unsigned int session_id_length; | ||
217 | unsigned int clen; | ||
218 | unsigned int rlen; | ||
219 | } tmp; | ||
220 | } SSL2_STATE; | ||
221 | |||
222 | /* SSLv2 */ | ||
223 | /* client */ | ||
224 | #define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT) | ||
225 | #define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT) | ||
226 | #define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT) | ||
227 | #define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT) | ||
228 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT) | ||
229 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT) | ||
230 | #define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT) | ||
231 | #define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT) | ||
232 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT) | ||
233 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT) | ||
234 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT) | ||
235 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT) | ||
236 | #define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT) | ||
237 | #define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT) | ||
238 | #define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT) | ||
239 | #define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT) | ||
240 | #define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT) | ||
241 | #define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT) | ||
242 | /* server */ | ||
243 | #define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT) | ||
244 | #define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT) | ||
245 | #define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT) | ||
246 | #define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT) | ||
247 | #define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT) | ||
248 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT) | ||
249 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT) | ||
250 | #define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT) | ||
251 | #define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT) | ||
252 | #define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT) | ||
253 | #define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT) | ||
254 | #define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT) | ||
255 | #define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT) | ||
256 | #define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT) | ||
257 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT) | ||
258 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT) | ||
259 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT) | ||
260 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT) | ||
261 | #define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT) | ||
262 | #define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT) | ||
263 | |||
264 | #ifdef __cplusplus | ||
265 | } | ||
266 | #endif | ||
267 | #endif | ||
268 | |||
diff --git a/src/lib/libssl/ssl23.h b/src/lib/libssl/ssl23.h deleted file mode 100644 index d3228983c7..0000000000 --- a/src/lib/libssl/ssl23.h +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | /* ssl/ssl23.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 | |||
59 | #ifndef HEADER_SSL23_H | ||
60 | #define HEADER_SSL23_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | /*client */ | ||
67 | /* write to server */ | ||
68 | #define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT) | ||
69 | #define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT) | ||
70 | /* read from server */ | ||
71 | #define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT) | ||
72 | #define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT) | ||
73 | |||
74 | /* server */ | ||
75 | /* read from client */ | ||
76 | #define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT) | ||
77 | #define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT) | ||
78 | |||
79 | #ifdef __cplusplus | ||
80 | } | ||
81 | #endif | ||
82 | #endif | ||
83 | |||
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h deleted file mode 100644 index 1153aeda74..0000000000 --- a/src/lib/libssl/ssl3.h +++ /dev/null | |||
@@ -1,526 +0,0 @@ | |||
1 | /* ssl/ssl3.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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #ifndef HEADER_SSL3_H | ||
113 | #define HEADER_SSL3_H | ||
114 | |||
115 | #ifndef OPENSSL_NO_COMP | ||
116 | #include <openssl/comp.h> | ||
117 | #endif | ||
118 | #include <openssl/buffer.h> | ||
119 | #include <openssl/evp.h> | ||
120 | #include <openssl/ssl.h> | ||
121 | |||
122 | #ifdef __cplusplus | ||
123 | extern "C" { | ||
124 | #endif | ||
125 | |||
126 | #define SSL3_CK_RSA_NULL_MD5 0x03000001 | ||
127 | #define SSL3_CK_RSA_NULL_SHA 0x03000002 | ||
128 | #define SSL3_CK_RSA_RC4_40_MD5 0x03000003 | ||
129 | #define SSL3_CK_RSA_RC4_128_MD5 0x03000004 | ||
130 | #define SSL3_CK_RSA_RC4_128_SHA 0x03000005 | ||
131 | #define SSL3_CK_RSA_RC2_40_MD5 0x03000006 | ||
132 | #define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 | ||
133 | #define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 | ||
134 | #define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 | ||
135 | #define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A | ||
136 | |||
137 | #define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B | ||
138 | #define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C | ||
139 | #define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D | ||
140 | #define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E | ||
141 | #define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F | ||
142 | #define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 | ||
143 | |||
144 | #define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011 | ||
145 | #define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012 | ||
146 | #define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013 | ||
147 | #define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014 | ||
148 | #define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015 | ||
149 | #define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016 | ||
150 | |||
151 | #define SSL3_CK_ADH_RC4_40_MD5 0x03000017 | ||
152 | #define SSL3_CK_ADH_RC4_128_MD5 0x03000018 | ||
153 | #define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 | ||
154 | #define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A | ||
155 | #define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B | ||
156 | |||
157 | #define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C | ||
158 | #define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D | ||
159 | #if 0 /* Because it clashes with KRB5, is never used any more, and is safe | ||
160 | to remove according to David Hopwood <david.hopwood@zetnet.co.uk> | ||
161 | of the ietf-tls list */ | ||
162 | #define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E | ||
163 | #endif | ||
164 | |||
165 | /* VRS Additional Kerberos5 entries | ||
166 | */ | ||
167 | #define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E | ||
168 | #define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F | ||
169 | #define SSL3_CK_KRB5_RC4_128_SHA 0x03000020 | ||
170 | #define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021 | ||
171 | #define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022 | ||
172 | #define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023 | ||
173 | #define SSL3_CK_KRB5_RC4_128_MD5 0x03000024 | ||
174 | #define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025 | ||
175 | |||
176 | #define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026 | ||
177 | #define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027 | ||
178 | #define SSL3_CK_KRB5_RC4_40_SHA 0x03000028 | ||
179 | #define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029 | ||
180 | #define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A | ||
181 | #define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B | ||
182 | |||
183 | #define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" | ||
184 | #define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" | ||
185 | #define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" | ||
186 | #define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" | ||
187 | #define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" | ||
188 | #define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" | ||
189 | #define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" | ||
190 | #define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" | ||
191 | #define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" | ||
192 | #define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" | ||
193 | |||
194 | #define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" | ||
195 | #define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" | ||
196 | #define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" | ||
197 | #define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" | ||
198 | #define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" | ||
199 | #define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" | ||
200 | |||
201 | #define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" | ||
202 | #define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" | ||
203 | #define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" | ||
204 | #define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" | ||
205 | #define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" | ||
206 | #define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" | ||
207 | |||
208 | #define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" | ||
209 | #define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" | ||
210 | #define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" | ||
211 | #define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" | ||
212 | #define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" | ||
213 | |||
214 | #define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA" | ||
215 | #define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" | ||
216 | #define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" | ||
217 | |||
218 | #define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA" | ||
219 | #define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA" | ||
220 | #define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA" | ||
221 | #define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA" | ||
222 | #define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5" | ||
223 | #define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5" | ||
224 | #define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5" | ||
225 | #define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5" | ||
226 | |||
227 | #define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA" | ||
228 | #define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA" | ||
229 | #define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA" | ||
230 | #define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5" | ||
231 | #define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5" | ||
232 | #define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5" | ||
233 | |||
234 | #define SSL3_SSL_SESSION_ID_LENGTH 32 | ||
235 | #define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 | ||
236 | |||
237 | #define SSL3_MASTER_SECRET_SIZE 48 | ||
238 | #define SSL3_RANDOM_SIZE 32 | ||
239 | #define SSL3_SESSION_ID_SIZE 32 | ||
240 | #define SSL3_RT_HEADER_LENGTH 5 | ||
241 | |||
242 | /* Due to MS stuffing up, this can change.... */ | ||
243 | #if defined(OPENSSL_SYS_WIN16) || \ | ||
244 | (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32)) | ||
245 | #define SSL3_RT_MAX_EXTRA (14000) | ||
246 | #else | ||
247 | #define SSL3_RT_MAX_EXTRA (16384) | ||
248 | #endif | ||
249 | |||
250 | #define SSL3_RT_MAX_PLAIN_LENGTH 16384 | ||
251 | #define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) | ||
252 | #define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) | ||
253 | #define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) | ||
254 | #define SSL3_RT_MAX_DATA_SIZE (1024*1024) | ||
255 | |||
256 | #define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54" | ||
257 | #define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52" | ||
258 | |||
259 | #define SSL3_VERSION 0x0300 | ||
260 | #define SSL3_VERSION_MAJOR 0x03 | ||
261 | #define SSL3_VERSION_MINOR 0x00 | ||
262 | |||
263 | #define SSL3_RT_CHANGE_CIPHER_SPEC 20 | ||
264 | #define SSL3_RT_ALERT 21 | ||
265 | #define SSL3_RT_HANDSHAKE 22 | ||
266 | #define SSL3_RT_APPLICATION_DATA 23 | ||
267 | |||
268 | #define SSL3_AL_WARNING 1 | ||
269 | #define SSL3_AL_FATAL 2 | ||
270 | |||
271 | #define SSL3_AD_CLOSE_NOTIFY 0 | ||
272 | #define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */ | ||
273 | #define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */ | ||
274 | #define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */ | ||
275 | #define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */ | ||
276 | #define SSL3_AD_NO_CERTIFICATE 41 | ||
277 | #define SSL3_AD_BAD_CERTIFICATE 42 | ||
278 | #define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 | ||
279 | #define SSL3_AD_CERTIFICATE_REVOKED 44 | ||
280 | #define SSL3_AD_CERTIFICATE_EXPIRED 45 | ||
281 | #define SSL3_AD_CERTIFICATE_UNKNOWN 46 | ||
282 | #define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */ | ||
283 | |||
284 | typedef struct ssl3_record_st | ||
285 | { | ||
286 | /*r */ int type; /* type of record */ | ||
287 | /*rw*/ unsigned int length; /* How many bytes available */ | ||
288 | /*r */ unsigned int off; /* read/write offset into 'buf' */ | ||
289 | /*rw*/ unsigned char *data; /* pointer to the record data */ | ||
290 | /*rw*/ unsigned char *input; /* where the decode bytes are */ | ||
291 | /*r */ unsigned char *comp; /* only used with decompression - malloc()ed */ | ||
292 | } SSL3_RECORD; | ||
293 | |||
294 | typedef struct ssl3_buffer_st | ||
295 | { | ||
296 | unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes, | ||
297 | * see ssl3_setup_buffers() */ | ||
298 | size_t len; /* buffer size */ | ||
299 | int offset; /* where to 'copy from' */ | ||
300 | int left; /* how many bytes left */ | ||
301 | } SSL3_BUFFER; | ||
302 | |||
303 | #define SSL3_CT_RSA_SIGN 1 | ||
304 | #define SSL3_CT_DSS_SIGN 2 | ||
305 | #define SSL3_CT_RSA_FIXED_DH 3 | ||
306 | #define SSL3_CT_DSS_FIXED_DH 4 | ||
307 | #define SSL3_CT_RSA_EPHEMERAL_DH 5 | ||
308 | #define SSL3_CT_DSS_EPHEMERAL_DH 6 | ||
309 | #define SSL3_CT_FORTEZZA_DMS 20 | ||
310 | #define SSL3_CT_NUMBER 7 | ||
311 | |||
312 | #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 | ||
313 | #define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 | ||
314 | #define SSL3_FLAGS_POP_BUFFER 0x0004 | ||
315 | #define TLS1_FLAGS_TLS_PADDING_BUG 0x0008 | ||
316 | |||
317 | typedef struct ssl3_state_st | ||
318 | { | ||
319 | long flags; | ||
320 | int delay_buf_pop_ret; | ||
321 | |||
322 | unsigned char read_sequence[8]; | ||
323 | unsigned char read_mac_secret[EVP_MAX_MD_SIZE]; | ||
324 | unsigned char write_sequence[8]; | ||
325 | unsigned char write_mac_secret[EVP_MAX_MD_SIZE]; | ||
326 | |||
327 | unsigned char server_random[SSL3_RANDOM_SIZE]; | ||
328 | unsigned char client_random[SSL3_RANDOM_SIZE]; | ||
329 | |||
330 | /* flags for countermeasure against known-IV weakness */ | ||
331 | int need_empty_fragments; | ||
332 | int empty_fragment_done; | ||
333 | |||
334 | SSL3_BUFFER rbuf; /* read IO goes into here */ | ||
335 | SSL3_BUFFER wbuf; /* write IO goes into here */ | ||
336 | |||
337 | SSL3_RECORD rrec; /* each decoded record goes in here */ | ||
338 | SSL3_RECORD wrec; /* goes out from here */ | ||
339 | |||
340 | /* storage for Alert/Handshake protocol data received but not | ||
341 | * yet processed by ssl3_read_bytes: */ | ||
342 | unsigned char alert_fragment[2]; | ||
343 | unsigned int alert_fragment_len; | ||
344 | unsigned char handshake_fragment[4]; | ||
345 | unsigned int handshake_fragment_len; | ||
346 | |||
347 | /* partial write - check the numbers match */ | ||
348 | unsigned int wnum; /* number of bytes sent so far */ | ||
349 | int wpend_tot; /* number bytes written */ | ||
350 | int wpend_type; | ||
351 | int wpend_ret; /* number of bytes submitted */ | ||
352 | const unsigned char *wpend_buf; | ||
353 | |||
354 | /* used during startup, digest all incoming/outgoing packets */ | ||
355 | EVP_MD_CTX finish_dgst1; | ||
356 | EVP_MD_CTX finish_dgst2; | ||
357 | |||
358 | /* this is set whenerver we see a change_cipher_spec message | ||
359 | * come in when we are not looking for one */ | ||
360 | int change_cipher_spec; | ||
361 | |||
362 | int warn_alert; | ||
363 | int fatal_alert; | ||
364 | /* we allow one fatal and one warning alert to be outstanding, | ||
365 | * send close alert via the warning alert */ | ||
366 | int alert_dispatch; | ||
367 | unsigned char send_alert[2]; | ||
368 | |||
369 | /* This flag is set when we should renegotiate ASAP, basically when | ||
370 | * there is no more data in the read or write buffers */ | ||
371 | int renegotiate; | ||
372 | int total_renegotiations; | ||
373 | int num_renegotiations; | ||
374 | |||
375 | int in_read_app_data; | ||
376 | |||
377 | struct { | ||
378 | /* actually only needs to be 16+20 */ | ||
379 | unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2]; | ||
380 | |||
381 | /* actually only need to be 16+20 for SSLv3 and 12 for TLS */ | ||
382 | unsigned char finish_md[EVP_MAX_MD_SIZE*2]; | ||
383 | int finish_md_len; | ||
384 | unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2]; | ||
385 | int peer_finish_md_len; | ||
386 | |||
387 | unsigned long message_size; | ||
388 | int message_type; | ||
389 | |||
390 | /* used to hold the new cipher we are going to use */ | ||
391 | SSL_CIPHER *new_cipher; | ||
392 | #ifndef OPENSSL_NO_DH | ||
393 | DH *dh; | ||
394 | #endif | ||
395 | /* used when SSL_ST_FLUSH_DATA is entered */ | ||
396 | int next_state; | ||
397 | |||
398 | int reuse_message; | ||
399 | |||
400 | /* used for certificate requests */ | ||
401 | int cert_req; | ||
402 | int ctype_num; | ||
403 | char ctype[SSL3_CT_NUMBER]; | ||
404 | STACK_OF(X509_NAME) *ca_names; | ||
405 | |||
406 | int use_rsa_tmp; | ||
407 | |||
408 | int key_block_length; | ||
409 | unsigned char *key_block; | ||
410 | |||
411 | const EVP_CIPHER *new_sym_enc; | ||
412 | const EVP_MD *new_hash; | ||
413 | #ifndef OPENSSL_NO_COMP | ||
414 | const SSL_COMP *new_compression; | ||
415 | #else | ||
416 | char *new_compression; | ||
417 | #endif | ||
418 | int cert_request; | ||
419 | } tmp; | ||
420 | |||
421 | } SSL3_STATE; | ||
422 | |||
423 | /* SSLv3 */ | ||
424 | /*client */ | ||
425 | /* extra state */ | ||
426 | #define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT) | ||
427 | /* write to server */ | ||
428 | #define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT) | ||
429 | #define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT) | ||
430 | /* read from server */ | ||
431 | #define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) | ||
432 | #define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) | ||
433 | #define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) | ||
434 | #define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) | ||
435 | #define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) | ||
436 | #define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT) | ||
437 | #define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT) | ||
438 | #define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT) | ||
439 | #define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT) | ||
440 | #define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT) | ||
441 | /* write to server */ | ||
442 | #define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT) | ||
443 | #define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT) | ||
444 | #define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT) | ||
445 | #define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT) | ||
446 | #define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT) | ||
447 | #define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT) | ||
448 | #define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT) | ||
449 | #define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT) | ||
450 | #define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT) | ||
451 | #define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT) | ||
452 | #define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT) | ||
453 | #define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT) | ||
454 | /* read from server */ | ||
455 | #define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT) | ||
456 | #define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) | ||
457 | #define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) | ||
458 | #define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) | ||
459 | |||
460 | /* server */ | ||
461 | /* extra state */ | ||
462 | #define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT) | ||
463 | /* read from client */ | ||
464 | /* Do not change the number values, they do matter */ | ||
465 | #define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT) | ||
466 | #define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) | ||
467 | #define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) | ||
468 | /* write to client */ | ||
469 | #define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) | ||
470 | #define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) | ||
471 | #define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) | ||
472 | #define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT) | ||
473 | #define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT) | ||
474 | #define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT) | ||
475 | #define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT) | ||
476 | #define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT) | ||
477 | #define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT) | ||
478 | #define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT) | ||
479 | #define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT) | ||
480 | #define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT) | ||
481 | #define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT) | ||
482 | /* read from client */ | ||
483 | #define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT) | ||
484 | #define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT) | ||
485 | #define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT) | ||
486 | #define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT) | ||
487 | #define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT) | ||
488 | #define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT) | ||
489 | #define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT) | ||
490 | #define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT) | ||
491 | #define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT) | ||
492 | #define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT) | ||
493 | /* write to client */ | ||
494 | #define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT) | ||
495 | #define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) | ||
496 | #define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) | ||
497 | #define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) | ||
498 | |||
499 | #define SSL3_MT_HELLO_REQUEST 0 | ||
500 | #define SSL3_MT_CLIENT_HELLO 1 | ||
501 | #define SSL3_MT_SERVER_HELLO 2 | ||
502 | #define SSL3_MT_CERTIFICATE 11 | ||
503 | #define SSL3_MT_SERVER_KEY_EXCHANGE 12 | ||
504 | #define SSL3_MT_CERTIFICATE_REQUEST 13 | ||
505 | #define SSL3_MT_SERVER_DONE 14 | ||
506 | #define SSL3_MT_CERTIFICATE_VERIFY 15 | ||
507 | #define SSL3_MT_CLIENT_KEY_EXCHANGE 16 | ||
508 | #define SSL3_MT_FINISHED 20 | ||
509 | |||
510 | #define SSL3_MT_CCS 1 | ||
511 | |||
512 | /* These are used when changing over to a new cipher */ | ||
513 | #define SSL3_CC_READ 0x01 | ||
514 | #define SSL3_CC_WRITE 0x02 | ||
515 | #define SSL3_CC_CLIENT 0x10 | ||
516 | #define SSL3_CC_SERVER 0x20 | ||
517 | #define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) | ||
518 | #define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) | ||
519 | #define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) | ||
520 | #define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) | ||
521 | |||
522 | #ifdef __cplusplus | ||
523 | } | ||
524 | #endif | ||
525 | #endif | ||
526 | |||
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c deleted file mode 100644 index 3d1299ee7b..0000000000 --- a/src/lib/libssl/ssl_algs.c +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | /* ssl/ssl_algs.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/objects.h> | ||
61 | #include <openssl/lhash.h> | ||
62 | #include "ssl_locl.h" | ||
63 | |||
64 | int SSL_library_init(void) | ||
65 | { | ||
66 | |||
67 | #ifndef OPENSSL_NO_DES | ||
68 | EVP_add_cipher(EVP_des_cbc()); | ||
69 | EVP_add_cipher(EVP_des_ede3_cbc()); | ||
70 | #endif | ||
71 | #ifndef OPENSSL_NO_IDEA | ||
72 | EVP_add_cipher(EVP_idea_cbc()); | ||
73 | #endif | ||
74 | #ifndef OPENSSL_NO_RC4 | ||
75 | EVP_add_cipher(EVP_rc4()); | ||
76 | #endif | ||
77 | #ifndef OPENSSL_NO_RC2 | ||
78 | EVP_add_cipher(EVP_rc2_cbc()); | ||
79 | #endif | ||
80 | #ifndef OPENSSL_NO_AES | ||
81 | EVP_add_cipher(EVP_aes_128_cbc()); | ||
82 | EVP_add_cipher(EVP_aes_192_cbc()); | ||
83 | EVP_add_cipher(EVP_aes_256_cbc()); | ||
84 | #endif | ||
85 | #ifndef OPENSSL_NO_MD2 | ||
86 | EVP_add_digest(EVP_md2()); | ||
87 | #endif | ||
88 | #ifndef OPENSSL_NO_MD5 | ||
89 | EVP_add_digest(EVP_md5()); | ||
90 | EVP_add_digest_alias(SN_md5,"ssl2-md5"); | ||
91 | EVP_add_digest_alias(SN_md5,"ssl3-md5"); | ||
92 | #endif | ||
93 | #ifndef OPENSSL_NO_SHA | ||
94 | EVP_add_digest(EVP_sha1()); /* RSA with sha1 */ | ||
95 | EVP_add_digest_alias(SN_sha1,"ssl3-sha1"); | ||
96 | EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA); | ||
97 | #endif | ||
98 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_DSA) | ||
99 | EVP_add_digest(EVP_dss1()); /* DSA with sha1 */ | ||
100 | EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); | ||
101 | EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1"); | ||
102 | EVP_add_digest_alias(SN_dsaWithSHA1,"dss1"); | ||
103 | #endif | ||
104 | /* If you want support for phased out ciphers, add the following */ | ||
105 | #if 0 | ||
106 | EVP_add_digest(EVP_sha()); | ||
107 | EVP_add_digest(EVP_dss()); | ||
108 | #endif | ||
109 | return(1); | ||
110 | } | ||
111 | |||
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c deleted file mode 100644 index fc5fcce108..0000000000 --- a/src/lib/libssl/ssl_asn1.c +++ /dev/null | |||
@@ -1,398 +0,0 @@ | |||
1 | /* ssl/ssl_asn1.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include "ssl_locl.h" | ||
62 | #include <openssl/asn1_mac.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | typedef struct ssl_session_asn1_st | ||
67 | { | ||
68 | ASN1_INTEGER version; | ||
69 | ASN1_INTEGER ssl_version; | ||
70 | ASN1_OCTET_STRING cipher; | ||
71 | ASN1_OCTET_STRING master_key; | ||
72 | ASN1_OCTET_STRING session_id; | ||
73 | ASN1_OCTET_STRING session_id_context; | ||
74 | ASN1_OCTET_STRING key_arg; | ||
75 | #ifndef OPENSSL_NO_KRB5 | ||
76 | ASN1_OCTET_STRING krb5_princ; | ||
77 | #endif /* OPENSSL_NO_KRB5 */ | ||
78 | ASN1_INTEGER time; | ||
79 | ASN1_INTEGER timeout; | ||
80 | ASN1_INTEGER verify_result; | ||
81 | } SSL_SESSION_ASN1; | ||
82 | |||
83 | int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | ||
84 | { | ||
85 | #define LSIZE2 (sizeof(long)*2) | ||
86 | int v1=0,v2=0,v3=0,v4=0,v5=0; | ||
87 | unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2]; | ||
88 | unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2]; | ||
89 | long l; | ||
90 | SSL_SESSION_ASN1 a; | ||
91 | M_ASN1_I2D_vars(in); | ||
92 | |||
93 | if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0))) | ||
94 | return(0); | ||
95 | |||
96 | /* Note that I cheat in the following 2 assignments. I know | ||
97 | * that if the ASN1_INTEGER passed to ASN1_INTEGER_set | ||
98 | * is > sizeof(long)+1, the buffer will not be re-OPENSSL_malloc()ed. | ||
99 | * This is a bit evil but makes things simple, no dynamic allocation | ||
100 | * to clean up :-) */ | ||
101 | a.version.length=LSIZE2; | ||
102 | a.version.type=V_ASN1_INTEGER; | ||
103 | a.version.data=ibuf1; | ||
104 | ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION); | ||
105 | |||
106 | a.ssl_version.length=LSIZE2; | ||
107 | a.ssl_version.type=V_ASN1_INTEGER; | ||
108 | a.ssl_version.data=ibuf2; | ||
109 | ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version); | ||
110 | |||
111 | a.cipher.type=V_ASN1_OCTET_STRING; | ||
112 | a.cipher.data=buf; | ||
113 | |||
114 | if (in->cipher == NULL) | ||
115 | l=in->cipher_id; | ||
116 | else | ||
117 | l=in->cipher->id; | ||
118 | if (in->ssl_version == SSL2_VERSION) | ||
119 | { | ||
120 | a.cipher.length=3; | ||
121 | buf[0]=((unsigned char)(l>>16L))&0xff; | ||
122 | buf[1]=((unsigned char)(l>> 8L))&0xff; | ||
123 | buf[2]=((unsigned char)(l ))&0xff; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | a.cipher.length=2; | ||
128 | buf[0]=((unsigned char)(l>>8L))&0xff; | ||
129 | buf[1]=((unsigned char)(l ))&0xff; | ||
130 | } | ||
131 | |||
132 | a.master_key.length=in->master_key_length; | ||
133 | a.master_key.type=V_ASN1_OCTET_STRING; | ||
134 | a.master_key.data=in->master_key; | ||
135 | |||
136 | a.session_id.length=in->session_id_length; | ||
137 | a.session_id.type=V_ASN1_OCTET_STRING; | ||
138 | a.session_id.data=in->session_id; | ||
139 | |||
140 | a.session_id_context.length=in->sid_ctx_length; | ||
141 | a.session_id_context.type=V_ASN1_OCTET_STRING; | ||
142 | a.session_id_context.data=in->sid_ctx; | ||
143 | |||
144 | a.key_arg.length=in->key_arg_length; | ||
145 | a.key_arg.type=V_ASN1_OCTET_STRING; | ||
146 | a.key_arg.data=in->key_arg; | ||
147 | |||
148 | #ifndef OPENSSL_NO_KRB5 | ||
149 | if (in->krb5_client_princ_len) | ||
150 | { | ||
151 | a.krb5_princ.length=in->krb5_client_princ_len; | ||
152 | a.krb5_princ.type=V_ASN1_OCTET_STRING; | ||
153 | a.krb5_princ.data=in->krb5_client_princ; | ||
154 | } | ||
155 | #endif /* OPENSSL_NO_KRB5 */ | ||
156 | |||
157 | if (in->time != 0L) | ||
158 | { | ||
159 | a.time.length=LSIZE2; | ||
160 | a.time.type=V_ASN1_INTEGER; | ||
161 | a.time.data=ibuf3; | ||
162 | ASN1_INTEGER_set(&(a.time),in->time); | ||
163 | } | ||
164 | |||
165 | if (in->timeout != 0L) | ||
166 | { | ||
167 | a.timeout.length=LSIZE2; | ||
168 | a.timeout.type=V_ASN1_INTEGER; | ||
169 | a.timeout.data=ibuf4; | ||
170 | ASN1_INTEGER_set(&(a.timeout),in->timeout); | ||
171 | } | ||
172 | |||
173 | if (in->verify_result != X509_V_OK) | ||
174 | { | ||
175 | a.verify_result.length=LSIZE2; | ||
176 | a.verify_result.type=V_ASN1_INTEGER; | ||
177 | a.verify_result.data=ibuf5; | ||
178 | ASN1_INTEGER_set(&a.verify_result,in->verify_result); | ||
179 | } | ||
180 | |||
181 | |||
182 | M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); | ||
183 | M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
184 | M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
185 | M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
186 | M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
187 | #ifndef OPENSSL_NO_KRB5 | ||
188 | if (in->krb5_client_princ_len) | ||
189 | M_ASN1_I2D_len(&(a.krb5_princ), i2d_ASN1_OCTET_STRING); | ||
190 | #endif /* OPENSSL_NO_KRB5 */ | ||
191 | if (in->key_arg_length > 0) | ||
192 | M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING); | ||
193 | if (in->time != 0L) | ||
194 | M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
195 | if (in->timeout != 0L) | ||
196 | M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
197 | if (in->peer != NULL) | ||
198 | M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3); | ||
199 | M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4); | ||
200 | if (in->verify_result != X509_V_OK) | ||
201 | M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5); | ||
202 | |||
203 | M_ASN1_I2D_seq_total(); | ||
204 | |||
205 | M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER); | ||
206 | M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
207 | M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
208 | M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
209 | M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
210 | #ifndef OPENSSL_NO_KRB5 | ||
211 | if (in->krb5_client_princ_len) | ||
212 | M_ASN1_I2D_put(&(a.krb5_princ), i2d_ASN1_OCTET_STRING); | ||
213 | #endif /* OPENSSL_NO_KRB5 */ | ||
214 | if (in->key_arg_length > 0) | ||
215 | M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0); | ||
216 | if (in->time != 0L) | ||
217 | M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
218 | if (in->timeout != 0L) | ||
219 | M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
220 | if (in->peer != NULL) | ||
221 | M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3); | ||
222 | M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4, | ||
223 | v4); | ||
224 | if (in->verify_result != X509_V_OK) | ||
225 | M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5); | ||
226 | M_ASN1_I2D_finish(); | ||
227 | } | ||
228 | |||
229 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char * const *pp, | ||
230 | long length) | ||
231 | { | ||
232 | int version,ssl_version=0,i; | ||
233 | long id; | ||
234 | ASN1_INTEGER ai,*aip; | ||
235 | ASN1_OCTET_STRING os,*osp; | ||
236 | M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new); | ||
237 | |||
238 | aip= &ai; | ||
239 | osp= &os; | ||
240 | |||
241 | M_ASN1_D2I_Init(); | ||
242 | M_ASN1_D2I_start_sequence(); | ||
243 | |||
244 | ai.data=NULL; ai.length=0; | ||
245 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
246 | version=(int)ASN1_INTEGER_get(aip); | ||
247 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } | ||
248 | |||
249 | /* we don't care about the version right now :-) */ | ||
250 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
251 | ssl_version=(int)ASN1_INTEGER_get(aip); | ||
252 | ret->ssl_version=ssl_version; | ||
253 | if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; } | ||
254 | |||
255 | os.data=NULL; os.length=0; | ||
256 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
257 | if (ssl_version == SSL2_VERSION) | ||
258 | { | ||
259 | if (os.length != 3) | ||
260 | { | ||
261 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
262 | goto err; | ||
263 | } | ||
264 | id=0x02000000L| | ||
265 | ((unsigned long)os.data[0]<<16L)| | ||
266 | ((unsigned long)os.data[1]<< 8L)| | ||
267 | (unsigned long)os.data[2]; | ||
268 | } | ||
269 | else if ((ssl_version>>8) == SSL3_VERSION_MAJOR) | ||
270 | { | ||
271 | if (os.length != 2) | ||
272 | { | ||
273 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
274 | goto err; | ||
275 | } | ||
276 | id=0x03000000L| | ||
277 | ((unsigned long)os.data[0]<<8L)| | ||
278 | (unsigned long)os.data[1]; | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION); | ||
283 | return(NULL); | ||
284 | } | ||
285 | |||
286 | ret->cipher=NULL; | ||
287 | ret->cipher_id=id; | ||
288 | |||
289 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
290 | if ((ssl_version>>8) == SSL3_VERSION_MAJOR) | ||
291 | i=SSL3_MAX_SSL_SESSION_ID_LENGTH; | ||
292 | else /* if (ssl_version == SSL2_VERSION_MAJOR) */ | ||
293 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; | ||
294 | |||
295 | if (os.length > i) | ||
296 | os.length = i; | ||
297 | if (os.length > sizeof ret->session_id) /* can't happen */ | ||
298 | os.length = sizeof ret->session_id; | ||
299 | |||
300 | ret->session_id_length=os.length; | ||
301 | OPENSSL_assert(os.length <= sizeof ret->session_id); | ||
302 | memcpy(ret->session_id,os.data,os.length); | ||
303 | |||
304 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
305 | if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH) | ||
306 | ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | ||
307 | else | ||
308 | ret->master_key_length=os.length; | ||
309 | memcpy(ret->master_key,os.data,ret->master_key_length); | ||
310 | |||
311 | os.length=0; | ||
312 | |||
313 | #ifndef OPENSSL_NO_KRB5 | ||
314 | os.length=0; | ||
315 | M_ASN1_D2I_get_opt(osp,d2i_ASN1_OCTET_STRING,V_ASN1_OCTET_STRING); | ||
316 | if (os.data) | ||
317 | { | ||
318 | if (os.length > SSL_MAX_KRB5_PRINCIPAL_LENGTH) | ||
319 | ret->krb5_client_princ_len=0; | ||
320 | else | ||
321 | ret->krb5_client_princ_len=os.length; | ||
322 | memcpy(ret->krb5_client_princ,os.data,ret->krb5_client_princ_len); | ||
323 | OPENSSL_free(os.data); | ||
324 | os.data = NULL; | ||
325 | os.length = 0; | ||
326 | } | ||
327 | else | ||
328 | ret->krb5_client_princ_len=0; | ||
329 | #endif /* OPENSSL_NO_KRB5 */ | ||
330 | |||
331 | M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING); | ||
332 | if (os.length > SSL_MAX_KEY_ARG_LENGTH) | ||
333 | ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH; | ||
334 | else | ||
335 | ret->key_arg_length=os.length; | ||
336 | memcpy(ret->key_arg,os.data,ret->key_arg_length); | ||
337 | if (os.data != NULL) OPENSSL_free(os.data); | ||
338 | |||
339 | ai.length=0; | ||
340 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1); | ||
341 | if (ai.data != NULL) | ||
342 | { | ||
343 | ret->time=ASN1_INTEGER_get(aip); | ||
344 | OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; | ||
345 | } | ||
346 | else | ||
347 | ret->time=(unsigned long)time(NULL); | ||
348 | |||
349 | ai.length=0; | ||
350 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2); | ||
351 | if (ai.data != NULL) | ||
352 | { | ||
353 | ret->timeout=ASN1_INTEGER_get(aip); | ||
354 | OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; | ||
355 | } | ||
356 | else | ||
357 | ret->timeout=3; | ||
358 | |||
359 | if (ret->peer != NULL) | ||
360 | { | ||
361 | X509_free(ret->peer); | ||
362 | ret->peer=NULL; | ||
363 | } | ||
364 | M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3); | ||
365 | |||
366 | os.length=0; | ||
367 | os.data=NULL; | ||
368 | M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4); | ||
369 | |||
370 | if(os.data != NULL) | ||
371 | { | ||
372 | if (os.length > SSL_MAX_SID_CTX_LENGTH) | ||
373 | { | ||
374 | ret->sid_ctx_length=os.length; | ||
375 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH); | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | ret->sid_ctx_length=os.length; | ||
380 | memcpy(ret->sid_ctx,os.data,os.length); | ||
381 | } | ||
382 | OPENSSL_free(os.data); os.data=NULL; os.length=0; | ||
383 | } | ||
384 | else | ||
385 | ret->sid_ctx_length=0; | ||
386 | |||
387 | ai.length=0; | ||
388 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5); | ||
389 | if (ai.data != NULL) | ||
390 | { | ||
391 | ret->verify_result=ASN1_INTEGER_get(aip); | ||
392 | OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; | ||
393 | } | ||
394 | else | ||
395 | ret->verify_result=X509_V_OK; | ||
396 | |||
397 | M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION); | ||
398 | } | ||
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c deleted file mode 100644 index b779e6bb4d..0000000000 --- a/src/lib/libssl/ssl_cert.c +++ /dev/null | |||
@@ -1,898 +0,0 @@ | |||
1 | /*! \file ssl/ssl_cert.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@OpenSSL.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | */ | ||
106 | |||
107 | #include <stdio.h> | ||
108 | |||
109 | #include "e_os.h" | ||
110 | #ifndef NO_SYS_TYPES_H | ||
111 | # include <sys/types.h> | ||
112 | #endif | ||
113 | |||
114 | #if !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) && !defined(NeXT) && !defined(MAC_OS_pre_X) | ||
115 | #include <dirent.h> | ||
116 | #endif | ||
117 | |||
118 | #if defined(WIN32) | ||
119 | #include <windows.h> | ||
120 | #include <tchar.h> | ||
121 | #endif | ||
122 | |||
123 | #ifdef NeXT | ||
124 | #include <sys/dir.h> | ||
125 | #define dirent direct | ||
126 | #endif | ||
127 | |||
128 | #include <openssl/objects.h> | ||
129 | #include <openssl/bio.h> | ||
130 | #include <openssl/pem.h> | ||
131 | #include <openssl/x509v3.h> | ||
132 | #include "ssl_locl.h" | ||
133 | #include <openssl/fips.h> | ||
134 | |||
135 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) | ||
136 | { | ||
137 | static volatile int ssl_x509_store_ctx_idx= -1; | ||
138 | |||
139 | if (ssl_x509_store_ctx_idx < 0) | ||
140 | { | ||
141 | /* any write lock will do; usually this branch | ||
142 | * will only be taken once anyway */ | ||
143 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
144 | |||
145 | if (ssl_x509_store_ctx_idx < 0) | ||
146 | { | ||
147 | ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index( | ||
148 | 0,"SSL for verify callback",NULL,NULL,NULL); | ||
149 | } | ||
150 | |||
151 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
152 | } | ||
153 | return ssl_x509_store_ctx_idx; | ||
154 | } | ||
155 | |||
156 | CERT *ssl_cert_new(void) | ||
157 | { | ||
158 | CERT *ret; | ||
159 | |||
160 | ret=(CERT *)OPENSSL_malloc(sizeof(CERT)); | ||
161 | if (ret == NULL) | ||
162 | { | ||
163 | SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE); | ||
164 | return(NULL); | ||
165 | } | ||
166 | memset(ret,0,sizeof(CERT)); | ||
167 | |||
168 | ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]); | ||
169 | ret->references=1; | ||
170 | |||
171 | return(ret); | ||
172 | } | ||
173 | |||
174 | CERT *ssl_cert_dup(CERT *cert) | ||
175 | { | ||
176 | CERT *ret; | ||
177 | int i; | ||
178 | |||
179 | ret = (CERT *)OPENSSL_malloc(sizeof(CERT)); | ||
180 | if (ret == NULL) | ||
181 | { | ||
182 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); | ||
183 | return(NULL); | ||
184 | } | ||
185 | |||
186 | memset(ret, 0, sizeof(CERT)); | ||
187 | |||
188 | ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]]; | ||
189 | /* or ret->key = ret->pkeys + (cert->key - cert->pkeys), | ||
190 | * if you find that more readable */ | ||
191 | |||
192 | ret->valid = cert->valid; | ||
193 | ret->mask = cert->mask; | ||
194 | ret->export_mask = cert->export_mask; | ||
195 | |||
196 | #ifndef OPENSSL_NO_RSA | ||
197 | if (cert->rsa_tmp != NULL) | ||
198 | { | ||
199 | RSA_up_ref(cert->rsa_tmp); | ||
200 | ret->rsa_tmp = cert->rsa_tmp; | ||
201 | } | ||
202 | ret->rsa_tmp_cb = cert->rsa_tmp_cb; | ||
203 | #endif | ||
204 | |||
205 | #ifndef OPENSSL_NO_DH | ||
206 | if (cert->dh_tmp != NULL) | ||
207 | { | ||
208 | /* DH parameters don't have a reference count */ | ||
209 | ret->dh_tmp = DHparams_dup(cert->dh_tmp); | ||
210 | if (ret->dh_tmp == NULL) | ||
211 | { | ||
212 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB); | ||
213 | goto err; | ||
214 | } | ||
215 | if (cert->dh_tmp->priv_key) | ||
216 | { | ||
217 | BIGNUM *b = BN_dup(cert->dh_tmp->priv_key); | ||
218 | if (!b) | ||
219 | { | ||
220 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB); | ||
221 | goto err; | ||
222 | } | ||
223 | ret->dh_tmp->priv_key = b; | ||
224 | } | ||
225 | if (cert->dh_tmp->pub_key) | ||
226 | { | ||
227 | BIGNUM *b = BN_dup(cert->dh_tmp->pub_key); | ||
228 | if (!b) | ||
229 | { | ||
230 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB); | ||
231 | goto err; | ||
232 | } | ||
233 | ret->dh_tmp->pub_key = b; | ||
234 | } | ||
235 | } | ||
236 | ret->dh_tmp_cb = cert->dh_tmp_cb; | ||
237 | #endif | ||
238 | |||
239 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
240 | { | ||
241 | if (cert->pkeys[i].x509 != NULL) | ||
242 | { | ||
243 | ret->pkeys[i].x509 = cert->pkeys[i].x509; | ||
244 | CRYPTO_add(&ret->pkeys[i].x509->references, 1, | ||
245 | CRYPTO_LOCK_X509); | ||
246 | } | ||
247 | |||
248 | if (cert->pkeys[i].privatekey != NULL) | ||
249 | { | ||
250 | ret->pkeys[i].privatekey = cert->pkeys[i].privatekey; | ||
251 | CRYPTO_add(&ret->pkeys[i].privatekey->references, 1, | ||
252 | CRYPTO_LOCK_EVP_PKEY); | ||
253 | |||
254 | switch(i) | ||
255 | { | ||
256 | /* If there was anything special to do for | ||
257 | * certain types of keys, we'd do it here. | ||
258 | * (Nothing at the moment, I think.) */ | ||
259 | |||
260 | case SSL_PKEY_RSA_ENC: | ||
261 | case SSL_PKEY_RSA_SIGN: | ||
262 | /* We have an RSA key. */ | ||
263 | break; | ||
264 | |||
265 | case SSL_PKEY_DSA_SIGN: | ||
266 | /* We have a DSA key. */ | ||
267 | break; | ||
268 | |||
269 | case SSL_PKEY_DH_RSA: | ||
270 | case SSL_PKEY_DH_DSA: | ||
271 | /* We have a DH key. */ | ||
272 | break; | ||
273 | |||
274 | default: | ||
275 | /* Can't happen. */ | ||
276 | SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG); | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /* ret->extra_certs *should* exist, but currently the own certificate | ||
282 | * chain is held inside SSL_CTX */ | ||
283 | |||
284 | ret->references=1; | ||
285 | |||
286 | return(ret); | ||
287 | |||
288 | #ifndef OPENSSL_NO_DH /* avoid 'unreferenced label' warning if OPENSSL_NO_DH is defined */ | ||
289 | err: | ||
290 | #endif | ||
291 | #ifndef OPENSSL_NO_RSA | ||
292 | if (ret->rsa_tmp != NULL) | ||
293 | RSA_free(ret->rsa_tmp); | ||
294 | #endif | ||
295 | #ifndef OPENSSL_NO_DH | ||
296 | if (ret->dh_tmp != NULL) | ||
297 | DH_free(ret->dh_tmp); | ||
298 | #endif | ||
299 | |||
300 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
301 | { | ||
302 | if (ret->pkeys[i].x509 != NULL) | ||
303 | X509_free(ret->pkeys[i].x509); | ||
304 | if (ret->pkeys[i].privatekey != NULL) | ||
305 | EVP_PKEY_free(ret->pkeys[i].privatekey); | ||
306 | } | ||
307 | |||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | |||
312 | void ssl_cert_free(CERT *c) | ||
313 | { | ||
314 | int i; | ||
315 | |||
316 | if(c == NULL) | ||
317 | return; | ||
318 | |||
319 | i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT); | ||
320 | #ifdef REF_PRINT | ||
321 | REF_PRINT("CERT",c); | ||
322 | #endif | ||
323 | if (i > 0) return; | ||
324 | #ifdef REF_CHECK | ||
325 | if (i < 0) | ||
326 | { | ||
327 | fprintf(stderr,"ssl_cert_free, bad reference count\n"); | ||
328 | abort(); /* ok */ | ||
329 | } | ||
330 | #endif | ||
331 | |||
332 | #ifndef OPENSSL_NO_RSA | ||
333 | if (c->rsa_tmp) RSA_free(c->rsa_tmp); | ||
334 | #endif | ||
335 | #ifndef OPENSSL_NO_DH | ||
336 | if (c->dh_tmp) DH_free(c->dh_tmp); | ||
337 | #endif | ||
338 | |||
339 | for (i=0; i<SSL_PKEY_NUM; i++) | ||
340 | { | ||
341 | if (c->pkeys[i].x509 != NULL) | ||
342 | X509_free(c->pkeys[i].x509); | ||
343 | if (c->pkeys[i].privatekey != NULL) | ||
344 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
345 | #if 0 | ||
346 | if (c->pkeys[i].publickey != NULL) | ||
347 | EVP_PKEY_free(c->pkeys[i].publickey); | ||
348 | #endif | ||
349 | } | ||
350 | OPENSSL_free(c); | ||
351 | } | ||
352 | |||
353 | int ssl_cert_inst(CERT **o) | ||
354 | { | ||
355 | /* Create a CERT if there isn't already one | ||
356 | * (which cannot really happen, as it is initially created in | ||
357 | * SSL_CTX_new; but the earlier code usually allows for that one | ||
358 | * being non-existant, so we follow that behaviour, as it might | ||
359 | * turn out that there actually is a reason for it -- but I'm | ||
360 | * not sure that *all* of the existing code could cope with | ||
361 | * s->cert being NULL, otherwise we could do without the | ||
362 | * initialization in SSL_CTX_new). | ||
363 | */ | ||
364 | |||
365 | if (o == NULL) | ||
366 | { | ||
367 | SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER); | ||
368 | return(0); | ||
369 | } | ||
370 | if (*o == NULL) | ||
371 | { | ||
372 | if ((*o = ssl_cert_new()) == NULL) | ||
373 | { | ||
374 | SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE); | ||
375 | return(0); | ||
376 | } | ||
377 | } | ||
378 | return(1); | ||
379 | } | ||
380 | |||
381 | |||
382 | SESS_CERT *ssl_sess_cert_new(void) | ||
383 | { | ||
384 | SESS_CERT *ret; | ||
385 | |||
386 | ret = OPENSSL_malloc(sizeof *ret); | ||
387 | if (ret == NULL) | ||
388 | { | ||
389 | SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE); | ||
390 | return NULL; | ||
391 | } | ||
392 | |||
393 | memset(ret, 0 ,sizeof *ret); | ||
394 | ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]); | ||
395 | ret->references = 1; | ||
396 | |||
397 | return ret; | ||
398 | } | ||
399 | |||
400 | void ssl_sess_cert_free(SESS_CERT *sc) | ||
401 | { | ||
402 | int i; | ||
403 | |||
404 | if (sc == NULL) | ||
405 | return; | ||
406 | |||
407 | i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT); | ||
408 | #ifdef REF_PRINT | ||
409 | REF_PRINT("SESS_CERT", sc); | ||
410 | #endif | ||
411 | if (i > 0) | ||
412 | return; | ||
413 | #ifdef REF_CHECK | ||
414 | if (i < 0) | ||
415 | { | ||
416 | fprintf(stderr,"ssl_sess_cert_free, bad reference count\n"); | ||
417 | abort(); /* ok */ | ||
418 | } | ||
419 | #endif | ||
420 | |||
421 | /* i == 0 */ | ||
422 | if (sc->cert_chain != NULL) | ||
423 | sk_X509_pop_free(sc->cert_chain, X509_free); | ||
424 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
425 | { | ||
426 | if (sc->peer_pkeys[i].x509 != NULL) | ||
427 | X509_free(sc->peer_pkeys[i].x509); | ||
428 | #if 0 /* We don't have the peer's private key. These lines are just | ||
429 | * here as a reminder that we're still using a not-quite-appropriate | ||
430 | * data structure. */ | ||
431 | if (sc->peer_pkeys[i].privatekey != NULL) | ||
432 | EVP_PKEY_free(sc->peer_pkeys[i].privatekey); | ||
433 | #endif | ||
434 | } | ||
435 | |||
436 | #ifndef OPENSSL_NO_RSA | ||
437 | if (sc->peer_rsa_tmp != NULL) | ||
438 | RSA_free(sc->peer_rsa_tmp); | ||
439 | #endif | ||
440 | #ifndef OPENSSL_NO_DH | ||
441 | if (sc->peer_dh_tmp != NULL) | ||
442 | DH_free(sc->peer_dh_tmp); | ||
443 | #endif | ||
444 | |||
445 | OPENSSL_free(sc); | ||
446 | } | ||
447 | |||
448 | int ssl_set_peer_cert_type(SESS_CERT *sc,int type) | ||
449 | { | ||
450 | sc->peer_cert_type = type; | ||
451 | return(1); | ||
452 | } | ||
453 | |||
454 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk) | ||
455 | { | ||
456 | X509 *x; | ||
457 | int i; | ||
458 | X509_STORE_CTX ctx; | ||
459 | |||
460 | if ((sk == NULL) || (sk_X509_num(sk) == 0)) | ||
461 | return(0); | ||
462 | |||
463 | x=sk_X509_value(sk,0); | ||
464 | if(!X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk)) | ||
465 | { | ||
466 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB); | ||
467 | return(0); | ||
468 | } | ||
469 | if (SSL_get_verify_depth(s) >= 0) | ||
470 | X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s)); | ||
471 | X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s); | ||
472 | |||
473 | /* We need to set the verify purpose. The purpose can be determined by | ||
474 | * the context: if its a server it will verify SSL client certificates | ||
475 | * or vice versa. | ||
476 | */ | ||
477 | if (s->server) | ||
478 | i = X509_PURPOSE_SSL_CLIENT; | ||
479 | else | ||
480 | i = X509_PURPOSE_SSL_SERVER; | ||
481 | |||
482 | X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust); | ||
483 | |||
484 | if (s->verify_callback) | ||
485 | X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback); | ||
486 | |||
487 | if (s->ctx->app_verify_callback != NULL) | ||
488 | #if 1 /* new with OpenSSL 0.9.7 */ | ||
489 | i=s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg); | ||
490 | #else | ||
491 | i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */ | ||
492 | #endif | ||
493 | else | ||
494 | { | ||
495 | #ifndef OPENSSL_NO_X509_VERIFY | ||
496 | i=X509_verify_cert(&ctx); | ||
497 | #else | ||
498 | i=0; | ||
499 | ctx.error=X509_V_ERR_APPLICATION_VERIFICATION; | ||
500 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK); | ||
501 | #endif | ||
502 | } | ||
503 | |||
504 | s->verify_result=ctx.error; | ||
505 | X509_STORE_CTX_cleanup(&ctx); | ||
506 | |||
507 | return(i); | ||
508 | } | ||
509 | |||
510 | static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *name_list) | ||
511 | { | ||
512 | if (*ca_list != NULL) | ||
513 | sk_X509_NAME_pop_free(*ca_list,X509_NAME_free); | ||
514 | |||
515 | *ca_list=name_list; | ||
516 | } | ||
517 | |||
518 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk) | ||
519 | { | ||
520 | int i; | ||
521 | STACK_OF(X509_NAME) *ret; | ||
522 | X509_NAME *name; | ||
523 | |||
524 | ret=sk_X509_NAME_new_null(); | ||
525 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
526 | { | ||
527 | name=X509_NAME_dup(sk_X509_NAME_value(sk,i)); | ||
528 | if ((name == NULL) || !sk_X509_NAME_push(ret,name)) | ||
529 | { | ||
530 | sk_X509_NAME_pop_free(ret,X509_NAME_free); | ||
531 | return(NULL); | ||
532 | } | ||
533 | } | ||
534 | return(ret); | ||
535 | } | ||
536 | |||
537 | void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *name_list) | ||
538 | { | ||
539 | set_client_CA_list(&(s->client_CA),name_list); | ||
540 | } | ||
541 | |||
542 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *name_list) | ||
543 | { | ||
544 | set_client_CA_list(&(ctx->client_CA),name_list); | ||
545 | } | ||
546 | |||
547 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *ctx) | ||
548 | { | ||
549 | return(ctx->client_CA); | ||
550 | } | ||
551 | |||
552 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s) | ||
553 | { | ||
554 | if (s->type == SSL_ST_CONNECT) | ||
555 | { /* we are in the client */ | ||
556 | if (((s->version>>8) == SSL3_VERSION_MAJOR) && | ||
557 | (s->s3 != NULL)) | ||
558 | return(s->s3->tmp.ca_names); | ||
559 | else | ||
560 | return(NULL); | ||
561 | } | ||
562 | else | ||
563 | { | ||
564 | if (s->client_CA != NULL) | ||
565 | return(s->client_CA); | ||
566 | else | ||
567 | return(s->ctx->client_CA); | ||
568 | } | ||
569 | } | ||
570 | |||
571 | static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x) | ||
572 | { | ||
573 | X509_NAME *name; | ||
574 | |||
575 | if (x == NULL) return(0); | ||
576 | if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL)) | ||
577 | return(0); | ||
578 | |||
579 | if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL) | ||
580 | return(0); | ||
581 | |||
582 | if (!sk_X509_NAME_push(*sk,name)) | ||
583 | { | ||
584 | X509_NAME_free(name); | ||
585 | return(0); | ||
586 | } | ||
587 | return(1); | ||
588 | } | ||
589 | |||
590 | int SSL_add_client_CA(SSL *ssl,X509 *x) | ||
591 | { | ||
592 | return(add_client_CA(&(ssl->client_CA),x)); | ||
593 | } | ||
594 | |||
595 | int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x) | ||
596 | { | ||
597 | return(add_client_CA(&(ctx->client_CA),x)); | ||
598 | } | ||
599 | |||
600 | static int xname_cmp(const X509_NAME * const *a, const X509_NAME * const *b) | ||
601 | { | ||
602 | return(X509_NAME_cmp(*a,*b)); | ||
603 | } | ||
604 | |||
605 | #ifndef OPENSSL_NO_STDIO | ||
606 | /*! | ||
607 | * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed; | ||
608 | * it doesn't really have anything to do with clients (except that a common use | ||
609 | * for a stack of CAs is to send it to the client). Actually, it doesn't have | ||
610 | * much to do with CAs, either, since it will load any old cert. | ||
611 | * \param file the file containing one or more certs. | ||
612 | * \return a ::STACK containing the certs. | ||
613 | */ | ||
614 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) | ||
615 | { | ||
616 | BIO *in; | ||
617 | X509 *x=NULL; | ||
618 | X509_NAME *xn=NULL; | ||
619 | STACK_OF(X509_NAME) *ret = NULL,*sk; | ||
620 | |||
621 | sk=sk_X509_NAME_new(xname_cmp); | ||
622 | |||
623 | in=BIO_new(BIO_s_file_internal()); | ||
624 | |||
625 | if ((sk == NULL) || (in == NULL)) | ||
626 | { | ||
627 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE); | ||
628 | goto err; | ||
629 | } | ||
630 | |||
631 | if (!BIO_read_filename(in,file)) | ||
632 | goto err; | ||
633 | |||
634 | for (;;) | ||
635 | { | ||
636 | if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL) | ||
637 | break; | ||
638 | if (ret == NULL) | ||
639 | { | ||
640 | ret = sk_X509_NAME_new_null(); | ||
641 | if (ret == NULL) | ||
642 | { | ||
643 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE); | ||
644 | goto err; | ||
645 | } | ||
646 | } | ||
647 | if ((xn=X509_get_subject_name(x)) == NULL) goto err; | ||
648 | /* check for duplicates */ | ||
649 | xn=X509_NAME_dup(xn); | ||
650 | if (xn == NULL) goto err; | ||
651 | if (sk_X509_NAME_find(sk,xn) >= 0) | ||
652 | X509_NAME_free(xn); | ||
653 | else | ||
654 | { | ||
655 | sk_X509_NAME_push(sk,xn); | ||
656 | sk_X509_NAME_push(ret,xn); | ||
657 | } | ||
658 | } | ||
659 | |||
660 | if (0) | ||
661 | { | ||
662 | err: | ||
663 | if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free); | ||
664 | ret=NULL; | ||
665 | } | ||
666 | if (sk != NULL) sk_X509_NAME_free(sk); | ||
667 | if (in != NULL) BIO_free(in); | ||
668 | if (x != NULL) X509_free(x); | ||
669 | if (ret != NULL) | ||
670 | ERR_clear_error(); | ||
671 | return(ret); | ||
672 | } | ||
673 | #endif | ||
674 | |||
675 | /*! | ||
676 | * Add a file of certs to a stack. | ||
677 | * \param stack the stack to add to. | ||
678 | * \param file the file to add from. All certs in this file that are not | ||
679 | * already in the stack will be added. | ||
680 | * \return 1 for success, 0 for failure. Note that in the case of failure some | ||
681 | * certs may have been added to \c stack. | ||
682 | */ | ||
683 | |||
684 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
685 | const char *file) | ||
686 | { | ||
687 | BIO *in; | ||
688 | X509 *x=NULL; | ||
689 | X509_NAME *xn=NULL; | ||
690 | int ret=1; | ||
691 | int (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b); | ||
692 | |||
693 | oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp); | ||
694 | |||
695 | in=BIO_new(BIO_s_file_internal()); | ||
696 | |||
697 | if (in == NULL) | ||
698 | { | ||
699 | SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE); | ||
700 | goto err; | ||
701 | } | ||
702 | |||
703 | if (!BIO_read_filename(in,file)) | ||
704 | goto err; | ||
705 | |||
706 | for (;;) | ||
707 | { | ||
708 | if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL) | ||
709 | break; | ||
710 | if ((xn=X509_get_subject_name(x)) == NULL) goto err; | ||
711 | xn=X509_NAME_dup(xn); | ||
712 | if (xn == NULL) goto err; | ||
713 | if (sk_X509_NAME_find(stack,xn) >= 0) | ||
714 | X509_NAME_free(xn); | ||
715 | else | ||
716 | sk_X509_NAME_push(stack,xn); | ||
717 | } | ||
718 | |||
719 | if (0) | ||
720 | { | ||
721 | err: | ||
722 | ret=0; | ||
723 | } | ||
724 | if(in != NULL) | ||
725 | BIO_free(in); | ||
726 | if(x != NULL) | ||
727 | X509_free(x); | ||
728 | |||
729 | sk_X509_NAME_set_cmp_func(stack,oldcmp); | ||
730 | |||
731 | return ret; | ||
732 | } | ||
733 | |||
734 | /*! | ||
735 | * Add a directory of certs to a stack. | ||
736 | * \param stack the stack to append to. | ||
737 | * \param dir the directory to append from. All files in this directory will be | ||
738 | * examined as potential certs. Any that are acceptable to | ||
739 | * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be | ||
740 | * included. | ||
741 | * \return 1 for success, 0 for failure. Note that in the case of failure some | ||
742 | * certs may have been added to \c stack. | ||
743 | */ | ||
744 | |||
745 | #ifndef OPENSSL_SYS_WIN32 | ||
746 | #ifndef OPENSSL_SYS_VMS /* XXXX This may be fixed in the future */ | ||
747 | #ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! */ | ||
748 | |||
749 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
750 | const char *dir) | ||
751 | { | ||
752 | DIR *d; | ||
753 | struct dirent *dstruct; | ||
754 | int ret = 0; | ||
755 | |||
756 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | ||
757 | d = opendir(dir); | ||
758 | |||
759 | /* Note that a side effect is that the CAs will be sorted by name */ | ||
760 | if(!d) | ||
761 | { | ||
762 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); | ||
763 | ERR_add_error_data(3, "opendir('", dir, "')"); | ||
764 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); | ||
765 | goto err; | ||
766 | } | ||
767 | |||
768 | while((dstruct=readdir(d))) | ||
769 | { | ||
770 | char buf[1024]; | ||
771 | int r; | ||
772 | |||
773 | if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf) | ||
774 | { | ||
775 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
776 | goto err; | ||
777 | } | ||
778 | |||
779 | r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name); | ||
780 | if (r <= 0 || r >= sizeof buf) | ||
781 | goto err; | ||
782 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) | ||
783 | goto err; | ||
784 | } | ||
785 | ret = 1; | ||
786 | |||
787 | err: | ||
788 | if (d) closedir(d); | ||
789 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | ||
790 | return ret; | ||
791 | } | ||
792 | |||
793 | #endif | ||
794 | #endif | ||
795 | |||
796 | #else /* OPENSSL_SYS_WIN32 */ | ||
797 | |||
798 | #if defined(_WIN32_WCE) | ||
799 | # ifndef UNICODE | ||
800 | # error "WinCE comes in UNICODE flavor only..." | ||
801 | # endif | ||
802 | # if _WIN32_WCE<101 && !defined(OPENSSL_NO_MULTIBYTE) | ||
803 | # define OPENSSL_NO_MULTIBYTE | ||
804 | # endif | ||
805 | # ifndef FindFirstFile | ||
806 | # define FindFirstFile FindFirstFileW | ||
807 | # endif | ||
808 | # ifndef FindNextFile | ||
809 | # define FindNextFile FindNextFileW | ||
810 | # endif | ||
811 | #endif | ||
812 | |||
813 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
814 | const char *dir) | ||
815 | { | ||
816 | WIN32_FIND_DATA FindFileData; | ||
817 | HANDLE hFind; | ||
818 | int ret = 0; | ||
819 | TCHAR *wdir = NULL; | ||
820 | size_t i,len_0 = strlen(dir)+1; /* len_0 accounts for trailing 0 */ | ||
821 | char buf[1024],*slash; | ||
822 | |||
823 | if (len_0 > (sizeof(buf)-14)) /* 14 is just some value... */ | ||
824 | { | ||
825 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
826 | return ret; | ||
827 | } | ||
828 | |||
829 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | ||
830 | |||
831 | if (sizeof(TCHAR) != sizeof(char)) | ||
832 | { | ||
833 | wdir = (TCHAR *)malloc(len_0*sizeof(TCHAR)); | ||
834 | if (wdir == NULL) | ||
835 | goto err_noclose; | ||
836 | #ifndef OPENSSL_NO_MULTIBYTE | ||
837 | if (!MultiByteToWideChar(CP_ACP,0,dir,len_0, | ||
838 | (WCHAR *)wdir,len_0)) | ||
839 | #endif | ||
840 | for (i=0;i<len_0;i++) wdir[i]=(TCHAR)dir[i]; | ||
841 | |||
842 | hFind = FindFirstFile(wdir, &FindFileData); | ||
843 | } | ||
844 | else hFind = FindFirstFile((const TCHAR *)dir, &FindFileData); | ||
845 | |||
846 | /* Note that a side effect is that the CAs will be sorted by name */ | ||
847 | if(hFind == INVALID_HANDLE_VALUE) | ||
848 | { | ||
849 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); | ||
850 | ERR_add_error_data(3, "opendir('", dir, "')"); | ||
851 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); | ||
852 | goto err_noclose; | ||
853 | } | ||
854 | |||
855 | strncpy(buf,dir,sizeof(buf)); /* strcpy is safe too... */ | ||
856 | buf[len_0-1]='/'; /* no trailing zero! */ | ||
857 | slash=buf+len_0; | ||
858 | |||
859 | do { | ||
860 | const TCHAR *fnam=FindFileData.cFileName; | ||
861 | size_t flen_0=_tcslen(fnam)+1; | ||
862 | |||
863 | if (flen_0 > (sizeof(buf)-len_0)) | ||
864 | { | ||
865 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
866 | goto err; | ||
867 | } | ||
868 | /* else strcpy would be safe too... */ | ||
869 | |||
870 | if (sizeof(TCHAR) != sizeof(char)) | ||
871 | { | ||
872 | #ifndef OPENSSL_NO_MULTIBYTE | ||
873 | if (!WideCharToMultiByte(CP_ACP,0, | ||
874 | (WCHAR *)fnam,flen_0, | ||
875 | slash,sizeof(buf)-len_0, | ||
876 | NULL,0)) | ||
877 | #endif | ||
878 | for (i=0;i<flen_0;i++) slash[i]=(char)fnam[i]; | ||
879 | } | ||
880 | else strncpy(slash,(const char *)fnam,sizeof(buf)-len_0); | ||
881 | |||
882 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) | ||
883 | goto err; | ||
884 | } | ||
885 | while (FindNextFile(hFind, &FindFileData) != FALSE); | ||
886 | ret = 1; | ||
887 | |||
888 | err: | ||
889 | FindClose(hFind); | ||
890 | err_noclose: | ||
891 | if (wdir != NULL) | ||
892 | free(wdir); | ||
893 | |||
894 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | ||
895 | return ret; | ||
896 | } | ||
897 | |||
898 | #endif | ||
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c deleted file mode 100644 index f622180c69..0000000000 --- a/src/lib/libssl/ssl_ciph.c +++ /dev/null | |||
@@ -1,1139 +0,0 @@ | |||
1 | /* ssl/ssl_ciph.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/objects.h> | ||
61 | #include <openssl/comp.h> | ||
62 | #include <openssl/fips.h> | ||
63 | #include "ssl_locl.h" | ||
64 | |||
65 | #define SSL_ENC_DES_IDX 0 | ||
66 | #define SSL_ENC_3DES_IDX 1 | ||
67 | #define SSL_ENC_RC4_IDX 2 | ||
68 | #define SSL_ENC_RC2_IDX 3 | ||
69 | #define SSL_ENC_IDEA_IDX 4 | ||
70 | #define SSL_ENC_eFZA_IDX 5 | ||
71 | #define SSL_ENC_NULL_IDX 6 | ||
72 | #define SSL_ENC_AES128_IDX 7 | ||
73 | #define SSL_ENC_AES256_IDX 8 | ||
74 | #define SSL_ENC_NUM_IDX 9 | ||
75 | |||
76 | static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={ | ||
77 | NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL | ||
78 | }; | ||
79 | |||
80 | static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL; | ||
81 | |||
82 | #define SSL_MD_MD5_IDX 0 | ||
83 | #define SSL_MD_SHA1_IDX 1 | ||
84 | #define SSL_MD_NUM_IDX 2 | ||
85 | static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={ | ||
86 | NULL,NULL, | ||
87 | }; | ||
88 | |||
89 | #define CIPHER_ADD 1 | ||
90 | #define CIPHER_KILL 2 | ||
91 | #define CIPHER_DEL 3 | ||
92 | #define CIPHER_ORD 4 | ||
93 | #define CIPHER_SPECIAL 5 | ||
94 | |||
95 | typedef struct cipher_order_st | ||
96 | { | ||
97 | SSL_CIPHER *cipher; | ||
98 | int active; | ||
99 | int dead; | ||
100 | struct cipher_order_st *next,*prev; | ||
101 | } CIPHER_ORDER; | ||
102 | |||
103 | static const SSL_CIPHER cipher_aliases[]={ | ||
104 | /* Don't include eNULL unless specifically enabled. */ | ||
105 | {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */ | ||
106 | {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */ | ||
107 | {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
108 | {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */ | ||
109 | {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
110 | {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
111 | {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
112 | {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
113 | {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
114 | {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
115 | {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0}, | ||
116 | |||
117 | {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */ | ||
118 | {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
119 | {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
120 | {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
121 | {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0}, | ||
122 | {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
123 | {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
124 | |||
125 | {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0}, | ||
126 | {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0}, | ||
127 | {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0}, | ||
128 | {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0}, | ||
129 | #ifndef OPENSSL_NO_IDEA | ||
130 | {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0}, | ||
131 | #endif | ||
132 | {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, | ||
133 | {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0}, | ||
134 | {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0}, | ||
135 | |||
136 | {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0}, | ||
137 | {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0}, | ||
138 | {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0}, | ||
139 | |||
140 | {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0}, | ||
141 | {0,SSL_TXT_KRB5,0,SSL_KRB5, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0}, | ||
142 | {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0}, | ||
143 | {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0}, | ||
144 | {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0}, | ||
145 | |||
146 | {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0}, | ||
147 | {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0}, | ||
148 | {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0}, | ||
149 | |||
150 | {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK}, | ||
151 | {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK}, | ||
152 | {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK}, | ||
153 | {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK}, | ||
154 | {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK}, | ||
155 | {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK}, | ||
156 | {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK}, | ||
157 | {0,SSL_TXT_FIPS, 0, 0, SSL_FIPS, 0,0,0,0,SSL_FIPS|SSL_STRONG_NONE}, | ||
158 | }; | ||
159 | |||
160 | static int init_ciphers=1; | ||
161 | |||
162 | static void load_ciphers(void) | ||
163 | { | ||
164 | ssl_cipher_methods[SSL_ENC_DES_IDX]= | ||
165 | EVP_get_cipherbyname(SN_des_cbc); | ||
166 | ssl_cipher_methods[SSL_ENC_3DES_IDX]= | ||
167 | EVP_get_cipherbyname(SN_des_ede3_cbc); | ||
168 | ssl_cipher_methods[SSL_ENC_RC4_IDX]= | ||
169 | EVP_get_cipherbyname(SN_rc4); | ||
170 | ssl_cipher_methods[SSL_ENC_RC2_IDX]= | ||
171 | EVP_get_cipherbyname(SN_rc2_cbc); | ||
172 | #ifndef OPENSSL_NO_IDEA | ||
173 | ssl_cipher_methods[SSL_ENC_IDEA_IDX]= | ||
174 | EVP_get_cipherbyname(SN_idea_cbc); | ||
175 | #else | ||
176 | ssl_cipher_methods[SSL_ENC_IDEA_IDX]= NULL; | ||
177 | #endif | ||
178 | ssl_cipher_methods[SSL_ENC_AES128_IDX]= | ||
179 | EVP_get_cipherbyname(SN_aes_128_cbc); | ||
180 | ssl_cipher_methods[SSL_ENC_AES256_IDX]= | ||
181 | EVP_get_cipherbyname(SN_aes_256_cbc); | ||
182 | |||
183 | ssl_digest_methods[SSL_MD_MD5_IDX]= | ||
184 | EVP_get_digestbyname(SN_md5); | ||
185 | ssl_digest_methods[SSL_MD_SHA1_IDX]= | ||
186 | EVP_get_digestbyname(SN_sha1); | ||
187 | init_ciphers=0; | ||
188 | } | ||
189 | |||
190 | int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | ||
191 | const EVP_MD **md, SSL_COMP **comp) | ||
192 | { | ||
193 | int i; | ||
194 | SSL_CIPHER *c; | ||
195 | |||
196 | c=s->cipher; | ||
197 | if (c == NULL) return(0); | ||
198 | if (comp != NULL) | ||
199 | { | ||
200 | SSL_COMP ctmp; | ||
201 | |||
202 | if (s->compress_meth == 0) | ||
203 | *comp=NULL; | ||
204 | else if (ssl_comp_methods == NULL) | ||
205 | { | ||
206 | /* bad */ | ||
207 | *comp=NULL; | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | |||
212 | ctmp.id=s->compress_meth; | ||
213 | i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp); | ||
214 | if (i >= 0) | ||
215 | *comp=sk_SSL_COMP_value(ssl_comp_methods,i); | ||
216 | else | ||
217 | *comp=NULL; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | if ((enc == NULL) || (md == NULL)) return(0); | ||
222 | |||
223 | switch (c->algorithms & SSL_ENC_MASK) | ||
224 | { | ||
225 | case SSL_DES: | ||
226 | i=SSL_ENC_DES_IDX; | ||
227 | break; | ||
228 | case SSL_3DES: | ||
229 | i=SSL_ENC_3DES_IDX; | ||
230 | break; | ||
231 | case SSL_RC4: | ||
232 | i=SSL_ENC_RC4_IDX; | ||
233 | break; | ||
234 | case SSL_RC2: | ||
235 | i=SSL_ENC_RC2_IDX; | ||
236 | break; | ||
237 | case SSL_IDEA: | ||
238 | i=SSL_ENC_IDEA_IDX; | ||
239 | break; | ||
240 | case SSL_eNULL: | ||
241 | i=SSL_ENC_NULL_IDX; | ||
242 | break; | ||
243 | case SSL_AES: | ||
244 | switch(c->alg_bits) | ||
245 | { | ||
246 | case 128: i=SSL_ENC_AES128_IDX; break; | ||
247 | case 256: i=SSL_ENC_AES256_IDX; break; | ||
248 | default: i=-1; break; | ||
249 | } | ||
250 | break; | ||
251 | default: | ||
252 | i= -1; | ||
253 | break; | ||
254 | } | ||
255 | |||
256 | if ((i < 0) || (i >= SSL_ENC_NUM_IDX)) | ||
257 | *enc=NULL; | ||
258 | else | ||
259 | { | ||
260 | if (i == SSL_ENC_NULL_IDX) | ||
261 | *enc=EVP_enc_null(); | ||
262 | else | ||
263 | *enc=ssl_cipher_methods[i]; | ||
264 | } | ||
265 | |||
266 | switch (c->algorithms & SSL_MAC_MASK) | ||
267 | { | ||
268 | case SSL_MD5: | ||
269 | i=SSL_MD_MD5_IDX; | ||
270 | break; | ||
271 | case SSL_SHA1: | ||
272 | i=SSL_MD_SHA1_IDX; | ||
273 | break; | ||
274 | default: | ||
275 | i= -1; | ||
276 | break; | ||
277 | } | ||
278 | if ((i < 0) || (i >= SSL_MD_NUM_IDX)) | ||
279 | *md=NULL; | ||
280 | else | ||
281 | *md=ssl_digest_methods[i]; | ||
282 | |||
283 | if ((*enc != NULL) && (*md != NULL)) | ||
284 | return(1); | ||
285 | else | ||
286 | return(0); | ||
287 | } | ||
288 | |||
289 | #define ITEM_SEP(a) \ | ||
290 | (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ',')) | ||
291 | |||
292 | static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr, | ||
293 | CIPHER_ORDER **tail) | ||
294 | { | ||
295 | if (curr == *tail) return; | ||
296 | if (curr == *head) | ||
297 | *head=curr->next; | ||
298 | if (curr->prev != NULL) | ||
299 | curr->prev->next=curr->next; | ||
300 | if (curr->next != NULL) /* should always be true */ | ||
301 | curr->next->prev=curr->prev; | ||
302 | (*tail)->next=curr; | ||
303 | curr->prev= *tail; | ||
304 | curr->next=NULL; | ||
305 | *tail=curr; | ||
306 | } | ||
307 | |||
308 | static unsigned long ssl_cipher_get_disabled(void) | ||
309 | { | ||
310 | unsigned long mask; | ||
311 | |||
312 | mask = SSL_kFZA; | ||
313 | #ifdef OPENSSL_NO_RSA | ||
314 | mask |= SSL_aRSA|SSL_kRSA; | ||
315 | #endif | ||
316 | #ifdef OPENSSL_NO_DSA | ||
317 | mask |= SSL_aDSS; | ||
318 | #endif | ||
319 | #ifdef OPENSSL_NO_DH | ||
320 | mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH; | ||
321 | #endif | ||
322 | #ifdef OPENSSL_NO_KRB5 | ||
323 | mask |= SSL_kKRB5|SSL_aKRB5; | ||
324 | #endif | ||
325 | |||
326 | #ifdef SSL_FORBID_ENULL | ||
327 | mask |= SSL_eNULL; | ||
328 | #endif | ||
329 | |||
330 | mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0; | ||
331 | mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0; | ||
332 | mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0; | ||
333 | mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0; | ||
334 | mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0; | ||
335 | mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0; | ||
336 | mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0; | ||
337 | |||
338 | mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0; | ||
339 | mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0; | ||
340 | |||
341 | return(mask); | ||
342 | } | ||
343 | |||
344 | static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, | ||
345 | int num_of_ciphers, unsigned long mask, CIPHER_ORDER *co_list, | ||
346 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | ||
347 | { | ||
348 | int i, co_list_num; | ||
349 | SSL_CIPHER *c; | ||
350 | |||
351 | /* | ||
352 | * We have num_of_ciphers descriptions compiled in, depending on the | ||
353 | * method selected (SSLv2 and/or SSLv3, TLSv1 etc). | ||
354 | * These will later be sorted in a linked list with at most num | ||
355 | * entries. | ||
356 | */ | ||
357 | |||
358 | /* Get the initial list of ciphers */ | ||
359 | co_list_num = 0; /* actual count of ciphers */ | ||
360 | for (i = 0; i < num_of_ciphers; i++) | ||
361 | { | ||
362 | c = ssl_method->get_cipher(i); | ||
363 | /* drop those that use any of that is not available */ | ||
364 | #ifdef OPENSSL_FIPS | ||
365 | if ((c != NULL) && c->valid && !(c->algorithms & mask) | ||
366 | && (!FIPS_mode() || (c->algo_strength & SSL_FIPS))) | ||
367 | #else | ||
368 | if ((c != NULL) && c->valid && !(c->algorithms & mask)) | ||
369 | #endif | ||
370 | { | ||
371 | co_list[co_list_num].cipher = c; | ||
372 | co_list[co_list_num].next = NULL; | ||
373 | co_list[co_list_num].prev = NULL; | ||
374 | co_list[co_list_num].active = 0; | ||
375 | co_list_num++; | ||
376 | #ifdef KSSL_DEBUG | ||
377 | printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms); | ||
378 | #endif /* KSSL_DEBUG */ | ||
379 | /* | ||
380 | if (!sk_push(ca_list,(char *)c)) goto err; | ||
381 | */ | ||
382 | } | ||
383 | } | ||
384 | |||
385 | /* | ||
386 | * Prepare linked list from list entries | ||
387 | */ | ||
388 | for (i = 1; i < co_list_num - 1; i++) | ||
389 | { | ||
390 | co_list[i].prev = &(co_list[i-1]); | ||
391 | co_list[i].next = &(co_list[i+1]); | ||
392 | } | ||
393 | if (co_list_num > 0) | ||
394 | { | ||
395 | (*head_p) = &(co_list[0]); | ||
396 | (*head_p)->prev = NULL; | ||
397 | (*head_p)->next = &(co_list[1]); | ||
398 | (*tail_p) = &(co_list[co_list_num - 1]); | ||
399 | (*tail_p)->prev = &(co_list[co_list_num - 2]); | ||
400 | (*tail_p)->next = NULL; | ||
401 | } | ||
402 | } | ||
403 | |||
404 | static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list, | ||
405 | int num_of_group_aliases, unsigned long mask, | ||
406 | CIPHER_ORDER *head) | ||
407 | { | ||
408 | CIPHER_ORDER *ciph_curr; | ||
409 | SSL_CIPHER **ca_curr; | ||
410 | int i; | ||
411 | |||
412 | /* | ||
413 | * First, add the real ciphers as already collected | ||
414 | */ | ||
415 | ciph_curr = head; | ||
416 | ca_curr = ca_list; | ||
417 | while (ciph_curr != NULL) | ||
418 | { | ||
419 | *ca_curr = ciph_curr->cipher; | ||
420 | ca_curr++; | ||
421 | ciph_curr = ciph_curr->next; | ||
422 | } | ||
423 | |||
424 | /* | ||
425 | * Now we add the available ones from the cipher_aliases[] table. | ||
426 | * They represent either an algorithm, that must be fully | ||
427 | * supported (not match any bit in mask) or represent a cipher | ||
428 | * strength value (will be added in any case because algorithms=0). | ||
429 | */ | ||
430 | for (i = 0; i < num_of_group_aliases; i++) | ||
431 | { | ||
432 | if ((i == 0) || /* always fetch "ALL" */ | ||
433 | !(cipher_aliases[i].algorithms & mask)) | ||
434 | { | ||
435 | *ca_curr = (SSL_CIPHER *)(cipher_aliases + i); | ||
436 | ca_curr++; | ||
437 | } | ||
438 | } | ||
439 | |||
440 | *ca_curr = NULL; /* end of list */ | ||
441 | } | ||
442 | |||
443 | static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask, | ||
444 | unsigned long algo_strength, unsigned long mask_strength, | ||
445 | int rule, int strength_bits, CIPHER_ORDER *co_list, | ||
446 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | ||
447 | { | ||
448 | CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2; | ||
449 | SSL_CIPHER *cp; | ||
450 | unsigned long ma, ma_s; | ||
451 | |||
452 | #ifdef CIPHER_DEBUG | ||
453 | printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n", | ||
454 | rule, algorithms, mask, algo_strength, mask_strength, | ||
455 | strength_bits); | ||
456 | #endif | ||
457 | |||
458 | curr = head = *head_p; | ||
459 | curr2 = head; | ||
460 | tail2 = tail = *tail_p; | ||
461 | for (;;) | ||
462 | { | ||
463 | if ((curr == NULL) || (curr == tail2)) break; | ||
464 | curr = curr2; | ||
465 | curr2 = curr->next; | ||
466 | |||
467 | cp = curr->cipher; | ||
468 | |||
469 | /* | ||
470 | * Selection criteria is either the number of strength_bits | ||
471 | * or the algorithm used. | ||
472 | */ | ||
473 | if (strength_bits == -1) | ||
474 | { | ||
475 | ma = mask & cp->algorithms; | ||
476 | ma_s = mask_strength & cp->algo_strength; | ||
477 | |||
478 | #ifdef CIPHER_DEBUG | ||
479 | printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength); | ||
480 | printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength); | ||
481 | #endif | ||
482 | /* | ||
483 | * Select: if none of the mask bit was met from the | ||
484 | * cipher or not all of the bits were met, the | ||
485 | * selection does not apply. | ||
486 | */ | ||
487 | if (((ma == 0) && (ma_s == 0)) || | ||
488 | ((ma & algorithms) != ma) || | ||
489 | ((ma_s & algo_strength) != ma_s)) | ||
490 | continue; /* does not apply */ | ||
491 | } | ||
492 | else if (strength_bits != cp->strength_bits) | ||
493 | continue; /* does not apply */ | ||
494 | |||
495 | #ifdef CIPHER_DEBUG | ||
496 | printf("Action = %d\n", rule); | ||
497 | #endif | ||
498 | |||
499 | /* add the cipher if it has not been added yet. */ | ||
500 | if (rule == CIPHER_ADD) | ||
501 | { | ||
502 | if (!curr->active) | ||
503 | { | ||
504 | ll_append_tail(&head, curr, &tail); | ||
505 | curr->active = 1; | ||
506 | } | ||
507 | } | ||
508 | /* Move the added cipher to this location */ | ||
509 | else if (rule == CIPHER_ORD) | ||
510 | { | ||
511 | if (curr->active) | ||
512 | { | ||
513 | ll_append_tail(&head, curr, &tail); | ||
514 | } | ||
515 | } | ||
516 | else if (rule == CIPHER_DEL) | ||
517 | curr->active = 0; | ||
518 | else if (rule == CIPHER_KILL) | ||
519 | { | ||
520 | if (head == curr) | ||
521 | head = curr->next; | ||
522 | else | ||
523 | curr->prev->next = curr->next; | ||
524 | if (tail == curr) | ||
525 | tail = curr->prev; | ||
526 | curr->active = 0; | ||
527 | if (curr->next != NULL) | ||
528 | curr->next->prev = curr->prev; | ||
529 | if (curr->prev != NULL) | ||
530 | curr->prev->next = curr->next; | ||
531 | curr->next = NULL; | ||
532 | curr->prev = NULL; | ||
533 | } | ||
534 | } | ||
535 | |||
536 | *head_p = head; | ||
537 | *tail_p = tail; | ||
538 | } | ||
539 | |||
540 | static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list, | ||
541 | CIPHER_ORDER **head_p, | ||
542 | CIPHER_ORDER **tail_p) | ||
543 | { | ||
544 | int max_strength_bits, i, *number_uses; | ||
545 | CIPHER_ORDER *curr; | ||
546 | |||
547 | /* | ||
548 | * This routine sorts the ciphers with descending strength. The sorting | ||
549 | * must keep the pre-sorted sequence, so we apply the normal sorting | ||
550 | * routine as '+' movement to the end of the list. | ||
551 | */ | ||
552 | max_strength_bits = 0; | ||
553 | curr = *head_p; | ||
554 | while (curr != NULL) | ||
555 | { | ||
556 | if (curr->active && | ||
557 | (curr->cipher->strength_bits > max_strength_bits)) | ||
558 | max_strength_bits = curr->cipher->strength_bits; | ||
559 | curr = curr->next; | ||
560 | } | ||
561 | |||
562 | number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int)); | ||
563 | if (!number_uses) | ||
564 | { | ||
565 | SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE); | ||
566 | return(0); | ||
567 | } | ||
568 | memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int)); | ||
569 | |||
570 | /* | ||
571 | * Now find the strength_bits values actually used | ||
572 | */ | ||
573 | curr = *head_p; | ||
574 | while (curr != NULL) | ||
575 | { | ||
576 | if (curr->active) | ||
577 | number_uses[curr->cipher->strength_bits]++; | ||
578 | curr = curr->next; | ||
579 | } | ||
580 | /* | ||
581 | * Go through the list of used strength_bits values in descending | ||
582 | * order. | ||
583 | */ | ||
584 | for (i = max_strength_bits; i >= 0; i--) | ||
585 | if (number_uses[i] > 0) | ||
586 | ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i, | ||
587 | co_list, head_p, tail_p); | ||
588 | |||
589 | OPENSSL_free(number_uses); | ||
590 | return(1); | ||
591 | } | ||
592 | |||
593 | static int ssl_cipher_process_rulestr(const char *rule_str, | ||
594 | CIPHER_ORDER *co_list, CIPHER_ORDER **head_p, | ||
595 | CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list) | ||
596 | { | ||
597 | unsigned long algorithms, mask, algo_strength, mask_strength; | ||
598 | const char *l, *start, *buf; | ||
599 | int j, multi, found, rule, retval, ok, buflen; | ||
600 | char ch; | ||
601 | |||
602 | retval = 1; | ||
603 | l = rule_str; | ||
604 | for (;;) | ||
605 | { | ||
606 | ch = *l; | ||
607 | |||
608 | if (ch == '\0') | ||
609 | break; /* done */ | ||
610 | if (ch == '-') | ||
611 | { rule = CIPHER_DEL; l++; } | ||
612 | else if (ch == '+') | ||
613 | { rule = CIPHER_ORD; l++; } | ||
614 | else if (ch == '!') | ||
615 | { rule = CIPHER_KILL; l++; } | ||
616 | else if (ch == '@') | ||
617 | { rule = CIPHER_SPECIAL; l++; } | ||
618 | else | ||
619 | { rule = CIPHER_ADD; } | ||
620 | |||
621 | if (ITEM_SEP(ch)) | ||
622 | { | ||
623 | l++; | ||
624 | continue; | ||
625 | } | ||
626 | |||
627 | algorithms = mask = algo_strength = mask_strength = 0; | ||
628 | |||
629 | start=l; | ||
630 | for (;;) | ||
631 | { | ||
632 | ch = *l; | ||
633 | buf = l; | ||
634 | buflen = 0; | ||
635 | #ifndef CHARSET_EBCDIC | ||
636 | while ( ((ch >= 'A') && (ch <= 'Z')) || | ||
637 | ((ch >= '0') && (ch <= '9')) || | ||
638 | ((ch >= 'a') && (ch <= 'z')) || | ||
639 | (ch == '-')) | ||
640 | #else | ||
641 | while ( isalnum(ch) || (ch == '-')) | ||
642 | #endif | ||
643 | { | ||
644 | ch = *(++l); | ||
645 | buflen++; | ||
646 | } | ||
647 | |||
648 | if (buflen == 0) | ||
649 | { | ||
650 | /* | ||
651 | * We hit something we cannot deal with, | ||
652 | * it is no command or separator nor | ||
653 | * alphanumeric, so we call this an error. | ||
654 | */ | ||
655 | SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, | ||
656 | SSL_R_INVALID_COMMAND); | ||
657 | retval = found = 0; | ||
658 | l++; | ||
659 | break; | ||
660 | } | ||
661 | |||
662 | if (rule == CIPHER_SPECIAL) | ||
663 | { | ||
664 | found = 0; /* unused -- avoid compiler warning */ | ||
665 | break; /* special treatment */ | ||
666 | } | ||
667 | |||
668 | /* check for multi-part specification */ | ||
669 | if (ch == '+') | ||
670 | { | ||
671 | multi=1; | ||
672 | l++; | ||
673 | } | ||
674 | else | ||
675 | multi=0; | ||
676 | |||
677 | /* | ||
678 | * Now search for the cipher alias in the ca_list. Be careful | ||
679 | * with the strncmp, because the "buflen" limitation | ||
680 | * will make the rule "ADH:SOME" and the cipher | ||
681 | * "ADH-MY-CIPHER" look like a match for buflen=3. | ||
682 | * So additionally check whether the cipher name found | ||
683 | * has the correct length. We can save a strlen() call: | ||
684 | * just checking for the '\0' at the right place is | ||
685 | * sufficient, we have to strncmp() anyway. (We cannot | ||
686 | * use strcmp(), because buf is not '\0' terminated.) | ||
687 | */ | ||
688 | j = found = 0; | ||
689 | while (ca_list[j]) | ||
690 | { | ||
691 | if (!strncmp(buf, ca_list[j]->name, buflen) && | ||
692 | (ca_list[j]->name[buflen] == '\0')) | ||
693 | { | ||
694 | found = 1; | ||
695 | break; | ||
696 | } | ||
697 | else | ||
698 | j++; | ||
699 | } | ||
700 | if (!found) | ||
701 | break; /* ignore this entry */ | ||
702 | |||
703 | /* New algorithms: | ||
704 | * 1 - any old restrictions apply outside new mask | ||
705 | * 2 - any new restrictions apply outside old mask | ||
706 | * 3 - enforce old & new where masks intersect | ||
707 | */ | ||
708 | algorithms = (algorithms & ~ca_list[j]->mask) | /* 1 */ | ||
709 | (ca_list[j]->algorithms & ~mask) | /* 2 */ | ||
710 | (algorithms & ca_list[j]->algorithms); /* 3 */ | ||
711 | mask |= ca_list[j]->mask; | ||
712 | algo_strength = (algo_strength & ~ca_list[j]->mask_strength) | | ||
713 | (ca_list[j]->algo_strength & ~mask_strength) | | ||
714 | (algo_strength & ca_list[j]->algo_strength); | ||
715 | mask_strength |= ca_list[j]->mask_strength; | ||
716 | |||
717 | if (!multi) break; | ||
718 | } | ||
719 | |||
720 | /* | ||
721 | * Ok, we have the rule, now apply it | ||
722 | */ | ||
723 | if (rule == CIPHER_SPECIAL) | ||
724 | { /* special command */ | ||
725 | ok = 0; | ||
726 | if ((buflen == 8) && | ||
727 | !strncmp(buf, "STRENGTH", 8)) | ||
728 | ok = ssl_cipher_strength_sort(co_list, | ||
729 | head_p, tail_p); | ||
730 | else | ||
731 | SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, | ||
732 | SSL_R_INVALID_COMMAND); | ||
733 | if (ok == 0) | ||
734 | retval = 0; | ||
735 | /* | ||
736 | * We do not support any "multi" options | ||
737 | * together with "@", so throw away the | ||
738 | * rest of the command, if any left, until | ||
739 | * end or ':' is found. | ||
740 | */ | ||
741 | while ((*l != '\0') && ITEM_SEP(*l)) | ||
742 | l++; | ||
743 | } | ||
744 | else if (found) | ||
745 | { | ||
746 | ssl_cipher_apply_rule(algorithms, mask, | ||
747 | algo_strength, mask_strength, rule, -1, | ||
748 | co_list, head_p, tail_p); | ||
749 | } | ||
750 | else | ||
751 | { | ||
752 | while ((*l != '\0') && ITEM_SEP(*l)) | ||
753 | l++; | ||
754 | } | ||
755 | if (*l == '\0') break; /* done */ | ||
756 | } | ||
757 | |||
758 | return(retval); | ||
759 | } | ||
760 | |||
761 | STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | ||
762 | STACK_OF(SSL_CIPHER) **cipher_list, | ||
763 | STACK_OF(SSL_CIPHER) **cipher_list_by_id, | ||
764 | const char *rule_str) | ||
765 | { | ||
766 | int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases; | ||
767 | unsigned long disabled_mask; | ||
768 | STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list; | ||
769 | const char *rule_p; | ||
770 | CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; | ||
771 | SSL_CIPHER **ca_list = NULL; | ||
772 | |||
773 | /* | ||
774 | * Return with error if nothing to do. | ||
775 | */ | ||
776 | if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL) | ||
777 | return NULL; | ||
778 | |||
779 | if (init_ciphers) | ||
780 | { | ||
781 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
782 | if (init_ciphers) load_ciphers(); | ||
783 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
784 | } | ||
785 | |||
786 | /* | ||
787 | * To reduce the work to do we only want to process the compiled | ||
788 | * in algorithms, so we first get the mask of disabled ciphers. | ||
789 | */ | ||
790 | disabled_mask = ssl_cipher_get_disabled(); | ||
791 | |||
792 | /* | ||
793 | * Now we have to collect the available ciphers from the compiled | ||
794 | * in ciphers. We cannot get more than the number compiled in, so | ||
795 | * it is used for allocation. | ||
796 | */ | ||
797 | num_of_ciphers = ssl_method->num_ciphers(); | ||
798 | #ifdef KSSL_DEBUG | ||
799 | printf("ssl_create_cipher_list() for %d ciphers\n", num_of_ciphers); | ||
800 | #endif /* KSSL_DEBUG */ | ||
801 | co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * num_of_ciphers); | ||
802 | if (co_list == NULL) | ||
803 | { | ||
804 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
805 | return(NULL); /* Failure */ | ||
806 | } | ||
807 | |||
808 | ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask, | ||
809 | co_list, &head, &tail); | ||
810 | |||
811 | /* | ||
812 | * We also need cipher aliases for selecting based on the rule_str. | ||
813 | * There might be two types of entries in the rule_str: 1) names | ||
814 | * of ciphers themselves 2) aliases for groups of ciphers. | ||
815 | * For 1) we need the available ciphers and for 2) the cipher | ||
816 | * groups of cipher_aliases added together in one list (otherwise | ||
817 | * we would be happy with just the cipher_aliases table). | ||
818 | */ | ||
819 | num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER); | ||
820 | num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1; | ||
821 | ca_list = | ||
822 | (SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max); | ||
823 | if (ca_list == NULL) | ||
824 | { | ||
825 | OPENSSL_free(co_list); | ||
826 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
827 | return(NULL); /* Failure */ | ||
828 | } | ||
829 | ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask, | ||
830 | head); | ||
831 | |||
832 | /* | ||
833 | * If the rule_string begins with DEFAULT, apply the default rule | ||
834 | * before using the (possibly available) additional rules. | ||
835 | */ | ||
836 | ok = 1; | ||
837 | rule_p = rule_str; | ||
838 | if (strncmp(rule_str,"DEFAULT",7) == 0) | ||
839 | { | ||
840 | ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST, | ||
841 | co_list, &head, &tail, ca_list); | ||
842 | rule_p += 7; | ||
843 | if (*rule_p == ':') | ||
844 | rule_p++; | ||
845 | } | ||
846 | |||
847 | if (ok && (strlen(rule_p) > 0)) | ||
848 | ok = ssl_cipher_process_rulestr(rule_p, co_list, &head, &tail, | ||
849 | ca_list); | ||
850 | |||
851 | OPENSSL_free(ca_list); /* Not needed anymore */ | ||
852 | |||
853 | if (!ok) | ||
854 | { /* Rule processing failure */ | ||
855 | OPENSSL_free(co_list); | ||
856 | return(NULL); | ||
857 | } | ||
858 | /* | ||
859 | * Allocate new "cipherstack" for the result, return with error | ||
860 | * if we cannot get one. | ||
861 | */ | ||
862 | if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) | ||
863 | { | ||
864 | OPENSSL_free(co_list); | ||
865 | return(NULL); | ||
866 | } | ||
867 | |||
868 | /* | ||
869 | * The cipher selection for the list is done. The ciphers are added | ||
870 | * to the resulting precedence to the STACK_OF(SSL_CIPHER). | ||
871 | */ | ||
872 | for (curr = head; curr != NULL; curr = curr->next) | ||
873 | { | ||
874 | #ifdef OPENSSL_FIPS | ||
875 | if (curr->active && (!FIPS_mode() || curr->cipher->algo_strength & SSL_FIPS)) | ||
876 | #else | ||
877 | if (curr->active) | ||
878 | #endif | ||
879 | { | ||
880 | sk_SSL_CIPHER_push(cipherstack, curr->cipher); | ||
881 | #ifdef CIPHER_DEBUG | ||
882 | printf("<%s>\n",curr->cipher->name); | ||
883 | #endif | ||
884 | } | ||
885 | } | ||
886 | OPENSSL_free(co_list); /* Not needed any longer */ | ||
887 | |||
888 | tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack); | ||
889 | if (tmp_cipher_list == NULL) | ||
890 | { | ||
891 | sk_SSL_CIPHER_free(cipherstack); | ||
892 | return NULL; | ||
893 | } | ||
894 | if (*cipher_list != NULL) | ||
895 | sk_SSL_CIPHER_free(*cipher_list); | ||
896 | *cipher_list = cipherstack; | ||
897 | if (*cipher_list_by_id != NULL) | ||
898 | sk_SSL_CIPHER_free(*cipher_list_by_id); | ||
899 | *cipher_list_by_id = tmp_cipher_list; | ||
900 | sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp); | ||
901 | |||
902 | return(cipherstack); | ||
903 | } | ||
904 | |||
905 | char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | ||
906 | { | ||
907 | int is_export,pkl,kl; | ||
908 | char *ver,*exp_str; | ||
909 | char *kx,*au,*enc,*mac; | ||
910 | unsigned long alg,alg2,alg_s; | ||
911 | #ifdef KSSL_DEBUG | ||
912 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n"; | ||
913 | #else | ||
914 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n"; | ||
915 | #endif /* KSSL_DEBUG */ | ||
916 | |||
917 | alg=cipher->algorithms; | ||
918 | alg_s=cipher->algo_strength; | ||
919 | alg2=cipher->algorithm2; | ||
920 | |||
921 | is_export=SSL_C_IS_EXPORT(cipher); | ||
922 | pkl=SSL_C_EXPORT_PKEYLENGTH(cipher); | ||
923 | kl=SSL_C_EXPORT_KEYLENGTH(cipher); | ||
924 | exp_str=is_export?" export":""; | ||
925 | |||
926 | if (alg & SSL_SSLV2) | ||
927 | ver="SSLv2"; | ||
928 | else if (alg & SSL_SSLV3) | ||
929 | ver="SSLv3"; | ||
930 | else | ||
931 | ver="unknown"; | ||
932 | |||
933 | switch (alg&SSL_MKEY_MASK) | ||
934 | { | ||
935 | case SSL_kRSA: | ||
936 | kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA"; | ||
937 | break; | ||
938 | case SSL_kDHr: | ||
939 | kx="DH/RSA"; | ||
940 | break; | ||
941 | case SSL_kDHd: | ||
942 | kx="DH/DSS"; | ||
943 | break; | ||
944 | case SSL_kKRB5: /* VRS */ | ||
945 | case SSL_KRB5: /* VRS */ | ||
946 | kx="KRB5"; | ||
947 | break; | ||
948 | case SSL_kFZA: | ||
949 | kx="Fortezza"; | ||
950 | break; | ||
951 | case SSL_kEDH: | ||
952 | kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH"; | ||
953 | break; | ||
954 | default: | ||
955 | kx="unknown"; | ||
956 | } | ||
957 | |||
958 | switch (alg&SSL_AUTH_MASK) | ||
959 | { | ||
960 | case SSL_aRSA: | ||
961 | au="RSA"; | ||
962 | break; | ||
963 | case SSL_aDSS: | ||
964 | au="DSS"; | ||
965 | break; | ||
966 | case SSL_aDH: | ||
967 | au="DH"; | ||
968 | break; | ||
969 | case SSL_aKRB5: /* VRS */ | ||
970 | case SSL_KRB5: /* VRS */ | ||
971 | au="KRB5"; | ||
972 | break; | ||
973 | case SSL_aFZA: | ||
974 | case SSL_aNULL: | ||
975 | au="None"; | ||
976 | break; | ||
977 | default: | ||
978 | au="unknown"; | ||
979 | break; | ||
980 | } | ||
981 | |||
982 | switch (alg&SSL_ENC_MASK) | ||
983 | { | ||
984 | case SSL_DES: | ||
985 | enc=(is_export && kl == 5)?"DES(40)":"DES(56)"; | ||
986 | break; | ||
987 | case SSL_3DES: | ||
988 | enc="3DES(168)"; | ||
989 | break; | ||
990 | case SSL_RC4: | ||
991 | enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)") | ||
992 | :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)"); | ||
993 | break; | ||
994 | case SSL_RC2: | ||
995 | enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)"; | ||
996 | break; | ||
997 | case SSL_IDEA: | ||
998 | enc="IDEA(128)"; | ||
999 | break; | ||
1000 | case SSL_eFZA: | ||
1001 | enc="Fortezza"; | ||
1002 | break; | ||
1003 | case SSL_eNULL: | ||
1004 | enc="None"; | ||
1005 | break; | ||
1006 | case SSL_AES: | ||
1007 | switch(cipher->strength_bits) | ||
1008 | { | ||
1009 | case 128: enc="AES(128)"; break; | ||
1010 | case 192: enc="AES(192)"; break; | ||
1011 | case 256: enc="AES(256)"; break; | ||
1012 | default: enc="AES(?""?""?)"; break; | ||
1013 | } | ||
1014 | break; | ||
1015 | default: | ||
1016 | enc="unknown"; | ||
1017 | break; | ||
1018 | } | ||
1019 | |||
1020 | switch (alg&SSL_MAC_MASK) | ||
1021 | { | ||
1022 | case SSL_MD5: | ||
1023 | mac="MD5"; | ||
1024 | break; | ||
1025 | case SSL_SHA1: | ||
1026 | mac="SHA1"; | ||
1027 | break; | ||
1028 | default: | ||
1029 | mac="unknown"; | ||
1030 | break; | ||
1031 | } | ||
1032 | |||
1033 | if (buf == NULL) | ||
1034 | { | ||
1035 | len=128; | ||
1036 | buf=OPENSSL_malloc(len); | ||
1037 | if (buf == NULL) return("OPENSSL_malloc Error"); | ||
1038 | } | ||
1039 | else if (len < 128) | ||
1040 | return("Buffer too small"); | ||
1041 | |||
1042 | #ifdef KSSL_DEBUG | ||
1043 | BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg); | ||
1044 | #else | ||
1045 | BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str); | ||
1046 | #endif /* KSSL_DEBUG */ | ||
1047 | return(buf); | ||
1048 | } | ||
1049 | |||
1050 | char *SSL_CIPHER_get_version(const SSL_CIPHER *c) | ||
1051 | { | ||
1052 | int i; | ||
1053 | |||
1054 | if (c == NULL) return("(NONE)"); | ||
1055 | i=(int)(c->id>>24L); | ||
1056 | if (i == 3) | ||
1057 | return("TLSv1/SSLv3"); | ||
1058 | else if (i == 2) | ||
1059 | return("SSLv2"); | ||
1060 | else | ||
1061 | return("unknown"); | ||
1062 | } | ||
1063 | |||
1064 | /* return the actual cipher being used */ | ||
1065 | const char *SSL_CIPHER_get_name(const SSL_CIPHER *c) | ||
1066 | { | ||
1067 | if (c != NULL) | ||
1068 | return(c->name); | ||
1069 | return("(NONE)"); | ||
1070 | } | ||
1071 | |||
1072 | /* number of bits for symmetric cipher */ | ||
1073 | int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits) | ||
1074 | { | ||
1075 | int ret=0; | ||
1076 | |||
1077 | if (c != NULL) | ||
1078 | { | ||
1079 | if (alg_bits != NULL) *alg_bits = c->alg_bits; | ||
1080 | ret = c->strength_bits; | ||
1081 | } | ||
1082 | return(ret); | ||
1083 | } | ||
1084 | |||
1085 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n) | ||
1086 | { | ||
1087 | SSL_COMP *ctmp; | ||
1088 | int i,nn; | ||
1089 | |||
1090 | if ((n == 0) || (sk == NULL)) return(NULL); | ||
1091 | nn=sk_SSL_COMP_num(sk); | ||
1092 | for (i=0; i<nn; i++) | ||
1093 | { | ||
1094 | ctmp=sk_SSL_COMP_value(sk,i); | ||
1095 | if (ctmp->id == n) | ||
1096 | return(ctmp); | ||
1097 | } | ||
1098 | return(NULL); | ||
1099 | } | ||
1100 | |||
1101 | static int sk_comp_cmp(const SSL_COMP * const *a, | ||
1102 | const SSL_COMP * const *b) | ||
1103 | { | ||
1104 | return((*a)->id-(*b)->id); | ||
1105 | } | ||
1106 | |||
1107 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) | ||
1108 | { | ||
1109 | return(ssl_comp_methods); | ||
1110 | } | ||
1111 | |||
1112 | int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) | ||
1113 | { | ||
1114 | SSL_COMP *comp; | ||
1115 | STACK_OF(SSL_COMP) *sk; | ||
1116 | |||
1117 | if (cm == NULL || cm->type == NID_undef) | ||
1118 | return 1; | ||
1119 | |||
1120 | MemCheck_off(); | ||
1121 | comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP)); | ||
1122 | comp->id=id; | ||
1123 | comp->method=cm; | ||
1124 | if (ssl_comp_methods == NULL) | ||
1125 | sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp); | ||
1126 | else | ||
1127 | sk=ssl_comp_methods; | ||
1128 | if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp)) | ||
1129 | { | ||
1130 | MemCheck_on(); | ||
1131 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE); | ||
1132 | return(1); | ||
1133 | } | ||
1134 | else | ||
1135 | { | ||
1136 | MemCheck_on(); | ||
1137 | return(0); | ||
1138 | } | ||
1139 | } | ||
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c deleted file mode 100644 index 4bcf591298..0000000000 --- a/src/lib/libssl/ssl_err.c +++ /dev/null | |||
@@ -1,462 +0,0 @@ | |||
1 | /* ssl/ssl_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/ssl.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_SSL,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_SSL,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA SSL_str_functs[]= | ||
72 | { | ||
73 | {ERR_FUNC(SSL_F_CLIENT_CERTIFICATE), "CLIENT_CERTIFICATE"}, | ||
74 | {ERR_FUNC(SSL_F_CLIENT_FINISHED), "CLIENT_FINISHED"}, | ||
75 | {ERR_FUNC(SSL_F_CLIENT_HELLO), "CLIENT_HELLO"}, | ||
76 | {ERR_FUNC(SSL_F_CLIENT_MASTER_KEY), "CLIENT_MASTER_KEY"}, | ||
77 | {ERR_FUNC(SSL_F_D2I_SSL_SESSION), "d2i_SSL_SESSION"}, | ||
78 | {ERR_FUNC(SSL_F_DO_SSL3_WRITE), "DO_SSL3_WRITE"}, | ||
79 | {ERR_FUNC(SSL_F_GET_CLIENT_FINISHED), "GET_CLIENT_FINISHED"}, | ||
80 | {ERR_FUNC(SSL_F_GET_CLIENT_HELLO), "GET_CLIENT_HELLO"}, | ||
81 | {ERR_FUNC(SSL_F_GET_CLIENT_MASTER_KEY), "GET_CLIENT_MASTER_KEY"}, | ||
82 | {ERR_FUNC(SSL_F_GET_SERVER_FINISHED), "GET_SERVER_FINISHED"}, | ||
83 | {ERR_FUNC(SSL_F_GET_SERVER_HELLO), "GET_SERVER_HELLO"}, | ||
84 | {ERR_FUNC(SSL_F_GET_SERVER_VERIFY), "GET_SERVER_VERIFY"}, | ||
85 | {ERR_FUNC(SSL_F_I2D_SSL_SESSION), "i2d_SSL_SESSION"}, | ||
86 | {ERR_FUNC(SSL_F_READ_N), "READ_N"}, | ||
87 | {ERR_FUNC(SSL_F_REQUEST_CERTIFICATE), "REQUEST_CERTIFICATE"}, | ||
88 | {ERR_FUNC(SSL_F_SERVER_FINISH), "SERVER_FINISH"}, | ||
89 | {ERR_FUNC(SSL_F_SERVER_HELLO), "SERVER_HELLO"}, | ||
90 | {ERR_FUNC(SSL_F_SERVER_VERIFY), "SERVER_VERIFY"}, | ||
91 | {ERR_FUNC(SSL_F_SSL23_ACCEPT), "SSL23_ACCEPT"}, | ||
92 | {ERR_FUNC(SSL_F_SSL23_CLIENT_HELLO), "SSL23_CLIENT_HELLO"}, | ||
93 | {ERR_FUNC(SSL_F_SSL23_CONNECT), "SSL23_CONNECT"}, | ||
94 | {ERR_FUNC(SSL_F_SSL23_GET_CLIENT_HELLO), "SSL23_GET_CLIENT_HELLO"}, | ||
95 | {ERR_FUNC(SSL_F_SSL23_GET_SERVER_HELLO), "SSL23_GET_SERVER_HELLO"}, | ||
96 | {ERR_FUNC(SSL_F_SSL23_PEEK), "SSL23_PEEK"}, | ||
97 | {ERR_FUNC(SSL_F_SSL23_READ), "SSL23_READ"}, | ||
98 | {ERR_FUNC(SSL_F_SSL23_WRITE), "SSL23_WRITE"}, | ||
99 | {ERR_FUNC(SSL_F_SSL2_ACCEPT), "SSL2_ACCEPT"}, | ||
100 | {ERR_FUNC(SSL_F_SSL2_CONNECT), "SSL2_CONNECT"}, | ||
101 | {ERR_FUNC(SSL_F_SSL2_ENC_INIT), "SSL2_ENC_INIT"}, | ||
102 | {ERR_FUNC(SSL_F_SSL2_GENERATE_KEY_MATERIAL), "SSL2_GENERATE_KEY_MATERIAL"}, | ||
103 | {ERR_FUNC(SSL_F_SSL2_PEEK), "SSL2_PEEK"}, | ||
104 | {ERR_FUNC(SSL_F_SSL2_READ), "SSL2_READ"}, | ||
105 | {ERR_FUNC(SSL_F_SSL2_READ_INTERNAL), "SSL2_READ_INTERNAL"}, | ||
106 | {ERR_FUNC(SSL_F_SSL2_SET_CERTIFICATE), "SSL2_SET_CERTIFICATE"}, | ||
107 | {ERR_FUNC(SSL_F_SSL2_WRITE), "SSL2_WRITE"}, | ||
108 | {ERR_FUNC(SSL_F_SSL3_ACCEPT), "SSL3_ACCEPT"}, | ||
109 | {ERR_FUNC(SSL_F_SSL3_CALLBACK_CTRL), "SSL3_CALLBACK_CTRL"}, | ||
110 | {ERR_FUNC(SSL_F_SSL3_CHANGE_CIPHER_STATE), "SSL3_CHANGE_CIPHER_STATE"}, | ||
111 | {ERR_FUNC(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM), "SSL3_CHECK_CERT_AND_ALGORITHM"}, | ||
112 | {ERR_FUNC(SSL_F_SSL3_CLIENT_HELLO), "SSL3_CLIENT_HELLO"}, | ||
113 | {ERR_FUNC(SSL_F_SSL3_CONNECT), "SSL3_CONNECT"}, | ||
114 | {ERR_FUNC(SSL_F_SSL3_CTRL), "SSL3_CTRL"}, | ||
115 | {ERR_FUNC(SSL_F_SSL3_CTX_CTRL), "SSL3_CTX_CTRL"}, | ||
116 | {ERR_FUNC(SSL_F_SSL3_ENC), "SSL3_ENC"}, | ||
117 | {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "SSL3_GENERATE_KEY_BLOCK"}, | ||
118 | {ERR_FUNC(SSL_F_SSL3_GET_CERTIFICATE_REQUEST), "SSL3_GET_CERTIFICATE_REQUEST"}, | ||
119 | {ERR_FUNC(SSL_F_SSL3_GET_CERT_VERIFY), "SSL3_GET_CERT_VERIFY"}, | ||
120 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_CERTIFICATE), "SSL3_GET_CLIENT_CERTIFICATE"}, | ||
121 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_HELLO), "SSL3_GET_CLIENT_HELLO"}, | ||
122 | {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE), "SSL3_GET_CLIENT_KEY_EXCHANGE"}, | ||
123 | {ERR_FUNC(SSL_F_SSL3_GET_FINISHED), "SSL3_GET_FINISHED"}, | ||
124 | {ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE), "SSL3_GET_KEY_EXCHANGE"}, | ||
125 | {ERR_FUNC(SSL_F_SSL3_GET_MESSAGE), "SSL3_GET_MESSAGE"}, | ||
126 | {ERR_FUNC(SSL_F_SSL3_GET_RECORD), "SSL3_GET_RECORD"}, | ||
127 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"}, | ||
128 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"}, | ||
129 | {ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO), "SSL3_GET_SERVER_HELLO"}, | ||
130 | {ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN), "SSL3_OUTPUT_CERT_CHAIN"}, | ||
131 | {ERR_FUNC(SSL_F_SSL3_PEEK), "SSL3_PEEK"}, | ||
132 | {ERR_FUNC(SSL_F_SSL3_READ_BYTES), "SSL3_READ_BYTES"}, | ||
133 | {ERR_FUNC(SSL_F_SSL3_READ_N), "SSL3_READ_N"}, | ||
134 | {ERR_FUNC(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST), "SSL3_SEND_CERTIFICATE_REQUEST"}, | ||
135 | {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE), "SSL3_SEND_CLIENT_CERTIFICATE"}, | ||
136 | {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE), "SSL3_SEND_CLIENT_KEY_EXCHANGE"}, | ||
137 | {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_VERIFY), "SSL3_SEND_CLIENT_VERIFY"}, | ||
138 | {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_CERTIFICATE), "SSL3_SEND_SERVER_CERTIFICATE"}, | ||
139 | {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_HELLO), "SSL3_SEND_SERVER_HELLO"}, | ||
140 | {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, | ||
141 | {ERR_FUNC(SSL_F_SSL3_SETUP_BUFFERS), "SSL3_SETUP_BUFFERS"}, | ||
142 | {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"}, | ||
143 | {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"}, | ||
144 | {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"}, | ||
145 | {ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK), "SSL_add_dir_cert_subjects_to_stack"}, | ||
146 | {ERR_FUNC(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK), "SSL_add_file_cert_subjects_to_stack"}, | ||
147 | {ERR_FUNC(SSL_F_SSL_BAD_METHOD), "SSL_BAD_METHOD"}, | ||
148 | {ERR_FUNC(SSL_F_SSL_BYTES_TO_CIPHER_LIST), "SSL_BYTES_TO_CIPHER_LIST"}, | ||
149 | {ERR_FUNC(SSL_F_SSL_CERT_DUP), "SSL_CERT_DUP"}, | ||
150 | {ERR_FUNC(SSL_F_SSL_CERT_INST), "SSL_CERT_INST"}, | ||
151 | {ERR_FUNC(SSL_F_SSL_CERT_INSTANTIATE), "SSL_CERT_INSTANTIATE"}, | ||
152 | {ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"}, | ||
153 | {ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY), "SSL_check_private_key"}, | ||
154 | {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "SSL_CIPHER_PROCESS_RULESTR"}, | ||
155 | {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "SSL_CIPHER_STRENGTH_SORT"}, | ||
156 | {ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"}, | ||
157 | {ERR_FUNC(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD), "SSL_COMP_add_compression_method"}, | ||
158 | {ERR_FUNC(SSL_F_SSL_CREATE_CIPHER_LIST), "SSL_CREATE_CIPHER_LIST"}, | ||
159 | {ERR_FUNC(SSL_F_SSL_CTRL), "SSL_ctrl"}, | ||
160 | {ERR_FUNC(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY), "SSL_CTX_check_private_key"}, | ||
161 | {ERR_FUNC(SSL_F_SSL_CTX_NEW), "SSL_CTX_new"}, | ||
162 | {ERR_FUNC(SSL_F_SSL_CTX_SET_CIPHER_LIST), "SSL_CTX_set_cipher_list"}, | ||
163 | {ERR_FUNC(SSL_F_SSL_CTX_SET_PURPOSE), "SSL_CTX_set_purpose"}, | ||
164 | {ERR_FUNC(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT), "SSL_CTX_set_session_id_context"}, | ||
165 | {ERR_FUNC(SSL_F_SSL_CTX_SET_SSL_VERSION), "SSL_CTX_set_ssl_version"}, | ||
166 | {ERR_FUNC(SSL_F_SSL_CTX_SET_TRUST), "SSL_CTX_set_trust"}, | ||
167 | {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE), "SSL_CTX_use_certificate"}, | ||
168 | {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1), "SSL_CTX_use_certificate_ASN1"}, | ||
169 | {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE), "SSL_CTX_use_certificate_chain_file"}, | ||
170 | {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE), "SSL_CTX_use_certificate_file"}, | ||
171 | {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY), "SSL_CTX_use_PrivateKey"}, | ||
172 | {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1), "SSL_CTX_use_PrivateKey_ASN1"}, | ||
173 | {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE), "SSL_CTX_use_PrivateKey_file"}, | ||
174 | {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY), "SSL_CTX_use_RSAPrivateKey"}, | ||
175 | {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1), "SSL_CTX_use_RSAPrivateKey_ASN1"}, | ||
176 | {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE), "SSL_CTX_use_RSAPrivateKey_file"}, | ||
177 | {ERR_FUNC(SSL_F_SSL_DO_HANDSHAKE), "SSL_do_handshake"}, | ||
178 | {ERR_FUNC(SSL_F_SSL_GET_NEW_SESSION), "SSL_GET_NEW_SESSION"}, | ||
179 | {ERR_FUNC(SSL_F_SSL_GET_PREV_SESSION), "SSL_GET_PREV_SESSION"}, | ||
180 | {ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_CERT), "SSL_GET_SERVER_SEND_CERT"}, | ||
181 | {ERR_FUNC(SSL_F_SSL_GET_SIGN_PKEY), "SSL_GET_SIGN_PKEY"}, | ||
182 | {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"}, | ||
183 | {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE), "SSL_load_client_CA_file"}, | ||
184 | {ERR_FUNC(SSL_F_SSL_NEW), "SSL_new"}, | ||
185 | {ERR_FUNC(SSL_F_SSL_READ), "SSL_read"}, | ||
186 | {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT), "SSL_RSA_PRIVATE_DECRYPT"}, | ||
187 | {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT), "SSL_RSA_PUBLIC_ENCRYPT"}, | ||
188 | {ERR_FUNC(SSL_F_SSL_SESSION_NEW), "SSL_SESSION_new"}, | ||
189 | {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP), "SSL_SESSION_print_fp"}, | ||
190 | {ERR_FUNC(SSL_F_SSL_SESS_CERT_NEW), "SSL_SESS_CERT_NEW"}, | ||
191 | {ERR_FUNC(SSL_F_SSL_SET_CERT), "SSL_SET_CERT"}, | ||
192 | {ERR_FUNC(SSL_F_SSL_SET_CIPHER_LIST), "SSL_set_cipher_list"}, | ||
193 | {ERR_FUNC(SSL_F_SSL_SET_FD), "SSL_set_fd"}, | ||
194 | {ERR_FUNC(SSL_F_SSL_SET_PKEY), "SSL_SET_PKEY"}, | ||
195 | {ERR_FUNC(SSL_F_SSL_SET_PURPOSE), "SSL_set_purpose"}, | ||
196 | {ERR_FUNC(SSL_F_SSL_SET_RFD), "SSL_set_rfd"}, | ||
197 | {ERR_FUNC(SSL_F_SSL_SET_SESSION), "SSL_set_session"}, | ||
198 | {ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT), "SSL_set_session_id_context"}, | ||
199 | {ERR_FUNC(SSL_F_SSL_SET_TRUST), "SSL_set_trust"}, | ||
200 | {ERR_FUNC(SSL_F_SSL_SET_WFD), "SSL_set_wfd"}, | ||
201 | {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"}, | ||
202 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_CONST_FUNCTION), "SSL_UNDEFINED_CONST_FUNCTION"}, | ||
203 | {ERR_FUNC(SSL_F_SSL_UNDEFINED_FUNCTION), "SSL_UNDEFINED_FUNCTION"}, | ||
204 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE), "SSL_use_certificate"}, | ||
205 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_ASN1), "SSL_use_certificate_ASN1"}, | ||
206 | {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_FILE), "SSL_use_certificate_file"}, | ||
207 | {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY), "SSL_use_PrivateKey"}, | ||
208 | {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_ASN1), "SSL_use_PrivateKey_ASN1"}, | ||
209 | {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_FILE), "SSL_use_PrivateKey_file"}, | ||
210 | {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY), "SSL_use_RSAPrivateKey"}, | ||
211 | {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1), "SSL_use_RSAPrivateKey_ASN1"}, | ||
212 | {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE), "SSL_use_RSAPrivateKey_file"}, | ||
213 | {ERR_FUNC(SSL_F_SSL_VERIFY_CERT_CHAIN), "SSL_VERIFY_CERT_CHAIN"}, | ||
214 | {ERR_FUNC(SSL_F_SSL_WRITE), "SSL_write"}, | ||
215 | {ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE), "TLS1_CHANGE_CIPHER_STATE"}, | ||
216 | {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"}, | ||
217 | {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"}, | ||
218 | {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"}, | ||
219 | {0,NULL} | ||
220 | }; | ||
221 | |||
222 | static ERR_STRING_DATA SSL_str_reasons[]= | ||
223 | { | ||
224 | {ERR_REASON(SSL_R_APP_DATA_IN_HANDSHAKE) ,"app data in handshake"}, | ||
225 | {ERR_REASON(SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT),"attempt to reuse session in different context"}, | ||
226 | {ERR_REASON(SSL_R_BAD_ALERT_RECORD) ,"bad alert record"}, | ||
227 | {ERR_REASON(SSL_R_BAD_AUTHENTICATION_TYPE),"bad authentication type"}, | ||
228 | {ERR_REASON(SSL_R_BAD_CHANGE_CIPHER_SPEC),"bad change cipher spec"}, | ||
229 | {ERR_REASON(SSL_R_BAD_CHECKSUM) ,"bad checksum"}, | ||
230 | {ERR_REASON(SSL_R_BAD_DATA_RETURNED_BY_CALLBACK),"bad data returned by callback"}, | ||
231 | {ERR_REASON(SSL_R_BAD_DECOMPRESSION) ,"bad decompression"}, | ||
232 | {ERR_REASON(SSL_R_BAD_DH_G_LENGTH) ,"bad dh g length"}, | ||
233 | {ERR_REASON(SSL_R_BAD_DH_PUB_KEY_LENGTH) ,"bad dh pub key length"}, | ||
234 | {ERR_REASON(SSL_R_BAD_DH_P_LENGTH) ,"bad dh p length"}, | ||
235 | {ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) ,"bad digest length"}, | ||
236 | {ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) ,"bad dsa signature"}, | ||
237 | {ERR_REASON(SSL_R_BAD_HELLO_REQUEST) ,"bad hello request"}, | ||
238 | {ERR_REASON(SSL_R_BAD_LENGTH) ,"bad length"}, | ||
239 | {ERR_REASON(SSL_R_BAD_MAC_DECODE) ,"bad mac decode"}, | ||
240 | {ERR_REASON(SSL_R_BAD_MESSAGE_TYPE) ,"bad message type"}, | ||
241 | {ERR_REASON(SSL_R_BAD_PACKET_LENGTH) ,"bad packet length"}, | ||
242 | {ERR_REASON(SSL_R_BAD_PROTOCOL_VERSION_NUMBER),"bad protocol version number"}, | ||
243 | {ERR_REASON(SSL_R_BAD_RESPONSE_ARGUMENT) ,"bad response argument"}, | ||
244 | {ERR_REASON(SSL_R_BAD_RSA_DECRYPT) ,"bad rsa decrypt"}, | ||
245 | {ERR_REASON(SSL_R_BAD_RSA_ENCRYPT) ,"bad rsa encrypt"}, | ||
246 | {ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) ,"bad rsa e length"}, | ||
247 | {ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH),"bad rsa modulus length"}, | ||
248 | {ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) ,"bad rsa signature"}, | ||
249 | {ERR_REASON(SSL_R_BAD_SIGNATURE) ,"bad signature"}, | ||
250 | {ERR_REASON(SSL_R_BAD_SSL_FILETYPE) ,"bad ssl filetype"}, | ||
251 | {ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH),"bad ssl session id length"}, | ||
252 | {ERR_REASON(SSL_R_BAD_STATE) ,"bad state"}, | ||
253 | {ERR_REASON(SSL_R_BAD_WRITE_RETRY) ,"bad write retry"}, | ||
254 | {ERR_REASON(SSL_R_BIO_NOT_SET) ,"bio not set"}, | ||
255 | {ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG),"block cipher pad is wrong"}, | ||
256 | {ERR_REASON(SSL_R_BN_LIB) ,"bn lib"}, | ||
257 | {ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) ,"ca dn length mismatch"}, | ||
258 | {ERR_REASON(SSL_R_CA_DN_TOO_LONG) ,"ca dn too long"}, | ||
259 | {ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) ,"ccs received early"}, | ||
260 | {ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED),"certificate verify failed"}, | ||
261 | {ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) ,"cert length mismatch"}, | ||
262 | {ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT),"challenge is different"}, | ||
263 | {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH),"cipher code wrong length"}, | ||
264 | {ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE),"cipher or hash unavailable"}, | ||
265 | {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR),"cipher table src error"}, | ||
266 | {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG),"compressed length too long"}, | ||
267 | {ERR_REASON(SSL_R_COMPRESSION_FAILURE) ,"compression failure"}, | ||
268 | {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR),"compression library error"}, | ||
269 | {ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT),"connection id is different"}, | ||
270 | {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET),"connection type not set"}, | ||
271 | {ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED),"data between ccs and finished"}, | ||
272 | {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) ,"data length too long"}, | ||
273 | {ERR_REASON(SSL_R_DECRYPTION_FAILED) ,"decryption failed"}, | ||
274 | {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC),"decryption failed or bad record mac"}, | ||
275 | {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG),"dh public value length is wrong"}, | ||
276 | {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) ,"digest check failed"}, | ||
277 | {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG),"encrypted length too long"}, | ||
278 | {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY),"error generating tmp rsa key"}, | ||
279 | {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST),"error in received cipher list"}, | ||
280 | {ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE),"excessive message size"}, | ||
281 | {ERR_REASON(SSL_R_EXTRA_DATA_IN_MESSAGE) ,"extra data in message"}, | ||
282 | {ERR_REASON(SSL_R_GOT_A_FIN_BEFORE_A_CCS),"got a fin before a ccs"}, | ||
283 | {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST) ,"https proxy request"}, | ||
284 | {ERR_REASON(SSL_R_HTTP_REQUEST) ,"http request"}, | ||
285 | {ERR_REASON(SSL_R_ILLEGAL_PADDING) ,"illegal padding"}, | ||
286 | {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH),"invalid challenge length"}, | ||
287 | {ERR_REASON(SSL_R_INVALID_COMMAND) ,"invalid command"}, | ||
288 | {ERR_REASON(SSL_R_INVALID_PURPOSE) ,"invalid purpose"}, | ||
289 | {ERR_REASON(SSL_R_INVALID_TRUST) ,"invalid trust"}, | ||
290 | {ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) ,"key arg too long"}, | ||
291 | {ERR_REASON(SSL_R_KRB5) ,"krb5"}, | ||
292 | {ERR_REASON(SSL_R_KRB5_C_CC_PRINC) ,"krb5 client cc principal (no tkt?)"}, | ||
293 | {ERR_REASON(SSL_R_KRB5_C_GET_CRED) ,"krb5 client get cred"}, | ||
294 | {ERR_REASON(SSL_R_KRB5_C_INIT) ,"krb5 client init"}, | ||
295 | {ERR_REASON(SSL_R_KRB5_C_MK_REQ) ,"krb5 client mk_req (expired tkt?)"}, | ||
296 | {ERR_REASON(SSL_R_KRB5_S_BAD_TICKET) ,"krb5 server bad ticket"}, | ||
297 | {ERR_REASON(SSL_R_KRB5_S_INIT) ,"krb5 server init"}, | ||
298 | {ERR_REASON(SSL_R_KRB5_S_RD_REQ) ,"krb5 server rd_req (keytab perms?)"}, | ||
299 | {ERR_REASON(SSL_R_KRB5_S_TKT_EXPIRED) ,"krb5 server tkt expired"}, | ||
300 | {ERR_REASON(SSL_R_KRB5_S_TKT_NYV) ,"krb5 server tkt not yet valid"}, | ||
301 | {ERR_REASON(SSL_R_KRB5_S_TKT_SKEW) ,"krb5 server tkt skew"}, | ||
302 | {ERR_REASON(SSL_R_LENGTH_MISMATCH) ,"length mismatch"}, | ||
303 | {ERR_REASON(SSL_R_LENGTH_TOO_SHORT) ,"length too short"}, | ||
304 | {ERR_REASON(SSL_R_LIBRARY_BUG) ,"library bug"}, | ||
305 | {ERR_REASON(SSL_R_LIBRARY_HAS_NO_CIPHERS),"library has no ciphers"}, | ||
306 | {ERR_REASON(SSL_R_MESSAGE_TOO_LONG) ,"message too long"}, | ||
307 | {ERR_REASON(SSL_R_MISSING_DH_DSA_CERT) ,"missing dh dsa cert"}, | ||
308 | {ERR_REASON(SSL_R_MISSING_DH_KEY) ,"missing dh key"}, | ||
309 | {ERR_REASON(SSL_R_MISSING_DH_RSA_CERT) ,"missing dh rsa cert"}, | ||
310 | {ERR_REASON(SSL_R_MISSING_DSA_SIGNING_CERT),"missing dsa signing cert"}, | ||
311 | {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_DH_KEY),"missing export tmp dh key"}, | ||
312 | {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_RSA_KEY),"missing export tmp rsa key"}, | ||
313 | {ERR_REASON(SSL_R_MISSING_RSA_CERTIFICATE),"missing rsa certificate"}, | ||
314 | {ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT),"missing rsa encrypting cert"}, | ||
315 | {ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT),"missing rsa signing cert"}, | ||
316 | {ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) ,"missing tmp dh key"}, | ||
317 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) ,"missing tmp rsa key"}, | ||
318 | {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) ,"missing tmp rsa pkey"}, | ||
319 | {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE),"missing verify message"}, | ||
320 | {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET),"non sslv2 initial packet"}, | ||
321 | {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED),"no certificates returned"}, | ||
322 | {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED),"no certificate assigned"}, | ||
323 | {ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED),"no certificate returned"}, | ||
324 | {ERR_REASON(SSL_R_NO_CERTIFICATE_SET) ,"no certificate set"}, | ||
325 | {ERR_REASON(SSL_R_NO_CERTIFICATE_SPECIFIED),"no certificate specified"}, | ||
326 | {ERR_REASON(SSL_R_NO_CIPHERS_AVAILABLE) ,"no ciphers available"}, | ||
327 | {ERR_REASON(SSL_R_NO_CIPHERS_PASSED) ,"no ciphers passed"}, | ||
328 | {ERR_REASON(SSL_R_NO_CIPHERS_SPECIFIED) ,"no ciphers specified"}, | ||
329 | {ERR_REASON(SSL_R_NO_CIPHER_LIST) ,"no cipher list"}, | ||
330 | {ERR_REASON(SSL_R_NO_CIPHER_MATCH) ,"no cipher match"}, | ||
331 | {ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED),"no client cert received"}, | ||
332 | {ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED),"no compression specified"}, | ||
333 | {ERR_REASON(SSL_R_NO_METHOD_SPECIFIED) ,"no method specified"}, | ||
334 | {ERR_REASON(SSL_R_NO_PRIVATEKEY) ,"no privatekey"}, | ||
335 | {ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED),"no private key assigned"}, | ||
336 | {ERR_REASON(SSL_R_NO_PROTOCOLS_AVAILABLE),"no protocols available"}, | ||
337 | {ERR_REASON(SSL_R_NO_PUBLICKEY) ,"no publickey"}, | ||
338 | {ERR_REASON(SSL_R_NO_SHARED_CIPHER) ,"no shared cipher"}, | ||
339 | {ERR_REASON(SSL_R_NO_VERIFY_CALLBACK) ,"no verify callback"}, | ||
340 | {ERR_REASON(SSL_R_NULL_SSL_CTX) ,"null ssl ctx"}, | ||
341 | {ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED),"null ssl method passed"}, | ||
342 | {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED),"old session cipher not returned"}, | ||
343 | {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE),"only tls allowed in fips mode"}, | ||
344 | {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG),"packet length too long"}, | ||
345 | {ERR_REASON(SSL_R_PATH_TOO_LONG) ,"path too long"}, | ||
346 | {ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE),"peer did not return a certificate"}, | ||
347 | {ERR_REASON(SSL_R_PEER_ERROR) ,"peer error"}, | ||
348 | {ERR_REASON(SSL_R_PEER_ERROR_CERTIFICATE),"peer error certificate"}, | ||
349 | {ERR_REASON(SSL_R_PEER_ERROR_NO_CERTIFICATE),"peer error no certificate"}, | ||
350 | {ERR_REASON(SSL_R_PEER_ERROR_NO_CIPHER) ,"peer error no cipher"}, | ||
351 | {ERR_REASON(SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE),"peer error unsupported certificate type"}, | ||
352 | {ERR_REASON(SSL_R_PRE_MAC_LENGTH_TOO_LONG),"pre mac length too long"}, | ||
353 | {ERR_REASON(SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS),"problems mapping cipher functions"}, | ||
354 | {ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN) ,"protocol is shutdown"}, | ||
355 | {ERR_REASON(SSL_R_PUBLIC_KEY_ENCRYPT_ERROR),"public key encrypt error"}, | ||
356 | {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) ,"public key is not rsa"}, | ||
357 | {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) ,"public key not rsa"}, | ||
358 | {ERR_REASON(SSL_R_READ_BIO_NOT_SET) ,"read bio not set"}, | ||
359 | {ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE),"read wrong packet type"}, | ||
360 | {ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH),"record length mismatch"}, | ||
361 | {ERR_REASON(SSL_R_RECORD_TOO_LARGE) ,"record too large"}, | ||
362 | {ERR_REASON(SSL_R_RECORD_TOO_SMALL) ,"record too small"}, | ||
363 | {ERR_REASON(SSL_R_REQUIRED_CIPHER_MISSING),"required cipher missing"}, | ||
364 | {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO),"reuse cert length not zero"}, | ||
365 | {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO),"reuse cert type not zero"}, | ||
366 | {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO),"reuse cipher list not zero"}, | ||
367 | {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED),"session id context uninitialized"}, | ||
368 | {ERR_REASON(SSL_R_SHORT_READ) ,"short read"}, | ||
369 | {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE),"signature for non signing certificate"}, | ||
370 | {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE),"ssl23 doing session id reuse"}, | ||
371 | {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG),"ssl2 connection id too long"}, | ||
372 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG),"ssl3 session id too long"}, | ||
373 | {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT),"ssl3 session id too short"}, | ||
374 | {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE),"sslv3 alert bad certificate"}, | ||
375 | {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_RECORD_MAC),"sslv3 alert bad record mac"}, | ||
376 | {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED),"sslv3 alert certificate expired"}, | ||
377 | {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED),"sslv3 alert certificate revoked"}, | ||
378 | {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN),"sslv3 alert certificate unknown"}, | ||
379 | {ERR_REASON(SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE),"sslv3 alert decompression failure"}, | ||
380 | {ERR_REASON(SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE),"sslv3 alert handshake failure"}, | ||
381 | {ERR_REASON(SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER),"sslv3 alert illegal parameter"}, | ||
382 | {ERR_REASON(SSL_R_SSLV3_ALERT_NO_CERTIFICATE),"sslv3 alert no certificate"}, | ||
383 | {ERR_REASON(SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE),"sslv3 alert unexpected message"}, | ||
384 | {ERR_REASON(SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE),"sslv3 alert unsupported certificate"}, | ||
385 | {ERR_REASON(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION),"ssl ctx has no default ssl version"}, | ||
386 | {ERR_REASON(SSL_R_SSL_HANDSHAKE_FAILURE) ,"ssl handshake failure"}, | ||
387 | {ERR_REASON(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS),"ssl library has no ciphers"}, | ||
388 | {ERR_REASON(SSL_R_SSL_SESSION_ID_CALLBACK_FAILED),"ssl session id callback failed"}, | ||
389 | {ERR_REASON(SSL_R_SSL_SESSION_ID_CONFLICT),"ssl session id conflict"}, | ||
390 | {ERR_REASON(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG),"ssl session id context too long"}, | ||
391 | {ERR_REASON(SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH),"ssl session id has bad length"}, | ||
392 | {ERR_REASON(SSL_R_SSL_SESSION_ID_IS_DIFFERENT),"ssl session id is different"}, | ||
393 | {ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED),"tlsv1 alert access denied"}, | ||
394 | {ERR_REASON(SSL_R_TLSV1_ALERT_DECODE_ERROR),"tlsv1 alert decode error"}, | ||
395 | {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED),"tlsv1 alert decryption failed"}, | ||
396 | {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPT_ERROR),"tlsv1 alert decrypt error"}, | ||
397 | {ERR_REASON(SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION),"tlsv1 alert export restriction"}, | ||
398 | {ERR_REASON(SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY),"tlsv1 alert insufficient security"}, | ||
399 | {ERR_REASON(SSL_R_TLSV1_ALERT_INTERNAL_ERROR),"tlsv1 alert internal error"}, | ||
400 | {ERR_REASON(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION),"tlsv1 alert no renegotiation"}, | ||
401 | {ERR_REASON(SSL_R_TLSV1_ALERT_PROTOCOL_VERSION),"tlsv1 alert protocol version"}, | ||
402 | {ERR_REASON(SSL_R_TLSV1_ALERT_RECORD_OVERFLOW),"tlsv1 alert record overflow"}, | ||
403 | {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA),"tlsv1 alert unknown ca"}, | ||
404 | {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED),"tlsv1 alert user cancelled"}, | ||
405 | {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER),"tls client cert req with anon cipher"}, | ||
406 | {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST),"tls peer did not respond with certificate list"}, | ||
407 | {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG),"tls rsa encrypted value length is wrong"}, | ||
408 | {ERR_REASON(SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER),"tried to use unsupported cipher"}, | ||
409 | {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS),"unable to decode dh certs"}, | ||
410 | {ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY),"unable to extract public key"}, | ||
411 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS),"unable to find dh parameters"}, | ||
412 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS),"unable to find public key parameters"}, | ||
413 | {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD),"unable to find ssl method"}, | ||
414 | {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES),"unable to load ssl2 md5 routines"}, | ||
415 | {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES),"unable to load ssl3 md5 routines"}, | ||
416 | {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES),"unable to load ssl3 sha1 routines"}, | ||
417 | {ERR_REASON(SSL_R_UNEXPECTED_MESSAGE) ,"unexpected message"}, | ||
418 | {ERR_REASON(SSL_R_UNEXPECTED_RECORD) ,"unexpected record"}, | ||
419 | {ERR_REASON(SSL_R_UNINITIALIZED) ,"uninitialized"}, | ||
420 | {ERR_REASON(SSL_R_UNKNOWN_ALERT_TYPE) ,"unknown alert type"}, | ||
421 | {ERR_REASON(SSL_R_UNKNOWN_CERTIFICATE_TYPE),"unknown certificate type"}, | ||
422 | {ERR_REASON(SSL_R_UNKNOWN_CIPHER_RETURNED),"unknown cipher returned"}, | ||
423 | {ERR_REASON(SSL_R_UNKNOWN_CIPHER_TYPE) ,"unknown cipher type"}, | ||
424 | {ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE),"unknown key exchange type"}, | ||
425 | {ERR_REASON(SSL_R_UNKNOWN_PKEY_TYPE) ,"unknown pkey type"}, | ||
426 | {ERR_REASON(SSL_R_UNKNOWN_PROTOCOL) ,"unknown protocol"}, | ||
427 | {ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE),"unknown remote error type"}, | ||
428 | {ERR_REASON(SSL_R_UNKNOWN_SSL_VERSION) ,"unknown ssl version"}, | ||
429 | {ERR_REASON(SSL_R_UNKNOWN_STATE) ,"unknown state"}, | ||
430 | {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, | ||
431 | {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM),"unsupported compression algorithm"}, | ||
432 | {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) ,"unsupported protocol"}, | ||
433 | {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION),"unsupported ssl version"}, | ||
434 | {ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) ,"write bio not set"}, | ||
435 | {ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) ,"wrong cipher returned"}, | ||
436 | {ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) ,"wrong message type"}, | ||
437 | {ERR_REASON(SSL_R_WRONG_NUMBER_OF_KEY_BITS),"wrong number of key bits"}, | ||
438 | {ERR_REASON(SSL_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"}, | ||
439 | {ERR_REASON(SSL_R_WRONG_SIGNATURE_SIZE) ,"wrong signature size"}, | ||
440 | {ERR_REASON(SSL_R_WRONG_SSL_VERSION) ,"wrong ssl version"}, | ||
441 | {ERR_REASON(SSL_R_WRONG_VERSION_NUMBER) ,"wrong version number"}, | ||
442 | {ERR_REASON(SSL_R_X509_LIB) ,"x509 lib"}, | ||
443 | {ERR_REASON(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS),"x509 verification setup problems"}, | ||
444 | {0,NULL} | ||
445 | }; | ||
446 | |||
447 | #endif | ||
448 | |||
449 | void ERR_load_SSL_strings(void) | ||
450 | { | ||
451 | static int init=1; | ||
452 | |||
453 | if (init) | ||
454 | { | ||
455 | init=0; | ||
456 | #ifndef OPENSSL_NO_ERR | ||
457 | ERR_load_strings(0,SSL_str_functs); | ||
458 | ERR_load_strings(0,SSL_str_reasons); | ||
459 | #endif | ||
460 | |||
461 | } | ||
462 | } | ||
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c deleted file mode 100644 index ea95a5f983..0000000000 --- a/src/lib/libssl/ssl_err2.c +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | /* ssl/ssl_err2.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/err.h> | ||
61 | #include <openssl/ssl.h> | ||
62 | |||
63 | void SSL_load_error_strings(void) | ||
64 | { | ||
65 | #ifndef OPENSSL_NO_ERR | ||
66 | ERR_load_crypto_strings(); | ||
67 | ERR_load_SSL_strings(); | ||
68 | #endif | ||
69 | } | ||
70 | |||
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c deleted file mode 100644 index 0f4b7a475b..0000000000 --- a/src/lib/libssl/ssl_lib.c +++ /dev/null | |||
@@ -1,2355 +0,0 @@ | |||
1 | /*! \file ssl/ssl_lib.c | ||
2 | * \brief Version independent SSL functions. | ||
3 | */ | ||
4 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * This package is an SSL implementation written | ||
8 | * by Eric Young (eay@cryptsoft.com). | ||
9 | * The implementation was written so as to conform with Netscapes SSL. | ||
10 | * | ||
11 | * This library is free for commercial and non-commercial use as long as | ||
12 | * the following conditions are aheared to. The following conditions | ||
13 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
14 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
15 | * included with this distribution is covered by the same copyright terms | ||
16 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
17 | * | ||
18 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
19 | * the code are not to be removed. | ||
20 | * If this package is used in a product, Eric Young should be given attribution | ||
21 | * as the author of the parts of the library used. | ||
22 | * This can be in the form of a textual message at program startup or | ||
23 | * in documentation (online or textual) provided with the package. | ||
24 | * | ||
25 | * Redistribution and use in source and binary forms, with or without | ||
26 | * modification, are permitted provided that the following conditions | ||
27 | * are met: | ||
28 | * 1. Redistributions of source code must retain the copyright | ||
29 | * notice, this list of conditions and the following disclaimer. | ||
30 | * 2. Redistributions in binary form must reproduce the above copyright | ||
31 | * notice, this list of conditions and the following disclaimer in the | ||
32 | * documentation and/or other materials provided with the distribution. | ||
33 | * 3. All advertising materials mentioning features or use of this software | ||
34 | * must display the following acknowledgement: | ||
35 | * "This product includes cryptographic software written by | ||
36 | * Eric Young (eay@cryptsoft.com)" | ||
37 | * The word 'cryptographic' can be left out if the rouines from the library | ||
38 | * being used are not cryptographic related :-). | ||
39 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
40 | * the apps directory (application code) you must include an acknowledgement: | ||
41 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
42 | * | ||
43 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
44 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
46 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
49 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
50 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
51 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
52 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
53 | * SUCH DAMAGE. | ||
54 | * | ||
55 | * The licence and distribution terms for any publically available version or | ||
56 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
57 | * copied and put under another distribution licence | ||
58 | * [including the GNU Public Licence.] | ||
59 | */ | ||
60 | /* ==================================================================== | ||
61 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
62 | * | ||
63 | * Redistribution and use in source and binary forms, with or without | ||
64 | * modification, are permitted provided that the following conditions | ||
65 | * are met: | ||
66 | * | ||
67 | * 1. Redistributions of source code must retain the above copyright | ||
68 | * notice, this list of conditions and the following disclaimer. | ||
69 | * | ||
70 | * 2. Redistributions in binary form must reproduce the above copyright | ||
71 | * notice, this list of conditions and the following disclaimer in | ||
72 | * the documentation and/or other materials provided with the | ||
73 | * distribution. | ||
74 | * | ||
75 | * 3. All advertising materials mentioning features or use of this | ||
76 | * software must display the following acknowledgment: | ||
77 | * "This product includes software developed by the OpenSSL Project | ||
78 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
79 | * | ||
80 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
81 | * endorse or promote products derived from this software without | ||
82 | * prior written permission. For written permission, please contact | ||
83 | * openssl-core@openssl.org. | ||
84 | * | ||
85 | * 5. Products derived from this software may not be called "OpenSSL" | ||
86 | * nor may "OpenSSL" appear in their names without prior written | ||
87 | * permission of the OpenSSL Project. | ||
88 | * | ||
89 | * 6. Redistributions of any form whatsoever must retain the following | ||
90 | * acknowledgment: | ||
91 | * "This product includes software developed by the OpenSSL Project | ||
92 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
93 | * | ||
94 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
95 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
96 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
97 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
98 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
99 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
100 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
101 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
102 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
103 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
104 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
105 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
106 | * ==================================================================== | ||
107 | * | ||
108 | * This product includes cryptographic software written by Eric Young | ||
109 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
110 | * Hudson (tjh@cryptsoft.com). | ||
111 | * | ||
112 | */ | ||
113 | |||
114 | |||
115 | #ifdef REF_CHECK | ||
116 | # include <assert.h> | ||
117 | #endif | ||
118 | #include <stdio.h> | ||
119 | #include "ssl_locl.h" | ||
120 | #include "kssl_lcl.h" | ||
121 | #include <openssl/objects.h> | ||
122 | #include <openssl/lhash.h> | ||
123 | #include <openssl/x509v3.h> | ||
124 | #include <openssl/fips.h> | ||
125 | |||
126 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; | ||
127 | |||
128 | SSL3_ENC_METHOD ssl3_undef_enc_method={ | ||
129 | /* evil casts, but these functions are only called if there's a library bug */ | ||
130 | (int (*)(SSL *,int))ssl_undefined_function, | ||
131 | (int (*)(SSL *, unsigned char *, int))ssl_undefined_function, | ||
132 | ssl_undefined_function, | ||
133 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | ||
134 | (int (*)(SSL*, int))ssl_undefined_function, | ||
135 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function | ||
136 | }; | ||
137 | |||
138 | int SSL_clear(SSL *s) | ||
139 | { | ||
140 | |||
141 | if (s->method == NULL) | ||
142 | { | ||
143 | SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED); | ||
144 | return(0); | ||
145 | } | ||
146 | |||
147 | if (ssl_clear_bad_session(s)) | ||
148 | { | ||
149 | SSL_SESSION_free(s->session); | ||
150 | s->session=NULL; | ||
151 | } | ||
152 | |||
153 | s->error=0; | ||
154 | s->hit=0; | ||
155 | s->shutdown=0; | ||
156 | |||
157 | #if 0 /* Disabled since version 1.10 of this file (early return not | ||
158 | * needed because SSL_clear is not called when doing renegotiation) */ | ||
159 | /* This is set if we are doing dynamic renegotiation so keep | ||
160 | * the old cipher. It is sort of a SSL_clear_lite :-) */ | ||
161 | if (s->new_session) return(1); | ||
162 | #else | ||
163 | if (s->new_session) | ||
164 | { | ||
165 | SSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR); | ||
166 | return 0; | ||
167 | } | ||
168 | #endif | ||
169 | |||
170 | s->type=0; | ||
171 | |||
172 | s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT); | ||
173 | |||
174 | s->version=s->method->version; | ||
175 | s->client_version=s->version; | ||
176 | s->rwstate=SSL_NOTHING; | ||
177 | s->rstate=SSL_ST_READ_HEADER; | ||
178 | #if 0 | ||
179 | s->read_ahead=s->ctx->read_ahead; | ||
180 | #endif | ||
181 | |||
182 | if (s->init_buf != NULL) | ||
183 | { | ||
184 | BUF_MEM_free(s->init_buf); | ||
185 | s->init_buf=NULL; | ||
186 | } | ||
187 | |||
188 | ssl_clear_cipher_ctx(s); | ||
189 | |||
190 | s->first_packet=0; | ||
191 | |||
192 | #if 1 | ||
193 | /* Check to see if we were changed into a different method, if | ||
194 | * so, revert back if we are not doing session-id reuse. */ | ||
195 | if (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method)) | ||
196 | { | ||
197 | s->method->ssl_free(s); | ||
198 | s->method=s->ctx->method; | ||
199 | if (!s->method->ssl_new(s)) | ||
200 | return(0); | ||
201 | } | ||
202 | else | ||
203 | #endif | ||
204 | s->method->ssl_clear(s); | ||
205 | return(1); | ||
206 | } | ||
207 | |||
208 | /** Used to change an SSL_CTXs default SSL method type */ | ||
209 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth) | ||
210 | { | ||
211 | STACK_OF(SSL_CIPHER) *sk; | ||
212 | |||
213 | ctx->method=meth; | ||
214 | |||
215 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | ||
216 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); | ||
217 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) | ||
218 | { | ||
219 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | ||
220 | return(0); | ||
221 | } | ||
222 | return(1); | ||
223 | } | ||
224 | |||
225 | SSL *SSL_new(SSL_CTX *ctx) | ||
226 | { | ||
227 | SSL *s; | ||
228 | |||
229 | if (ctx == NULL) | ||
230 | { | ||
231 | SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX); | ||
232 | return(NULL); | ||
233 | } | ||
234 | if (ctx->method == NULL) | ||
235 | { | ||
236 | SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION); | ||
237 | return(NULL); | ||
238 | } | ||
239 | |||
240 | s=(SSL *)OPENSSL_malloc(sizeof(SSL)); | ||
241 | if (s == NULL) goto err; | ||
242 | memset(s,0,sizeof(SSL)); | ||
243 | |||
244 | #ifndef OPENSSL_NO_KRB5 | ||
245 | s->kssl_ctx = kssl_ctx_new(); | ||
246 | #endif /* OPENSSL_NO_KRB5 */ | ||
247 | |||
248 | s->options=ctx->options; | ||
249 | s->mode=ctx->mode; | ||
250 | s->max_cert_list=ctx->max_cert_list; | ||
251 | |||
252 | if (ctx->cert != NULL) | ||
253 | { | ||
254 | /* Earlier library versions used to copy the pointer to | ||
255 | * the CERT, not its contents; only when setting new | ||
256 | * parameters for the per-SSL copy, ssl_cert_new would be | ||
257 | * called (and the direct reference to the per-SSL_CTX | ||
258 | * settings would be lost, but those still were indirectly | ||
259 | * accessed for various purposes, and for that reason they | ||
260 | * used to be known as s->ctx->default_cert). | ||
261 | * Now we don't look at the SSL_CTX's CERT after having | ||
262 | * duplicated it once. */ | ||
263 | |||
264 | s->cert = ssl_cert_dup(ctx->cert); | ||
265 | if (s->cert == NULL) | ||
266 | goto err; | ||
267 | } | ||
268 | else | ||
269 | s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */ | ||
270 | |||
271 | s->read_ahead=ctx->read_ahead; | ||
272 | s->msg_callback=ctx->msg_callback; | ||
273 | s->msg_callback_arg=ctx->msg_callback_arg; | ||
274 | s->verify_mode=ctx->verify_mode; | ||
275 | s->verify_depth=ctx->verify_depth; | ||
276 | s->sid_ctx_length=ctx->sid_ctx_length; | ||
277 | OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx); | ||
278 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); | ||
279 | s->verify_callback=ctx->default_verify_callback; | ||
280 | s->generate_session_id=ctx->generate_session_id; | ||
281 | s->purpose = ctx->purpose; | ||
282 | s->trust = ctx->trust; | ||
283 | s->quiet_shutdown=ctx->quiet_shutdown; | ||
284 | |||
285 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | ||
286 | s->ctx=ctx; | ||
287 | |||
288 | s->verify_result=X509_V_OK; | ||
289 | |||
290 | s->method=ctx->method; | ||
291 | |||
292 | if (!s->method->ssl_new(s)) | ||
293 | goto err; | ||
294 | |||
295 | s->references=1; | ||
296 | s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1; | ||
297 | |||
298 | SSL_clear(s); | ||
299 | |||
300 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); | ||
301 | |||
302 | return(s); | ||
303 | err: | ||
304 | if (s != NULL) | ||
305 | { | ||
306 | if (s->cert != NULL) | ||
307 | ssl_cert_free(s->cert); | ||
308 | if (s->ctx != NULL) | ||
309 | SSL_CTX_free(s->ctx); /* decrement reference count */ | ||
310 | OPENSSL_free(s); | ||
311 | } | ||
312 | SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | ||
313 | return(NULL); | ||
314 | } | ||
315 | |||
316 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, | ||
317 | unsigned int sid_ctx_len) | ||
318 | { | ||
319 | if(sid_ctx_len > sizeof ctx->sid_ctx) | ||
320 | { | ||
321 | SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
322 | return 0; | ||
323 | } | ||
324 | ctx->sid_ctx_length=sid_ctx_len; | ||
325 | memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len); | ||
326 | |||
327 | return 1; | ||
328 | } | ||
329 | |||
330 | int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, | ||
331 | unsigned int sid_ctx_len) | ||
332 | { | ||
333 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | ||
334 | { | ||
335 | SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
336 | return 0; | ||
337 | } | ||
338 | ssl->sid_ctx_length=sid_ctx_len; | ||
339 | memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len); | ||
340 | |||
341 | return 1; | ||
342 | } | ||
343 | |||
344 | int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb) | ||
345 | { | ||
346 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
347 | ctx->generate_session_id = cb; | ||
348 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
349 | return 1; | ||
350 | } | ||
351 | |||
352 | int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb) | ||
353 | { | ||
354 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
355 | ssl->generate_session_id = cb; | ||
356 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
357 | return 1; | ||
358 | } | ||
359 | |||
360 | int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | ||
361 | unsigned int id_len) | ||
362 | { | ||
363 | /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how | ||
364 | * we can "construct" a session to give us the desired check - ie. to | ||
365 | * find if there's a session in the hash table that would conflict with | ||
366 | * any new session built out of this id/id_len and the ssl_version in | ||
367 | * use by this SSL. */ | ||
368 | SSL_SESSION r, *p; | ||
369 | |||
370 | if(id_len > sizeof r.session_id) | ||
371 | return 0; | ||
372 | |||
373 | r.ssl_version = ssl->version; | ||
374 | r.session_id_length = id_len; | ||
375 | memcpy(r.session_id, id, id_len); | ||
376 | /* NB: SSLv2 always uses a fixed 16-byte session ID, so even if a | ||
377 | * callback is calling us to check the uniqueness of a shorter ID, it | ||
378 | * must be compared as a padded-out ID because that is what it will be | ||
379 | * converted to when the callback has finished choosing it. */ | ||
380 | if((r.ssl_version == SSL2_VERSION) && | ||
381 | (id_len < SSL2_SSL_SESSION_ID_LENGTH)) | ||
382 | { | ||
383 | memset(r.session_id + id_len, 0, | ||
384 | SSL2_SSL_SESSION_ID_LENGTH - id_len); | ||
385 | r.session_id_length = SSL2_SSL_SESSION_ID_LENGTH; | ||
386 | } | ||
387 | |||
388 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
389 | p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r); | ||
390 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
391 | return (p != NULL); | ||
392 | } | ||
393 | |||
394 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) | ||
395 | { | ||
396 | return X509_PURPOSE_set(&s->purpose, purpose); | ||
397 | } | ||
398 | |||
399 | int SSL_set_purpose(SSL *s, int purpose) | ||
400 | { | ||
401 | return X509_PURPOSE_set(&s->purpose, purpose); | ||
402 | } | ||
403 | |||
404 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) | ||
405 | { | ||
406 | return X509_TRUST_set(&s->trust, trust); | ||
407 | } | ||
408 | |||
409 | int SSL_set_trust(SSL *s, int trust) | ||
410 | { | ||
411 | return X509_TRUST_set(&s->trust, trust); | ||
412 | } | ||
413 | |||
414 | void SSL_free(SSL *s) | ||
415 | { | ||
416 | int i; | ||
417 | |||
418 | if(s == NULL) | ||
419 | return; | ||
420 | |||
421 | i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL); | ||
422 | #ifdef REF_PRINT | ||
423 | REF_PRINT("SSL",s); | ||
424 | #endif | ||
425 | if (i > 0) return; | ||
426 | #ifdef REF_CHECK | ||
427 | if (i < 0) | ||
428 | { | ||
429 | fprintf(stderr,"SSL_free, bad reference count\n"); | ||
430 | abort(); /* ok */ | ||
431 | } | ||
432 | #endif | ||
433 | |||
434 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data); | ||
435 | |||
436 | if (s->bbio != NULL) | ||
437 | { | ||
438 | /* If the buffering BIO is in place, pop it off */ | ||
439 | if (s->bbio == s->wbio) | ||
440 | { | ||
441 | s->wbio=BIO_pop(s->wbio); | ||
442 | } | ||
443 | BIO_free(s->bbio); | ||
444 | s->bbio=NULL; | ||
445 | } | ||
446 | if (s->rbio != NULL) | ||
447 | BIO_free_all(s->rbio); | ||
448 | if ((s->wbio != NULL) && (s->wbio != s->rbio)) | ||
449 | BIO_free_all(s->wbio); | ||
450 | |||
451 | if (s->init_buf != NULL) BUF_MEM_free(s->init_buf); | ||
452 | |||
453 | /* add extra stuff */ | ||
454 | if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list); | ||
455 | if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id); | ||
456 | |||
457 | /* Make the next call work :-) */ | ||
458 | if (s->session != NULL) | ||
459 | { | ||
460 | ssl_clear_bad_session(s); | ||
461 | SSL_SESSION_free(s->session); | ||
462 | } | ||
463 | |||
464 | ssl_clear_cipher_ctx(s); | ||
465 | |||
466 | if (s->cert != NULL) ssl_cert_free(s->cert); | ||
467 | /* Free up if allocated */ | ||
468 | |||
469 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
470 | |||
471 | if (s->client_CA != NULL) | ||
472 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); | ||
473 | |||
474 | if (s->method != NULL) s->method->ssl_free(s); | ||
475 | |||
476 | #ifndef OPENSSL_NO_KRB5 | ||
477 | if (s->kssl_ctx != NULL) | ||
478 | kssl_ctx_free(s->kssl_ctx); | ||
479 | #endif /* OPENSSL_NO_KRB5 */ | ||
480 | |||
481 | OPENSSL_free(s); | ||
482 | } | ||
483 | |||
484 | void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio) | ||
485 | { | ||
486 | /* If the output buffering BIO is still in place, remove it | ||
487 | */ | ||
488 | if (s->bbio != NULL) | ||
489 | { | ||
490 | if (s->wbio == s->bbio) | ||
491 | { | ||
492 | s->wbio=s->wbio->next_bio; | ||
493 | s->bbio->next_bio=NULL; | ||
494 | } | ||
495 | } | ||
496 | if ((s->rbio != NULL) && (s->rbio != rbio)) | ||
497 | BIO_free_all(s->rbio); | ||
498 | if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio)) | ||
499 | BIO_free_all(s->wbio); | ||
500 | s->rbio=rbio; | ||
501 | s->wbio=wbio; | ||
502 | } | ||
503 | |||
504 | BIO *SSL_get_rbio(const SSL *s) | ||
505 | { return(s->rbio); } | ||
506 | |||
507 | BIO *SSL_get_wbio(const SSL *s) | ||
508 | { return(s->wbio); } | ||
509 | |||
510 | int SSL_get_fd(const SSL *s) | ||
511 | { | ||
512 | return(SSL_get_rfd(s)); | ||
513 | } | ||
514 | |||
515 | int SSL_get_rfd(const SSL *s) | ||
516 | { | ||
517 | int ret= -1; | ||
518 | BIO *b,*r; | ||
519 | |||
520 | b=SSL_get_rbio(s); | ||
521 | r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR); | ||
522 | if (r != NULL) | ||
523 | BIO_get_fd(r,&ret); | ||
524 | return(ret); | ||
525 | } | ||
526 | |||
527 | int SSL_get_wfd(const SSL *s) | ||
528 | { | ||
529 | int ret= -1; | ||
530 | BIO *b,*r; | ||
531 | |||
532 | b=SSL_get_wbio(s); | ||
533 | r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR); | ||
534 | if (r != NULL) | ||
535 | BIO_get_fd(r,&ret); | ||
536 | return(ret); | ||
537 | } | ||
538 | |||
539 | #ifndef OPENSSL_NO_SOCK | ||
540 | int SSL_set_fd(SSL *s,int fd) | ||
541 | { | ||
542 | int ret=0; | ||
543 | BIO *bio=NULL; | ||
544 | |||
545 | bio=BIO_new(BIO_s_socket()); | ||
546 | |||
547 | if (bio == NULL) | ||
548 | { | ||
549 | SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB); | ||
550 | goto err; | ||
551 | } | ||
552 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
553 | SSL_set_bio(s,bio,bio); | ||
554 | ret=1; | ||
555 | err: | ||
556 | return(ret); | ||
557 | } | ||
558 | |||
559 | int SSL_set_wfd(SSL *s,int fd) | ||
560 | { | ||
561 | int ret=0; | ||
562 | BIO *bio=NULL; | ||
563 | |||
564 | if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET) | ||
565 | || ((int)BIO_get_fd(s->rbio,NULL) != fd)) | ||
566 | { | ||
567 | bio=BIO_new(BIO_s_socket()); | ||
568 | |||
569 | if (bio == NULL) | ||
570 | { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; } | ||
571 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
572 | SSL_set_bio(s,SSL_get_rbio(s),bio); | ||
573 | } | ||
574 | else | ||
575 | SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s)); | ||
576 | ret=1; | ||
577 | err: | ||
578 | return(ret); | ||
579 | } | ||
580 | |||
581 | int SSL_set_rfd(SSL *s,int fd) | ||
582 | { | ||
583 | int ret=0; | ||
584 | BIO *bio=NULL; | ||
585 | |||
586 | if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET) | ||
587 | || ((int)BIO_get_fd(s->wbio,NULL) != fd)) | ||
588 | { | ||
589 | bio=BIO_new(BIO_s_socket()); | ||
590 | |||
591 | if (bio == NULL) | ||
592 | { | ||
593 | SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB); | ||
594 | goto err; | ||
595 | } | ||
596 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
597 | SSL_set_bio(s,bio,SSL_get_wbio(s)); | ||
598 | } | ||
599 | else | ||
600 | SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s)); | ||
601 | ret=1; | ||
602 | err: | ||
603 | return(ret); | ||
604 | } | ||
605 | #endif | ||
606 | |||
607 | |||
608 | /* return length of latest Finished message we sent, copy to 'buf' */ | ||
609 | size_t SSL_get_finished(const SSL *s, void *buf, size_t count) | ||
610 | { | ||
611 | size_t ret = 0; | ||
612 | |||
613 | if (s->s3 != NULL) | ||
614 | { | ||
615 | ret = s->s3->tmp.finish_md_len; | ||
616 | if (count > ret) | ||
617 | count = ret; | ||
618 | memcpy(buf, s->s3->tmp.finish_md, count); | ||
619 | } | ||
620 | return ret; | ||
621 | } | ||
622 | |||
623 | /* return length of latest Finished message we expected, copy to 'buf' */ | ||
624 | size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count) | ||
625 | { | ||
626 | size_t ret = 0; | ||
627 | |||
628 | if (s->s3 != NULL) | ||
629 | { | ||
630 | ret = s->s3->tmp.peer_finish_md_len; | ||
631 | if (count > ret) | ||
632 | count = ret; | ||
633 | memcpy(buf, s->s3->tmp.peer_finish_md, count); | ||
634 | } | ||
635 | return ret; | ||
636 | } | ||
637 | |||
638 | |||
639 | int SSL_get_verify_mode(const SSL *s) | ||
640 | { | ||
641 | return(s->verify_mode); | ||
642 | } | ||
643 | |||
644 | int SSL_get_verify_depth(const SSL *s) | ||
645 | { | ||
646 | return(s->verify_depth); | ||
647 | } | ||
648 | |||
649 | int (*SSL_get_verify_callback(const SSL *s))(int,X509_STORE_CTX *) | ||
650 | { | ||
651 | return(s->verify_callback); | ||
652 | } | ||
653 | |||
654 | int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) | ||
655 | { | ||
656 | return(ctx->verify_mode); | ||
657 | } | ||
658 | |||
659 | int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) | ||
660 | { | ||
661 | return(ctx->verify_depth); | ||
662 | } | ||
663 | |||
664 | int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int,X509_STORE_CTX *) | ||
665 | { | ||
666 | return(ctx->default_verify_callback); | ||
667 | } | ||
668 | |||
669 | void SSL_set_verify(SSL *s,int mode, | ||
670 | int (*callback)(int ok,X509_STORE_CTX *ctx)) | ||
671 | { | ||
672 | s->verify_mode=mode; | ||
673 | if (callback != NULL) | ||
674 | s->verify_callback=callback; | ||
675 | } | ||
676 | |||
677 | void SSL_set_verify_depth(SSL *s,int depth) | ||
678 | { | ||
679 | s->verify_depth=depth; | ||
680 | } | ||
681 | |||
682 | void SSL_set_read_ahead(SSL *s,int yes) | ||
683 | { | ||
684 | s->read_ahead=yes; | ||
685 | } | ||
686 | |||
687 | int SSL_get_read_ahead(const SSL *s) | ||
688 | { | ||
689 | return(s->read_ahead); | ||
690 | } | ||
691 | |||
692 | int SSL_pending(const SSL *s) | ||
693 | { | ||
694 | /* SSL_pending cannot work properly if read-ahead is enabled | ||
695 | * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)), | ||
696 | * and it is impossible to fix since SSL_pending cannot report | ||
697 | * errors that may be observed while scanning the new data. | ||
698 | * (Note that SSL_pending() is often used as a boolean value, | ||
699 | * so we'd better not return -1.) | ||
700 | */ | ||
701 | return(s->method->ssl_pending(s)); | ||
702 | } | ||
703 | |||
704 | X509 *SSL_get_peer_certificate(const SSL *s) | ||
705 | { | ||
706 | X509 *r; | ||
707 | |||
708 | if ((s == NULL) || (s->session == NULL)) | ||
709 | r=NULL; | ||
710 | else | ||
711 | r=s->session->peer; | ||
712 | |||
713 | if (r == NULL) return(r); | ||
714 | |||
715 | CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509); | ||
716 | |||
717 | return(r); | ||
718 | } | ||
719 | |||
720 | STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s) | ||
721 | { | ||
722 | STACK_OF(X509) *r; | ||
723 | |||
724 | if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL)) | ||
725 | r=NULL; | ||
726 | else | ||
727 | r=s->session->sess_cert->cert_chain; | ||
728 | |||
729 | /* If we are a client, cert_chain includes the peer's own | ||
730 | * certificate; if we are a server, it does not. */ | ||
731 | |||
732 | return(r); | ||
733 | } | ||
734 | |||
735 | /* Now in theory, since the calling process own 't' it should be safe to | ||
736 | * modify. We need to be able to read f without being hassled */ | ||
737 | void SSL_copy_session_id(SSL *t,const SSL *f) | ||
738 | { | ||
739 | CERT *tmp; | ||
740 | |||
741 | /* Do we need to to SSL locking? */ | ||
742 | SSL_set_session(t,SSL_get_session(f)); | ||
743 | |||
744 | /* what if we are setup as SSLv2 but want to talk SSLv3 or | ||
745 | * vice-versa */ | ||
746 | if (t->method != f->method) | ||
747 | { | ||
748 | t->method->ssl_free(t); /* cleanup current */ | ||
749 | t->method=f->method; /* change method */ | ||
750 | t->method->ssl_new(t); /* setup new */ | ||
751 | } | ||
752 | |||
753 | tmp=t->cert; | ||
754 | if (f->cert != NULL) | ||
755 | { | ||
756 | CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT); | ||
757 | t->cert=f->cert; | ||
758 | } | ||
759 | else | ||
760 | t->cert=NULL; | ||
761 | if (tmp != NULL) ssl_cert_free(tmp); | ||
762 | SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length); | ||
763 | } | ||
764 | |||
765 | /* Fix this so it checks all the valid key/cert options */ | ||
766 | int SSL_CTX_check_private_key(const SSL_CTX *ctx) | ||
767 | { | ||
768 | if ( (ctx == NULL) || | ||
769 | (ctx->cert == NULL) || | ||
770 | (ctx->cert->key->x509 == NULL)) | ||
771 | { | ||
772 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
773 | return(0); | ||
774 | } | ||
775 | if (ctx->cert->key->privatekey == NULL) | ||
776 | { | ||
777 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
778 | return(0); | ||
779 | } | ||
780 | return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey)); | ||
781 | } | ||
782 | |||
783 | /* Fix this function so that it takes an optional type parameter */ | ||
784 | int SSL_check_private_key(const SSL *ssl) | ||
785 | { | ||
786 | if (ssl == NULL) | ||
787 | { | ||
788 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER); | ||
789 | return(0); | ||
790 | } | ||
791 | if (ssl->cert == NULL) | ||
792 | { | ||
793 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
794 | return 0; | ||
795 | } | ||
796 | if (ssl->cert->key->x509 == NULL) | ||
797 | { | ||
798 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
799 | return(0); | ||
800 | } | ||
801 | if (ssl->cert->key->privatekey == NULL) | ||
802 | { | ||
803 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
804 | return(0); | ||
805 | } | ||
806 | return(X509_check_private_key(ssl->cert->key->x509, | ||
807 | ssl->cert->key->privatekey)); | ||
808 | } | ||
809 | |||
810 | int SSL_accept(SSL *s) | ||
811 | { | ||
812 | if (s->handshake_func == 0) | ||
813 | /* Not properly initialized yet */ | ||
814 | SSL_set_accept_state(s); | ||
815 | |||
816 | return(s->method->ssl_accept(s)); | ||
817 | } | ||
818 | |||
819 | int SSL_connect(SSL *s) | ||
820 | { | ||
821 | if (s->handshake_func == 0) | ||
822 | /* Not properly initialized yet */ | ||
823 | SSL_set_connect_state(s); | ||
824 | |||
825 | return(s->method->ssl_connect(s)); | ||
826 | } | ||
827 | |||
828 | long SSL_get_default_timeout(const SSL *s) | ||
829 | { | ||
830 | return(s->method->get_timeout()); | ||
831 | } | ||
832 | |||
833 | int SSL_read(SSL *s,void *buf,int num) | ||
834 | { | ||
835 | if (s->handshake_func == 0) | ||
836 | { | ||
837 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | ||
838 | return -1; | ||
839 | } | ||
840 | |||
841 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
842 | { | ||
843 | s->rwstate=SSL_NOTHING; | ||
844 | return(0); | ||
845 | } | ||
846 | return(s->method->ssl_read(s,buf,num)); | ||
847 | } | ||
848 | |||
849 | int SSL_peek(SSL *s,void *buf,int num) | ||
850 | { | ||
851 | if (s->handshake_func == 0) | ||
852 | { | ||
853 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | ||
854 | return -1; | ||
855 | } | ||
856 | |||
857 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
858 | { | ||
859 | return(0); | ||
860 | } | ||
861 | return(s->method->ssl_peek(s,buf,num)); | ||
862 | } | ||
863 | |||
864 | int SSL_write(SSL *s,const void *buf,int num) | ||
865 | { | ||
866 | if (s->handshake_func == 0) | ||
867 | { | ||
868 | SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED); | ||
869 | return -1; | ||
870 | } | ||
871 | |||
872 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
873 | { | ||
874 | s->rwstate=SSL_NOTHING; | ||
875 | SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN); | ||
876 | return(-1); | ||
877 | } | ||
878 | return(s->method->ssl_write(s,buf,num)); | ||
879 | } | ||
880 | |||
881 | int SSL_shutdown(SSL *s) | ||
882 | { | ||
883 | /* Note that this function behaves differently from what one might | ||
884 | * expect. Return values are 0 for no success (yet), | ||
885 | * 1 for success; but calling it once is usually not enough, | ||
886 | * even if blocking I/O is used (see ssl3_shutdown). | ||
887 | */ | ||
888 | |||
889 | if (s->handshake_func == 0) | ||
890 | { | ||
891 | SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED); | ||
892 | return -1; | ||
893 | } | ||
894 | |||
895 | if ((s != NULL) && !SSL_in_init(s)) | ||
896 | return(s->method->ssl_shutdown(s)); | ||
897 | else | ||
898 | return(1); | ||
899 | } | ||
900 | |||
901 | int SSL_renegotiate(SSL *s) | ||
902 | { | ||
903 | if (s->new_session == 0) | ||
904 | { | ||
905 | s->new_session=1; | ||
906 | } | ||
907 | return(s->method->ssl_renegotiate(s)); | ||
908 | } | ||
909 | |||
910 | int SSL_renegotiate_pending(SSL *s) | ||
911 | { | ||
912 | /* becomes true when negotiation is requested; | ||
913 | * false again once a handshake has finished */ | ||
914 | return (s->new_session != 0); | ||
915 | } | ||
916 | |||
917 | long SSL_ctrl(SSL *s,int cmd,long larg,void *parg) | ||
918 | { | ||
919 | long l; | ||
920 | |||
921 | switch (cmd) | ||
922 | { | ||
923 | case SSL_CTRL_GET_READ_AHEAD: | ||
924 | return(s->read_ahead); | ||
925 | case SSL_CTRL_SET_READ_AHEAD: | ||
926 | l=s->read_ahead; | ||
927 | s->read_ahead=larg; | ||
928 | return(l); | ||
929 | |||
930 | case SSL_CTRL_SET_MSG_CALLBACK_ARG: | ||
931 | s->msg_callback_arg = parg; | ||
932 | return 1; | ||
933 | |||
934 | case SSL_CTRL_OPTIONS: | ||
935 | return(s->options|=larg); | ||
936 | case SSL_CTRL_MODE: | ||
937 | return(s->mode|=larg); | ||
938 | case SSL_CTRL_GET_MAX_CERT_LIST: | ||
939 | return(s->max_cert_list); | ||
940 | case SSL_CTRL_SET_MAX_CERT_LIST: | ||
941 | l=s->max_cert_list; | ||
942 | s->max_cert_list=larg; | ||
943 | return(l); | ||
944 | default: | ||
945 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | ||
946 | } | ||
947 | } | ||
948 | |||
949 | long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)()) | ||
950 | { | ||
951 | switch(cmd) | ||
952 | { | ||
953 | case SSL_CTRL_SET_MSG_CALLBACK: | ||
954 | s->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp); | ||
955 | return 1; | ||
956 | |||
957 | default: | ||
958 | return(s->method->ssl_callback_ctrl(s,cmd,fp)); | ||
959 | } | ||
960 | } | ||
961 | |||
962 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx) | ||
963 | { | ||
964 | return ctx->sessions; | ||
965 | } | ||
966 | |||
967 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg) | ||
968 | { | ||
969 | long l; | ||
970 | |||
971 | switch (cmd) | ||
972 | { | ||
973 | case SSL_CTRL_GET_READ_AHEAD: | ||
974 | return(ctx->read_ahead); | ||
975 | case SSL_CTRL_SET_READ_AHEAD: | ||
976 | l=ctx->read_ahead; | ||
977 | ctx->read_ahead=larg; | ||
978 | return(l); | ||
979 | |||
980 | case SSL_CTRL_SET_MSG_CALLBACK_ARG: | ||
981 | ctx->msg_callback_arg = parg; | ||
982 | return 1; | ||
983 | |||
984 | case SSL_CTRL_GET_MAX_CERT_LIST: | ||
985 | return(ctx->max_cert_list); | ||
986 | case SSL_CTRL_SET_MAX_CERT_LIST: | ||
987 | l=ctx->max_cert_list; | ||
988 | ctx->max_cert_list=larg; | ||
989 | return(l); | ||
990 | |||
991 | case SSL_CTRL_SET_SESS_CACHE_SIZE: | ||
992 | l=ctx->session_cache_size; | ||
993 | ctx->session_cache_size=larg; | ||
994 | return(l); | ||
995 | case SSL_CTRL_GET_SESS_CACHE_SIZE: | ||
996 | return(ctx->session_cache_size); | ||
997 | case SSL_CTRL_SET_SESS_CACHE_MODE: | ||
998 | l=ctx->session_cache_mode; | ||
999 | ctx->session_cache_mode=larg; | ||
1000 | return(l); | ||
1001 | case SSL_CTRL_GET_SESS_CACHE_MODE: | ||
1002 | return(ctx->session_cache_mode); | ||
1003 | |||
1004 | case SSL_CTRL_SESS_NUMBER: | ||
1005 | return(ctx->sessions->num_items); | ||
1006 | case SSL_CTRL_SESS_CONNECT: | ||
1007 | return(ctx->stats.sess_connect); | ||
1008 | case SSL_CTRL_SESS_CONNECT_GOOD: | ||
1009 | return(ctx->stats.sess_connect_good); | ||
1010 | case SSL_CTRL_SESS_CONNECT_RENEGOTIATE: | ||
1011 | return(ctx->stats.sess_connect_renegotiate); | ||
1012 | case SSL_CTRL_SESS_ACCEPT: | ||
1013 | return(ctx->stats.sess_accept); | ||
1014 | case SSL_CTRL_SESS_ACCEPT_GOOD: | ||
1015 | return(ctx->stats.sess_accept_good); | ||
1016 | case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE: | ||
1017 | return(ctx->stats.sess_accept_renegotiate); | ||
1018 | case SSL_CTRL_SESS_HIT: | ||
1019 | return(ctx->stats.sess_hit); | ||
1020 | case SSL_CTRL_SESS_CB_HIT: | ||
1021 | return(ctx->stats.sess_cb_hit); | ||
1022 | case SSL_CTRL_SESS_MISSES: | ||
1023 | return(ctx->stats.sess_miss); | ||
1024 | case SSL_CTRL_SESS_TIMEOUTS: | ||
1025 | return(ctx->stats.sess_timeout); | ||
1026 | case SSL_CTRL_SESS_CACHE_FULL: | ||
1027 | return(ctx->stats.sess_cache_full); | ||
1028 | case SSL_CTRL_OPTIONS: | ||
1029 | return(ctx->options|=larg); | ||
1030 | case SSL_CTRL_MODE: | ||
1031 | return(ctx->mode|=larg); | ||
1032 | default: | ||
1033 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | ||
1034 | } | ||
1035 | } | ||
1036 | |||
1037 | long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | ||
1038 | { | ||
1039 | switch(cmd) | ||
1040 | { | ||
1041 | case SSL_CTRL_SET_MSG_CALLBACK: | ||
1042 | ctx->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp); | ||
1043 | return 1; | ||
1044 | |||
1045 | default: | ||
1046 | return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp)); | ||
1047 | } | ||
1048 | } | ||
1049 | |||
1050 | int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b) | ||
1051 | { | ||
1052 | long l; | ||
1053 | |||
1054 | l=a->id-b->id; | ||
1055 | if (l == 0L) | ||
1056 | return(0); | ||
1057 | else | ||
1058 | return((l > 0)?1:-1); | ||
1059 | } | ||
1060 | |||
1061 | int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, | ||
1062 | const SSL_CIPHER * const *bp) | ||
1063 | { | ||
1064 | long l; | ||
1065 | |||
1066 | l=(*ap)->id-(*bp)->id; | ||
1067 | if (l == 0L) | ||
1068 | return(0); | ||
1069 | else | ||
1070 | return((l > 0)?1:-1); | ||
1071 | } | ||
1072 | |||
1073 | /** return a STACK of the ciphers available for the SSL and in order of | ||
1074 | * preference */ | ||
1075 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s) | ||
1076 | { | ||
1077 | if (s != NULL) | ||
1078 | { | ||
1079 | if (s->cipher_list != NULL) | ||
1080 | { | ||
1081 | return(s->cipher_list); | ||
1082 | } | ||
1083 | else if ((s->ctx != NULL) && | ||
1084 | (s->ctx->cipher_list != NULL)) | ||
1085 | { | ||
1086 | return(s->ctx->cipher_list); | ||
1087 | } | ||
1088 | } | ||
1089 | return(NULL); | ||
1090 | } | ||
1091 | |||
1092 | /** return a STACK of the ciphers available for the SSL and in order of | ||
1093 | * algorithm id */ | ||
1094 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) | ||
1095 | { | ||
1096 | if (s != NULL) | ||
1097 | { | ||
1098 | if (s->cipher_list_by_id != NULL) | ||
1099 | { | ||
1100 | return(s->cipher_list_by_id); | ||
1101 | } | ||
1102 | else if ((s->ctx != NULL) && | ||
1103 | (s->ctx->cipher_list_by_id != NULL)) | ||
1104 | { | ||
1105 | return(s->ctx->cipher_list_by_id); | ||
1106 | } | ||
1107 | } | ||
1108 | return(NULL); | ||
1109 | } | ||
1110 | |||
1111 | /** The old interface to get the same thing as SSL_get_ciphers() */ | ||
1112 | const char *SSL_get_cipher_list(const SSL *s,int n) | ||
1113 | { | ||
1114 | SSL_CIPHER *c; | ||
1115 | STACK_OF(SSL_CIPHER) *sk; | ||
1116 | |||
1117 | if (s == NULL) return(NULL); | ||
1118 | sk=SSL_get_ciphers(s); | ||
1119 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n)) | ||
1120 | return(NULL); | ||
1121 | c=sk_SSL_CIPHER_value(sk,n); | ||
1122 | if (c == NULL) return(NULL); | ||
1123 | return(c->name); | ||
1124 | } | ||
1125 | |||
1126 | /** specify the ciphers to be used by default by the SSL_CTX */ | ||
1127 | int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) | ||
1128 | { | ||
1129 | STACK_OF(SSL_CIPHER) *sk; | ||
1130 | |||
1131 | sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list, | ||
1132 | &ctx->cipher_list_by_id,str); | ||
1133 | /* ssl_create_cipher_list may return an empty stack if it | ||
1134 | * was unable to find a cipher matching the given rule string | ||
1135 | * (for example if the rule string specifies a cipher which | ||
1136 | * has been disabled). This is not an error as far as | ||
1137 | * ssl_create_cipher_list is concerned, and hence | ||
1138 | * ctx->cipher_list and ctx->cipher_list_by_id has been | ||
1139 | * updated. */ | ||
1140 | if (sk == NULL) | ||
1141 | return 0; | ||
1142 | else if (sk_SSL_CIPHER_num(sk) == 0) | ||
1143 | { | ||
1144 | SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH); | ||
1145 | return 0; | ||
1146 | } | ||
1147 | return 1; | ||
1148 | } | ||
1149 | |||
1150 | /** specify the ciphers to be used by the SSL */ | ||
1151 | int SSL_set_cipher_list(SSL *s,const char *str) | ||
1152 | { | ||
1153 | STACK_OF(SSL_CIPHER) *sk; | ||
1154 | |||
1155 | sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list, | ||
1156 | &s->cipher_list_by_id,str); | ||
1157 | /* see comment in SSL_CTX_set_cipher_list */ | ||
1158 | if (sk == NULL) | ||
1159 | return 0; | ||
1160 | else if (sk_SSL_CIPHER_num(sk) == 0) | ||
1161 | { | ||
1162 | SSLerr(SSL_F_SSL_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH); | ||
1163 | return 0; | ||
1164 | } | ||
1165 | return 1; | ||
1166 | } | ||
1167 | |||
1168 | /* works well for SSLv2, not so good for SSLv3 */ | ||
1169 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len) | ||
1170 | { | ||
1171 | char *end; | ||
1172 | STACK_OF(SSL_CIPHER) *sk; | ||
1173 | SSL_CIPHER *c; | ||
1174 | size_t curlen = 0; | ||
1175 | int i; | ||
1176 | |||
1177 | if ((s->session == NULL) || (s->session->ciphers == NULL) || | ||
1178 | (len < 2)) | ||
1179 | return(NULL); | ||
1180 | |||
1181 | sk=s->session->ciphers; | ||
1182 | buf[0] = '\0'; | ||
1183 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
1184 | { | ||
1185 | c=sk_SSL_CIPHER_value(sk,i); | ||
1186 | end = buf + curlen; | ||
1187 | if (strlcat(buf, c->name, len) >= len || | ||
1188 | (curlen = strlcat(buf, ":", len)) >= len) | ||
1189 | { | ||
1190 | /* remove truncated cipher from list */ | ||
1191 | *end = '\0'; | ||
1192 | break; | ||
1193 | } | ||
1194 | } | ||
1195 | /* remove trailing colon */ | ||
1196 | if ((end = strrchr(buf, ':')) != NULL) | ||
1197 | *end = '\0'; | ||
1198 | return(buf); | ||
1199 | } | ||
1200 | |||
1201 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | ||
1202 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)) | ||
1203 | { | ||
1204 | int i,j=0; | ||
1205 | SSL_CIPHER *c; | ||
1206 | unsigned char *q; | ||
1207 | #ifndef OPENSSL_NO_KRB5 | ||
1208 | int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx); | ||
1209 | #endif /* OPENSSL_NO_KRB5 */ | ||
1210 | |||
1211 | if (sk == NULL) return(0); | ||
1212 | q=p; | ||
1213 | |||
1214 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
1215 | { | ||
1216 | c=sk_SSL_CIPHER_value(sk,i); | ||
1217 | #ifndef OPENSSL_NO_KRB5 | ||
1218 | if ((c->algorithms & SSL_KRB5) && nokrb5) | ||
1219 | continue; | ||
1220 | #endif /* OPENSSL_NO_KRB5 */ | ||
1221 | |||
1222 | j = put_cb ? put_cb(c,p) : ssl_put_cipher_by_char(s,c,p); | ||
1223 | p+=j; | ||
1224 | } | ||
1225 | return(p-q); | ||
1226 | } | ||
1227 | |||
1228 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | ||
1229 | STACK_OF(SSL_CIPHER) **skp) | ||
1230 | { | ||
1231 | SSL_CIPHER *c; | ||
1232 | STACK_OF(SSL_CIPHER) *sk; | ||
1233 | int i,n; | ||
1234 | |||
1235 | n=ssl_put_cipher_by_char(s,NULL,NULL); | ||
1236 | if ((num%n) != 0) | ||
1237 | { | ||
1238 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); | ||
1239 | return(NULL); | ||
1240 | } | ||
1241 | if ((skp == NULL) || (*skp == NULL)) | ||
1242 | sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */ | ||
1243 | else | ||
1244 | { | ||
1245 | sk= *skp; | ||
1246 | sk_SSL_CIPHER_zero(sk); | ||
1247 | } | ||
1248 | |||
1249 | for (i=0; i<num; i+=n) | ||
1250 | { | ||
1251 | c=ssl_get_cipher_by_char(s,p); | ||
1252 | p+=n; | ||
1253 | if (c != NULL) | ||
1254 | { | ||
1255 | if (!sk_SSL_CIPHER_push(sk,c)) | ||
1256 | { | ||
1257 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
1258 | goto err; | ||
1259 | } | ||
1260 | } | ||
1261 | } | ||
1262 | |||
1263 | if (skp != NULL) | ||
1264 | *skp=sk; | ||
1265 | return(sk); | ||
1266 | err: | ||
1267 | if ((skp == NULL) || (*skp == NULL)) | ||
1268 | sk_SSL_CIPHER_free(sk); | ||
1269 | return(NULL); | ||
1270 | } | ||
1271 | |||
1272 | unsigned long SSL_SESSION_hash(const SSL_SESSION *a) | ||
1273 | { | ||
1274 | unsigned long l; | ||
1275 | |||
1276 | l=(unsigned long) | ||
1277 | ((unsigned int) a->session_id[0] )| | ||
1278 | ((unsigned int) a->session_id[1]<< 8L)| | ||
1279 | ((unsigned long)a->session_id[2]<<16L)| | ||
1280 | ((unsigned long)a->session_id[3]<<24L); | ||
1281 | return(l); | ||
1282 | } | ||
1283 | |||
1284 | /* NB: If this function (or indeed the hash function which uses a sort of | ||
1285 | * coarser function than this one) is changed, ensure | ||
1286 | * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being | ||
1287 | * able to construct an SSL_SESSION that will collide with any existing session | ||
1288 | * with a matching session ID. */ | ||
1289 | int SSL_SESSION_cmp(const SSL_SESSION *a,const SSL_SESSION *b) | ||
1290 | { | ||
1291 | if (a->ssl_version != b->ssl_version) | ||
1292 | return(1); | ||
1293 | if (a->session_id_length != b->session_id_length) | ||
1294 | return(1); | ||
1295 | return(memcmp(a->session_id,b->session_id,a->session_id_length)); | ||
1296 | } | ||
1297 | |||
1298 | /* These wrapper functions should remain rather than redeclaring | ||
1299 | * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each | ||
1300 | * variable. The reason is that the functions aren't static, they're exposed via | ||
1301 | * ssl.h. */ | ||
1302 | static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *) | ||
1303 | static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *) | ||
1304 | |||
1305 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | ||
1306 | { | ||
1307 | SSL_CTX *ret=NULL; | ||
1308 | |||
1309 | if (meth == NULL) | ||
1310 | { | ||
1311 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | ||
1312 | return(NULL); | ||
1313 | } | ||
1314 | |||
1315 | #ifdef OPENSSL_FIPS | ||
1316 | if (FIPS_mode() && (meth->version < TLS1_VERSION)) | ||
1317 | { | ||
1318 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE); | ||
1319 | return NULL; | ||
1320 | } | ||
1321 | #endif | ||
1322 | |||
1323 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | ||
1324 | { | ||
1325 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | ||
1326 | goto err; | ||
1327 | } | ||
1328 | ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX)); | ||
1329 | if (ret == NULL) | ||
1330 | goto err; | ||
1331 | |||
1332 | memset(ret,0,sizeof(SSL_CTX)); | ||
1333 | |||
1334 | ret->method=meth; | ||
1335 | |||
1336 | ret->cert_store=NULL; | ||
1337 | ret->session_cache_mode=SSL_SESS_CACHE_SERVER; | ||
1338 | ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT; | ||
1339 | ret->session_cache_head=NULL; | ||
1340 | ret->session_cache_tail=NULL; | ||
1341 | |||
1342 | /* We take the system default */ | ||
1343 | ret->session_timeout=meth->get_timeout(); | ||
1344 | |||
1345 | ret->new_session_cb=0; | ||
1346 | ret->remove_session_cb=0; | ||
1347 | ret->get_session_cb=0; | ||
1348 | ret->generate_session_id=0; | ||
1349 | |||
1350 | memset((char *)&ret->stats,0,sizeof(ret->stats)); | ||
1351 | |||
1352 | ret->references=1; | ||
1353 | ret->quiet_shutdown=0; | ||
1354 | |||
1355 | /* ret->cipher=NULL;*/ | ||
1356 | /* ret->s2->challenge=NULL; | ||
1357 | ret->master_key=NULL; | ||
1358 | ret->key_arg=NULL; | ||
1359 | ret->s2->conn_id=NULL; */ | ||
1360 | |||
1361 | ret->info_callback=NULL; | ||
1362 | |||
1363 | ret->app_verify_callback=0; | ||
1364 | ret->app_verify_arg=NULL; | ||
1365 | |||
1366 | ret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT; | ||
1367 | ret->read_ahead=0; | ||
1368 | ret->msg_callback=0; | ||
1369 | ret->msg_callback_arg=NULL; | ||
1370 | ret->verify_mode=SSL_VERIFY_NONE; | ||
1371 | ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */ | ||
1372 | ret->sid_ctx_length=0; | ||
1373 | ret->default_verify_callback=NULL; | ||
1374 | if ((ret->cert=ssl_cert_new()) == NULL) | ||
1375 | goto err; | ||
1376 | |||
1377 | ret->default_passwd_callback=0; | ||
1378 | ret->default_passwd_callback_userdata=NULL; | ||
1379 | ret->client_cert_cb=0; | ||
1380 | |||
1381 | ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash), | ||
1382 | LHASH_COMP_FN(SSL_SESSION_cmp)); | ||
1383 | if (ret->sessions == NULL) goto err; | ||
1384 | ret->cert_store=X509_STORE_new(); | ||
1385 | if (ret->cert_store == NULL) goto err; | ||
1386 | |||
1387 | ssl_create_cipher_list(ret->method, | ||
1388 | &ret->cipher_list,&ret->cipher_list_by_id, | ||
1389 | SSL_DEFAULT_CIPHER_LIST); | ||
1390 | if (ret->cipher_list == NULL | ||
1391 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | ||
1392 | { | ||
1393 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS); | ||
1394 | goto err2; | ||
1395 | } | ||
1396 | |||
1397 | if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL) | ||
1398 | { | ||
1399 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); | ||
1400 | goto err2; | ||
1401 | } | ||
1402 | if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL) | ||
1403 | { | ||
1404 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES); | ||
1405 | goto err2; | ||
1406 | } | ||
1407 | if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL) | ||
1408 | { | ||
1409 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES); | ||
1410 | goto err2; | ||
1411 | } | ||
1412 | |||
1413 | if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL) | ||
1414 | goto err; | ||
1415 | |||
1416 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data); | ||
1417 | |||
1418 | ret->extra_certs=NULL; | ||
1419 | ret->comp_methods=SSL_COMP_get_compression_methods(); | ||
1420 | |||
1421 | return(ret); | ||
1422 | err: | ||
1423 | SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE); | ||
1424 | err2: | ||
1425 | if (ret != NULL) SSL_CTX_free(ret); | ||
1426 | return(NULL); | ||
1427 | } | ||
1428 | |||
1429 | #if 0 | ||
1430 | static void SSL_COMP_free(SSL_COMP *comp) | ||
1431 | { OPENSSL_free(comp); } | ||
1432 | #endif | ||
1433 | |||
1434 | void SSL_CTX_free(SSL_CTX *a) | ||
1435 | { | ||
1436 | int i; | ||
1437 | |||
1438 | if (a == NULL) return; | ||
1439 | |||
1440 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX); | ||
1441 | #ifdef REF_PRINT | ||
1442 | REF_PRINT("SSL_CTX",a); | ||
1443 | #endif | ||
1444 | if (i > 0) return; | ||
1445 | #ifdef REF_CHECK | ||
1446 | if (i < 0) | ||
1447 | { | ||
1448 | fprintf(stderr,"SSL_CTX_free, bad reference count\n"); | ||
1449 | abort(); /* ok */ | ||
1450 | } | ||
1451 | #endif | ||
1452 | |||
1453 | /* | ||
1454 | * Free internal session cache. However: the remove_cb() may reference | ||
1455 | * the ex_data of SSL_CTX, thus the ex_data store can only be removed | ||
1456 | * after the sessions were flushed. | ||
1457 | * As the ex_data handling routines might also touch the session cache, | ||
1458 | * the most secure solution seems to be: empty (flush) the cache, then | ||
1459 | * free ex_data, then finally free the cache. | ||
1460 | * (See ticket [openssl.org #212].) | ||
1461 | */ | ||
1462 | if (a->sessions != NULL) | ||
1463 | SSL_CTX_flush_sessions(a,0); | ||
1464 | |||
1465 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data); | ||
1466 | |||
1467 | if (a->sessions != NULL) | ||
1468 | lh_free(a->sessions); | ||
1469 | |||
1470 | if (a->cert_store != NULL) | ||
1471 | X509_STORE_free(a->cert_store); | ||
1472 | if (a->cipher_list != NULL) | ||
1473 | sk_SSL_CIPHER_free(a->cipher_list); | ||
1474 | if (a->cipher_list_by_id != NULL) | ||
1475 | sk_SSL_CIPHER_free(a->cipher_list_by_id); | ||
1476 | if (a->cert != NULL) | ||
1477 | ssl_cert_free(a->cert); | ||
1478 | if (a->client_CA != NULL) | ||
1479 | sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free); | ||
1480 | if (a->extra_certs != NULL) | ||
1481 | sk_X509_pop_free(a->extra_certs,X509_free); | ||
1482 | #if 0 /* This should never be done, since it removes a global database */ | ||
1483 | if (a->comp_methods != NULL) | ||
1484 | sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free); | ||
1485 | #else | ||
1486 | a->comp_methods = NULL; | ||
1487 | #endif | ||
1488 | OPENSSL_free(a); | ||
1489 | } | ||
1490 | |||
1491 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) | ||
1492 | { | ||
1493 | ctx->default_passwd_callback=cb; | ||
1494 | } | ||
1495 | |||
1496 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u) | ||
1497 | { | ||
1498 | ctx->default_passwd_callback_userdata=u; | ||
1499 | } | ||
1500 | |||
1501 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg) | ||
1502 | { | ||
1503 | ctx->app_verify_callback=cb; | ||
1504 | ctx->app_verify_arg=arg; | ||
1505 | } | ||
1506 | |||
1507 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *)) | ||
1508 | { | ||
1509 | ctx->verify_mode=mode; | ||
1510 | ctx->default_verify_callback=cb; | ||
1511 | } | ||
1512 | |||
1513 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | ||
1514 | { | ||
1515 | ctx->verify_depth=depth; | ||
1516 | } | ||
1517 | |||
1518 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | ||
1519 | { | ||
1520 | CERT_PKEY *cpk; | ||
1521 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | ||
1522 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | ||
1523 | int rsa_tmp_export,dh_tmp_export,kl; | ||
1524 | unsigned long mask,emask; | ||
1525 | |||
1526 | if (c == NULL) return; | ||
1527 | |||
1528 | kl=SSL_C_EXPORT_PKEYLENGTH(cipher); | ||
1529 | |||
1530 | #ifndef OPENSSL_NO_RSA | ||
1531 | rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL); | ||
1532 | rsa_tmp_export=(c->rsa_tmp_cb != NULL || | ||
1533 | (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl)); | ||
1534 | #else | ||
1535 | rsa_tmp=rsa_tmp_export=0; | ||
1536 | #endif | ||
1537 | #ifndef OPENSSL_NO_DH | ||
1538 | dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL); | ||
1539 | dh_tmp_export=(c->dh_tmp_cb != NULL || | ||
1540 | (dh_tmp && DH_size(c->dh_tmp)*8 <= kl)); | ||
1541 | #else | ||
1542 | dh_tmp=dh_tmp_export=0; | ||
1543 | #endif | ||
1544 | |||
1545 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); | ||
1546 | rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1547 | rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1548 | cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]); | ||
1549 | rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1550 | cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]); | ||
1551 | dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1552 | cpk= &(c->pkeys[SSL_PKEY_DH_RSA]); | ||
1553 | dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1554 | dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1555 | cpk= &(c->pkeys[SSL_PKEY_DH_DSA]); | ||
1556 | /* FIX THIS EAY EAY EAY */ | ||
1557 | dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1558 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1559 | |||
1560 | mask=0; | ||
1561 | emask=0; | ||
1562 | |||
1563 | #ifdef CIPHER_DEBUG | ||
1564 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", | ||
1565 | rsa_tmp,rsa_tmp_export,dh_tmp, | ||
1566 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | ||
1567 | #endif | ||
1568 | |||
1569 | if (rsa_enc || (rsa_tmp && rsa_sign)) | ||
1570 | mask|=SSL_kRSA; | ||
1571 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) | ||
1572 | emask|=SSL_kRSA; | ||
1573 | |||
1574 | #if 0 | ||
1575 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | ||
1576 | if ( (dh_tmp || dh_rsa || dh_dsa) && | ||
1577 | (rsa_enc || rsa_sign || dsa_sign)) | ||
1578 | mask|=SSL_kEDH; | ||
1579 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | ||
1580 | (rsa_enc || rsa_sign || dsa_sign)) | ||
1581 | emask|=SSL_kEDH; | ||
1582 | #endif | ||
1583 | |||
1584 | if (dh_tmp_export) | ||
1585 | emask|=SSL_kEDH; | ||
1586 | |||
1587 | if (dh_tmp) | ||
1588 | mask|=SSL_kEDH; | ||
1589 | |||
1590 | if (dh_rsa) mask|=SSL_kDHr; | ||
1591 | if (dh_rsa_export) emask|=SSL_kDHr; | ||
1592 | |||
1593 | if (dh_dsa) mask|=SSL_kDHd; | ||
1594 | if (dh_dsa_export) emask|=SSL_kDHd; | ||
1595 | |||
1596 | if (rsa_enc || rsa_sign) | ||
1597 | { | ||
1598 | mask|=SSL_aRSA; | ||
1599 | emask|=SSL_aRSA; | ||
1600 | } | ||
1601 | |||
1602 | if (dsa_sign) | ||
1603 | { | ||
1604 | mask|=SSL_aDSS; | ||
1605 | emask|=SSL_aDSS; | ||
1606 | } | ||
1607 | |||
1608 | mask|=SSL_aNULL; | ||
1609 | emask|=SSL_aNULL; | ||
1610 | |||
1611 | #ifndef OPENSSL_NO_KRB5 | ||
1612 | mask|=SSL_kKRB5|SSL_aKRB5; | ||
1613 | emask|=SSL_kKRB5|SSL_aKRB5; | ||
1614 | #endif | ||
1615 | |||
1616 | c->mask=mask; | ||
1617 | c->export_mask=emask; | ||
1618 | c->valid=1; | ||
1619 | } | ||
1620 | |||
1621 | /* THIS NEEDS CLEANING UP */ | ||
1622 | X509 *ssl_get_server_send_cert(SSL *s) | ||
1623 | { | ||
1624 | unsigned long alg,mask,kalg; | ||
1625 | CERT *c; | ||
1626 | int i,is_export; | ||
1627 | |||
1628 | c=s->cert; | ||
1629 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); | ||
1630 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1631 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | ||
1632 | mask=is_export?c->export_mask:c->mask; | ||
1633 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
1634 | |||
1635 | if (kalg & SSL_kDHr) | ||
1636 | i=SSL_PKEY_DH_RSA; | ||
1637 | else if (kalg & SSL_kDHd) | ||
1638 | i=SSL_PKEY_DH_DSA; | ||
1639 | else if (kalg & SSL_aDSS) | ||
1640 | i=SSL_PKEY_DSA_SIGN; | ||
1641 | else if (kalg & SSL_aRSA) | ||
1642 | { | ||
1643 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | ||
1644 | i=SSL_PKEY_RSA_SIGN; | ||
1645 | else | ||
1646 | i=SSL_PKEY_RSA_ENC; | ||
1647 | } | ||
1648 | else if (kalg & SSL_aKRB5) | ||
1649 | { | ||
1650 | /* VRS something else here? */ | ||
1651 | return(NULL); | ||
1652 | } | ||
1653 | else /* if (kalg & SSL_aNULL) */ | ||
1654 | { | ||
1655 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR); | ||
1656 | return(NULL); | ||
1657 | } | ||
1658 | if (c->pkeys[i].x509 == NULL) return(NULL); | ||
1659 | return(c->pkeys[i].x509); | ||
1660 | } | ||
1661 | |||
1662 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | ||
1663 | { | ||
1664 | unsigned long alg; | ||
1665 | CERT *c; | ||
1666 | |||
1667 | alg=cipher->algorithms; | ||
1668 | c=s->cert; | ||
1669 | |||
1670 | if ((alg & SSL_aDSS) && | ||
1671 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | ||
1672 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | ||
1673 | else if (alg & SSL_aRSA) | ||
1674 | { | ||
1675 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | ||
1676 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | ||
1677 | else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL) | ||
1678 | return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey); | ||
1679 | else | ||
1680 | return(NULL); | ||
1681 | } | ||
1682 | else /* if (alg & SSL_aNULL) */ | ||
1683 | { | ||
1684 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR); | ||
1685 | return(NULL); | ||
1686 | } | ||
1687 | } | ||
1688 | |||
1689 | void ssl_update_cache(SSL *s,int mode) | ||
1690 | { | ||
1691 | int i; | ||
1692 | |||
1693 | /* If the session_id_length is 0, we are not supposed to cache it, | ||
1694 | * and it would be rather hard to do anyway :-) */ | ||
1695 | if (s->session->session_id_length == 0) return; | ||
1696 | |||
1697 | i=s->ctx->session_cache_mode; | ||
1698 | if ((i & mode) && (!s->hit) | ||
1699 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) | ||
1700 | || SSL_CTX_add_session(s->ctx,s->session)) | ||
1701 | && (s->ctx->new_session_cb != NULL)) | ||
1702 | { | ||
1703 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
1704 | if (!s->ctx->new_session_cb(s,s->session)) | ||
1705 | SSL_SESSION_free(s->session); | ||
1706 | } | ||
1707 | |||
1708 | /* auto flush every 255 connections */ | ||
1709 | if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && | ||
1710 | ((i & mode) == mode)) | ||
1711 | { | ||
1712 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | ||
1713 | ?s->ctx->stats.sess_connect_good | ||
1714 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) | ||
1715 | { | ||
1716 | SSL_CTX_flush_sessions(s->ctx,(unsigned long)time(NULL)); | ||
1717 | } | ||
1718 | } | ||
1719 | } | ||
1720 | |||
1721 | SSL_METHOD *SSL_get_ssl_method(SSL *s) | ||
1722 | { | ||
1723 | return(s->method); | ||
1724 | } | ||
1725 | |||
1726 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) | ||
1727 | { | ||
1728 | int conn= -1; | ||
1729 | int ret=1; | ||
1730 | |||
1731 | if (s->method != meth) | ||
1732 | { | ||
1733 | if (s->handshake_func != NULL) | ||
1734 | conn=(s->handshake_func == s->method->ssl_connect); | ||
1735 | |||
1736 | if (s->method->version == meth->version) | ||
1737 | s->method=meth; | ||
1738 | else | ||
1739 | { | ||
1740 | s->method->ssl_free(s); | ||
1741 | s->method=meth; | ||
1742 | ret=s->method->ssl_new(s); | ||
1743 | } | ||
1744 | |||
1745 | if (conn == 1) | ||
1746 | s->handshake_func=meth->ssl_connect; | ||
1747 | else if (conn == 0) | ||
1748 | s->handshake_func=meth->ssl_accept; | ||
1749 | } | ||
1750 | return(ret); | ||
1751 | } | ||
1752 | |||
1753 | int SSL_get_error(const SSL *s,int i) | ||
1754 | { | ||
1755 | int reason; | ||
1756 | unsigned long l; | ||
1757 | BIO *bio; | ||
1758 | |||
1759 | if (i > 0) return(SSL_ERROR_NONE); | ||
1760 | |||
1761 | /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake | ||
1762 | * etc, where we do encode the error */ | ||
1763 | if ((l=ERR_peek_error()) != 0) | ||
1764 | { | ||
1765 | if (ERR_GET_LIB(l) == ERR_LIB_SYS) | ||
1766 | return(SSL_ERROR_SYSCALL); | ||
1767 | else | ||
1768 | return(SSL_ERROR_SSL); | ||
1769 | } | ||
1770 | |||
1771 | if ((i < 0) && SSL_want_read(s)) | ||
1772 | { | ||
1773 | bio=SSL_get_rbio(s); | ||
1774 | if (BIO_should_read(bio)) | ||
1775 | return(SSL_ERROR_WANT_READ); | ||
1776 | else if (BIO_should_write(bio)) | ||
1777 | /* This one doesn't make too much sense ... We never try | ||
1778 | * to write to the rbio, and an application program where | ||
1779 | * rbio and wbio are separate couldn't even know what it | ||
1780 | * should wait for. | ||
1781 | * However if we ever set s->rwstate incorrectly | ||
1782 | * (so that we have SSL_want_read(s) instead of | ||
1783 | * SSL_want_write(s)) and rbio and wbio *are* the same, | ||
1784 | * this test works around that bug; so it might be safer | ||
1785 | * to keep it. */ | ||
1786 | return(SSL_ERROR_WANT_WRITE); | ||
1787 | else if (BIO_should_io_special(bio)) | ||
1788 | { | ||
1789 | reason=BIO_get_retry_reason(bio); | ||
1790 | if (reason == BIO_RR_CONNECT) | ||
1791 | return(SSL_ERROR_WANT_CONNECT); | ||
1792 | else if (reason == BIO_RR_ACCEPT) | ||
1793 | return(SSL_ERROR_WANT_ACCEPT); | ||
1794 | else | ||
1795 | return(SSL_ERROR_SYSCALL); /* unknown */ | ||
1796 | } | ||
1797 | } | ||
1798 | |||
1799 | if ((i < 0) && SSL_want_write(s)) | ||
1800 | { | ||
1801 | bio=SSL_get_wbio(s); | ||
1802 | if (BIO_should_write(bio)) | ||
1803 | return(SSL_ERROR_WANT_WRITE); | ||
1804 | else if (BIO_should_read(bio)) | ||
1805 | /* See above (SSL_want_read(s) with BIO_should_write(bio)) */ | ||
1806 | return(SSL_ERROR_WANT_READ); | ||
1807 | else if (BIO_should_io_special(bio)) | ||
1808 | { | ||
1809 | reason=BIO_get_retry_reason(bio); | ||
1810 | if (reason == BIO_RR_CONNECT) | ||
1811 | return(SSL_ERROR_WANT_CONNECT); | ||
1812 | else if (reason == BIO_RR_ACCEPT) | ||
1813 | return(SSL_ERROR_WANT_ACCEPT); | ||
1814 | else | ||
1815 | return(SSL_ERROR_SYSCALL); | ||
1816 | } | ||
1817 | } | ||
1818 | if ((i < 0) && SSL_want_x509_lookup(s)) | ||
1819 | { | ||
1820 | return(SSL_ERROR_WANT_X509_LOOKUP); | ||
1821 | } | ||
1822 | |||
1823 | if (i == 0) | ||
1824 | { | ||
1825 | if (s->version == SSL2_VERSION) | ||
1826 | { | ||
1827 | /* assume it is the socket being closed */ | ||
1828 | return(SSL_ERROR_ZERO_RETURN); | ||
1829 | } | ||
1830 | else | ||
1831 | { | ||
1832 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && | ||
1833 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) | ||
1834 | return(SSL_ERROR_ZERO_RETURN); | ||
1835 | } | ||
1836 | } | ||
1837 | return(SSL_ERROR_SYSCALL); | ||
1838 | } | ||
1839 | |||
1840 | int SSL_do_handshake(SSL *s) | ||
1841 | { | ||
1842 | int ret=1; | ||
1843 | |||
1844 | if (s->handshake_func == NULL) | ||
1845 | { | ||
1846 | SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET); | ||
1847 | return(-1); | ||
1848 | } | ||
1849 | |||
1850 | s->method->ssl_renegotiate_check(s); | ||
1851 | |||
1852 | if (SSL_in_init(s) || SSL_in_before(s)) | ||
1853 | { | ||
1854 | ret=s->handshake_func(s); | ||
1855 | } | ||
1856 | return(ret); | ||
1857 | } | ||
1858 | |||
1859 | /* For the next 2 functions, SSL_clear() sets shutdown and so | ||
1860 | * one of these calls will reset it */ | ||
1861 | void SSL_set_accept_state(SSL *s) | ||
1862 | { | ||
1863 | s->server=1; | ||
1864 | s->shutdown=0; | ||
1865 | s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE; | ||
1866 | s->handshake_func=s->method->ssl_accept; | ||
1867 | /* clear the current cipher */ | ||
1868 | ssl_clear_cipher_ctx(s); | ||
1869 | } | ||
1870 | |||
1871 | void SSL_set_connect_state(SSL *s) | ||
1872 | { | ||
1873 | s->server=0; | ||
1874 | s->shutdown=0; | ||
1875 | s->state=SSL_ST_CONNECT|SSL_ST_BEFORE; | ||
1876 | s->handshake_func=s->method->ssl_connect; | ||
1877 | /* clear the current cipher */ | ||
1878 | ssl_clear_cipher_ctx(s); | ||
1879 | } | ||
1880 | |||
1881 | int ssl_undefined_function(SSL *s) | ||
1882 | { | ||
1883 | SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1884 | return(0); | ||
1885 | } | ||
1886 | |||
1887 | int ssl_undefined_const_function(const SSL *s) | ||
1888 | { | ||
1889 | SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1890 | return(0); | ||
1891 | } | ||
1892 | |||
1893 | SSL_METHOD *ssl_bad_method(int ver) | ||
1894 | { | ||
1895 | SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1896 | return(NULL); | ||
1897 | } | ||
1898 | |||
1899 | const char *SSL_get_version(const SSL *s) | ||
1900 | { | ||
1901 | if (s->version == TLS1_VERSION) | ||
1902 | return("TLSv1"); | ||
1903 | else if (s->version == SSL3_VERSION) | ||
1904 | return("SSLv3"); | ||
1905 | else if (s->version == SSL2_VERSION) | ||
1906 | return("SSLv2"); | ||
1907 | else | ||
1908 | return("unknown"); | ||
1909 | } | ||
1910 | |||
1911 | SSL *SSL_dup(SSL *s) | ||
1912 | { | ||
1913 | STACK_OF(X509_NAME) *sk; | ||
1914 | X509_NAME *xn; | ||
1915 | SSL *ret; | ||
1916 | int i; | ||
1917 | |||
1918 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) | ||
1919 | return(NULL); | ||
1920 | |||
1921 | ret->version = s->version; | ||
1922 | ret->type = s->type; | ||
1923 | ret->method = s->method; | ||
1924 | |||
1925 | if (s->session != NULL) | ||
1926 | { | ||
1927 | /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */ | ||
1928 | SSL_copy_session_id(ret,s); | ||
1929 | } | ||
1930 | else | ||
1931 | { | ||
1932 | /* No session has been established yet, so we have to expect | ||
1933 | * that s->cert or ret->cert will be changed later -- | ||
1934 | * they should not both point to the same object, | ||
1935 | * and thus we can't use SSL_copy_session_id. */ | ||
1936 | |||
1937 | ret->method->ssl_free(ret); | ||
1938 | ret->method = s->method; | ||
1939 | ret->method->ssl_new(ret); | ||
1940 | |||
1941 | if (s->cert != NULL) | ||
1942 | { | ||
1943 | if (ret->cert != NULL) | ||
1944 | { | ||
1945 | ssl_cert_free(ret->cert); | ||
1946 | } | ||
1947 | ret->cert = ssl_cert_dup(s->cert); | ||
1948 | if (ret->cert == NULL) | ||
1949 | goto err; | ||
1950 | } | ||
1951 | |||
1952 | SSL_set_session_id_context(ret, | ||
1953 | s->sid_ctx, s->sid_ctx_length); | ||
1954 | } | ||
1955 | |||
1956 | ret->options=s->options; | ||
1957 | ret->mode=s->mode; | ||
1958 | SSL_set_max_cert_list(ret,SSL_get_max_cert_list(s)); | ||
1959 | SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); | ||
1960 | ret->msg_callback = s->msg_callback; | ||
1961 | ret->msg_callback_arg = s->msg_callback_arg; | ||
1962 | SSL_set_verify(ret,SSL_get_verify_mode(s), | ||
1963 | SSL_get_verify_callback(s)); | ||
1964 | SSL_set_verify_depth(ret,SSL_get_verify_depth(s)); | ||
1965 | ret->generate_session_id = s->generate_session_id; | ||
1966 | |||
1967 | SSL_set_info_callback(ret,SSL_get_info_callback(s)); | ||
1968 | |||
1969 | ret->debug=s->debug; | ||
1970 | |||
1971 | /* copy app data, a little dangerous perhaps */ | ||
1972 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data)) | ||
1973 | goto err; | ||
1974 | |||
1975 | /* setup rbio, and wbio */ | ||
1976 | if (s->rbio != NULL) | ||
1977 | { | ||
1978 | if (!BIO_dup_state(s->rbio,(char *)&ret->rbio)) | ||
1979 | goto err; | ||
1980 | } | ||
1981 | if (s->wbio != NULL) | ||
1982 | { | ||
1983 | if (s->wbio != s->rbio) | ||
1984 | { | ||
1985 | if (!BIO_dup_state(s->wbio,(char *)&ret->wbio)) | ||
1986 | goto err; | ||
1987 | } | ||
1988 | else | ||
1989 | ret->wbio=ret->rbio; | ||
1990 | } | ||
1991 | ret->rwstate = s->rwstate; | ||
1992 | ret->in_handshake = s->in_handshake; | ||
1993 | ret->handshake_func = s->handshake_func; | ||
1994 | ret->server = s->server; | ||
1995 | ret->new_session = s->new_session; | ||
1996 | ret->quiet_shutdown = s->quiet_shutdown; | ||
1997 | ret->shutdown=s->shutdown; | ||
1998 | ret->state=s->state; /* SSL_dup does not really work at any state, though */ | ||
1999 | ret->rstate=s->rstate; | ||
2000 | ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */ | ||
2001 | ret->hit=s->hit; | ||
2002 | ret->purpose=s->purpose; | ||
2003 | ret->trust=s->trust; | ||
2004 | |||
2005 | /* dup the cipher_list and cipher_list_by_id stacks */ | ||
2006 | if (s->cipher_list != NULL) | ||
2007 | { | ||
2008 | if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL) | ||
2009 | goto err; | ||
2010 | } | ||
2011 | if (s->cipher_list_by_id != NULL) | ||
2012 | if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id)) | ||
2013 | == NULL) | ||
2014 | goto err; | ||
2015 | |||
2016 | /* Dup the client_CA list */ | ||
2017 | if (s->client_CA != NULL) | ||
2018 | { | ||
2019 | if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err; | ||
2020 | ret->client_CA=sk; | ||
2021 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
2022 | { | ||
2023 | xn=sk_X509_NAME_value(sk,i); | ||
2024 | if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL) | ||
2025 | { | ||
2026 | X509_NAME_free(xn); | ||
2027 | goto err; | ||
2028 | } | ||
2029 | } | ||
2030 | } | ||
2031 | |||
2032 | if (0) | ||
2033 | { | ||
2034 | err: | ||
2035 | if (ret != NULL) SSL_free(ret); | ||
2036 | ret=NULL; | ||
2037 | } | ||
2038 | return(ret); | ||
2039 | } | ||
2040 | |||
2041 | void ssl_clear_cipher_ctx(SSL *s) | ||
2042 | { | ||
2043 | if (s->enc_read_ctx != NULL) | ||
2044 | { | ||
2045 | EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); | ||
2046 | OPENSSL_free(s->enc_read_ctx); | ||
2047 | s->enc_read_ctx=NULL; | ||
2048 | } | ||
2049 | if (s->enc_write_ctx != NULL) | ||
2050 | { | ||
2051 | EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); | ||
2052 | OPENSSL_free(s->enc_write_ctx); | ||
2053 | s->enc_write_ctx=NULL; | ||
2054 | } | ||
2055 | if (s->expand != NULL) | ||
2056 | { | ||
2057 | COMP_CTX_free(s->expand); | ||
2058 | s->expand=NULL; | ||
2059 | } | ||
2060 | if (s->compress != NULL) | ||
2061 | { | ||
2062 | COMP_CTX_free(s->compress); | ||
2063 | s->compress=NULL; | ||
2064 | } | ||
2065 | } | ||
2066 | |||
2067 | /* Fix this function so that it takes an optional type parameter */ | ||
2068 | X509 *SSL_get_certificate(const SSL *s) | ||
2069 | { | ||
2070 | if (s->cert != NULL) | ||
2071 | return(s->cert->key->x509); | ||
2072 | else | ||
2073 | return(NULL); | ||
2074 | } | ||
2075 | |||
2076 | /* Fix this function so that it takes an optional type parameter */ | ||
2077 | EVP_PKEY *SSL_get_privatekey(SSL *s) | ||
2078 | { | ||
2079 | if (s->cert != NULL) | ||
2080 | return(s->cert->key->privatekey); | ||
2081 | else | ||
2082 | return(NULL); | ||
2083 | } | ||
2084 | |||
2085 | SSL_CIPHER *SSL_get_current_cipher(const SSL *s) | ||
2086 | { | ||
2087 | if ((s->session != NULL) && (s->session->cipher != NULL)) | ||
2088 | return(s->session->cipher); | ||
2089 | return(NULL); | ||
2090 | } | ||
2091 | |||
2092 | int ssl_init_wbio_buffer(SSL *s,int push) | ||
2093 | { | ||
2094 | BIO *bbio; | ||
2095 | |||
2096 | if (s->bbio == NULL) | ||
2097 | { | ||
2098 | bbio=BIO_new(BIO_f_buffer()); | ||
2099 | if (bbio == NULL) return(0); | ||
2100 | s->bbio=bbio; | ||
2101 | } | ||
2102 | else | ||
2103 | { | ||
2104 | bbio=s->bbio; | ||
2105 | if (s->bbio == s->wbio) | ||
2106 | s->wbio=BIO_pop(s->wbio); | ||
2107 | } | ||
2108 | (void)BIO_reset(bbio); | ||
2109 | /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ | ||
2110 | if (!BIO_set_read_buffer_size(bbio,1)) | ||
2111 | { | ||
2112 | SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB); | ||
2113 | return(0); | ||
2114 | } | ||
2115 | if (push) | ||
2116 | { | ||
2117 | if (s->wbio != bbio) | ||
2118 | s->wbio=BIO_push(bbio,s->wbio); | ||
2119 | } | ||
2120 | else | ||
2121 | { | ||
2122 | if (s->wbio == bbio) | ||
2123 | s->wbio=BIO_pop(bbio); | ||
2124 | } | ||
2125 | return(1); | ||
2126 | } | ||
2127 | |||
2128 | void ssl_free_wbio_buffer(SSL *s) | ||
2129 | { | ||
2130 | if (s->bbio == NULL) return; | ||
2131 | |||
2132 | if (s->bbio == s->wbio) | ||
2133 | { | ||
2134 | /* remove buffering */ | ||
2135 | s->wbio=BIO_pop(s->wbio); | ||
2136 | #ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */ | ||
2137 | assert(s->wbio != NULL); | ||
2138 | #endif | ||
2139 | } | ||
2140 | BIO_free(s->bbio); | ||
2141 | s->bbio=NULL; | ||
2142 | } | ||
2143 | |||
2144 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode) | ||
2145 | { | ||
2146 | ctx->quiet_shutdown=mode; | ||
2147 | } | ||
2148 | |||
2149 | int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx) | ||
2150 | { | ||
2151 | return(ctx->quiet_shutdown); | ||
2152 | } | ||
2153 | |||
2154 | void SSL_set_quiet_shutdown(SSL *s,int mode) | ||
2155 | { | ||
2156 | s->quiet_shutdown=mode; | ||
2157 | } | ||
2158 | |||
2159 | int SSL_get_quiet_shutdown(const SSL *s) | ||
2160 | { | ||
2161 | return(s->quiet_shutdown); | ||
2162 | } | ||
2163 | |||
2164 | void SSL_set_shutdown(SSL *s,int mode) | ||
2165 | { | ||
2166 | s->shutdown=mode; | ||
2167 | } | ||
2168 | |||
2169 | int SSL_get_shutdown(const SSL *s) | ||
2170 | { | ||
2171 | return(s->shutdown); | ||
2172 | } | ||
2173 | |||
2174 | int SSL_version(const SSL *s) | ||
2175 | { | ||
2176 | return(s->version); | ||
2177 | } | ||
2178 | |||
2179 | SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) | ||
2180 | { | ||
2181 | return(ssl->ctx); | ||
2182 | } | ||
2183 | |||
2184 | #ifndef OPENSSL_NO_STDIO | ||
2185 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) | ||
2186 | { | ||
2187 | return(X509_STORE_set_default_paths(ctx->cert_store)); | ||
2188 | } | ||
2189 | |||
2190 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | ||
2191 | const char *CApath) | ||
2192 | { | ||
2193 | int r; | ||
2194 | r=X509_STORE_load_locations(ctx->cert_store,CAfile,CApath); | ||
2195 | return r; | ||
2196 | } | ||
2197 | #endif | ||
2198 | |||
2199 | void SSL_set_info_callback(SSL *ssl, | ||
2200 | void (*cb)(const SSL *ssl,int type,int val)) | ||
2201 | { | ||
2202 | ssl->info_callback=cb; | ||
2203 | } | ||
2204 | |||
2205 | void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl,int type,int val) | ||
2206 | { | ||
2207 | return ssl->info_callback; | ||
2208 | } | ||
2209 | |||
2210 | int SSL_state(const SSL *ssl) | ||
2211 | { | ||
2212 | return(ssl->state); | ||
2213 | } | ||
2214 | |||
2215 | void SSL_set_verify_result(SSL *ssl,long arg) | ||
2216 | { | ||
2217 | ssl->verify_result=arg; | ||
2218 | } | ||
2219 | |||
2220 | long SSL_get_verify_result(const SSL *ssl) | ||
2221 | { | ||
2222 | return(ssl->verify_result); | ||
2223 | } | ||
2224 | |||
2225 | int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, | ||
2226 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) | ||
2227 | { | ||
2228 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp, | ||
2229 | new_func, dup_func, free_func); | ||
2230 | } | ||
2231 | |||
2232 | int SSL_set_ex_data(SSL *s,int idx,void *arg) | ||
2233 | { | ||
2234 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
2235 | } | ||
2236 | |||
2237 | void *SSL_get_ex_data(const SSL *s,int idx) | ||
2238 | { | ||
2239 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
2240 | } | ||
2241 | |||
2242 | int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, | ||
2243 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) | ||
2244 | { | ||
2245 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp, | ||
2246 | new_func, dup_func, free_func); | ||
2247 | } | ||
2248 | |||
2249 | int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg) | ||
2250 | { | ||
2251 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
2252 | } | ||
2253 | |||
2254 | void *SSL_CTX_get_ex_data(const SSL_CTX *s,int idx) | ||
2255 | { | ||
2256 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
2257 | } | ||
2258 | |||
2259 | int ssl_ok(SSL *s) | ||
2260 | { | ||
2261 | return(1); | ||
2262 | } | ||
2263 | |||
2264 | X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx) | ||
2265 | { | ||
2266 | return(ctx->cert_store); | ||
2267 | } | ||
2268 | |||
2269 | void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store) | ||
2270 | { | ||
2271 | if (ctx->cert_store != NULL) | ||
2272 | X509_STORE_free(ctx->cert_store); | ||
2273 | ctx->cert_store=store; | ||
2274 | } | ||
2275 | |||
2276 | int SSL_want(const SSL *s) | ||
2277 | { | ||
2278 | return(s->rwstate); | ||
2279 | } | ||
2280 | |||
2281 | /*! | ||
2282 | * \brief Set the callback for generating temporary RSA keys. | ||
2283 | * \param ctx the SSL context. | ||
2284 | * \param cb the callback | ||
2285 | */ | ||
2286 | |||
2287 | #ifndef OPENSSL_NO_RSA | ||
2288 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, | ||
2289 | int is_export, | ||
2290 | int keylength)) | ||
2291 | { | ||
2292 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
2293 | } | ||
2294 | |||
2295 | void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, | ||
2296 | int is_export, | ||
2297 | int keylength)) | ||
2298 | { | ||
2299 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
2300 | } | ||
2301 | #endif | ||
2302 | |||
2303 | #ifdef DOXYGEN | ||
2304 | /*! | ||
2305 | * \brief The RSA temporary key callback function. | ||
2306 | * \param ssl the SSL session. | ||
2307 | * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite. | ||
2308 | * \param keylength if \c is_export is \c TRUE, then \c keylength is the size | ||
2309 | * of the required key in bits. | ||
2310 | * \return the temporary RSA key. | ||
2311 | * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback | ||
2312 | */ | ||
2313 | |||
2314 | RSA *cb(SSL *ssl,int is_export,int keylength) | ||
2315 | {} | ||
2316 | #endif | ||
2317 | |||
2318 | /*! | ||
2319 | * \brief Set the callback for generating temporary DH keys. | ||
2320 | * \param ctx the SSL context. | ||
2321 | * \param dh the callback | ||
2322 | */ | ||
2323 | |||
2324 | #ifndef OPENSSL_NO_DH | ||
2325 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | ||
2326 | int keylength)) | ||
2327 | { | ||
2328 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
2329 | } | ||
2330 | |||
2331 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | ||
2332 | int keylength)) | ||
2333 | { | ||
2334 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
2335 | } | ||
2336 | #endif | ||
2337 | |||
2338 | |||
2339 | void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | ||
2340 | { | ||
2341 | SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | ||
2342 | } | ||
2343 | void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)) | ||
2344 | { | ||
2345 | SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb); | ||
2346 | } | ||
2347 | |||
2348 | |||
2349 | |||
2350 | #if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16) | ||
2351 | #include "../crypto/bio/bss_file.c" | ||
2352 | #endif | ||
2353 | |||
2354 | IMPLEMENT_STACK_OF(SSL_CIPHER) | ||
2355 | IMPLEMENT_STACK_OF(SSL_COMP) | ||
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h deleted file mode 100644 index 6a0b7595f4..0000000000 --- a/src/lib/libssl/ssl_locl.h +++ /dev/null | |||
@@ -1,623 +0,0 @@ | |||
1 | /* ssl/ssl_locl.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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #ifndef HEADER_SSL_LOCL_H | ||
113 | #define HEADER_SSL_LOCL_H | ||
114 | #include <stdlib.h> | ||
115 | #include <time.h> | ||
116 | #include <string.h> | ||
117 | #include <errno.h> | ||
118 | |||
119 | #include "e_os.h" | ||
120 | |||
121 | #include <openssl/buffer.h> | ||
122 | #include <openssl/comp.h> | ||
123 | #include <openssl/bio.h> | ||
124 | #include <openssl/crypto.h> | ||
125 | #include <openssl/evp.h> | ||
126 | #include <openssl/stack.h> | ||
127 | #include <openssl/x509.h> | ||
128 | #include <openssl/err.h> | ||
129 | #include <openssl/ssl.h> | ||
130 | #include <openssl/symhacks.h> | ||
131 | |||
132 | #ifdef OPENSSL_BUILD_SHLIBSSL | ||
133 | # undef OPENSSL_EXTERN | ||
134 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
135 | #endif | ||
136 | |||
137 | #define PKCS1_CHECK | ||
138 | |||
139 | #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ | ||
140 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
141 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
142 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
143 | |||
144 | /* NOTE - c is not incremented as per c2l */ | ||
145 | #define c2ln(c,l1,l2,n) { \ | ||
146 | c+=n; \ | ||
147 | l1=l2=0; \ | ||
148 | switch (n) { \ | ||
149 | case 8: l2 =((unsigned long)(*(--(c))))<<24; \ | ||
150 | case 7: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
151 | case 6: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
152 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
153 | case 4: l1 =((unsigned long)(*(--(c))))<<24; \ | ||
154 | case 3: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
155 | case 2: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
156 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
157 | } \ | ||
158 | } | ||
159 | |||
160 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
161 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
162 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
163 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
164 | |||
165 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \ | ||
166 | l|=((unsigned long)(*((c)++)))<<16, \ | ||
167 | l|=((unsigned long)(*((c)++)))<< 8, \ | ||
168 | l|=((unsigned long)(*((c)++)))) | ||
169 | |||
170 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
171 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
172 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
173 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
174 | |||
175 | /* NOTE - c is not incremented as per l2c */ | ||
176 | #define l2cn(l1,l2,c,n) { \ | ||
177 | c+=n; \ | ||
178 | switch (n) { \ | ||
179 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
180 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
181 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
182 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
183 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
184 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
185 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
186 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
187 | } \ | ||
188 | } | ||
189 | |||
190 | #define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \ | ||
191 | (((unsigned int)(c[1])) )),c+=2) | ||
192 | #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \ | ||
193 | c[1]=(unsigned char)(((s) )&0xff)),c+=2) | ||
194 | |||
195 | #define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \ | ||
196 | (((unsigned long)(c[1]))<< 8)| \ | ||
197 | (((unsigned long)(c[2])) )),c+=3) | ||
198 | |||
199 | #define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \ | ||
200 | c[1]=(unsigned char)(((l)>> 8)&0xff), \ | ||
201 | c[2]=(unsigned char)(((l) )&0xff)),c+=3) | ||
202 | |||
203 | /* LOCAL STUFF */ | ||
204 | |||
205 | #define SSL_DECRYPT 0 | ||
206 | #define SSL_ENCRYPT 1 | ||
207 | |||
208 | #define TWO_BYTE_BIT 0x80 | ||
209 | #define SEC_ESC_BIT 0x40 | ||
210 | #define TWO_BYTE_MASK 0x7fff | ||
211 | #define THREE_BYTE_MASK 0x3fff | ||
212 | |||
213 | #define INC32(a) ((a)=((a)+1)&0xffffffffL) | ||
214 | #define DEC32(a) ((a)=((a)-1)&0xffffffffL) | ||
215 | #define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */ | ||
216 | |||
217 | /* | ||
218 | * Define the Bitmasks for SSL_CIPHER.algorithms. | ||
219 | * This bits are used packed as dense as possible. If new methods/ciphers | ||
220 | * etc will be added, the bits a likely to change, so this information | ||
221 | * is for internal library use only, even though SSL_CIPHER.algorithms | ||
222 | * can be publicly accessed. | ||
223 | * Use the according functions for cipher management instead. | ||
224 | * | ||
225 | * The bit mask handling in the selection and sorting scheme in | ||
226 | * ssl_create_cipher_list() has only limited capabilities, reflecting | ||
227 | * that the different entities within are mutually exclusive: | ||
228 | * ONLY ONE BIT PER MASK CAN BE SET AT A TIME. | ||
229 | */ | ||
230 | #define SSL_MKEY_MASK 0x0000003FL | ||
231 | #define SSL_kRSA 0x00000001L /* RSA key exchange */ | ||
232 | #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ | ||
233 | #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ | ||
234 | #define SSL_kFZA 0x00000008L | ||
235 | #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ | ||
236 | #define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */ | ||
237 | #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) | ||
238 | |||
239 | #define SSL_AUTH_MASK 0x00000FC0L | ||
240 | #define SSL_aRSA 0x00000040L /* Authenticate with RSA */ | ||
241 | #define SSL_aDSS 0x00000080L /* Authenticate with DSS */ | ||
242 | #define SSL_DSS SSL_aDSS | ||
243 | #define SSL_aFZA 0x00000100L | ||
244 | #define SSL_aNULL 0x00000200L /* no Authenticate, ADH */ | ||
245 | #define SSL_aDH 0x00000400L /* no Authenticate, ADH */ | ||
246 | #define SSL_aKRB5 0x00000800L /* Authenticate with KRB5 */ | ||
247 | |||
248 | #define SSL_NULL (SSL_eNULL) | ||
249 | #define SSL_ADH (SSL_kEDH|SSL_aNULL) | ||
250 | #define SSL_RSA (SSL_kRSA|SSL_aRSA) | ||
251 | #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) | ||
252 | #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) | ||
253 | #define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5) | ||
254 | |||
255 | #define SSL_ENC_MASK 0x0087F000L | ||
256 | #define SSL_DES 0x00001000L | ||
257 | #define SSL_3DES 0x00002000L | ||
258 | #define SSL_RC4 0x00004000L | ||
259 | #define SSL_RC2 0x00008000L | ||
260 | #define SSL_IDEA 0x00010000L | ||
261 | #define SSL_eFZA 0x00020000L | ||
262 | #define SSL_eNULL 0x00040000L | ||
263 | #define SSL_AES 0x00800000L | ||
264 | |||
265 | #define SSL_MAC_MASK 0x00180000L | ||
266 | #define SSL_MD5 0x00080000L | ||
267 | #define SSL_SHA1 0x00100000L | ||
268 | #define SSL_SHA (SSL_SHA1) | ||
269 | |||
270 | #define SSL_SSL_MASK 0x00600000L | ||
271 | #define SSL_SSLV2 0x00200000L | ||
272 | #define SSL_SSLV3 0x00400000L | ||
273 | #define SSL_TLSV1 SSL_SSLV3 /* for now */ | ||
274 | |||
275 | /* we have used 007fffff - 9 bits left to go */ | ||
276 | |||
277 | /* | ||
278 | * Export and cipher strength information. For each cipher we have to decide | ||
279 | * whether it is exportable or not. This information is likely to change | ||
280 | * over time, since the export control rules are no static technical issue. | ||
281 | * | ||
282 | * Independent of the export flag the cipher strength is sorted into classes. | ||
283 | * SSL_EXP40 was denoting the 40bit US export limit of past times, which now | ||
284 | * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change | ||
285 | * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more, | ||
286 | * since SSL_EXP64 could be similar to SSL_LOW. | ||
287 | * For this reason SSL_MICRO and SSL_MINI macros are included to widen the | ||
288 | * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed | ||
289 | * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would | ||
290 | * be possible. | ||
291 | */ | ||
292 | #define SSL_EXP_MASK 0x00000003L | ||
293 | #define SSL_NOT_EXP 0x00000001L | ||
294 | #define SSL_EXPORT 0x00000002L | ||
295 | |||
296 | #define SSL_STRONG_MASK 0x000000fcL | ||
297 | #define SSL_STRONG_NONE 0x00000004L | ||
298 | #define SSL_EXP40 0x00000008L | ||
299 | #define SSL_MICRO (SSL_EXP40) | ||
300 | #define SSL_EXP56 0x00000010L | ||
301 | #define SSL_MINI (SSL_EXP56) | ||
302 | #define SSL_LOW 0x00000020L | ||
303 | #define SSL_MEDIUM 0x00000040L | ||
304 | #define SSL_HIGH 0x00000080L | ||
305 | #define SSL_FIPS 0x00000100L | ||
306 | |||
307 | /* we have used 000001ff - 23 bits left to go */ | ||
308 | |||
309 | /* | ||
310 | * Macros to check the export status and cipher strength for export ciphers. | ||
311 | * Even though the macros for EXPORT and EXPORT40/56 have similar names, | ||
312 | * their meaning is different: | ||
313 | * *_EXPORT macros check the 'exportable' status. | ||
314 | * *_EXPORT40/56 macros are used to check whether a certain cipher strength | ||
315 | * is given. | ||
316 | * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct | ||
317 | * algorithm structure element to be passed (algorithms, algo_strength) and no | ||
318 | * typechecking can be done as they are all of type unsigned long, their | ||
319 | * direct usage is discouraged. | ||
320 | * Use the SSL_C_* macros instead. | ||
321 | */ | ||
322 | #define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT) | ||
323 | #define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56) | ||
324 | #define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40) | ||
325 | #define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength) | ||
326 | #define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength) | ||
327 | #define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength) | ||
328 | |||
329 | #define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \ | ||
330 | ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7) | ||
331 | #define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024) | ||
332 | #define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \ | ||
333 | (c)->algo_strength) | ||
334 | #define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength) | ||
335 | |||
336 | |||
337 | #define SSL_ALL 0xffffffffL | ||
338 | #define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\ | ||
339 | SSL_MAC_MASK) | ||
340 | #define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK) | ||
341 | |||
342 | /* Mostly for SSLv3 */ | ||
343 | #define SSL_PKEY_RSA_ENC 0 | ||
344 | #define SSL_PKEY_RSA_SIGN 1 | ||
345 | #define SSL_PKEY_DSA_SIGN 2 | ||
346 | #define SSL_PKEY_DH_RSA 3 | ||
347 | #define SSL_PKEY_DH_DSA 4 | ||
348 | #define SSL_PKEY_NUM 5 | ||
349 | |||
350 | /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | | ||
351 | * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) | ||
352 | * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN) | ||
353 | * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN | ||
354 | * SSL_aRSA <- RSA_ENC | RSA_SIGN | ||
355 | * SSL_aDSS <- DSA_SIGN | ||
356 | */ | ||
357 | |||
358 | /* | ||
359 | #define CERT_INVALID 0 | ||
360 | #define CERT_PUBLIC_KEY 1 | ||
361 | #define CERT_PRIVATE_KEY 2 | ||
362 | */ | ||
363 | |||
364 | typedef struct cert_pkey_st | ||
365 | { | ||
366 | X509 *x509; | ||
367 | EVP_PKEY *privatekey; | ||
368 | } CERT_PKEY; | ||
369 | |||
370 | typedef struct cert_st | ||
371 | { | ||
372 | /* Current active set */ | ||
373 | CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array | ||
374 | * Probably it would make more sense to store | ||
375 | * an index, not a pointer. */ | ||
376 | |||
377 | /* The following masks are for the key and auth | ||
378 | * algorithms that are supported by the certs below */ | ||
379 | int valid; | ||
380 | unsigned long mask; | ||
381 | unsigned long export_mask; | ||
382 | #ifndef OPENSSL_NO_RSA | ||
383 | RSA *rsa_tmp; | ||
384 | RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize); | ||
385 | #endif | ||
386 | #ifndef OPENSSL_NO_DH | ||
387 | DH *dh_tmp; | ||
388 | DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize); | ||
389 | #endif | ||
390 | |||
391 | CERT_PKEY pkeys[SSL_PKEY_NUM]; | ||
392 | |||
393 | int references; /* >1 only if SSL_copy_session_id is used */ | ||
394 | } CERT; | ||
395 | |||
396 | |||
397 | typedef struct sess_cert_st | ||
398 | { | ||
399 | STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */ | ||
400 | |||
401 | /* The 'peer_...' members are used only by clients. */ | ||
402 | int peer_cert_type; | ||
403 | |||
404 | CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */ | ||
405 | CERT_PKEY peer_pkeys[SSL_PKEY_NUM]; | ||
406 | /* Obviously we don't have the private keys of these, | ||
407 | * so maybe we shouldn't even use the CERT_PKEY type here. */ | ||
408 | |||
409 | #ifndef OPENSSL_NO_RSA | ||
410 | RSA *peer_rsa_tmp; /* not used for SSL 2 */ | ||
411 | #endif | ||
412 | #ifndef OPENSSL_NO_DH | ||
413 | DH *peer_dh_tmp; /* not used for SSL 2 */ | ||
414 | #endif | ||
415 | |||
416 | int references; /* actually always 1 at the moment */ | ||
417 | } SESS_CERT; | ||
418 | |||
419 | |||
420 | /*#define MAC_DEBUG */ | ||
421 | |||
422 | /*#define ERR_DEBUG */ | ||
423 | /*#define ABORT_DEBUG */ | ||
424 | /*#define PKT_DEBUG 1 */ | ||
425 | /*#define DES_DEBUG */ | ||
426 | /*#define DES_OFB_DEBUG */ | ||
427 | /*#define SSL_DEBUG */ | ||
428 | /*#define RSA_DEBUG */ | ||
429 | /*#define IDEA_DEBUG */ | ||
430 | |||
431 | #define FP_ICC (int (*)(const void *,const void *)) | ||
432 | #define ssl_put_cipher_by_char(ssl,ciph,ptr) \ | ||
433 | ((ssl)->method->put_cipher_by_char((ciph),(ptr))) | ||
434 | #define ssl_get_cipher_by_char(ssl,ptr) \ | ||
435 | ((ssl)->method->get_cipher_by_char(ptr)) | ||
436 | |||
437 | /* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff | ||
438 | * It is a bit of a mess of functions, but hell, think of it as | ||
439 | * an opaque structure :-) */ | ||
440 | typedef struct ssl3_enc_method | ||
441 | { | ||
442 | int (*enc)(SSL *, int); | ||
443 | int (*mac)(SSL *, unsigned char *, int); | ||
444 | int (*setup_key_block)(SSL *); | ||
445 | int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int); | ||
446 | int (*change_cipher_state)(SSL *, int); | ||
447 | int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *); | ||
448 | int finish_mac_length; | ||
449 | int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *); | ||
450 | const char *client_finished_label; | ||
451 | int client_finished_label_len; | ||
452 | const char *server_finished_label; | ||
453 | int server_finished_label_len; | ||
454 | int (*alert_value)(int); | ||
455 | } SSL3_ENC_METHOD; | ||
456 | |||
457 | /* Used for holding the relevant compression methods loaded into SSL_CTX */ | ||
458 | typedef struct ssl3_comp_st | ||
459 | { | ||
460 | int comp_id; /* The identifier byte for this compression type */ | ||
461 | char *name; /* Text name used for the compression type */ | ||
462 | COMP_METHOD *method; /* The method :-) */ | ||
463 | } SSL3_COMP; | ||
464 | |||
465 | extern SSL3_ENC_METHOD ssl3_undef_enc_method; | ||
466 | OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[]; | ||
467 | OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[]; | ||
468 | |||
469 | #ifdef OPENSSL_SYS_VMS | ||
470 | #undef SSL_COMP_get_compression_methods | ||
471 | #define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods | ||
472 | #endif | ||
473 | |||
474 | |||
475 | SSL_METHOD *ssl_bad_method(int ver); | ||
476 | SSL_METHOD *sslv2_base_method(void); | ||
477 | SSL_METHOD *sslv23_base_method(void); | ||
478 | SSL_METHOD *sslv3_base_method(void); | ||
479 | |||
480 | void ssl_clear_cipher_ctx(SSL *s); | ||
481 | int ssl_clear_bad_session(SSL *s); | ||
482 | CERT *ssl_cert_new(void); | ||
483 | CERT *ssl_cert_dup(CERT *cert); | ||
484 | int ssl_cert_inst(CERT **o); | ||
485 | void ssl_cert_free(CERT *c); | ||
486 | SESS_CERT *ssl_sess_cert_new(void); | ||
487 | void ssl_sess_cert_free(SESS_CERT *sc); | ||
488 | int ssl_set_peer_cert_type(SESS_CERT *c, int type); | ||
489 | int ssl_get_new_session(SSL *s, int session); | ||
490 | int ssl_get_prev_session(SSL *s, unsigned char *session,int len); | ||
491 | int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b); | ||
492 | int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, | ||
493 | const SSL_CIPHER * const *bp); | ||
494 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | ||
495 | STACK_OF(SSL_CIPHER) **skp); | ||
496 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p, | ||
497 | int (*put_cb)(const SSL_CIPHER *, unsigned char *)); | ||
498 | STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, | ||
499 | STACK_OF(SSL_CIPHER) **pref, | ||
500 | STACK_OF(SSL_CIPHER) **sorted, | ||
501 | const char *rule_str); | ||
502 | void ssl_update_cache(SSL *s, int mode); | ||
503 | int ssl_cipher_get_evp(const SSL_SESSION *s,const EVP_CIPHER **enc, | ||
504 | const EVP_MD **md,SSL_COMP **comp); | ||
505 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk); | ||
506 | int ssl_undefined_function(SSL *s); | ||
507 | int ssl_undefined_const_function(const SSL *s); | ||
508 | X509 *ssl_get_server_send_cert(SSL *); | ||
509 | EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); | ||
510 | int ssl_cert_type(X509 *x,EVP_PKEY *pkey); | ||
511 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher); | ||
512 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); | ||
513 | int ssl_verify_alarm_type(long type); | ||
514 | |||
515 | int ssl2_enc_init(SSL *s, int client); | ||
516 | int ssl2_generate_key_material(SSL *s); | ||
517 | void ssl2_enc(SSL *s,int send_data); | ||
518 | void ssl2_mac(SSL *s,unsigned char *mac,int send_data); | ||
519 | SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); | ||
520 | int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | ||
521 | int ssl2_part_read(SSL *s, unsigned long f, int i); | ||
522 | int ssl2_do_write(SSL *s); | ||
523 | int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data); | ||
524 | void ssl2_return_error(SSL *s,int reason); | ||
525 | void ssl2_write_error(SSL *s); | ||
526 | int ssl2_num_ciphers(void); | ||
527 | SSL_CIPHER *ssl2_get_cipher(unsigned int u); | ||
528 | int ssl2_new(SSL *s); | ||
529 | void ssl2_free(SSL *s); | ||
530 | int ssl2_accept(SSL *s); | ||
531 | int ssl2_connect(SSL *s); | ||
532 | int ssl2_read(SSL *s, void *buf, int len); | ||
533 | int ssl2_peek(SSL *s, void *buf, int len); | ||
534 | int ssl2_write(SSL *s, const void *buf, int len); | ||
535 | int ssl2_shutdown(SSL *s); | ||
536 | void ssl2_clear(SSL *s); | ||
537 | long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg); | ||
538 | long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); | ||
539 | long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
540 | long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | ||
541 | int ssl2_pending(const SSL *s); | ||
542 | |||
543 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p); | ||
544 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | ||
545 | void ssl3_init_finished_mac(SSL *s); | ||
546 | int ssl3_send_server_certificate(SSL *s); | ||
547 | int ssl3_get_finished(SSL *s,int state_a,int state_b); | ||
548 | int ssl3_setup_key_block(SSL *s); | ||
549 | int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); | ||
550 | int ssl3_change_cipher_state(SSL *s,int which); | ||
551 | void ssl3_cleanup_key_block(SSL *s); | ||
552 | int ssl3_do_write(SSL *s,int type); | ||
553 | void ssl3_send_alert(SSL *s,int level, int desc); | ||
554 | int ssl3_generate_master_secret(SSL *s, unsigned char *out, | ||
555 | unsigned char *p, int len); | ||
556 | int ssl3_get_req_cert_type(SSL *s,unsigned char *p); | ||
557 | long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); | ||
558 | int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen); | ||
559 | int ssl3_num_ciphers(void); | ||
560 | SSL_CIPHER *ssl3_get_cipher(unsigned int u); | ||
561 | int ssl3_renegotiate(SSL *ssl); | ||
562 | int ssl3_renegotiate_check(SSL *ssl); | ||
563 | int ssl3_dispatch_alert(SSL *s); | ||
564 | int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek); | ||
565 | int ssl3_write_bytes(SSL *s, int type, const void *buf, int len); | ||
566 | int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2, | ||
567 | const char *sender, int slen,unsigned char *p); | ||
568 | int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
569 | void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len); | ||
570 | int ssl3_enc(SSL *s, int send_data); | ||
571 | int ssl3_mac(SSL *ssl, unsigned char *md, int send_data); | ||
572 | unsigned long ssl3_output_cert_chain(SSL *s, X509 *x); | ||
573 | SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *clnt, | ||
574 | STACK_OF(SSL_CIPHER) *srvr); | ||
575 | int ssl3_setup_buffers(SSL *s); | ||
576 | int ssl3_new(SSL *s); | ||
577 | void ssl3_free(SSL *s); | ||
578 | int ssl3_accept(SSL *s); | ||
579 | int ssl3_connect(SSL *s); | ||
580 | int ssl3_read(SSL *s, void *buf, int len); | ||
581 | int ssl3_peek(SSL *s, void *buf, int len); | ||
582 | int ssl3_write(SSL *s, const void *buf, int len); | ||
583 | int ssl3_shutdown(SSL *s); | ||
584 | void ssl3_clear(SSL *s); | ||
585 | long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg); | ||
586 | long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg); | ||
587 | long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
588 | long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | ||
589 | int ssl3_pending(const SSL *s); | ||
590 | |||
591 | int ssl23_accept(SSL *s); | ||
592 | int ssl23_connect(SSL *s); | ||
593 | int ssl23_read_bytes(SSL *s, int n); | ||
594 | int ssl23_write_bytes(SSL *s); | ||
595 | |||
596 | int tls1_new(SSL *s); | ||
597 | void tls1_free(SSL *s); | ||
598 | void tls1_clear(SSL *s); | ||
599 | long tls1_ctrl(SSL *s,int cmd, long larg, void *parg); | ||
600 | long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
601 | SSL_METHOD *tlsv1_base_method(void ); | ||
602 | |||
603 | int ssl_init_wbio_buffer(SSL *s, int push); | ||
604 | void ssl_free_wbio_buffer(SSL *s); | ||
605 | |||
606 | int tls1_change_cipher_state(SSL *s, int which); | ||
607 | int tls1_setup_key_block(SSL *s); | ||
608 | int tls1_enc(SSL *s, int snd); | ||
609 | int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | ||
610 | const char *str, int slen, unsigned char *p); | ||
611 | int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
612 | int tls1_mac(SSL *ssl, unsigned char *md, int snd); | ||
613 | int tls1_generate_master_secret(SSL *s, unsigned char *out, | ||
614 | unsigned char *p, int len); | ||
615 | int tls1_alert_code(int code); | ||
616 | int ssl3_alert_code(int code); | ||
617 | int ssl_ok(SSL *s); | ||
618 | |||
619 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n); | ||
620 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); | ||
621 | |||
622 | |||
623 | #endif | ||
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c deleted file mode 100644 index fb0bd4d045..0000000000 --- a/src/lib/libssl/ssl_rsa.c +++ /dev/null | |||
@@ -1,817 +0,0 @@ | |||
1 | /* ssl/ssl_rsa.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include "ssl_locl.h" | ||
61 | #include <openssl/bio.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/x509.h> | ||
65 | #include <openssl/pem.h> | ||
66 | |||
67 | static int ssl_set_cert(CERT *c, X509 *x509); | ||
68 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); | ||
69 | int SSL_use_certificate(SSL *ssl, X509 *x) | ||
70 | { | ||
71 | if (x == NULL) | ||
72 | { | ||
73 | SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER); | ||
74 | return(0); | ||
75 | } | ||
76 | if (!ssl_cert_inst(&ssl->cert)) | ||
77 | { | ||
78 | SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
79 | return(0); | ||
80 | } | ||
81 | return(ssl_set_cert(ssl->cert,x)); | ||
82 | } | ||
83 | |||
84 | #ifndef OPENSSL_NO_STDIO | ||
85 | int SSL_use_certificate_file(SSL *ssl, const char *file, int type) | ||
86 | { | ||
87 | int j; | ||
88 | BIO *in; | ||
89 | int ret=0; | ||
90 | X509 *x=NULL; | ||
91 | |||
92 | in=BIO_new(BIO_s_file_internal()); | ||
93 | if (in == NULL) | ||
94 | { | ||
95 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB); | ||
96 | goto end; | ||
97 | } | ||
98 | |||
99 | if (BIO_read_filename(in,file) <= 0) | ||
100 | { | ||
101 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB); | ||
102 | goto end; | ||
103 | } | ||
104 | if (type == SSL_FILETYPE_ASN1) | ||
105 | { | ||
106 | j=ERR_R_ASN1_LIB; | ||
107 | x=d2i_X509_bio(in,NULL); | ||
108 | } | ||
109 | else if (type == SSL_FILETYPE_PEM) | ||
110 | { | ||
111 | j=ERR_R_PEM_LIB; | ||
112 | x=PEM_read_bio_X509(in,NULL,ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
117 | goto end; | ||
118 | } | ||
119 | |||
120 | if (x == NULL) | ||
121 | { | ||
122 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,j); | ||
123 | goto end; | ||
124 | } | ||
125 | |||
126 | ret=SSL_use_certificate(ssl,x); | ||
127 | end: | ||
128 | if (x != NULL) X509_free(x); | ||
129 | if (in != NULL) BIO_free(in); | ||
130 | return(ret); | ||
131 | } | ||
132 | #endif | ||
133 | |||
134 | int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len) | ||
135 | { | ||
136 | X509 *x; | ||
137 | int ret; | ||
138 | |||
139 | x=d2i_X509(NULL,&d,(long)len); | ||
140 | if (x == NULL) | ||
141 | { | ||
142 | SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB); | ||
143 | return(0); | ||
144 | } | ||
145 | |||
146 | ret=SSL_use_certificate(ssl,x); | ||
147 | X509_free(x); | ||
148 | return(ret); | ||
149 | } | ||
150 | |||
151 | #ifndef OPENSSL_NO_RSA | ||
152 | int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa) | ||
153 | { | ||
154 | EVP_PKEY *pkey; | ||
155 | int ret; | ||
156 | |||
157 | if (rsa == NULL) | ||
158 | { | ||
159 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
160 | return(0); | ||
161 | } | ||
162 | if (!ssl_cert_inst(&ssl->cert)) | ||
163 | { | ||
164 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
165 | return(0); | ||
166 | } | ||
167 | if ((pkey=EVP_PKEY_new()) == NULL) | ||
168 | { | ||
169 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB); | ||
170 | return(0); | ||
171 | } | ||
172 | |||
173 | RSA_up_ref(rsa); | ||
174 | EVP_PKEY_assign_RSA(pkey,rsa); | ||
175 | |||
176 | ret=ssl_set_pkey(ssl->cert,pkey); | ||
177 | EVP_PKEY_free(pkey); | ||
178 | return(ret); | ||
179 | } | ||
180 | #endif | ||
181 | |||
182 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey) | ||
183 | { | ||
184 | int i,ok=0,bad=0; | ||
185 | |||
186 | i=ssl_cert_type(NULL,pkey); | ||
187 | if (i < 0) | ||
188 | { | ||
189 | SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
190 | return(0); | ||
191 | } | ||
192 | |||
193 | if (c->pkeys[i].x509 != NULL) | ||
194 | { | ||
195 | EVP_PKEY *pktmp; | ||
196 | pktmp = X509_get_pubkey(c->pkeys[i].x509); | ||
197 | EVP_PKEY_copy_parameters(pktmp,pkey); | ||
198 | EVP_PKEY_free(pktmp); | ||
199 | ERR_clear_error(); | ||
200 | |||
201 | #ifndef OPENSSL_NO_RSA | ||
202 | /* Don't check the public/private key, this is mostly | ||
203 | * for smart cards. */ | ||
204 | if ((pkey->type == EVP_PKEY_RSA) && | ||
205 | (RSA_flags(pkey->pkey.rsa) & | ||
206 | RSA_METHOD_FLAG_NO_CHECK)) | ||
207 | ok=1; | ||
208 | else | ||
209 | #endif | ||
210 | if (!X509_check_private_key(c->pkeys[i].x509,pkey)) | ||
211 | { | ||
212 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | ||
213 | { | ||
214 | i=(i == SSL_PKEY_DH_RSA)? | ||
215 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
216 | |||
217 | if (c->pkeys[i].x509 == NULL) | ||
218 | ok=1; | ||
219 | else | ||
220 | { | ||
221 | if (!X509_check_private_key( | ||
222 | c->pkeys[i].x509,pkey)) | ||
223 | bad=1; | ||
224 | else | ||
225 | ok=1; | ||
226 | } | ||
227 | } | ||
228 | else | ||
229 | bad=1; | ||
230 | } | ||
231 | else | ||
232 | ok=1; | ||
233 | } | ||
234 | else | ||
235 | ok=1; | ||
236 | |||
237 | if (bad) | ||
238 | { | ||
239 | X509_free(c->pkeys[i].x509); | ||
240 | c->pkeys[i].x509=NULL; | ||
241 | return(0); | ||
242 | } | ||
243 | |||
244 | ERR_clear_error(); /* make sure no error from X509_check_private_key() | ||
245 | * is left if we have chosen to ignore it */ | ||
246 | if (c->pkeys[i].privatekey != NULL) | ||
247 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
248 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
249 | c->pkeys[i].privatekey=pkey; | ||
250 | c->key= &(c->pkeys[i]); | ||
251 | |||
252 | c->valid=0; | ||
253 | return(1); | ||
254 | } | ||
255 | |||
256 | #ifndef OPENSSL_NO_RSA | ||
257 | #ifndef OPENSSL_NO_STDIO | ||
258 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type) | ||
259 | { | ||
260 | int j,ret=0; | ||
261 | BIO *in; | ||
262 | RSA *rsa=NULL; | ||
263 | |||
264 | in=BIO_new(BIO_s_file_internal()); | ||
265 | if (in == NULL) | ||
266 | { | ||
267 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
268 | goto end; | ||
269 | } | ||
270 | |||
271 | if (BIO_read_filename(in,file) <= 0) | ||
272 | { | ||
273 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
274 | goto end; | ||
275 | } | ||
276 | if (type == SSL_FILETYPE_ASN1) | ||
277 | { | ||
278 | j=ERR_R_ASN1_LIB; | ||
279 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
280 | } | ||
281 | else if (type == SSL_FILETYPE_PEM) | ||
282 | { | ||
283 | j=ERR_R_PEM_LIB; | ||
284 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
285 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | ||
286 | } | ||
287 | else | ||
288 | { | ||
289 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
290 | goto end; | ||
291 | } | ||
292 | if (rsa == NULL) | ||
293 | { | ||
294 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j); | ||
295 | goto end; | ||
296 | } | ||
297 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
298 | RSA_free(rsa); | ||
299 | end: | ||
300 | if (in != NULL) BIO_free(in); | ||
301 | return(ret); | ||
302 | } | ||
303 | #endif | ||
304 | |||
305 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len) | ||
306 | { | ||
307 | int ret; | ||
308 | const unsigned char *p; | ||
309 | RSA *rsa; | ||
310 | |||
311 | p=d; | ||
312 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
313 | { | ||
314 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
315 | return(0); | ||
316 | } | ||
317 | |||
318 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
319 | RSA_free(rsa); | ||
320 | return(ret); | ||
321 | } | ||
322 | #endif /* !OPENSSL_NO_RSA */ | ||
323 | |||
324 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey) | ||
325 | { | ||
326 | int ret; | ||
327 | |||
328 | if (pkey == NULL) | ||
329 | { | ||
330 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
331 | return(0); | ||
332 | } | ||
333 | if (!ssl_cert_inst(&ssl->cert)) | ||
334 | { | ||
335 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
336 | return(0); | ||
337 | } | ||
338 | ret=ssl_set_pkey(ssl->cert,pkey); | ||
339 | return(ret); | ||
340 | } | ||
341 | |||
342 | #ifndef OPENSSL_NO_STDIO | ||
343 | int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type) | ||
344 | { | ||
345 | int j,ret=0; | ||
346 | BIO *in; | ||
347 | EVP_PKEY *pkey=NULL; | ||
348 | |||
349 | in=BIO_new(BIO_s_file_internal()); | ||
350 | if (in == NULL) | ||
351 | { | ||
352 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
353 | goto end; | ||
354 | } | ||
355 | |||
356 | if (BIO_read_filename(in,file) <= 0) | ||
357 | { | ||
358 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
359 | goto end; | ||
360 | } | ||
361 | if (type == SSL_FILETYPE_PEM) | ||
362 | { | ||
363 | j=ERR_R_PEM_LIB; | ||
364 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
365 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
370 | goto end; | ||
371 | } | ||
372 | if (pkey == NULL) | ||
373 | { | ||
374 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j); | ||
375 | goto end; | ||
376 | } | ||
377 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
378 | EVP_PKEY_free(pkey); | ||
379 | end: | ||
380 | if (in != NULL) BIO_free(in); | ||
381 | return(ret); | ||
382 | } | ||
383 | #endif | ||
384 | |||
385 | int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len) | ||
386 | { | ||
387 | int ret; | ||
388 | unsigned char *p; | ||
389 | EVP_PKEY *pkey; | ||
390 | |||
391 | p=d; | ||
392 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
393 | { | ||
394 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
395 | return(0); | ||
396 | } | ||
397 | |||
398 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
399 | EVP_PKEY_free(pkey); | ||
400 | return(ret); | ||
401 | } | ||
402 | |||
403 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) | ||
404 | { | ||
405 | if (x == NULL) | ||
406 | { | ||
407 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER); | ||
408 | return(0); | ||
409 | } | ||
410 | if (!ssl_cert_inst(&ctx->cert)) | ||
411 | { | ||
412 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
413 | return(0); | ||
414 | } | ||
415 | return(ssl_set_cert(ctx->cert, x)); | ||
416 | } | ||
417 | |||
418 | static int ssl_set_cert(CERT *c, X509 *x) | ||
419 | { | ||
420 | EVP_PKEY *pkey; | ||
421 | int i,ok=0,bad=0; | ||
422 | |||
423 | pkey=X509_get_pubkey(x); | ||
424 | if (pkey == NULL) | ||
425 | { | ||
426 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB); | ||
427 | return(0); | ||
428 | } | ||
429 | |||
430 | i=ssl_cert_type(x,pkey); | ||
431 | if (i < 0) | ||
432 | { | ||
433 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
434 | EVP_PKEY_free(pkey); | ||
435 | return(0); | ||
436 | } | ||
437 | |||
438 | if (c->pkeys[i].privatekey != NULL) | ||
439 | { | ||
440 | EVP_PKEY_copy_parameters(pkey,c->pkeys[i].privatekey); | ||
441 | ERR_clear_error(); | ||
442 | |||
443 | #ifndef OPENSSL_NO_RSA | ||
444 | /* Don't check the public/private key, this is mostly | ||
445 | * for smart cards. */ | ||
446 | if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) && | ||
447 | (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) & | ||
448 | RSA_METHOD_FLAG_NO_CHECK)) | ||
449 | ok=1; | ||
450 | else | ||
451 | #endif | ||
452 | { | ||
453 | if (!X509_check_private_key(x,c->pkeys[i].privatekey)) | ||
454 | { | ||
455 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | ||
456 | { | ||
457 | i=(i == SSL_PKEY_DH_RSA)? | ||
458 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
459 | |||
460 | if (c->pkeys[i].privatekey == NULL) | ||
461 | ok=1; | ||
462 | else | ||
463 | { | ||
464 | if (!X509_check_private_key(x, | ||
465 | c->pkeys[i].privatekey)) | ||
466 | bad=1; | ||
467 | else | ||
468 | ok=1; | ||
469 | } | ||
470 | } | ||
471 | else | ||
472 | bad=1; | ||
473 | } | ||
474 | else | ||
475 | ok=1; | ||
476 | } /* OPENSSL_NO_RSA */ | ||
477 | } | ||
478 | else | ||
479 | ok=1; | ||
480 | |||
481 | EVP_PKEY_free(pkey); | ||
482 | if (bad) | ||
483 | { | ||
484 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
485 | c->pkeys[i].privatekey=NULL; | ||
486 | } | ||
487 | |||
488 | if (c->pkeys[i].x509 != NULL) | ||
489 | X509_free(c->pkeys[i].x509); | ||
490 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
491 | c->pkeys[i].x509=x; | ||
492 | c->key= &(c->pkeys[i]); | ||
493 | |||
494 | c->valid=0; | ||
495 | return(1); | ||
496 | } | ||
497 | |||
498 | #ifndef OPENSSL_NO_STDIO | ||
499 | int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type) | ||
500 | { | ||
501 | int j; | ||
502 | BIO *in; | ||
503 | int ret=0; | ||
504 | X509 *x=NULL; | ||
505 | |||
506 | in=BIO_new(BIO_s_file_internal()); | ||
507 | if (in == NULL) | ||
508 | { | ||
509 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB); | ||
510 | goto end; | ||
511 | } | ||
512 | |||
513 | if (BIO_read_filename(in,file) <= 0) | ||
514 | { | ||
515 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB); | ||
516 | goto end; | ||
517 | } | ||
518 | if (type == SSL_FILETYPE_ASN1) | ||
519 | { | ||
520 | j=ERR_R_ASN1_LIB; | ||
521 | x=d2i_X509_bio(in,NULL); | ||
522 | } | ||
523 | else if (type == SSL_FILETYPE_PEM) | ||
524 | { | ||
525 | j=ERR_R_PEM_LIB; | ||
526 | x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
527 | } | ||
528 | else | ||
529 | { | ||
530 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
531 | goto end; | ||
532 | } | ||
533 | |||
534 | if (x == NULL) | ||
535 | { | ||
536 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j); | ||
537 | goto end; | ||
538 | } | ||
539 | |||
540 | ret=SSL_CTX_use_certificate(ctx,x); | ||
541 | end: | ||
542 | if (x != NULL) X509_free(x); | ||
543 | if (in != NULL) BIO_free(in); | ||
544 | return(ret); | ||
545 | } | ||
546 | #endif | ||
547 | |||
548 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d) | ||
549 | { | ||
550 | X509 *x; | ||
551 | int ret; | ||
552 | |||
553 | x=d2i_X509(NULL,&d,(long)len); | ||
554 | if (x == NULL) | ||
555 | { | ||
556 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB); | ||
557 | return(0); | ||
558 | } | ||
559 | |||
560 | ret=SSL_CTX_use_certificate(ctx,x); | ||
561 | X509_free(x); | ||
562 | return(ret); | ||
563 | } | ||
564 | |||
565 | #ifndef OPENSSL_NO_RSA | ||
566 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa) | ||
567 | { | ||
568 | int ret; | ||
569 | EVP_PKEY *pkey; | ||
570 | |||
571 | if (rsa == NULL) | ||
572 | { | ||
573 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
574 | return(0); | ||
575 | } | ||
576 | if (!ssl_cert_inst(&ctx->cert)) | ||
577 | { | ||
578 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
579 | return(0); | ||
580 | } | ||
581 | if ((pkey=EVP_PKEY_new()) == NULL) | ||
582 | { | ||
583 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB); | ||
584 | return(0); | ||
585 | } | ||
586 | |||
587 | RSA_up_ref(rsa); | ||
588 | EVP_PKEY_assign_RSA(pkey,rsa); | ||
589 | |||
590 | ret=ssl_set_pkey(ctx->cert, pkey); | ||
591 | EVP_PKEY_free(pkey); | ||
592 | return(ret); | ||
593 | } | ||
594 | |||
595 | #ifndef OPENSSL_NO_STDIO | ||
596 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type) | ||
597 | { | ||
598 | int j,ret=0; | ||
599 | BIO *in; | ||
600 | RSA *rsa=NULL; | ||
601 | |||
602 | in=BIO_new(BIO_s_file_internal()); | ||
603 | if (in == NULL) | ||
604 | { | ||
605 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
606 | goto end; | ||
607 | } | ||
608 | |||
609 | if (BIO_read_filename(in,file) <= 0) | ||
610 | { | ||
611 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
612 | goto end; | ||
613 | } | ||
614 | if (type == SSL_FILETYPE_ASN1) | ||
615 | { | ||
616 | j=ERR_R_ASN1_LIB; | ||
617 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
618 | } | ||
619 | else if (type == SSL_FILETYPE_PEM) | ||
620 | { | ||
621 | j=ERR_R_PEM_LIB; | ||
622 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
623 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
624 | } | ||
625 | else | ||
626 | { | ||
627 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
628 | goto end; | ||
629 | } | ||
630 | if (rsa == NULL) | ||
631 | { | ||
632 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j); | ||
633 | goto end; | ||
634 | } | ||
635 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
636 | RSA_free(rsa); | ||
637 | end: | ||
638 | if (in != NULL) BIO_free(in); | ||
639 | return(ret); | ||
640 | } | ||
641 | #endif | ||
642 | |||
643 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len) | ||
644 | { | ||
645 | int ret; | ||
646 | const unsigned char *p; | ||
647 | RSA *rsa; | ||
648 | |||
649 | p=d; | ||
650 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
651 | { | ||
652 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
653 | return(0); | ||
654 | } | ||
655 | |||
656 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
657 | RSA_free(rsa); | ||
658 | return(ret); | ||
659 | } | ||
660 | #endif /* !OPENSSL_NO_RSA */ | ||
661 | |||
662 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey) | ||
663 | { | ||
664 | if (pkey == NULL) | ||
665 | { | ||
666 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
667 | return(0); | ||
668 | } | ||
669 | if (!ssl_cert_inst(&ctx->cert)) | ||
670 | { | ||
671 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
672 | return(0); | ||
673 | } | ||
674 | return(ssl_set_pkey(ctx->cert,pkey)); | ||
675 | } | ||
676 | |||
677 | #ifndef OPENSSL_NO_STDIO | ||
678 | int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) | ||
679 | { | ||
680 | int j,ret=0; | ||
681 | BIO *in; | ||
682 | EVP_PKEY *pkey=NULL; | ||
683 | |||
684 | in=BIO_new(BIO_s_file_internal()); | ||
685 | if (in == NULL) | ||
686 | { | ||
687 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
688 | goto end; | ||
689 | } | ||
690 | |||
691 | if (BIO_read_filename(in,file) <= 0) | ||
692 | { | ||
693 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
694 | goto end; | ||
695 | } | ||
696 | if (type == SSL_FILETYPE_PEM) | ||
697 | { | ||
698 | j=ERR_R_PEM_LIB; | ||
699 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
700 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
701 | } | ||
702 | else | ||
703 | { | ||
704 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
705 | goto end; | ||
706 | } | ||
707 | if (pkey == NULL) | ||
708 | { | ||
709 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j); | ||
710 | goto end; | ||
711 | } | ||
712 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
713 | EVP_PKEY_free(pkey); | ||
714 | end: | ||
715 | if (in != NULL) BIO_free(in); | ||
716 | return(ret); | ||
717 | } | ||
718 | #endif | ||
719 | |||
720 | int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d, | ||
721 | long len) | ||
722 | { | ||
723 | int ret; | ||
724 | unsigned char *p; | ||
725 | EVP_PKEY *pkey; | ||
726 | |||
727 | p=d; | ||
728 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
729 | { | ||
730 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
731 | return(0); | ||
732 | } | ||
733 | |||
734 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
735 | EVP_PKEY_free(pkey); | ||
736 | return(ret); | ||
737 | } | ||
738 | |||
739 | |||
740 | #ifndef OPENSSL_NO_STDIO | ||
741 | /* Read a file that contains our certificate in "PEM" format, | ||
742 | * possibly followed by a sequence of CA certificates that should be | ||
743 | * sent to the peer in the Certificate message. | ||
744 | */ | ||
745 | int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | ||
746 | { | ||
747 | BIO *in; | ||
748 | int ret=0; | ||
749 | X509 *x=NULL; | ||
750 | |||
751 | in=BIO_new(BIO_s_file_internal()); | ||
752 | if (in == NULL) | ||
753 | { | ||
754 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_BUF_LIB); | ||
755 | goto end; | ||
756 | } | ||
757 | |||
758 | if (BIO_read_filename(in,file) <= 0) | ||
759 | { | ||
760 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_SYS_LIB); | ||
761 | goto end; | ||
762 | } | ||
763 | |||
764 | x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
765 | if (x == NULL) | ||
766 | { | ||
767 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_PEM_LIB); | ||
768 | goto end; | ||
769 | } | ||
770 | |||
771 | ret=SSL_CTX_use_certificate(ctx,x); | ||
772 | if (ERR_peek_error() != 0) | ||
773 | ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */ | ||
774 | if (ret) | ||
775 | { | ||
776 | /* If we could set up our certificate, now proceed to | ||
777 | * the CA certificates. | ||
778 | */ | ||
779 | X509 *ca; | ||
780 | int r; | ||
781 | unsigned long err; | ||
782 | |||
783 | if (ctx->extra_certs != NULL) | ||
784 | { | ||
785 | sk_X509_pop_free(ctx->extra_certs, X509_free); | ||
786 | ctx->extra_certs = NULL; | ||
787 | } | ||
788 | |||
789 | while ((ca = PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata)) | ||
790 | != NULL) | ||
791 | { | ||
792 | r = SSL_CTX_add_extra_chain_cert(ctx, ca); | ||
793 | if (!r) | ||
794 | { | ||
795 | X509_free(ca); | ||
796 | ret = 0; | ||
797 | goto end; | ||
798 | } | ||
799 | /* Note that we must not free r if it was successfully | ||
800 | * added to the chain (while we must free the main | ||
801 | * certificate, since its reference count is increased | ||
802 | * by SSL_CTX_use_certificate). */ | ||
803 | } | ||
804 | /* When the while loop ends, it's usually just EOF. */ | ||
805 | err = ERR_peek_last_error(); | ||
806 | if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) | ||
807 | ERR_clear_error(); | ||
808 | else | ||
809 | ret = 0; /* some real error */ | ||
810 | } | ||
811 | |||
812 | end: | ||
813 | if (x != NULL) X509_free(x); | ||
814 | if (in != NULL) BIO_free(in); | ||
815 | return(ret); | ||
816 | } | ||
817 | #endif | ||
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c deleted file mode 100644 index 2ba8b9612e..0000000000 --- a/src/lib/libssl/ssl_sess.c +++ /dev/null | |||
@@ -1,755 +0,0 @@ | |||
1 | /* ssl/ssl_sess.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/lhash.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include "ssl_locl.h" | ||
63 | |||
64 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s); | ||
65 | static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s); | ||
66 | static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck); | ||
67 | |||
68 | SSL_SESSION *SSL_get_session(const SSL *ssl) | ||
69 | /* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */ | ||
70 | { | ||
71 | return(ssl->session); | ||
72 | } | ||
73 | |||
74 | SSL_SESSION *SSL_get1_session(SSL *ssl) | ||
75 | /* variant of SSL_get_session: caller really gets something */ | ||
76 | { | ||
77 | SSL_SESSION *sess; | ||
78 | /* Need to lock this all up rather than just use CRYPTO_add so that | ||
79 | * somebody doesn't free ssl->session between when we check it's | ||
80 | * non-null and when we up the reference count. */ | ||
81 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION); | ||
82 | sess = ssl->session; | ||
83 | if(sess) | ||
84 | sess->references++; | ||
85 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION); | ||
86 | return(sess); | ||
87 | } | ||
88 | |||
89 | int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
90 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
91 | { | ||
92 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, argl, argp, | ||
93 | new_func, dup_func, free_func); | ||
94 | } | ||
95 | |||
96 | int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg) | ||
97 | { | ||
98 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
99 | } | ||
100 | |||
101 | void *SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx) | ||
102 | { | ||
103 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
104 | } | ||
105 | |||
106 | SSL_SESSION *SSL_SESSION_new(void) | ||
107 | { | ||
108 | SSL_SESSION *ss; | ||
109 | |||
110 | ss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION)); | ||
111 | if (ss == NULL) | ||
112 | { | ||
113 | SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE); | ||
114 | return(0); | ||
115 | } | ||
116 | memset(ss,0,sizeof(SSL_SESSION)); | ||
117 | |||
118 | ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ | ||
119 | ss->references=1; | ||
120 | ss->timeout=60*5+4; /* 5 minute timeout by default */ | ||
121 | ss->time=(unsigned long)time(NULL); | ||
122 | ss->prev=NULL; | ||
123 | ss->next=NULL; | ||
124 | ss->compress_meth=0; | ||
125 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); | ||
126 | return(ss); | ||
127 | } | ||
128 | |||
129 | /* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1 | ||
130 | * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly | ||
131 | * until we have no conflict is going to complete in one iteration pretty much | ||
132 | * "most" of the time (btw: understatement). So, if it takes us 10 iterations | ||
133 | * and we still can't avoid a conflict - well that's a reasonable point to call | ||
134 | * it quits. Either the RAND code is broken or someone is trying to open roughly | ||
135 | * very close to 2^128 (or 2^256) SSL sessions to our server. How you might | ||
136 | * store that many sessions is perhaps a more interesting question ... */ | ||
137 | |||
138 | #define MAX_SESS_ID_ATTEMPTS 10 | ||
139 | static int def_generate_session_id(const SSL *ssl, unsigned char *id, | ||
140 | unsigned int *id_len) | ||
141 | { | ||
142 | unsigned int retry = 0; | ||
143 | do | ||
144 | if(RAND_pseudo_bytes(id, *id_len) <= 0) | ||
145 | return 0; | ||
146 | while(SSL_has_matching_session_id(ssl, id, *id_len) && | ||
147 | (++retry < MAX_SESS_ID_ATTEMPTS)); | ||
148 | if(retry < MAX_SESS_ID_ATTEMPTS) | ||
149 | return 1; | ||
150 | /* else - woops a session_id match */ | ||
151 | /* XXX We should also check the external cache -- | ||
152 | * but the probability of a collision is negligible, and | ||
153 | * we could not prevent the concurrent creation of sessions | ||
154 | * with identical IDs since we currently don't have means | ||
155 | * to atomically check whether a session ID already exists | ||
156 | * and make a reservation for it if it does not | ||
157 | * (this problem applies to the internal cache as well). | ||
158 | */ | ||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | int ssl_get_new_session(SSL *s, int session) | ||
163 | { | ||
164 | /* This gets used by clients and servers. */ | ||
165 | |||
166 | unsigned int tmp; | ||
167 | SSL_SESSION *ss=NULL; | ||
168 | GEN_SESSION_CB cb = def_generate_session_id; | ||
169 | |||
170 | if ((ss=SSL_SESSION_new()) == NULL) return(0); | ||
171 | |||
172 | /* If the context has a default timeout, use it */ | ||
173 | if (s->ctx->session_timeout == 0) | ||
174 | ss->timeout=SSL_get_default_timeout(s); | ||
175 | else | ||
176 | ss->timeout=s->ctx->session_timeout; | ||
177 | |||
178 | if (s->session != NULL) | ||
179 | { | ||
180 | SSL_SESSION_free(s->session); | ||
181 | s->session=NULL; | ||
182 | } | ||
183 | |||
184 | if (session) | ||
185 | { | ||
186 | if (s->version == SSL2_VERSION) | ||
187 | { | ||
188 | ss->ssl_version=SSL2_VERSION; | ||
189 | ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH; | ||
190 | } | ||
191 | else if (s->version == SSL3_VERSION) | ||
192 | { | ||
193 | ss->ssl_version=SSL3_VERSION; | ||
194 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
195 | } | ||
196 | else if (s->version == TLS1_VERSION) | ||
197 | { | ||
198 | ss->ssl_version=TLS1_VERSION; | ||
199 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION); | ||
204 | SSL_SESSION_free(ss); | ||
205 | return(0); | ||
206 | } | ||
207 | /* Choose which callback will set the session ID */ | ||
208 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
209 | if(s->generate_session_id) | ||
210 | cb = s->generate_session_id; | ||
211 | else if(s->ctx->generate_session_id) | ||
212 | cb = s->ctx->generate_session_id; | ||
213 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
214 | /* Choose a session ID */ | ||
215 | tmp = ss->session_id_length; | ||
216 | if(!cb(s, ss->session_id, &tmp)) | ||
217 | { | ||
218 | /* The callback failed */ | ||
219 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, | ||
220 | SSL_R_SSL_SESSION_ID_CALLBACK_FAILED); | ||
221 | SSL_SESSION_free(ss); | ||
222 | return(0); | ||
223 | } | ||
224 | /* Don't allow the callback to set the session length to zero. | ||
225 | * nor set it higher than it was. */ | ||
226 | if(!tmp || (tmp > ss->session_id_length)) | ||
227 | { | ||
228 | /* The callback set an illegal length */ | ||
229 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, | ||
230 | SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH); | ||
231 | SSL_SESSION_free(ss); | ||
232 | return(0); | ||
233 | } | ||
234 | /* If the session length was shrunk and we're SSLv2, pad it */ | ||
235 | if((tmp < ss->session_id_length) && (s->version == SSL2_VERSION)) | ||
236 | memset(ss->session_id + tmp, 0, ss->session_id_length - tmp); | ||
237 | else | ||
238 | ss->session_id_length = tmp; | ||
239 | /* Finally, check for a conflict */ | ||
240 | if(SSL_has_matching_session_id(s, ss->session_id, | ||
241 | ss->session_id_length)) | ||
242 | { | ||
243 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, | ||
244 | SSL_R_SSL_SESSION_ID_CONFLICT); | ||
245 | SSL_SESSION_free(ss); | ||
246 | return(0); | ||
247 | } | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | ss->session_id_length=0; | ||
252 | } | ||
253 | |||
254 | if (s->sid_ctx_length > sizeof ss->sid_ctx) | ||
255 | { | ||
256 | SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); | ||
257 | SSL_SESSION_free(ss); | ||
258 | return 0; | ||
259 | } | ||
260 | memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length); | ||
261 | ss->sid_ctx_length=s->sid_ctx_length; | ||
262 | s->session=ss; | ||
263 | ss->ssl_version=s->version; | ||
264 | ss->verify_result = X509_V_OK; | ||
265 | |||
266 | return(1); | ||
267 | } | ||
268 | |||
269 | int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len) | ||
270 | { | ||
271 | /* This is used only by servers. */ | ||
272 | |||
273 | SSL_SESSION *ret=NULL,data; | ||
274 | int fatal = 0; | ||
275 | |||
276 | data.ssl_version=s->version; | ||
277 | data.session_id_length=len; | ||
278 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) | ||
279 | goto err; | ||
280 | memcpy(data.session_id,session_id,len); | ||
281 | |||
282 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | ||
283 | { | ||
284 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
285 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data); | ||
286 | if (ret != NULL) | ||
287 | /* don't allow other threads to steal it: */ | ||
288 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
289 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
290 | } | ||
291 | |||
292 | if (ret == NULL) | ||
293 | { | ||
294 | int copy=1; | ||
295 | |||
296 | s->ctx->stats.sess_miss++; | ||
297 | ret=NULL; | ||
298 | if (s->ctx->get_session_cb != NULL | ||
299 | && (ret=s->ctx->get_session_cb(s,session_id,len,©)) | ||
300 | != NULL) | ||
301 | { | ||
302 | s->ctx->stats.sess_cb_hit++; | ||
303 | |||
304 | /* Increment reference count now if the session callback | ||
305 | * asks us to do so (note that if the session structures | ||
306 | * returned by the callback are shared between threads, | ||
307 | * it must handle the reference count itself [i.e. copy == 0], | ||
308 | * or things won't be thread-safe). */ | ||
309 | if (copy) | ||
310 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
311 | |||
312 | /* Add the externally cached session to the internal | ||
313 | * cache as well if and only if we are supposed to. */ | ||
314 | if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE)) | ||
315 | /* The following should not return 1, otherwise, | ||
316 | * things are very strange */ | ||
317 | SSL_CTX_add_session(s->ctx,ret); | ||
318 | } | ||
319 | if (ret == NULL) | ||
320 | goto err; | ||
321 | } | ||
322 | |||
323 | /* Now ret is non-NULL, and we own one of its reference counts. */ | ||
324 | |||
325 | if((s->verify_mode&SSL_VERIFY_PEER) | ||
326 | && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length | ||
327 | || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length))) | ||
328 | { | ||
329 | /* We've found the session named by the client, but we don't | ||
330 | * want to use it in this context. */ | ||
331 | |||
332 | if (s->sid_ctx_length == 0) | ||
333 | { | ||
334 | /* application should have used SSL[_CTX]_set_session_id_context | ||
335 | * -- we could tolerate this and just pretend we never heard | ||
336 | * of this session, but then applications could effectively | ||
337 | * disable the session cache by accident without anyone noticing */ | ||
338 | |||
339 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED); | ||
340 | fatal = 1; | ||
341 | goto err; | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | #if 0 /* The client cannot always know when a session is not appropriate, | ||
346 | * so we shouldn't generate an error message. */ | ||
347 | |||
348 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | ||
349 | #endif | ||
350 | goto err; /* treat like cache miss */ | ||
351 | } | ||
352 | } | ||
353 | |||
354 | if (ret->cipher == NULL) | ||
355 | { | ||
356 | unsigned char buf[5],*p; | ||
357 | unsigned long l; | ||
358 | |||
359 | p=buf; | ||
360 | l=ret->cipher_id; | ||
361 | l2n(l,p); | ||
362 | if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR) | ||
363 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[2])); | ||
364 | else | ||
365 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[1])); | ||
366 | if (ret->cipher == NULL) | ||
367 | goto err; | ||
368 | } | ||
369 | |||
370 | |||
371 | #if 0 /* This is way too late. */ | ||
372 | |||
373 | /* If a thread got the session, then 'swaped', and another got | ||
374 | * it and then due to a time-out decided to 'OPENSSL_free' it we could | ||
375 | * be in trouble. So I'll increment it now, then double decrement | ||
376 | * later - am I speaking rubbish?. */ | ||
377 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
378 | #endif | ||
379 | |||
380 | if (ret->timeout < (long)(time(NULL) - ret->time)) /* timeout */ | ||
381 | { | ||
382 | s->ctx->stats.sess_timeout++; | ||
383 | /* remove it from the cache */ | ||
384 | SSL_CTX_remove_session(s->ctx,ret); | ||
385 | goto err; | ||
386 | } | ||
387 | |||
388 | s->ctx->stats.sess_hit++; | ||
389 | |||
390 | /* ret->time=time(NULL); */ /* rezero timeout? */ | ||
391 | /* again, just leave the session | ||
392 | * if it is the same session, we have just incremented and | ||
393 | * then decremented the reference count :-) */ | ||
394 | if (s->session != NULL) | ||
395 | SSL_SESSION_free(s->session); | ||
396 | s->session=ret; | ||
397 | s->verify_result = s->session->verify_result; | ||
398 | return(1); | ||
399 | |||
400 | err: | ||
401 | if (ret != NULL) | ||
402 | SSL_SESSION_free(ret); | ||
403 | if (fatal) | ||
404 | return -1; | ||
405 | else | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c) | ||
410 | { | ||
411 | int ret=0; | ||
412 | SSL_SESSION *s; | ||
413 | |||
414 | /* add just 1 reference count for the SSL_CTX's session cache | ||
415 | * even though it has two ways of access: each session is in a | ||
416 | * doubly linked list and an lhash */ | ||
417 | CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
418 | /* if session c is in already in cache, we take back the increment later */ | ||
419 | |||
420 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
421 | s=(SSL_SESSION *)lh_insert(ctx->sessions,c); | ||
422 | |||
423 | /* s != NULL iff we already had a session with the given PID. | ||
424 | * In this case, s == c should hold (then we did not really modify | ||
425 | * ctx->sessions), or we're in trouble. */ | ||
426 | if (s != NULL && s != c) | ||
427 | { | ||
428 | /* We *are* in trouble ... */ | ||
429 | SSL_SESSION_list_remove(ctx,s); | ||
430 | SSL_SESSION_free(s); | ||
431 | /* ... so pretend the other session did not exist in cache | ||
432 | * (we cannot handle two SSL_SESSION structures with identical | ||
433 | * session ID in the same cache, which could happen e.g. when | ||
434 | * two threads concurrently obtain the same session from an external | ||
435 | * cache) */ | ||
436 | s = NULL; | ||
437 | } | ||
438 | |||
439 | /* Put at the head of the queue unless it is already in the cache */ | ||
440 | if (s == NULL) | ||
441 | SSL_SESSION_list_add(ctx,c); | ||
442 | |||
443 | if (s != NULL) | ||
444 | { | ||
445 | /* existing cache entry -- decrement previously incremented reference | ||
446 | * count because it already takes into account the cache */ | ||
447 | |||
448 | SSL_SESSION_free(s); /* s == c */ | ||
449 | ret=0; | ||
450 | } | ||
451 | else | ||
452 | { | ||
453 | /* new cache entry -- remove old ones if cache has become too large */ | ||
454 | |||
455 | ret=1; | ||
456 | |||
457 | if (SSL_CTX_sess_get_cache_size(ctx) > 0) | ||
458 | { | ||
459 | while (SSL_CTX_sess_number(ctx) > | ||
460 | SSL_CTX_sess_get_cache_size(ctx)) | ||
461 | { | ||
462 | if (!remove_session_lock(ctx, | ||
463 | ctx->session_cache_tail, 0)) | ||
464 | break; | ||
465 | else | ||
466 | ctx->stats.sess_cache_full++; | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
471 | return(ret); | ||
472 | } | ||
473 | |||
474 | int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c) | ||
475 | { | ||
476 | return remove_session_lock(ctx, c, 1); | ||
477 | } | ||
478 | |||
479 | static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck) | ||
480 | { | ||
481 | SSL_SESSION *r; | ||
482 | int ret=0; | ||
483 | |||
484 | if ((c != NULL) && (c->session_id_length != 0)) | ||
485 | { | ||
486 | if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
487 | if ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c) | ||
488 | { | ||
489 | ret=1; | ||
490 | r=(SSL_SESSION *)lh_delete(ctx->sessions,c); | ||
491 | SSL_SESSION_list_remove(ctx,c); | ||
492 | } | ||
493 | |||
494 | if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
495 | |||
496 | if (ret) | ||
497 | { | ||
498 | r->not_resumable=1; | ||
499 | if (ctx->remove_session_cb != NULL) | ||
500 | ctx->remove_session_cb(ctx,r); | ||
501 | SSL_SESSION_free(r); | ||
502 | } | ||
503 | } | ||
504 | else | ||
505 | ret=0; | ||
506 | return(ret); | ||
507 | } | ||
508 | |||
509 | void SSL_SESSION_free(SSL_SESSION *ss) | ||
510 | { | ||
511 | int i; | ||
512 | |||
513 | if(ss == NULL) | ||
514 | return; | ||
515 | |||
516 | i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION); | ||
517 | #ifdef REF_PRINT | ||
518 | REF_PRINT("SSL_SESSION",ss); | ||
519 | #endif | ||
520 | if (i > 0) return; | ||
521 | #ifdef REF_CHECK | ||
522 | if (i < 0) | ||
523 | { | ||
524 | fprintf(stderr,"SSL_SESSION_free, bad reference count\n"); | ||
525 | abort(); /* ok */ | ||
526 | } | ||
527 | #endif | ||
528 | |||
529 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); | ||
530 | |||
531 | OPENSSL_cleanse(ss->key_arg,sizeof ss->key_arg); | ||
532 | OPENSSL_cleanse(ss->master_key,sizeof ss->master_key); | ||
533 | OPENSSL_cleanse(ss->session_id,sizeof ss->session_id); | ||
534 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); | ||
535 | if (ss->peer != NULL) X509_free(ss->peer); | ||
536 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); | ||
537 | OPENSSL_cleanse(ss,sizeof(*ss)); | ||
538 | OPENSSL_free(ss); | ||
539 | } | ||
540 | |||
541 | int SSL_set_session(SSL *s, SSL_SESSION *session) | ||
542 | { | ||
543 | int ret=0; | ||
544 | SSL_METHOD *meth; | ||
545 | |||
546 | if (session != NULL) | ||
547 | { | ||
548 | meth=s->ctx->method->get_ssl_method(session->ssl_version); | ||
549 | if (meth == NULL) | ||
550 | meth=s->method->get_ssl_method(session->ssl_version); | ||
551 | if (meth == NULL) | ||
552 | { | ||
553 | SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD); | ||
554 | return(0); | ||
555 | } | ||
556 | |||
557 | if (meth != s->method) | ||
558 | { | ||
559 | if (!SSL_set_ssl_method(s,meth)) | ||
560 | return(0); | ||
561 | if (s->ctx->session_timeout == 0) | ||
562 | session->timeout=SSL_get_default_timeout(s); | ||
563 | else | ||
564 | session->timeout=s->ctx->session_timeout; | ||
565 | } | ||
566 | |||
567 | #ifndef OPENSSL_NO_KRB5 | ||
568 | if (s->kssl_ctx && !s->kssl_ctx->client_princ && | ||
569 | session->krb5_client_princ_len > 0) | ||
570 | { | ||
571 | s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1); | ||
572 | memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ, | ||
573 | session->krb5_client_princ_len); | ||
574 | s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0'; | ||
575 | } | ||
576 | #endif /* OPENSSL_NO_KRB5 */ | ||
577 | |||
578 | /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/ | ||
579 | CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
580 | if (s->session != NULL) | ||
581 | SSL_SESSION_free(s->session); | ||
582 | s->session=session; | ||
583 | s->verify_result = s->session->verify_result; | ||
584 | /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/ | ||
585 | ret=1; | ||
586 | } | ||
587 | else | ||
588 | { | ||
589 | if (s->session != NULL) | ||
590 | { | ||
591 | SSL_SESSION_free(s->session); | ||
592 | s->session=NULL; | ||
593 | } | ||
594 | |||
595 | meth=s->ctx->method; | ||
596 | if (meth != s->method) | ||
597 | { | ||
598 | if (!SSL_set_ssl_method(s,meth)) | ||
599 | return(0); | ||
600 | } | ||
601 | ret=1; | ||
602 | } | ||
603 | return(ret); | ||
604 | } | ||
605 | |||
606 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t) | ||
607 | { | ||
608 | if (s == NULL) return(0); | ||
609 | s->timeout=t; | ||
610 | return(1); | ||
611 | } | ||
612 | |||
613 | long SSL_SESSION_get_timeout(const SSL_SESSION *s) | ||
614 | { | ||
615 | if (s == NULL) return(0); | ||
616 | return(s->timeout); | ||
617 | } | ||
618 | |||
619 | long SSL_SESSION_get_time(const SSL_SESSION *s) | ||
620 | { | ||
621 | if (s == NULL) return(0); | ||
622 | return(s->time); | ||
623 | } | ||
624 | |||
625 | long SSL_SESSION_set_time(SSL_SESSION *s, long t) | ||
626 | { | ||
627 | if (s == NULL) return(0); | ||
628 | s->time=t; | ||
629 | return(t); | ||
630 | } | ||
631 | |||
632 | long SSL_CTX_set_timeout(SSL_CTX *s, long t) | ||
633 | { | ||
634 | long l; | ||
635 | if (s == NULL) return(0); | ||
636 | l=s->session_timeout; | ||
637 | s->session_timeout=t; | ||
638 | return(l); | ||
639 | } | ||
640 | |||
641 | long SSL_CTX_get_timeout(const SSL_CTX *s) | ||
642 | { | ||
643 | if (s == NULL) return(0); | ||
644 | return(s->session_timeout); | ||
645 | } | ||
646 | |||
647 | typedef struct timeout_param_st | ||
648 | { | ||
649 | SSL_CTX *ctx; | ||
650 | long time; | ||
651 | LHASH *cache; | ||
652 | } TIMEOUT_PARAM; | ||
653 | |||
654 | static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p) | ||
655 | { | ||
656 | if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */ | ||
657 | { | ||
658 | /* The reason we don't call SSL_CTX_remove_session() is to | ||
659 | * save on locking overhead */ | ||
660 | lh_delete(p->cache,s); | ||
661 | SSL_SESSION_list_remove(p->ctx,s); | ||
662 | s->not_resumable=1; | ||
663 | if (p->ctx->remove_session_cb != NULL) | ||
664 | p->ctx->remove_session_cb(p->ctx,s); | ||
665 | SSL_SESSION_free(s); | ||
666 | } | ||
667 | } | ||
668 | |||
669 | static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *) | ||
670 | |||
671 | void SSL_CTX_flush_sessions(SSL_CTX *s, long t) | ||
672 | { | ||
673 | unsigned long i; | ||
674 | TIMEOUT_PARAM tp; | ||
675 | |||
676 | tp.ctx=s; | ||
677 | tp.cache=s->sessions; | ||
678 | if (tp.cache == NULL) return; | ||
679 | tp.time=t; | ||
680 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
681 | i=tp.cache->down_load; | ||
682 | tp.cache->down_load=0; | ||
683 | lh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp); | ||
684 | tp.cache->down_load=i; | ||
685 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
686 | } | ||
687 | |||
688 | int ssl_clear_bad_session(SSL *s) | ||
689 | { | ||
690 | if ( (s->session != NULL) && | ||
691 | !(s->shutdown & SSL_SENT_SHUTDOWN) && | ||
692 | !(SSL_in_init(s) || SSL_in_before(s))) | ||
693 | { | ||
694 | SSL_CTX_remove_session(s->ctx,s->session); | ||
695 | return(1); | ||
696 | } | ||
697 | else | ||
698 | return(0); | ||
699 | } | ||
700 | |||
701 | /* locked by SSL_CTX in the calling function */ | ||
702 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s) | ||
703 | { | ||
704 | if ((s->next == NULL) || (s->prev == NULL)) return; | ||
705 | |||
706 | if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) | ||
707 | { /* last element in list */ | ||
708 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
709 | { /* only one element in list */ | ||
710 | ctx->session_cache_head=NULL; | ||
711 | ctx->session_cache_tail=NULL; | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | ctx->session_cache_tail=s->prev; | ||
716 | s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
717 | } | ||
718 | } | ||
719 | else | ||
720 | { | ||
721 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
722 | { /* first element in list */ | ||
723 | ctx->session_cache_head=s->next; | ||
724 | s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
725 | } | ||
726 | else | ||
727 | { /* middle of list */ | ||
728 | s->next->prev=s->prev; | ||
729 | s->prev->next=s->next; | ||
730 | } | ||
731 | } | ||
732 | s->prev=s->next=NULL; | ||
733 | } | ||
734 | |||
735 | static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s) | ||
736 | { | ||
737 | if ((s->next != NULL) && (s->prev != NULL)) | ||
738 | SSL_SESSION_list_remove(ctx,s); | ||
739 | |||
740 | if (ctx->session_cache_head == NULL) | ||
741 | { | ||
742 | ctx->session_cache_head=s; | ||
743 | ctx->session_cache_tail=s; | ||
744 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
745 | s->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
746 | } | ||
747 | else | ||
748 | { | ||
749 | s->next=ctx->session_cache_head; | ||
750 | s->next->prev=s; | ||
751 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
752 | ctx->session_cache_head=s; | ||
753 | } | ||
754 | } | ||
755 | |||
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c deleted file mode 100644 index b16d253081..0000000000 --- a/src/lib/libssl/ssl_stat.c +++ /dev/null | |||
@@ -1,502 +0,0 @@ | |||
1 | /* ssl/ssl_stat.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include "ssl_locl.h" | ||
61 | |||
62 | const char *SSL_state_string_long(const SSL *s) | ||
63 | { | ||
64 | const char *str; | ||
65 | |||
66 | switch (s->state) | ||
67 | { | ||
68 | case SSL_ST_BEFORE: str="before SSL initialization"; break; | ||
69 | case SSL_ST_ACCEPT: str="before accept initialization"; break; | ||
70 | case SSL_ST_CONNECT: str="before connect initialization"; break; | ||
71 | case SSL_ST_OK: str="SSL negotiation finished successfully"; break; | ||
72 | case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break; | ||
73 | case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initialization"; break; | ||
74 | case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initialization"; break; | ||
75 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initialization"; break; | ||
76 | case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initialization"; break; | ||
77 | #ifndef OPENSSL_NO_SSL2 | ||
78 | case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break; | ||
79 | case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break; | ||
80 | case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break; | ||
81 | case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break; | ||
82 | case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break; | ||
83 | case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break; | ||
84 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break; | ||
85 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break; | ||
86 | case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break; | ||
87 | case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break; | ||
88 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break; | ||
89 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break; | ||
90 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break; | ||
91 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break; | ||
92 | case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break; | ||
93 | case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break; | ||
94 | case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break; | ||
95 | case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break; | ||
96 | case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break; | ||
97 | case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break; | ||
98 | case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break; | ||
99 | case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break; | ||
100 | case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break; | ||
101 | case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break; | ||
102 | case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break; | ||
103 | case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break; | ||
104 | case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break; | ||
105 | case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break; | ||
106 | case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break; | ||
107 | case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break; | ||
108 | case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break; | ||
109 | case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break; | ||
110 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break; | ||
111 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break; | ||
112 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break; | ||
113 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break; | ||
114 | case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break; | ||
115 | case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break; | ||
116 | #endif | ||
117 | |||
118 | #ifndef OPENSSL_NO_SSL3 | ||
119 | /* SSLv3 additions */ | ||
120 | case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break; | ||
121 | case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break; | ||
122 | case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break; | ||
123 | case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break; | ||
124 | case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break; | ||
125 | case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break; | ||
126 | case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break; | ||
127 | case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break; | ||
128 | case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break; | ||
129 | case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break; | ||
130 | case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break; | ||
131 | case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break; | ||
132 | case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break; | ||
133 | case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break; | ||
134 | case SSL3_ST_CW_CERT_C: str="SSLv3 write client certificate C"; break; | ||
135 | case SSL3_ST_CW_CERT_D: str="SSLv3 write client certificate D"; break; | ||
136 | case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break; | ||
137 | case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break; | ||
138 | case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break; | ||
139 | case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify B"; break; | ||
140 | |||
141 | case SSL3_ST_CW_CHANGE_A: | ||
142 | case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break; | ||
143 | case SSL3_ST_CW_CHANGE_B: | ||
144 | case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break; | ||
145 | case SSL3_ST_CW_FINISHED_A: | ||
146 | case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break; | ||
147 | case SSL3_ST_CW_FINISHED_B: | ||
148 | case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished B"; break; | ||
149 | case SSL3_ST_CR_CHANGE_A: | ||
150 | case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break; | ||
151 | case SSL3_ST_CR_CHANGE_B: | ||
152 | case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break; | ||
153 | case SSL3_ST_CR_FINISHED_A: | ||
154 | case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break; | ||
155 | case SSL3_ST_CR_FINISHED_B: | ||
156 | case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break; | ||
157 | |||
158 | case SSL3_ST_CW_FLUSH: | ||
159 | case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break; | ||
160 | |||
161 | case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break; | ||
162 | case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break; | ||
163 | case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break; | ||
164 | case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break; | ||
165 | case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break; | ||
166 | case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break; | ||
167 | case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break; | ||
168 | case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break; | ||
169 | case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break; | ||
170 | case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break; | ||
171 | case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break; | ||
172 | case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break; | ||
173 | case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break; | ||
174 | case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break; | ||
175 | case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break; | ||
176 | case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break; | ||
177 | case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break; | ||
178 | case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break; | ||
179 | case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break; | ||
180 | case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break; | ||
181 | case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break; | ||
182 | case SSL3_ST_SR_CERT_VRFY_B: str="SSLv3 read certificate verify B"; break; | ||
183 | #endif | ||
184 | |||
185 | #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3) | ||
186 | /* SSLv2/v3 compatibility states */ | ||
187 | /* client */ | ||
188 | case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break; | ||
189 | case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break; | ||
190 | case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break; | ||
191 | case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break; | ||
192 | /* server */ | ||
193 | case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break; | ||
194 | case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break; | ||
195 | #endif | ||
196 | |||
197 | default: str="unknown state"; break; | ||
198 | } | ||
199 | return(str); | ||
200 | } | ||
201 | |||
202 | const char *SSL_rstate_string_long(const SSL *s) | ||
203 | { | ||
204 | const char *str; | ||
205 | |||
206 | switch (s->rstate) | ||
207 | { | ||
208 | case SSL_ST_READ_HEADER: str="read header"; break; | ||
209 | case SSL_ST_READ_BODY: str="read body"; break; | ||
210 | case SSL_ST_READ_DONE: str="read done"; break; | ||
211 | default: str="unknown"; break; | ||
212 | } | ||
213 | return(str); | ||
214 | } | ||
215 | |||
216 | const char *SSL_state_string(const SSL *s) | ||
217 | { | ||
218 | const char *str; | ||
219 | |||
220 | switch (s->state) | ||
221 | { | ||
222 | case SSL_ST_BEFORE: str="PINIT "; break; | ||
223 | case SSL_ST_ACCEPT: str="AINIT "; break; | ||
224 | case SSL_ST_CONNECT: str="CINIT "; break; | ||
225 | case SSL_ST_OK: str="SSLOK "; break; | ||
226 | #ifndef OPENSSL_NO_SSL2 | ||
227 | case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break; | ||
228 | case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break; | ||
229 | case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break; | ||
230 | case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break; | ||
231 | case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break; | ||
232 | case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break; | ||
233 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break; | ||
234 | case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break; | ||
235 | case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break; | ||
236 | case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break; | ||
237 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break; | ||
238 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break; | ||
239 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break; | ||
240 | case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break; | ||
241 | case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break; | ||
242 | case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break; | ||
243 | case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break; | ||
244 | case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break; | ||
245 | case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break; | ||
246 | case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break; | ||
247 | case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break; | ||
248 | case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break; | ||
249 | case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break; | ||
250 | case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break; | ||
251 | case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break; | ||
252 | case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break; | ||
253 | case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break; | ||
254 | case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break; | ||
255 | case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break; | ||
256 | case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break; | ||
257 | case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break; | ||
258 | case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break; | ||
259 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break; | ||
260 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break; | ||
261 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break; | ||
262 | case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break; | ||
263 | case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break; | ||
264 | case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break; | ||
265 | #endif | ||
266 | |||
267 | #ifndef OPENSSL_NO_SSL3 | ||
268 | /* SSLv3 additions */ | ||
269 | case SSL3_ST_SW_FLUSH: | ||
270 | case SSL3_ST_CW_FLUSH: str="3FLUSH"; break; | ||
271 | case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break; | ||
272 | case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break; | ||
273 | case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break; | ||
274 | case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break; | ||
275 | case SSL3_ST_CR_CERT_A: str="3RSC_A"; break; | ||
276 | case SSL3_ST_CR_CERT_B: str="3RSC_B"; break; | ||
277 | case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break; | ||
278 | case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break; | ||
279 | case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break; | ||
280 | case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break; | ||
281 | case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break; | ||
282 | case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break; | ||
283 | case SSL3_ST_CW_CERT_A: str="3WCC_A"; break; | ||
284 | case SSL3_ST_CW_CERT_B: str="3WCC_B"; break; | ||
285 | case SSL3_ST_CW_CERT_C: str="3WCC_C"; break; | ||
286 | case SSL3_ST_CW_CERT_D: str="3WCC_D"; break; | ||
287 | case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break; | ||
288 | case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break; | ||
289 | case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break; | ||
290 | case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break; | ||
291 | |||
292 | case SSL3_ST_SW_CHANGE_A: | ||
293 | case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break; | ||
294 | case SSL3_ST_SW_CHANGE_B: | ||
295 | case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break; | ||
296 | case SSL3_ST_SW_FINISHED_A: | ||
297 | case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break; | ||
298 | case SSL3_ST_SW_FINISHED_B: | ||
299 | case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break; | ||
300 | case SSL3_ST_SR_CHANGE_A: | ||
301 | case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break; | ||
302 | case SSL3_ST_SR_CHANGE_B: | ||
303 | case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break; | ||
304 | case SSL3_ST_SR_FINISHED_A: | ||
305 | case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break; | ||
306 | case SSL3_ST_SR_FINISHED_B: | ||
307 | case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break; | ||
308 | |||
309 | case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break; | ||
310 | case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break; | ||
311 | case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break; | ||
312 | case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break; | ||
313 | case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break; | ||
314 | case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break; | ||
315 | case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break; | ||
316 | case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break; | ||
317 | case SSL3_ST_SW_CERT_A: str="3WSC_A"; break; | ||
318 | case SSL3_ST_SW_CERT_B: str="3WSC_B"; break; | ||
319 | case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break; | ||
320 | case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break; | ||
321 | case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break; | ||
322 | case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break; | ||
323 | case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break; | ||
324 | case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break; | ||
325 | case SSL3_ST_SR_CERT_A: str="3RCC_A"; break; | ||
326 | case SSL3_ST_SR_CERT_B: str="3RCC_B"; break; | ||
327 | case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break; | ||
328 | case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break; | ||
329 | case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break; | ||
330 | case SSL3_ST_SR_CERT_VRFY_B: str="3RCV_B"; break; | ||
331 | #endif | ||
332 | |||
333 | #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3) | ||
334 | /* SSLv2/v3 compatibility states */ | ||
335 | /* client */ | ||
336 | case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break; | ||
337 | case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break; | ||
338 | case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break; | ||
339 | case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break; | ||
340 | /* server */ | ||
341 | case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break; | ||
342 | case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break; | ||
343 | #endif | ||
344 | |||
345 | default: str="UNKWN "; break; | ||
346 | } | ||
347 | return(str); | ||
348 | } | ||
349 | |||
350 | const char *SSL_alert_type_string_long(int value) | ||
351 | { | ||
352 | value>>=8; | ||
353 | if (value == SSL3_AL_WARNING) | ||
354 | return("warning"); | ||
355 | else if (value == SSL3_AL_FATAL) | ||
356 | return("fatal"); | ||
357 | else | ||
358 | return("unknown"); | ||
359 | } | ||
360 | |||
361 | const char *SSL_alert_type_string(int value) | ||
362 | { | ||
363 | value>>=8; | ||
364 | if (value == SSL3_AL_WARNING) | ||
365 | return("W"); | ||
366 | else if (value == SSL3_AL_FATAL) | ||
367 | return("F"); | ||
368 | else | ||
369 | return("U"); | ||
370 | } | ||
371 | |||
372 | const char *SSL_alert_desc_string(int value) | ||
373 | { | ||
374 | const char *str; | ||
375 | |||
376 | switch (value & 0xff) | ||
377 | { | ||
378 | case SSL3_AD_CLOSE_NOTIFY: str="CN"; break; | ||
379 | case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break; | ||
380 | case SSL3_AD_BAD_RECORD_MAC: str="BM"; break; | ||
381 | case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break; | ||
382 | case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break; | ||
383 | case SSL3_AD_NO_CERTIFICATE: str="NC"; break; | ||
384 | case SSL3_AD_BAD_CERTIFICATE: str="BC"; break; | ||
385 | case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break; | ||
386 | case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break; | ||
387 | case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break; | ||
388 | case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break; | ||
389 | case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break; | ||
390 | case TLS1_AD_DECRYPTION_FAILED: str="DC"; break; | ||
391 | case TLS1_AD_RECORD_OVERFLOW: str="RO"; break; | ||
392 | case TLS1_AD_UNKNOWN_CA: str="CA"; break; | ||
393 | case TLS1_AD_ACCESS_DENIED: str="AD"; break; | ||
394 | case TLS1_AD_DECODE_ERROR: str="DE"; break; | ||
395 | case TLS1_AD_DECRYPT_ERROR: str="CY"; break; | ||
396 | case TLS1_AD_EXPORT_RESTRICTION: str="ER"; break; | ||
397 | case TLS1_AD_PROTOCOL_VERSION: str="PV"; break; | ||
398 | case TLS1_AD_INSUFFICIENT_SECURITY: str="IS"; break; | ||
399 | case TLS1_AD_INTERNAL_ERROR: str="IE"; break; | ||
400 | case TLS1_AD_USER_CANCELLED: str="US"; break; | ||
401 | case TLS1_AD_NO_RENEGOTIATION: str="NR"; break; | ||
402 | default: str="UK"; break; | ||
403 | } | ||
404 | return(str); | ||
405 | } | ||
406 | |||
407 | const char *SSL_alert_desc_string_long(int value) | ||
408 | { | ||
409 | const char *str; | ||
410 | |||
411 | switch (value & 0xff) | ||
412 | { | ||
413 | case SSL3_AD_CLOSE_NOTIFY: | ||
414 | str="close notify"; | ||
415 | break; | ||
416 | case SSL3_AD_UNEXPECTED_MESSAGE: | ||
417 | str="unexpected_message"; | ||
418 | break; | ||
419 | case SSL3_AD_BAD_RECORD_MAC: | ||
420 | str="bad record mac"; | ||
421 | break; | ||
422 | case SSL3_AD_DECOMPRESSION_FAILURE: | ||
423 | str="decompression failure"; | ||
424 | break; | ||
425 | case SSL3_AD_HANDSHAKE_FAILURE: | ||
426 | str="handshake failure"; | ||
427 | break; | ||
428 | case SSL3_AD_NO_CERTIFICATE: | ||
429 | str="no certificate"; | ||
430 | break; | ||
431 | case SSL3_AD_BAD_CERTIFICATE: | ||
432 | str="bad certificate"; | ||
433 | break; | ||
434 | case SSL3_AD_UNSUPPORTED_CERTIFICATE: | ||
435 | str="unsupported certificate"; | ||
436 | break; | ||
437 | case SSL3_AD_CERTIFICATE_REVOKED: | ||
438 | str="certificate revoked"; | ||
439 | break; | ||
440 | case SSL3_AD_CERTIFICATE_EXPIRED: | ||
441 | str="certificate expired"; | ||
442 | break; | ||
443 | case SSL3_AD_CERTIFICATE_UNKNOWN: | ||
444 | str="certificate unknown"; | ||
445 | break; | ||
446 | case SSL3_AD_ILLEGAL_PARAMETER: | ||
447 | str="illegal parameter"; | ||
448 | break; | ||
449 | case TLS1_AD_DECRYPTION_FAILED: | ||
450 | str="decryption failed"; | ||
451 | break; | ||
452 | case TLS1_AD_RECORD_OVERFLOW: | ||
453 | str="record overflow"; | ||
454 | break; | ||
455 | case TLS1_AD_UNKNOWN_CA: | ||
456 | str="unknown CA"; | ||
457 | break; | ||
458 | case TLS1_AD_ACCESS_DENIED: | ||
459 | str="access denied"; | ||
460 | break; | ||
461 | case TLS1_AD_DECODE_ERROR: | ||
462 | str="decode error"; | ||
463 | break; | ||
464 | case TLS1_AD_DECRYPT_ERROR: | ||
465 | str="decrypt error"; | ||
466 | break; | ||
467 | case TLS1_AD_EXPORT_RESTRICTION: | ||
468 | str="export restriction"; | ||
469 | break; | ||
470 | case TLS1_AD_PROTOCOL_VERSION: | ||
471 | str="protocol version"; | ||
472 | break; | ||
473 | case TLS1_AD_INSUFFICIENT_SECURITY: | ||
474 | str="insufficient security"; | ||
475 | break; | ||
476 | case TLS1_AD_INTERNAL_ERROR: | ||
477 | str="internal error"; | ||
478 | break; | ||
479 | case TLS1_AD_USER_CANCELLED: | ||
480 | str="user canceled"; | ||
481 | break; | ||
482 | case TLS1_AD_NO_RENEGOTIATION: | ||
483 | str="no renegotiation"; | ||
484 | break; | ||
485 | default: str="unknown"; break; | ||
486 | } | ||
487 | return(str); | ||
488 | } | ||
489 | |||
490 | const char *SSL_rstate_string(const SSL *s) | ||
491 | { | ||
492 | const char *str; | ||
493 | |||
494 | switch (s->rstate) | ||
495 | { | ||
496 | case SSL_ST_READ_HEADER:str="RH"; break; | ||
497 | case SSL_ST_READ_BODY: str="RB"; break; | ||
498 | case SSL_ST_READ_DONE: str="RD"; break; | ||
499 | default: str="unknown"; break; | ||
500 | } | ||
501 | return(str); | ||
502 | } | ||
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c deleted file mode 100644 index 8655a31333..0000000000 --- a/src/lib/libssl/ssl_txt.c +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | /* ssl/ssl_txt.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/buffer.h> | ||
61 | #include "ssl_locl.h" | ||
62 | |||
63 | #ifndef OPENSSL_NO_FP_API | ||
64 | int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x) | ||
65 | { | ||
66 | BIO *b; | ||
67 | int ret; | ||
68 | |||
69 | if ((b=BIO_new(BIO_s_file_internal())) == NULL) | ||
70 | { | ||
71 | SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB); | ||
72 | return(0); | ||
73 | } | ||
74 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
75 | ret=SSL_SESSION_print(b,x); | ||
76 | BIO_free(b); | ||
77 | return(ret); | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | int SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | ||
82 | { | ||
83 | unsigned int i; | ||
84 | char *s; | ||
85 | |||
86 | if (x == NULL) goto err; | ||
87 | if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err; | ||
88 | if (x->ssl_version == SSL2_VERSION) | ||
89 | s="SSLv2"; | ||
90 | else if (x->ssl_version == SSL3_VERSION) | ||
91 | s="SSLv3"; | ||
92 | else if (x->ssl_version == TLS1_VERSION) | ||
93 | s="TLSv1"; | ||
94 | else | ||
95 | s="unknown"; | ||
96 | if (BIO_printf(bp," Protocol : %s\n",s) <= 0) goto err; | ||
97 | |||
98 | if (x->cipher == NULL) | ||
99 | { | ||
100 | if (((x->cipher_id) & 0xff000000) == 0x02000000) | ||
101 | { | ||
102 | if (BIO_printf(bp," Cipher : %06lX\n",x->cipher_id&0xffffff) <= 0) | ||
103 | goto err; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | if (BIO_printf(bp," Cipher : %04lX\n",x->cipher_id&0xffff) <= 0) | ||
108 | goto err; | ||
109 | } | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | if (BIO_printf(bp," Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0) | ||
114 | goto err; | ||
115 | } | ||
116 | if (BIO_puts(bp," Session-ID: ") <= 0) goto err; | ||
117 | for (i=0; i<x->session_id_length; i++) | ||
118 | { | ||
119 | if (BIO_printf(bp,"%02X",x->session_id[i]) <= 0) goto err; | ||
120 | } | ||
121 | if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err; | ||
122 | for (i=0; i<x->sid_ctx_length; i++) | ||
123 | { | ||
124 | if (BIO_printf(bp,"%02X",x->sid_ctx[i]) <= 0) | ||
125 | goto err; | ||
126 | } | ||
127 | if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err; | ||
128 | for (i=0; i<(unsigned int)x->master_key_length; i++) | ||
129 | { | ||
130 | if (BIO_printf(bp,"%02X",x->master_key[i]) <= 0) goto err; | ||
131 | } | ||
132 | if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err; | ||
133 | if (x->key_arg_length == 0) | ||
134 | { | ||
135 | if (BIO_puts(bp,"None") <= 0) goto err; | ||
136 | } | ||
137 | else | ||
138 | for (i=0; i<x->key_arg_length; i++) | ||
139 | { | ||
140 | if (BIO_printf(bp,"%02X",x->key_arg[i]) <= 0) goto err; | ||
141 | } | ||
142 | #ifndef OPENSSL_NO_KRB5 | ||
143 | if (BIO_puts(bp,"\n Krb5 Principal: ") <= 0) goto err; | ||
144 | if (x->krb5_client_princ_len == 0) | ||
145 | { | ||
146 | if (BIO_puts(bp,"None") <= 0) goto err; | ||
147 | } | ||
148 | else | ||
149 | for (i=0; i<x->krb5_client_princ_len; i++) | ||
150 | { | ||
151 | if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err; | ||
152 | } | ||
153 | #endif /* OPENSSL_NO_KRB5 */ | ||
154 | if (x->compress_meth != 0) | ||
155 | { | ||
156 | SSL_COMP *comp; | ||
157 | |||
158 | ssl_cipher_get_evp(x,NULL,NULL,&comp); | ||
159 | if (comp == NULL) | ||
160 | { | ||
161 | if (BIO_printf(bp,"\n Compression: %d",x->compress_meth) <= 0) goto err; | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err; | ||
166 | } | ||
167 | } | ||
168 | if (x->time != 0L) | ||
169 | { | ||
170 | if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err; | ||
171 | } | ||
172 | if (x->timeout != 0L) | ||
173 | { | ||
174 | if (BIO_printf(bp, "\n Timeout : %ld (sec)",x->timeout) <= 0) goto err; | ||
175 | } | ||
176 | if (BIO_puts(bp,"\n") <= 0) goto err; | ||
177 | |||
178 | if (BIO_puts(bp, " Verify return code: ") <= 0) goto err; | ||
179 | if (BIO_printf(bp, "%ld (%s)\n", x->verify_result, | ||
180 | X509_verify_cert_error_string(x->verify_result)) <= 0) goto err; | ||
181 | |||
182 | return(1); | ||
183 | err: | ||
184 | return(0); | ||
185 | } | ||
186 | |||
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c deleted file mode 100644 index 57205fb429..0000000000 --- a/src/lib/libssl/t1_clnt.c +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | /* ssl/t1_clnt.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include "ssl_locl.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/evp.h> | ||
65 | |||
66 | static SSL_METHOD *tls1_get_client_method(int ver); | ||
67 | static SSL_METHOD *tls1_get_client_method(int ver) | ||
68 | { | ||
69 | if (ver == TLS1_VERSION) | ||
70 | return(TLSv1_client_method()); | ||
71 | else | ||
72 | return(NULL); | ||
73 | } | ||
74 | |||
75 | SSL_METHOD *TLSv1_client_method(void) | ||
76 | { | ||
77 | static int init=1; | ||
78 | static SSL_METHOD TLSv1_client_data; | ||
79 | |||
80 | if (init) | ||
81 | { | ||
82 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
83 | |||
84 | if (init) | ||
85 | { | ||
86 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), | ||
87 | sizeof(SSL_METHOD)); | ||
88 | TLSv1_client_data.ssl_connect=ssl3_connect; | ||
89 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | ||
90 | init=0; | ||
91 | } | ||
92 | |||
93 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
94 | } | ||
95 | return(&TLSv1_client_data); | ||
96 | } | ||
97 | |||
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c deleted file mode 100644 index 2c6246abf5..0000000000 --- a/src/lib/libssl/t1_enc.c +++ /dev/null | |||
@@ -1,816 +0,0 @@ | |||
1 | /* ssl/t1_enc.c */ | ||
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 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include "ssl_locl.h" | ||
114 | #include <openssl/comp.h> | ||
115 | #include <openssl/evp.h> | ||
116 | #include <openssl/hmac.h> | ||
117 | #include <openssl/md5.h> | ||
118 | #include <openssl/fips.h> | ||
119 | |||
120 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | ||
121 | int sec_len, unsigned char *seed, int seed_len, | ||
122 | unsigned char *out, int olen) | ||
123 | { | ||
124 | int chunk,n; | ||
125 | unsigned int j; | ||
126 | HMAC_CTX ctx; | ||
127 | HMAC_CTX ctx_tmp; | ||
128 | unsigned char A1[EVP_MAX_MD_SIZE]; | ||
129 | unsigned int A1_len; | ||
130 | |||
131 | chunk=EVP_MD_size(md); | ||
132 | |||
133 | HMAC_CTX_init(&ctx); | ||
134 | HMAC_CTX_init(&ctx_tmp); | ||
135 | HMAC_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
136 | HMAC_CTX_set_flags(&ctx_tmp, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); | ||
137 | HMAC_Init_ex(&ctx,sec,sec_len,md, NULL); | ||
138 | HMAC_Init_ex(&ctx_tmp,sec,sec_len,md, NULL); | ||
139 | HMAC_Update(&ctx,seed,seed_len); | ||
140 | HMAC_Final(&ctx,A1,&A1_len); | ||
141 | |||
142 | n=0; | ||
143 | for (;;) | ||
144 | { | ||
145 | HMAC_Init_ex(&ctx,NULL,0,NULL,NULL); /* re-init */ | ||
146 | HMAC_Init_ex(&ctx_tmp,NULL,0,NULL,NULL); /* re-init */ | ||
147 | HMAC_Update(&ctx,A1,A1_len); | ||
148 | HMAC_Update(&ctx_tmp,A1,A1_len); | ||
149 | HMAC_Update(&ctx,seed,seed_len); | ||
150 | |||
151 | if (olen > chunk) | ||
152 | { | ||
153 | HMAC_Final(&ctx,out,&j); | ||
154 | out+=j; | ||
155 | olen-=j; | ||
156 | HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */ | ||
157 | } | ||
158 | else /* last one */ | ||
159 | { | ||
160 | HMAC_Final(&ctx,A1,&A1_len); | ||
161 | memcpy(out,A1,olen); | ||
162 | break; | ||
163 | } | ||
164 | } | ||
165 | HMAC_CTX_cleanup(&ctx); | ||
166 | HMAC_CTX_cleanup(&ctx_tmp); | ||
167 | OPENSSL_cleanse(A1,sizeof(A1)); | ||
168 | } | ||
169 | |||
170 | static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1, | ||
171 | unsigned char *label, int label_len, | ||
172 | const unsigned char *sec, int slen, unsigned char *out1, | ||
173 | unsigned char *out2, int olen) | ||
174 | { | ||
175 | int len,i; | ||
176 | const unsigned char *S1,*S2; | ||
177 | |||
178 | len=slen/2; | ||
179 | S1=sec; | ||
180 | S2= &(sec[len]); | ||
181 | len+=(slen&1); /* add for odd, make longer */ | ||
182 | |||
183 | tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen); | ||
184 | tls1_P_hash(sha1,S2,len,label,label_len,out2,olen); | ||
185 | |||
186 | for (i=0; i<olen; i++) | ||
187 | out1[i]^=out2[i]; | ||
188 | } | ||
189 | |||
190 | static void tls1_generate_key_block(SSL *s, unsigned char *km, | ||
191 | unsigned char *tmp, int num) | ||
192 | { | ||
193 | unsigned char *p; | ||
194 | unsigned char buf[SSL3_RANDOM_SIZE*2+ | ||
195 | TLS_MD_MAX_CONST_SIZE]; | ||
196 | p=buf; | ||
197 | |||
198 | memcpy(p,TLS_MD_KEY_EXPANSION_CONST, | ||
199 | TLS_MD_KEY_EXPANSION_CONST_SIZE); | ||
200 | p+=TLS_MD_KEY_EXPANSION_CONST_SIZE; | ||
201 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
202 | p+=SSL3_RANDOM_SIZE; | ||
203 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
204 | p+=SSL3_RANDOM_SIZE; | ||
205 | |||
206 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf), | ||
207 | s->session->master_key,s->session->master_key_length, | ||
208 | km,tmp,num); | ||
209 | #ifdef KSSL_DEBUG | ||
210 | printf("tls1_generate_key_block() ==> %d byte master_key =\n\t", | ||
211 | s->session->master_key_length); | ||
212 | { | ||
213 | int i; | ||
214 | for (i=0; i < s->session->master_key_length; i++) | ||
215 | { | ||
216 | printf("%02X", s->session->master_key[i]); | ||
217 | } | ||
218 | printf("\n"); } | ||
219 | #endif /* KSSL_DEBUG */ | ||
220 | } | ||
221 | |||
222 | int tls1_change_cipher_state(SSL *s, int which) | ||
223 | { | ||
224 | static const unsigned char empty[]=""; | ||
225 | unsigned char *p,*key_block,*mac_secret; | ||
226 | unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+ | ||
227 | SSL3_RANDOM_SIZE*2]; | ||
228 | unsigned char tmp1[EVP_MAX_KEY_LENGTH]; | ||
229 | unsigned char tmp2[EVP_MAX_KEY_LENGTH]; | ||
230 | unsigned char iv1[EVP_MAX_IV_LENGTH*2]; | ||
231 | unsigned char iv2[EVP_MAX_IV_LENGTH*2]; | ||
232 | unsigned char *ms,*key,*iv,*er1,*er2; | ||
233 | int client_write; | ||
234 | EVP_CIPHER_CTX *dd; | ||
235 | const EVP_CIPHER *c; | ||
236 | const SSL_COMP *comp; | ||
237 | const EVP_MD *m; | ||
238 | int is_export,n,i,j,k,exp_label_len,cl; | ||
239 | int reuse_dd = 0; | ||
240 | |||
241 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | ||
242 | c=s->s3->tmp.new_sym_enc; | ||
243 | m=s->s3->tmp.new_hash; | ||
244 | comp=s->s3->tmp.new_compression; | ||
245 | key_block=s->s3->tmp.key_block; | ||
246 | |||
247 | #ifdef KSSL_DEBUG | ||
248 | printf("tls1_change_cipher_state(which= %d) w/\n", which); | ||
249 | printf("\talg= %ld, comp= %p\n", s->s3->tmp.new_cipher->algorithms, | ||
250 | comp); | ||
251 | printf("\tevp_cipher == %p ==? &d_cbc_ede_cipher3\n", c); | ||
252 | printf("\tevp_cipher: nid, blksz= %d, %d, keylen=%d, ivlen=%d\n", | ||
253 | c->nid,c->block_size,c->key_len,c->iv_len); | ||
254 | printf("\tkey_block: len= %d, data= ", s->s3->tmp.key_block_length); | ||
255 | { | ||
256 | int i; | ||
257 | for (i=0; i<s->s3->tmp.key_block_length; i++) | ||
258 | printf("%02x", key_block[i]); printf("\n"); | ||
259 | } | ||
260 | #endif /* KSSL_DEBUG */ | ||
261 | |||
262 | if (which & SSL3_CC_READ) | ||
263 | { | ||
264 | if (s->enc_read_ctx != NULL) | ||
265 | reuse_dd = 1; | ||
266 | else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) | ||
267 | goto err; | ||
268 | dd= s->enc_read_ctx; | ||
269 | s->read_hash=m; | ||
270 | if (s->expand != NULL) | ||
271 | { | ||
272 | COMP_CTX_free(s->expand); | ||
273 | s->expand=NULL; | ||
274 | } | ||
275 | if (comp != NULL) | ||
276 | { | ||
277 | s->expand=COMP_CTX_new(comp->method); | ||
278 | if (s->expand == NULL) | ||
279 | { | ||
280 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR); | ||
281 | goto err2; | ||
282 | } | ||
283 | if (s->s3->rrec.comp == NULL) | ||
284 | s->s3->rrec.comp=(unsigned char *) | ||
285 | OPENSSL_malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH); | ||
286 | if (s->s3->rrec.comp == NULL) | ||
287 | goto err; | ||
288 | } | ||
289 | memset(&(s->s3->read_sequence[0]),0,8); | ||
290 | mac_secret= &(s->s3->read_mac_secret[0]); | ||
291 | } | ||
292 | else | ||
293 | { | ||
294 | if (s->enc_write_ctx != NULL) | ||
295 | reuse_dd = 1; | ||
296 | else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL) | ||
297 | goto err; | ||
298 | if ((s->enc_write_ctx == NULL) && | ||
299 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) | ||
300 | OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | ||
301 | goto err; | ||
302 | dd= s->enc_write_ctx; | ||
303 | s->write_hash=m; | ||
304 | if (s->compress != NULL) | ||
305 | { | ||
306 | COMP_CTX_free(s->compress); | ||
307 | s->compress=NULL; | ||
308 | } | ||
309 | if (comp != NULL) | ||
310 | { | ||
311 | s->compress=COMP_CTX_new(comp->method); | ||
312 | if (s->compress == NULL) | ||
313 | { | ||
314 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR); | ||
315 | goto err2; | ||
316 | } | ||
317 | } | ||
318 | memset(&(s->s3->write_sequence[0]),0,8); | ||
319 | mac_secret= &(s->s3->write_mac_secret[0]); | ||
320 | } | ||
321 | |||
322 | if (reuse_dd) | ||
323 | EVP_CIPHER_CTX_cleanup(dd); | ||
324 | EVP_CIPHER_CTX_init(dd); | ||
325 | |||
326 | p=s->s3->tmp.key_block; | ||
327 | i=EVP_MD_size(m); | ||
328 | cl=EVP_CIPHER_key_length(c); | ||
329 | j=is_export ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ? | ||
330 | cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl; | ||
331 | /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */ | ||
332 | k=EVP_CIPHER_iv_length(c); | ||
333 | er1= &(s->s3->client_random[0]); | ||
334 | er2= &(s->s3->server_random[0]); | ||
335 | if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || | ||
336 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) | ||
337 | { | ||
338 | ms= &(p[ 0]); n=i+i; | ||
339 | key= &(p[ n]); n+=j+j; | ||
340 | iv= &(p[ n]); n+=k+k; | ||
341 | exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST; | ||
342 | exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE; | ||
343 | client_write=1; | ||
344 | } | ||
345 | else | ||
346 | { | ||
347 | n=i; | ||
348 | ms= &(p[ n]); n+=i+j; | ||
349 | key= &(p[ n]); n+=j+k; | ||
350 | iv= &(p[ n]); n+=k; | ||
351 | exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST; | ||
352 | exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE; | ||
353 | client_write=0; | ||
354 | } | ||
355 | |||
356 | if (n > s->s3->tmp.key_block_length) | ||
357 | { | ||
358 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_INTERNAL_ERROR); | ||
359 | goto err2; | ||
360 | } | ||
361 | |||
362 | memcpy(mac_secret,ms,i); | ||
363 | #ifdef TLS_DEBUG | ||
364 | printf("which = %04X\nmac key=",which); | ||
365 | { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); } | ||
366 | #endif | ||
367 | if (is_export) | ||
368 | { | ||
369 | /* In here I set both the read and write key/iv to the | ||
370 | * same value since only the correct one will be used :-). | ||
371 | */ | ||
372 | p=buf; | ||
373 | memcpy(p,exp_label,exp_label_len); | ||
374 | p+=exp_label_len; | ||
375 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
376 | p+=SSL3_RANDOM_SIZE; | ||
377 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
378 | p+=SSL3_RANDOM_SIZE; | ||
379 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),key,j, | ||
380 | tmp1,tmp2,EVP_CIPHER_key_length(c)); | ||
381 | key=tmp1; | ||
382 | |||
383 | if (k > 0) | ||
384 | { | ||
385 | p=buf; | ||
386 | memcpy(p,TLS_MD_IV_BLOCK_CONST, | ||
387 | TLS_MD_IV_BLOCK_CONST_SIZE); | ||
388 | p+=TLS_MD_IV_BLOCK_CONST_SIZE; | ||
389 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
390 | p+=SSL3_RANDOM_SIZE; | ||
391 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
392 | p+=SSL3_RANDOM_SIZE; | ||
393 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,empty,0, | ||
394 | iv1,iv2,k*2); | ||
395 | if (client_write) | ||
396 | iv=iv1; | ||
397 | else | ||
398 | iv= &(iv1[k]); | ||
399 | } | ||
400 | } | ||
401 | |||
402 | s->session->key_arg_length=0; | ||
403 | #ifdef KSSL_DEBUG | ||
404 | { | ||
405 | int i; | ||
406 | printf("EVP_CipherInit_ex(dd,c,key=,iv=,which)\n"); | ||
407 | printf("\tkey= "); for (i=0; i<c->key_len; i++) printf("%02x", key[i]); | ||
408 | printf("\n"); | ||
409 | printf("\t iv= "); for (i=0; i<c->iv_len; i++) printf("%02x", iv[i]); | ||
410 | printf("\n"); | ||
411 | } | ||
412 | #endif /* KSSL_DEBUG */ | ||
413 | |||
414 | EVP_CipherInit_ex(dd,c,NULL,key,iv,(which & SSL3_CC_WRITE)); | ||
415 | #ifdef TLS_DEBUG | ||
416 | printf("which = %04X\nkey=",which); | ||
417 | { int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); } | ||
418 | printf("\niv="); | ||
419 | { int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); } | ||
420 | printf("\n"); | ||
421 | #endif | ||
422 | |||
423 | OPENSSL_cleanse(tmp1,sizeof(tmp1)); | ||
424 | OPENSSL_cleanse(tmp2,sizeof(tmp1)); | ||
425 | OPENSSL_cleanse(iv1,sizeof(iv1)); | ||
426 | OPENSSL_cleanse(iv2,sizeof(iv2)); | ||
427 | return(1); | ||
428 | err: | ||
429 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE); | ||
430 | err2: | ||
431 | return(0); | ||
432 | } | ||
433 | |||
434 | int tls1_setup_key_block(SSL *s) | ||
435 | { | ||
436 | unsigned char *p1,*p2; | ||
437 | const EVP_CIPHER *c; | ||
438 | const EVP_MD *hash; | ||
439 | int num; | ||
440 | SSL_COMP *comp; | ||
441 | |||
442 | #ifdef KSSL_DEBUG | ||
443 | printf ("tls1_setup_key_block()\n"); | ||
444 | #endif /* KSSL_DEBUG */ | ||
445 | |||
446 | if (s->s3->tmp.key_block_length != 0) | ||
447 | return(1); | ||
448 | |||
449 | if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp)) | ||
450 | { | ||
451 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | ||
452 | return(0); | ||
453 | } | ||
454 | |||
455 | s->s3->tmp.new_sym_enc=c; | ||
456 | s->s3->tmp.new_hash=hash; | ||
457 | |||
458 | num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c); | ||
459 | num*=2; | ||
460 | |||
461 | ssl3_cleanup_key_block(s); | ||
462 | |||
463 | if ((p1=(unsigned char *)OPENSSL_malloc(num)) == NULL) | ||
464 | goto err; | ||
465 | if ((p2=(unsigned char *)OPENSSL_malloc(num)) == NULL) | ||
466 | goto err; | ||
467 | |||
468 | s->s3->tmp.key_block_length=num; | ||
469 | s->s3->tmp.key_block=p1; | ||
470 | |||
471 | |||
472 | #ifdef TLS_DEBUG | ||
473 | printf("client random\n"); | ||
474 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); } | ||
475 | printf("server random\n"); | ||
476 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); } | ||
477 | printf("pre-master\n"); | ||
478 | { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); } | ||
479 | #endif | ||
480 | tls1_generate_key_block(s,p1,p2,num); | ||
481 | OPENSSL_cleanse(p2,num); | ||
482 | OPENSSL_free(p2); | ||
483 | #ifdef TLS_DEBUG | ||
484 | printf("\nkey block\n"); | ||
485 | { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); } | ||
486 | #endif | ||
487 | |||
488 | if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)) | ||
489 | { | ||
490 | /* enable vulnerability countermeasure for CBC ciphers with | ||
491 | * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt) | ||
492 | */ | ||
493 | s->s3->need_empty_fragments = 1; | ||
494 | |||
495 | if (s->session->cipher != NULL) | ||
496 | { | ||
497 | if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_eNULL) | ||
498 | s->s3->need_empty_fragments = 0; | ||
499 | |||
500 | #ifndef OPENSSL_NO_RC4 | ||
501 | if ((s->session->cipher->algorithms & SSL_ENC_MASK) == SSL_RC4) | ||
502 | s->s3->need_empty_fragments = 0; | ||
503 | #endif | ||
504 | } | ||
505 | } | ||
506 | |||
507 | return(1); | ||
508 | err: | ||
509 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); | ||
510 | return(0); | ||
511 | } | ||
512 | |||
513 | int tls1_enc(SSL *s, int send) | ||
514 | { | ||
515 | SSL3_RECORD *rec; | ||
516 | EVP_CIPHER_CTX *ds; | ||
517 | unsigned long l; | ||
518 | int bs,i,ii,j,k,n=0; | ||
519 | const EVP_CIPHER *enc; | ||
520 | |||
521 | if (send) | ||
522 | { | ||
523 | if (s->write_hash != NULL) | ||
524 | n=EVP_MD_size(s->write_hash); | ||
525 | ds=s->enc_write_ctx; | ||
526 | rec= &(s->s3->wrec); | ||
527 | if (s->enc_write_ctx == NULL) | ||
528 | enc=NULL; | ||
529 | else | ||
530 | enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); | ||
531 | } | ||
532 | else | ||
533 | { | ||
534 | if (s->read_hash != NULL) | ||
535 | n=EVP_MD_size(s->read_hash); | ||
536 | ds=s->enc_read_ctx; | ||
537 | rec= &(s->s3->rrec); | ||
538 | if (s->enc_read_ctx == NULL) | ||
539 | enc=NULL; | ||
540 | else | ||
541 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); | ||
542 | } | ||
543 | |||
544 | #ifdef KSSL_DEBUG | ||
545 | printf("tls1_enc(%d)\n", send); | ||
546 | #endif /* KSSL_DEBUG */ | ||
547 | |||
548 | if ((s->session == NULL) || (ds == NULL) || | ||
549 | (enc == NULL)) | ||
550 | { | ||
551 | memmove(rec->data,rec->input,rec->length); | ||
552 | rec->input=rec->data; | ||
553 | } | ||
554 | else | ||
555 | { | ||
556 | l=rec->length; | ||
557 | bs=EVP_CIPHER_block_size(ds->cipher); | ||
558 | |||
559 | if ((bs != 1) && send) | ||
560 | { | ||
561 | i=bs-((int)l%bs); | ||
562 | |||
563 | /* Add weird padding of upto 256 bytes */ | ||
564 | |||
565 | /* we need to add 'i' padding bytes of value j */ | ||
566 | j=i-1; | ||
567 | if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
568 | { | ||
569 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
570 | j++; | ||
571 | } | ||
572 | for (k=(int)l; k<(int)(l+i); k++) | ||
573 | rec->input[k]=j; | ||
574 | l+=i; | ||
575 | rec->length+=i; | ||
576 | } | ||
577 | |||
578 | #ifdef KSSL_DEBUG | ||
579 | { | ||
580 | unsigned long ui; | ||
581 | printf("EVP_Cipher(ds=%p,rec->data=%p,rec->input=%p,l=%ld) ==>\n", | ||
582 | ds,rec->data,rec->input,l); | ||
583 | printf("\tEVP_CIPHER_CTX: %d buf_len, %d key_len [%d %d], %d iv_len\n", | ||
584 | ds->buf_len, ds->cipher->key_len, | ||
585 | DES_KEY_SZ, DES_SCHEDULE_SZ, | ||
586 | ds->cipher->iv_len); | ||
587 | printf("\t\tIV: "); | ||
588 | for (i=0; i<ds->cipher->iv_len; i++) printf("%02X", ds->iv[i]); | ||
589 | printf("\n"); | ||
590 | printf("\trec->input="); | ||
591 | for (ui=0; ui<l; ui++) printf(" %02x", rec->input[ui]); | ||
592 | printf("\n"); | ||
593 | } | ||
594 | #endif /* KSSL_DEBUG */ | ||
595 | |||
596 | if (!send) | ||
597 | { | ||
598 | if (l == 0 || l%bs != 0) | ||
599 | { | ||
600 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | ||
601 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
602 | return 0; | ||
603 | } | ||
604 | } | ||
605 | |||
606 | EVP_Cipher(ds,rec->data,rec->input,l); | ||
607 | |||
608 | #ifdef KSSL_DEBUG | ||
609 | { | ||
610 | unsigned long i; | ||
611 | printf("\trec->data="); | ||
612 | for (i=0; i<l; i++) | ||
613 | printf(" %02x", rec->data[i]); printf("\n"); | ||
614 | } | ||
615 | #endif /* KSSL_DEBUG */ | ||
616 | |||
617 | if ((bs != 1) && !send) | ||
618 | { | ||
619 | ii=i=rec->data[l-1]; /* padding_length */ | ||
620 | i++; | ||
621 | if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
622 | { | ||
623 | /* First packet is even in size, so check */ | ||
624 | if ((memcmp(s->s3->read_sequence, | ||
625 | "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1)) | ||
626 | s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG; | ||
627 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
628 | i--; | ||
629 | } | ||
630 | /* TLS 1.0 does not bound the number of padding bytes by the block size. | ||
631 | * All of them must have value 'padding_length'. */ | ||
632 | if (i > (int)rec->length) | ||
633 | { | ||
634 | /* Incorrect padding. SSLerr() and ssl3_alert are done | ||
635 | * by caller: we don't want to reveal whether this is | ||
636 | * a decryption error or a MAC verification failure | ||
637 | * (see http://www.openssl.org/~bodo/tls-cbc.txt) */ | ||
638 | return -1; | ||
639 | } | ||
640 | for (j=(int)(l-i); j<(int)l; j++) | ||
641 | { | ||
642 | if (rec->data[j] != ii) | ||
643 | { | ||
644 | /* Incorrect padding */ | ||
645 | return -1; | ||
646 | } | ||
647 | } | ||
648 | rec->length-=i; | ||
649 | } | ||
650 | } | ||
651 | return(1); | ||
652 | } | ||
653 | |||
654 | int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out) | ||
655 | { | ||
656 | unsigned int ret; | ||
657 | EVP_MD_CTX ctx; | ||
658 | |||
659 | EVP_MD_CTX_init(&ctx); | ||
660 | EVP_MD_CTX_copy_ex(&ctx,in_ctx); | ||
661 | EVP_DigestFinal_ex(&ctx,out,&ret); | ||
662 | EVP_MD_CTX_cleanup(&ctx); | ||
663 | return((int)ret); | ||
664 | } | ||
665 | |||
666 | int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | ||
667 | const char *str, int slen, unsigned char *out) | ||
668 | { | ||
669 | unsigned int i; | ||
670 | EVP_MD_CTX ctx; | ||
671 | unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
672 | unsigned char *q,buf2[12]; | ||
673 | |||
674 | q=buf; | ||
675 | memcpy(q,str,slen); | ||
676 | q+=slen; | ||
677 | |||
678 | EVP_MD_CTX_init(&ctx); | ||
679 | EVP_MD_CTX_copy_ex(&ctx,in1_ctx); | ||
680 | EVP_DigestFinal_ex(&ctx,q,&i); | ||
681 | q+=i; | ||
682 | EVP_MD_CTX_copy_ex(&ctx,in2_ctx); | ||
683 | EVP_DigestFinal_ex(&ctx,q,&i); | ||
684 | q+=i; | ||
685 | |||
686 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), | ||
687 | s->session->master_key,s->session->master_key_length, | ||
688 | out,buf2,sizeof buf2); | ||
689 | EVP_MD_CTX_cleanup(&ctx); | ||
690 | |||
691 | return sizeof buf2; | ||
692 | } | ||
693 | |||
694 | int tls1_mac(SSL *ssl, unsigned char *md, int send) | ||
695 | { | ||
696 | SSL3_RECORD *rec; | ||
697 | unsigned char *mac_sec,*seq; | ||
698 | const EVP_MD *hash; | ||
699 | unsigned int md_size; | ||
700 | int i; | ||
701 | HMAC_CTX hmac; | ||
702 | unsigned char buf[5]; | ||
703 | |||
704 | if (send) | ||
705 | { | ||
706 | rec= &(ssl->s3->wrec); | ||
707 | mac_sec= &(ssl->s3->write_mac_secret[0]); | ||
708 | seq= &(ssl->s3->write_sequence[0]); | ||
709 | hash=ssl->write_hash; | ||
710 | } | ||
711 | else | ||
712 | { | ||
713 | rec= &(ssl->s3->rrec); | ||
714 | mac_sec= &(ssl->s3->read_mac_secret[0]); | ||
715 | seq= &(ssl->s3->read_sequence[0]); | ||
716 | hash=ssl->read_hash; | ||
717 | } | ||
718 | |||
719 | md_size=EVP_MD_size(hash); | ||
720 | |||
721 | buf[0]=rec->type; | ||
722 | buf[1]=TLS1_VERSION_MAJOR; | ||
723 | buf[2]=TLS1_VERSION_MINOR; | ||
724 | buf[3]=rec->length>>8; | ||
725 | buf[4]=rec->length&0xff; | ||
726 | |||
727 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | ||
728 | HMAC_CTX_init(&hmac); | ||
729 | HMAC_Init_ex(&hmac,mac_sec,EVP_MD_size(hash),hash,NULL); | ||
730 | HMAC_Update(&hmac,seq,8); | ||
731 | HMAC_Update(&hmac,buf,5); | ||
732 | HMAC_Update(&hmac,rec->input,rec->length); | ||
733 | HMAC_Final(&hmac,md,&md_size); | ||
734 | HMAC_CTX_cleanup(&hmac); | ||
735 | |||
736 | #ifdef TLS_DEBUG | ||
737 | printf("sec="); | ||
738 | {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); } | ||
739 | printf("seq="); | ||
740 | {int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); } | ||
741 | printf("buf="); | ||
742 | {int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
743 | printf("rec="); | ||
744 | {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
745 | #endif | ||
746 | |||
747 | for (i=7; i>=0; i--) | ||
748 | { | ||
749 | ++seq[i]; | ||
750 | if (seq[i] != 0) break; | ||
751 | } | ||
752 | |||
753 | #ifdef TLS_DEBUG | ||
754 | {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); } | ||
755 | #endif | ||
756 | return(md_size); | ||
757 | } | ||
758 | |||
759 | int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | ||
760 | int len) | ||
761 | { | ||
762 | unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE]; | ||
763 | unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; | ||
764 | |||
765 | #ifdef KSSL_DEBUG | ||
766 | printf ("tls1_generate_master_secret(%p,%p, %p, %d)\n", s,out, p,len); | ||
767 | #endif /* KSSL_DEBUG */ | ||
768 | |||
769 | /* Setup the stuff to munge */ | ||
770 | memcpy(buf,TLS_MD_MASTER_SECRET_CONST, | ||
771 | TLS_MD_MASTER_SECRET_CONST_SIZE); | ||
772 | memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
773 | s->s3->client_random,SSL3_RANDOM_SIZE); | ||
774 | memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
775 | s->s3->server_random,SSL3_RANDOM_SIZE); | ||
776 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | ||
777 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, | ||
778 | s->session->master_key,buff,sizeof buff); | ||
779 | #ifdef KSSL_DEBUG | ||
780 | printf ("tls1_generate_master_secret() complete\n"); | ||
781 | #endif /* KSSL_DEBUG */ | ||
782 | return(SSL3_MASTER_SECRET_SIZE); | ||
783 | } | ||
784 | |||
785 | int tls1_alert_code(int code) | ||
786 | { | ||
787 | switch (code) | ||
788 | { | ||
789 | case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY); | ||
790 | case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE); | ||
791 | case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC); | ||
792 | case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED); | ||
793 | case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW); | ||
794 | case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE); | ||
795 | case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE); | ||
796 | case SSL_AD_NO_CERTIFICATE: return(-1); | ||
797 | case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE); | ||
798 | case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE); | ||
799 | case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED); | ||
800 | case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED); | ||
801 | case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN); | ||
802 | case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER); | ||
803 | case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA); | ||
804 | case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED); | ||
805 | case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR); | ||
806 | case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR); | ||
807 | case SSL_AD_EXPORT_RESTRICTION: return(TLS1_AD_EXPORT_RESTRICTION); | ||
808 | case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION); | ||
809 | case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY); | ||
810 | case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR); | ||
811 | case SSL_AD_USER_CANCELLED: return(TLS1_AD_USER_CANCELLED); | ||
812 | case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION); | ||
813 | default: return(-1); | ||
814 | } | ||
815 | } | ||
816 | |||
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c deleted file mode 100644 index ca6c03d5af..0000000000 --- a/src/lib/libssl/t1_lib.c +++ /dev/null | |||
@@ -1,149 +0,0 @@ | |||
1 | /* ssl/t1_lib.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/objects.h> | ||
61 | #include "ssl_locl.h" | ||
62 | |||
63 | const char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT; | ||
64 | |||
65 | static long tls1_default_timeout(void); | ||
66 | |||
67 | static SSL3_ENC_METHOD TLSv1_enc_data={ | ||
68 | tls1_enc, | ||
69 | tls1_mac, | ||
70 | tls1_setup_key_block, | ||
71 | tls1_generate_master_secret, | ||
72 | tls1_change_cipher_state, | ||
73 | tls1_final_finish_mac, | ||
74 | TLS1_FINISH_MAC_LENGTH, | ||
75 | tls1_cert_verify_mac, | ||
76 | TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE, | ||
77 | TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE, | ||
78 | tls1_alert_code, | ||
79 | }; | ||
80 | |||
81 | static SSL_METHOD TLSv1_data= { | ||
82 | TLS1_VERSION, | ||
83 | tls1_new, | ||
84 | tls1_clear, | ||
85 | tls1_free, | ||
86 | ssl_undefined_function, | ||
87 | ssl_undefined_function, | ||
88 | ssl3_read, | ||
89 | ssl3_peek, | ||
90 | ssl3_write, | ||
91 | ssl3_shutdown, | ||
92 | ssl3_renegotiate, | ||
93 | ssl3_renegotiate_check, | ||
94 | ssl3_ctrl, | ||
95 | ssl3_ctx_ctrl, | ||
96 | ssl3_get_cipher_by_char, | ||
97 | ssl3_put_cipher_by_char, | ||
98 | ssl3_pending, | ||
99 | ssl3_num_ciphers, | ||
100 | ssl3_get_cipher, | ||
101 | ssl_bad_method, | ||
102 | tls1_default_timeout, | ||
103 | &TLSv1_enc_data, | ||
104 | ssl_undefined_function, | ||
105 | ssl3_callback_ctrl, | ||
106 | ssl3_ctx_callback_ctrl, | ||
107 | }; | ||
108 | |||
109 | static long tls1_default_timeout(void) | ||
110 | { | ||
111 | /* 2 hours, the 24 hours mentioned in the TLSv1 spec | ||
112 | * is way too long for http, the cache would over fill */ | ||
113 | return(60*60*2); | ||
114 | } | ||
115 | |||
116 | SSL_METHOD *tlsv1_base_method(void) | ||
117 | { | ||
118 | return(&TLSv1_data); | ||
119 | } | ||
120 | |||
121 | int tls1_new(SSL *s) | ||
122 | { | ||
123 | if (!ssl3_new(s)) return(0); | ||
124 | s->method->ssl_clear(s); | ||
125 | return(1); | ||
126 | } | ||
127 | |||
128 | void tls1_free(SSL *s) | ||
129 | { | ||
130 | ssl3_free(s); | ||
131 | } | ||
132 | |||
133 | void tls1_clear(SSL *s) | ||
134 | { | ||
135 | ssl3_clear(s); | ||
136 | s->version=TLS1_VERSION; | ||
137 | } | ||
138 | |||
139 | #if 0 | ||
140 | long tls1_ctrl(SSL *s, int cmd, long larg, char *parg) | ||
141 | { | ||
142 | return(0); | ||
143 | } | ||
144 | |||
145 | long tls1_callback_ctrl(SSL *s, int cmd, void *(*fp)()) | ||
146 | { | ||
147 | return(0); | ||
148 | } | ||
149 | #endif | ||
diff --git a/src/lib/libssl/t1_meth.c b/src/lib/libssl/t1_meth.c deleted file mode 100644 index fcc243f782..0000000000 --- a/src/lib/libssl/t1_meth.c +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* ssl/t1_meth.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/objects.h> | ||
61 | #include "ssl_locl.h" | ||
62 | |||
63 | static SSL_METHOD *tls1_get_method(int ver); | ||
64 | static SSL_METHOD *tls1_get_method(int ver) | ||
65 | { | ||
66 | if (ver == TLS1_VERSION) | ||
67 | return(TLSv1_method()); | ||
68 | else | ||
69 | return(NULL); | ||
70 | } | ||
71 | |||
72 | SSL_METHOD *TLSv1_method(void) | ||
73 | { | ||
74 | static int init=1; | ||
75 | static SSL_METHOD TLSv1_data; | ||
76 | |||
77 | if (init) | ||
78 | { | ||
79 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
80 | |||
81 | if (init) | ||
82 | { | ||
83 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), | ||
84 | sizeof(SSL_METHOD)); | ||
85 | TLSv1_data.ssl_connect=ssl3_connect; | ||
86 | TLSv1_data.ssl_accept=ssl3_accept; | ||
87 | TLSv1_data.get_ssl_method=tls1_get_method; | ||
88 | init=0; | ||
89 | } | ||
90 | |||
91 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
92 | } | ||
93 | |||
94 | return(&TLSv1_data); | ||
95 | } | ||
96 | |||
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c deleted file mode 100644 index 1c1149e49f..0000000000 --- a/src/lib/libssl/t1_srvr.c +++ /dev/null | |||
@@ -1,98 +0,0 @@ | |||
1 | /* ssl/t1_srvr.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include "ssl_locl.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/evp.h> | ||
65 | #include <openssl/x509.h> | ||
66 | |||
67 | static SSL_METHOD *tls1_get_server_method(int ver); | ||
68 | static SSL_METHOD *tls1_get_server_method(int ver) | ||
69 | { | ||
70 | if (ver == TLS1_VERSION) | ||
71 | return(TLSv1_server_method()); | ||
72 | else | ||
73 | return(NULL); | ||
74 | } | ||
75 | |||
76 | SSL_METHOD *TLSv1_server_method(void) | ||
77 | { | ||
78 | static int init=1; | ||
79 | static SSL_METHOD TLSv1_server_data; | ||
80 | |||
81 | if (init) | ||
82 | { | ||
83 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); | ||
84 | |||
85 | if (init) | ||
86 | { | ||
87 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), | ||
88 | sizeof(SSL_METHOD)); | ||
89 | TLSv1_server_data.ssl_accept=ssl3_accept; | ||
90 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | ||
91 | init=0; | ||
92 | } | ||
93 | |||
94 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
95 | } | ||
96 | return(&TLSv1_server_data); | ||
97 | } | ||
98 | |||
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf deleted file mode 100644 index 21da59a73a..0000000000 --- a/src/lib/libssl/test/CAss.cnf +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | RANDFILE = ./.rnd | ||
7 | |||
8 | #################################################################### | ||
9 | [ req ] | ||
10 | default_bits = 512 | ||
11 | default_keyfile = keySS.pem | ||
12 | distinguished_name = req_distinguished_name | ||
13 | encrypt_rsa_key = no | ||
14 | default_md = sha1 | ||
15 | |||
16 | [ req_distinguished_name ] | ||
17 | countryName = Country Name (2 letter code) | ||
18 | countryName_default = AU | ||
19 | countryName_value = AU | ||
20 | |||
21 | organizationName = Organization Name (eg, company) | ||
22 | organizationName_value = Dodgy Brothers | ||
23 | |||
24 | commonName = Common Name (eg, YOUR name) | ||
25 | commonName_value = Dodgy CA | ||
26 | |||
27 | [ v3_ca ] | ||
28 | subjectKeyIdentifier=hash | ||
29 | authorityKeyIdentifier=keyid:always,issuer:always | ||
30 | basicConstraints = CA:true,pathlen:1 | ||
31 | keyUsage = cRLSign, keyCertSign | ||
32 | issuerAltName=issuer:copy | ||
33 | |||
diff --git a/src/lib/libssl/test/CAssdh.cnf b/src/lib/libssl/test/CAssdh.cnf deleted file mode 100644 index 4e0a908679..0000000000 --- a/src/lib/libssl/test/CAssdh.cnf +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | # hacked by iang to do DH certs - CA | ||
6 | |||
7 | RANDFILE = ./.rnd | ||
8 | |||
9 | #################################################################### | ||
10 | [ req ] | ||
11 | distinguished_name = req_distinguished_name | ||
12 | encrypt_rsa_key = no | ||
13 | |||
14 | [ req_distinguished_name ] | ||
15 | countryName = Country Name (2 letter code) | ||
16 | countryName_default = CU | ||
17 | countryName_value = CU | ||
18 | |||
19 | organizationName = Organization Name (eg, company) | ||
20 | organizationName_value = La Junta de la Revolucion | ||
21 | |||
22 | commonName = Common Name (eg, YOUR name) | ||
23 | commonName_value = Junta | ||
24 | |||
diff --git a/src/lib/libssl/test/CAssdsa.cnf b/src/lib/libssl/test/CAssdsa.cnf deleted file mode 100644 index a6b4d1810c..0000000000 --- a/src/lib/libssl/test/CAssdsa.cnf +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | # hacked by iang to do DSA certs - CA | ||
6 | |||
7 | RANDFILE = ./.rnd | ||
8 | |||
9 | #################################################################### | ||
10 | [ req ] | ||
11 | distinguished_name = req_distinguished_name | ||
12 | encrypt_rsa_key = no | ||
13 | |||
14 | [ req_distinguished_name ] | ||
15 | countryName = Country Name (2 letter code) | ||
16 | countryName_default = ES | ||
17 | countryName_value = ES | ||
18 | |||
19 | organizationName = Organization Name (eg, company) | ||
20 | organizationName_value = Hermanos Locos | ||
21 | |||
22 | commonName = Common Name (eg, YOUR name) | ||
23 | commonName_value = Hermanos Locos CA | ||
diff --git a/src/lib/libssl/test/CAssrsa.cnf b/src/lib/libssl/test/CAssrsa.cnf deleted file mode 100644 index eb24a6dfc0..0000000000 --- a/src/lib/libssl/test/CAssrsa.cnf +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | # create RSA certs - CA | ||
6 | |||
7 | RANDFILE = ./.rnd | ||
8 | |||
9 | #################################################################### | ||
10 | [ req ] | ||
11 | distinguished_name = req_distinguished_name | ||
12 | encrypt_key = no | ||
13 | |||
14 | [ req_distinguished_name ] | ||
15 | countryName = Country Name (2 letter code) | ||
16 | countryName_default = ES | ||
17 | countryName_value = ES | ||
18 | |||
19 | organizationName = Organization Name (eg, company) | ||
20 | organizationName_value = Hermanos Locos | ||
21 | |||
22 | commonName = Common Name (eg, YOUR name) | ||
23 | commonName_value = Hermanos Locos CA | ||
24 | |||
diff --git a/src/lib/libssl/test/P1ss.cnf b/src/lib/libssl/test/P1ss.cnf deleted file mode 100644 index 876a0d35f8..0000000000 --- a/src/lib/libssl/test/P1ss.cnf +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | RANDFILE = ./.rnd | ||
7 | |||
8 | #################################################################### | ||
9 | [ req ] | ||
10 | default_bits = 512 | ||
11 | default_keyfile = keySS.pem | ||
12 | distinguished_name = req_distinguished_name | ||
13 | encrypt_rsa_key = no | ||
14 | default_md = md2 | ||
15 | |||
16 | [ req_distinguished_name ] | ||
17 | countryName = Country Name (2 letter code) | ||
18 | countryName_default = AU | ||
19 | countryName_value = AU | ||
20 | |||
21 | organizationName = Organization Name (eg, company) | ||
22 | organizationName_value = Dodgy Brothers | ||
23 | |||
24 | 0.commonName = Common Name (eg, YOUR name) | ||
25 | 0.commonName_value = Brother 1 | ||
26 | |||
27 | 1.commonName = Common Name (eg, YOUR name) | ||
28 | 1.commonName_value = Brother 2 | ||
29 | |||
30 | 2.commonName = Common Name (eg, YOUR name) | ||
31 | 2.commonName_value = Proxy 1 | ||
32 | |||
33 | [ v3_proxy ] | ||
34 | basicConstraints=CA:FALSE | ||
35 | subjectKeyIdentifier=hash | ||
36 | authorityKeyIdentifier=keyid,issuer:always | ||
37 | proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB | ||
diff --git a/src/lib/libssl/test/P2ss.cnf b/src/lib/libssl/test/P2ss.cnf deleted file mode 100644 index 373a87e7c2..0000000000 --- a/src/lib/libssl/test/P2ss.cnf +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | RANDFILE = ./.rnd | ||
7 | |||
8 | #################################################################### | ||
9 | [ req ] | ||
10 | default_bits = 512 | ||
11 | default_keyfile = keySS.pem | ||
12 | distinguished_name = req_distinguished_name | ||
13 | encrypt_rsa_key = no | ||
14 | default_md = md2 | ||
15 | |||
16 | [ req_distinguished_name ] | ||
17 | countryName = Country Name (2 letter code) | ||
18 | countryName_default = AU | ||
19 | countryName_value = AU | ||
20 | |||
21 | organizationName = Organization Name (eg, company) | ||
22 | organizationName_value = Dodgy Brothers | ||
23 | |||
24 | 0.commonName = Common Name (eg, YOUR name) | ||
25 | 0.commonName_value = Brother 1 | ||
26 | |||
27 | 1.commonName = Common Name (eg, YOUR name) | ||
28 | 1.commonName_value = Brother 2 | ||
29 | |||
30 | 2.commonName = Common Name (eg, YOUR name) | ||
31 | 2.commonName_value = Proxy 1 | ||
32 | |||
33 | 3.commonName = Common Name (eg, YOUR name) | ||
34 | 3.commonName_value = Proxy 2 | ||
35 | |||
36 | [ v3_proxy ] | ||
37 | basicConstraints=CA:FALSE | ||
38 | subjectKeyIdentifier=hash | ||
39 | authorityKeyIdentifier=keyid,issuer:always | ||
40 | proxyCertInfo=critical,@proxy_ext | ||
41 | |||
42 | [ proxy_ext ] | ||
43 | language=id-ppl-anyLanguage | ||
44 | pathlen=0 | ||
45 | policy=text:BC | ||
diff --git a/src/lib/libssl/test/Sssdsa.cnf b/src/lib/libssl/test/Sssdsa.cnf deleted file mode 100644 index 8e170a28ef..0000000000 --- a/src/lib/libssl/test/Sssdsa.cnf +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | # hacked by iang to do DSA certs - Server | ||
6 | |||
7 | RANDFILE = ./.rnd | ||
8 | |||
9 | #################################################################### | ||
10 | [ req ] | ||
11 | distinguished_name = req_distinguished_name | ||
12 | encrypt_rsa_key = no | ||
13 | |||
14 | [ req_distinguished_name ] | ||
15 | countryName = Country Name (2 letter code) | ||
16 | countryName_default = ES | ||
17 | countryName_value = ES | ||
18 | |||
19 | organizationName = Organization Name (eg, company) | ||
20 | organizationName_value = Tortilleras S.A. | ||
21 | |||
22 | 0.commonName = Common Name (eg, YOUR name) | ||
23 | 0.commonName_value = Torti | ||
24 | |||
25 | 1.commonName = Common Name (eg, YOUR name) | ||
26 | 1.commonName_value = Gordita | ||
27 | |||
diff --git a/src/lib/libssl/test/Sssrsa.cnf b/src/lib/libssl/test/Sssrsa.cnf deleted file mode 100644 index 8c79a03fca..0000000000 --- a/src/lib/libssl/test/Sssrsa.cnf +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | # create RSA certs - Server | ||
6 | |||
7 | RANDFILE = ./.rnd | ||
8 | |||
9 | #################################################################### | ||
10 | [ req ] | ||
11 | distinguished_name = req_distinguished_name | ||
12 | encrypt_key = no | ||
13 | |||
14 | [ req_distinguished_name ] | ||
15 | countryName = Country Name (2 letter code) | ||
16 | countryName_default = ES | ||
17 | countryName_value = ES | ||
18 | |||
19 | organizationName = Organization Name (eg, company) | ||
20 | organizationName_value = Tortilleras S.A. | ||
21 | |||
22 | 0.commonName = Common Name (eg, YOUR name) | ||
23 | 0.commonName_value = Torti | ||
24 | |||
25 | 1.commonName = Common Name (eg, YOUR name) | ||
26 | 1.commonName_value = Gordita | ||
diff --git a/src/lib/libssl/test/Uss.cnf b/src/lib/libssl/test/Uss.cnf deleted file mode 100644 index 0c0ebb5f67..0000000000 --- a/src/lib/libssl/test/Uss.cnf +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | RANDFILE = ./.rnd | ||
7 | |||
8 | #################################################################### | ||
9 | [ req ] | ||
10 | default_bits = 512 | ||
11 | default_keyfile = keySS.pem | ||
12 | distinguished_name = req_distinguished_name | ||
13 | encrypt_rsa_key = no | ||
14 | default_md = md2 | ||
15 | |||
16 | [ req_distinguished_name ] | ||
17 | countryName = Country Name (2 letter code) | ||
18 | countryName_default = AU | ||
19 | countryName_value = AU | ||
20 | |||
21 | organizationName = Organization Name (eg, company) | ||
22 | organizationName_value = Dodgy Brothers | ||
23 | |||
24 | 0.commonName = Common Name (eg, YOUR name) | ||
25 | 0.commonName_value = Brother 1 | ||
26 | |||
27 | 1.commonName = Common Name (eg, YOUR name) | ||
28 | 1.commonName_value = Brother 2 | ||
29 | |||
30 | [ v3_ee ] | ||
31 | subjectKeyIdentifier=hash | ||
32 | authorityKeyIdentifier=keyid,issuer:always | ||
33 | basicConstraints = CA:false | ||
34 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
35 | issuerAltName=issuer:copy | ||
36 | |||
diff --git a/src/lib/libssl/test/VMSca-response.1 b/src/lib/libssl/test/VMSca-response.1 deleted file mode 100644 index 8b13789179..0000000000 --- a/src/lib/libssl/test/VMSca-response.1 +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | |||
diff --git a/src/lib/libssl/test/VMSca-response.2 b/src/lib/libssl/test/VMSca-response.2 deleted file mode 100644 index 9b48ee4cf9..0000000000 --- a/src/lib/libssl/test/VMSca-response.2 +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | y | ||
2 | y | ||
diff --git a/src/lib/libssl/test/bctest b/src/lib/libssl/test/bctest deleted file mode 100644 index e81fc0733a..0000000000 --- a/src/lib/libssl/test/bctest +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # This script is used by test/Makefile to check whether a sane 'bc' | ||
4 | # is installed. | ||
5 | # ('make test_bn' should not try to run 'bc' if it does not exist or if | ||
6 | # it is a broken 'bc' version that is known to cause trouble.) | ||
7 | # | ||
8 | # If 'bc' works, we also test if it knows the 'print' command. | ||
9 | # | ||
10 | # In any case, output an appropriate command line for running (or not | ||
11 | # running) bc. | ||
12 | |||
13 | |||
14 | IFS=: | ||
15 | try_without_dir=true | ||
16 | # First we try "bc", then "$dir/bc" for each item in $PATH. | ||
17 | for dir in dummy:$PATH; do | ||
18 | if [ "$try_without_dir" = true ]; then | ||
19 | # first iteration | ||
20 | bc=bc | ||
21 | try_without_dir=false | ||
22 | else | ||
23 | # second and later iterations | ||
24 | bc="$dir/bc" | ||
25 | if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix | ||
26 | bc='' | ||
27 | fi | ||
28 | fi | ||
29 | |||
30 | if [ ! "$bc" = '' ]; then | ||
31 | failure=none | ||
32 | |||
33 | |||
34 | # Test for SunOS 5.[78] bc bug | ||
35 | "$bc" >tmp.bctest <<\EOF | ||
36 | obase=16 | ||
37 | ibase=16 | ||
38 | a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\ | ||
39 | CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\ | ||
40 | 10F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\ | ||
41 | C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\ | ||
42 | 3BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\ | ||
43 | 4FC3CADF855448B24A9D7640BCF473E | ||
44 | b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\ | ||
45 | 9209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\ | ||
46 | 8B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\ | ||
47 | 3ED0E2017D60A68775B75481449 | ||
48 | (a/b)*b + (a%b) - a | ||
49 | EOF | ||
50 | if [ 0 != "`cat tmp.bctest`" ]; then | ||
51 | failure=SunOStest | ||
52 | fi | ||
53 | |||
54 | |||
55 | if [ "$failure" = none ]; then | ||
56 | # Test for SCO bc bug. | ||
57 | "$bc" >tmp.bctest <<\EOF | ||
58 | obase=16 | ||
59 | ibase=16 | ||
60 | -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\ | ||
61 | 9DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\ | ||
62 | 11B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\ | ||
63 | 1239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\ | ||
64 | AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\ | ||
65 | F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\ | ||
66 | B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\ | ||
67 | 02EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\ | ||
68 | 85EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\ | ||
69 | A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\ | ||
70 | E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\ | ||
71 | 8C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\ | ||
72 | 04E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\ | ||
73 | 89C8D71 | ||
74 | AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\ | ||
75 | 928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\ | ||
76 | 8A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\ | ||
77 | 37F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\ | ||
78 | E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\ | ||
79 | F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\ | ||
80 | 9E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\ | ||
81 | D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\ | ||
82 | 5296964 | ||
83 | EOF | ||
84 | if [ "0 | ||
85 | 0" != "`cat tmp.bctest`" ]; then | ||
86 | failure=SCOtest | ||
87 | fi | ||
88 | fi | ||
89 | |||
90 | |||
91 | if [ "$failure" = none ]; then | ||
92 | # bc works; now check if it knows the 'print' command. | ||
93 | if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ] | ||
94 | then | ||
95 | echo "$bc" | ||
96 | else | ||
97 | echo "sed 's/print.*//' | $bc" | ||
98 | fi | ||
99 | exit 0 | ||
100 | fi | ||
101 | |||
102 | echo "$bc does not work properly ('$failure' failed). Looking for another bc ..." >&2 | ||
103 | fi | ||
104 | done | ||
105 | |||
106 | echo "No working bc found. Consider installing GNU bc." >&2 | ||
107 | if [ "$1" = ignore ]; then | ||
108 | echo "cat >/dev/null" | ||
109 | exit 0 | ||
110 | fi | ||
111 | exit 1 | ||
diff --git a/src/lib/libssl/test/methtest.c b/src/lib/libssl/test/methtest.c deleted file mode 100644 index 005c2f4822..0000000000 --- a/src/lib/libssl/test/methtest.c +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* test/methtest.c */ | ||
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 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <openssl/rsa.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include "meth.h" | ||
64 | #include <openssl/err.h> | ||
65 | |||
66 | int main(argc,argv) | ||
67 | int argc; | ||
68 | char *argv[]; | ||
69 | { | ||
70 | METHOD_CTX *top,*tmp1,*tmp2; | ||
71 | |||
72 | top=METH_new(x509_lookup()); /* get a top level context */ | ||
73 | if (top == NULL) goto err; | ||
74 | |||
75 | tmp1=METH_new(x509_by_file()); | ||
76 | if (top == NULL) goto err; | ||
77 | METH_arg(tmp1,METH_TYPE_FILE,"cafile1"); | ||
78 | METH_arg(tmp1,METH_TYPE_FILE,"cafile2"); | ||
79 | METH_push(top,METH_X509_CA_BY_SUBJECT,tmp1); | ||
80 | |||
81 | tmp2=METH_new(x509_by_dir()); | ||
82 | METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/.CAcerts"); | ||
83 | METH_arg(tmp2,METH_TYPE_DIR,"/home/eay/SSLeay/certs"); | ||
84 | METH_arg(tmp2,METH_TYPE_DIR,"/usr/local/ssl/certs"); | ||
85 | METH_push(top,METH_X509_CA_BY_SUBJECT,tmp2); | ||
86 | |||
87 | /* tmp=METH_new(x509_by_issuer_dir); | ||
88 | METH_arg(tmp,METH_TYPE_DIR,"/home/eay/.mycerts"); | ||
89 | METH_push(top,METH_X509_BY_ISSUER,tmp); | ||
90 | |||
91 | tmp=METH_new(x509_by_issuer_primary); | ||
92 | METH_arg(tmp,METH_TYPE_FILE,"/home/eay/.mycerts/primary.pem"); | ||
93 | METH_push(top,METH_X509_BY_ISSUER,tmp); | ||
94 | */ | ||
95 | |||
96 | METH_init(top); | ||
97 | METH_control(tmp1,METH_CONTROL_DUMP,stdout); | ||
98 | METH_control(tmp2,METH_CONTROL_DUMP,stdout); | ||
99 | EXIT(0); | ||
100 | err: | ||
101 | ERR_load_crypto_strings(); | ||
102 | ERR_print_errors_fp(stderr); | ||
103 | EXIT(1); | ||
104 | return(0); | ||
105 | } | ||
diff --git a/src/lib/libssl/test/pkcs7-1.pem b/src/lib/libssl/test/pkcs7-1.pem deleted file mode 100644 index c47b27af88..0000000000 --- a/src/lib/libssl/test/pkcs7-1.pem +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | -----BEGIN PKCS7----- | ||
2 | MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG | ||
3 | SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE | ||
4 | AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF | ||
5 | eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4 | ||
6 | MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv | ||
7 | bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK | ||
8 | ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB | ||
9 | FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N | ||
10 | 9XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8 | ||
11 | BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w | ||
12 | bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB | ||
13 | BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C | ||
14 | j7Kie1x339mxW/w9VZNTUDQQweHh | ||
15 | -----END PKCS7----- | ||
diff --git a/src/lib/libssl/test/pkcs7.pem b/src/lib/libssl/test/pkcs7.pem deleted file mode 100644 index d55c60b94e..0000000000 --- a/src/lib/libssl/test/pkcs7.pem +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | MIAGCSqGSIb3DQEHAqCAMIACAQExADCABgkqhkiG9w0BBwEAAKCAMIIE+DCCBGGg | ||
2 | AwIBAgIQaGSF/JpbS1C223+yrc+N1DANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQH | ||
3 | EwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1Zl | ||
4 | cmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYw | ||
5 | ODEyMDAwMDAwWhcNOTYwODE3MjM1OTU5WjCCASAxETAPBgNVBAcTCEludGVybmV0 | ||
6 | MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh | ||
7 | c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjE3MDUGA1UECxMuRGlnaXRh | ||
8 | bCBJRCBDbGFzcyAxIC0gU01JTUUgVmVyaVNpZ24sIEluYy4gVEVTVDFGMEQGA1UE | ||
9 | CxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJl | ||
10 | Zi4sTElBQi5MVEQoYyk5NjEZMBcGA1UEAxMQQWxleGFuZHJlIERlYWNvbjEgMB4G | ||
11 | CSqGSIb3DQEJARYRYWxleEB2ZXJpc2lnbi5jb20wWzANBgkqhkiG9w0BAQEFAANK | ||
12 | ADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDORl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0 | ||
13 | l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMBAAGjggIyMIICLjAJBgNVHRMEAjAAMIIC | ||
14 | HwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMg | ||
15 | Y2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzIGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1 | ||
16 | c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0bywgdGhlIFZlcmlTaWduIENlcnRpZmlj | ||
17 | YXRpb24gUHJhY3RpY2UgU3RhdGVtZW50IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0 | ||
18 | dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9DUFM7IGJ5IEUtbWFpbCBhdCBDUFMtcmVx | ||
19 | dWVzdHNAdmVyaXNpZ24uY29tOyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMu | ||
20 | LCAyNTkzIENvYXN0IEF2ZS4sIE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBU | ||
21 | ZWwuICsxICg0MTUpIDk2MS04ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2ln | ||
22 | biwgSW5jLiAgQWxsIFJpZ2h0cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVT | ||
23 | IERJU0NMQUlNRUQgYW5kIExJQUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcB | ||
24 | AQGhDgYMYIZIAYb4RQEHAQECMCwwKhYoaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t | ||
25 | L3JlcG9zaXRvcnkvQ1BTIDANBgkqhkiG9w0BAQQFAAOBgQAimWMGQwwwxk+b3KAL | ||
26 | HlSWXtU7LWHe29CEG8XeVNTvrqs6SBqT7OoENOkGxpfdpVgZ3Qw2SKjxDvbvpfSF | ||
27 | slsqcxWSgB/hWuaVuZCkvTw/dYGGOxkTJGxvDCfl1PZjX4dKbatslsi9Z9HpGWT7 | ||
28 | ttItRwKqcBKgmCJvKi1pGWED0zCCAnkwggHioAMCAQICEDURpVKQb+fQKaRAGdQR | ||
29 | /D4wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlT | ||
30 | aWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmltYXJ5IENlcnRp | ||
31 | ZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDYyNzAwMDAwMFoXDTk3MDYyNzIzNTk1 | ||
32 | OVowYjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMu | ||
33 | MTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJz | ||
34 | Y3JpYmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2FKbPTdAFDdjKI9Bv | ||
35 | qrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7jW80GqLd5HUQq7XPy | ||
36 | sVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cariQPJUObwW7s987Lrb | ||
37 | P2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABozMwMTAPBgNVHRMECDAGAQH/AgEBMAsG | ||
38 | A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADgYEA | ||
39 | KeXHoBmnbxRCgk0jM9e9mDppdxpsipIna/J8DOHEUuD4nONAr4+xOg73SBl026n7 | ||
40 | Bk55A2wvAMGo7+kKTZ+rHaFDDcmq4O+rzFri2RIOeGAncj1IcGptAQhvXoIhFMG4 | ||
41 | Jlzg1KlHZHqy7D3jex78zcSU7kKOu8f5tAX1jC3+sToAAKGAMIIBJzCBkTANBgkq | ||
42 | hkiG9w0BAQIFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNp | ||
43 | Z24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlk | ||
44 | dWFsIFN1YnNjcmliZXIXDTk2MDcwMTE3MzA0MFoXDTk3MDcwMTAwMDAwMFowDQYJ | ||
45 | KoZIhvcNAQECBQADgYEAGLuQ6PX8A7AiqBEtWzYtl6lZNSDI0bR5YUo+D2Jzkw30 | ||
46 | dxQnJSbKXEc6XYuzAW5HvrzATXu5c19WWPT4cRDwmjH71i9QcDysWwf/wE0qGTiW | ||
47 | I3tQT0I5VGh7jIJD07nlBw3R4Xl8dH9kr85JsWinqDH5YKpIo9o8knY5n7+qjOow | ||
48 | ggEkMIGOMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5W | ||
49 | ZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMSBQdWJsaWMgUHJpbWFyeSBD | ||
50 | ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eRcNOTYwNzE2MjMxMTI5WhcNOTYwODE1MDAw | ||
51 | MDAwWjANBgkqhkiG9w0BAQIFAAOBgQAXsLE4vnsY6sY67QrmWec7iaU2ehzxanEK | ||
52 | /9wKHZNuhlNzk+qGZZw2evxfUe2OaRbYpl8zuZvhK9BHD3ad14OSe9/zx5hOPgP/ | ||
53 | DQXt6R4R8Q/1JheBrolrgbavjvI2wKS8/Psp2prBrkF4T48+AKRmS8Zzh1guxgvP | ||
54 | b+xSu/jH0gAAMYAAAAAAAAAAAA== | ||
diff --git a/src/lib/libssl/test/r160test.c b/src/lib/libssl/test/r160test.c deleted file mode 100644 index a172e393ca..0000000000 --- a/src/lib/libssl/test/r160test.c +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | /* test/r160test.c */ | ||
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 | */ | ||
diff --git a/src/lib/libssl/test/tcrl b/src/lib/libssl/test/tcrl deleted file mode 100644 index 3ffed12a03..0000000000 --- a/src/lib/libssl/test/tcrl +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl crl' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=testcrl.pem | ||
16 | fi | ||
17 | |||
18 | echo testing crl conversions | ||
19 | cp $t fff.p | ||
20 | |||
21 | echo "p -> d" | ||
22 | $cmd -in fff.p -inform p -outform d >f.d | ||
23 | if [ $? != 0 ]; then exit 1; fi | ||
24 | #echo "p -> t" | ||
25 | #$cmd -in fff.p -inform p -outform t >f.t | ||
26 | #if [ $? != 0 ]; then exit 1; fi | ||
27 | echo "p -> p" | ||
28 | $cmd -in fff.p -inform p -outform p >f.p | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | |||
31 | echo "d -> d" | ||
32 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | #echo "t -> d" | ||
35 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
36 | #if [ $? != 0 ]; then exit 1; fi | ||
37 | echo "p -> d" | ||
38 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | |||
41 | #echo "d -> t" | ||
42 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
43 | #if [ $? != 0 ]; then exit 1; fi | ||
44 | #echo "t -> t" | ||
45 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
46 | #if [ $? != 0 ]; then exit 1; fi | ||
47 | #echo "p -> t" | ||
48 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
49 | #if [ $? != 0 ]; then exit 1; fi | ||
50 | |||
51 | echo "d -> p" | ||
52 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
53 | if [ $? != 0 ]; then exit 1; fi | ||
54 | #echo "t -> p" | ||
55 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
56 | #if [ $? != 0 ]; then exit 1; fi | ||
57 | echo "p -> p" | ||
58 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
59 | if [ $? != 0 ]; then exit 1; fi | ||
60 | |||
61 | cmp fff.p f.p | ||
62 | if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p1 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | #cmp fff.p ff.p2 | ||
66 | #if [ $? != 0 ]; then exit 1; fi | ||
67 | cmp fff.p ff.p3 | ||
68 | if [ $? != 0 ]; then exit 1; fi | ||
69 | |||
70 | #cmp f.t ff.t1 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | #cmp f.t ff.t2 | ||
73 | #if [ $? != 0 ]; then exit 1; fi | ||
74 | #cmp f.t ff.t3 | ||
75 | #if [ $? != 0 ]; then exit 1; fi | ||
76 | |||
77 | cmp f.p ff.p1 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | #cmp f.p ff.p2 | ||
80 | #if [ $? != 0 ]; then exit 1; fi | ||
81 | cmp f.p ff.p3 | ||
82 | if [ $? != 0 ]; then exit 1; fi | ||
83 | |||
84 | /bin/rm -f f.* ff.* fff.* | ||
85 | exit 0 | ||
diff --git a/src/lib/libssl/test/test.cnf b/src/lib/libssl/test/test.cnf deleted file mode 100644 index faad3914a8..0000000000 --- a/src/lib/libssl/test/test.cnf +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | # | ||
2 | # SSLeay example configuration file. | ||
3 | # This is mostly being used for generation of certificate requests. | ||
4 | # | ||
5 | |||
6 | RANDFILE = ./.rnd | ||
7 | |||
8 | #################################################################### | ||
9 | [ ca ] | ||
10 | default_ca = CA_default # The default ca section | ||
11 | |||
12 | #################################################################### | ||
13 | [ CA_default ] | ||
14 | |||
15 | dir = ./demoCA # Where everything is kept | ||
16 | certs = $dir/certs # Where the issued certs are kept | ||
17 | crl_dir = $dir/crl # Where the issued crl are kept | ||
18 | database = $dir/index.txt # database index file. | ||
19 | new_certs_dir = $dir/new_certs # default place for new certs. | ||
20 | |||
21 | certificate = $dir/CAcert.pem # The CA certificate | ||
22 | serial = $dir/serial # The current serial number | ||
23 | crl = $dir/crl.pem # The current CRL | ||
24 | private_key = $dir/private/CAkey.pem# The private key | ||
25 | RANDFILE = $dir/private/.rand # private random number file | ||
26 | |||
27 | default_days = 365 # how long to certify for | ||
28 | default_crl_days= 30 # how long before next CRL | ||
29 | default_md = md5 # which md to use. | ||
30 | |||
31 | # A few difference way of specifying how similar the request should look | ||
32 | # For type CA, the listed attributes must be the same, and the optional | ||
33 | # and supplied fields are just that :-) | ||
34 | policy = policy_match | ||
35 | |||
36 | # For the CA policy | ||
37 | [ policy_match ] | ||
38 | countryName = match | ||
39 | stateOrProvinceName = match | ||
40 | organizationName = match | ||
41 | organizationalUnitName = optional | ||
42 | commonName = supplied | ||
43 | emailAddress = optional | ||
44 | |||
45 | # For the 'anything' policy | ||
46 | # At this point in time, you must list all acceptable 'object' | ||
47 | # types. | ||
48 | [ policy_anything ] | ||
49 | countryName = optional | ||
50 | stateOrProvinceName = optional | ||
51 | localityName = optional | ||
52 | organizationName = optional | ||
53 | organizationalUnitName = optional | ||
54 | commonName = supplied | ||
55 | emailAddress = optional | ||
56 | |||
57 | #################################################################### | ||
58 | [ req ] | ||
59 | default_bits = 512 | ||
60 | default_keyfile = testkey.pem | ||
61 | distinguished_name = req_distinguished_name | ||
62 | encrypt_rsa_key = no | ||
63 | |||
64 | [ req_distinguished_name ] | ||
65 | countryName = Country Name (2 letter code) | ||
66 | countryName_default = AU | ||
67 | countryName_value = AU | ||
68 | |||
69 | stateOrProvinceName = State or Province Name (full name) | ||
70 | stateOrProvinceName_default = Queensland | ||
71 | stateOrProvinceName_value = | ||
72 | |||
73 | localityName = Locality Name (eg, city) | ||
74 | localityName_value = Brisbane | ||
75 | |||
76 | organizationName = Organization Name (eg, company) | ||
77 | organizationName_default = | ||
78 | organizationName_value = CryptSoft Pty Ltd | ||
79 | |||
80 | organizationalUnitName = Organizational Unit Name (eg, section) | ||
81 | organizationalUnitName_default = | ||
82 | organizationalUnitName_value = . | ||
83 | |||
84 | commonName = Common Name (eg, YOUR name) | ||
85 | commonName_value = Eric Young | ||
86 | |||
87 | emailAddress = Email Address | ||
88 | emailAddress_value = eay@mincom.oz.au | ||
diff --git a/src/lib/libssl/test/testca b/src/lib/libssl/test/testca deleted file mode 100644 index 5b2faa78f1..0000000000 --- a/src/lib/libssl/test/testca +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | SH="/bin/sh" | ||
4 | if test "$OSTYPE" = msdosdjgpp; then | ||
5 | PATH=./apps\;../apps\;$PATH | ||
6 | else | ||
7 | PATH=../apps:$PATH | ||
8 | fi | ||
9 | export SH PATH | ||
10 | |||
11 | SSLEAY_CONFIG="-config CAss.cnf" | ||
12 | export SSLEAY_CONFIG | ||
13 | |||
14 | OPENSSL="`pwd`/../util/shlib_wrap.sh openssl" | ||
15 | export OPENSSL | ||
16 | |||
17 | /bin/rm -fr demoCA | ||
18 | $SH ../apps/CA.sh -newca <<EOF | ||
19 | EOF | ||
20 | |||
21 | if [ $? != 0 ]; then | ||
22 | exit 1; | ||
23 | fi | ||
24 | |||
25 | SSLEAY_CONFIG="-config Uss.cnf" | ||
26 | export SSLEAY_CONFIG | ||
27 | $SH ../apps/CA.sh -newreq | ||
28 | if [ $? != 0 ]; then | ||
29 | exit 1; | ||
30 | fi | ||
31 | |||
32 | |||
33 | SSLEAY_CONFIG="-config ../apps/openssl.cnf" | ||
34 | export SSLEAY_CONFIG | ||
35 | $SH ../apps/CA.sh -sign <<EOF | ||
36 | y | ||
37 | y | ||
38 | EOF | ||
39 | if [ $? != 0 ]; then | ||
40 | exit 1; | ||
41 | fi | ||
42 | |||
43 | |||
44 | $SH ../apps/CA.sh -verify newcert.pem | ||
45 | if [ $? != 0 ]; then | ||
46 | exit 1; | ||
47 | fi | ||
48 | |||
49 | /bin/rm -fr demoCA newcert.pem newreq.pem | ||
50 | #usage: CA -newcert|-newreq|-newca|-sign|-verify | ||
51 | |||
diff --git a/src/lib/libssl/test/testcrl.pem b/src/lib/libssl/test/testcrl.pem deleted file mode 100644 index 0989788354..0000000000 --- a/src/lib/libssl/test/testcrl.pem +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | -----BEGIN X509 CRL----- | ||
2 | MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT | ||
3 | F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy | ||
4 | IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw | ||
5 | MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw | ||
6 | MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw | ||
7 | MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw | ||
8 | MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw | ||
9 | MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw | ||
10 | MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw | ||
11 | NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw | ||
12 | NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF | ||
13 | AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ | ||
14 | wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt | ||
15 | JaAL3iTJHJD55kK2D/VoyY1djlsPuNh6AEgdVwFAyp0v | ||
16 | -----END X509 CRL----- | ||
diff --git a/src/lib/libssl/test/testenc b/src/lib/libssl/test/testenc deleted file mode 100644 index 4571ea2875..0000000000 --- a/src/lib/libssl/test/testenc +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | testsrc=Makefile | ||
4 | test=./p | ||
5 | cmd="../util/shlib_wrap.sh ../apps/openssl" | ||
6 | |||
7 | cat $testsrc >$test; | ||
8 | |||
9 | echo cat | ||
10 | $cmd enc -non-fips-allow < $test > $test.cipher | ||
11 | $cmd enc -non-fips-allow < $test.cipher >$test.clear | ||
12 | cmp $test $test.clear | ||
13 | if [ $? != 0 ] | ||
14 | then | ||
15 | exit 1 | ||
16 | else | ||
17 | /bin/rm $test.cipher $test.clear | ||
18 | fi | ||
19 | echo base64 | ||
20 | $cmd enc -non-fips-allow -a -e < $test > $test.cipher | ||
21 | $cmd enc -non-fips-allow -a -d < $test.cipher >$test.clear | ||
22 | cmp $test $test.clear | ||
23 | if [ $? != 0 ] | ||
24 | then | ||
25 | exit 1 | ||
26 | else | ||
27 | /bin/rm $test.cipher $test.clear | ||
28 | fi | ||
29 | |||
30 | for i in `$cmd list-cipher-commands` | ||
31 | do | ||
32 | echo $i | ||
33 | $cmd $i -non-fips-allow -bufsize 113 -e -k test < $test > $test.$i.cipher | ||
34 | $cmd $i -non-fips-allow -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear | ||
35 | cmp $test $test.$i.clear | ||
36 | if [ $? != 0 ] | ||
37 | then | ||
38 | exit 1 | ||
39 | else | ||
40 | /bin/rm $test.$i.cipher $test.$i.clear | ||
41 | fi | ||
42 | |||
43 | echo $i base64 | ||
44 | $cmd $i -non-fips-allow -bufsize 113 -a -e -k test < $test > $test.$i.cipher | ||
45 | $cmd $i -non-fips-allow -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear | ||
46 | cmp $test $test.$i.clear | ||
47 | if [ $? != 0 ] | ||
48 | then | ||
49 | exit 1 | ||
50 | else | ||
51 | /bin/rm $test.$i.cipher $test.$i.clear | ||
52 | fi | ||
53 | done | ||
54 | rm -f $test | ||
diff --git a/src/lib/libssl/test/testgen b/src/lib/libssl/test/testgen deleted file mode 100644 index 524c0d134c..0000000000 --- a/src/lib/libssl/test/testgen +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | T=testcert | ||
4 | KEY=512 | ||
5 | CA=../certs/testca.pem | ||
6 | |||
7 | /bin/rm -f $T.1 $T.2 $T.key | ||
8 | |||
9 | if test "$OSTYPE" = msdosdjgpp; then | ||
10 | PATH=../apps\;$PATH; | ||
11 | else | ||
12 | PATH=../apps:$PATH; | ||
13 | fi | ||
14 | export PATH | ||
15 | |||
16 | echo "generating certificate request" | ||
17 | |||
18 | echo "string to make the random number generator think it has entropy" >> ./.rnd | ||
19 | |||
20 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then | ||
21 | req_new='-newkey dsa:../apps/dsa512.pem' | ||
22 | else | ||
23 | req_new='-new' | ||
24 | echo "There should be a 2 sequences of .'s and some +'s." | ||
25 | echo "There should not be more that at most 80 per line" | ||
26 | fi | ||
27 | |||
28 | echo "This could take some time." | ||
29 | |||
30 | rm -f testkey.pem testreq.pem | ||
31 | |||
32 | ../util/shlib_wrap.sh ../apps/openssl req -config test.cnf $req_new -out testreq.pem | ||
33 | if [ $? != 0 ]; then | ||
34 | echo problems creating request | ||
35 | exit 1 | ||
36 | fi | ||
37 | |||
38 | ../util/shlib_wrap.sh ../apps/openssl req -config test.cnf -verify -in testreq.pem -noout | ||
39 | if [ $? != 0 ]; then | ||
40 | echo signature on req is wrong | ||
41 | exit 1 | ||
42 | fi | ||
43 | |||
44 | exit 0 | ||
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem deleted file mode 100644 index e5b7866c31..0000000000 --- a/src/lib/libssl/test/testp7.pem +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | -----BEGIN PKCS7----- | ||
2 | MIIIGAYJKoZIhvcNAQcCoIIICTCCCAUCAQExADALBgkqhkiG9w0BBwGgggY8MIIE | ||
3 | cjCCBBygAwIBAgIQeS+OJfWJUZAx6cX0eAiMjzANBgkqhkiG9w0BAQQFADBiMREw | ||
4 | DwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNV | ||
5 | BAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIw | ||
6 | HhcNOTYwNzE5MDAwMDAwWhcNOTcwMzMwMjM1OTU5WjCB1TERMA8GA1UEBxMISW50 | ||
7 | ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln | ||
8 | biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMSgwJgYDVQQLEx9E | ||
9 | aWdpdGFsIElEIENsYXNzIDEgLSBTTUlNRSBUZXN0MUcwRQYDVQQLEz53d3cudmVy | ||
10 | aXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMCBJbmMuIGJ5IFJlZi4sTElBQi5M | ||
11 | VEQoYyk5NjBbMA0GCSqGSIb3DQEBAQUAA0oAMEcCQA7LvHEIAiQ5+4gDYvJGnGAq | ||
12 | UM5GXyG11diEXmIEZTHUZhorooX5sr8IIjSXiPY59YYUFSvAaharFM1xaBN8zNEC | ||
13 | AwEAAaOCAjkwggI1MAkGA1UdEwQCMAAwggImBgNVHQMEggIdMIICGTCCAhUwggIR | ||
14 | BgtghkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0 | ||
15 | ZXMgYnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0 | ||
16 | IHRvLCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1l | ||
17 | bnQgKENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t | ||
18 | L0NQUy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29t | ||
19 | OyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4s | ||
20 | IE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04 | ||
21 | ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0 | ||
22 | cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJ | ||
23 | QUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQEC | ||
24 | MC8wLRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEu | ||
25 | AzANBgkqhkiG9w0BAQQFAANBAMCYDuSb/eIlYSxY31nZZTaCZkCSfHjlacMofExr | ||
26 | cF+A2yHoEuT+eCQkqM0pMNHXddUeoQ9RjV+VuMBNmm63DUYwggHCMIIBbKADAgEC | ||
27 | AhB8CYTq1bkRFJBYOd67cp9JMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT | ||
28 | MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD | ||
29 | QTAeFw05NjA3MTcwMDAwMDBaFw05NzA3MTcyMzU5NTlaMGIxETAPBgNVBAcTCElu | ||
30 | dGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNp | ||
31 | Z24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjBcMA0GCSqGSIb3 | ||
32 | DQEBAQUAA0sAMEgCQQDsVzrNgnDhbAJZrWeLd9g1vMZJA2W67D33TTbga6yMt+ES | ||
33 | TWEywhS6RNP+fzLGg7utinjH4tL60cXa0G27GDsLAgMBAAGjIjAgMAsGA1UdDwQE | ||
34 | AwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADQQAUp6bRwkaD | ||
35 | 2d1MBs/mjUcgTI2fXVmW8tTm/Ud6OzUwpC3vYgybiOOA4f6mOC5dbyUHrLOsrihU | ||
36 | 47ZQ0Jo1DUfboYIBrTCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT | ||
37 | MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD | ||
38 | QRcNOTYwNzE3MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANB | ||
39 | AHitA0/xAukCjHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMl | ||
40 | ExONA3ju10f7owIq3s3wx10wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UE | ||
41 | BxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytW | ||
42 | ZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3 | ||
43 | MTcxNzU5MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsW | ||
44 | sQmste9f+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9 | ||
45 | XfZsaiiIgotQHjEA | ||
46 | -----END PKCS7----- | ||
diff --git a/src/lib/libssl/test/testreq2.pem b/src/lib/libssl/test/testreq2.pem deleted file mode 100644 index c3cdcffcbc..0000000000 --- a/src/lib/libssl/test/testreq2.pem +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | -----BEGIN CERTIFICATE REQUEST----- | ||
2 | MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC | ||
3 | QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG | ||
4 | DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq | ||
5 | hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi | ||
6 | gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U= | ||
7 | -----END CERTIFICATE REQUEST----- | ||
diff --git a/src/lib/libssl/test/testrsa.pem b/src/lib/libssl/test/testrsa.pem deleted file mode 100644 index aad21067a8..0000000000 --- a/src/lib/libssl/test/testrsa.pem +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | -----BEGIN RSA PRIVATE KEY----- | ||
2 | MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I | ||
3 | Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R | ||
4 | rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy | ||
5 | oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S | ||
6 | mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz | ||
7 | rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA | ||
8 | mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM= | ||
9 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/lib/libssl/test/testsid.pem b/src/lib/libssl/test/testsid.pem deleted file mode 100644 index 7ffd008f66..0000000000 --- a/src/lib/libssl/test/testsid.pem +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | -----BEGIN SSL SESSION PARAMETERS----- | ||
2 | MIIB1gIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV | ||
3 | bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw | ||
4 | ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz | ||
5 | YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG | ||
6 | A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk | ||
7 | LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G | ||
8 | CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD | ||
9 | TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI | ||
10 | hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L | ||
11 | CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTvpA0EC3Rlc3Rjb250ZXh0 | ||
12 | -----END SSL SESSION PARAMETERS----- | ||
diff --git a/src/lib/libssl/test/testss b/src/lib/libssl/test/testss deleted file mode 100644 index 1a426857d3..0000000000 --- a/src/lib/libssl/test/testss +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | digest='-sha1' | ||
4 | reqcmd="../util/shlib_wrap.sh ../apps/openssl req" | ||
5 | x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest" | ||
6 | verifycmd="../util/shlib_wrap.sh ../apps/openssl verify" | ||
7 | dummycnf="../apps/openssl.cnf" | ||
8 | |||
9 | CAkey="keyCA.ss" | ||
10 | CAcert="certCA.ss" | ||
11 | CAreq="reqCA.ss" | ||
12 | CAconf="CAss.cnf" | ||
13 | CAreq2="req2CA.ss" # temp | ||
14 | |||
15 | Uconf="Uss.cnf" | ||
16 | Ukey="keyU.ss" | ||
17 | Ureq="reqU.ss" | ||
18 | Ucert="certU.ss" | ||
19 | |||
20 | P1conf="P1ss.cnf" | ||
21 | P1key="keyP1.ss" | ||
22 | P1req="reqP1.ss" | ||
23 | P1cert="certP1.ss" | ||
24 | P1intermediate="tmp_intP1.ss" | ||
25 | |||
26 | P2conf="P2ss.cnf" | ||
27 | P2key="keyP2.ss" | ||
28 | P2req="reqP2.ss" | ||
29 | P2cert="certP2.ss" | ||
30 | P2intermediate="tmp_intP2.ss" | ||
31 | |||
32 | echo | ||
33 | echo "make a certificate request using 'req'" | ||
34 | |||
35 | echo "string to make the random number generator think it has entropy" >> ./.rnd | ||
36 | |||
37 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then | ||
38 | req_new='-newkey dsa:../apps/dsa512.pem' | ||
39 | else | ||
40 | req_new='-new' | ||
41 | fi | ||
42 | |||
43 | $reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss | ||
44 | if [ $? != 0 ]; then | ||
45 | echo "error using 'req' to generate a certificate request" | ||
46 | exit 1 | ||
47 | fi | ||
48 | echo | ||
49 | echo "convert the certificate request into a self signed certificate using 'x509'" | ||
50 | $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss | ||
51 | if [ $? != 0 ]; then | ||
52 | echo "error using 'x509' to self sign a certificate request" | ||
53 | exit 1 | ||
54 | fi | ||
55 | |||
56 | echo | ||
57 | echo "convert a certificate into a certificate request using 'x509'" | ||
58 | $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss | ||
59 | if [ $? != 0 ]; then | ||
60 | echo "error using 'x509' convert a certificate to a certificate request" | ||
61 | exit 1 | ||
62 | fi | ||
63 | |||
64 | $reqcmd -config $dummycnf -verify -in $CAreq -noout | ||
65 | if [ $? != 0 ]; then | ||
66 | echo first generated request is invalid | ||
67 | exit 1 | ||
68 | fi | ||
69 | |||
70 | $reqcmd -config $dummycnf -verify -in $CAreq2 -noout | ||
71 | if [ $? != 0 ]; then | ||
72 | echo second generated request is invalid | ||
73 | exit 1 | ||
74 | fi | ||
75 | |||
76 | $verifycmd -CAfile $CAcert $CAcert | ||
77 | if [ $? != 0 ]; then | ||
78 | echo first generated cert is invalid | ||
79 | exit 1 | ||
80 | fi | ||
81 | |||
82 | echo | ||
83 | echo "make a user certificate request using 'req'" | ||
84 | $reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss | ||
85 | if [ $? != 0 ]; then | ||
86 | echo "error using 'req' to generate a user certificate request" | ||
87 | exit 1 | ||
88 | fi | ||
89 | |||
90 | echo | ||
91 | echo "sign user certificate request with the just created CA via 'x509'" | ||
92 | $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss | ||
93 | if [ $? != 0 ]; then | ||
94 | echo "error using 'x509' to sign a user certificate request" | ||
95 | exit 1 | ||
96 | fi | ||
97 | |||
98 | $verifycmd -CAfile $CAcert $Ucert | ||
99 | echo | ||
100 | echo "Certificate details" | ||
101 | $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert | ||
102 | |||
103 | echo | ||
104 | echo "make a proxy certificate request using 'req'" | ||
105 | $reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss | ||
106 | if [ $? != 0 ]; then | ||
107 | echo "error using 'req' to generate a proxy certificate request" | ||
108 | exit 1 | ||
109 | fi | ||
110 | |||
111 | echo | ||
112 | echo "sign proxy certificate request with the just created user certificate via 'x509'" | ||
113 | $x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss | ||
114 | if [ $? != 0 ]; then | ||
115 | echo "error using 'x509' to sign a proxy certificate request" | ||
116 | exit 1 | ||
117 | fi | ||
118 | |||
119 | cat $Ucert > $P1intermediate | ||
120 | $verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert | ||
121 | echo | ||
122 | echo "Certificate details" | ||
123 | $x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert | ||
124 | |||
125 | echo | ||
126 | echo "make another proxy certificate request using 'req'" | ||
127 | $reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss | ||
128 | if [ $? != 0 ]; then | ||
129 | echo "error using 'req' to generate another proxy certificate request" | ||
130 | exit 1 | ||
131 | fi | ||
132 | |||
133 | echo | ||
134 | echo "sign second proxy certificate request with the first proxy certificate via 'x509'" | ||
135 | $x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss | ||
136 | if [ $? != 0 ]; then | ||
137 | echo "error using 'x509' to sign a second proxy certificate request" | ||
138 | exit 1 | ||
139 | fi | ||
140 | |||
141 | cat $Ucert $P1cert > $P2intermediate | ||
142 | $verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert | ||
143 | echo | ||
144 | echo "Certificate details" | ||
145 | $x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert | ||
146 | |||
147 | echo | ||
148 | echo The generated CA certificate is $CAcert | ||
149 | echo The generated CA private key is $CAkey | ||
150 | |||
151 | echo The generated user certificate is $Ucert | ||
152 | echo The generated user private key is $Ukey | ||
153 | |||
154 | echo The first generated proxy certificate is $P1cert | ||
155 | echo The first generated proxy private key is $P1key | ||
156 | |||
157 | echo The second generated proxy certificate is $P2cert | ||
158 | echo The second generated proxy private key is $P2key | ||
159 | |||
160 | /bin/rm err.ss | ||
161 | #/bin/rm $P1intermediate | ||
162 | #/bin/rm $P2intermediate | ||
163 | exit 0 | ||
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl deleted file mode 100644 index 8ac90ae5ee..0000000000 --- a/src/lib/libssl/test/testssl +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if [ "$1" = "" ]; then | ||
4 | key=../apps/server.pem | ||
5 | else | ||
6 | key="$1" | ||
7 | fi | ||
8 | if [ "$2" = "" ]; then | ||
9 | cert=../apps/server.pem | ||
10 | else | ||
11 | cert="$2" | ||
12 | fi | ||
13 | ssltest="../util/shlib_wrap.sh ./ssltest -key $key -cert $cert -c_key $key -c_cert $cert" | ||
14 | |||
15 | if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then | ||
16 | dsa_cert=YES | ||
17 | else | ||
18 | dsa_cert=NO | ||
19 | fi | ||
20 | |||
21 | if [ "$3" = "" ]; then | ||
22 | CA="-CApath ../certs" | ||
23 | else | ||
24 | CA="-CAfile $3" | ||
25 | fi | ||
26 | |||
27 | if [ "$4" = "" ]; then | ||
28 | extra="" | ||
29 | else | ||
30 | extra="$4" | ||
31 | fi | ||
32 | |||
33 | ############################################################################# | ||
34 | |||
35 | echo test sslv2 | ||
36 | $ssltest -ssl2 $extra || exit 1 | ||
37 | |||
38 | echo test sslv2 with server authentication | ||
39 | $ssltest -ssl2 -server_auth $CA $extra || exit 1 | ||
40 | |||
41 | if [ $dsa_cert = NO ]; then | ||
42 | echo test sslv2 with client authentication | ||
43 | $ssltest -ssl2 -client_auth $CA $extra || exit 1 | ||
44 | |||
45 | echo test sslv2 with both client and server authentication | ||
46 | $ssltest -ssl2 -server_auth -client_auth $CA $extra || exit 1 | ||
47 | fi | ||
48 | |||
49 | echo test sslv3 | ||
50 | $ssltest -ssl3 $extra || exit 1 | ||
51 | |||
52 | echo test sslv3 with server authentication | ||
53 | $ssltest -ssl3 -server_auth $CA $extra || exit 1 | ||
54 | |||
55 | echo test sslv3 with client authentication | ||
56 | $ssltest -ssl3 -client_auth $CA $extra || exit 1 | ||
57 | |||
58 | echo test sslv3 with both client and server authentication | ||
59 | $ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1 | ||
60 | |||
61 | echo test sslv2/sslv3 | ||
62 | $ssltest $extra || exit 1 | ||
63 | |||
64 | echo test sslv2/sslv3 with server authentication | ||
65 | $ssltest -server_auth $CA $extra || exit 1 | ||
66 | |||
67 | echo test sslv2/sslv3 with client authentication | ||
68 | $ssltest -client_auth $CA $extra || exit 1 | ||
69 | |||
70 | echo test sslv2/sslv3 with both client and server authentication | ||
71 | $ssltest -server_auth -client_auth $CA $extra || exit 1 | ||
72 | |||
73 | echo test sslv2 via BIO pair | ||
74 | $ssltest -bio_pair -ssl2 $extra || exit 1 | ||
75 | |||
76 | echo test sslv2 with server authentication via BIO pair | ||
77 | $ssltest -bio_pair -ssl2 -server_auth $CA $extra || exit 1 | ||
78 | |||
79 | if [ $dsa_cert = NO ]; then | ||
80 | echo test sslv2 with client authentication via BIO pair | ||
81 | $ssltest -bio_pair -ssl2 -client_auth $CA $extra || exit 1 | ||
82 | |||
83 | echo test sslv2 with both client and server authentication via BIO pair | ||
84 | $ssltest -bio_pair -ssl2 -server_auth -client_auth $CA $extra || exit 1 | ||
85 | fi | ||
86 | |||
87 | echo test sslv3 via BIO pair | ||
88 | $ssltest -bio_pair -ssl3 $extra || exit 1 | ||
89 | |||
90 | echo test sslv3 with server authentication via BIO pair | ||
91 | $ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1 | ||
92 | |||
93 | echo test sslv3 with client authentication via BIO pair | ||
94 | $ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1 | ||
95 | |||
96 | echo test sslv3 with both client and server authentication via BIO pair | ||
97 | $ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1 | ||
98 | |||
99 | echo test sslv2/sslv3 via BIO pair | ||
100 | $ssltest $extra || exit 1 | ||
101 | |||
102 | if [ $dsa_cert = NO ]; then | ||
103 | echo test sslv2/sslv3 w/o DHE via BIO pair | ||
104 | $ssltest -bio_pair -no_dhe $extra || exit 1 | ||
105 | fi | ||
106 | |||
107 | echo test sslv2/sslv3 with 1024bit DHE via BIO pair | ||
108 | $ssltest -bio_pair -dhe1024dsa -v $extra || exit 1 | ||
109 | |||
110 | echo test sslv2/sslv3 with server authentication | ||
111 | $ssltest -bio_pair -server_auth $CA $extra || exit 1 | ||
112 | |||
113 | echo test sslv2/sslv3 with client authentication via BIO pair | ||
114 | $ssltest -bio_pair -client_auth $CA $extra || exit 1 | ||
115 | |||
116 | echo test sslv2/sslv3 with both client and server authentication via BIO pair | ||
117 | $ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1 | ||
118 | |||
119 | echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify | ||
120 | $ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1 | ||
121 | |||
122 | ############################################################################# | ||
123 | |||
124 | if ../util/shlib_wrap.sh ../apps/openssl no-dh; then | ||
125 | echo skipping anonymous DH tests | ||
126 | else | ||
127 | echo test tls1 with 1024bit anonymous DH, multiple handshakes | ||
128 | $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
129 | fi | ||
130 | |||
131 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then | ||
132 | echo skipping RSA tests | ||
133 | else | ||
134 | echo test tls1 with 1024bit RSA, no DHE, multiple handshakes | ||
135 | ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -num 10 -f -time $extra || exit 1 | ||
136 | |||
137 | if ../util/shlib_wrap.sh ../apps/openssl no-dh; then | ||
138 | echo skipping RSA+DHE tests | ||
139 | else | ||
140 | echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes | ||
141 | ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
142 | fi | ||
143 | fi | ||
144 | |||
145 | exit 0 | ||
diff --git a/src/lib/libssl/test/testsslproxy b/src/lib/libssl/test/testsslproxy deleted file mode 100644 index 58bbda8ab7..0000000000 --- a/src/lib/libssl/test/testsslproxy +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | #! /bin/sh | ||
2 | |||
3 | echo 'Testing a lot of proxy conditions.' | ||
4 | echo 'Some of them may turn out being invalid, which is fine.' | ||
5 | for auth in A B C BC; do | ||
6 | for cond in A B C 'A|B&!C'; do | ||
7 | sh ./testssl $1 $2 $3 "-proxy -proxy_auth $auth -proxy_cond $cond" | ||
8 | if [ $? = 3 ]; then exit 1; fi | ||
9 | done | ||
10 | done | ||
diff --git a/src/lib/libssl/test/testx509.pem b/src/lib/libssl/test/testx509.pem deleted file mode 100644 index 8a85d14964..0000000000 --- a/src/lib/libssl/test/testx509.pem +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV | ||
3 | BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz | ||
4 | MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM | ||
5 | RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF | ||
6 | AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO | ||
7 | /Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE | ||
8 | Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ | ||
9 | zl9HYIMxATFyqSiD9jsx | ||
10 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/times b/src/lib/libssl/test/times deleted file mode 100644 index 738d569b8f..0000000000 --- a/src/lib/libssl/test/times +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | |||
2 | More number for the questions about SSL overheads.... | ||
3 | |||
4 | The following numbers were generated on a pentium pro 200, running linux. | ||
5 | They give an indication of the SSL protocol and encryption overheads. | ||
6 | |||
7 | The program that generated them is an unreleased version of ssl/ssltest.c | ||
8 | which is the SSLeay ssl protocol testing program. It is a single process that | ||
9 | talks both sides of the SSL protocol via a non-blocking memory buffer | ||
10 | interface. | ||
11 | |||
12 | How do I read this? The protocol and cipher are reasonable obvious. | ||
13 | The next number is the number of connections being made. The next is the | ||
14 | number of bytes exchanged bewteen the client and server side of the protocol. | ||
15 | This is the number of bytes that the client sends to the server, and then | ||
16 | the server sends back. Because this is all happening in one process, | ||
17 | the data is being encrypted, decrypted, encrypted and then decrypted again. | ||
18 | It is a round trip of that many bytes. Because the one process performs | ||
19 | both the client and server sides of the protocol and it sends this many bytes | ||
20 | each direction, multiply this number by 4 to generate the number | ||
21 | of bytes encrypted/decrypted/MACed. The first time value is how many seconds | ||
22 | elapsed doing a full SSL handshake, the second is the cost of one | ||
23 | full handshake and the rest being session-id reuse. | ||
24 | |||
25 | SSLv2 RC4-MD5 1000 x 1 12.83s 0.70s | ||
26 | SSLv3 NULL-MD5 1000 x 1 14.35s 1.47s | ||
27 | SSLv3 RC4-MD5 1000 x 1 14.46s 1.56s | ||
28 | SSLv3 RC4-MD5 1000 x 1 51.93s 1.62s 1024bit RSA | ||
29 | SSLv3 RC4-SHA 1000 x 1 14.61s 1.83s | ||
30 | SSLv3 DES-CBC-SHA 1000 x 1 14.70s 1.89s | ||
31 | SSLv3 DES-CBC3-SHA 1000 x 1 15.16s 2.16s | ||
32 | |||
33 | SSLv2 RC4-MD5 1000 x 1024 13.72s 1.27s | ||
34 | SSLv3 NULL-MD5 1000 x 1024 14.79s 1.92s | ||
35 | SSLv3 RC4-MD5 1000 x 1024 52.58s 2.29s 1024bit RSA | ||
36 | SSLv3 RC4-SHA 1000 x 1024 15.39s 2.67s | ||
37 | SSLv3 DES-CBC-SHA 1000 x 1024 16.45s 3.55s | ||
38 | SSLv3 DES-CBC3-SHA 1000 x 1024 18.21s 5.38s | ||
39 | |||
40 | SSLv2 RC4-MD5 1000 x 10240 18.97s 6.52s | ||
41 | SSLv3 NULL-MD5 1000 x 10240 17.79s 5.11s | ||
42 | SSLv3 RC4-MD5 1000 x 10240 20.25s 7.90s | ||
43 | SSLv3 RC4-MD5 1000 x 10240 58.26s 8.08s 1024bit RSA | ||
44 | SSLv3 RC4-SHA 1000 x 10240 22.96s 11.44s | ||
45 | SSLv3 DES-CBC-SHA 1000 x 10240 30.65s 18.41s | ||
46 | SSLv3 DES-CBC3-SHA 1000 x 10240 47.04s 34.53s | ||
47 | |||
48 | SSLv2 RC4-MD5 1000 x 102400 70.22s 57.74s | ||
49 | SSLv3 NULL-MD5 1000 x 102400 43.73s 31.03s | ||
50 | SSLv3 RC4-MD5 1000 x 102400 71.32s 58.83s | ||
51 | SSLv3 RC4-MD5 1000 x 102400 109.66s 59.20s 1024bit RSA | ||
52 | SSLv3 RC4-SHA 1000 x 102400 95.88s 82.21s | ||
53 | SSLv3 DES-CBC-SHA 1000 x 102400 173.22s 160.55s | ||
54 | SSLv3 DES-CBC3-SHA 1000 x 102400 336.61s 323.82s | ||
55 | |||
56 | What does this all mean? Well for a server, with no session-id reuse, with | ||
57 | a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key, | ||
58 | a pentium pro 200 running linux can handle the SSLv3 protocol overheads of | ||
59 | about 49 connections a second. Reality will be quite different :-). | ||
60 | |||
61 | Remeber the first number is 1000 full ssl handshakes, the second is | ||
62 | 1 full and 999 with session-id reuse. The RSA overheads for each exchange | ||
63 | would be one public and one private operation, but the protocol/MAC/cipher | ||
64 | cost would be quite similar in both the client and server. | ||
65 | |||
66 | eric (adding numbers to speculation) | ||
67 | |||
68 | --- Appendix --- | ||
69 | - The time measured is user time but these number a very rough. | ||
70 | - Remember this is the cost of both client and server sides of the protocol. | ||
71 | - The TCP/kernel overhead of connection establishment is normally the | ||
72 | killer in SSL. Often delays in the TCP protocol will make session-id | ||
73 | reuse look slower that new sessions, but this would not be the case on | ||
74 | a loaded server. | ||
75 | - The TCP round trip latencies, while slowing indervidual connections, | ||
76 | would have minimal impact on throughput. | ||
77 | - Instead of sending one 102400 byte buffer, one 8k buffer is sent until | ||
78 | - the required number of bytes are processed. | ||
79 | - The SSLv3 connections were actually SSLv2 compatable SSLv3 headers. | ||
80 | - A 512bit server key was being used except where noted. | ||
81 | - No server key verification was being performed on the client side of the | ||
82 | protocol. This would slow things down very little. | ||
83 | - The library being used is SSLeay 0.8.x. | ||
84 | - The normal mesauring system was commands of the form | ||
85 | time ./ssltest -num 1000 -bytes 102400 -cipher DES-CBC-SHA -reuse | ||
86 | This modified version of ssltest should be in the next public release of | ||
87 | SSLeay. | ||
88 | |||
89 | The general cipher performace number for this platform are | ||
90 | |||
91 | SSLeay 0.8.2a 04-Sep-1997 | ||
92 | built on Fri Sep 5 17:37:05 EST 1997 | ||
93 | options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2) | ||
94 | C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized | ||
95 | The 'numbers' are in 1000s of bytes per second processed. | ||
96 | type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes | ||
97 | md2 131.02k 368.41k 500.57k 549.21k 566.09k | ||
98 | mdc2 535.60k 589.10k 595.88k 595.97k 594.54k | ||
99 | md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k | ||
100 | sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k | ||
101 | sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k | ||
102 | rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k | ||
103 | des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k | ||
104 | des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k | ||
105 | idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k | ||
106 | rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k | ||
107 | blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k | ||
108 | sign verify | ||
109 | rsa 512 bits 0.0100s 0.0011s | ||
110 | rsa 1024 bits 0.0451s 0.0012s | ||
111 | rsa 2048 bits 0.2605s 0.0086s | ||
112 | rsa 4096 bits 1.6883s 0.0302s | ||
113 | |||
diff --git a/src/lib/libssl/test/tpkcs7 b/src/lib/libssl/test/tpkcs7 deleted file mode 100644 index 79bb6e0edf..0000000000 --- a/src/lib/libssl/test/tpkcs7 +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=testp7.pem | ||
16 | fi | ||
17 | |||
18 | echo testing pkcs7 conversions | ||
19 | cp $t fff.p | ||
20 | |||
21 | echo "p -> d" | ||
22 | $cmd -in fff.p -inform p -outform d >f.d | ||
23 | if [ $? != 0 ]; then exit 1; fi | ||
24 | echo "p -> p" | ||
25 | $cmd -in fff.p -inform p -outform p >f.p | ||
26 | if [ $? != 0 ]; then exit 1; fi | ||
27 | |||
28 | echo "d -> d" | ||
29 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
30 | if [ $? != 0 ]; then exit 1; fi | ||
31 | echo "p -> d" | ||
32 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | |||
35 | echo "d -> p" | ||
36 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
37 | if [ $? != 0 ]; then exit 1; fi | ||
38 | echo "p -> p" | ||
39 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
40 | if [ $? != 0 ]; then exit 1; fi | ||
41 | |||
42 | cmp fff.p f.p | ||
43 | if [ $? != 0 ]; then exit 1; fi | ||
44 | cmp fff.p ff.p1 | ||
45 | if [ $? != 0 ]; then exit 1; fi | ||
46 | cmp fff.p ff.p3 | ||
47 | if [ $? != 0 ]; then exit 1; fi | ||
48 | |||
49 | cmp f.p ff.p1 | ||
50 | if [ $? != 0 ]; then exit 1; fi | ||
51 | cmp f.p ff.p3 | ||
52 | if [ $? != 0 ]; then exit 1; fi | ||
53 | |||
54 | /bin/rm -f f.* ff.* fff.* | ||
55 | exit 0 | ||
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d deleted file mode 100644 index 20394b34c4..0000000000 --- a/src/lib/libssl/test/tpkcs7d +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=pkcs7-1.pem | ||
16 | fi | ||
17 | |||
18 | echo "testing pkcs7 conversions (2)" | ||
19 | cp $t fff.p | ||
20 | |||
21 | echo "p -> d" | ||
22 | $cmd -in fff.p -inform p -outform d >f.d | ||
23 | if [ $? != 0 ]; then exit 1; fi | ||
24 | echo "p -> p" | ||
25 | $cmd -in fff.p -inform p -outform p >f.p | ||
26 | if [ $? != 0 ]; then exit 1; fi | ||
27 | |||
28 | echo "d -> d" | ||
29 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
30 | if [ $? != 0 ]; then exit 1; fi | ||
31 | echo "p -> d" | ||
32 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | |||
35 | echo "d -> p" | ||
36 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
37 | if [ $? != 0 ]; then exit 1; fi | ||
38 | echo "p -> p" | ||
39 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
40 | if [ $? != 0 ]; then exit 1; fi | ||
41 | |||
42 | cmp f.p ff.p1 | ||
43 | if [ $? != 0 ]; then exit 1; fi | ||
44 | cmp f.p ff.p3 | ||
45 | if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | /bin/rm -f f.* ff.* fff.* | ||
48 | exit 0 | ||
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq deleted file mode 100644 index 7e020210a5..0000000000 --- a/src/lib/libssl/test/treq +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=testreq.pem | ||
16 | fi | ||
17 | |||
18 | if $cmd -in $t -inform p -noout -text | fgrep 'Unknown Public Key'; then | ||
19 | echo "skipping req conversion test for $t" | ||
20 | exit 0 | ||
21 | fi | ||
22 | |||
23 | echo testing req conversions | ||
24 | cp $t fff.p | ||
25 | |||
26 | echo "p -> d" | ||
27 | $cmd -in fff.p -inform p -outform d >f.d | ||
28 | if [ $? != 0 ]; then exit 1; fi | ||
29 | #echo "p -> t" | ||
30 | #$cmd -in fff.p -inform p -outform t >f.t | ||
31 | #if [ $? != 0 ]; then exit 1; fi | ||
32 | echo "p -> p" | ||
33 | $cmd -in fff.p -inform p -outform p >f.p | ||
34 | if [ $? != 0 ]; then exit 1; fi | ||
35 | |||
36 | echo "d -> d" | ||
37 | $cmd -verify -in f.d -inform d -outform d >ff.d1 | ||
38 | if [ $? != 0 ]; then exit 1; fi | ||
39 | #echo "t -> d" | ||
40 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
41 | #if [ $? != 0 ]; then exit 1; fi | ||
42 | echo "p -> d" | ||
43 | $cmd -verify -in f.p -inform p -outform d >ff.d3 | ||
44 | if [ $? != 0 ]; then exit 1; fi | ||
45 | |||
46 | #echo "d -> t" | ||
47 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
48 | #if [ $? != 0 ]; then exit 1; fi | ||
49 | #echo "t -> t" | ||
50 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
51 | #if [ $? != 0 ]; then exit 1; fi | ||
52 | #echo "p -> t" | ||
53 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
54 | #if [ $? != 0 ]; then exit 1; fi | ||
55 | |||
56 | echo "d -> p" | ||
57 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | #echo "t -> p" | ||
60 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
61 | #if [ $? != 0 ]; then exit 1; fi | ||
62 | echo "p -> p" | ||
63 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | cmp fff.p f.p | ||
67 | if [ $? != 0 ]; then exit 1; fi | ||
68 | cmp fff.p ff.p1 | ||
69 | if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp fff.p ff.p2 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | cmp fff.p ff.p3 | ||
73 | if [ $? != 0 ]; then exit 1; fi | ||
74 | |||
75 | #cmp f.t ff.t1 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | #cmp f.t ff.t2 | ||
78 | #if [ $? != 0 ]; then exit 1; fi | ||
79 | #cmp f.t ff.t3 | ||
80 | #if [ $? != 0 ]; then exit 1; fi | ||
81 | |||
82 | cmp f.p ff.p1 | ||
83 | if [ $? != 0 ]; then exit 1; fi | ||
84 | #cmp f.p ff.p2 | ||
85 | #if [ $? != 0 ]; then exit 1; fi | ||
86 | cmp f.p ff.p3 | ||
87 | if [ $? != 0 ]; then exit 1; fi | ||
88 | |||
89 | /bin/rm -f f.* ff.* fff.* | ||
90 | exit 0 | ||
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa deleted file mode 100644 index 67b4a98841..0000000000 --- a/src/lib/libssl/test/trsa +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then | ||
11 | echo skipping rsa conversion test | ||
12 | exit 0 | ||
13 | fi | ||
14 | |||
15 | cmd='../util/shlib_wrap.sh ../apps/openssl rsa' | ||
16 | |||
17 | if [ "$1"x != "x" ]; then | ||
18 | t=$1 | ||
19 | else | ||
20 | t=testrsa.pem | ||
21 | fi | ||
22 | |||
23 | echo testing rsa conversions | ||
24 | cp $t fff.p | ||
25 | |||
26 | echo "p -> d" | ||
27 | $cmd -in fff.p -inform p -outform d >f.d | ||
28 | if [ $? != 0 ]; then exit 1; fi | ||
29 | #echo "p -> t" | ||
30 | #$cmd -in fff.p -inform p -outform t >f.t | ||
31 | #if [ $? != 0 ]; then exit 1; fi | ||
32 | echo "p -> p" | ||
33 | $cmd -in fff.p -inform p -outform p >f.p | ||
34 | if [ $? != 0 ]; then exit 1; fi | ||
35 | |||
36 | echo "d -> d" | ||
37 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
38 | if [ $? != 0 ]; then exit 1; fi | ||
39 | #echo "t -> d" | ||
40 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
41 | #if [ $? != 0 ]; then exit 1; fi | ||
42 | echo "p -> d" | ||
43 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
44 | if [ $? != 0 ]; then exit 1; fi | ||
45 | |||
46 | #echo "d -> t" | ||
47 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
48 | #if [ $? != 0 ]; then exit 1; fi | ||
49 | #echo "t -> t" | ||
50 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
51 | #if [ $? != 0 ]; then exit 1; fi | ||
52 | #echo "p -> t" | ||
53 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
54 | #if [ $? != 0 ]; then exit 1; fi | ||
55 | |||
56 | echo "d -> p" | ||
57 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | #echo "t -> p" | ||
60 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
61 | #if [ $? != 0 ]; then exit 1; fi | ||
62 | echo "p -> p" | ||
63 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | cmp fff.p f.p | ||
67 | if [ $? != 0 ]; then exit 1; fi | ||
68 | cmp fff.p ff.p1 | ||
69 | if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp fff.p ff.p2 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | cmp fff.p ff.p3 | ||
73 | if [ $? != 0 ]; then exit 1; fi | ||
74 | |||
75 | #cmp f.t ff.t1 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | #cmp f.t ff.t2 | ||
78 | #if [ $? != 0 ]; then exit 1; fi | ||
79 | #cmp f.t ff.t3 | ||
80 | #if [ $? != 0 ]; then exit 1; fi | ||
81 | |||
82 | cmp f.p ff.p1 | ||
83 | if [ $? != 0 ]; then exit 1; fi | ||
84 | #cmp f.p ff.p2 | ||
85 | #if [ $? != 0 ]; then exit 1; fi | ||
86 | cmp f.p ff.p3 | ||
87 | if [ $? != 0 ]; then exit 1; fi | ||
88 | |||
89 | /bin/rm -f f.* ff.* fff.* | ||
90 | exit 0 | ||
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid deleted file mode 100644 index fb4a7213b9..0000000000 --- a/src/lib/libssl/test/tsid +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl sess_id' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=testsid.pem | ||
16 | fi | ||
17 | |||
18 | echo testing session-id conversions | ||
19 | cp $t fff.p | ||
20 | |||
21 | echo "p -> d" | ||
22 | $cmd -in fff.p -inform p -outform d >f.d | ||
23 | if [ $? != 0 ]; then exit 1; fi | ||
24 | #echo "p -> t" | ||
25 | #$cmd -in fff.p -inform p -outform t >f.t | ||
26 | #if [ $? != 0 ]; then exit 1; fi | ||
27 | echo "p -> p" | ||
28 | $cmd -in fff.p -inform p -outform p >f.p | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | |||
31 | echo "d -> d" | ||
32 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | #echo "t -> d" | ||
35 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
36 | #if [ $? != 0 ]; then exit 1; fi | ||
37 | echo "p -> d" | ||
38 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | |||
41 | #echo "d -> t" | ||
42 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
43 | #if [ $? != 0 ]; then exit 1; fi | ||
44 | #echo "t -> t" | ||
45 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
46 | #if [ $? != 0 ]; then exit 1; fi | ||
47 | #echo "p -> t" | ||
48 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
49 | #if [ $? != 0 ]; then exit 1; fi | ||
50 | |||
51 | echo "d -> p" | ||
52 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
53 | if [ $? != 0 ]; then exit 1; fi | ||
54 | #echo "t -> p" | ||
55 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
56 | #if [ $? != 0 ]; then exit 1; fi | ||
57 | echo "p -> p" | ||
58 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
59 | if [ $? != 0 ]; then exit 1; fi | ||
60 | |||
61 | cmp fff.p f.p | ||
62 | if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p1 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | #cmp fff.p ff.p2 | ||
66 | #if [ $? != 0 ]; then exit 1; fi | ||
67 | cmp fff.p ff.p3 | ||
68 | if [ $? != 0 ]; then exit 1; fi | ||
69 | |||
70 | #cmp f.t ff.t1 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | #cmp f.t ff.t2 | ||
73 | #if [ $? != 0 ]; then exit 1; fi | ||
74 | #cmp f.t ff.t3 | ||
75 | #if [ $? != 0 ]; then exit 1; fi | ||
76 | |||
77 | cmp f.p ff.p1 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | #cmp f.p ff.p2 | ||
80 | #if [ $? != 0 ]; then exit 1; fi | ||
81 | cmp f.p ff.p3 | ||
82 | if [ $? != 0 ]; then exit 1; fi | ||
83 | |||
84 | /bin/rm -f f.* ff.* fff.* | ||
85 | exit 0 | ||
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509 deleted file mode 100644 index 1b9c8661f3..0000000000 --- a/src/lib/libssl/test/tx509 +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if test "$OSTYPE" = msdosdjgpp; then | ||
4 | PATH=../apps\;$PATH | ||
5 | else | ||
6 | PATH=../apps:$PATH | ||
7 | fi | ||
8 | export PATH | ||
9 | |||
10 | cmd='../util/shlib_wrap.sh ../apps/openssl x509' | ||
11 | |||
12 | if [ "$1"x != "x" ]; then | ||
13 | t=$1 | ||
14 | else | ||
15 | t=testx509.pem | ||
16 | fi | ||
17 | |||
18 | echo testing X509 conversions | ||
19 | cp $t fff.p | ||
20 | |||
21 | echo "p -> d" | ||
22 | $cmd -in fff.p -inform p -outform d >f.d | ||
23 | if [ $? != 0 ]; then exit 1; fi | ||
24 | echo "p -> n" | ||
25 | $cmd -in fff.p -inform p -outform n >f.n | ||
26 | if [ $? != 0 ]; then exit 1; fi | ||
27 | echo "p -> p" | ||
28 | $cmd -in fff.p -inform p -outform p >f.p | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | |||
31 | echo "d -> d" | ||
32 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | echo "n -> d" | ||
35 | $cmd -in f.n -inform n -outform d >ff.d2 | ||
36 | if [ $? != 0 ]; then exit 1; fi | ||
37 | echo "p -> d" | ||
38 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | |||
41 | echo "d -> n" | ||
42 | $cmd -in f.d -inform d -outform n >ff.n1 | ||
43 | if [ $? != 0 ]; then exit 1; fi | ||
44 | echo "n -> n" | ||
45 | $cmd -in f.n -inform n -outform n >ff.n2 | ||
46 | if [ $? != 0 ]; then exit 1; fi | ||
47 | echo "p -> n" | ||
48 | $cmd -in f.p -inform p -outform n >ff.n3 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | |||
51 | echo "d -> p" | ||
52 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
53 | if [ $? != 0 ]; then exit 1; fi | ||
54 | echo "n -> p" | ||
55 | $cmd -in f.n -inform n -outform p >ff.p2 | ||
56 | if [ $? != 0 ]; then exit 1; fi | ||
57 | echo "p -> p" | ||
58 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
59 | if [ $? != 0 ]; then exit 1; fi | ||
60 | |||
61 | cmp fff.p f.p | ||
62 | if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p1 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | cmp fff.p ff.p2 | ||
66 | if [ $? != 0 ]; then exit 1; fi | ||
67 | cmp fff.p ff.p3 | ||
68 | if [ $? != 0 ]; then exit 1; fi | ||
69 | |||
70 | cmp f.n ff.n1 | ||
71 | if [ $? != 0 ]; then exit 1; fi | ||
72 | cmp f.n ff.n2 | ||
73 | if [ $? != 0 ]; then exit 1; fi | ||
74 | cmp f.n ff.n3 | ||
75 | if [ $? != 0 ]; then exit 1; fi | ||
76 | |||
77 | cmp f.p ff.p1 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | cmp f.p ff.p2 | ||
80 | if [ $? != 0 ]; then exit 1; fi | ||
81 | cmp f.p ff.p3 | ||
82 | if [ $? != 0 ]; then exit 1; fi | ||
83 | |||
84 | /bin/rm -f f.* ff.* fff.* | ||
85 | exit 0 | ||
diff --git a/src/lib/libssl/test/v3-cert1.pem b/src/lib/libssl/test/v3-cert1.pem deleted file mode 100644 index 0da253d5c3..0000000000 --- a/src/lib/libssl/test/v3-cert1.pem +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx | ||
3 | NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz | ||
4 | dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw | ||
5 | ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu | ||
6 | ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2 | ||
7 | ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp | ||
8 | miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C | ||
9 | AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK | ||
10 | Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x | ||
11 | DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR | ||
12 | MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB | ||
13 | AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21 | ||
14 | X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3 | ||
15 | WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO | ||
16 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/test/v3-cert2.pem b/src/lib/libssl/test/v3-cert2.pem deleted file mode 100644 index de0723ff8d..0000000000 --- a/src/lib/libssl/test/v3-cert2.pem +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | -----BEGIN CERTIFICATE----- | ||
2 | MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD | ||
3 | YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0 | ||
4 | ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu | ||
5 | dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1 | ||
6 | WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV | ||
7 | BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx | ||
8 | FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA | ||
9 | 6ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT | ||
10 | G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ | ||
11 | YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm | ||
12 | b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc | ||
13 | F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz | ||
14 | lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap | ||
15 | jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU= | ||
16 | -----END CERTIFICATE----- | ||
diff --git a/src/lib/libssl/tls1.h b/src/lib/libssl/tls1.h deleted file mode 100644 index 38838ea9a5..0000000000 --- a/src/lib/libssl/tls1.h +++ /dev/null | |||
@@ -1,195 +0,0 @@ | |||
1 | /* ssl/tls1.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 | |||
59 | #ifndef HEADER_TLS1_H | ||
60 | #define HEADER_TLS1_H | ||
61 | |||
62 | #include <openssl/buffer.h> | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | extern "C" { | ||
66 | #endif | ||
67 | |||
68 | #define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 1 | ||
69 | |||
70 | #define TLS1_VERSION 0x0301 | ||
71 | #define TLS1_VERSION_MAJOR 0x03 | ||
72 | #define TLS1_VERSION_MINOR 0x01 | ||
73 | |||
74 | #define TLS1_AD_DECRYPTION_FAILED 21 | ||
75 | #define TLS1_AD_RECORD_OVERFLOW 22 | ||
76 | #define TLS1_AD_UNKNOWN_CA 48 /* fatal */ | ||
77 | #define TLS1_AD_ACCESS_DENIED 49 /* fatal */ | ||
78 | #define TLS1_AD_DECODE_ERROR 50 /* fatal */ | ||
79 | #define TLS1_AD_DECRYPT_ERROR 51 | ||
80 | #define TLS1_AD_EXPORT_RESTRICTION 60 /* fatal */ | ||
81 | #define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */ | ||
82 | #define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */ | ||
83 | #define TLS1_AD_INTERNAL_ERROR 80 /* fatal */ | ||
84 | #define TLS1_AD_USER_CANCELLED 90 | ||
85 | #define TLS1_AD_NO_RENEGOTIATION 100 | ||
86 | |||
87 | /* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt | ||
88 | * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see | ||
89 | * s3_lib.c). We actually treat them like SSL 3.0 ciphers, which we probably | ||
90 | * shouldn't. */ | ||
91 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060 | ||
92 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061 | ||
93 | #define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062 | ||
94 | #define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063 | ||
95 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064 | ||
96 | #define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065 | ||
97 | #define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066 | ||
98 | |||
99 | /* AES ciphersuites from RFC3268 */ | ||
100 | |||
101 | #define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F | ||
102 | #define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030 | ||
103 | #define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031 | ||
104 | #define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032 | ||
105 | #define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033 | ||
106 | #define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034 | ||
107 | |||
108 | #define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035 | ||
109 | #define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036 | ||
110 | #define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037 | ||
111 | #define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038 | ||
112 | #define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039 | ||
113 | #define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A | ||
114 | |||
115 | /* XXX | ||
116 | * Inconsistency alert: | ||
117 | * The OpenSSL names of ciphers with ephemeral DH here include the string | ||
118 | * "DHE", while elsewhere it has always been "EDH". | ||
119 | * (The alias for the list of all such ciphers also is "EDH".) | ||
120 | * The specifications speak of "EDH"; maybe we should allow both forms | ||
121 | * for everything. */ | ||
122 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5" | ||
123 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5" | ||
124 | #define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA" | ||
125 | #define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA" | ||
126 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA" | ||
127 | #define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA" | ||
128 | #define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA" | ||
129 | |||
130 | /* AES ciphersuites from RFC3268 */ | ||
131 | #define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA" | ||
132 | #define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA" | ||
133 | #define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA" | ||
134 | #define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA" | ||
135 | #define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA" | ||
136 | #define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA" | ||
137 | |||
138 | #define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA" | ||
139 | #define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA" | ||
140 | #define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA" | ||
141 | #define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA" | ||
142 | #define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA" | ||
143 | #define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA" | ||
144 | |||
145 | |||
146 | #define TLS_CT_RSA_SIGN 1 | ||
147 | #define TLS_CT_DSS_SIGN 2 | ||
148 | #define TLS_CT_RSA_FIXED_DH 3 | ||
149 | #define TLS_CT_DSS_FIXED_DH 4 | ||
150 | #define TLS_CT_NUMBER 4 | ||
151 | |||
152 | #define TLS1_FINISH_MAC_LENGTH 12 | ||
153 | |||
154 | #define TLS_MD_MAX_CONST_SIZE 20 | ||
155 | #define TLS_MD_CLIENT_FINISH_CONST "client finished" | ||
156 | #define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 | ||
157 | #define TLS_MD_SERVER_FINISH_CONST "server finished" | ||
158 | #define TLS_MD_SERVER_FINISH_CONST_SIZE 15 | ||
159 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
160 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
161 | #define TLS_MD_KEY_EXPANSION_CONST "key expansion" | ||
162 | #define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 | ||
163 | #define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" | ||
164 | #define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 | ||
165 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
166 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
167 | #define TLS_MD_IV_BLOCK_CONST "IV block" | ||
168 | #define TLS_MD_IV_BLOCK_CONST_SIZE 8 | ||
169 | #define TLS_MD_MASTER_SECRET_CONST "master secret" | ||
170 | #define TLS_MD_MASTER_SECRET_CONST_SIZE 13 | ||
171 | |||
172 | #ifdef CHARSET_EBCDIC | ||
173 | #undef TLS_MD_CLIENT_FINISH_CONST | ||
174 | #define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/ | ||
175 | #undef TLS_MD_SERVER_FINISH_CONST | ||
176 | #define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/ | ||
177 | #undef TLS_MD_SERVER_WRITE_KEY_CONST | ||
178 | #define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/ | ||
179 | #undef TLS_MD_KEY_EXPANSION_CONST | ||
180 | #define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/ | ||
181 | #undef TLS_MD_CLIENT_WRITE_KEY_CONST | ||
182 | #define TLS_MD_CLIENT_WRITE_KEY_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*client write key*/ | ||
183 | #undef TLS_MD_SERVER_WRITE_KEY_CONST | ||
184 | #define TLS_MD_SERVER_WRITE_KEY_CONST "\x73\x65\x72\x76\x65\x72\x20\x77\x72\x69\x74\x65\x20\x6b\x65\x79" /*server write key*/ | ||
185 | #undef TLS_MD_IV_BLOCK_CONST | ||
186 | #define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/ | ||
187 | #undef TLS_MD_MASTER_SECRET_CONST | ||
188 | #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/ | ||
189 | #endif | ||
190 | |||
191 | #ifdef __cplusplus | ||
192 | } | ||
193 | #endif | ||
194 | #endif | ||
195 | |||