diff options
Diffstat (limited to 'src/lib/libssl')
71 files changed, 0 insertions, 22681 deletions
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE deleted file mode 100644 index bdd5f7bdd0..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-2000 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 d73c41adcd..0000000000 --- a/src/lib/libssl/bio_ssl.c +++ /dev/null | |||
@@ -1,586 +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,char *buf,int num); | ||
69 | static int ssl_read(BIO *h,char *buf,int size); | ||
70 | static int ssl_puts(BIO *h,char *str); | ||
71 | static long ssl_ctrl(BIO *h,int cmd,long arg1,char *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,void (*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 *)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 | 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_CONNECT: | ||
210 | BIO_set_retry_special(b); | ||
211 | retry_reason=BIO_RR_CONNECT; | ||
212 | break; | ||
213 | case SSL_ERROR_SYSCALL: | ||
214 | case SSL_ERROR_SSL: | ||
215 | case SSL_ERROR_ZERO_RETURN: | ||
216 | default: | ||
217 | break; | ||
218 | } | ||
219 | |||
220 | b->retry_reason=retry_reason; | ||
221 | return(ret); | ||
222 | } | ||
223 | |||
224 | static int ssl_write(BIO *b, char *out, int outl) | ||
225 | { | ||
226 | int ret,r=0; | ||
227 | int retry_reason=0; | ||
228 | SSL *ssl; | ||
229 | BIO_SSL *bs; | ||
230 | |||
231 | if (out == NULL) return(0); | ||
232 | bs=(BIO_SSL *)b->ptr; | ||
233 | ssl=bs->ssl; | ||
234 | |||
235 | BIO_clear_retry_flags(b); | ||
236 | |||
237 | /* ret=SSL_do_handshake(ssl); | ||
238 | if (ret > 0) */ | ||
239 | ret=SSL_write(ssl,out,outl); | ||
240 | |||
241 | switch (SSL_get_error(ssl,ret)) | ||
242 | { | ||
243 | case SSL_ERROR_NONE: | ||
244 | if (ret <= 0) break; | ||
245 | if (bs->renegotiate_count > 0) | ||
246 | { | ||
247 | bs->byte_count+=ret; | ||
248 | if (bs->byte_count > bs->renegotiate_count) | ||
249 | { | ||
250 | bs->byte_count=0; | ||
251 | bs->num_renegotiates++; | ||
252 | SSL_renegotiate(ssl); | ||
253 | r=1; | ||
254 | } | ||
255 | } | ||
256 | if ((bs->renegotiate_timeout > 0) && (!r)) | ||
257 | { | ||
258 | unsigned long tm; | ||
259 | |||
260 | tm=(unsigned long)time(NULL); | ||
261 | if (tm > bs->last_time+bs->renegotiate_timeout) | ||
262 | { | ||
263 | bs->last_time=tm; | ||
264 | bs->num_renegotiates++; | ||
265 | SSL_renegotiate(ssl); | ||
266 | } | ||
267 | } | ||
268 | break; | ||
269 | case SSL_ERROR_WANT_WRITE: | ||
270 | BIO_set_retry_write(b); | ||
271 | break; | ||
272 | case SSL_ERROR_WANT_READ: | ||
273 | BIO_set_retry_read(b); | ||
274 | break; | ||
275 | case SSL_ERROR_WANT_X509_LOOKUP: | ||
276 | BIO_set_retry_special(b); | ||
277 | retry_reason=BIO_RR_SSL_X509_LOOKUP; | ||
278 | break; | ||
279 | case SSL_ERROR_WANT_CONNECT: | ||
280 | BIO_set_retry_special(b); | ||
281 | retry_reason=BIO_RR_CONNECT; | ||
282 | case SSL_ERROR_SYSCALL: | ||
283 | case SSL_ERROR_SSL: | ||
284 | default: | ||
285 | break; | ||
286 | } | ||
287 | |||
288 | b->retry_reason=retry_reason; | ||
289 | return(ret); | ||
290 | } | ||
291 | |||
292 | static long ssl_ctrl(BIO *b, int cmd, long num, char *ptr) | ||
293 | { | ||
294 | SSL **sslp,*ssl; | ||
295 | BIO_SSL *bs; | ||
296 | BIO *dbio,*bio; | ||
297 | long ret=1; | ||
298 | |||
299 | bs=(BIO_SSL *)b->ptr; | ||
300 | ssl=bs->ssl; | ||
301 | if ((ssl == NULL) && (cmd != BIO_C_SET_SSL)) | ||
302 | return(0); | ||
303 | switch (cmd) | ||
304 | { | ||
305 | case BIO_CTRL_RESET: | ||
306 | SSL_shutdown(ssl); | ||
307 | |||
308 | if (ssl->handshake_func == ssl->method->ssl_connect) | ||
309 | SSL_set_connect_state(ssl); | ||
310 | else if (ssl->handshake_func == ssl->method->ssl_accept) | ||
311 | SSL_set_accept_state(ssl); | ||
312 | |||
313 | SSL_clear(ssl); | ||
314 | |||
315 | if (b->next_bio != NULL) | ||
316 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | ||
317 | else if (ssl->rbio != NULL) | ||
318 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
319 | else | ||
320 | ret=1; | ||
321 | break; | ||
322 | case BIO_CTRL_INFO: | ||
323 | ret=0; | ||
324 | break; | ||
325 | case BIO_C_SSL_MODE: | ||
326 | if (num) /* client mode */ | ||
327 | SSL_set_connect_state(ssl); | ||
328 | else | ||
329 | SSL_set_accept_state(ssl); | ||
330 | break; | ||
331 | case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT: | ||
332 | ret=bs->renegotiate_timeout; | ||
333 | if (num < 60) num=5; | ||
334 | bs->renegotiate_timeout=(unsigned long)num; | ||
335 | bs->last_time=(unsigned long)time(NULL); | ||
336 | break; | ||
337 | case BIO_C_SET_SSL_RENEGOTIATE_BYTES: | ||
338 | ret=bs->renegotiate_count; | ||
339 | if ((long)num >=512) | ||
340 | bs->renegotiate_count=(unsigned long)num; | ||
341 | break; | ||
342 | case BIO_C_GET_SSL_NUM_RENEGOTIATES: | ||
343 | ret=bs->num_renegotiates; | ||
344 | break; | ||
345 | case BIO_C_SET_SSL: | ||
346 | if (ssl != NULL) | ||
347 | ssl_free(b); | ||
348 | b->shutdown=(int)num; | ||
349 | ssl=(SSL *)ptr; | ||
350 | ((BIO_SSL *)b->ptr)->ssl=ssl; | ||
351 | bio=SSL_get_rbio(ssl); | ||
352 | if (bio != NULL) | ||
353 | { | ||
354 | if (b->next_bio != NULL) | ||
355 | BIO_push(bio,b->next_bio); | ||
356 | b->next_bio=bio; | ||
357 | CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO); | ||
358 | } | ||
359 | b->init=1; | ||
360 | break; | ||
361 | case BIO_C_GET_SSL: | ||
362 | if (ptr != NULL) | ||
363 | { | ||
364 | sslp=(SSL **)ptr; | ||
365 | *sslp=ssl; | ||
366 | } | ||
367 | else | ||
368 | ret=0; | ||
369 | break; | ||
370 | case BIO_CTRL_GET_CLOSE: | ||
371 | ret=b->shutdown; | ||
372 | break; | ||
373 | case BIO_CTRL_SET_CLOSE: | ||
374 | b->shutdown=(int)num; | ||
375 | break; | ||
376 | case BIO_CTRL_WPENDING: | ||
377 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
378 | break; | ||
379 | case BIO_CTRL_PENDING: | ||
380 | ret=SSL_pending(ssl); | ||
381 | if (ret == 0) | ||
382 | ret=BIO_pending(ssl->rbio); | ||
383 | break; | ||
384 | case BIO_CTRL_FLUSH: | ||
385 | BIO_clear_retry_flags(b); | ||
386 | ret=BIO_ctrl(ssl->wbio,cmd,num,ptr); | ||
387 | BIO_copy_next_retry(b); | ||
388 | break; | ||
389 | case BIO_CTRL_PUSH: | ||
390 | if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) | ||
391 | { | ||
392 | SSL_set_bio(ssl,b->next_bio,b->next_bio); | ||
393 | CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | ||
394 | } | ||
395 | break; | ||
396 | case BIO_CTRL_POP: | ||
397 | /* ugly bit of a hack */ | ||
398 | if (ssl->rbio != ssl->wbio) /* we are in trouble :-( */ | ||
399 | { | ||
400 | BIO_free_all(ssl->wbio); | ||
401 | } | ||
402 | ssl->wbio=NULL; | ||
403 | ssl->rbio=NULL; | ||
404 | break; | ||
405 | case BIO_C_DO_STATE_MACHINE: | ||
406 | BIO_clear_retry_flags(b); | ||
407 | |||
408 | b->retry_reason=0; | ||
409 | ret=(int)SSL_do_handshake(ssl); | ||
410 | |||
411 | switch (SSL_get_error(ssl,(int)ret)) | ||
412 | { | ||
413 | case SSL_ERROR_WANT_READ: | ||
414 | BIO_set_flags(b, | ||
415 | BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY); | ||
416 | break; | ||
417 | case SSL_ERROR_WANT_WRITE: | ||
418 | BIO_set_flags(b, | ||
419 | BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY); | ||
420 | break; | ||
421 | case SSL_ERROR_WANT_CONNECT: | ||
422 | BIO_set_flags(b, | ||
423 | BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY); | ||
424 | b->retry_reason=b->next_bio->retry_reason; | ||
425 | break; | ||
426 | default: | ||
427 | break; | ||
428 | } | ||
429 | break; | ||
430 | case BIO_CTRL_DUP: | ||
431 | dbio=(BIO *)ptr; | ||
432 | if (((BIO_SSL *)dbio->ptr)->ssl != NULL) | ||
433 | SSL_free(((BIO_SSL *)dbio->ptr)->ssl); | ||
434 | ((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl); | ||
435 | ((BIO_SSL *)dbio->ptr)->renegotiate_count= | ||
436 | ((BIO_SSL *)b->ptr)->renegotiate_count; | ||
437 | ((BIO_SSL *)dbio->ptr)->byte_count= | ||
438 | ((BIO_SSL *)b->ptr)->byte_count; | ||
439 | ((BIO_SSL *)dbio->ptr)->renegotiate_timeout= | ||
440 | ((BIO_SSL *)b->ptr)->renegotiate_timeout; | ||
441 | ((BIO_SSL *)dbio->ptr)->last_time= | ||
442 | ((BIO_SSL *)b->ptr)->last_time; | ||
443 | ret=(((BIO_SSL *)dbio->ptr)->ssl != NULL); | ||
444 | break; | ||
445 | case BIO_C_GET_FD: | ||
446 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
447 | break; | ||
448 | case BIO_CTRL_SET_CALLBACK: | ||
449 | { | ||
450 | #if 0 /* FIXME: Should this be used? -- Richard Levitte */ | ||
451 | BIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
452 | ret = -1; | ||
453 | #else | ||
454 | ret=0; | ||
455 | #endif | ||
456 | } | ||
457 | break; | ||
458 | case BIO_CTRL_GET_CALLBACK: | ||
459 | { | ||
460 | void (**fptr)(); | ||
461 | |||
462 | fptr=(void (**)())ptr; | ||
463 | *fptr=SSL_get_info_callback(ssl); | ||
464 | } | ||
465 | break; | ||
466 | default: | ||
467 | ret=BIO_ctrl(ssl->rbio,cmd,num,ptr); | ||
468 | break; | ||
469 | } | ||
470 | return(ret); | ||
471 | } | ||
472 | |||
473 | static long ssl_callback_ctrl(BIO *b, int cmd, void (*fp)()) | ||
474 | { | ||
475 | SSL *ssl; | ||
476 | BIO_SSL *bs; | ||
477 | long ret=1; | ||
478 | |||
479 | bs=(BIO_SSL *)b->ptr; | ||
480 | ssl=bs->ssl; | ||
481 | switch (cmd) | ||
482 | { | ||
483 | case BIO_CTRL_SET_CALLBACK: | ||
484 | { | ||
485 | SSL_set_info_callback(ssl,fp); | ||
486 | } | ||
487 | break; | ||
488 | default: | ||
489 | ret=BIO_callback_ctrl(ssl->rbio,cmd,fp); | ||
490 | break; | ||
491 | } | ||
492 | return(ret); | ||
493 | } | ||
494 | |||
495 | static int ssl_puts(BIO *bp, char *str) | ||
496 | { | ||
497 | int n,ret; | ||
498 | |||
499 | n=strlen(str); | ||
500 | ret=BIO_write(bp,str,n); | ||
501 | return(ret); | ||
502 | } | ||
503 | |||
504 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) | ||
505 | { | ||
506 | BIO *ret=NULL,*buf=NULL,*ssl=NULL; | ||
507 | |||
508 | if ((buf=BIO_new(BIO_f_buffer())) == NULL) | ||
509 | return(NULL); | ||
510 | if ((ssl=BIO_new_ssl_connect(ctx)) == NULL) | ||
511 | goto err; | ||
512 | if ((ret=BIO_push(buf,ssl)) == NULL) | ||
513 | goto err; | ||
514 | return(ret); | ||
515 | err: | ||
516 | if (buf != NULL) BIO_free(buf); | ||
517 | if (ssl != NULL) BIO_free(ssl); | ||
518 | return(NULL); | ||
519 | } | ||
520 | |||
521 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx) | ||
522 | { | ||
523 | BIO *ret=NULL,*con=NULL,*ssl=NULL; | ||
524 | |||
525 | if ((con=BIO_new(BIO_s_connect())) == NULL) | ||
526 | return(NULL); | ||
527 | if ((ssl=BIO_new_ssl(ctx,1)) == NULL) | ||
528 | goto err; | ||
529 | if ((ret=BIO_push(ssl,con)) == NULL) | ||
530 | goto err; | ||
531 | return(ret); | ||
532 | err: | ||
533 | if (con != NULL) BIO_free(con); | ||
534 | if (ret != NULL) BIO_free(ret); | ||
535 | return(NULL); | ||
536 | } | ||
537 | |||
538 | BIO *BIO_new_ssl(SSL_CTX *ctx, int client) | ||
539 | { | ||
540 | BIO *ret; | ||
541 | SSL *ssl; | ||
542 | |||
543 | if ((ret=BIO_new(BIO_f_ssl())) == NULL) | ||
544 | return(NULL); | ||
545 | if ((ssl=SSL_new(ctx)) == NULL) | ||
546 | { | ||
547 | BIO_free(ret); | ||
548 | return(NULL); | ||
549 | } | ||
550 | if (client) | ||
551 | SSL_set_connect_state(ssl); | ||
552 | else | ||
553 | SSL_set_accept_state(ssl); | ||
554 | |||
555 | BIO_set_ssl(ret,ssl,BIO_CLOSE); | ||
556 | return(ret); | ||
557 | } | ||
558 | |||
559 | int BIO_ssl_copy_session_id(BIO *t, BIO *f) | ||
560 | { | ||
561 | t=BIO_find_type(t,BIO_TYPE_SSL); | ||
562 | f=BIO_find_type(f,BIO_TYPE_SSL); | ||
563 | if ((t == NULL) || (f == NULL)) | ||
564 | return(0); | ||
565 | if ( (((BIO_SSL *)t->ptr)->ssl == NULL) || | ||
566 | (((BIO_SSL *)f->ptr)->ssl == NULL)) | ||
567 | return(0); | ||
568 | SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,((BIO_SSL *)f->ptr)->ssl); | ||
569 | return(1); | ||
570 | } | ||
571 | |||
572 | void BIO_ssl_shutdown(BIO *b) | ||
573 | { | ||
574 | SSL *s; | ||
575 | |||
576 | while (b != NULL) | ||
577 | { | ||
578 | if (b->method->type == BIO_TYPE_SSL) | ||
579 | { | ||
580 | s=((BIO_SSL *)b->ptr)->ssl; | ||
581 | SSL_shutdown(s); | ||
582 | break; | ||
583 | } | ||
584 | b=b->next_bio; | ||
585 | } | ||
586 | } | ||
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf deleted file mode 100644 index dbe8cbefe0..0000000000 --- a/src/lib/libssl/doc/openssl.cnf +++ /dev/null | |||
@@ -1,244 +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 | new_certs_dir = $dir/newcerts # default place for new certs. | ||
42 | |||
43 | certificate = $dir/cacert.pem # The CA certificate | ||
44 | serial = $dir/serial # The current serial number | ||
45 | crl = $dir/crl.pem # The current CRL | ||
46 | private_key = $dir/private/cakey.pem# The private key | ||
47 | RANDFILE = $dir/private/.rand # private random number file | ||
48 | |||
49 | x509_extensions = usr_cert # The extentions to add to the cert | ||
50 | |||
51 | # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs | ||
52 | # so this is commented out by default to leave a V1 CRL. | ||
53 | # crl_extensions = crl_ext | ||
54 | |||
55 | default_days = 365 # how long to certify for | ||
56 | default_crl_days= 30 # how long before next CRL | ||
57 | default_md = md5 # which md to use. | ||
58 | preserve = no # keep passed DN ordering | ||
59 | |||
60 | # A few difference way of specifying how similar the request should look | ||
61 | # For type CA, the listed attributes must be the same, and the optional | ||
62 | # and supplied fields are just that :-) | ||
63 | policy = policy_match | ||
64 | |||
65 | # For the CA policy | ||
66 | [ policy_match ] | ||
67 | countryName = match | ||
68 | stateOrProvinceName = match | ||
69 | organizationName = match | ||
70 | organizationalUnitName = optional | ||
71 | commonName = supplied | ||
72 | emailAddress = optional | ||
73 | |||
74 | # For the 'anything' policy | ||
75 | # At this point in time, you must list all acceptable 'object' | ||
76 | # types. | ||
77 | [ policy_anything ] | ||
78 | countryName = optional | ||
79 | stateOrProvinceName = optional | ||
80 | localityName = optional | ||
81 | organizationName = optional | ||
82 | organizationalUnitName = optional | ||
83 | commonName = supplied | ||
84 | emailAddress = optional | ||
85 | |||
86 | #################################################################### | ||
87 | [ req ] | ||
88 | default_bits = 1024 | ||
89 | default_keyfile = privkey.pem | ||
90 | distinguished_name = req_distinguished_name | ||
91 | attributes = req_attributes | ||
92 | x509_extensions = v3_ca # The extentions to add to the self signed cert | ||
93 | |||
94 | # Passwords for private keys if not present they will be prompted for | ||
95 | # input_password = secret | ||
96 | # output_password = secret | ||
97 | |||
98 | # This sets a mask for permitted string types. There are several options. | ||
99 | # default: PrintableString, T61String, BMPString. | ||
100 | # pkix : PrintableString, BMPString. | ||
101 | # utf8only: only UTF8Strings. | ||
102 | # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). | ||
103 | # MASK:XXXX a literal mask value. | ||
104 | # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings | ||
105 | # so use this option with caution! | ||
106 | string_mask = nombstr | ||
107 | |||
108 | # req_extensions = v3_req # The extensions to add to a certificate request | ||
109 | |||
110 | [ req_distinguished_name ] | ||
111 | countryName = Country Name (2 letter code) | ||
112 | countryName_default = AU | ||
113 | countryName_min = 2 | ||
114 | countryName_max = 2 | ||
115 | |||
116 | stateOrProvinceName = State or Province Name (full name) | ||
117 | stateOrProvinceName_default = Some-State | ||
118 | |||
119 | localityName = Locality Name (eg, city) | ||
120 | |||
121 | 0.organizationName = Organization Name (eg, company) | ||
122 | 0.organizationName_default = Internet Widgits Pty Ltd | ||
123 | |||
124 | # we can do this but it is not needed normally :-) | ||
125 | #1.organizationName = Second Organization Name (eg, company) | ||
126 | #1.organizationName_default = World Wide Web Pty Ltd | ||
127 | |||
128 | organizationalUnitName = Organizational Unit Name (eg, section) | ||
129 | #organizationalUnitName_default = | ||
130 | |||
131 | commonName = Common Name (eg, YOUR name) | ||
132 | commonName_max = 64 | ||
133 | |||
134 | emailAddress = Email Address | ||
135 | emailAddress_max = 40 | ||
136 | |||
137 | # SET-ex3 = SET extension number 3 | ||
138 | |||
139 | [ req_attributes ] | ||
140 | challengePassword = A challenge password | ||
141 | challengePassword_min = 4 | ||
142 | challengePassword_max = 20 | ||
143 | |||
144 | unstructuredName = An optional company name | ||
145 | |||
146 | [ usr_cert ] | ||
147 | |||
148 | # These extensions are added when 'ca' signs a request. | ||
149 | |||
150 | # This goes against PKIX guidelines but some CAs do it and some software | ||
151 | # requires this to avoid interpreting an end user certificate as a CA. | ||
152 | |||
153 | basicConstraints=CA:FALSE | ||
154 | |||
155 | # Here are some examples of the usage of nsCertType. If it is omitted | ||
156 | # the certificate can be used for anything *except* object signing. | ||
157 | |||
158 | # This is OK for an SSL server. | ||
159 | # nsCertType = server | ||
160 | |||
161 | # For an object signing certificate this would be used. | ||
162 | # nsCertType = objsign | ||
163 | |||
164 | # For normal client use this is typical | ||
165 | # nsCertType = client, email | ||
166 | |||
167 | # and for everything including object signing: | ||
168 | # nsCertType = client, email, objsign | ||
169 | |||
170 | # This is typical in keyUsage for a client certificate. | ||
171 | # keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
172 | |||
173 | # This will be displayed in Netscape's comment listbox. | ||
174 | nsComment = "OpenSSL Generated Certificate" | ||
175 | |||
176 | # PKIX recommendations harmless if included in all certificates. | ||
177 | subjectKeyIdentifier=hash | ||
178 | authorityKeyIdentifier=keyid,issuer:always | ||
179 | |||
180 | # This stuff is for subjectAltName and issuerAltname. | ||
181 | # Import the email address. | ||
182 | # subjectAltName=email:copy | ||
183 | |||
184 | # Copy subject details | ||
185 | # issuerAltName=issuer:copy | ||
186 | |||
187 | #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem | ||
188 | #nsBaseUrl | ||
189 | #nsRevocationUrl | ||
190 | #nsRenewalUrl | ||
191 | #nsCaPolicyUrl | ||
192 | #nsSslServerName | ||
193 | |||
194 | [ v3_req ] | ||
195 | |||
196 | # Extensions to add to a certificate request | ||
197 | |||
198 | basicConstraints = CA:FALSE | ||
199 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment | ||
200 | |||
201 | [ v3_ca ] | ||
202 | |||
203 | |||
204 | # Extensions for a typical CA | ||
205 | |||
206 | |||
207 | # PKIX recommendation. | ||
208 | |||
209 | subjectKeyIdentifier=hash | ||
210 | |||
211 | authorityKeyIdentifier=keyid:always,issuer:always | ||
212 | |||
213 | # This is what PKIX recommends but some broken software chokes on critical | ||
214 | # extensions. | ||
215 | #basicConstraints = critical,CA:true | ||
216 | # So we do this instead. | ||
217 | basicConstraints = CA:true | ||
218 | |||
219 | # Key usage: this is typical for a CA certificate. However since it will | ||
220 | # prevent it being used as an test self-signed certificate it is best | ||
221 | # left out by default. | ||
222 | # keyUsage = cRLSign, keyCertSign | ||
223 | |||
224 | # Some might want this also | ||
225 | # nsCertType = sslCA, emailCA | ||
226 | |||
227 | # Include email address in subject alt name: another PKIX recommendation | ||
228 | # subjectAltName=email:copy | ||
229 | # Copy issuer details | ||
230 | # issuerAltName=issuer:copy | ||
231 | |||
232 | # DER hex encoding of an extension: beware experts only! | ||
233 | # obj=DER:02:03 | ||
234 | # Where 'obj' is a standard or added object | ||
235 | # You can even override a supported extension: | ||
236 | # basicConstraints= critical, DER:30:03:01:01:FF | ||
237 | |||
238 | [ crl_ext ] | ||
239 | |||
240 | # CRL extensions. | ||
241 | # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. | ||
242 | |||
243 | # issuerAltName=issuer:copy | ||
244 | authorityKeyIdentifier=keyid:always,issuer:always | ||
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt deleted file mode 100644 index 880eace4da..0000000000 --- a/src/lib/libssl/doc/openssl.txt +++ /dev/null | |||
@@ -1,1176 +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,URL: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 | CRL distribution points. | ||
359 | |||
360 | This is a multi-valued extension that supports all the literal options of | ||
361 | subject alternative name. Of the few software packages that currently interpret | ||
362 | this extension most only interpret the URI option. | ||
363 | |||
364 | Currently each option will set a new DistributionPoint with the fullName | ||
365 | field set to the given value. | ||
366 | |||
367 | Other fields like cRLissuer and reasons cannot currently be set or displayed: | ||
368 | at this time no examples were available that used these fields. | ||
369 | |||
370 | If you see this extension with <UNSUPPORTED> when you attempt to print it out | ||
371 | or it doesn't appear to display correctly then let me know, including the | ||
372 | certificate (mail me at steve@openssl.org) . | ||
373 | |||
374 | Examples: | ||
375 | |||
376 | crlDistributionPoints=URI:http://www.myhost.com/myca.crl | ||
377 | crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl | ||
378 | |||
379 | Certificate Policies. | ||
380 | |||
381 | This is a RAW extension. It attempts to display the contents of this extension: | ||
382 | unfortunately this extension is often improperly encoded. | ||
383 | |||
384 | The certificate policies extension will rarely be used in practice: few | ||
385 | software packages interpret it correctly or at all. IE5 does partially | ||
386 | support this extension: but it needs the 'ia5org' option because it will | ||
387 | only correctly support a broken encoding. Of the options below only the | ||
388 | policy OID, explicitText and CPS options are displayed with IE5. | ||
389 | |||
390 | All the fields of this extension can be set by using the appropriate syntax. | ||
391 | |||
392 | If you follow the PKIX recommendations of not including any qualifiers and just | ||
393 | using only one OID then you just include the value of that OID. Multiple OIDs | ||
394 | can be set separated by commas, for example: | ||
395 | |||
396 | certificatePolicies= 1.2.4.5, 1.1.3.4 | ||
397 | |||
398 | If you wish to include qualifiers then the policy OID and qualifiers need to | ||
399 | be specified in a separate section: this is done by using the @section syntax | ||
400 | instead of a literal OID value. | ||
401 | |||
402 | The section referred to must include the policy OID using the name | ||
403 | policyIdentifier, cPSuri qualifiers can be included using the syntax: | ||
404 | |||
405 | CPS.nnn=value | ||
406 | |||
407 | userNotice qualifiers can be set using the syntax: | ||
408 | |||
409 | userNotice.nnn=@notice | ||
410 | |||
411 | The value of the userNotice qualifier is specified in the relevant section. | ||
412 | This section can include explicitText, organization and noticeNumbers | ||
413 | options. explicitText and organization are text strings, noticeNumbers is a | ||
414 | comma separated list of numbers. The organization and noticeNumbers options | ||
415 | (if included) must BOTH be present. If you use the userNotice option with IE5 | ||
416 | then you need the 'ia5org' option at the top level to modify the encoding: | ||
417 | otherwise it will not be interpreted properly. | ||
418 | |||
419 | Example: | ||
420 | |||
421 | certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect | ||
422 | |||
423 | [polsect] | ||
424 | |||
425 | policyIdentifier = 1.3.5.8 | ||
426 | CPS.1="http://my.host.name/" | ||
427 | CPS.2="http://my.your.name/" | ||
428 | userNotice.1=@notice | ||
429 | |||
430 | [notice] | ||
431 | |||
432 | explicitText="Explicit Text Here" | ||
433 | organization="Organisation Name" | ||
434 | noticeNumbers=1,2,3,4 | ||
435 | |||
436 | TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field, | ||
437 | according to PKIX it should be of type DisplayText but Verisign uses an | ||
438 | IA5STRING and IE5 needs this too. | ||
439 | |||
440 | Display only extensions. | ||
441 | |||
442 | Some extensions are only partially supported and currently are only displayed | ||
443 | but cannot be set. These include private key usage period, CRL number, and | ||
444 | CRL reason. | ||
445 | |||
446 | ============================================================================== | ||
447 | X509V3 Extension code: programmers guide | ||
448 | ============================================================================== | ||
449 | |||
450 | The purpose of the extension code is twofold. It allows an extension to be | ||
451 | created from a string or structure describing its contents and it prints out an | ||
452 | extension in a human or machine readable form. | ||
453 | |||
454 | 1. Initialisation and cleanup. | ||
455 | |||
456 | No special initialisation is needed before calling the extension functions. | ||
457 | You used to have to call X509V3_add_standard_extensions(); but this is no longer | ||
458 | required and this function no longer does anything. | ||
459 | |||
460 | void X509V3_EXT_cleanup(void); | ||
461 | |||
462 | This function should be called to cleanup the extension code if any custom | ||
463 | extensions have been added. If no custom extensions have been added then this | ||
464 | call does nothing. After this call all custom extension code is freed up but | ||
465 | you can still use the standard extensions. | ||
466 | |||
467 | 2. Printing and parsing extensions. | ||
468 | |||
469 | The simplest way to print out extensions is via the standard X509 printing | ||
470 | routines: if you use the standard X509_print() function, the supported | ||
471 | extensions will be printed out automatically. | ||
472 | |||
473 | The following functions allow finer control over extension display: | ||
474 | |||
475 | int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent); | ||
476 | int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); | ||
477 | |||
478 | These two functions print out an individual extension to a BIO or FILE pointer. | ||
479 | Currently the flag argument is unused and should be set to 0. The 'indent' | ||
480 | argument is the number of spaces to indent each line. | ||
481 | |||
482 | void *X509V3_EXT_d2i(X509_EXTENSION *ext); | ||
483 | |||
484 | This function parses an extension and returns its internal structure. The | ||
485 | precise structure you get back depends on the extension being parsed. If the | ||
486 | extension if basicConstraints you will get back a pointer to a | ||
487 | BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more | ||
488 | details about the structures returned. The returned structure should be freed | ||
489 | after use using the relevant free function, BASIC_CONSTRAINTS_free() for | ||
490 | example. | ||
491 | |||
492 | 3. Generating extensions. | ||
493 | |||
494 | An extension will typically be generated from a configuration file, or some | ||
495 | other kind of configuration database. | ||
496 | |||
497 | int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, | ||
498 | X509 *cert); | ||
499 | int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, | ||
500 | X509_CRL *crl); | ||
501 | |||
502 | These functions add all the extensions in the given section to the given | ||
503 | certificate or CRL. They will normally be called just before the certificate | ||
504 | or CRL is due to be signed. Both return 0 on error on non zero for success. | ||
505 | |||
506 | In each case 'conf' is the LHASH pointer of the configuration file to use | ||
507 | and 'section' is the section containing the extension details. | ||
508 | |||
509 | See the 'context functions' section for a description of the ctx parameter. | ||
510 | |||
511 | |||
512 | X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, | ||
513 | char *value); | ||
514 | |||
515 | This function returns an extension based on a name and value pair, if the | ||
516 | pair will not need to access other sections in a config file (or there is no | ||
517 | config file) then the 'conf' parameter can be set to NULL. | ||
518 | |||
519 | X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid, | ||
520 | char *value); | ||
521 | |||
522 | This function creates an extension in the same way as X509V3_EXT_conf() but | ||
523 | takes the NID of the extension rather than its name. | ||
524 | |||
525 | For example to produce basicConstraints with the CA flag and a path length of | ||
526 | 10: | ||
527 | |||
528 | x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10"); | ||
529 | |||
530 | |||
531 | X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); | ||
532 | |||
533 | This function sets up an extension from its internal structure. The ext_nid | ||
534 | parameter is the NID of the extension and 'crit' is the critical flag. | ||
535 | |||
536 | 4. Context functions. | ||
537 | |||
538 | The following functions set and manipulate an extension context structure. | ||
539 | The purpose of the extension context is to allow the extension code to | ||
540 | access various structures relating to the "environment" of the certificate: | ||
541 | for example the issuers certificate or the certificate request. | ||
542 | |||
543 | void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, | ||
544 | X509_REQ *req, X509_CRL *crl, int flags); | ||
545 | |||
546 | This function sets up an X509V3_CTX structure with details of the certificate | ||
547 | environment: specifically the issuers certificate, the subject certificate, | ||
548 | the certificate request and the CRL: if these are not relevant or not | ||
549 | available then they can be set to NULL. The 'flags' parameter should be set | ||
550 | to zero. | ||
551 | |||
552 | X509V3_set_ctx_test(ctx) | ||
553 | |||
554 | This macro is used to set the 'ctx' structure to a 'test' value: this is to | ||
555 | allow the syntax of an extension (or configuration file) to be tested. | ||
556 | |||
557 | X509V3_set_ctx_nodb(ctx) | ||
558 | |||
559 | This macro is used when no configuration database is present. | ||
560 | |||
561 | void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash); | ||
562 | |||
563 | This function is used to set the configuration database when it is an LHASH | ||
564 | structure: typically a configuration file. | ||
565 | |||
566 | The following functions are used to access a configuration database: they | ||
567 | should only be used in RAW extensions. | ||
568 | |||
569 | char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section); | ||
570 | |||
571 | This function returns the value of the parameter "name" in "section", or NULL | ||
572 | if there has been an error. | ||
573 | |||
574 | void X509V3_string_free(X509V3_CTX *ctx, char *str); | ||
575 | |||
576 | This function frees up the string returned by the above function. | ||
577 | |||
578 | STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section); | ||
579 | |||
580 | This function returns a whole section as a STACK_OF(CONF_VALUE) . | ||
581 | |||
582 | void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); | ||
583 | |||
584 | This function frees up the STACK returned by the above function. | ||
585 | |||
586 | Note: it is possible to use the extension code with a custom configuration | ||
587 | database. To do this the "db_meth" element of the X509V3_CTX structure should | ||
588 | be set to an X509V3_CTX_METHOD structure. This structure contains the following | ||
589 | function pointers: | ||
590 | |||
591 | char * (*get_string)(void *db, char *section, char *value); | ||
592 | STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section); | ||
593 | void (*free_string)(void *db, char * string); | ||
594 | void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section); | ||
595 | |||
596 | these will be called and passed the 'db' element in the X509V3_CTX structure | ||
597 | to access the database. If a given function is not implemented or not required | ||
598 | it can be set to NULL. | ||
599 | |||
600 | 5. String helper functions. | ||
601 | |||
602 | There are several "i2s" and "s2i" functions that convert structures to and | ||
603 | from ASCII strings. In all the "i2s" cases the returned string should be | ||
604 | freed using Free() after use. Since some of these are part of other extension | ||
605 | code they may take a 'method' parameter. Unless otherwise stated it can be | ||
606 | safely set to NULL. | ||
607 | |||
608 | char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct); | ||
609 | |||
610 | This returns a hex string from an ASN1_OCTET_STRING. | ||
611 | |||
612 | char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint); | ||
613 | char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); | ||
614 | |||
615 | These return a string decimal representations of an ASN1_INTEGER and an | ||
616 | ASN1_ENUMERATED type, respectively. | ||
617 | |||
618 | ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, | ||
619 | X509V3_CTX *ctx, char *str); | ||
620 | |||
621 | This converts an ASCII hex string to an ASN1_OCTET_STRING. | ||
622 | |||
623 | ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value); | ||
624 | |||
625 | This converts a decimal ASCII string into an ASN1_INTEGER. | ||
626 | |||
627 | 6. Multi valued extension helper functions. | ||
628 | |||
629 | The following functions can be used to manipulate STACKs of CONF_VALUE | ||
630 | structures, as used by multi valued extensions. | ||
631 | |||
632 | int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool); | ||
633 | |||
634 | This function expects a boolean value in 'value' and sets 'asn1_bool' to | ||
635 | it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following | ||
636 | strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE" | ||
637 | "false", "N", "n", "NO" or "no". | ||
638 | |||
639 | int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint); | ||
640 | |||
641 | This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER. | ||
642 | |||
643 | int X509V3_add_value(const char *name, const char *value, | ||
644 | STACK_OF(CONF_VALUE) **extlist); | ||
645 | |||
646 | This simply adds a string name and value pair. | ||
647 | |||
648 | int X509V3_add_value_uchar(const char *name, const unsigned char *value, | ||
649 | STACK_OF(CONF_VALUE) **extlist); | ||
650 | |||
651 | The same as above but for an unsigned character value. | ||
652 | |||
653 | int X509V3_add_value_bool(const char *name, int asn1_bool, | ||
654 | STACK_OF(CONF_VALUE) **extlist); | ||
655 | |||
656 | This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool' | ||
657 | |||
658 | int X509V3_add_value_bool_nf(char *name, int asn1_bool, | ||
659 | STACK_OF(CONF_VALUE) **extlist); | ||
660 | |||
661 | This is the same as above except it adds nothing if asn1_bool is FALSE. | ||
662 | |||
663 | int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, | ||
664 | STACK_OF(CONF_VALUE) **extlist); | ||
665 | |||
666 | This function adds the value of the ASN1_INTEGER in decimal form. | ||
667 | |||
668 | 7. Other helper functions. | ||
669 | |||
670 | <to be added> | ||
671 | |||
672 | ADDING CUSTOM EXTENSIONS. | ||
673 | |||
674 | Currently there are three types of supported extensions. | ||
675 | |||
676 | String extensions are simple strings where the value is placed directly in the | ||
677 | extensions, and the string returned is printed out. | ||
678 | |||
679 | Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs | ||
680 | or return a STACK_OF(CONF_VALUE). | ||
681 | |||
682 | Raw extensions are just passed a BIO or a value and it is the extensions | ||
683 | responsibility to handle all the necessary printing. | ||
684 | |||
685 | There are two ways to add an extension. One is simply as an alias to an already | ||
686 | existing extension. An alias is an extension that is identical in ASN1 structure | ||
687 | to an existing extension but has a different OBJECT IDENTIFIER. This can be | ||
688 | done by calling: | ||
689 | |||
690 | int X509V3_EXT_add_alias(int nid_to, int nid_from); | ||
691 | |||
692 | 'nid_to' is the new extension NID and 'nid_from' is the already existing | ||
693 | extension NID. | ||
694 | |||
695 | Alternatively an extension can be written from scratch. This involves writing | ||
696 | the ASN1 code to encode and decode the extension and functions to print out and | ||
697 | generate the extension from strings. The relevant functions are then placed in | ||
698 | a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext); | ||
699 | called. | ||
700 | |||
701 | The X509V3_EXT_METHOD structure is described below. | ||
702 | |||
703 | strut { | ||
704 | int ext_nid; | ||
705 | int ext_flags; | ||
706 | X509V3_EXT_NEW ext_new; | ||
707 | X509V3_EXT_FREE ext_free; | ||
708 | X509V3_EXT_D2I d2i; | ||
709 | X509V3_EXT_I2D i2d; | ||
710 | X509V3_EXT_I2S i2s; | ||
711 | X509V3_EXT_S2I s2i; | ||
712 | X509V3_EXT_I2V i2v; | ||
713 | X509V3_EXT_V2I v2i; | ||
714 | X509V3_EXT_R2I r2i; | ||
715 | X509V3_EXT_I2R i2r; | ||
716 | |||
717 | void *usr_data; | ||
718 | }; | ||
719 | |||
720 | The elements have the following meanings. | ||
721 | |||
722 | ext_nid is the NID of the object identifier of the extension. | ||
723 | |||
724 | ext_flags is set of flags. Currently the only external flag is | ||
725 | X509V3_EXT_MULTILINE which means a multi valued extensions | ||
726 | should be printed on separate lines. | ||
727 | |||
728 | usr_data is an extension specific pointer to any relevant data. This | ||
729 | allows extensions to share identical code but have different | ||
730 | uses. An example of this is the bit string extension which uses | ||
731 | usr_data to contain a list of the bit names. | ||
732 | |||
733 | All the remaining elements are function pointers. | ||
734 | |||
735 | ext_new is a pointer to a function that allocates memory for the | ||
736 | extension ASN1 structure: for example ASN1_OBJECT_new(). | ||
737 | |||
738 | ext_free is a pointer to a function that free up memory of the extension | ||
739 | ASN1 structure: for example ASN1_OBJECT_free(). | ||
740 | |||
741 | d2i is the standard ASN1 function that converts a DER buffer into | ||
742 | the internal ASN1 structure: for example d2i_ASN1_IA5STRING(). | ||
743 | |||
744 | i2d is the standard ASN1 function that converts the internal | ||
745 | structure into the DER representation: for example | ||
746 | i2d_ASN1_IA5STRING(). | ||
747 | |||
748 | The remaining functions are depend on the type of extension. One i2X and | ||
749 | one X2i should be set and the rest set to NULL. The types set do not need | ||
750 | to match up, for example the extension could be set using the multi valued | ||
751 | v2i function and printed out using the raw i2r. | ||
752 | |||
753 | All functions have the X509V3_EXT_METHOD passed to them in the 'method' | ||
754 | parameter and an X509V3_CTX structure. Extension code can then access the | ||
755 | parent structure via the 'method' parameter to for example make use of the value | ||
756 | of usr_data. If the code needs to use detail relating to the request it can | ||
757 | use the 'ctx' parameter. | ||
758 | |||
759 | A note should be given here about the 'flags' member of the 'ctx' parameter. | ||
760 | If it has the value CTX_TEST then the configuration syntax is being checked | ||
761 | and no actual certificate or CRL exists. Therefore any attempt in the config | ||
762 | file to access such information should silently succeed. If the syntax is OK | ||
763 | then it should simply return a (possibly bogus) extension, otherwise it | ||
764 | should return NULL. | ||
765 | |||
766 | char *i2s(struct v3_ext_method *method, void *ext); | ||
767 | |||
768 | This function takes the internal structure in the ext parameter and returns | ||
769 | a Malloc'ed string representing its value. | ||
770 | |||
771 | void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); | ||
772 | |||
773 | This function takes the string representation in the ext parameter and returns | ||
774 | an allocated internal structure: ext_free() will be used on this internal | ||
775 | structure after use. | ||
776 | |||
777 | i2v and v2i handle a STACK_OF(CONF_VALUE): | ||
778 | |||
779 | typedef struct | ||
780 | { | ||
781 | char *section; | ||
782 | char *name; | ||
783 | char *value; | ||
784 | } CONF_VALUE; | ||
785 | |||
786 | Only the name and value members are currently used. | ||
787 | |||
788 | STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext); | ||
789 | |||
790 | This function is passed the internal structure in the ext parameter and | ||
791 | returns a STACK of CONF_VALUE structures. The values of name, value, | ||
792 | section and the structure itself will be freed up with Free after use. | ||
793 | Several helper functions are available to add values to this STACK. | ||
794 | |||
795 | void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, | ||
796 | STACK_OF(CONF_VALUE) *values); | ||
797 | |||
798 | This function takes a STACK_OF(CONF_VALUE) structures and should set the | ||
799 | values of the external structure. This typically uses the name element to | ||
800 | determine which structure element to set and the value element to determine | ||
801 | what to set it to. Several helper functions are available for this | ||
802 | purpose (see above). | ||
803 | |||
804 | int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent); | ||
805 | |||
806 | This function is passed the internal extension structure in the ext parameter | ||
807 | and sends out a human readable version of the extension to out. The 'indent' | ||
808 | parameter should be noted to determine the necessary amount of indentation | ||
809 | needed on the output. | ||
810 | |||
811 | void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); | ||
812 | |||
813 | This is just passed the string representation of the extension. It is intended | ||
814 | to be used for more elaborate extensions where the standard single and multi | ||
815 | valued options are insufficient. They can use the 'ctx' parameter to parse the | ||
816 | configuration database themselves. See the context functions section for details | ||
817 | of how to do this. | ||
818 | |||
819 | Note: although this type takes the same parameters as the "r2s" function there | ||
820 | is a subtle difference. Whereas an "r2i" function can access a configuration | ||
821 | database an "s2i" function MUST NOT. This is so the internal code can safely | ||
822 | assume that an "s2i" function will work without a configuration database. | ||
823 | |||
824 | ============================================================================== | ||
825 | PKCS#12 Library | ||
826 | ============================================================================== | ||
827 | |||
828 | This section describes the internal PKCS#12 support. There are very few | ||
829 | differences between the old external library and the new internal code at | ||
830 | present. This may well change because the external library will not be updated | ||
831 | much in future. | ||
832 | |||
833 | This version now includes a couple of high level PKCS#12 functions which | ||
834 | generally "do the right thing" and should make it much easier to handle PKCS#12 | ||
835 | structures. | ||
836 | |||
837 | HIGH LEVEL FUNCTIONS. | ||
838 | |||
839 | For most applications you only need concern yourself with the high level | ||
840 | functions. They can parse and generate simple PKCS#12 files as produced by | ||
841 | Netscape and MSIE or indeed any compliant PKCS#12 file containing a single | ||
842 | private key and certificate pair. | ||
843 | |||
844 | 1. Initialisation and cleanup. | ||
845 | |||
846 | No special initialisation is needed for the internal PKCS#12 library: the | ||
847 | standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to | ||
848 | add all algorithms (you should at least add SHA1 though) then you can manually | ||
849 | initialise the PKCS#12 library with: | ||
850 | |||
851 | PKCS12_PBE_add(); | ||
852 | |||
853 | The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is | ||
854 | called or it can be directly freed with: | ||
855 | |||
856 | EVP_PBE_cleanup(); | ||
857 | |||
858 | after this call (or EVP_cleanup() ) no more PKCS#12 library functions should | ||
859 | be called. | ||
860 | |||
861 | 2. I/O functions. | ||
862 | |||
863 | i2d_PKCS12_bio(bp, p12) | ||
864 | |||
865 | This writes out a PKCS12 structure to a BIO. | ||
866 | |||
867 | i2d_PKCS12_fp(fp, p12) | ||
868 | |||
869 | This is the same but for a FILE pointer. | ||
870 | |||
871 | d2i_PKCS12_bio(bp, p12) | ||
872 | |||
873 | This reads in a PKCS12 structure from a BIO. | ||
874 | |||
875 | d2i_PKCS12_fp(fp, p12) | ||
876 | |||
877 | This is the same but for a FILE pointer. | ||
878 | |||
879 | 3. High level functions. | ||
880 | |||
881 | 3.1 Parsing with PKCS12_parse(). | ||
882 | |||
883 | int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert, | ||
884 | STACK **ca); | ||
885 | |||
886 | This function takes a PKCS12 structure and a password (ASCII, null terminated) | ||
887 | and returns the private key, the corresponding certificate and any CA | ||
888 | certificates. If any of these is not required it can be passed as a NULL. | ||
889 | The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK | ||
890 | structure. Typically to read in a PKCS#12 file you might do: | ||
891 | |||
892 | p12 = d2i_PKCS12_fp(fp, NULL); | ||
893 | PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */ | ||
894 | PKCS12_free(p12); | ||
895 | |||
896 | 3.2 PKCS#12 creation with PKCS12_create(). | ||
897 | |||
898 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, | ||
899 | STACK *ca, int nid_key, int nid_cert, int iter, | ||
900 | int mac_iter, int keytype); | ||
901 | |||
902 | This function will create a PKCS12 structure from a given password, name, | ||
903 | private key, certificate and optional STACK of CA certificates. The remaining | ||
904 | 5 parameters can be set to 0 and sensible defaults will be used. | ||
905 | |||
906 | The parameters nid_key and nid_cert are the key and certificate encryption | ||
907 | algorithms, iter is the encryption iteration count, mac_iter is the MAC | ||
908 | iteration count and keytype is the type of private key. If you really want | ||
909 | to know what these last 5 parameters do then read the low level section. | ||
910 | |||
911 | Typically to create a PKCS#12 file the following could be used: | ||
912 | |||
913 | p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0); | ||
914 | i2d_PKCS12_fp(fp, p12); | ||
915 | PKCS12_free(p12); | ||
916 | |||
917 | 3.3 Changing a PKCS#12 structure password. | ||
918 | |||
919 | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass); | ||
920 | |||
921 | This changes the password of an already existing PKCS#12 structure. oldpass | ||
922 | is the old password and newpass is the new one. An error occurs if the old | ||
923 | password is incorrect. | ||
924 | |||
925 | LOW LEVEL FUNCTIONS. | ||
926 | |||
927 | In some cases the high level functions do not provide the necessary | ||
928 | functionality. For example if you want to generate or parse more complex | ||
929 | PKCS#12 files. The sample pkcs12 application uses the low level functions | ||
930 | to display details about the internal structure of a PKCS#12 file. | ||
931 | |||
932 | Introduction. | ||
933 | |||
934 | This is a brief description of how a PKCS#12 file is represented internally: | ||
935 | some knowledge of PKCS#12 is assumed. | ||
936 | |||
937 | A PKCS#12 object contains several levels. | ||
938 | |||
939 | At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a | ||
940 | CRL, a private key, encrypted or unencrypted, a set of safebags (so the | ||
941 | structure can be nested) or other secrets (not documented at present). | ||
942 | A safebag can optionally have attributes, currently these are: a unicode | ||
943 | friendlyName (a Unicode string) or a localKeyID (a string of bytes). | ||
944 | |||
945 | At the next level is an authSafe which is a set of safebags collected into | ||
946 | a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself. | ||
947 | |||
948 | At the top level is the PKCS12 structure itself which contains a set of | ||
949 | authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it | ||
950 | contains a MAC which is a kind of password protected digest to preserve | ||
951 | integrity (so any unencrypted stuff below can't be tampered with). | ||
952 | |||
953 | The reason for these levels is so various objects can be encrypted in various | ||
954 | ways. For example you might want to encrypt a set of private keys with | ||
955 | triple-DES and then include the related certificates either unencrypted or | ||
956 | with lower encryption. Yes it's the dreaded crypto laws at work again which | ||
957 | allow strong encryption on private keys and only weak encryption on other | ||
958 | stuff. | ||
959 | |||
960 | To build one of these things you turn all certificates and keys into safebags | ||
961 | (with optional attributes). You collect the safebags into (one or more) STACKS | ||
962 | and convert these into authsafes (encrypted or unencrypted). The authsafes | ||
963 | are collected into a STACK and added to a PKCS12 structure. Finally a MAC | ||
964 | inserted. | ||
965 | |||
966 | Pulling one apart is basically the reverse process. The MAC is verified against | ||
967 | the given password. The authsafes are extracted and each authsafe split into | ||
968 | a set of safebags (possibly involving decryption). Finally the safebags are | ||
969 | decomposed into the original keys and certificates and the attributes used to | ||
970 | match up private key and certificate pairs. | ||
971 | |||
972 | Anyway here are the functions that do the dirty work. | ||
973 | |||
974 | 1. Construction functions. | ||
975 | |||
976 | 1.1 Safebag functions. | ||
977 | |||
978 | M_PKCS12_x5092certbag(x509) | ||
979 | |||
980 | This macro takes an X509 structure and returns a certificate bag. The | ||
981 | X509 structure can be freed up after calling this function. | ||
982 | |||
983 | M_PKCS12_x509crl2certbag(crl) | ||
984 | |||
985 | As above but for a CRL. | ||
986 | |||
987 | PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey) | ||
988 | |||
989 | Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure. | ||
990 | Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo | ||
991 | structure contains a private key data in plain text form it should be free'd | ||
992 | up as soon as it has been encrypted for security reasons (freeing up the | ||
993 | structure zeros out the sensitive data). This can be done with | ||
994 | PKCS8_PRIV_KEY_INFO_free(). | ||
995 | |||
996 | PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage) | ||
997 | |||
998 | This sets the key type when a key is imported into MSIE or Outlook 98. Two | ||
999 | values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type | ||
1000 | key that can also be used for signing but its size is limited in the export | ||
1001 | versions of MS software to 512 bits, it is also the default. KEY_SIG is a | ||
1002 | signing only key but the keysize is unlimited (well 16K is supposed to work). | ||
1003 | If you are using the domestic version of MSIE then you can ignore this because | ||
1004 | KEY_EX is not limited and can be used for both. | ||
1005 | |||
1006 | PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8) | ||
1007 | |||
1008 | Convert a PKCS8 private key structure into a keybag. This routine embeds the | ||
1009 | p8 structure in the keybag so p8 should not be freed up or used after it is | ||
1010 | called. The p8 structure will be freed up when the safebag is freed. | ||
1011 | |||
1012 | 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) | ||
1013 | |||
1014 | Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not | ||
1015 | embedded and can be freed up after use. | ||
1016 | |||
1017 | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen) | ||
1018 | int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen) | ||
1019 | |||
1020 | Add a local key id or a friendlyname to a safebag. | ||
1021 | |||
1022 | 1.2 Authsafe functions. | ||
1023 | |||
1024 | PKCS7 *PKCS12_pack_p7data(STACK *sk) | ||
1025 | Take a stack of safebags and convert them into an unencrypted authsafe. The | ||
1026 | stack of safebags can be freed up after calling this function. | ||
1027 | |||
1028 | PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags); | ||
1029 | |||
1030 | As above but encrypted. | ||
1031 | |||
1032 | 1.3 PKCS12 functions. | ||
1033 | |||
1034 | PKCS12 *PKCS12_init(int mode) | ||
1035 | |||
1036 | Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data). | ||
1037 | |||
1038 | M_PKCS12_pack_authsafes(p12, safes) | ||
1039 | |||
1040 | This macro takes a STACK of authsafes and adds them to a PKCS#12 structure. | ||
1041 | |||
1042 | int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type); | ||
1043 | |||
1044 | Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests | ||
1045 | that SHA-1 should be used. | ||
1046 | |||
1047 | 2. Extraction Functions. | ||
1048 | |||
1049 | 2.1 Safebags. | ||
1050 | |||
1051 | M_PKCS12_bag_type(bag) | ||
1052 | |||
1053 | Return the type of "bag". Returns one of the following | ||
1054 | |||
1055 | NID_keyBag | ||
1056 | NID_pkcs8ShroudedKeyBag 7 | ||
1057 | NID_certBag 8 | ||
1058 | NID_crlBag 9 | ||
1059 | NID_secretBag 10 | ||
1060 | NID_safeContentsBag 11 | ||
1061 | |||
1062 | M_PKCS12_cert_bag_type(bag) | ||
1063 | |||
1064 | Returns type of certificate bag, following are understood. | ||
1065 | |||
1066 | NID_x509Certificate 14 | ||
1067 | NID_sdsiCertificate 15 | ||
1068 | |||
1069 | M_PKCS12_crl_bag_type(bag) | ||
1070 | |||
1071 | Returns crl bag type, currently only NID_crlBag is recognised. | ||
1072 | |||
1073 | M_PKCS12_certbag2x509(bag) | ||
1074 | |||
1075 | This macro extracts an X509 certificate from a certificate bag. | ||
1076 | |||
1077 | M_PKCS12_certbag2x509crl(bag) | ||
1078 | |||
1079 | As above but for a CRL. | ||
1080 | |||
1081 | EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) | ||
1082 | |||
1083 | Extract a private key from a PKCS8 private key info structure. | ||
1084 | |||
1085 | M_PKCS12_decrypt_skey(bag, pass, passlen) | ||
1086 | |||
1087 | Decrypt a shrouded key bag and return a PKCS8 private key info structure. | ||
1088 | Works with both RSA and DSA keys | ||
1089 | |||
1090 | char *PKCS12_get_friendlyname(bag) | ||
1091 | |||
1092 | Returns the friendlyName of a bag if present or NULL if none. The returned | ||
1093 | string is a null terminated ASCII string allocated with Malloc(). It should | ||
1094 | thus be freed up with Free() after use. | ||
1095 | |||
1096 | 2.2 AuthSafe functions. | ||
1097 | |||
1098 | M_PKCS12_unpack_p7data(p7) | ||
1099 | |||
1100 | Extract a STACK of safe bags from a PKCS#7 data ContentInfo. | ||
1101 | |||
1102 | #define M_PKCS12_unpack_p7encdata(p7, pass, passlen) | ||
1103 | |||
1104 | As above but for an encrypted content info. | ||
1105 | |||
1106 | 2.3 PKCS12 functions. | ||
1107 | |||
1108 | M_PKCS12_unpack_authsafes(p12) | ||
1109 | |||
1110 | Extract a STACK of authsafes from a PKCS12 structure. | ||
1111 | |||
1112 | M_PKCS12_mac_present(p12) | ||
1113 | |||
1114 | Check to see if a MAC is present. | ||
1115 | |||
1116 | int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen) | ||
1117 | |||
1118 | Verify a MAC on a PKCS12 structure. Returns an error if MAC not present. | ||
1119 | |||
1120 | |||
1121 | Notes. | ||
1122 | |||
1123 | 1. All the function return 0 or NULL on error. | ||
1124 | 2. Encryption based functions take a common set of parameters. These are | ||
1125 | described below. | ||
1126 | |||
1127 | pass, passlen | ||
1128 | ASCII password and length. The password on the MAC is called the "integrity | ||
1129 | password" the encryption password is called the "privacy password" in the | ||
1130 | PKCS#12 documentation. The passwords do not have to be the same. If -1 is | ||
1131 | passed for the length it is worked out by the function itself (currently | ||
1132 | this is sometimes done whatever is passed as the length but that may change). | ||
1133 | |||
1134 | salt, saltlen | ||
1135 | A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a | ||
1136 | default length is used. | ||
1137 | |||
1138 | iter | ||
1139 | Iteration count. This is a measure of how many times an internal function is | ||
1140 | called to encrypt the data. The larger this value is the longer it takes, it | ||
1141 | makes dictionary attacks on passwords harder. NOTE: Some implementations do | ||
1142 | not support an iteration count on the MAC. If the password for the MAC and | ||
1143 | encryption is the same then there is no point in having a high iteration | ||
1144 | count for encryption if the MAC has no count. The MAC could be attacked | ||
1145 | and the password used for the main decryption. | ||
1146 | |||
1147 | pbe_nid | ||
1148 | This is the NID of the password based encryption method used. The following are | ||
1149 | supported. | ||
1150 | NID_pbe_WithSHA1And128BitRC4 | ||
1151 | NID_pbe_WithSHA1And40BitRC4 | ||
1152 | NID_pbe_WithSHA1And3_Key_TripleDES_CBC | ||
1153 | NID_pbe_WithSHA1And2_Key_TripleDES_CBC | ||
1154 | NID_pbe_WithSHA1And128BitRC2_CBC | ||
1155 | NID_pbe_WithSHA1And40BitRC2_CBC | ||
1156 | |||
1157 | Which you use depends on the implementation you are exporting to. "Export | ||
1158 | grade" (i.e. cryptographically challenged) products cannot support all | ||
1159 | algorithms. Typically you may be able to use any encryption on shrouded key | ||
1160 | bags but they must then be placed in an unencrypted authsafe. Other authsafes | ||
1161 | may only support 40bit encryption. Of course if you are using SSLeay | ||
1162 | throughout you can strongly encrypt everything and have high iteration counts | ||
1163 | on everything. | ||
1164 | |||
1165 | 3. For decryption routines only the password and length are needed. | ||
1166 | |||
1167 | 4. Unlike the external version the nid's of objects are the values of the | ||
1168 | constants: that is NID_certBag is the real nid, therefore there is no | ||
1169 | PKCS12_obj_offset() function. Note the object constants are not the same as | ||
1170 | those of the external version. If you use these constants then you will need | ||
1171 | to recompile your code. | ||
1172 | |||
1173 | 5. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or | ||
1174 | macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be | ||
1175 | reused or freed up safely. | ||
1176 | |||
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c deleted file mode 100644 index aaedf6a9bb..0000000000 --- a/src/lib/libssl/s23_clnt.c +++ /dev/null | |||
@@ -1,473 +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 <openssl/buffer.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include "ssl_locl.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 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 | memcpy((char *)&SSLv23_client_data, | ||
91 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
92 | SSLv23_client_data.ssl_connect=ssl23_connect; | ||
93 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | ||
94 | init=0; | ||
95 | } | ||
96 | return(&SSLv23_client_data); | ||
97 | } | ||
98 | |||
99 | int ssl23_connect(SSL *s) | ||
100 | { | ||
101 | BUF_MEM *buf; | ||
102 | unsigned long Time=time(NULL); | ||
103 | void (*cb)()=NULL; | ||
104 | int ret= -1; | ||
105 | int new_state,state; | ||
106 | |||
107 | RAND_add(&Time,sizeof(Time),0); | ||
108 | ERR_clear_error(); | ||
109 | clear_sys_error(); | ||
110 | |||
111 | if (s->info_callback != NULL) | ||
112 | cb=s->info_callback; | ||
113 | else if (s->ctx->info_callback != NULL) | ||
114 | cb=s->ctx->info_callback; | ||
115 | |||
116 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
117 | s->in_handshake++; | ||
118 | |||
119 | for (;;) | ||
120 | { | ||
121 | state=s->state; | ||
122 | |||
123 | switch(s->state) | ||
124 | { | ||
125 | case SSL_ST_BEFORE: | ||
126 | case SSL_ST_CONNECT: | ||
127 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
128 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
129 | |||
130 | if (s->session != NULL) | ||
131 | { | ||
132 | SSLerr(SSL_F_SSL23_CONNECT,SSL_R_SSL23_DOING_SESSION_ID_REUSE); | ||
133 | ret= -1; | ||
134 | goto end; | ||
135 | } | ||
136 | s->server=0; | ||
137 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
138 | |||
139 | /* s->version=TLS1_VERSION; */ | ||
140 | s->type=SSL_ST_CONNECT; | ||
141 | |||
142 | if (s->init_buf == NULL) | ||
143 | { | ||
144 | if ((buf=BUF_MEM_new()) == NULL) | ||
145 | { | ||
146 | ret= -1; | ||
147 | goto end; | ||
148 | } | ||
149 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
150 | { | ||
151 | ret= -1; | ||
152 | goto end; | ||
153 | } | ||
154 | s->init_buf=buf; | ||
155 | } | ||
156 | |||
157 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
158 | |||
159 | ssl3_init_finished_mac(s); | ||
160 | |||
161 | s->state=SSL23_ST_CW_CLNT_HELLO_A; | ||
162 | s->ctx->stats.sess_connect++; | ||
163 | s->init_num=0; | ||
164 | break; | ||
165 | |||
166 | case SSL23_ST_CW_CLNT_HELLO_A: | ||
167 | case SSL23_ST_CW_CLNT_HELLO_B: | ||
168 | |||
169 | s->shutdown=0; | ||
170 | ret=ssl23_client_hello(s); | ||
171 | if (ret <= 0) goto end; | ||
172 | s->state=SSL23_ST_CR_SRVR_HELLO_A; | ||
173 | s->init_num=0; | ||
174 | |||
175 | break; | ||
176 | |||
177 | case SSL23_ST_CR_SRVR_HELLO_A: | ||
178 | case SSL23_ST_CR_SRVR_HELLO_B: | ||
179 | ret=ssl23_get_server_hello(s); | ||
180 | if (ret >= 0) cb=NULL; | ||
181 | goto end; | ||
182 | /* break; */ | ||
183 | |||
184 | default: | ||
185 | SSLerr(SSL_F_SSL23_CONNECT,SSL_R_UNKNOWN_STATE); | ||
186 | ret= -1; | ||
187 | goto end; | ||
188 | /* break; */ | ||
189 | } | ||
190 | |||
191 | if (s->debug) { (void)BIO_flush(s->wbio); } | ||
192 | |||
193 | if ((cb != NULL) && (s->state != state)) | ||
194 | { | ||
195 | new_state=s->state; | ||
196 | s->state=state; | ||
197 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
198 | s->state=new_state; | ||
199 | } | ||
200 | } | ||
201 | end: | ||
202 | s->in_handshake--; | ||
203 | if (cb != NULL) | ||
204 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
205 | return(ret); | ||
206 | } | ||
207 | |||
208 | |||
209 | static int ssl23_client_hello(SSL *s) | ||
210 | { | ||
211 | unsigned char *buf; | ||
212 | unsigned char *p,*d; | ||
213 | int i,ch_len; | ||
214 | |||
215 | buf=(unsigned char *)s->init_buf->data; | ||
216 | if (s->state == SSL23_ST_CW_CLNT_HELLO_A) | ||
217 | { | ||
218 | #if 0 | ||
219 | /* don't reuse session-id's */ | ||
220 | if (!ssl_get_new_session(s,0)) | ||
221 | { | ||
222 | return(-1); | ||
223 | } | ||
224 | #endif | ||
225 | |||
226 | p=s->s3->client_random; | ||
227 | RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE); | ||
228 | |||
229 | /* Do the message type and length last */ | ||
230 | d= &(buf[2]); | ||
231 | p=d+9; | ||
232 | |||
233 | *(d++)=SSL2_MT_CLIENT_HELLO; | ||
234 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
235 | { | ||
236 | *(d++)=TLS1_VERSION_MAJOR; | ||
237 | *(d++)=TLS1_VERSION_MINOR; | ||
238 | s->client_version=TLS1_VERSION; | ||
239 | } | ||
240 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
241 | { | ||
242 | *(d++)=SSL3_VERSION_MAJOR; | ||
243 | *(d++)=SSL3_VERSION_MINOR; | ||
244 | s->client_version=SSL3_VERSION; | ||
245 | } | ||
246 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
247 | { | ||
248 | *(d++)=SSL2_VERSION_MAJOR; | ||
249 | *(d++)=SSL2_VERSION_MINOR; | ||
250 | s->client_version=SSL2_VERSION; | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_PROTOCOLS_AVAILABLE); | ||
255 | return(-1); | ||
256 | } | ||
257 | |||
258 | /* Ciphers supported */ | ||
259 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),p); | ||
260 | if (i == 0) | ||
261 | { | ||
262 | /* no ciphers */ | ||
263 | SSLerr(SSL_F_SSL23_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
264 | return(-1); | ||
265 | } | ||
266 | s2n(i,d); | ||
267 | p+=i; | ||
268 | |||
269 | /* put in the session-id, zero since there is no | ||
270 | * reuse. */ | ||
271 | #if 0 | ||
272 | s->session->session_id_length=0; | ||
273 | #endif | ||
274 | s2n(0,d); | ||
275 | |||
276 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
277 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
278 | else | ||
279 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
280 | |||
281 | /* write out sslv2 challenge */ | ||
282 | if (SSL3_RANDOM_SIZE < ch_len) | ||
283 | i=SSL3_RANDOM_SIZE; | ||
284 | else | ||
285 | i=ch_len; | ||
286 | s2n(i,d); | ||
287 | memset(&(s->s3->client_random[0]),0,SSL3_RANDOM_SIZE); | ||
288 | RAND_pseudo_bytes(&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
289 | memcpy(p,&(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
290 | p+=i; | ||
291 | |||
292 | i= p- &(buf[2]); | ||
293 | buf[0]=((i>>8)&0xff)|0x80; | ||
294 | buf[1]=(i&0xff); | ||
295 | |||
296 | s->state=SSL23_ST_CW_CLNT_HELLO_B; | ||
297 | /* number of bytes to write */ | ||
298 | s->init_num=i+2; | ||
299 | s->init_off=0; | ||
300 | |||
301 | ssl3_finish_mac(s,&(buf[2]),i); | ||
302 | } | ||
303 | |||
304 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
305 | return(ssl23_write_bytes(s)); | ||
306 | } | ||
307 | |||
308 | static int ssl23_get_server_hello(SSL *s) | ||
309 | { | ||
310 | char buf[8]; | ||
311 | unsigned char *p; | ||
312 | int i; | ||
313 | int n; | ||
314 | |||
315 | n=ssl23_read_bytes(s,7); | ||
316 | |||
317 | if (n != 7) return(n); | ||
318 | p=s->packet; | ||
319 | |||
320 | memcpy(buf,p,n); | ||
321 | |||
322 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_SERVER_HELLO) && | ||
323 | (p[5] == 0x00) && (p[6] == 0x02)) | ||
324 | { | ||
325 | #ifdef NO_SSL2 | ||
326 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
327 | goto err; | ||
328 | #else | ||
329 | /* we are talking sslv2 */ | ||
330 | /* we need to clean up the SSLv3 setup and put in the | ||
331 | * sslv2 stuff. */ | ||
332 | int ch_len; | ||
333 | |||
334 | if (s->options & SSL_OP_NO_SSLv2) | ||
335 | { | ||
336 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
337 | goto err; | ||
338 | } | ||
339 | if (s->s2 == NULL) | ||
340 | { | ||
341 | if (!ssl2_new(s)) | ||
342 | goto err; | ||
343 | } | ||
344 | else | ||
345 | ssl2_clear(s); | ||
346 | |||
347 | if (s->options & SSL_OP_NETSCAPE_CHALLENGE_BUG) | ||
348 | ch_len=SSL2_CHALLENGE_LENGTH; | ||
349 | else | ||
350 | ch_len=SSL2_MAX_CHALLENGE_LENGTH; | ||
351 | |||
352 | /* write out sslv2 challenge */ | ||
353 | i=(SSL3_RANDOM_SIZE < ch_len) | ||
354 | ?SSL3_RANDOM_SIZE:ch_len; | ||
355 | s->s2->challenge_length=i; | ||
356 | memcpy(s->s2->challenge, | ||
357 | &(s->s3->client_random[SSL3_RANDOM_SIZE-i]),i); | ||
358 | |||
359 | if (s->s3 != NULL) ssl3_free(s); | ||
360 | |||
361 | if (!BUF_MEM_grow(s->init_buf, | ||
362 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
363 | { | ||
364 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB); | ||
365 | goto err; | ||
366 | } | ||
367 | |||
368 | s->state=SSL2_ST_GET_SERVER_HELLO_A; | ||
369 | s->s2->ssl2_rollback=1; | ||
370 | |||
371 | /* setup the 5 bytes we have read so we get them from | ||
372 | * the sslv2 buffer */ | ||
373 | s->rstate=SSL_ST_READ_HEADER; | ||
374 | s->packet_length=n; | ||
375 | s->packet= &(s->s2->rbuf[0]); | ||
376 | memcpy(s->packet,buf,n); | ||
377 | s->s2->rbuf_left=n; | ||
378 | s->s2->rbuf_offs=0; | ||
379 | |||
380 | /* we have already written one */ | ||
381 | s->s2->write_sequence=1; | ||
382 | |||
383 | s->method=SSLv2_client_method(); | ||
384 | s->handshake_func=s->method->ssl_connect; | ||
385 | #endif | ||
386 | } | ||
387 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
388 | (p[1] == SSL3_VERSION_MAJOR) && | ||
389 | ((p[2] == SSL3_VERSION_MINOR) || | ||
390 | (p[2] == TLS1_VERSION_MINOR)) && | ||
391 | (p[5] == SSL3_MT_SERVER_HELLO)) | ||
392 | { | ||
393 | /* we have sslv3 or tls1 */ | ||
394 | |||
395 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
396 | |||
397 | /* we are in this state */ | ||
398 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
399 | |||
400 | /* put the 5 bytes we have read into the input buffer | ||
401 | * for SSLv3 */ | ||
402 | s->rstate=SSL_ST_READ_HEADER; | ||
403 | s->packet_length=n; | ||
404 | s->packet= &(s->s3->rbuf.buf[0]); | ||
405 | memcpy(s->packet,buf,n); | ||
406 | s->s3->rbuf.left=n; | ||
407 | s->s3->rbuf.offset=0; | ||
408 | |||
409 | if ((p[2] == SSL3_VERSION_MINOR) && | ||
410 | !(s->options & SSL_OP_NO_SSLv3)) | ||
411 | { | ||
412 | s->version=SSL3_VERSION; | ||
413 | s->method=SSLv3_client_method(); | ||
414 | } | ||
415 | else if ((p[2] == TLS1_VERSION_MINOR) && | ||
416 | !(s->options & SSL_OP_NO_TLSv1)) | ||
417 | { | ||
418 | s->version=TLS1_VERSION; | ||
419 | s->method=TLSv1_client_method(); | ||
420 | } | ||
421 | else | ||
422 | { | ||
423 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
424 | goto err; | ||
425 | } | ||
426 | |||
427 | s->handshake_func=s->method->ssl_connect; | ||
428 | } | ||
429 | else if ((p[0] == SSL3_RT_ALERT) && | ||
430 | (p[1] == SSL3_VERSION_MAJOR) && | ||
431 | ((p[2] == SSL3_VERSION_MINOR) || | ||
432 | (p[2] == TLS1_VERSION_MINOR)) && | ||
433 | (p[3] == 0) && | ||
434 | (p[4] == 2)) | ||
435 | { | ||
436 | void (*cb)()=NULL; | ||
437 | int j; | ||
438 | |||
439 | /* An alert */ | ||
440 | if (s->info_callback != NULL) | ||
441 | cb=s->info_callback; | ||
442 | else if (s->ctx->info_callback != NULL) | ||
443 | cb=s->ctx->info_callback; | ||
444 | |||
445 | i=p[5]; | ||
446 | if (cb != NULL) | ||
447 | { | ||
448 | j=(i<<8)|p[6]; | ||
449 | cb(s,SSL_CB_READ_ALERT,j); | ||
450 | } | ||
451 | |||
452 | s->rwstate=SSL_NOTHING; | ||
453 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]); | ||
454 | goto err; | ||
455 | } | ||
456 | else | ||
457 | { | ||
458 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
459 | goto err; | ||
460 | } | ||
461 | s->init_num=0; | ||
462 | |||
463 | /* Since, if we are sending a ssl23 client hello, we are not | ||
464 | * reusing a session-id */ | ||
465 | if (!ssl_get_new_session(s,0)) | ||
466 | goto err; | ||
467 | |||
468 | s->first_packet=1; | ||
469 | return(SSL_connect(s)); | ||
470 | err: | ||
471 | return(-1); | ||
472 | } | ||
473 | |||
diff --git a/src/lib/libssl/s23_lib.c b/src/lib/libssl/s23_lib.c deleted file mode 100644 index dded7a19c5..0000000000 --- a/src/lib/libssl/s23_lib.c +++ /dev/null | |||
@@ -1,226 +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_write(SSL *s, const void *buf, int len); | ||
67 | static long ssl23_default_timeout(void ); | ||
68 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p); | ||
69 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p); | ||
70 | const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT; | ||
71 | |||
72 | static SSL_METHOD SSLv23_data= { | ||
73 | TLS1_VERSION, | ||
74 | tls1_new, | ||
75 | tls1_clear, | ||
76 | tls1_free, | ||
77 | ssl_undefined_function, | ||
78 | ssl_undefined_function, | ||
79 | ssl23_read, | ||
80 | (int (*)(struct ssl_st *, char *, int))ssl_undefined_function, | ||
81 | ssl23_write, | ||
82 | ssl_undefined_function, | ||
83 | ssl_undefined_function, | ||
84 | ssl_ok, | ||
85 | ssl3_ctrl, | ||
86 | ssl3_ctx_ctrl, | ||
87 | ssl23_get_cipher_by_char, | ||
88 | ssl23_put_cipher_by_char, | ||
89 | ssl_undefined_function, | ||
90 | ssl23_num_ciphers, | ||
91 | ssl23_get_cipher, | ||
92 | ssl_bad_method, | ||
93 | ssl23_default_timeout, | ||
94 | &ssl3_undef_enc_method, | ||
95 | ssl_undefined_function, | ||
96 | ssl3_callback_ctrl, | ||
97 | ssl3_ctx_callback_ctrl, | ||
98 | }; | ||
99 | |||
100 | static long ssl23_default_timeout(void) | ||
101 | { | ||
102 | return(300); | ||
103 | } | ||
104 | |||
105 | SSL_METHOD *sslv23_base_method(void) | ||
106 | { | ||
107 | return(&SSLv23_data); | ||
108 | } | ||
109 | |||
110 | static int ssl23_num_ciphers(void) | ||
111 | { | ||
112 | return(ssl3_num_ciphers() | ||
113 | #ifndef NO_SSL2 | ||
114 | + ssl2_num_ciphers() | ||
115 | #endif | ||
116 | ); | ||
117 | } | ||
118 | |||
119 | static SSL_CIPHER *ssl23_get_cipher(unsigned int u) | ||
120 | { | ||
121 | unsigned int uu=ssl3_num_ciphers(); | ||
122 | |||
123 | if (u < uu) | ||
124 | return(ssl3_get_cipher(u)); | ||
125 | else | ||
126 | #ifndef NO_SSL2 | ||
127 | return(ssl2_get_cipher(u-uu)); | ||
128 | #else | ||
129 | return(NULL); | ||
130 | #endif | ||
131 | } | ||
132 | |||
133 | /* This function needs to check if the ciphers required are actually | ||
134 | * available */ | ||
135 | static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p) | ||
136 | { | ||
137 | SSL_CIPHER c,*cp; | ||
138 | unsigned long id; | ||
139 | int n; | ||
140 | |||
141 | n=ssl3_num_ciphers(); | ||
142 | id=0x03000000|((unsigned long)p[0]<<16L)| | ||
143 | ((unsigned long)p[1]<<8L)|(unsigned long)p[2]; | ||
144 | c.id=id; | ||
145 | cp=ssl3_get_cipher_by_char(p); | ||
146 | #ifndef NO_SSL2 | ||
147 | if (cp == NULL) | ||
148 | cp=ssl2_get_cipher_by_char(p); | ||
149 | #endif | ||
150 | return(cp); | ||
151 | } | ||
152 | |||
153 | static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | ||
154 | { | ||
155 | long l; | ||
156 | |||
157 | /* We can write SSLv2 and SSLv3 ciphers */ | ||
158 | if (p != NULL) | ||
159 | { | ||
160 | l=c->id; | ||
161 | p[0]=((unsigned char)(l>>16L))&0xFF; | ||
162 | p[1]=((unsigned char)(l>> 8L))&0xFF; | ||
163 | p[2]=((unsigned char)(l ))&0xFF; | ||
164 | } | ||
165 | return(3); | ||
166 | } | ||
167 | |||
168 | static int ssl23_read(SSL *s, void *buf, int len) | ||
169 | { | ||
170 | int n; | ||
171 | |||
172 | #if 0 | ||
173 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
174 | { | ||
175 | s->rwstate=SSL_NOTHING; | ||
176 | return(0); | ||
177 | } | ||
178 | #endif | ||
179 | clear_sys_error(); | ||
180 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
181 | { | ||
182 | n=s->handshake_func(s); | ||
183 | if (n < 0) return(n); | ||
184 | if (n == 0) | ||
185 | { | ||
186 | SSLerr(SSL_F_SSL23_READ,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
187 | return(-1); | ||
188 | } | ||
189 | return(SSL_read(s,buf,len)); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | ssl_undefined_function(s); | ||
194 | return(-1); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | static int ssl23_write(SSL *s, const void *buf, int len) | ||
199 | { | ||
200 | int n; | ||
201 | |||
202 | #if 0 | ||
203 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
204 | { | ||
205 | s->rwstate=SSL_NOTHING; | ||
206 | return(0); | ||
207 | } | ||
208 | #endif | ||
209 | clear_sys_error(); | ||
210 | if (SSL_in_init(s) && (!s->in_handshake)) | ||
211 | { | ||
212 | n=s->handshake_func(s); | ||
213 | if (n < 0) return(n); | ||
214 | if (n == 0) | ||
215 | { | ||
216 | SSLerr(SSL_F_SSL23_WRITE,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
217 | return(-1); | ||
218 | } | ||
219 | return(SSL_write(s,buf,len)); | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | ssl_undefined_function(s); | ||
224 | return(-1); | ||
225 | } | ||
226 | } | ||
diff --git a/src/lib/libssl/s23_pkt.c b/src/lib/libssl/s23_pkt.c deleted file mode 100644 index f45e1ce3d8..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 <openssl/evp.h> | ||
63 | #include <openssl/buffer.h> | ||
64 | #include "ssl_locl.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 6a3bbb10b9..0000000000 --- a/src/lib/libssl/s23_srvr.c +++ /dev/null | |||
@@ -1,568 +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 | #include <stdio.h> | ||
60 | #include <openssl/buffer.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include "ssl_locl.h" | ||
65 | |||
66 | static SSL_METHOD *ssl23_get_server_method(int ver); | ||
67 | int ssl23_get_client_hello(SSL *s); | ||
68 | static SSL_METHOD *ssl23_get_server_method(int ver) | ||
69 | { | ||
70 | #ifndef NO_SSL2 | ||
71 | if (ver == SSL2_VERSION) | ||
72 | return(SSLv2_server_method()); | ||
73 | #endif | ||
74 | if (ver == SSL3_VERSION) | ||
75 | return(SSLv3_server_method()); | ||
76 | else if (ver == TLS1_VERSION) | ||
77 | return(TLSv1_server_method()); | ||
78 | else | ||
79 | return(NULL); | ||
80 | } | ||
81 | |||
82 | SSL_METHOD *SSLv23_server_method(void) | ||
83 | { | ||
84 | static int init=1; | ||
85 | static SSL_METHOD SSLv23_server_data; | ||
86 | |||
87 | if (init) | ||
88 | { | ||
89 | memcpy((char *)&SSLv23_server_data, | ||
90 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
91 | SSLv23_server_data.ssl_accept=ssl23_accept; | ||
92 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | ||
93 | init=0; | ||
94 | } | ||
95 | return(&SSLv23_server_data); | ||
96 | } | ||
97 | |||
98 | int ssl23_accept(SSL *s) | ||
99 | { | ||
100 | BUF_MEM *buf; | ||
101 | unsigned long Time=time(NULL); | ||
102 | void (*cb)()=NULL; | ||
103 | int ret= -1; | ||
104 | int new_state,state; | ||
105 | |||
106 | RAND_add(&Time,sizeof(Time),0); | ||
107 | ERR_clear_error(); | ||
108 | clear_sys_error(); | ||
109 | |||
110 | if (s->info_callback != NULL) | ||
111 | cb=s->info_callback; | ||
112 | else if (s->ctx->info_callback != NULL) | ||
113 | cb=s->ctx->info_callback; | ||
114 | |||
115 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
116 | s->in_handshake++; | ||
117 | |||
118 | for (;;) | ||
119 | { | ||
120 | state=s->state; | ||
121 | |||
122 | switch(s->state) | ||
123 | { | ||
124 | case SSL_ST_BEFORE: | ||
125 | case SSL_ST_ACCEPT: | ||
126 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
127 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
128 | |||
129 | s->server=1; | ||
130 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
131 | |||
132 | /* s->version=SSL3_VERSION; */ | ||
133 | s->type=SSL_ST_ACCEPT; | ||
134 | |||
135 | if (s->init_buf == NULL) | ||
136 | { | ||
137 | if ((buf=BUF_MEM_new()) == NULL) | ||
138 | { | ||
139 | ret= -1; | ||
140 | goto end; | ||
141 | } | ||
142 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
143 | { | ||
144 | ret= -1; | ||
145 | goto end; | ||
146 | } | ||
147 | s->init_buf=buf; | ||
148 | } | ||
149 | |||
150 | ssl3_init_finished_mac(s); | ||
151 | |||
152 | s->state=SSL23_ST_SR_CLNT_HELLO_A; | ||
153 | s->ctx->stats.sess_accept++; | ||
154 | s->init_num=0; | ||
155 | break; | ||
156 | |||
157 | case SSL23_ST_SR_CLNT_HELLO_A: | ||
158 | case SSL23_ST_SR_CLNT_HELLO_B: | ||
159 | |||
160 | s->shutdown=0; | ||
161 | ret=ssl23_get_client_hello(s); | ||
162 | if (ret >= 0) cb=NULL; | ||
163 | goto end; | ||
164 | /* break; */ | ||
165 | |||
166 | default: | ||
167 | SSLerr(SSL_F_SSL23_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
168 | ret= -1; | ||
169 | goto end; | ||
170 | /* break; */ | ||
171 | } | ||
172 | |||
173 | if ((cb != NULL) && (s->state != state)) | ||
174 | { | ||
175 | new_state=s->state; | ||
176 | s->state=state; | ||
177 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
178 | s->state=new_state; | ||
179 | } | ||
180 | } | ||
181 | end: | ||
182 | if (cb != NULL) | ||
183 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
184 | s->in_handshake--; | ||
185 | return(ret); | ||
186 | } | ||
187 | |||
188 | |||
189 | int ssl23_get_client_hello(SSL *s) | ||
190 | { | ||
191 | char buf_space[11]; /* Request this many bytes in initial read. | ||
192 | * We can detect SSL 3.0/TLS 1.0 Client Hellos | ||
193 | * ('type == 3') correctly only when the following | ||
194 | * is in a single record, which is not guaranteed by | ||
195 | * the protocol specification: | ||
196 | * Byte Content | ||
197 | * 0 type \ | ||
198 | * 1/2 version > record header | ||
199 | * 3/4 length / | ||
200 | * 5 msg_type \ | ||
201 | * 6-8 length > Client Hello message | ||
202 | * 9/10 client_version / | ||
203 | */ | ||
204 | char *buf= &(buf_space[0]); | ||
205 | unsigned char *p,*d,*dd; | ||
206 | unsigned int i; | ||
207 | unsigned int csl,sil,cl; | ||
208 | int n=0,j; | ||
209 | int type=0; | ||
210 | int v[2]; | ||
211 | #ifndef NO_RSA | ||
212 | int use_sslv2_strong=0; | ||
213 | #endif | ||
214 | |||
215 | if (s->state == SSL23_ST_SR_CLNT_HELLO_A) | ||
216 | { | ||
217 | /* read the initial header */ | ||
218 | v[0]=v[1]=0; | ||
219 | |||
220 | if (!ssl3_setup_buffers(s)) goto err; | ||
221 | |||
222 | n=ssl23_read_bytes(s, sizeof buf_space); | ||
223 | if (n != sizeof buf_space) return(n); /* n == -1 || n == 0 */ | ||
224 | |||
225 | p=s->packet; | ||
226 | |||
227 | memcpy(buf,p,n); | ||
228 | |||
229 | if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) | ||
230 | { | ||
231 | /* | ||
232 | * SSLv2 header | ||
233 | */ | ||
234 | if ((p[3] == 0x00) && (p[4] == 0x02)) | ||
235 | { | ||
236 | v[0]=p[3]; v[1]=p[4]; | ||
237 | /* SSLv2 */ | ||
238 | if (!(s->options & SSL_OP_NO_SSLv2)) | ||
239 | type=1; | ||
240 | } | ||
241 | else if (p[3] == SSL3_VERSION_MAJOR) | ||
242 | { | ||
243 | v[0]=p[3]; v[1]=p[4]; | ||
244 | /* SSLv3/TLSv1 */ | ||
245 | if (p[4] >= TLS1_VERSION_MINOR) | ||
246 | { | ||
247 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
248 | { | ||
249 | s->version=TLS1_VERSION; | ||
250 | /* type=2; */ /* done later to survive restarts */ | ||
251 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
252 | } | ||
253 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
254 | { | ||
255 | s->version=SSL3_VERSION; | ||
256 | /* type=2; */ | ||
257 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
258 | } | ||
259 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
260 | { | ||
261 | type=1; | ||
262 | } | ||
263 | } | ||
264 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
265 | { | ||
266 | s->version=SSL3_VERSION; | ||
267 | /* type=2; */ | ||
268 | s->state=SSL23_ST_SR_CLNT_HELLO_B; | ||
269 | } | ||
270 | else if (!(s->options & SSL_OP_NO_SSLv2)) | ||
271 | type=1; | ||
272 | |||
273 | if (s->options & SSL_OP_NON_EXPORT_FIRST) | ||
274 | /* Not only utterly confusing, but broken | ||
275 | * ('fractured programming'?) -- the details | ||
276 | * of this block nearly make it work | ||
277 | * as intended in this environment, but on one | ||
278 | * of the fine points (w.r.t. restarts) it fails. | ||
279 | * The obvious fix would be even more devastating | ||
280 | * to program structure; if you want the functionality, | ||
281 | * throw this away and implement it in a way | ||
282 | * that makes sense */ | ||
283 | { | ||
284 | #if 0 | ||
285 | STACK_OF(SSL_CIPHER) *sk; | ||
286 | SSL_CIPHER *c; | ||
287 | int ne2,ne3; | ||
288 | |||
289 | j=((p[0]&0x7f)<<8)|p[1]; | ||
290 | if (j > (1024*4)) | ||
291 | { | ||
292 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE); | ||
293 | goto err; | ||
294 | } | ||
295 | |||
296 | n=ssl23_read_bytes(s,j+2); | ||
297 | if (n <= 0) return(n); | ||
298 | p=s->packet; | ||
299 | |||
300 | if ((buf=Malloc(n)) == NULL) | ||
301 | { | ||
302 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,ERR_R_MALLOC_FAILURE); | ||
303 | goto err; | ||
304 | } | ||
305 | memcpy(buf,p,n); | ||
306 | |||
307 | p+=5; | ||
308 | n2s(p,csl); | ||
309 | p+=4; | ||
310 | |||
311 | sk=ssl_bytes_to_cipher_list( | ||
312 | s,p,csl,NULL); | ||
313 | if (sk != NULL) | ||
314 | { | ||
315 | ne2=ne3=0; | ||
316 | for (j=0; j<sk_SSL_CIPHER_num(sk); j++) | ||
317 | { | ||
318 | c=sk_SSL_CIPHER_value(sk,j); | ||
319 | if (!SSL_C_IS_EXPORT(c)) | ||
320 | { | ||
321 | if ((c->id>>24L) == 2L) | ||
322 | ne2=1; | ||
323 | else | ||
324 | ne3=1; | ||
325 | } | ||
326 | } | ||
327 | if (ne2 && !ne3) | ||
328 | { | ||
329 | type=1; | ||
330 | use_sslv2_strong=1; | ||
331 | goto next_bit; | ||
332 | } | ||
333 | } | ||
334 | #else | ||
335 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_OPTION); | ||
336 | goto err; | ||
337 | #endif | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | else if ((p[0] == SSL3_RT_HANDSHAKE) && | ||
342 | (p[1] == SSL3_VERSION_MAJOR) && | ||
343 | (p[5] == SSL3_MT_CLIENT_HELLO) && | ||
344 | ((p[3] == 0 && p[4] < 5 /* silly record length? */) | ||
345 | || (p[9] == p[1]))) | ||
346 | { | ||
347 | /* | ||
348 | * SSLv3 or tls1 header | ||
349 | */ | ||
350 | |||
351 | v[0]=p[1]; /* major version */ | ||
352 | /* We must look at client_version inside the Client Hello message | ||
353 | * to get the correct minor version: */ | ||
354 | v[1]=p[10]; | ||
355 | /* However if we have only a pathologically small fragment of the | ||
356 | * Client Hello message, we simply use the version from the | ||
357 | * record header -- this is incorrect but unlikely to fail in | ||
358 | * practice */ | ||
359 | if (p[3] == 0 && p[4] < 6) | ||
360 | v[1]=p[2]; | ||
361 | if (v[1] >= TLS1_VERSION_MINOR) | ||
362 | { | ||
363 | if (!(s->options & SSL_OP_NO_TLSv1)) | ||
364 | { | ||
365 | s->version=TLS1_VERSION; | ||
366 | type=3; | ||
367 | } | ||
368 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
369 | { | ||
370 | s->version=SSL3_VERSION; | ||
371 | type=3; | ||
372 | } | ||
373 | } | ||
374 | else if (!(s->options & SSL_OP_NO_SSLv3)) | ||
375 | { | ||
376 | s->version=SSL3_VERSION; | ||
377 | type=3; | ||
378 | } | ||
379 | } | ||
380 | else if ((strncmp("GET ", (char *)p,4) == 0) || | ||
381 | (strncmp("POST ",(char *)p,5) == 0) || | ||
382 | (strncmp("HEAD ",(char *)p,5) == 0) || | ||
383 | (strncmp("PUT ", (char *)p,4) == 0)) | ||
384 | { | ||
385 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST); | ||
386 | goto err; | ||
387 | } | ||
388 | else if (strncmp("CONNECT",(char *)p,7) == 0) | ||
389 | { | ||
390 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST); | ||
391 | goto err; | ||
392 | } | ||
393 | } | ||
394 | |||
395 | if (s->state == SSL23_ST_SR_CLNT_HELLO_B) | ||
396 | { | ||
397 | /* we have SSLv3/TLSv1 in an SSLv2 header | ||
398 | * (other cases skip this state) */ | ||
399 | |||
400 | type=2; | ||
401 | p=s->packet; | ||
402 | v[0] = p[3]; /* == SSL3_VERSION_MAJOR */ | ||
403 | v[1] = p[4]; | ||
404 | |||
405 | n=((p[0]&0x7f)<<8)|p[1]; | ||
406 | if (n > (1024*4)) | ||
407 | { | ||
408 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE); | ||
409 | goto err; | ||
410 | } | ||
411 | |||
412 | j=ssl23_read_bytes(s,n+2); | ||
413 | if (j <= 0) return(j); | ||
414 | |||
415 | ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2); | ||
416 | |||
417 | p=s->packet; | ||
418 | p+=5; | ||
419 | n2s(p,csl); | ||
420 | n2s(p,sil); | ||
421 | n2s(p,cl); | ||
422 | d=(unsigned char *)s->init_buf->data; | ||
423 | if ((csl+sil+cl+11) != s->packet_length) | ||
424 | { | ||
425 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH); | ||
426 | goto err; | ||
427 | } | ||
428 | |||
429 | *(d++) = SSL3_VERSION_MAJOR; /* == v[0] */ | ||
430 | *(d++) = v[1]; | ||
431 | |||
432 | /* lets populate the random area */ | ||
433 | /* get the challenge_length */ | ||
434 | i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl; | ||
435 | memset(d,0,SSL3_RANDOM_SIZE); | ||
436 | memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i); | ||
437 | d+=SSL3_RANDOM_SIZE; | ||
438 | |||
439 | /* no session-id reuse */ | ||
440 | *(d++)=0; | ||
441 | |||
442 | /* ciphers */ | ||
443 | j=0; | ||
444 | dd=d; | ||
445 | d+=2; | ||
446 | for (i=0; i<csl; i+=3) | ||
447 | { | ||
448 | if (p[i] != 0) continue; | ||
449 | *(d++)=p[i+1]; | ||
450 | *(d++)=p[i+2]; | ||
451 | j+=2; | ||
452 | } | ||
453 | s2n(j,dd); | ||
454 | |||
455 | /* COMPRESSION */ | ||
456 | *(d++)=1; | ||
457 | *(d++)=0; | ||
458 | |||
459 | i=(d-(unsigned char *)s->init_buf->data); | ||
460 | |||
461 | /* get the data reused from the init_buf */ | ||
462 | s->s3->tmp.reuse_message=1; | ||
463 | s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO; | ||
464 | s->s3->tmp.message_size=i; | ||
465 | } | ||
466 | |||
467 | /* imaginary new state (for program structure): */ | ||
468 | /* s->state = SSL23_SR_CLNT_HELLO_C */ | ||
469 | |||
470 | if (type == 1) | ||
471 | { | ||
472 | #ifdef NO_SSL2 | ||
473 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL); | ||
474 | goto err; | ||
475 | #else | ||
476 | /* we are talking sslv2 */ | ||
477 | /* we need to clean up the SSLv3/TLSv1 setup and put in the | ||
478 | * sslv2 stuff. */ | ||
479 | |||
480 | if (s->s2 == NULL) | ||
481 | { | ||
482 | if (!ssl2_new(s)) | ||
483 | goto err; | ||
484 | } | ||
485 | else | ||
486 | ssl2_clear(s); | ||
487 | |||
488 | if (s->s3 != NULL) ssl3_free(s); | ||
489 | |||
490 | if (!BUF_MEM_grow(s->init_buf, | ||
491 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | ||
492 | { | ||
493 | goto err; | ||
494 | } | ||
495 | |||
496 | s->state=SSL2_ST_GET_CLIENT_HELLO_A; | ||
497 | if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) || | ||
498 | use_sslv2_strong) | ||
499 | s->s2->ssl2_rollback=0; | ||
500 | else | ||
501 | s->s2->ssl2_rollback=1; | ||
502 | |||
503 | /* setup the n bytes we have read so we get them from | ||
504 | * the sslv2 buffer */ | ||
505 | s->rstate=SSL_ST_READ_HEADER; | ||
506 | s->packet_length=n; | ||
507 | s->packet= &(s->s2->rbuf[0]); | ||
508 | memcpy(s->packet,buf,n); | ||
509 | s->s2->rbuf_left=n; | ||
510 | s->s2->rbuf_offs=0; | ||
511 | |||
512 | s->method=SSLv2_server_method(); | ||
513 | s->handshake_func=s->method->ssl_accept; | ||
514 | #endif | ||
515 | } | ||
516 | |||
517 | if ((type == 2) || (type == 3)) | ||
518 | { | ||
519 | /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */ | ||
520 | |||
521 | if (!ssl_init_wbio_buffer(s,1)) goto err; | ||
522 | |||
523 | /* we are in this state */ | ||
524 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
525 | |||
526 | if (type == 3) | ||
527 | { | ||
528 | /* put the 'n' bytes we have read into the input buffer | ||
529 | * for SSLv3 */ | ||
530 | s->rstate=SSL_ST_READ_HEADER; | ||
531 | s->packet_length=n; | ||
532 | s->packet= &(s->s3->rbuf.buf[0]); | ||
533 | memcpy(s->packet,buf,n); | ||
534 | s->s3->rbuf.left=n; | ||
535 | s->s3->rbuf.offset=0; | ||
536 | } | ||
537 | else | ||
538 | { | ||
539 | s->packet_length=0; | ||
540 | s->s3->rbuf.left=0; | ||
541 | s->s3->rbuf.offset=0; | ||
542 | } | ||
543 | |||
544 | if (s->version == TLS1_VERSION) | ||
545 | s->method = TLSv1_server_method(); | ||
546 | else | ||
547 | s->method = SSLv3_server_method(); | ||
548 | #if 0 /* ssl3_get_client_hello does this */ | ||
549 | s->client_version=(v[0]<<8)|v[1]; | ||
550 | #endif | ||
551 | s->handshake_func=s->method->ssl_accept; | ||
552 | } | ||
553 | |||
554 | if ((type < 1) || (type > 3)) | ||
555 | { | ||
556 | /* bad, very bad */ | ||
557 | SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL); | ||
558 | goto err; | ||
559 | } | ||
560 | s->init_num=0; | ||
561 | |||
562 | if (buf != buf_space) Free(buf); | ||
563 | s->first_packet=1; | ||
564 | return(SSL_accept(s)); | ||
565 | err: | ||
566 | if (buf != buf_space) Free(buf); | ||
567 | return(-1); | ||
568 | } | ||
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c deleted file mode 100644 index 03e0c38770..0000000000 --- a/src/lib/libssl/s3_both.c +++ /dev/null | |||
@@ -1,588 +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-2000 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 <string.h> | ||
113 | #include <stdio.h> | ||
114 | #include <openssl/buffer.h> | ||
115 | #include <openssl/rand.h> | ||
116 | #include <openssl/objects.h> | ||
117 | #include <openssl/evp.h> | ||
118 | #include <openssl/x509.h> | ||
119 | #include "ssl_locl.h" | ||
120 | |||
121 | /* send s->init_buf in records of type 'type' */ | ||
122 | int ssl3_do_write(SSL *s, int type) | ||
123 | { | ||
124 | int ret; | ||
125 | |||
126 | ret=ssl3_write_bytes(s,type,&s->init_buf->data[s->init_off], | ||
127 | s->init_num); | ||
128 | if (ret < 0) return(-1); | ||
129 | if (type == SSL3_RT_HANDSHAKE) | ||
130 | /* should not be done for 'Hello Request's, but in that case | ||
131 | * we'll ignore the result anyway */ | ||
132 | ssl3_finish_mac(s,(unsigned char *)&s->init_buf->data[s->init_off],ret); | ||
133 | |||
134 | if (ret == s->init_num) | ||
135 | return(1); | ||
136 | s->init_off+=ret; | ||
137 | s->init_num-=ret; | ||
138 | return(0); | ||
139 | } | ||
140 | |||
141 | int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen) | ||
142 | { | ||
143 | unsigned char *p,*d; | ||
144 | int i; | ||
145 | unsigned long l; | ||
146 | |||
147 | if (s->state == a) | ||
148 | { | ||
149 | d=(unsigned char *)s->init_buf->data; | ||
150 | p= &(d[4]); | ||
151 | |||
152 | i=s->method->ssl3_enc->final_finish_mac(s, | ||
153 | &(s->s3->finish_dgst1), | ||
154 | &(s->s3->finish_dgst2), | ||
155 | sender,slen,s->s3->tmp.finish_md); | ||
156 | s->s3->tmp.finish_md_len = i; | ||
157 | memcpy(p, s->s3->tmp.finish_md, i); | ||
158 | p+=i; | ||
159 | l=i; | ||
160 | |||
161 | #ifdef WIN16 | ||
162 | /* MSVC 1.5 does not clear the top bytes of the word unless | ||
163 | * I do this. | ||
164 | */ | ||
165 | l&=0xffff; | ||
166 | #endif | ||
167 | |||
168 | *(d++)=SSL3_MT_FINISHED; | ||
169 | l2n3(l,d); | ||
170 | s->init_num=(int)l+4; | ||
171 | s->init_off=0; | ||
172 | |||
173 | s->state=b; | ||
174 | } | ||
175 | |||
176 | /* SSL3_ST_SEND_xxxxxx_HELLO_B */ | ||
177 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
178 | } | ||
179 | |||
180 | int ssl3_get_finished(SSL *s, int a, int b) | ||
181 | { | ||
182 | int al,i,ok; | ||
183 | long n; | ||
184 | unsigned char *p; | ||
185 | |||
186 | /* the mac has already been generated when we received the | ||
187 | * change cipher spec message and is in s->s3->tmp.peer_finish_md | ||
188 | */ | ||
189 | |||
190 | n=ssl3_get_message(s, | ||
191 | a, | ||
192 | b, | ||
193 | SSL3_MT_FINISHED, | ||
194 | 64, /* should actually be 36+4 :-) */ | ||
195 | &ok); | ||
196 | |||
197 | if (!ok) return((int)n); | ||
198 | |||
199 | /* If this occurs, we have missed a message */ | ||
200 | if (!s->s3->change_cipher_spec) | ||
201 | { | ||
202 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
203 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS); | ||
204 | goto f_err; | ||
205 | } | ||
206 | s->s3->change_cipher_spec=0; | ||
207 | |||
208 | p = (unsigned char *)s->init_buf->data; | ||
209 | i = s->s3->tmp.peer_finish_md_len; | ||
210 | |||
211 | if (i != n) | ||
212 | { | ||
213 | al=SSL_AD_DECODE_ERROR; | ||
214 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH); | ||
215 | goto f_err; | ||
216 | } | ||
217 | |||
218 | if (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0) | ||
219 | { | ||
220 | al=SSL_AD_DECRYPT_ERROR; | ||
221 | SSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED); | ||
222 | goto f_err; | ||
223 | } | ||
224 | |||
225 | return(1); | ||
226 | f_err: | ||
227 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
228 | return(0); | ||
229 | } | ||
230 | |||
231 | /* for these 2 messages, we need to | ||
232 | * ssl->enc_read_ctx re-init | ||
233 | * ssl->s3->read_sequence zero | ||
234 | * ssl->s3->read_mac_secret re-init | ||
235 | * ssl->session->read_sym_enc assign | ||
236 | * ssl->session->read_compression assign | ||
237 | * ssl->session->read_hash assign | ||
238 | */ | ||
239 | int ssl3_send_change_cipher_spec(SSL *s, int a, int b) | ||
240 | { | ||
241 | unsigned char *p; | ||
242 | |||
243 | if (s->state == a) | ||
244 | { | ||
245 | p=(unsigned char *)s->init_buf->data; | ||
246 | *p=SSL3_MT_CCS; | ||
247 | s->init_num=1; | ||
248 | s->init_off=0; | ||
249 | |||
250 | s->state=b; | ||
251 | } | ||
252 | |||
253 | /* SSL3_ST_CW_CHANGE_B */ | ||
254 | return(ssl3_do_write(s,SSL3_RT_CHANGE_CIPHER_SPEC)); | ||
255 | } | ||
256 | |||
257 | unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | ||
258 | { | ||
259 | unsigned char *p; | ||
260 | int n,i; | ||
261 | unsigned long l=7; | ||
262 | BUF_MEM *buf; | ||
263 | X509_STORE_CTX xs_ctx; | ||
264 | X509_OBJECT obj; | ||
265 | |||
266 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ | ||
267 | buf=s->init_buf; | ||
268 | if (!BUF_MEM_grow(buf,(int)(10))) | ||
269 | { | ||
270 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
271 | return(0); | ||
272 | } | ||
273 | if (x != NULL) | ||
274 | { | ||
275 | X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL); | ||
276 | |||
277 | for (;;) | ||
278 | { | ||
279 | n=i2d_X509(x,NULL); | ||
280 | if (!BUF_MEM_grow(buf,(int)(n+l+3))) | ||
281 | { | ||
282 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
283 | return(0); | ||
284 | } | ||
285 | p=(unsigned char *)&(buf->data[l]); | ||
286 | l2n3(n,p); | ||
287 | i2d_X509(x,&p); | ||
288 | l+=n+3; | ||
289 | if (X509_NAME_cmp(X509_get_subject_name(x), | ||
290 | X509_get_issuer_name(x)) == 0) break; | ||
291 | |||
292 | i=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509, | ||
293 | X509_get_issuer_name(x),&obj); | ||
294 | if (i <= 0) break; | ||
295 | x=obj.data.x509; | ||
296 | /* Count is one too high since the X509_STORE_get uped the | ||
297 | * ref count */ | ||
298 | X509_free(x); | ||
299 | } | ||
300 | |||
301 | X509_STORE_CTX_cleanup(&xs_ctx); | ||
302 | } | ||
303 | |||
304 | /* Thawte special :-) */ | ||
305 | if (s->ctx->extra_certs != NULL) | ||
306 | for (i=0; i<sk_X509_num(s->ctx->extra_certs); i++) | ||
307 | { | ||
308 | x=sk_X509_value(s->ctx->extra_certs,i); | ||
309 | n=i2d_X509(x,NULL); | ||
310 | if (!BUF_MEM_grow(buf,(int)(n+l+3))) | ||
311 | { | ||
312 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | ||
313 | return(0); | ||
314 | } | ||
315 | p=(unsigned char *)&(buf->data[l]); | ||
316 | l2n3(n,p); | ||
317 | i2d_X509(x,&p); | ||
318 | l+=n+3; | ||
319 | } | ||
320 | |||
321 | l-=7; | ||
322 | p=(unsigned char *)&(buf->data[4]); | ||
323 | l2n3(l,p); | ||
324 | l+=3; | ||
325 | p=(unsigned char *)&(buf->data[0]); | ||
326 | *(p++)=SSL3_MT_CERTIFICATE; | ||
327 | l2n3(l,p); | ||
328 | l+=4; | ||
329 | return(l); | ||
330 | } | ||
331 | |||
332 | /* Obtain handshake message of message type 'mt' (any if mt == -1), | ||
333 | * maximum acceptable body length 'max'. | ||
334 | * The first four bytes (msg_type and length) are read in state 'st1', | ||
335 | * the body is read in state 'stn'. | ||
336 | */ | ||
337 | long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | ||
338 | { | ||
339 | unsigned char *p; | ||
340 | unsigned long l; | ||
341 | long n; | ||
342 | int i,al; | ||
343 | |||
344 | if (s->s3->tmp.reuse_message) | ||
345 | { | ||
346 | s->s3->tmp.reuse_message=0; | ||
347 | if ((mt >= 0) && (s->s3->tmp.message_type != mt)) | ||
348 | { | ||
349 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
350 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
351 | goto f_err; | ||
352 | } | ||
353 | *ok=1; | ||
354 | return((int)s->s3->tmp.message_size); | ||
355 | } | ||
356 | |||
357 | p=(unsigned char *)s->init_buf->data; | ||
358 | |||
359 | if (s->state == st1) /* s->init_num < 4 */ | ||
360 | { | ||
361 | int skip_message; | ||
362 | |||
363 | do | ||
364 | { | ||
365 | while (s->init_num < 4) | ||
366 | { | ||
367 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num], | ||
368 | 4 - s->init_num); | ||
369 | if (i <= 0) | ||
370 | { | ||
371 | s->rwstate=SSL_READING; | ||
372 | *ok = 0; | ||
373 | return i; | ||
374 | } | ||
375 | s->init_num+=i; | ||
376 | } | ||
377 | |||
378 | skip_message = 0; | ||
379 | if (!s->server) | ||
380 | if (p[0] == SSL3_MT_HELLO_REQUEST) | ||
381 | /* The server may always send 'Hello Request' messages -- | ||
382 | * we are doing a handshake anyway now, so ignore them | ||
383 | * if their format is correct. Does not count for | ||
384 | * 'Finished' MAC. */ | ||
385 | if (p[1] == 0 && p[2] == 0 &&p[3] == 0) | ||
386 | skip_message = 1; | ||
387 | } | ||
388 | while (skip_message); | ||
389 | |||
390 | /* s->init_num == 4 */ | ||
391 | |||
392 | if ((mt >= 0) && (*p != mt)) | ||
393 | { | ||
394 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
395 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE); | ||
396 | goto f_err; | ||
397 | } | ||
398 | if ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) && | ||
399 | (st1 == SSL3_ST_SR_CERT_A) && | ||
400 | (stn == SSL3_ST_SR_CERT_B)) | ||
401 | { | ||
402 | /* At this point we have got an MS SGC second client | ||
403 | * hello (maybe we should always allow the client to | ||
404 | * start a new handshake?). We need to restart the mac. | ||
405 | * Don't increment {num,total}_renegotiations because | ||
406 | * we have not completed the handshake. */ | ||
407 | ssl3_init_finished_mac(s); | ||
408 | } | ||
409 | |||
410 | ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, 4); | ||
411 | |||
412 | s->s3->tmp.message_type= *(p++); | ||
413 | |||
414 | n2l3(p,l); | ||
415 | if (l > (unsigned long)max) | ||
416 | { | ||
417 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
418 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); | ||
419 | goto f_err; | ||
420 | } | ||
421 | if (l && !BUF_MEM_grow(s->init_buf,(int)l)) | ||
422 | { | ||
423 | SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); | ||
424 | goto err; | ||
425 | } | ||
426 | s->s3->tmp.message_size=l; | ||
427 | s->state=stn; | ||
428 | |||
429 | s->init_num=0; | ||
430 | } | ||
431 | |||
432 | /* next state (stn) */ | ||
433 | p=(unsigned char *)s->init_buf->data; | ||
434 | n=s->s3->tmp.message_size; | ||
435 | while (n > 0) | ||
436 | { | ||
437 | i=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n); | ||
438 | if (i <= 0) | ||
439 | { | ||
440 | s->rwstate=SSL_READING; | ||
441 | *ok = 0; | ||
442 | return i; | ||
443 | } | ||
444 | s->init_num += i; | ||
445 | n -= i; | ||
446 | } | ||
447 | ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num); | ||
448 | *ok=1; | ||
449 | return s->init_num; | ||
450 | f_err: | ||
451 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
452 | err: | ||
453 | *ok=0; | ||
454 | return(-1); | ||
455 | } | ||
456 | |||
457 | int ssl_cert_type(X509 *x, EVP_PKEY *pkey) | ||
458 | { | ||
459 | EVP_PKEY *pk; | ||
460 | int ret= -1,i,j; | ||
461 | |||
462 | if (pkey == NULL) | ||
463 | pk=X509_get_pubkey(x); | ||
464 | else | ||
465 | pk=pkey; | ||
466 | if (pk == NULL) goto err; | ||
467 | |||
468 | i=pk->type; | ||
469 | if (i == EVP_PKEY_RSA) | ||
470 | { | ||
471 | ret=SSL_PKEY_RSA_ENC; | ||
472 | if (x != NULL) | ||
473 | { | ||
474 | j=X509_get_ext_count(x); | ||
475 | /* check to see if this is a signing only certificate */ | ||
476 | /* EAY EAY EAY EAY */ | ||
477 | } | ||
478 | } | ||
479 | else if (i == EVP_PKEY_DSA) | ||
480 | { | ||
481 | ret=SSL_PKEY_DSA_SIGN; | ||
482 | } | ||
483 | else if (i == EVP_PKEY_DH) | ||
484 | { | ||
485 | /* if we just have a key, we needs to be guess */ | ||
486 | |||
487 | if (x == NULL) | ||
488 | ret=SSL_PKEY_DH_DSA; | ||
489 | else | ||
490 | { | ||
491 | j=X509_get_signature_type(x); | ||
492 | if (j == EVP_PKEY_RSA) | ||
493 | ret=SSL_PKEY_DH_RSA; | ||
494 | else if (j== EVP_PKEY_DSA) | ||
495 | ret=SSL_PKEY_DH_DSA; | ||
496 | else ret= -1; | ||
497 | } | ||
498 | } | ||
499 | else | ||
500 | ret= -1; | ||
501 | |||
502 | err: | ||
503 | if(!pkey) EVP_PKEY_free(pk); | ||
504 | return(ret); | ||
505 | } | ||
506 | |||
507 | int ssl_verify_alarm_type(long type) | ||
508 | { | ||
509 | int al; | ||
510 | |||
511 | switch(type) | ||
512 | { | ||
513 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
514 | case X509_V_ERR_UNABLE_TO_GET_CRL: | ||
515 | al=SSL_AD_UNKNOWN_CA; | ||
516 | break; | ||
517 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: | ||
518 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: | ||
519 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: | ||
520 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
521 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
522 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: | ||
523 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: | ||
524 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
525 | case X509_V_ERR_CRL_NOT_YET_VALID: | ||
526 | al=SSL_AD_BAD_CERTIFICATE; | ||
527 | break; | ||
528 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: | ||
529 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: | ||
530 | al=SSL_AD_DECRYPT_ERROR; | ||
531 | break; | ||
532 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
533 | case X509_V_ERR_CRL_HAS_EXPIRED: | ||
534 | al=SSL_AD_CERTIFICATE_EXPIRED; | ||
535 | break; | ||
536 | case X509_V_ERR_CERT_REVOKED: | ||
537 | al=SSL_AD_CERTIFICATE_REVOKED; | ||
538 | break; | ||
539 | case X509_V_ERR_OUT_OF_MEM: | ||
540 | al=SSL_AD_INTERNAL_ERROR; | ||
541 | break; | ||
542 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
543 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | ||
544 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: | ||
545 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: | ||
546 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: | ||
547 | al=SSL_AD_UNKNOWN_CA; | ||
548 | break; | ||
549 | case X509_V_ERR_APPLICATION_VERIFICATION: | ||
550 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
551 | break; | ||
552 | default: | ||
553 | al=SSL_AD_CERTIFICATE_UNKNOWN; | ||
554 | break; | ||
555 | } | ||
556 | return(al); | ||
557 | } | ||
558 | |||
559 | int ssl3_setup_buffers(SSL *s) | ||
560 | { | ||
561 | unsigned char *p; | ||
562 | unsigned int extra; | ||
563 | |||
564 | if (s->s3->rbuf.buf == NULL) | ||
565 | { | ||
566 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
567 | extra=SSL3_RT_MAX_EXTRA; | ||
568 | else | ||
569 | extra=0; | ||
570 | if ((p=Malloc(SSL3_RT_MAX_PACKET_SIZE+extra)) | ||
571 | == NULL) | ||
572 | goto err; | ||
573 | s->s3->rbuf.buf=p; | ||
574 | } | ||
575 | |||
576 | if (s->s3->wbuf.buf == NULL) | ||
577 | { | ||
578 | if ((p=Malloc(SSL3_RT_MAX_PACKET_SIZE)) | ||
579 | == NULL) | ||
580 | goto err; | ||
581 | s->s3->wbuf.buf=p; | ||
582 | } | ||
583 | s->packet= &(s->s3->rbuf.buf[0]); | ||
584 | return(1); | ||
585 | err: | ||
586 | SSLerr(SSL_F_SSL3_SETUP_BUFFERS,ERR_R_MALLOC_FAILURE); | ||
587 | return(0); | ||
588 | } | ||
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c deleted file mode 100644 index 0c8f551f73..0000000000 --- a/src/lib/libssl/s3_clnt.c +++ /dev/null | |||
@@ -1,1730 +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 | #include <stdio.h> | ||
60 | #include <openssl/buffer.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/md5.h> | ||
64 | #include <openssl/sha.h> | ||
65 | #include <openssl/evp.h> | ||
66 | #include "ssl_locl.h" | ||
67 | |||
68 | static SSL_METHOD *ssl3_get_client_method(int ver); | ||
69 | static int ssl3_client_hello(SSL *s); | ||
70 | static int ssl3_get_server_hello(SSL *s); | ||
71 | static int ssl3_get_certificate_request(SSL *s); | ||
72 | static int ca_dn_cmp(X509_NAME **a,X509_NAME **b); | ||
73 | static int ssl3_get_server_done(SSL *s); | ||
74 | static int ssl3_send_client_verify(SSL *s); | ||
75 | static int ssl3_send_client_certificate(SSL *s); | ||
76 | static int ssl3_send_client_key_exchange(SSL *s); | ||
77 | static int ssl3_get_key_exchange(SSL *s); | ||
78 | static int ssl3_get_server_certificate(SSL *s); | ||
79 | static int ssl3_check_cert_and_algorithm(SSL *s); | ||
80 | static SSL_METHOD *ssl3_get_client_method(int ver) | ||
81 | { | ||
82 | if (ver == SSL3_VERSION) | ||
83 | return(SSLv3_client_method()); | ||
84 | else | ||
85 | return(NULL); | ||
86 | } | ||
87 | |||
88 | SSL_METHOD *SSLv3_client_method(void) | ||
89 | { | ||
90 | static int init=1; | ||
91 | static SSL_METHOD SSLv3_client_data; | ||
92 | |||
93 | if (init) | ||
94 | { | ||
95 | init=0; | ||
96 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | ||
97 | sizeof(SSL_METHOD)); | ||
98 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
99 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
100 | } | ||
101 | return(&SSLv3_client_data); | ||
102 | } | ||
103 | |||
104 | int ssl3_connect(SSL *s) | ||
105 | { | ||
106 | BUF_MEM *buf; | ||
107 | unsigned long Time=time(NULL),l; | ||
108 | long num1; | ||
109 | void (*cb)()=NULL; | ||
110 | int ret= -1; | ||
111 | int new_state,state,skip=0;; | ||
112 | |||
113 | RAND_add(&Time,sizeof(Time),0); | ||
114 | ERR_clear_error(); | ||
115 | clear_sys_error(); | ||
116 | |||
117 | if (s->info_callback != NULL) | ||
118 | cb=s->info_callback; | ||
119 | else if (s->ctx->info_callback != NULL) | ||
120 | cb=s->ctx->info_callback; | ||
121 | |||
122 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
123 | s->in_handshake++; | ||
124 | |||
125 | for (;;) | ||
126 | { | ||
127 | state=s->state; | ||
128 | |||
129 | switch(s->state) | ||
130 | { | ||
131 | case SSL_ST_RENEGOTIATE: | ||
132 | s->new_session=1; | ||
133 | s->state=SSL_ST_CONNECT; | ||
134 | s->ctx->stats.sess_connect_renegotiate++; | ||
135 | /* break */ | ||
136 | case SSL_ST_BEFORE: | ||
137 | case SSL_ST_CONNECT: | ||
138 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | ||
139 | case SSL_ST_OK|SSL_ST_CONNECT: | ||
140 | |||
141 | s->server=0; | ||
142 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
143 | |||
144 | if ((s->version & 0xff00 ) != 0x0300) | ||
145 | abort(); | ||
146 | /* s->version=SSL3_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 | } | ||
163 | |||
164 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | ||
165 | |||
166 | /* setup buffing BIO */ | ||
167 | if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; } | ||
168 | |||
169 | /* don't push the buffering BIO quite yet */ | ||
170 | |||
171 | ssl3_init_finished_mac(s); | ||
172 | |||
173 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | ||
174 | s->ctx->stats.sess_connect++; | ||
175 | s->init_num=0; | ||
176 | break; | ||
177 | |||
178 | case SSL3_ST_CW_CLNT_HELLO_A: | ||
179 | case SSL3_ST_CW_CLNT_HELLO_B: | ||
180 | |||
181 | s->shutdown=0; | ||
182 | ret=ssl3_client_hello(s); | ||
183 | if (ret <= 0) goto end; | ||
184 | s->state=SSL3_ST_CR_SRVR_HELLO_A; | ||
185 | s->init_num=0; | ||
186 | |||
187 | /* turn on buffering for the next lot of output */ | ||
188 | if (s->bbio != s->wbio) | ||
189 | s->wbio=BIO_push(s->bbio,s->wbio); | ||
190 | |||
191 | break; | ||
192 | |||
193 | case SSL3_ST_CR_SRVR_HELLO_A: | ||
194 | case SSL3_ST_CR_SRVR_HELLO_B: | ||
195 | ret=ssl3_get_server_hello(s); | ||
196 | if (ret <= 0) goto end; | ||
197 | if (s->hit) | ||
198 | s->state=SSL3_ST_CR_FINISHED_A; | ||
199 | else | ||
200 | s->state=SSL3_ST_CR_CERT_A; | ||
201 | s->init_num=0; | ||
202 | break; | ||
203 | |||
204 | case SSL3_ST_CR_CERT_A: | ||
205 | case SSL3_ST_CR_CERT_B: | ||
206 | /* Check if it is anon DH */ | ||
207 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
208 | { | ||
209 | ret=ssl3_get_server_certificate(s); | ||
210 | if (ret <= 0) goto end; | ||
211 | } | ||
212 | else | ||
213 | skip=1; | ||
214 | s->state=SSL3_ST_CR_KEY_EXCH_A; | ||
215 | s->init_num=0; | ||
216 | break; | ||
217 | |||
218 | case SSL3_ST_CR_KEY_EXCH_A: | ||
219 | case SSL3_ST_CR_KEY_EXCH_B: | ||
220 | ret=ssl3_get_key_exchange(s); | ||
221 | if (ret <= 0) goto end; | ||
222 | s->state=SSL3_ST_CR_CERT_REQ_A; | ||
223 | s->init_num=0; | ||
224 | |||
225 | /* at this point we check that we have the | ||
226 | * required stuff from the server */ | ||
227 | if (!ssl3_check_cert_and_algorithm(s)) | ||
228 | { | ||
229 | ret= -1; | ||
230 | goto end; | ||
231 | } | ||
232 | break; | ||
233 | |||
234 | case SSL3_ST_CR_CERT_REQ_A: | ||
235 | case SSL3_ST_CR_CERT_REQ_B: | ||
236 | ret=ssl3_get_certificate_request(s); | ||
237 | if (ret <= 0) goto end; | ||
238 | s->state=SSL3_ST_CR_SRVR_DONE_A; | ||
239 | s->init_num=0; | ||
240 | break; | ||
241 | |||
242 | case SSL3_ST_CR_SRVR_DONE_A: | ||
243 | case SSL3_ST_CR_SRVR_DONE_B: | ||
244 | ret=ssl3_get_server_done(s); | ||
245 | if (ret <= 0) goto end; | ||
246 | if (s->s3->tmp.cert_req) | ||
247 | s->state=SSL3_ST_CW_CERT_A; | ||
248 | else | ||
249 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
250 | s->init_num=0; | ||
251 | |||
252 | break; | ||
253 | |||
254 | case SSL3_ST_CW_CERT_A: | ||
255 | case SSL3_ST_CW_CERT_B: | ||
256 | case SSL3_ST_CW_CERT_C: | ||
257 | case SSL3_ST_CW_CERT_D: | ||
258 | ret=ssl3_send_client_certificate(s); | ||
259 | if (ret <= 0) goto end; | ||
260 | s->state=SSL3_ST_CW_KEY_EXCH_A; | ||
261 | s->init_num=0; | ||
262 | break; | ||
263 | |||
264 | case SSL3_ST_CW_KEY_EXCH_A: | ||
265 | case SSL3_ST_CW_KEY_EXCH_B: | ||
266 | ret=ssl3_send_client_key_exchange(s); | ||
267 | if (ret <= 0) goto end; | ||
268 | l=s->s3->tmp.new_cipher->algorithms; | ||
269 | /* EAY EAY EAY need to check for DH fix cert | ||
270 | * sent back */ | ||
271 | /* For TLS, cert_req is set to 2, so a cert chain | ||
272 | * of nothing is sent, but no verify packet is sent */ | ||
273 | if (s->s3->tmp.cert_req == 1) | ||
274 | { | ||
275 | s->state=SSL3_ST_CW_CERT_VRFY_A; | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | s->state=SSL3_ST_CW_CHANGE_A; | ||
280 | s->s3->change_cipher_spec=0; | ||
281 | } | ||
282 | |||
283 | s->init_num=0; | ||
284 | break; | ||
285 | |||
286 | case SSL3_ST_CW_CERT_VRFY_A: | ||
287 | case SSL3_ST_CW_CERT_VRFY_B: | ||
288 | ret=ssl3_send_client_verify(s); | ||
289 | if (ret <= 0) goto end; | ||
290 | s->state=SSL3_ST_CW_CHANGE_A; | ||
291 | s->init_num=0; | ||
292 | s->s3->change_cipher_spec=0; | ||
293 | break; | ||
294 | |||
295 | case SSL3_ST_CW_CHANGE_A: | ||
296 | case SSL3_ST_CW_CHANGE_B: | ||
297 | ret=ssl3_send_change_cipher_spec(s, | ||
298 | SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B); | ||
299 | if (ret <= 0) goto end; | ||
300 | s->state=SSL3_ST_CW_FINISHED_A; | ||
301 | s->init_num=0; | ||
302 | |||
303 | s->session->cipher=s->s3->tmp.new_cipher; | ||
304 | if (s->s3->tmp.new_compression == NULL) | ||
305 | s->session->compress_meth=0; | ||
306 | else | ||
307 | s->session->compress_meth= | ||
308 | s->s3->tmp.new_compression->id; | ||
309 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
310 | { | ||
311 | ret= -1; | ||
312 | goto end; | ||
313 | } | ||
314 | |||
315 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
316 | SSL3_CHANGE_CIPHER_CLIENT_WRITE)) | ||
317 | { | ||
318 | ret= -1; | ||
319 | goto end; | ||
320 | } | ||
321 | |||
322 | break; | ||
323 | |||
324 | case SSL3_ST_CW_FINISHED_A: | ||
325 | case SSL3_ST_CW_FINISHED_B: | ||
326 | ret=ssl3_send_finished(s, | ||
327 | SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B, | ||
328 | s->method->ssl3_enc->client_finished_label, | ||
329 | s->method->ssl3_enc->client_finished_label_len); | ||
330 | if (ret <= 0) goto end; | ||
331 | s->state=SSL3_ST_CW_FLUSH; | ||
332 | |||
333 | /* clear flags */ | ||
334 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
335 | if (s->hit) | ||
336 | { | ||
337 | s->s3->tmp.next_state=SSL_ST_OK; | ||
338 | if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) | ||
339 | { | ||
340 | s->state=SSL_ST_OK; | ||
341 | s->s3->flags|=SSL3_FLAGS_POP_BUFFER; | ||
342 | s->s3->delay_buf_pop_ret=0; | ||
343 | } | ||
344 | } | ||
345 | else | ||
346 | { | ||
347 | s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A; | ||
348 | } | ||
349 | s->init_num=0; | ||
350 | break; | ||
351 | |||
352 | case SSL3_ST_CR_FINISHED_A: | ||
353 | case SSL3_ST_CR_FINISHED_B: | ||
354 | |||
355 | ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A, | ||
356 | SSL3_ST_CR_FINISHED_B); | ||
357 | if (ret <= 0) goto end; | ||
358 | |||
359 | if (s->hit) | ||
360 | s->state=SSL3_ST_CW_CHANGE_A; | ||
361 | else | ||
362 | s->state=SSL_ST_OK; | ||
363 | s->init_num=0; | ||
364 | break; | ||
365 | |||
366 | case SSL3_ST_CW_FLUSH: | ||
367 | /* number of bytes to be flushed */ | ||
368 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
369 | if (num1 > 0) | ||
370 | { | ||
371 | s->rwstate=SSL_WRITING; | ||
372 | num1=BIO_flush(s->wbio); | ||
373 | if (num1 <= 0) { ret= -1; goto end; } | ||
374 | s->rwstate=SSL_NOTHING; | ||
375 | } | ||
376 | |||
377 | s->state=s->s3->tmp.next_state; | ||
378 | break; | ||
379 | |||
380 | case SSL_ST_OK: | ||
381 | /* clean a few things up */ | ||
382 | ssl3_cleanup_key_block(s); | ||
383 | |||
384 | if (s->init_buf != NULL) | ||
385 | { | ||
386 | BUF_MEM_free(s->init_buf); | ||
387 | s->init_buf=NULL; | ||
388 | } | ||
389 | |||
390 | /* If we are not 'joining' the last two packets, | ||
391 | * remove the buffering now */ | ||
392 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
393 | ssl_free_wbio_buffer(s); | ||
394 | /* else do it later in ssl3_write */ | ||
395 | |||
396 | s->init_num=0; | ||
397 | s->new_session=0; | ||
398 | |||
399 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | ||
400 | if (s->hit) s->ctx->stats.sess_hit++; | ||
401 | |||
402 | ret=1; | ||
403 | /* s->server=0; */ | ||
404 | s->handshake_func=ssl3_connect; | ||
405 | s->ctx->stats.sess_connect_good++; | ||
406 | |||
407 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
408 | |||
409 | goto end; | ||
410 | /* break; */ | ||
411 | |||
412 | default: | ||
413 | SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE); | ||
414 | ret= -1; | ||
415 | goto end; | ||
416 | /* break; */ | ||
417 | } | ||
418 | |||
419 | /* did we do anything */ | ||
420 | if (!s->s3->tmp.reuse_message && !skip) | ||
421 | { | ||
422 | if (s->debug) | ||
423 | { | ||
424 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
425 | goto end; | ||
426 | } | ||
427 | |||
428 | if ((cb != NULL) && (s->state != state)) | ||
429 | { | ||
430 | new_state=s->state; | ||
431 | s->state=state; | ||
432 | cb(s,SSL_CB_CONNECT_LOOP,1); | ||
433 | s->state=new_state; | ||
434 | } | ||
435 | } | ||
436 | skip=0; | ||
437 | } | ||
438 | end: | ||
439 | if (cb != NULL) | ||
440 | cb(s,SSL_CB_CONNECT_EXIT,ret); | ||
441 | s->in_handshake--; | ||
442 | return(ret); | ||
443 | } | ||
444 | |||
445 | |||
446 | static int ssl3_client_hello(SSL *s) | ||
447 | { | ||
448 | unsigned char *buf; | ||
449 | unsigned char *p,*d; | ||
450 | int i,j; | ||
451 | unsigned long Time,l; | ||
452 | SSL_COMP *comp; | ||
453 | |||
454 | buf=(unsigned char *)s->init_buf->data; | ||
455 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | ||
456 | { | ||
457 | if ((s->session == NULL) || | ||
458 | (s->session->ssl_version != s->version) || | ||
459 | (s->session->not_resumable)) | ||
460 | { | ||
461 | if (!ssl_get_new_session(s,0)) | ||
462 | goto err; | ||
463 | } | ||
464 | /* else use the pre-loaded session */ | ||
465 | |||
466 | p=s->s3->client_random; | ||
467 | Time=time(NULL); /* Time */ | ||
468 | l2n(Time,p); | ||
469 | RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time)); | ||
470 | |||
471 | /* Do the message type and length last */ | ||
472 | d=p= &(buf[4]); | ||
473 | |||
474 | *(p++)=s->version>>8; | ||
475 | *(p++)=s->version&0xff; | ||
476 | s->client_version=s->version; | ||
477 | |||
478 | /* Random stuff */ | ||
479 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
480 | p+=SSL3_RANDOM_SIZE; | ||
481 | |||
482 | /* Session ID */ | ||
483 | if (s->new_session) | ||
484 | i=0; | ||
485 | else | ||
486 | i=s->session->session_id_length; | ||
487 | *(p++)=i; | ||
488 | if (i != 0) | ||
489 | { | ||
490 | memcpy(p,s->session->session_id,i); | ||
491 | p+=i; | ||
492 | } | ||
493 | |||
494 | /* Ciphers supported */ | ||
495 | i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2])); | ||
496 | if (i == 0) | ||
497 | { | ||
498 | SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE); | ||
499 | goto err; | ||
500 | } | ||
501 | s2n(i,p); | ||
502 | p+=i; | ||
503 | |||
504 | /* COMPRESSION */ | ||
505 | if (s->ctx->comp_methods == NULL) | ||
506 | j=0; | ||
507 | else | ||
508 | j=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
509 | *(p++)=1+j; | ||
510 | for (i=0; i<j; i++) | ||
511 | { | ||
512 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | ||
513 | *(p++)=comp->id; | ||
514 | } | ||
515 | *(p++)=0; /* Add the NULL method */ | ||
516 | |||
517 | l=(p-d); | ||
518 | d=buf; | ||
519 | *(d++)=SSL3_MT_CLIENT_HELLO; | ||
520 | l2n3(l,d); | ||
521 | |||
522 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
523 | /* number of bytes to write */ | ||
524 | s->init_num=p-buf; | ||
525 | s->init_off=0; | ||
526 | } | ||
527 | |||
528 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
529 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
530 | err: | ||
531 | return(-1); | ||
532 | } | ||
533 | |||
534 | static int ssl3_get_server_hello(SSL *s) | ||
535 | { | ||
536 | STACK_OF(SSL_CIPHER) *sk; | ||
537 | SSL_CIPHER *c; | ||
538 | unsigned char *p,*d; | ||
539 | int i,al,ok; | ||
540 | unsigned int j; | ||
541 | long n; | ||
542 | SSL_COMP *comp; | ||
543 | |||
544 | n=ssl3_get_message(s, | ||
545 | SSL3_ST_CR_SRVR_HELLO_A, | ||
546 | SSL3_ST_CR_SRVR_HELLO_B, | ||
547 | SSL3_MT_SERVER_HELLO, | ||
548 | 300, /* ?? */ | ||
549 | &ok); | ||
550 | |||
551 | if (!ok) return((int)n); | ||
552 | d=p=(unsigned char *)s->init_buf->data; | ||
553 | |||
554 | if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff))) | ||
555 | { | ||
556 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION); | ||
557 | s->version=(s->version&0xff00)|p[1]; | ||
558 | al=SSL_AD_PROTOCOL_VERSION; | ||
559 | goto f_err; | ||
560 | } | ||
561 | p+=2; | ||
562 | |||
563 | /* load the server hello data */ | ||
564 | /* load the server random */ | ||
565 | memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE); | ||
566 | p+=SSL3_RANDOM_SIZE; | ||
567 | |||
568 | /* get the session-id */ | ||
569 | j= *(p++); | ||
570 | |||
571 | if ((j != 0) && (j != SSL3_SESSION_ID_SIZE)) | ||
572 | { | ||
573 | /* SSLref returns 16 :-( */ | ||
574 | if (j < SSL2_SSL_SESSION_ID_LENGTH) | ||
575 | { | ||
576 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
577 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT); | ||
578 | goto f_err; | ||
579 | } | ||
580 | } | ||
581 | if (j != 0 && j == s->session->session_id_length | ||
582 | && memcmp(p,s->session->session_id,j) == 0) | ||
583 | { | ||
584 | if(s->sid_ctx_length != s->session->sid_ctx_length | ||
585 | || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length)) | ||
586 | { | ||
587 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
588 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | ||
589 | goto f_err; | ||
590 | } | ||
591 | s->hit=1; | ||
592 | } | ||
593 | else /* a miss or crap from the other end */ | ||
594 | { | ||
595 | /* If we were trying for session-id reuse, make a new | ||
596 | * SSL_SESSION so we don't stuff up other people */ | ||
597 | s->hit=0; | ||
598 | if (s->session->session_id_length > 0) | ||
599 | { | ||
600 | if (!ssl_get_new_session(s,0)) | ||
601 | { | ||
602 | al=SSL_AD_INTERNAL_ERROR; | ||
603 | goto f_err; | ||
604 | } | ||
605 | } | ||
606 | s->session->session_id_length=j; | ||
607 | memcpy(s->session->session_id,p,j); /* j could be 0 */ | ||
608 | } | ||
609 | p+=j; | ||
610 | c=ssl_get_cipher_by_char(s,p); | ||
611 | if (c == NULL) | ||
612 | { | ||
613 | /* unknown cipher */ | ||
614 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
615 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED); | ||
616 | goto f_err; | ||
617 | } | ||
618 | p+=ssl_put_cipher_by_char(s,NULL,NULL); | ||
619 | |||
620 | sk=ssl_get_ciphers_by_id(s); | ||
621 | i=sk_SSL_CIPHER_find(sk,c); | ||
622 | if (i < 0) | ||
623 | { | ||
624 | /* we did not say we would use this cipher */ | ||
625 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
626 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED); | ||
627 | goto f_err; | ||
628 | } | ||
629 | |||
630 | if (s->hit && (s->session->cipher != c)) | ||
631 | { | ||
632 | if (!(s->options & | ||
633 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) | ||
634 | { | ||
635 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
636 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED); | ||
637 | goto f_err; | ||
638 | } | ||
639 | } | ||
640 | s->s3->tmp.new_cipher=c; | ||
641 | |||
642 | /* lets get the compression algorithm */ | ||
643 | /* COMPRESSION */ | ||
644 | j= *(p++); | ||
645 | if (j == 0) | ||
646 | comp=NULL; | ||
647 | else | ||
648 | comp=ssl3_comp_find(s->ctx->comp_methods,j); | ||
649 | |||
650 | if ((j != 0) && (comp == NULL)) | ||
651 | { | ||
652 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
653 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | ||
654 | goto f_err; | ||
655 | } | ||
656 | else | ||
657 | { | ||
658 | s->s3->tmp.new_compression=comp; | ||
659 | } | ||
660 | |||
661 | if (p != (d+n)) | ||
662 | { | ||
663 | /* wrong packet length */ | ||
664 | al=SSL_AD_DECODE_ERROR; | ||
665 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH); | ||
666 | goto err; | ||
667 | } | ||
668 | |||
669 | return(1); | ||
670 | f_err: | ||
671 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
672 | err: | ||
673 | return(-1); | ||
674 | } | ||
675 | |||
676 | static int ssl3_get_server_certificate(SSL *s) | ||
677 | { | ||
678 | int al,i,ok,ret= -1; | ||
679 | unsigned long n,nc,llen,l; | ||
680 | X509 *x=NULL; | ||
681 | unsigned char *p,*d,*q; | ||
682 | STACK_OF(X509) *sk=NULL; | ||
683 | SESS_CERT *sc; | ||
684 | EVP_PKEY *pkey=NULL; | ||
685 | |||
686 | n=ssl3_get_message(s, | ||
687 | SSL3_ST_CR_CERT_A, | ||
688 | SSL3_ST_CR_CERT_B, | ||
689 | -1, | ||
690 | #if defined(MSDOS) && !defined(WIN32) | ||
691 | 1024*30, /* 30k max cert list :-) */ | ||
692 | #else | ||
693 | 1024*100, /* 100k max cert list :-) */ | ||
694 | #endif | ||
695 | &ok); | ||
696 | |||
697 | if (!ok) return((int)n); | ||
698 | |||
699 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) | ||
700 | { | ||
701 | s->s3->tmp.reuse_message=1; | ||
702 | return(1); | ||
703 | } | ||
704 | |||
705 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
706 | { | ||
707 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
708 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE); | ||
709 | goto f_err; | ||
710 | } | ||
711 | d=p=(unsigned char *)s->init_buf->data; | ||
712 | |||
713 | if ((sk=sk_X509_new_null()) == NULL) | ||
714 | { | ||
715 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
716 | goto err; | ||
717 | } | ||
718 | |||
719 | n2l3(p,llen); | ||
720 | if (llen+3 != n) | ||
721 | { | ||
722 | al=SSL_AD_DECODE_ERROR; | ||
723 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
724 | goto f_err; | ||
725 | } | ||
726 | for (nc=0; nc<llen; ) | ||
727 | { | ||
728 | n2l3(p,l); | ||
729 | if ((l+nc+3) > llen) | ||
730 | { | ||
731 | al=SSL_AD_DECODE_ERROR; | ||
732 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
733 | goto f_err; | ||
734 | } | ||
735 | |||
736 | q=p; | ||
737 | x=d2i_X509(NULL,&q,l); | ||
738 | if (x == NULL) | ||
739 | { | ||
740 | al=SSL_AD_BAD_CERTIFICATE; | ||
741 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB); | ||
742 | goto f_err; | ||
743 | } | ||
744 | if (q != (p+l)) | ||
745 | { | ||
746 | al=SSL_AD_DECODE_ERROR; | ||
747 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
748 | goto f_err; | ||
749 | } | ||
750 | if (!sk_X509_push(sk,x)) | ||
751 | { | ||
752 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
753 | goto err; | ||
754 | } | ||
755 | x=NULL; | ||
756 | nc+=l+3; | ||
757 | p=q; | ||
758 | } | ||
759 | |||
760 | i=ssl_verify_cert_chain(s,sk); | ||
761 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)) | ||
762 | { | ||
763 | al=ssl_verify_alarm_type(s->verify_result); | ||
764 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); | ||
765 | goto f_err; | ||
766 | } | ||
767 | |||
768 | sc=ssl_sess_cert_new(); | ||
769 | if (sc == NULL) goto err; | ||
770 | |||
771 | if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert); | ||
772 | s->session->sess_cert=sc; | ||
773 | |||
774 | sc->cert_chain=sk; | ||
775 | /* Inconsistency alert: cert_chain does include the peer's | ||
776 | * certificate, which we don't include in s3_srvr.c */ | ||
777 | x=sk_X509_value(sk,0); | ||
778 | sk=NULL; | ||
779 | |||
780 | pkey=X509_get_pubkey(x); | ||
781 | |||
782 | if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey)) | ||
783 | { | ||
784 | x=NULL; | ||
785 | al=SSL3_AL_FATAL; | ||
786 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS); | ||
787 | goto f_err; | ||
788 | } | ||
789 | |||
790 | i=ssl_cert_type(x,pkey); | ||
791 | if (i < 0) | ||
792 | { | ||
793 | x=NULL; | ||
794 | al=SSL3_AL_FATAL; | ||
795 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
796 | goto f_err; | ||
797 | } | ||
798 | |||
799 | sc->peer_cert_type=i; | ||
800 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
801 | if (sc->peer_pkeys[i].x509 != NULL) /* Why would this ever happen? | ||
802 | * We just created sc a couple of | ||
803 | * lines ago. */ | ||
804 | X509_free(sc->peer_pkeys[i].x509); | ||
805 | sc->peer_pkeys[i].x509=x; | ||
806 | sc->peer_key= &(sc->peer_pkeys[i]); | ||
807 | |||
808 | if (s->session->peer != NULL) | ||
809 | X509_free(s->session->peer); | ||
810 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
811 | s->session->peer=x; | ||
812 | |||
813 | x=NULL; | ||
814 | ret=1; | ||
815 | |||
816 | if (0) | ||
817 | { | ||
818 | f_err: | ||
819 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
820 | } | ||
821 | err: | ||
822 | EVP_PKEY_free(pkey); | ||
823 | X509_free(x); | ||
824 | sk_X509_pop_free(sk,X509_free); | ||
825 | return(ret); | ||
826 | } | ||
827 | |||
828 | static int ssl3_get_key_exchange(SSL *s) | ||
829 | { | ||
830 | #ifndef NO_RSA | ||
831 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; | ||
832 | #endif | ||
833 | EVP_MD_CTX md_ctx; | ||
834 | unsigned char *param,*p; | ||
835 | int al,i,j,param_len,ok; | ||
836 | long n,alg; | ||
837 | EVP_PKEY *pkey=NULL; | ||
838 | #ifndef NO_RSA | ||
839 | RSA *rsa=NULL; | ||
840 | #endif | ||
841 | #ifndef NO_DH | ||
842 | DH *dh=NULL; | ||
843 | #endif | ||
844 | |||
845 | n=ssl3_get_message(s, | ||
846 | SSL3_ST_CR_KEY_EXCH_A, | ||
847 | SSL3_ST_CR_KEY_EXCH_B, | ||
848 | -1, | ||
849 | 1024*8, /* ?? */ | ||
850 | &ok); | ||
851 | |||
852 | if (!ok) return((int)n); | ||
853 | |||
854 | if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) | ||
855 | { | ||
856 | s->s3->tmp.reuse_message=1; | ||
857 | return(1); | ||
858 | } | ||
859 | |||
860 | param=p=(unsigned char *)s->init_buf->data; | ||
861 | |||
862 | if (s->session->sess_cert != NULL) | ||
863 | { | ||
864 | #ifndef NO_RSA | ||
865 | if (s->session->sess_cert->peer_rsa_tmp != NULL) | ||
866 | { | ||
867 | RSA_free(s->session->sess_cert->peer_rsa_tmp); | ||
868 | s->session->sess_cert->peer_rsa_tmp=NULL; | ||
869 | } | ||
870 | #endif | ||
871 | #ifndef NO_DH | ||
872 | if (s->session->sess_cert->peer_dh_tmp) | ||
873 | { | ||
874 | DH_free(s->session->sess_cert->peer_dh_tmp); | ||
875 | s->session->sess_cert->peer_dh_tmp=NULL; | ||
876 | } | ||
877 | #endif | ||
878 | } | ||
879 | else | ||
880 | { | ||
881 | s->session->sess_cert=ssl_sess_cert_new(); | ||
882 | } | ||
883 | |||
884 | param_len=0; | ||
885 | alg=s->s3->tmp.new_cipher->algorithms; | ||
886 | |||
887 | #ifndef NO_RSA | ||
888 | if (alg & SSL_kRSA) | ||
889 | { | ||
890 | if ((rsa=RSA_new()) == NULL) | ||
891 | { | ||
892 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
893 | goto err; | ||
894 | } | ||
895 | n2s(p,i); | ||
896 | param_len=i+2; | ||
897 | if (param_len > n) | ||
898 | { | ||
899 | al=SSL_AD_DECODE_ERROR; | ||
900 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH); | ||
901 | goto f_err; | ||
902 | } | ||
903 | if (!(rsa->n=BN_bin2bn(p,i,rsa->n))) | ||
904 | { | ||
905 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
906 | goto err; | ||
907 | } | ||
908 | p+=i; | ||
909 | |||
910 | n2s(p,i); | ||
911 | param_len+=i+2; | ||
912 | if (param_len > n) | ||
913 | { | ||
914 | al=SSL_AD_DECODE_ERROR; | ||
915 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH); | ||
916 | goto f_err; | ||
917 | } | ||
918 | if (!(rsa->e=BN_bin2bn(p,i,rsa->e))) | ||
919 | { | ||
920 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
921 | goto err; | ||
922 | } | ||
923 | p+=i; | ||
924 | n-=param_len; | ||
925 | |||
926 | /* this should be because we are using an export cipher */ | ||
927 | if (alg & SSL_aRSA) | ||
928 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
929 | else | ||
930 | { | ||
931 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
932 | goto err; | ||
933 | } | ||
934 | s->session->sess_cert->peer_rsa_tmp=rsa; | ||
935 | rsa=NULL; | ||
936 | } | ||
937 | else | ||
938 | #endif | ||
939 | #ifndef NO_DH | ||
940 | if (alg & SSL_kEDH) | ||
941 | { | ||
942 | if ((dh=DH_new()) == NULL) | ||
943 | { | ||
944 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
945 | goto err; | ||
946 | } | ||
947 | n2s(p,i); | ||
948 | param_len=i+2; | ||
949 | if (param_len > n) | ||
950 | { | ||
951 | al=SSL_AD_DECODE_ERROR; | ||
952 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH); | ||
953 | goto f_err; | ||
954 | } | ||
955 | if (!(dh->p=BN_bin2bn(p,i,NULL))) | ||
956 | { | ||
957 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
958 | goto err; | ||
959 | } | ||
960 | p+=i; | ||
961 | |||
962 | n2s(p,i); | ||
963 | param_len+=i+2; | ||
964 | if (param_len > n) | ||
965 | { | ||
966 | al=SSL_AD_DECODE_ERROR; | ||
967 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH); | ||
968 | goto f_err; | ||
969 | } | ||
970 | if (!(dh->g=BN_bin2bn(p,i,NULL))) | ||
971 | { | ||
972 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
973 | goto err; | ||
974 | } | ||
975 | p+=i; | ||
976 | |||
977 | n2s(p,i); | ||
978 | param_len+=i+2; | ||
979 | if (param_len > n) | ||
980 | { | ||
981 | al=SSL_AD_DECODE_ERROR; | ||
982 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH); | ||
983 | goto f_err; | ||
984 | } | ||
985 | if (!(dh->pub_key=BN_bin2bn(p,i,NULL))) | ||
986 | { | ||
987 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB); | ||
988 | goto err; | ||
989 | } | ||
990 | p+=i; | ||
991 | n-=param_len; | ||
992 | |||
993 | #ifndef NO_RSA | ||
994 | if (alg & SSL_aRSA) | ||
995 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
996 | else | ||
997 | #endif | ||
998 | #ifndef NO_DSA | ||
999 | if (alg & SSL_aDSS) | ||
1000 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509); | ||
1001 | #endif | ||
1002 | /* else anonymous DH, so no certificate or pkey. */ | ||
1003 | |||
1004 | s->session->sess_cert->peer_dh_tmp=dh; | ||
1005 | dh=NULL; | ||
1006 | } | ||
1007 | else if ((alg & SSL_kDHr) || (alg & SSL_kDHd)) | ||
1008 | { | ||
1009 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1010 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
1011 | goto f_err; | ||
1012 | } | ||
1013 | #endif | ||
1014 | if (alg & SSL_aFZA) | ||
1015 | { | ||
1016 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1017 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
1018 | goto f_err; | ||
1019 | } | ||
1020 | |||
1021 | |||
1022 | /* p points to the next byte, there are 'n' bytes left */ | ||
1023 | |||
1024 | |||
1025 | /* if it was signed, check the signature */ | ||
1026 | if (pkey != NULL) | ||
1027 | { | ||
1028 | n2s(p,i); | ||
1029 | n-=2; | ||
1030 | j=EVP_PKEY_size(pkey); | ||
1031 | |||
1032 | if ((i != n) || (n > j) || (n <= 0)) | ||
1033 | { | ||
1034 | /* wrong packet length */ | ||
1035 | al=SSL_AD_DECODE_ERROR; | ||
1036 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH); | ||
1037 | goto f_err; | ||
1038 | } | ||
1039 | |||
1040 | #ifndef NO_RSA | ||
1041 | if (pkey->type == EVP_PKEY_RSA) | ||
1042 | { | ||
1043 | int num; | ||
1044 | |||
1045 | j=0; | ||
1046 | q=md_buf; | ||
1047 | for (num=2; num > 0; num--) | ||
1048 | { | ||
1049 | EVP_DigestInit(&md_ctx,(num == 2) | ||
1050 | ?s->ctx->md5:s->ctx->sha1); | ||
1051 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1052 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1053 | EVP_DigestUpdate(&md_ctx,param,param_len); | ||
1054 | EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i); | ||
1055 | q+=i; | ||
1056 | j+=i; | ||
1057 | } | ||
1058 | i=RSA_verify(NID_md5_sha1, md_buf, j, p, n, | ||
1059 | pkey->pkey.rsa); | ||
1060 | if (i < 0) | ||
1061 | { | ||
1062 | al=SSL_AD_DECRYPT_ERROR; | ||
1063 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | ||
1064 | goto f_err; | ||
1065 | } | ||
1066 | if (i == 0) | ||
1067 | { | ||
1068 | /* bad signature */ | ||
1069 | al=SSL_AD_DECRYPT_ERROR; | ||
1070 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
1071 | goto f_err; | ||
1072 | } | ||
1073 | } | ||
1074 | else | ||
1075 | #endif | ||
1076 | #ifndef NO_DSA | ||
1077 | if (pkey->type == EVP_PKEY_DSA) | ||
1078 | { | ||
1079 | /* lets do DSS */ | ||
1080 | EVP_VerifyInit(&md_ctx,EVP_dss1()); | ||
1081 | EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1082 | EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1083 | EVP_VerifyUpdate(&md_ctx,param,param_len); | ||
1084 | if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey)) | ||
1085 | { | ||
1086 | /* bad signature */ | ||
1087 | al=SSL_AD_DECRYPT_ERROR; | ||
1088 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE); | ||
1089 | goto f_err; | ||
1090 | } | ||
1091 | } | ||
1092 | else | ||
1093 | #endif | ||
1094 | { | ||
1095 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
1096 | goto err; | ||
1097 | } | ||
1098 | } | ||
1099 | else | ||
1100 | { | ||
1101 | /* still data left over */ | ||
1102 | if (!(alg & SSL_aNULL)) | ||
1103 | { | ||
1104 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
1105 | goto err; | ||
1106 | } | ||
1107 | if (n != 0) | ||
1108 | { | ||
1109 | al=SSL_AD_DECODE_ERROR; | ||
1110 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE); | ||
1111 | goto f_err; | ||
1112 | } | ||
1113 | } | ||
1114 | EVP_PKEY_free(pkey); | ||
1115 | return(1); | ||
1116 | f_err: | ||
1117 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1118 | err: | ||
1119 | EVP_PKEY_free(pkey); | ||
1120 | #ifndef NO_RSA | ||
1121 | if (rsa != NULL) | ||
1122 | RSA_free(rsa); | ||
1123 | #endif | ||
1124 | #ifndef NO_DH | ||
1125 | if (dh != NULL) | ||
1126 | DH_free(dh); | ||
1127 | #endif | ||
1128 | return(-1); | ||
1129 | } | ||
1130 | |||
1131 | static int ssl3_get_certificate_request(SSL *s) | ||
1132 | { | ||
1133 | int ok,ret=0; | ||
1134 | unsigned long n,nc,l; | ||
1135 | unsigned int llen,ctype_num,i; | ||
1136 | X509_NAME *xn=NULL; | ||
1137 | unsigned char *p,*d,*q; | ||
1138 | STACK_OF(X509_NAME) *ca_sk=NULL; | ||
1139 | |||
1140 | n=ssl3_get_message(s, | ||
1141 | SSL3_ST_CR_CERT_REQ_A, | ||
1142 | SSL3_ST_CR_CERT_REQ_B, | ||
1143 | -1, | ||
1144 | #if defined(MSDOS) && !defined(WIN32) | ||
1145 | 1024*30, /* 30k max cert list :-) */ | ||
1146 | #else | ||
1147 | 1024*100, /* 100k max cert list :-) */ | ||
1148 | #endif | ||
1149 | &ok); | ||
1150 | |||
1151 | if (!ok) return((int)n); | ||
1152 | |||
1153 | s->s3->tmp.cert_req=0; | ||
1154 | |||
1155 | if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE) | ||
1156 | { | ||
1157 | s->s3->tmp.reuse_message=1; | ||
1158 | return(1); | ||
1159 | } | ||
1160 | |||
1161 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) | ||
1162 | { | ||
1163 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
1164 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE); | ||
1165 | goto err; | ||
1166 | } | ||
1167 | |||
1168 | /* TLS does not like anon-DH with client cert */ | ||
1169 | if (s->version > SSL3_VERSION) | ||
1170 | { | ||
1171 | l=s->s3->tmp.new_cipher->algorithms; | ||
1172 | if (l & SSL_aNULL) | ||
1173 | { | ||
1174 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE); | ||
1175 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER); | ||
1176 | goto err; | ||
1177 | } | ||
1178 | } | ||
1179 | |||
1180 | d=p=(unsigned char *)s->init_buf->data; | ||
1181 | |||
1182 | if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL) | ||
1183 | { | ||
1184 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
1185 | goto err; | ||
1186 | } | ||
1187 | |||
1188 | /* get the certificate types */ | ||
1189 | ctype_num= *(p++); | ||
1190 | if (ctype_num > SSL3_CT_NUMBER) | ||
1191 | ctype_num=SSL3_CT_NUMBER; | ||
1192 | for (i=0; i<ctype_num; i++) | ||
1193 | s->s3->tmp.ctype[i]= p[i]; | ||
1194 | p+=ctype_num; | ||
1195 | |||
1196 | /* get the CA RDNs */ | ||
1197 | n2s(p,llen); | ||
1198 | #if 0 | ||
1199 | { | ||
1200 | FILE *out; | ||
1201 | out=fopen("/tmp/vsign.der","w"); | ||
1202 | fwrite(p,1,llen,out); | ||
1203 | fclose(out); | ||
1204 | } | ||
1205 | #endif | ||
1206 | |||
1207 | if ((llen+ctype_num+2+1) != n) | ||
1208 | { | ||
1209 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1210 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH); | ||
1211 | goto err; | ||
1212 | } | ||
1213 | |||
1214 | for (nc=0; nc<llen; ) | ||
1215 | { | ||
1216 | n2s(p,l); | ||
1217 | if ((l+nc+2) > llen) | ||
1218 | { | ||
1219 | if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
1220 | goto cont; /* netscape bugs */ | ||
1221 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1222 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG); | ||
1223 | goto err; | ||
1224 | } | ||
1225 | |||
1226 | q=p; | ||
1227 | |||
1228 | if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL) | ||
1229 | { | ||
1230 | /* If netscape tolerance is on, ignore errors */ | ||
1231 | if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG) | ||
1232 | goto cont; | ||
1233 | else | ||
1234 | { | ||
1235 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1236 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB); | ||
1237 | goto err; | ||
1238 | } | ||
1239 | } | ||
1240 | |||
1241 | if (q != (p+l)) | ||
1242 | { | ||
1243 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1244 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH); | ||
1245 | goto err; | ||
1246 | } | ||
1247 | if (!sk_X509_NAME_push(ca_sk,xn)) | ||
1248 | { | ||
1249 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
1250 | goto err; | ||
1251 | } | ||
1252 | |||
1253 | p+=l; | ||
1254 | nc+=l+2; | ||
1255 | } | ||
1256 | |||
1257 | if (0) | ||
1258 | { | ||
1259 | cont: | ||
1260 | ERR_clear_error(); | ||
1261 | } | ||
1262 | |||
1263 | /* we should setup a certificate to return.... */ | ||
1264 | s->s3->tmp.cert_req=1; | ||
1265 | s->s3->tmp.ctype_num=ctype_num; | ||
1266 | if (s->s3->tmp.ca_names != NULL) | ||
1267 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
1268 | s->s3->tmp.ca_names=ca_sk; | ||
1269 | ca_sk=NULL; | ||
1270 | |||
1271 | ret=1; | ||
1272 | err: | ||
1273 | if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free); | ||
1274 | return(ret); | ||
1275 | } | ||
1276 | |||
1277 | static int ca_dn_cmp(X509_NAME **a, X509_NAME **b) | ||
1278 | { | ||
1279 | return(X509_NAME_cmp(*a,*b)); | ||
1280 | } | ||
1281 | |||
1282 | static int ssl3_get_server_done(SSL *s) | ||
1283 | { | ||
1284 | int ok,ret=0; | ||
1285 | long n; | ||
1286 | |||
1287 | n=ssl3_get_message(s, | ||
1288 | SSL3_ST_CR_SRVR_DONE_A, | ||
1289 | SSL3_ST_CR_SRVR_DONE_B, | ||
1290 | SSL3_MT_SERVER_DONE, | ||
1291 | 30, /* should be very small, like 0 :-) */ | ||
1292 | &ok); | ||
1293 | |||
1294 | if (!ok) return((int)n); | ||
1295 | if (n > 0) | ||
1296 | { | ||
1297 | /* should contain no data */ | ||
1298 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | ||
1299 | SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH); | ||
1300 | } | ||
1301 | ret=1; | ||
1302 | return(ret); | ||
1303 | } | ||
1304 | |||
1305 | static int ssl3_send_client_key_exchange(SSL *s) | ||
1306 | { | ||
1307 | unsigned char *p,*d; | ||
1308 | int n; | ||
1309 | unsigned long l; | ||
1310 | #ifndef NO_RSA | ||
1311 | unsigned char *q; | ||
1312 | EVP_PKEY *pkey=NULL; | ||
1313 | #endif | ||
1314 | |||
1315 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | ||
1316 | { | ||
1317 | d=(unsigned char *)s->init_buf->data; | ||
1318 | p= &(d[4]); | ||
1319 | |||
1320 | l=s->s3->tmp.new_cipher->algorithms; | ||
1321 | |||
1322 | #ifndef NO_RSA | ||
1323 | if (l & SSL_kRSA) | ||
1324 | { | ||
1325 | RSA *rsa; | ||
1326 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; | ||
1327 | |||
1328 | if (s->session->sess_cert->peer_rsa_tmp != NULL) | ||
1329 | rsa=s->session->sess_cert->peer_rsa_tmp; | ||
1330 | else | ||
1331 | { | ||
1332 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); | ||
1333 | if ((pkey == NULL) || | ||
1334 | (pkey->type != EVP_PKEY_RSA) || | ||
1335 | (pkey->pkey.rsa == NULL)) | ||
1336 | { | ||
1337 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
1338 | goto err; | ||
1339 | } | ||
1340 | rsa=pkey->pkey.rsa; | ||
1341 | EVP_PKEY_free(pkey); | ||
1342 | } | ||
1343 | |||
1344 | tmp_buf[0]=s->client_version>>8; | ||
1345 | tmp_buf[1]=s->client_version&0xff; | ||
1346 | if (RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2) <= 0) | ||
1347 | goto err; | ||
1348 | |||
1349 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | ||
1350 | |||
1351 | q=p; | ||
1352 | /* Fix buf for TLS and beyond */ | ||
1353 | if (s->version > SSL3_VERSION) | ||
1354 | p+=2; | ||
1355 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, | ||
1356 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | ||
1357 | #ifdef PKCS1_CHECK | ||
1358 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | ||
1359 | if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70; | ||
1360 | #endif | ||
1361 | if (n <= 0) | ||
1362 | { | ||
1363 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); | ||
1364 | goto err; | ||
1365 | } | ||
1366 | |||
1367 | /* Fix buf for TLS and beyond */ | ||
1368 | if (s->version > SSL3_VERSION) | ||
1369 | { | ||
1370 | s2n(n,q); | ||
1371 | n+=2; | ||
1372 | } | ||
1373 | |||
1374 | s->session->master_key_length= | ||
1375 | s->method->ssl3_enc->generate_master_secret(s, | ||
1376 | s->session->master_key, | ||
1377 | tmp_buf,SSL_MAX_MASTER_KEY_LENGTH); | ||
1378 | memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH); | ||
1379 | } | ||
1380 | else | ||
1381 | #endif | ||
1382 | #ifndef NO_DH | ||
1383 | if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1384 | { | ||
1385 | DH *dh_srvr,*dh_clnt; | ||
1386 | |||
1387 | if (s->session->sess_cert->peer_dh_tmp != NULL) | ||
1388 | dh_srvr=s->session->sess_cert->peer_dh_tmp; | ||
1389 | else | ||
1390 | { | ||
1391 | /* we get them from the cert */ | ||
1392 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1393 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS); | ||
1394 | goto err; | ||
1395 | } | ||
1396 | |||
1397 | /* generate a new random key */ | ||
1398 | if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL) | ||
1399 | { | ||
1400 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1401 | goto err; | ||
1402 | } | ||
1403 | if (!DH_generate_key(dh_clnt)) | ||
1404 | { | ||
1405 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1406 | goto err; | ||
1407 | } | ||
1408 | |||
1409 | /* use the 'p' output buffer for the DH key, but | ||
1410 | * make sure to clear it out afterwards */ | ||
1411 | |||
1412 | n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt); | ||
1413 | |||
1414 | if (n <= 0) | ||
1415 | { | ||
1416 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1417 | goto err; | ||
1418 | } | ||
1419 | |||
1420 | /* generate master key from the result */ | ||
1421 | s->session->master_key_length= | ||
1422 | s->method->ssl3_enc->generate_master_secret(s, | ||
1423 | s->session->master_key,p,n); | ||
1424 | /* clean up */ | ||
1425 | memset(p,0,n); | ||
1426 | |||
1427 | /* send off the data */ | ||
1428 | n=BN_num_bytes(dh_clnt->pub_key); | ||
1429 | s2n(n,p); | ||
1430 | BN_bn2bin(dh_clnt->pub_key,p); | ||
1431 | n+=2; | ||
1432 | |||
1433 | DH_free(dh_clnt); | ||
1434 | |||
1435 | /* perhaps clean things up a bit EAY EAY EAY EAY*/ | ||
1436 | } | ||
1437 | else | ||
1438 | #endif | ||
1439 | { | ||
1440 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1441 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | ||
1442 | goto err; | ||
1443 | } | ||
1444 | |||
1445 | *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE; | ||
1446 | l2n3(n,d); | ||
1447 | |||
1448 | s->state=SSL3_ST_CW_KEY_EXCH_B; | ||
1449 | /* number of bytes to write */ | ||
1450 | s->init_num=n+4; | ||
1451 | s->init_off=0; | ||
1452 | } | ||
1453 | |||
1454 | /* SSL3_ST_CW_KEY_EXCH_B */ | ||
1455 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1456 | err: | ||
1457 | return(-1); | ||
1458 | } | ||
1459 | |||
1460 | static int ssl3_send_client_verify(SSL *s) | ||
1461 | { | ||
1462 | unsigned char *p,*d; | ||
1463 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
1464 | EVP_PKEY *pkey; | ||
1465 | #ifndef NO_RSA | ||
1466 | unsigned u=0; | ||
1467 | #endif | ||
1468 | unsigned long n; | ||
1469 | #ifndef NO_DSA | ||
1470 | int j; | ||
1471 | #endif | ||
1472 | |||
1473 | if (s->state == SSL3_ST_CW_CERT_VRFY_A) | ||
1474 | { | ||
1475 | d=(unsigned char *)s->init_buf->data; | ||
1476 | p= &(d[4]); | ||
1477 | pkey=s->cert->key->privatekey; | ||
1478 | |||
1479 | s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2), | ||
1480 | &(data[MD5_DIGEST_LENGTH])); | ||
1481 | |||
1482 | #ifndef NO_RSA | ||
1483 | if (pkey->type == EVP_PKEY_RSA) | ||
1484 | { | ||
1485 | s->method->ssl3_enc->cert_verify_mac(s, | ||
1486 | &(s->s3->finish_dgst1),&(data[0])); | ||
1487 | if (RSA_sign(NID_md5_sha1, data, | ||
1488 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
1489 | &(p[2]), &u, pkey->pkey.rsa) <= 0 ) | ||
1490 | { | ||
1491 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB); | ||
1492 | goto err; | ||
1493 | } | ||
1494 | s2n(u,p); | ||
1495 | n=u+2; | ||
1496 | } | ||
1497 | else | ||
1498 | #endif | ||
1499 | #ifndef NO_DSA | ||
1500 | if (pkey->type == EVP_PKEY_DSA) | ||
1501 | { | ||
1502 | if (!DSA_sign(pkey->save_type, | ||
1503 | &(data[MD5_DIGEST_LENGTH]), | ||
1504 | SHA_DIGEST_LENGTH,&(p[2]), | ||
1505 | (unsigned int *)&j,pkey->pkey.dsa)) | ||
1506 | { | ||
1507 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB); | ||
1508 | goto err; | ||
1509 | } | ||
1510 | s2n(j,p); | ||
1511 | n=j+2; | ||
1512 | } | ||
1513 | else | ||
1514 | #endif | ||
1515 | { | ||
1516 | SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR); | ||
1517 | goto err; | ||
1518 | } | ||
1519 | *(d++)=SSL3_MT_CERTIFICATE_VERIFY; | ||
1520 | l2n3(n,d); | ||
1521 | |||
1522 | s->init_num=(int)n+4; | ||
1523 | s->init_off=0; | ||
1524 | } | ||
1525 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1526 | err: | ||
1527 | return(-1); | ||
1528 | } | ||
1529 | |||
1530 | static int ssl3_send_client_certificate(SSL *s) | ||
1531 | { | ||
1532 | X509 *x509=NULL; | ||
1533 | EVP_PKEY *pkey=NULL; | ||
1534 | int i; | ||
1535 | unsigned long l; | ||
1536 | |||
1537 | if (s->state == SSL3_ST_CW_CERT_A) | ||
1538 | { | ||
1539 | if ((s->cert == NULL) || | ||
1540 | (s->cert->key->x509 == NULL) || | ||
1541 | (s->cert->key->privatekey == NULL)) | ||
1542 | s->state=SSL3_ST_CW_CERT_B; | ||
1543 | else | ||
1544 | s->state=SSL3_ST_CW_CERT_C; | ||
1545 | } | ||
1546 | |||
1547 | /* We need to get a client cert */ | ||
1548 | if (s->state == SSL3_ST_CW_CERT_B) | ||
1549 | { | ||
1550 | /* If we get an error, we need to | ||
1551 | * ssl->rwstate=SSL_X509_LOOKUP; return(-1); | ||
1552 | * We then get retied later */ | ||
1553 | i=0; | ||
1554 | if (s->ctx->client_cert_cb != NULL) | ||
1555 | i=s->ctx->client_cert_cb(s,&(x509),&(pkey)); | ||
1556 | if (i < 0) | ||
1557 | { | ||
1558 | s->rwstate=SSL_X509_LOOKUP; | ||
1559 | return(-1); | ||
1560 | } | ||
1561 | s->rwstate=SSL_NOTHING; | ||
1562 | if ((i == 1) && (pkey != NULL) && (x509 != NULL)) | ||
1563 | { | ||
1564 | s->state=SSL3_ST_CW_CERT_B; | ||
1565 | if ( !SSL_use_certificate(s,x509) || | ||
1566 | !SSL_use_PrivateKey(s,pkey)) | ||
1567 | i=0; | ||
1568 | } | ||
1569 | else if (i == 1) | ||
1570 | { | ||
1571 | i=0; | ||
1572 | SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK); | ||
1573 | } | ||
1574 | |||
1575 | if (x509 != NULL) X509_free(x509); | ||
1576 | if (pkey != NULL) EVP_PKEY_free(pkey); | ||
1577 | if (i == 0) | ||
1578 | { | ||
1579 | if (s->version == SSL3_VERSION) | ||
1580 | { | ||
1581 | s->s3->tmp.cert_req=0; | ||
1582 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE); | ||
1583 | return(1); | ||
1584 | } | ||
1585 | else | ||
1586 | { | ||
1587 | s->s3->tmp.cert_req=2; | ||
1588 | } | ||
1589 | } | ||
1590 | |||
1591 | /* Ok, we have a cert */ | ||
1592 | s->state=SSL3_ST_CW_CERT_C; | ||
1593 | } | ||
1594 | |||
1595 | if (s->state == SSL3_ST_CW_CERT_C) | ||
1596 | { | ||
1597 | s->state=SSL3_ST_CW_CERT_D; | ||
1598 | l=ssl3_output_cert_chain(s, | ||
1599 | (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509); | ||
1600 | s->init_num=(int)l; | ||
1601 | s->init_off=0; | ||
1602 | } | ||
1603 | /* SSL3_ST_CW_CERT_D */ | ||
1604 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1605 | } | ||
1606 | |||
1607 | #define has_bits(i,m) (((i)&(m)) == (m)) | ||
1608 | |||
1609 | static int ssl3_check_cert_and_algorithm(SSL *s) | ||
1610 | { | ||
1611 | int i,idx; | ||
1612 | long algs; | ||
1613 | EVP_PKEY *pkey=NULL; | ||
1614 | SESS_CERT *sc; | ||
1615 | #ifndef NO_RSA | ||
1616 | RSA *rsa; | ||
1617 | #endif | ||
1618 | #ifndef NO_DH | ||
1619 | DH *dh; | ||
1620 | #endif | ||
1621 | |||
1622 | sc=s->session->sess_cert; | ||
1623 | |||
1624 | if (sc == NULL) | ||
1625 | { | ||
1626 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR); | ||
1627 | goto err; | ||
1628 | } | ||
1629 | |||
1630 | algs=s->s3->tmp.new_cipher->algorithms; | ||
1631 | |||
1632 | /* we don't have a certificate */ | ||
1633 | if (algs & (SSL_aDH|SSL_aNULL)) | ||
1634 | return(1); | ||
1635 | |||
1636 | #ifndef NO_RSA | ||
1637 | rsa=s->session->sess_cert->peer_rsa_tmp; | ||
1638 | #endif | ||
1639 | #ifndef NO_DH | ||
1640 | dh=s->session->sess_cert->peer_dh_tmp; | ||
1641 | #endif | ||
1642 | |||
1643 | /* This is the passed certificate */ | ||
1644 | |||
1645 | idx=sc->peer_cert_type; | ||
1646 | pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); | ||
1647 | i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); | ||
1648 | EVP_PKEY_free(pkey); | ||
1649 | |||
1650 | |||
1651 | /* Check that we have a certificate if we require one */ | ||
1652 | if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN)) | ||
1653 | { | ||
1654 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT); | ||
1655 | goto f_err; | ||
1656 | } | ||
1657 | #ifndef NO_DSA | ||
1658 | else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN)) | ||
1659 | { | ||
1660 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT); | ||
1661 | goto f_err; | ||
1662 | } | ||
1663 | #endif | ||
1664 | #ifndef NO_RSA | ||
1665 | if ((algs & SSL_kRSA) && | ||
1666 | !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) | ||
1667 | { | ||
1668 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); | ||
1669 | goto f_err; | ||
1670 | } | ||
1671 | #endif | ||
1672 | #ifndef NO_DH | ||
1673 | if ((algs & SSL_kEDH) && | ||
1674 | !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) | ||
1675 | { | ||
1676 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); | ||
1677 | goto f_err; | ||
1678 | } | ||
1679 | else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA)) | ||
1680 | { | ||
1681 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT); | ||
1682 | goto f_err; | ||
1683 | } | ||
1684 | #ifndef NO_DSA | ||
1685 | else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA)) | ||
1686 | { | ||
1687 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT); | ||
1688 | goto f_err; | ||
1689 | } | ||
1690 | #endif | ||
1691 | #endif | ||
1692 | |||
1693 | if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP)) | ||
1694 | { | ||
1695 | #ifndef NO_RSA | ||
1696 | if (algs & SSL_kRSA) | ||
1697 | { | ||
1698 | if (rsa == NULL | ||
1699 | || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) | ||
1700 | { | ||
1701 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); | ||
1702 | goto f_err; | ||
1703 | } | ||
1704 | } | ||
1705 | else | ||
1706 | #endif | ||
1707 | #ifndef NO_DH | ||
1708 | if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1709 | { | ||
1710 | if (dh == NULL | ||
1711 | || DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) | ||
1712 | { | ||
1713 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); | ||
1714 | goto f_err; | ||
1715 | } | ||
1716 | } | ||
1717 | else | ||
1718 | #endif | ||
1719 | { | ||
1720 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
1721 | goto f_err; | ||
1722 | } | ||
1723 | } | ||
1724 | return(1); | ||
1725 | f_err: | ||
1726 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); | ||
1727 | err: | ||
1728 | return(0); | ||
1729 | } | ||
1730 | |||
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c deleted file mode 100644 index 7ada26cbb6..0000000000 --- a/src/lib/libssl/s3_lib.c +++ /dev/null | |||
@@ -1,1339 +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 | #include <stdio.h> | ||
60 | #include <openssl/md5.h> | ||
61 | #include <openssl/sha.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include "ssl_locl.h" | ||
64 | |||
65 | const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT; | ||
66 | |||
67 | #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER)) | ||
68 | |||
69 | static long ssl3_default_timeout(void ); | ||
70 | |||
71 | OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | ||
72 | /* The RSA ciphers */ | ||
73 | /* Cipher 01 */ | ||
74 | { | ||
75 | 1, | ||
76 | SSL3_TXT_RSA_NULL_MD5, | ||
77 | SSL3_CK_RSA_NULL_MD5, | ||
78 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3, | ||
79 | SSL_NOT_EXP, | ||
80 | 0, | ||
81 | 0, | ||
82 | 0, | ||
83 | SSL_ALL_CIPHERS, | ||
84 | SSL_ALL_STRENGTHS, | ||
85 | }, | ||
86 | /* Cipher 02 */ | ||
87 | { | ||
88 | 1, | ||
89 | SSL3_TXT_RSA_NULL_SHA, | ||
90 | SSL3_CK_RSA_NULL_SHA, | ||
91 | SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3, | ||
92 | SSL_NOT_EXP, | ||
93 | 0, | ||
94 | 0, | ||
95 | 0, | ||
96 | SSL_ALL_CIPHERS, | ||
97 | SSL_ALL_STRENGTHS, | ||
98 | }, | ||
99 | |||
100 | /* anon DH */ | ||
101 | /* Cipher 17 */ | ||
102 | { | ||
103 | 1, | ||
104 | SSL3_TXT_ADH_RC4_40_MD5, | ||
105 | SSL3_CK_ADH_RC4_40_MD5, | ||
106 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
107 | SSL_EXPORT|SSL_EXP40, | ||
108 | 0, | ||
109 | 40, | ||
110 | 128, | ||
111 | SSL_ALL_CIPHERS, | ||
112 | SSL_ALL_STRENGTHS, | ||
113 | }, | ||
114 | /* Cipher 18 */ | ||
115 | { | ||
116 | 1, | ||
117 | SSL3_TXT_ADH_RC4_128_MD5, | ||
118 | SSL3_CK_ADH_RC4_128_MD5, | ||
119 | SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
120 | SSL_NOT_EXP, | ||
121 | 0, | ||
122 | 128, | ||
123 | 128, | ||
124 | SSL_ALL_CIPHERS, | ||
125 | SSL_ALL_STRENGTHS, | ||
126 | }, | ||
127 | /* Cipher 19 */ | ||
128 | { | ||
129 | 1, | ||
130 | SSL3_TXT_ADH_DES_40_CBC_SHA, | ||
131 | SSL3_CK_ADH_DES_40_CBC_SHA, | ||
132 | SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
133 | SSL_EXPORT|SSL_EXP40, | ||
134 | 0, | ||
135 | 40, | ||
136 | 128, | ||
137 | SSL_ALL_CIPHERS, | ||
138 | SSL_ALL_STRENGTHS, | ||
139 | }, | ||
140 | /* Cipher 1A */ | ||
141 | { | ||
142 | 1, | ||
143 | SSL3_TXT_ADH_DES_64_CBC_SHA, | ||
144 | SSL3_CK_ADH_DES_64_CBC_SHA, | ||
145 | SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
146 | SSL_NOT_EXP, | ||
147 | 0, | ||
148 | 56, | ||
149 | 56, | ||
150 | SSL_ALL_CIPHERS, | ||
151 | SSL_ALL_STRENGTHS, | ||
152 | }, | ||
153 | /* Cipher 1B */ | ||
154 | { | ||
155 | 1, | ||
156 | SSL3_TXT_ADH_DES_192_CBC_SHA, | ||
157 | SSL3_CK_ADH_DES_192_CBC_SHA, | ||
158 | SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
159 | SSL_NOT_EXP, | ||
160 | 0, | ||
161 | 168, | ||
162 | 168, | ||
163 | SSL_ALL_CIPHERS, | ||
164 | SSL_ALL_STRENGTHS, | ||
165 | }, | ||
166 | |||
167 | /* RSA again */ | ||
168 | /* Cipher 03 */ | ||
169 | { | ||
170 | 1, | ||
171 | SSL3_TXT_RSA_RC4_40_MD5, | ||
172 | SSL3_CK_RSA_RC4_40_MD5, | ||
173 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3, | ||
174 | SSL_EXPORT|SSL_EXP40, | ||
175 | 0, | ||
176 | 40, | ||
177 | 128, | ||
178 | SSL_ALL_CIPHERS, | ||
179 | SSL_ALL_STRENGTHS, | ||
180 | }, | ||
181 | /* Cipher 04 */ | ||
182 | { | ||
183 | 1, | ||
184 | SSL3_TXT_RSA_RC4_128_MD5, | ||
185 | SSL3_CK_RSA_RC4_128_MD5, | ||
186 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3, | ||
187 | SSL_NOT_EXP|SSL_MEDIUM, | ||
188 | 0, | ||
189 | 128, | ||
190 | 128, | ||
191 | SSL_ALL_CIPHERS, | ||
192 | SSL_ALL_STRENGTHS, | ||
193 | }, | ||
194 | /* Cipher 05 */ | ||
195 | { | ||
196 | 1, | ||
197 | SSL3_TXT_RSA_RC4_128_SHA, | ||
198 | SSL3_CK_RSA_RC4_128_SHA, | ||
199 | SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3, | ||
200 | SSL_NOT_EXP|SSL_MEDIUM, | ||
201 | 0, | ||
202 | 128, | ||
203 | 128, | ||
204 | SSL_ALL_CIPHERS, | ||
205 | SSL_ALL_STRENGTHS, | ||
206 | }, | ||
207 | /* Cipher 06 */ | ||
208 | { | ||
209 | 1, | ||
210 | SSL3_TXT_RSA_RC2_40_MD5, | ||
211 | SSL3_CK_RSA_RC2_40_MD5, | ||
212 | SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3, | ||
213 | SSL_EXPORT|SSL_EXP40, | ||
214 | 0, | ||
215 | 40, | ||
216 | 128, | ||
217 | SSL_ALL_CIPHERS, | ||
218 | SSL_ALL_STRENGTHS, | ||
219 | }, | ||
220 | /* Cipher 07 */ | ||
221 | { | ||
222 | 1, | ||
223 | SSL3_TXT_RSA_IDEA_128_SHA, | ||
224 | SSL3_CK_RSA_IDEA_128_SHA, | ||
225 | SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3, | ||
226 | SSL_NOT_EXP|SSL_MEDIUM, | ||
227 | 0, | ||
228 | 128, | ||
229 | 128, | ||
230 | SSL_ALL_CIPHERS, | ||
231 | SSL_ALL_STRENGTHS, | ||
232 | }, | ||
233 | /* Cipher 08 */ | ||
234 | { | ||
235 | 1, | ||
236 | SSL3_TXT_RSA_DES_40_CBC_SHA, | ||
237 | SSL3_CK_RSA_DES_40_CBC_SHA, | ||
238 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
239 | SSL_EXPORT|SSL_EXP40, | ||
240 | 0, | ||
241 | 40, | ||
242 | 56, | ||
243 | SSL_ALL_CIPHERS, | ||
244 | SSL_ALL_STRENGTHS, | ||
245 | }, | ||
246 | /* Cipher 09 */ | ||
247 | { | ||
248 | 1, | ||
249 | SSL3_TXT_RSA_DES_64_CBC_SHA, | ||
250 | SSL3_CK_RSA_DES_64_CBC_SHA, | ||
251 | SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
252 | SSL_NOT_EXP|SSL_LOW, | ||
253 | 0, | ||
254 | 56, | ||
255 | 56, | ||
256 | SSL_ALL_CIPHERS, | ||
257 | SSL_ALL_STRENGTHS, | ||
258 | }, | ||
259 | /* Cipher 0A */ | ||
260 | { | ||
261 | 1, | ||
262 | SSL3_TXT_RSA_DES_192_CBC3_SHA, | ||
263 | SSL3_CK_RSA_DES_192_CBC3_SHA, | ||
264 | SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
265 | SSL_NOT_EXP|SSL_HIGH, | ||
266 | 0, | ||
267 | 168, | ||
268 | 168, | ||
269 | SSL_ALL_CIPHERS, | ||
270 | SSL_ALL_STRENGTHS, | ||
271 | }, | ||
272 | |||
273 | /* The DH ciphers */ | ||
274 | /* Cipher 0B */ | ||
275 | { | ||
276 | 0, | ||
277 | SSL3_TXT_DH_DSS_DES_40_CBC_SHA, | ||
278 | SSL3_CK_DH_DSS_DES_40_CBC_SHA, | ||
279 | SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
280 | SSL_EXPORT|SSL_EXP40, | ||
281 | 0, | ||
282 | 40, | ||
283 | 56, | ||
284 | SSL_ALL_CIPHERS, | ||
285 | SSL_ALL_STRENGTHS, | ||
286 | }, | ||
287 | /* Cipher 0C */ | ||
288 | { | ||
289 | 0, | ||
290 | SSL3_TXT_DH_DSS_DES_64_CBC_SHA, | ||
291 | SSL3_CK_DH_DSS_DES_64_CBC_SHA, | ||
292 | SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
293 | SSL_NOT_EXP|SSL_LOW, | ||
294 | 0, | ||
295 | 56, | ||
296 | 56, | ||
297 | SSL_ALL_CIPHERS, | ||
298 | SSL_ALL_STRENGTHS, | ||
299 | }, | ||
300 | /* Cipher 0D */ | ||
301 | { | ||
302 | 0, | ||
303 | SSL3_TXT_DH_DSS_DES_192_CBC3_SHA, | ||
304 | SSL3_CK_DH_DSS_DES_192_CBC3_SHA, | ||
305 | SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
306 | SSL_NOT_EXP|SSL_HIGH, | ||
307 | 0, | ||
308 | 168, | ||
309 | 168, | ||
310 | SSL_ALL_CIPHERS, | ||
311 | SSL_ALL_STRENGTHS, | ||
312 | }, | ||
313 | /* Cipher 0E */ | ||
314 | { | ||
315 | 0, | ||
316 | SSL3_TXT_DH_RSA_DES_40_CBC_SHA, | ||
317 | SSL3_CK_DH_RSA_DES_40_CBC_SHA, | ||
318 | SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
319 | SSL_EXPORT|SSL_EXP40, | ||
320 | 0, | ||
321 | 40, | ||
322 | 56, | ||
323 | SSL_ALL_CIPHERS, | ||
324 | SSL_ALL_STRENGTHS, | ||
325 | }, | ||
326 | /* Cipher 0F */ | ||
327 | { | ||
328 | 0, | ||
329 | SSL3_TXT_DH_RSA_DES_64_CBC_SHA, | ||
330 | SSL3_CK_DH_RSA_DES_64_CBC_SHA, | ||
331 | SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
332 | SSL_NOT_EXP|SSL_LOW, | ||
333 | 0, | ||
334 | 56, | ||
335 | 56, | ||
336 | SSL_ALL_CIPHERS, | ||
337 | SSL_ALL_STRENGTHS, | ||
338 | }, | ||
339 | /* Cipher 10 */ | ||
340 | { | ||
341 | 0, | ||
342 | SSL3_TXT_DH_RSA_DES_192_CBC3_SHA, | ||
343 | SSL3_CK_DH_RSA_DES_192_CBC3_SHA, | ||
344 | SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
345 | SSL_NOT_EXP|SSL_HIGH, | ||
346 | 0, | ||
347 | 168, | ||
348 | 168, | ||
349 | SSL_ALL_CIPHERS, | ||
350 | SSL_ALL_STRENGTHS, | ||
351 | }, | ||
352 | |||
353 | /* The Ephemeral DH ciphers */ | ||
354 | /* Cipher 11 */ | ||
355 | { | ||
356 | 1, | ||
357 | SSL3_TXT_EDH_DSS_DES_40_CBC_SHA, | ||
358 | SSL3_CK_EDH_DSS_DES_40_CBC_SHA, | ||
359 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
360 | SSL_EXPORT|SSL_EXP40, | ||
361 | 0, | ||
362 | 40, | ||
363 | 56, | ||
364 | SSL_ALL_CIPHERS, | ||
365 | SSL_ALL_STRENGTHS, | ||
366 | }, | ||
367 | /* Cipher 12 */ | ||
368 | { | ||
369 | 1, | ||
370 | SSL3_TXT_EDH_DSS_DES_64_CBC_SHA, | ||
371 | SSL3_CK_EDH_DSS_DES_64_CBC_SHA, | ||
372 | SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
373 | SSL_NOT_EXP|SSL_LOW, | ||
374 | 0, | ||
375 | 56, | ||
376 | 56, | ||
377 | SSL_ALL_CIPHERS, | ||
378 | SSL_ALL_STRENGTHS, | ||
379 | }, | ||
380 | /* Cipher 13 */ | ||
381 | { | ||
382 | 1, | ||
383 | SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA, | ||
384 | SSL3_CK_EDH_DSS_DES_192_CBC3_SHA, | ||
385 | SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
386 | SSL_NOT_EXP|SSL_HIGH, | ||
387 | 0, | ||
388 | 168, | ||
389 | 168, | ||
390 | SSL_ALL_CIPHERS, | ||
391 | SSL_ALL_STRENGTHS, | ||
392 | }, | ||
393 | /* Cipher 14 */ | ||
394 | { | ||
395 | 1, | ||
396 | SSL3_TXT_EDH_RSA_DES_40_CBC_SHA, | ||
397 | SSL3_CK_EDH_RSA_DES_40_CBC_SHA, | ||
398 | SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3, | ||
399 | SSL_EXPORT|SSL_EXP40, | ||
400 | 0, | ||
401 | 40, | ||
402 | 56, | ||
403 | SSL_ALL_CIPHERS, | ||
404 | SSL_ALL_STRENGTHS, | ||
405 | }, | ||
406 | /* Cipher 15 */ | ||
407 | { | ||
408 | 1, | ||
409 | SSL3_TXT_EDH_RSA_DES_64_CBC_SHA, | ||
410 | SSL3_CK_EDH_RSA_DES_64_CBC_SHA, | ||
411 | SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3, | ||
412 | SSL_NOT_EXP|SSL_LOW, | ||
413 | 0, | ||
414 | 56, | ||
415 | 56, | ||
416 | SSL_ALL_CIPHERS, | ||
417 | SSL_ALL_STRENGTHS, | ||
418 | }, | ||
419 | /* Cipher 16 */ | ||
420 | { | ||
421 | 1, | ||
422 | SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA, | ||
423 | SSL3_CK_EDH_RSA_DES_192_CBC3_SHA, | ||
424 | SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3, | ||
425 | SSL_NOT_EXP|SSL_HIGH, | ||
426 | 0, | ||
427 | 168, | ||
428 | 168, | ||
429 | SSL_ALL_CIPHERS, | ||
430 | SSL_ALL_STRENGTHS, | ||
431 | }, | ||
432 | |||
433 | /* Fortezza */ | ||
434 | /* Cipher 1C */ | ||
435 | { | ||
436 | 0, | ||
437 | SSL3_TXT_FZA_DMS_NULL_SHA, | ||
438 | SSL3_CK_FZA_DMS_NULL_SHA, | ||
439 | SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3, | ||
440 | SSL_NOT_EXP, | ||
441 | 0, | ||
442 | 0, | ||
443 | 0, | ||
444 | SSL_ALL_CIPHERS, | ||
445 | SSL_ALL_STRENGTHS, | ||
446 | }, | ||
447 | |||
448 | /* Cipher 1D */ | ||
449 | { | ||
450 | 0, | ||
451 | SSL3_TXT_FZA_DMS_FZA_SHA, | ||
452 | SSL3_CK_FZA_DMS_FZA_SHA, | ||
453 | SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3, | ||
454 | SSL_NOT_EXP, | ||
455 | 0, | ||
456 | 0, | ||
457 | 0, | ||
458 | SSL_ALL_CIPHERS, | ||
459 | SSL_ALL_STRENGTHS, | ||
460 | }, | ||
461 | |||
462 | /* Cipher 1E */ | ||
463 | { | ||
464 | 0, | ||
465 | SSL3_TXT_FZA_DMS_RC4_SHA, | ||
466 | SSL3_CK_FZA_DMS_RC4_SHA, | ||
467 | SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3, | ||
468 | SSL_NOT_EXP, | ||
469 | 0, | ||
470 | 128, | ||
471 | 128, | ||
472 | SSL_ALL_CIPHERS, | ||
473 | SSL_ALL_STRENGTHS, | ||
474 | }, | ||
475 | |||
476 | #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES | ||
477 | /* New TLS Export CipherSuites */ | ||
478 | /* Cipher 60 */ | ||
479 | { | ||
480 | 1, | ||
481 | TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5, | ||
482 | TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5, | ||
483 | SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1, | ||
484 | SSL_EXPORT|SSL_EXP56, | ||
485 | 0, | ||
486 | 56, | ||
487 | 128, | ||
488 | SSL_ALL_CIPHERS, | ||
489 | SSL_ALL_STRENGTHS, | ||
490 | }, | ||
491 | /* Cipher 61 */ | ||
492 | { | ||
493 | 1, | ||
494 | TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5, | ||
495 | TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5, | ||
496 | SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1, | ||
497 | SSL_EXPORT|SSL_EXP56, | ||
498 | 0, | ||
499 | 56, | ||
500 | 128, | ||
501 | SSL_ALL_CIPHERS, | ||
502 | SSL_ALL_STRENGTHS, | ||
503 | }, | ||
504 | /* Cipher 62 */ | ||
505 | { | ||
506 | 1, | ||
507 | TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA, | ||
508 | TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA, | ||
509 | SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1, | ||
510 | SSL_EXPORT|SSL_EXP56, | ||
511 | 0, | ||
512 | 56, | ||
513 | 56, | ||
514 | SSL_ALL_CIPHERS, | ||
515 | SSL_ALL_STRENGTHS, | ||
516 | }, | ||
517 | /* Cipher 63 */ | ||
518 | { | ||
519 | 1, | ||
520 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | ||
521 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA, | ||
522 | SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1, | ||
523 | SSL_EXPORT|SSL_EXP56, | ||
524 | 0, | ||
525 | 56, | ||
526 | 56, | ||
527 | SSL_ALL_CIPHERS, | ||
528 | SSL_ALL_STRENGTHS, | ||
529 | }, | ||
530 | /* Cipher 64 */ | ||
531 | { | ||
532 | 1, | ||
533 | TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA, | ||
534 | TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA, | ||
535 | SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
536 | SSL_EXPORT|SSL_EXP56, | ||
537 | 0, | ||
538 | 56, | ||
539 | 128, | ||
540 | SSL_ALL_CIPHERS, | ||
541 | SSL_ALL_STRENGTHS, | ||
542 | }, | ||
543 | /* Cipher 65 */ | ||
544 | { | ||
545 | 1, | ||
546 | TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA, | ||
547 | TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA, | ||
548 | SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
549 | SSL_EXPORT|SSL_EXP56, | ||
550 | 0, | ||
551 | 56, | ||
552 | 128, | ||
553 | SSL_ALL_CIPHERS, | ||
554 | SSL_ALL_STRENGTHS, | ||
555 | }, | ||
556 | /* Cipher 66 */ | ||
557 | { | ||
558 | 1, | ||
559 | TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA, | ||
560 | TLS1_CK_DHE_DSS_WITH_RC4_128_SHA, | ||
561 | SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1, | ||
562 | SSL_NOT_EXP, | ||
563 | 0, | ||
564 | 128, | ||
565 | 128, | ||
566 | SSL_ALL_CIPHERS, | ||
567 | SSL_ALL_STRENGTHS | ||
568 | }, | ||
569 | #endif | ||
570 | |||
571 | /* end of list */ | ||
572 | }; | ||
573 | |||
574 | static SSL3_ENC_METHOD SSLv3_enc_data={ | ||
575 | ssl3_enc, | ||
576 | ssl3_mac, | ||
577 | ssl3_setup_key_block, | ||
578 | ssl3_generate_master_secret, | ||
579 | ssl3_change_cipher_state, | ||
580 | ssl3_final_finish_mac, | ||
581 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, | ||
582 | ssl3_cert_verify_mac, | ||
583 | SSL3_MD_CLIENT_FINISHED_CONST,4, | ||
584 | SSL3_MD_SERVER_FINISHED_CONST,4, | ||
585 | ssl3_alert_code, | ||
586 | }; | ||
587 | |||
588 | static SSL_METHOD SSLv3_data= { | ||
589 | SSL3_VERSION, | ||
590 | ssl3_new, | ||
591 | ssl3_clear, | ||
592 | ssl3_free, | ||
593 | ssl_undefined_function, | ||
594 | ssl_undefined_function, | ||
595 | ssl3_read, | ||
596 | ssl3_peek, | ||
597 | ssl3_write, | ||
598 | ssl3_shutdown, | ||
599 | ssl3_renegotiate, | ||
600 | ssl3_renegotiate_check, | ||
601 | ssl3_ctrl, | ||
602 | ssl3_ctx_ctrl, | ||
603 | ssl3_get_cipher_by_char, | ||
604 | ssl3_put_cipher_by_char, | ||
605 | ssl3_pending, | ||
606 | ssl3_num_ciphers, | ||
607 | ssl3_get_cipher, | ||
608 | ssl_bad_method, | ||
609 | ssl3_default_timeout, | ||
610 | &SSLv3_enc_data, | ||
611 | ssl_undefined_function, | ||
612 | ssl3_callback_ctrl, | ||
613 | ssl3_ctx_callback_ctrl, | ||
614 | }; | ||
615 | |||
616 | static long ssl3_default_timeout(void) | ||
617 | { | ||
618 | /* 2 hours, the 24 hours mentioned in the SSLv3 spec | ||
619 | * is way too long for http, the cache would over fill */ | ||
620 | return(60*60*2); | ||
621 | } | ||
622 | |||
623 | SSL_METHOD *sslv3_base_method(void) | ||
624 | { | ||
625 | return(&SSLv3_data); | ||
626 | } | ||
627 | |||
628 | int ssl3_num_ciphers(void) | ||
629 | { | ||
630 | return(SSL3_NUM_CIPHERS); | ||
631 | } | ||
632 | |||
633 | SSL_CIPHER *ssl3_get_cipher(unsigned int u) | ||
634 | { | ||
635 | if (u < SSL3_NUM_CIPHERS) | ||
636 | return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u])); | ||
637 | else | ||
638 | return(NULL); | ||
639 | } | ||
640 | |||
641 | /* The problem is that it may not be the correct record type */ | ||
642 | int ssl3_pending(SSL *s) | ||
643 | { | ||
644 | return(s->s3->rrec.length); | ||
645 | } | ||
646 | |||
647 | int ssl3_new(SSL *s) | ||
648 | { | ||
649 | SSL3_STATE *s3; | ||
650 | |||
651 | if ((s3=Malloc(sizeof *s3)) == NULL) goto err; | ||
652 | memset(s3,0,sizeof *s3); | ||
653 | |||
654 | s->s3=s3; | ||
655 | |||
656 | s->method->ssl_clear(s); | ||
657 | return(1); | ||
658 | err: | ||
659 | return(0); | ||
660 | } | ||
661 | |||
662 | void ssl3_free(SSL *s) | ||
663 | { | ||
664 | if(s == NULL) | ||
665 | return; | ||
666 | |||
667 | ssl3_cleanup_key_block(s); | ||
668 | if (s->s3->rbuf.buf != NULL) | ||
669 | Free(s->s3->rbuf.buf); | ||
670 | if (s->s3->wbuf.buf != NULL) | ||
671 | Free(s->s3->wbuf.buf); | ||
672 | if (s->s3->rrec.comp != NULL) | ||
673 | Free(s->s3->rrec.comp); | ||
674 | #ifndef NO_DH | ||
675 | if (s->s3->tmp.dh != NULL) | ||
676 | DH_free(s->s3->tmp.dh); | ||
677 | #endif | ||
678 | if (s->s3->tmp.ca_names != NULL) | ||
679 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
680 | memset(s->s3,0,sizeof *s->s3); | ||
681 | Free(s->s3); | ||
682 | s->s3=NULL; | ||
683 | } | ||
684 | |||
685 | void ssl3_clear(SSL *s) | ||
686 | { | ||
687 | unsigned char *rp,*wp; | ||
688 | |||
689 | ssl3_cleanup_key_block(s); | ||
690 | if (s->s3->tmp.ca_names != NULL) | ||
691 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | ||
692 | |||
693 | if (s->s3->rrec.comp != NULL) | ||
694 | { | ||
695 | Free(s->s3->rrec.comp); | ||
696 | s->s3->rrec.comp=NULL; | ||
697 | } | ||
698 | #ifndef NO_DH | ||
699 | if (s->s3->tmp.dh != NULL) | ||
700 | DH_free(s->s3->tmp.dh); | ||
701 | #endif | ||
702 | |||
703 | rp=s->s3->rbuf.buf; | ||
704 | wp=s->s3->wbuf.buf; | ||
705 | |||
706 | memset(s->s3,0,sizeof *s->s3); | ||
707 | if (rp != NULL) s->s3->rbuf.buf=rp; | ||
708 | if (wp != NULL) s->s3->wbuf.buf=wp; | ||
709 | |||
710 | ssl_free_wbio_buffer(s); | ||
711 | |||
712 | s->packet_length=0; | ||
713 | s->s3->renegotiate=0; | ||
714 | s->s3->total_renegotiations=0; | ||
715 | s->s3->num_renegotiations=0; | ||
716 | s->s3->in_read_app_data=0; | ||
717 | s->version=SSL3_VERSION; | ||
718 | } | ||
719 | |||
720 | long ssl3_ctrl(SSL *s, int cmd, long larg, char *parg) | ||
721 | { | ||
722 | int ret=0; | ||
723 | |||
724 | #if !defined(NO_DSA) || !defined(NO_RSA) | ||
725 | if ( | ||
726 | #ifndef NO_RSA | ||
727 | cmd == SSL_CTRL_SET_TMP_RSA || | ||
728 | cmd == SSL_CTRL_SET_TMP_RSA_CB || | ||
729 | #endif | ||
730 | #ifndef NO_DSA | ||
731 | cmd == SSL_CTRL_SET_TMP_DH || | ||
732 | cmd == SSL_CTRL_SET_TMP_DH_CB || | ||
733 | #endif | ||
734 | 0) | ||
735 | { | ||
736 | if (!ssl_cert_inst(&s->cert)) | ||
737 | { | ||
738 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE); | ||
739 | return(0); | ||
740 | } | ||
741 | } | ||
742 | #endif | ||
743 | |||
744 | switch (cmd) | ||
745 | { | ||
746 | case SSL_CTRL_GET_SESSION_REUSED: | ||
747 | ret=s->hit; | ||
748 | break; | ||
749 | case SSL_CTRL_GET_CLIENT_CERT_REQUEST: | ||
750 | break; | ||
751 | case SSL_CTRL_GET_NUM_RENEGOTIATIONS: | ||
752 | ret=s->s3->num_renegotiations; | ||
753 | break; | ||
754 | case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS: | ||
755 | ret=s->s3->num_renegotiations; | ||
756 | s->s3->num_renegotiations=0; | ||
757 | break; | ||
758 | case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS: | ||
759 | ret=s->s3->total_renegotiations; | ||
760 | break; | ||
761 | case SSL_CTRL_GET_FLAGS: | ||
762 | ret=(int)(s->s3->flags); | ||
763 | break; | ||
764 | #ifndef NO_RSA | ||
765 | case SSL_CTRL_NEED_TMP_RSA: | ||
766 | if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) && | ||
767 | ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) || | ||
768 | (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))) | ||
769 | ret = 1; | ||
770 | break; | ||
771 | case SSL_CTRL_SET_TMP_RSA: | ||
772 | { | ||
773 | RSA *rsa = (RSA *)parg; | ||
774 | if (rsa == NULL) | ||
775 | { | ||
776 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER); | ||
777 | return(ret); | ||
778 | } | ||
779 | if ((rsa = RSAPrivateKey_dup(rsa)) == NULL) | ||
780 | { | ||
781 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB); | ||
782 | return(ret); | ||
783 | } | ||
784 | if (s->cert->rsa_tmp != NULL) | ||
785 | RSA_free(s->cert->rsa_tmp); | ||
786 | s->cert->rsa_tmp = rsa; | ||
787 | ret = 1; | ||
788 | } | ||
789 | break; | ||
790 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
791 | { | ||
792 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
793 | return(ret); | ||
794 | } | ||
795 | break; | ||
796 | #endif | ||
797 | #ifndef NO_DH | ||
798 | case SSL_CTRL_SET_TMP_DH: | ||
799 | { | ||
800 | DH *dh = (DH *)parg; | ||
801 | if (dh == NULL) | ||
802 | { | ||
803 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER); | ||
804 | return(ret); | ||
805 | } | ||
806 | if ((dh = DHparams_dup(dh)) == NULL) | ||
807 | { | ||
808 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB); | ||
809 | return(ret); | ||
810 | } | ||
811 | if (!(s->options & SSL_OP_SINGLE_DH_USE)) | ||
812 | { | ||
813 | if (!DH_generate_key(dh)) | ||
814 | { | ||
815 | DH_free(dh); | ||
816 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB); | ||
817 | return(ret); | ||
818 | } | ||
819 | } | ||
820 | if (s->cert->dh_tmp != NULL) | ||
821 | DH_free(s->cert->dh_tmp); | ||
822 | s->cert->dh_tmp = dh; | ||
823 | ret = 1; | ||
824 | } | ||
825 | break; | ||
826 | case SSL_CTRL_SET_TMP_DH_CB: | ||
827 | { | ||
828 | SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
829 | return(ret); | ||
830 | } | ||
831 | break; | ||
832 | #endif | ||
833 | default: | ||
834 | break; | ||
835 | } | ||
836 | return(ret); | ||
837 | } | ||
838 | |||
839 | long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)()) | ||
840 | { | ||
841 | int ret=0; | ||
842 | |||
843 | #if !defined(NO_DSA) || !defined(NO_RSA) | ||
844 | if ( | ||
845 | #ifndef NO_RSA | ||
846 | cmd == SSL_CTRL_SET_TMP_RSA_CB || | ||
847 | #endif | ||
848 | #ifndef NO_DSA | ||
849 | cmd == SSL_CTRL_SET_TMP_DH_CB || | ||
850 | #endif | ||
851 | 0) | ||
852 | { | ||
853 | if (!ssl_cert_inst(&s->cert)) | ||
854 | { | ||
855 | SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE); | ||
856 | return(0); | ||
857 | } | ||
858 | } | ||
859 | #endif | ||
860 | |||
861 | switch (cmd) | ||
862 | { | ||
863 | #ifndef NO_RSA | ||
864 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
865 | { | ||
866 | s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp; | ||
867 | } | ||
868 | break; | ||
869 | #endif | ||
870 | #ifndef NO_DH | ||
871 | case SSL_CTRL_SET_TMP_DH_CB: | ||
872 | { | ||
873 | s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp; | ||
874 | } | ||
875 | break; | ||
876 | #endif | ||
877 | default: | ||
878 | break; | ||
879 | } | ||
880 | return(ret); | ||
881 | } | ||
882 | |||
883 | long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, char *parg) | ||
884 | { | ||
885 | CERT *cert; | ||
886 | |||
887 | cert=ctx->cert; | ||
888 | |||
889 | switch (cmd) | ||
890 | { | ||
891 | #ifndef NO_RSA | ||
892 | case SSL_CTRL_NEED_TMP_RSA: | ||
893 | if ( (cert->rsa_tmp == NULL) && | ||
894 | ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) || | ||
895 | (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))) | ||
896 | ) | ||
897 | return(1); | ||
898 | else | ||
899 | return(0); | ||
900 | /* break; */ | ||
901 | case SSL_CTRL_SET_TMP_RSA: | ||
902 | { | ||
903 | RSA *rsa; | ||
904 | int i; | ||
905 | |||
906 | rsa=(RSA *)parg; | ||
907 | i=1; | ||
908 | if (rsa == NULL) | ||
909 | i=0; | ||
910 | else | ||
911 | { | ||
912 | if ((rsa=RSAPrivateKey_dup(rsa)) == NULL) | ||
913 | i=0; | ||
914 | } | ||
915 | if (!i) | ||
916 | { | ||
917 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB); | ||
918 | return(0); | ||
919 | } | ||
920 | else | ||
921 | { | ||
922 | if (cert->rsa_tmp != NULL) | ||
923 | RSA_free(cert->rsa_tmp); | ||
924 | cert->rsa_tmp=rsa; | ||
925 | return(1); | ||
926 | } | ||
927 | } | ||
928 | /* break; */ | ||
929 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
930 | { | ||
931 | SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
932 | return(0); | ||
933 | } | ||
934 | break; | ||
935 | #endif | ||
936 | #ifndef NO_DH | ||
937 | case SSL_CTRL_SET_TMP_DH: | ||
938 | { | ||
939 | DH *new=NULL,*dh; | ||
940 | |||
941 | dh=(DH *)parg; | ||
942 | if ((new=DHparams_dup(dh)) == NULL) | ||
943 | { | ||
944 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB); | ||
945 | return 0; | ||
946 | } | ||
947 | if (!(ctx->options & SSL_OP_SINGLE_DH_USE)) | ||
948 | { | ||
949 | if (!DH_generate_key(new)) | ||
950 | { | ||
951 | SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB); | ||
952 | DH_free(new); | ||
953 | return 0; | ||
954 | } | ||
955 | } | ||
956 | if (cert->dh_tmp != NULL) | ||
957 | DH_free(cert->dh_tmp); | ||
958 | cert->dh_tmp=new; | ||
959 | return 1; | ||
960 | } | ||
961 | /*break; */ | ||
962 | case SSL_CTRL_SET_TMP_DH_CB: | ||
963 | { | ||
964 | SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
965 | return(0); | ||
966 | } | ||
967 | break; | ||
968 | #endif | ||
969 | /* A Thawte special :-) */ | ||
970 | case SSL_CTRL_EXTRA_CHAIN_CERT: | ||
971 | if (ctx->extra_certs == NULL) | ||
972 | { | ||
973 | if ((ctx->extra_certs=sk_X509_new_null()) == NULL) | ||
974 | return(0); | ||
975 | } | ||
976 | sk_X509_push(ctx->extra_certs,(X509 *)parg); | ||
977 | break; | ||
978 | |||
979 | default: | ||
980 | return(0); | ||
981 | } | ||
982 | return(1); | ||
983 | } | ||
984 | |||
985 | long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | ||
986 | { | ||
987 | CERT *cert; | ||
988 | |||
989 | cert=ctx->cert; | ||
990 | |||
991 | switch (cmd) | ||
992 | { | ||
993 | #ifndef NO_RSA | ||
994 | case SSL_CTRL_SET_TMP_RSA_CB: | ||
995 | { | ||
996 | cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp; | ||
997 | } | ||
998 | break; | ||
999 | #endif | ||
1000 | #ifndef NO_DH | ||
1001 | case SSL_CTRL_SET_TMP_DH_CB: | ||
1002 | { | ||
1003 | cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp; | ||
1004 | } | ||
1005 | break; | ||
1006 | #endif | ||
1007 | default: | ||
1008 | return(0); | ||
1009 | } | ||
1010 | return(1); | ||
1011 | } | ||
1012 | |||
1013 | /* This function needs to check if the ciphers required are actually | ||
1014 | * available */ | ||
1015 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p) | ||
1016 | { | ||
1017 | static int init=1; | ||
1018 | static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS]; | ||
1019 | SSL_CIPHER c,*cp= &c,**cpp; | ||
1020 | unsigned long id; | ||
1021 | int i; | ||
1022 | |||
1023 | if (init) | ||
1024 | { | ||
1025 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
1026 | |||
1027 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | ||
1028 | sorted[i]= &(ssl3_ciphers[i]); | ||
1029 | |||
1030 | qsort( (char *)sorted, | ||
1031 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
1032 | FP_ICC ssl_cipher_ptr_id_cmp); | ||
1033 | |||
1034 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
1035 | |||
1036 | init=0; | ||
1037 | } | ||
1038 | |||
1039 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; | ||
1040 | c.id=id; | ||
1041 | cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp, | ||
1042 | (char *)sorted, | ||
1043 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | ||
1044 | (int (*)())ssl_cipher_ptr_id_cmp); | ||
1045 | if ((cpp == NULL) || !(*cpp)->valid) | ||
1046 | return(NULL); | ||
1047 | else | ||
1048 | return(*cpp); | ||
1049 | } | ||
1050 | |||
1051 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p) | ||
1052 | { | ||
1053 | long l; | ||
1054 | |||
1055 | if (p != NULL) | ||
1056 | { | ||
1057 | l=c->id; | ||
1058 | if ((l & 0xff000000) != 0x03000000) return(0); | ||
1059 | p[0]=((unsigned char)(l>> 8L))&0xFF; | ||
1060 | p[1]=((unsigned char)(l ))&0xFF; | ||
1061 | } | ||
1062 | return(2); | ||
1063 | } | ||
1064 | |||
1065 | SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *have, | ||
1066 | STACK_OF(SSL_CIPHER) *pref) | ||
1067 | { | ||
1068 | SSL_CIPHER *c,*ret=NULL; | ||
1069 | int i,j,ok; | ||
1070 | CERT *cert; | ||
1071 | unsigned long alg,mask,emask; | ||
1072 | |||
1073 | /* Let's see which ciphers we can support */ | ||
1074 | cert=s->cert; | ||
1075 | |||
1076 | sk_SSL_CIPHER_set_cmp_func(pref,ssl_cipher_ptr_id_cmp); | ||
1077 | |||
1078 | #ifdef CIPHER_DEBUG | ||
1079 | printf("Have:\n"); | ||
1080 | for(i=0 ; i < sk_num(pref) ; ++i) | ||
1081 | { | ||
1082 | c=(SSL_CIPHER *)sk_value(pref,i); | ||
1083 | printf("%p:%s\n",c,c->name); | ||
1084 | } | ||
1085 | #endif | ||
1086 | |||
1087 | for (i=0; i<sk_SSL_CIPHER_num(have); i++) | ||
1088 | { | ||
1089 | c=sk_SSL_CIPHER_value(have,i); | ||
1090 | |||
1091 | ssl_set_cert_masks(cert,c); | ||
1092 | mask=cert->mask; | ||
1093 | emask=cert->export_mask; | ||
1094 | |||
1095 | alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
1096 | if (SSL_C_IS_EXPORT(c)) | ||
1097 | { | ||
1098 | ok=((alg & emask) == alg)?1:0; | ||
1099 | #ifdef CIPHER_DEBUG | ||
1100 | printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask, | ||
1101 | c,c->name); | ||
1102 | #endif | ||
1103 | } | ||
1104 | else | ||
1105 | { | ||
1106 | ok=((alg & mask) == alg)?1:0; | ||
1107 | #ifdef CIPHER_DEBUG | ||
1108 | printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c, | ||
1109 | c->name); | ||
1110 | #endif | ||
1111 | } | ||
1112 | |||
1113 | if (!ok) continue; | ||
1114 | |||
1115 | j=sk_SSL_CIPHER_find(pref,c); | ||
1116 | if (j >= 0) | ||
1117 | { | ||
1118 | ret=sk_SSL_CIPHER_value(pref,j); | ||
1119 | break; | ||
1120 | } | ||
1121 | } | ||
1122 | return(ret); | ||
1123 | } | ||
1124 | |||
1125 | int ssl3_get_req_cert_type(SSL *s, unsigned char *p) | ||
1126 | { | ||
1127 | int ret=0; | ||
1128 | unsigned long alg; | ||
1129 | |||
1130 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1131 | |||
1132 | #ifndef NO_DH | ||
1133 | if (alg & (SSL_kDHr|SSL_kEDH)) | ||
1134 | { | ||
1135 | # ifndef NO_RSA | ||
1136 | p[ret++]=SSL3_CT_RSA_FIXED_DH; | ||
1137 | # endif | ||
1138 | # ifndef NO_DSA | ||
1139 | p[ret++]=SSL3_CT_DSS_FIXED_DH; | ||
1140 | # endif | ||
1141 | } | ||
1142 | if ((s->version == SSL3_VERSION) && | ||
1143 | (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr))) | ||
1144 | { | ||
1145 | # ifndef NO_RSA | ||
1146 | p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH; | ||
1147 | # endif | ||
1148 | # ifndef NO_DSA | ||
1149 | p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH; | ||
1150 | # endif | ||
1151 | } | ||
1152 | #endif /* !NO_DH */ | ||
1153 | #ifndef NO_RSA | ||
1154 | p[ret++]=SSL3_CT_RSA_SIGN; | ||
1155 | #endif | ||
1156 | #ifndef NO_DSA | ||
1157 | p[ret++]=SSL3_CT_DSS_SIGN; | ||
1158 | #endif | ||
1159 | return(ret); | ||
1160 | } | ||
1161 | |||
1162 | int ssl3_shutdown(SSL *s) | ||
1163 | { | ||
1164 | |||
1165 | /* Don't do anything much if we have not done the handshake or | ||
1166 | * we don't want to send messages :-) */ | ||
1167 | if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE)) | ||
1168 | { | ||
1169 | s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); | ||
1170 | return(1); | ||
1171 | } | ||
1172 | |||
1173 | if (!(s->shutdown & SSL_SENT_SHUTDOWN)) | ||
1174 | { | ||
1175 | s->shutdown|=SSL_SENT_SHUTDOWN; | ||
1176 | #if 1 | ||
1177 | ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY); | ||
1178 | #endif | ||
1179 | /* our shutdown alert has been sent now, and if it still needs | ||
1180 | * to be written, s->s3->alert_dispatch will be true */ | ||
1181 | } | ||
1182 | else if (s->s3->alert_dispatch) | ||
1183 | { | ||
1184 | /* resend it if not sent */ | ||
1185 | #if 1 | ||
1186 | ssl3_dispatch_alert(s); | ||
1187 | #endif | ||
1188 | } | ||
1189 | else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) | ||
1190 | { | ||
1191 | /* If we are waiting for a close from our peer, we are closed */ | ||
1192 | ssl3_read_bytes(s,0,NULL,0); | ||
1193 | } | ||
1194 | |||
1195 | if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) && | ||
1196 | !s->s3->alert_dispatch) | ||
1197 | return(1); | ||
1198 | else | ||
1199 | return(0); | ||
1200 | } | ||
1201 | |||
1202 | int ssl3_write(SSL *s, const void *buf, int len) | ||
1203 | { | ||
1204 | int ret,n; | ||
1205 | |||
1206 | #if 0 | ||
1207 | if (s->shutdown & SSL_SEND_SHUTDOWN) | ||
1208 | { | ||
1209 | s->rwstate=SSL_NOTHING; | ||
1210 | return(0); | ||
1211 | } | ||
1212 | #endif | ||
1213 | clear_sys_error(); | ||
1214 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
1215 | |||
1216 | /* This is an experimental flag that sends the | ||
1217 | * last handshake message in the same packet as the first | ||
1218 | * use data - used to see if it helps the TCP protocol during | ||
1219 | * session-id reuse */ | ||
1220 | /* The second test is because the buffer may have been removed */ | ||
1221 | if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio)) | ||
1222 | { | ||
1223 | /* First time through, we write into the buffer */ | ||
1224 | if (s->s3->delay_buf_pop_ret == 0) | ||
1225 | { | ||
1226 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
1227 | buf,len); | ||
1228 | if (ret <= 0) return(ret); | ||
1229 | |||
1230 | s->s3->delay_buf_pop_ret=ret; | ||
1231 | } | ||
1232 | |||
1233 | s->rwstate=SSL_WRITING; | ||
1234 | n=BIO_flush(s->wbio); | ||
1235 | if (n <= 0) return(n); | ||
1236 | s->rwstate=SSL_NOTHING; | ||
1237 | |||
1238 | /* We have flushed the buffer, so remove it */ | ||
1239 | ssl_free_wbio_buffer(s); | ||
1240 | s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER; | ||
1241 | |||
1242 | ret=s->s3->delay_buf_pop_ret; | ||
1243 | s->s3->delay_buf_pop_ret=0; | ||
1244 | } | ||
1245 | else | ||
1246 | { | ||
1247 | ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA, | ||
1248 | buf,len); | ||
1249 | if (ret <= 0) return(ret); | ||
1250 | } | ||
1251 | |||
1252 | return(ret); | ||
1253 | } | ||
1254 | |||
1255 | int ssl3_read(SSL *s, void *buf, int len) | ||
1256 | { | ||
1257 | int ret; | ||
1258 | |||
1259 | clear_sys_error(); | ||
1260 | if (s->s3->renegotiate) ssl3_renegotiate_check(s); | ||
1261 | s->s3->in_read_app_data=1; | ||
1262 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); | ||
1263 | if ((ret == -1) && (s->s3->in_read_app_data == 0)) | ||
1264 | { | ||
1265 | /* ssl3_read_bytes decided to call s->handshake_func, which | ||
1266 | * called ssl3_read_bytes to read handshake data. | ||
1267 | * However, ssl3_read_bytes actually found application data | ||
1268 | * and thinks that application data makes sense here (signalled | ||
1269 | * by resetting 'in_read_app_data', strangely); so disable | ||
1270 | * handshake processing and try to read application data again. */ | ||
1271 | s->in_handshake++; | ||
1272 | ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len); | ||
1273 | s->in_handshake--; | ||
1274 | } | ||
1275 | else | ||
1276 | s->s3->in_read_app_data=0; | ||
1277 | |||
1278 | return(ret); | ||
1279 | } | ||
1280 | |||
1281 | int ssl3_peek(SSL *s, char *buf, int len) | ||
1282 | { | ||
1283 | SSL3_RECORD *rr; | ||
1284 | int n; | ||
1285 | |||
1286 | rr= &(s->s3->rrec); | ||
1287 | if ((rr->length == 0) || (rr->type != SSL3_RT_APPLICATION_DATA)) | ||
1288 | { | ||
1289 | n=ssl3_read(s,buf,1); | ||
1290 | if (n <= 0) return(n); | ||
1291 | rr->length++; | ||
1292 | rr->off--; | ||
1293 | } | ||
1294 | |||
1295 | if ((unsigned int)len > rr->length) | ||
1296 | n=rr->length; | ||
1297 | else | ||
1298 | n=len; | ||
1299 | memcpy(buf,&(rr->data[rr->off]),(unsigned int)n); | ||
1300 | return(n); | ||
1301 | } | ||
1302 | |||
1303 | int ssl3_renegotiate(SSL *s) | ||
1304 | { | ||
1305 | if (s->handshake_func == NULL) | ||
1306 | return(1); | ||
1307 | |||
1308 | if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) | ||
1309 | return(0); | ||
1310 | |||
1311 | s->s3->renegotiate=1; | ||
1312 | return(1); | ||
1313 | } | ||
1314 | |||
1315 | int ssl3_renegotiate_check(SSL *s) | ||
1316 | { | ||
1317 | int ret=0; | ||
1318 | |||
1319 | if (s->s3->renegotiate) | ||
1320 | { | ||
1321 | if ( (s->s3->rbuf.left == 0) && | ||
1322 | (s->s3->wbuf.left == 0) && | ||
1323 | !SSL_in_init(s)) | ||
1324 | { | ||
1325 | /* | ||
1326 | if we are the server, and we have sent a 'RENEGOTIATE' message, we | ||
1327 | need to go to SSL_ST_ACCEPT. | ||
1328 | */ | ||
1329 | /* SSL_ST_ACCEPT */ | ||
1330 | s->state=SSL_ST_RENEGOTIATE; | ||
1331 | s->s3->renegotiate=0; | ||
1332 | s->s3->num_renegotiations++; | ||
1333 | s->s3->total_renegotiations++; | ||
1334 | ret=1; | ||
1335 | } | ||
1336 | } | ||
1337 | return(ret); | ||
1338 | } | ||
1339 | |||
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c deleted file mode 100644 index eb965310d9..0000000000 --- a/src/lib/libssl/s3_pkt.c +++ /dev/null | |||
@@ -1,1194 +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-2000 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 <openssl/evp.h> | ||
116 | #include <openssl/buffer.h> | ||
117 | #include "ssl_locl.h" | ||
118 | |||
119 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | ||
120 | unsigned int len); | ||
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 = SSL3_RT_MAX_PACKET_SIZE - s->packet_length; | ||
166 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
167 | max_max += SSL3_RT_MAX_EXTRA; | ||
168 | if (max > max_max) | ||
169 | max = max_max; | ||
170 | } | ||
171 | if (n > max) /* does not happen */ | ||
172 | { | ||
173 | SSLerr(SSL_F_SSL3_READ_N,SSL_R_INTERNAL_ERROR); | ||
174 | return -1; | ||
175 | } | ||
176 | |||
177 | off = s->packet_length; | ||
178 | newb = s->s3->rbuf.left; | ||
179 | /* Move any available bytes to front of buffer: | ||
180 | * 'off' bytes already pointed to by 'packet', | ||
181 | * 'newb' extra ones at the end */ | ||
182 | if (s->packet != s->s3->rbuf.buf) | ||
183 | { | ||
184 | /* off > 0 */ | ||
185 | memmove(s->s3->rbuf.buf, s->packet, off+newb); | ||
186 | s->packet = s->s3->rbuf.buf; | ||
187 | } | ||
188 | |||
189 | while (newb < n) | ||
190 | { | ||
191 | /* Now we have off+newb bytes at the front of s->s3->rbuf.buf and need | ||
192 | * to read in more until we have off+n (up to off+max if possible) */ | ||
193 | |||
194 | clear_sys_error(); | ||
195 | if (s->rbio != NULL) | ||
196 | { | ||
197 | s->rwstate=SSL_READING; | ||
198 | i=BIO_read(s->rbio, &(s->s3->rbuf.buf[off+newb]), max-newb); | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | SSLerr(SSL_F_SSL3_READ_N,SSL_R_READ_BIO_NOT_SET); | ||
203 | i = -1; | ||
204 | } | ||
205 | |||
206 | if (i <= 0) | ||
207 | { | ||
208 | s->s3->rbuf.left = newb; | ||
209 | return(i); | ||
210 | } | ||
211 | newb+=i; | ||
212 | } | ||
213 | |||
214 | /* done reading, now the book-keeping */ | ||
215 | s->s3->rbuf.offset = off + n; | ||
216 | s->s3->rbuf.left = newb - n; | ||
217 | s->packet_length += n; | ||
218 | s->rwstate=SSL_NOTHING; | ||
219 | return(n); | ||
220 | } | ||
221 | |||
222 | /* Call this to get a new input record. | ||
223 | * It will return <= 0 if more data is needed, normally due to an error | ||
224 | * or non-blocking IO. | ||
225 | * When it finishes, one packet has been decoded and can be found in | ||
226 | * ssl->s3->rrec.type - is the type of record | ||
227 | * ssl->s3->rrec.data, - data | ||
228 | * ssl->s3->rrec.length, - number of bytes | ||
229 | */ | ||
230 | /* used only by ssl3_read_bytes */ | ||
231 | static int ssl3_get_record(SSL *s) | ||
232 | { | ||
233 | int ssl_major,ssl_minor,al; | ||
234 | int n,i,ret= -1; | ||
235 | SSL3_RECORD *rr; | ||
236 | SSL_SESSION *sess; | ||
237 | unsigned char *p; | ||
238 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
239 | short version; | ||
240 | unsigned int mac_size; | ||
241 | int clear=0,extra; | ||
242 | |||
243 | rr= &(s->s3->rrec); | ||
244 | sess=s->session; | ||
245 | |||
246 | if (s->options & SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER) | ||
247 | extra=SSL3_RT_MAX_EXTRA; | ||
248 | else | ||
249 | extra=0; | ||
250 | |||
251 | again: | ||
252 | /* check if we have the header */ | ||
253 | if ( (s->rstate != SSL_ST_READ_BODY) || | ||
254 | (s->packet_length < SSL3_RT_HEADER_LENGTH)) | ||
255 | { | ||
256 | n=ssl3_read_n(s,SSL3_RT_HEADER_LENGTH, | ||
257 | SSL3_RT_MAX_PACKET_SIZE,0); | ||
258 | if (n <= 0) return(n); /* error or non-blocking */ | ||
259 | s->rstate=SSL_ST_READ_BODY; | ||
260 | |||
261 | p=s->packet; | ||
262 | |||
263 | /* Pull apart the header into the SSL3_RECORD */ | ||
264 | rr->type= *(p++); | ||
265 | ssl_major= *(p++); | ||
266 | ssl_minor= *(p++); | ||
267 | version=(ssl_major<<8)|ssl_minor; | ||
268 | n2s(p,rr->length); | ||
269 | |||
270 | /* Lets check version */ | ||
271 | if (s->first_packet) | ||
272 | { | ||
273 | s->first_packet=0; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | if (version != s->version) | ||
278 | { | ||
279 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
280 | /* Send back error using their | ||
281 | * version number :-) */ | ||
282 | s->version=version; | ||
283 | al=SSL_AD_PROTOCOL_VERSION; | ||
284 | goto f_err; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | if ((version>>8) != SSL3_VERSION_MAJOR) | ||
289 | { | ||
290 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_WRONG_VERSION_NUMBER); | ||
291 | goto err; | ||
292 | } | ||
293 | |||
294 | if (rr->length > | ||
295 | (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
296 | { | ||
297 | al=SSL_AD_RECORD_OVERFLOW; | ||
298 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PACKET_LENGTH_TOO_LONG); | ||
299 | goto f_err; | ||
300 | } | ||
301 | |||
302 | /* now s->rstate == SSL_ST_READ_BODY */ | ||
303 | } | ||
304 | |||
305 | /* s->rstate == SSL_ST_READ_BODY, get and decode the data */ | ||
306 | |||
307 | if (rr->length > (s->packet_length-SSL3_RT_HEADER_LENGTH)) | ||
308 | { | ||
309 | /* now s->packet_length == SSL3_RT_HEADER_LENGTH */ | ||
310 | i=rr->length; | ||
311 | n=ssl3_read_n(s,i,i,1); | ||
312 | if (n <= 0) return(n); /* error or non-blocking io */ | ||
313 | /* now n == rr->length, | ||
314 | * and s->packet_length == SSL3_RT_HEADER_LENGTH + rr->length */ | ||
315 | } | ||
316 | |||
317 | s->rstate=SSL_ST_READ_HEADER; /* set state for later operations */ | ||
318 | |||
319 | /* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length, | ||
320 | * and we have that many bytes in s->packet | ||
321 | */ | ||
322 | rr->input= &(s->packet[SSL3_RT_HEADER_LENGTH]); | ||
323 | |||
324 | /* ok, we can now read from 's->packet' data into 'rr' | ||
325 | * rr->input points at rr->length bytes, which | ||
326 | * need to be copied into rr->data by either | ||
327 | * the decryption or by the decompression | ||
328 | * When the data is 'copied' into the rr->data buffer, | ||
329 | * rr->input will be pointed at the new buffer */ | ||
330 | |||
331 | /* We now have - encrypted [ MAC [ compressed [ plain ] ] ] | ||
332 | * rr->length bytes of encrypted compressed stuff. */ | ||
333 | |||
334 | /* check is not needed I believe */ | ||
335 | if (rr->length > (unsigned int)SSL3_RT_MAX_ENCRYPTED_LENGTH+extra) | ||
336 | { | ||
337 | al=SSL_AD_RECORD_OVERFLOW; | ||
338 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_ENCRYPTED_LENGTH_TOO_LONG); | ||
339 | goto f_err; | ||
340 | } | ||
341 | |||
342 | /* decrypt in place in 'rr->input' */ | ||
343 | rr->data=rr->input; | ||
344 | |||
345 | if (!s->method->ssl3_enc->enc(s,0)) | ||
346 | { | ||
347 | al=SSL_AD_DECRYPT_ERROR; | ||
348 | goto f_err; | ||
349 | } | ||
350 | #ifdef TLS_DEBUG | ||
351 | printf("dec %d\n",rr->length); | ||
352 | { unsigned int z; for (z=0; z<rr->length; z++) printf("%02X%c",rr->data[z],((z+1)%16)?' ':'\n'); } | ||
353 | printf("\n"); | ||
354 | #endif | ||
355 | /* r->length is now the compressed data plus mac */ | ||
356 | if ( (sess == NULL) || | ||
357 | (s->enc_read_ctx == NULL) || | ||
358 | (s->read_hash == NULL)) | ||
359 | clear=1; | ||
360 | |||
361 | if (!clear) | ||
362 | { | ||
363 | mac_size=EVP_MD_size(s->read_hash); | ||
364 | |||
365 | if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH+extra+mac_size) | ||
366 | { | ||
367 | al=SSL_AD_RECORD_OVERFLOW; | ||
368 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); | ||
369 | goto f_err; | ||
370 | } | ||
371 | /* check the MAC for rr->input (it's in mac_size bytes at the tail) */ | ||
372 | if (rr->length < mac_size) | ||
373 | { | ||
374 | al=SSL_AD_DECODE_ERROR; | ||
375 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT); | ||
376 | goto f_err; | ||
377 | } | ||
378 | rr->length-=mac_size; | ||
379 | i=s->method->ssl3_enc->mac(s,md,0); | ||
380 | if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0) | ||
381 | { | ||
382 | al=SSL_AD_BAD_RECORD_MAC; | ||
383 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_MAC_DECODE); | ||
384 | ret= -1; | ||
385 | goto f_err; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | /* r->length is now just compressed */ | ||
390 | if (s->expand != NULL) | ||
391 | { | ||
392 | if (rr->length > | ||
393 | (unsigned int)SSL3_RT_MAX_COMPRESSED_LENGTH+extra) | ||
394 | { | ||
395 | al=SSL_AD_RECORD_OVERFLOW; | ||
396 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_COMPRESSED_LENGTH_TOO_LONG); | ||
397 | goto f_err; | ||
398 | } | ||
399 | if (!do_uncompress(s)) | ||
400 | { | ||
401 | al=SSL_AD_DECOMPRESSION_FAILURE; | ||
402 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_BAD_DECOMPRESSION); | ||
403 | goto f_err; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | if (rr->length > (unsigned int)SSL3_RT_MAX_PLAIN_LENGTH+extra) | ||
408 | { | ||
409 | al=SSL_AD_RECORD_OVERFLOW; | ||
410 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DATA_LENGTH_TOO_LONG); | ||
411 | goto f_err; | ||
412 | } | ||
413 | |||
414 | rr->off=0; | ||
415 | /* So at this point the following is true | ||
416 | * ssl->s3->rrec.type is the type of record | ||
417 | * ssl->s3->rrec.length == number of bytes in record | ||
418 | * ssl->s3->rrec.off == offset to first valid byte | ||
419 | * ssl->s3->rrec.data == where to take bytes from, increment | ||
420 | * after use :-). | ||
421 | */ | ||
422 | |||
423 | /* we have pulled in a full packet so zero things */ | ||
424 | s->packet_length=0; | ||
425 | |||
426 | /* just read a 0 length packet */ | ||
427 | if (rr->length == 0) goto again; | ||
428 | |||
429 | return(1); | ||
430 | f_err: | ||
431 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
432 | err: | ||
433 | return(ret); | ||
434 | } | ||
435 | |||
436 | static int do_uncompress(SSL *ssl) | ||
437 | { | ||
438 | int i; | ||
439 | SSL3_RECORD *rr; | ||
440 | |||
441 | rr= &(ssl->s3->rrec); | ||
442 | i=COMP_expand_block(ssl->expand,rr->comp, | ||
443 | SSL3_RT_MAX_PLAIN_LENGTH,rr->data,(int)rr->length); | ||
444 | if (i < 0) | ||
445 | return(0); | ||
446 | else | ||
447 | rr->length=i; | ||
448 | rr->data=rr->comp; | ||
449 | |||
450 | return(1); | ||
451 | } | ||
452 | |||
453 | static int do_compress(SSL *ssl) | ||
454 | { | ||
455 | int i; | ||
456 | SSL3_RECORD *wr; | ||
457 | |||
458 | wr= &(ssl->s3->wrec); | ||
459 | i=COMP_compress_block(ssl->compress,wr->data, | ||
460 | SSL3_RT_MAX_COMPRESSED_LENGTH, | ||
461 | wr->input,(int)wr->length); | ||
462 | if (i < 0) | ||
463 | return(0); | ||
464 | else | ||
465 | wr->length=i; | ||
466 | |||
467 | wr->input=wr->data; | ||
468 | return(1); | ||
469 | } | ||
470 | |||
471 | /* Call this to write data in records of type 'type' | ||
472 | * It will return <= 0 if not all data has been sent or non-blocking IO. | ||
473 | */ | ||
474 | int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len) | ||
475 | { | ||
476 | const unsigned char *buf=buf_; | ||
477 | unsigned int tot,n,nw; | ||
478 | int i; | ||
479 | |||
480 | s->rwstate=SSL_NOTHING; | ||
481 | tot=s->s3->wnum; | ||
482 | s->s3->wnum=0; | ||
483 | |||
484 | if (SSL_in_init(s) && !s->in_handshake) | ||
485 | { | ||
486 | i=s->handshake_func(s); | ||
487 | if (i < 0) return(i); | ||
488 | if (i == 0) | ||
489 | { | ||
490 | SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
491 | return(-1); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | n=(len-tot); | ||
496 | for (;;) | ||
497 | { | ||
498 | if (n > SSL3_RT_MAX_PLAIN_LENGTH) | ||
499 | nw=SSL3_RT_MAX_PLAIN_LENGTH; | ||
500 | else | ||
501 | nw=n; | ||
502 | |||
503 | i=do_ssl3_write(s,type,&(buf[tot]),nw); | ||
504 | if (i <= 0) | ||
505 | { | ||
506 | s->s3->wnum=tot; | ||
507 | return(i); | ||
508 | } | ||
509 | |||
510 | if ((i == (int)n) || | ||
511 | (type == SSL3_RT_APPLICATION_DATA && | ||
512 | (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE))) | ||
513 | { | ||
514 | return(tot+i); | ||
515 | } | ||
516 | |||
517 | n-=i; | ||
518 | tot+=i; | ||
519 | } | ||
520 | } | ||
521 | |||
522 | static int do_ssl3_write(SSL *s, int type, const unsigned char *buf, | ||
523 | unsigned int len) | ||
524 | { | ||
525 | unsigned char *p,*plen; | ||
526 | int i,mac_size,clear=0; | ||
527 | SSL3_RECORD *wr; | ||
528 | SSL3_BUFFER *wb; | ||
529 | SSL_SESSION *sess; | ||
530 | |||
531 | /* first check is there is a SSL3_RECORD still being written | ||
532 | * out. This will happen with non blocking IO */ | ||
533 | if (s->s3->wbuf.left != 0) | ||
534 | return(ssl3_write_pending(s,type,buf,len)); | ||
535 | |||
536 | /* If we have an alert to send, lets send it */ | ||
537 | if (s->s3->alert_dispatch) | ||
538 | { | ||
539 | i=ssl3_dispatch_alert(s); | ||
540 | if (i <= 0) | ||
541 | return(i); | ||
542 | /* if it went, fall through and send more stuff */ | ||
543 | } | ||
544 | |||
545 | if (len == 0) return(len); | ||
546 | |||
547 | wr= &(s->s3->wrec); | ||
548 | wb= &(s->s3->wbuf); | ||
549 | sess=s->session; | ||
550 | |||
551 | if ( (sess == NULL) || | ||
552 | (s->enc_write_ctx == NULL) || | ||
553 | (s->write_hash == NULL)) | ||
554 | clear=1; | ||
555 | |||
556 | if (clear) | ||
557 | mac_size=0; | ||
558 | else | ||
559 | mac_size=EVP_MD_size(s->write_hash); | ||
560 | |||
561 | p=wb->buf; | ||
562 | |||
563 | /* write the header */ | ||
564 | *(p++)=type&0xff; | ||
565 | wr->type=type; | ||
566 | |||
567 | *(p++)=(s->version>>8); | ||
568 | *(p++)=s->version&0xff; | ||
569 | |||
570 | /* record where we are to write out packet length */ | ||
571 | plen=p; | ||
572 | p+=2; | ||
573 | |||
574 | /* lets setup the record stuff. */ | ||
575 | wr->data=p; | ||
576 | wr->length=(int)len; | ||
577 | wr->input=(unsigned char *)buf; | ||
578 | |||
579 | /* we now 'read' from wr->input, wr->length bytes into | ||
580 | * wr->data */ | ||
581 | |||
582 | /* first we compress */ | ||
583 | if (s->compress != NULL) | ||
584 | { | ||
585 | if (!do_compress(s)) | ||
586 | { | ||
587 | SSLerr(SSL_F_DO_SSL3_WRITE,SSL_R_COMPRESSION_FAILURE); | ||
588 | goto err; | ||
589 | } | ||
590 | } | ||
591 | else | ||
592 | { | ||
593 | memcpy(wr->data,wr->input,wr->length); | ||
594 | wr->input=wr->data; | ||
595 | } | ||
596 | |||
597 | /* we should still have the output to wr->data and the input | ||
598 | * from wr->input. Length should be wr->length. | ||
599 | * wr->data still points in the wb->buf */ | ||
600 | |||
601 | if (mac_size != 0) | ||
602 | { | ||
603 | s->method->ssl3_enc->mac(s,&(p[wr->length]),1); | ||
604 | wr->length+=mac_size; | ||
605 | wr->input=p; | ||
606 | wr->data=p; | ||
607 | } | ||
608 | |||
609 | /* ssl3_enc can only have an error on read */ | ||
610 | s->method->ssl3_enc->enc(s,1); | ||
611 | |||
612 | /* record length after mac and block padding */ | ||
613 | s2n(wr->length,plen); | ||
614 | |||
615 | /* we should now have | ||
616 | * wr->data pointing to the encrypted data, which is | ||
617 | * wr->length long */ | ||
618 | wr->type=type; /* not needed but helps for debugging */ | ||
619 | wr->length+=SSL3_RT_HEADER_LENGTH; | ||
620 | |||
621 | /* Now lets setup wb */ | ||
622 | wb->left=wr->length; | ||
623 | wb->offset=0; | ||
624 | |||
625 | s->s3->wpend_tot=len; | ||
626 | s->s3->wpend_buf=buf; | ||
627 | s->s3->wpend_type=type; | ||
628 | s->s3->wpend_ret=len; | ||
629 | |||
630 | /* we now just need to write the buffer */ | ||
631 | return(ssl3_write_pending(s,type,buf,len)); | ||
632 | err: | ||
633 | return(-1); | ||
634 | } | ||
635 | |||
636 | /* if s->s3->wbuf.left != 0, we need to call this */ | ||
637 | static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | ||
638 | unsigned int len) | ||
639 | { | ||
640 | int i; | ||
641 | |||
642 | /* XXXX */ | ||
643 | if ((s->s3->wpend_tot > (int)len) | ||
644 | || ((s->s3->wpend_buf != buf) && | ||
645 | !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)) | ||
646 | || (s->s3->wpend_type != type)) | ||
647 | { | ||
648 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BAD_WRITE_RETRY); | ||
649 | return(-1); | ||
650 | } | ||
651 | |||
652 | for (;;) | ||
653 | { | ||
654 | clear_sys_error(); | ||
655 | if (s->wbio != NULL) | ||
656 | { | ||
657 | s->rwstate=SSL_WRITING; | ||
658 | i=BIO_write(s->wbio, | ||
659 | (char *)&(s->s3->wbuf.buf[s->s3->wbuf.offset]), | ||
660 | (unsigned int)s->s3->wbuf.left); | ||
661 | } | ||
662 | else | ||
663 | { | ||
664 | SSLerr(SSL_F_SSL3_WRITE_PENDING,SSL_R_BIO_NOT_SET); | ||
665 | i= -1; | ||
666 | } | ||
667 | if (i == s->s3->wbuf.left) | ||
668 | { | ||
669 | s->s3->wbuf.left=0; | ||
670 | s->rwstate=SSL_NOTHING; | ||
671 | return(s->s3->wpend_ret); | ||
672 | } | ||
673 | else if (i <= 0) | ||
674 | return(i); | ||
675 | s->s3->wbuf.offset+=i; | ||
676 | s->s3->wbuf.left-=i; | ||
677 | } | ||
678 | } | ||
679 | |||
680 | /* Return up to 'len' payload bytes received in 'type' records. | ||
681 | * 'type' is one of the following: | ||
682 | * | ||
683 | * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us) | ||
684 | * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us) | ||
685 | * - 0 (during a shutdown, no data has to be returned) | ||
686 | * | ||
687 | * If we don't have stored data to work from, read a SSL/TLS record first | ||
688 | * (possibly multiple records if we still don't have anything to return). | ||
689 | * | ||
690 | * This function must handle any surprises the peer may have for us, such as | ||
691 | * Alert records (e.g. close_notify), ChangeCipherSpec records (not really | ||
692 | * a surprise, but handled as if it were), or renegotiation requests. | ||
693 | * Also if record payloads contain fragments too small to process, we store | ||
694 | * them until there is enough for the respective protocol (the record protocol | ||
695 | * may use arbitrary fragmentation and even interleaving): | ||
696 | * Change cipher spec protocol | ||
697 | * just 1 byte needed, no need for keeping anything stored | ||
698 | * Alert protocol | ||
699 | * 2 bytes needed (AlertLevel, AlertDescription) | ||
700 | * Handshake protocol | ||
701 | * 4 bytes needed (HandshakeType, uint24 length) -- we just have | ||
702 | * to detect unexpected Client Hello and Hello Request messages | ||
703 | * here, anything else is handled by higher layers | ||
704 | * Application data protocol | ||
705 | * none of our business | ||
706 | */ | ||
707 | int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len) | ||
708 | { | ||
709 | int al,i,j,ret; | ||
710 | unsigned int n; | ||
711 | SSL3_RECORD *rr; | ||
712 | void (*cb)()=NULL; | ||
713 | |||
714 | if (s->s3->rbuf.buf == NULL) /* Not initialized yet */ | ||
715 | if (!ssl3_setup_buffers(s)) | ||
716 | return(-1); | ||
717 | |||
718 | if ((type != SSL3_RT_APPLICATION_DATA) && (type != SSL3_RT_HANDSHAKE) && type) | ||
719 | { | ||
720 | SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_INTERNAL_ERROR); | ||
721 | return -1; | ||
722 | } | ||
723 | |||
724 | if ((type == SSL3_RT_HANDSHAKE) && (s->s3->handshake_fragment_len > 0)) | ||
725 | /* (partially) satisfy request from storage */ | ||
726 | { | ||
727 | unsigned char *src = s->s3->handshake_fragment; | ||
728 | unsigned char *dst = buf; | ||
729 | unsigned int k; | ||
730 | |||
731 | n = 0; | ||
732 | while ((len > 0) && (s->s3->handshake_fragment_len > 0)) | ||
733 | { | ||
734 | *dst++ = *src++; | ||
735 | len--; s->s3->handshake_fragment_len--; | ||
736 | n++; | ||
737 | } | ||
738 | /* move any remaining fragment bytes: */ | ||
739 | for (k = 0; k < s->s3->handshake_fragment_len; k++) | ||
740 | s->s3->handshake_fragment[k] = *src++; | ||
741 | return n; | ||
742 | } | ||
743 | |||
744 | /* Now s->s3->handshake_fragment_len == 0 if type == SSL3_RT_HANDSHAKE. */ | ||
745 | |||
746 | if (!s->in_handshake && SSL_in_init(s)) | ||
747 | { | ||
748 | /* type == SSL3_RT_APPLICATION_DATA */ | ||
749 | i=s->handshake_func(s); | ||
750 | if (i < 0) return(i); | ||
751 | if (i == 0) | ||
752 | { | ||
753 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
754 | return(-1); | ||
755 | } | ||
756 | } | ||
757 | start: | ||
758 | s->rwstate=SSL_NOTHING; | ||
759 | |||
760 | /* s->s3->rrec.type - is the type of record | ||
761 | * s->s3->rrec.data, - data | ||
762 | * s->s3->rrec.off, - offset into 'data' for next read | ||
763 | * s->s3->rrec.length, - number of bytes. */ | ||
764 | rr = &(s->s3->rrec); | ||
765 | |||
766 | /* get new packet */ | ||
767 | if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) | ||
768 | { | ||
769 | ret=ssl3_get_record(s); | ||
770 | if (ret <= 0) return(ret); | ||
771 | } | ||
772 | |||
773 | /* we now have a packet which can be read and processed */ | ||
774 | |||
775 | if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec, | ||
776 | * reset by ssl3_get_finished */ | ||
777 | && (rr->type != SSL3_RT_HANDSHAKE)) | ||
778 | { | ||
779 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
780 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED); | ||
781 | goto err; | ||
782 | } | ||
783 | |||
784 | /* If the other end has shutdown, throw anything we read away */ | ||
785 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
786 | { | ||
787 | rr->length=0; | ||
788 | s->rwstate=SSL_NOTHING; | ||
789 | return(0); | ||
790 | } | ||
791 | |||
792 | |||
793 | if (type == rr->type) /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */ | ||
794 | { | ||
795 | /* make sure that we are not getting application data when we | ||
796 | * are doing a handshake for the first time */ | ||
797 | if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) && | ||
798 | (s->enc_read_ctx == NULL)) | ||
799 | { | ||
800 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
801 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE); | ||
802 | goto f_err; | ||
803 | } | ||
804 | |||
805 | if (len <= 0) return(len); | ||
806 | |||
807 | if ((unsigned int)len > rr->length) | ||
808 | n = rr->length; | ||
809 | else | ||
810 | n = (unsigned int)len; | ||
811 | |||
812 | memcpy(buf,&(rr->data[rr->off]),n); | ||
813 | rr->length-=n; | ||
814 | rr->off+=n; | ||
815 | if (rr->length == 0) | ||
816 | { | ||
817 | s->rstate=SSL_ST_READ_HEADER; | ||
818 | rr->off=0; | ||
819 | } | ||
820 | return(n); | ||
821 | } | ||
822 | |||
823 | |||
824 | /* If we get here, then type != rr->type; if we have a handshake | ||
825 | * message, then it was unexpected (Hello Request or Client Hello). */ | ||
826 | |||
827 | /* In case of record types for which we have 'fragment' storage, | ||
828 | * fill that so that we can process the data at a fixed place. | ||
829 | */ | ||
830 | { | ||
831 | unsigned int dest_maxlen = 0; | ||
832 | unsigned char *dest = NULL; | ||
833 | unsigned int *dest_len = NULL; | ||
834 | |||
835 | if (rr->type == SSL3_RT_HANDSHAKE) | ||
836 | { | ||
837 | dest_maxlen = sizeof s->s3->handshake_fragment; | ||
838 | dest = s->s3->handshake_fragment; | ||
839 | dest_len = &s->s3->handshake_fragment_len; | ||
840 | } | ||
841 | else if (rr->type == SSL3_RT_ALERT) | ||
842 | { | ||
843 | dest_maxlen = sizeof s->s3->alert_fragment; | ||
844 | dest = s->s3->alert_fragment; | ||
845 | dest_len = &s->s3->alert_fragment_len; | ||
846 | } | ||
847 | |||
848 | if (dest_maxlen > 0) | ||
849 | { | ||
850 | n = dest_maxlen - *dest_len; /* available space in 'dest' */ | ||
851 | if (rr->length < n) | ||
852 | n = rr->length; /* available bytes */ | ||
853 | |||
854 | /* now move 'n' bytes: */ | ||
855 | while (n-- > 0) | ||
856 | { | ||
857 | dest[(*dest_len)++] = rr->data[rr->off++]; | ||
858 | rr->length--; | ||
859 | } | ||
860 | |||
861 | if (*dest_len < dest_maxlen) | ||
862 | goto start; /* fragment was too small */ | ||
863 | } | ||
864 | } | ||
865 | |||
866 | /* s->s3->handshake_fragment_len == 4 iff rr->type == SSL3_RT_HANDSHAKE; | ||
867 | * s->s3->alert_fragment_len == 2 iff rr->type == SSL3_RT_ALERT. | ||
868 | * (Possibly rr is 'empty' now, i.e. rr->length may be 0.) */ | ||
869 | |||
870 | /* If we are a client, check for an incoming 'Hello Request': */ | ||
871 | if ((!s->server) && | ||
872 | (s->s3->handshake_fragment_len >= 4) && | ||
873 | (s->s3->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) && | ||
874 | (s->session != NULL) && (s->session->cipher != NULL)) | ||
875 | { | ||
876 | s->s3->handshake_fragment_len = 0; | ||
877 | |||
878 | if ((s->s3->handshake_fragment[1] != 0) || | ||
879 | (s->s3->handshake_fragment[2] != 0) || | ||
880 | (s->s3->handshake_fragment[3] != 0)) | ||
881 | { | ||
882 | al=SSL_AD_DECODE_ERROR; | ||
883 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_HELLO_REQUEST); | ||
884 | goto err; | ||
885 | } | ||
886 | |||
887 | if (SSL_is_init_finished(s) && | ||
888 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) && | ||
889 | !s->s3->renegotiate) | ||
890 | { | ||
891 | ssl3_renegotiate(s); | ||
892 | if (ssl3_renegotiate_check(s)) | ||
893 | { | ||
894 | i=s->handshake_func(s); | ||
895 | if (i < 0) return(i); | ||
896 | if (i == 0) | ||
897 | { | ||
898 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
899 | return(-1); | ||
900 | } | ||
901 | |||
902 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
903 | { | ||
904 | BIO *bio; | ||
905 | /* In the case where we try to read application data | ||
906 | * the first time, but we trigger an SSL handshake, we | ||
907 | * return -1 with the retry option set. I do this | ||
908 | * otherwise renegotiation can cause nasty problems | ||
909 | * in the blocking world */ /* ? */ | ||
910 | s->rwstate=SSL_READING; | ||
911 | bio=SSL_get_rbio(s); | ||
912 | BIO_clear_retry_flags(bio); | ||
913 | BIO_set_retry_read(bio); | ||
914 | return(-1); | ||
915 | } | ||
916 | } | ||
917 | } | ||
918 | /* we either finished a handshake or ignored the request, | ||
919 | * now try again to obtain the (application) data we were asked for */ | ||
920 | goto start; | ||
921 | } | ||
922 | |||
923 | if (s->s3->alert_fragment_len >= 2) | ||
924 | { | ||
925 | int alert_level = s->s3->alert_fragment[0]; | ||
926 | int alert_descr = s->s3->alert_fragment[1]; | ||
927 | |||
928 | s->s3->alert_fragment_len = 0; | ||
929 | |||
930 | if (s->info_callback != NULL) | ||
931 | cb=s->info_callback; | ||
932 | else if (s->ctx->info_callback != NULL) | ||
933 | cb=s->ctx->info_callback; | ||
934 | |||
935 | if (cb != NULL) | ||
936 | { | ||
937 | j = (alert_level << 8) | alert_descr; | ||
938 | cb(s, SSL_CB_READ_ALERT, j); | ||
939 | } | ||
940 | |||
941 | if (alert_level == 1) /* warning */ | ||
942 | { | ||
943 | s->s3->warn_alert = alert_descr; | ||
944 | if (alert_descr == SSL_AD_CLOSE_NOTIFY) | ||
945 | { | ||
946 | s->shutdown |= SSL_RECEIVED_SHUTDOWN; | ||
947 | return(0); | ||
948 | } | ||
949 | } | ||
950 | else if (alert_level == 2) /* fatal */ | ||
951 | { | ||
952 | char tmp[16]; | ||
953 | |||
954 | s->rwstate=SSL_NOTHING; | ||
955 | s->s3->fatal_alert = alert_descr; | ||
956 | SSLerr(SSL_F_SSL3_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr); | ||
957 | sprintf(tmp,"%d",alert_descr); | ||
958 | ERR_add_error_data(2,"SSL alert number ",tmp); | ||
959 | s->shutdown|=SSL_RECEIVED_SHUTDOWN; | ||
960 | SSL_CTX_remove_session(s->ctx,s->session); | ||
961 | return(0); | ||
962 | } | ||
963 | else | ||
964 | { | ||
965 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
966 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE); | ||
967 | goto f_err; | ||
968 | } | ||
969 | |||
970 | goto start; | ||
971 | } | ||
972 | |||
973 | if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */ | ||
974 | { | ||
975 | s->rwstate=SSL_NOTHING; | ||
976 | rr->length=0; | ||
977 | return(0); | ||
978 | } | ||
979 | |||
980 | if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) | ||
981 | { | ||
982 | /* 'Change Cipher Spec' is just a single byte, so we know | ||
983 | * exactly what the record payload has to look like */ | ||
984 | if ( (rr->length != 1) || (rr->off != 0) || | ||
985 | (rr->data[0] != SSL3_MT_CCS)) | ||
986 | { | ||
987 | i=SSL_AD_ILLEGAL_PARAMETER; | ||
988 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC); | ||
989 | goto err; | ||
990 | } | ||
991 | |||
992 | rr->length=0; | ||
993 | s->s3->change_cipher_spec=1; | ||
994 | if (!do_change_cipher_spec(s)) | ||
995 | goto err; | ||
996 | else | ||
997 | goto start; | ||
998 | } | ||
999 | |||
1000 | /* Unexpected handshake message (Client Hello, or protocol violation) */ | ||
1001 | if ((s->s3->handshake_fragment_len >= 4) && !s->in_handshake) | ||
1002 | { | ||
1003 | if (((s->state&SSL_ST_MASK) == SSL_ST_OK) && | ||
1004 | !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) | ||
1005 | { | ||
1006 | #if 0 /* worked only because C operator preferences are not as expected (and | ||
1007 | * because this is not really needed for clients except for detecting | ||
1008 | * protocol violations): */ | ||
1009 | s->state=SSL_ST_BEFORE|(s->server) | ||
1010 | ?SSL_ST_ACCEPT | ||
1011 | :SSL_ST_CONNECT; | ||
1012 | #else | ||
1013 | s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT; | ||
1014 | #endif | ||
1015 | s->new_session=1; | ||
1016 | } | ||
1017 | i=s->handshake_func(s); | ||
1018 | if (i < 0) return(i); | ||
1019 | if (i == 0) | ||
1020 | { | ||
1021 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE); | ||
1022 | return(-1); | ||
1023 | } | ||
1024 | |||
1025 | if (s->s3->rbuf.left == 0) /* no read-ahead left? */ | ||
1026 | { | ||
1027 | BIO *bio; | ||
1028 | /* In the case where we try to read application data | ||
1029 | * the first time, but we trigger an SSL handshake, we | ||
1030 | * return -1 with the retry option set. I do this | ||
1031 | * otherwise renegotiation can cause nasty problems | ||
1032 | * in the blocking world */ /* ? */ | ||
1033 | s->rwstate=SSL_READING; | ||
1034 | bio=SSL_get_rbio(s); | ||
1035 | BIO_clear_retry_flags(bio); | ||
1036 | BIO_set_retry_read(bio); | ||
1037 | return(-1); | ||
1038 | } | ||
1039 | goto start; | ||
1040 | } | ||
1041 | |||
1042 | switch (rr->type) | ||
1043 | { | ||
1044 | default: | ||
1045 | #ifndef NO_TLS | ||
1046 | /* TLS just ignores unknown message types */ | ||
1047 | if (s->version == TLS1_VERSION) | ||
1048 | { | ||
1049 | goto start; | ||
1050 | } | ||
1051 | #endif | ||
1052 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1053 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
1054 | goto f_err; | ||
1055 | case SSL3_RT_CHANGE_CIPHER_SPEC: | ||
1056 | case SSL3_RT_ALERT: | ||
1057 | case SSL3_RT_HANDSHAKE: | ||
1058 | /* we already handled all of these, with the possible exception | ||
1059 | * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that | ||
1060 | * should not happen when type != rr->type */ | ||
1061 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1062 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_INTERNAL_ERROR); | ||
1063 | goto f_err; | ||
1064 | case SSL3_RT_APPLICATION_DATA: | ||
1065 | /* At this point, we were expecting handshake data, | ||
1066 | * but have application data. If the library was | ||
1067 | * running inside ssl3_read() (i.e. in_read_app_data | ||
1068 | * is set) and it makes sense to read application data | ||
1069 | * at this point (session renegotiation not yet started), | ||
1070 | * we will indulge it. | ||
1071 | */ | ||
1072 | if (s->s3->in_read_app_data && | ||
1073 | (s->s3->total_renegotiations != 0) && | ||
1074 | (( | ||
1075 | (s->state & SSL_ST_CONNECT) && | ||
1076 | (s->state >= SSL3_ST_CW_CLNT_HELLO_A) && | ||
1077 | (s->state <= SSL3_ST_CR_SRVR_HELLO_A) | ||
1078 | ) || ( | ||
1079 | (s->state & SSL_ST_ACCEPT) && | ||
1080 | (s->state <= SSL3_ST_SW_HELLO_REQ_A) && | ||
1081 | (s->state >= SSL3_ST_SR_CLNT_HELLO_A) | ||
1082 | ) | ||
1083 | )) | ||
1084 | { | ||
1085 | s->s3->in_read_app_data=0; | ||
1086 | return(-1); | ||
1087 | } | ||
1088 | else | ||
1089 | { | ||
1090 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1091 | SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD); | ||
1092 | goto f_err; | ||
1093 | } | ||
1094 | } | ||
1095 | /* not reached */ | ||
1096 | |||
1097 | f_err: | ||
1098 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1099 | err: | ||
1100 | return(-1); | ||
1101 | } | ||
1102 | |||
1103 | static int do_change_cipher_spec(SSL *s) | ||
1104 | { | ||
1105 | int i; | ||
1106 | const char *sender; | ||
1107 | int slen; | ||
1108 | |||
1109 | if (s->state & SSL_ST_ACCEPT) | ||
1110 | i=SSL3_CHANGE_CIPHER_SERVER_READ; | ||
1111 | else | ||
1112 | i=SSL3_CHANGE_CIPHER_CLIENT_READ; | ||
1113 | |||
1114 | if (s->s3->tmp.key_block == NULL) | ||
1115 | { | ||
1116 | s->session->cipher=s->s3->tmp.new_cipher; | ||
1117 | if (!s->method->ssl3_enc->setup_key_block(s)) return(0); | ||
1118 | } | ||
1119 | |||
1120 | if (!s->method->ssl3_enc->change_cipher_state(s,i)) | ||
1121 | return(0); | ||
1122 | |||
1123 | /* we have to record the message digest at | ||
1124 | * this point so we can get it before we read | ||
1125 | * the finished message */ | ||
1126 | if (s->state & SSL_ST_CONNECT) | ||
1127 | { | ||
1128 | sender=s->method->ssl3_enc->server_finished_label; | ||
1129 | slen=s->method->ssl3_enc->server_finished_label_len; | ||
1130 | } | ||
1131 | else | ||
1132 | { | ||
1133 | sender=s->method->ssl3_enc->client_finished_label; | ||
1134 | slen=s->method->ssl3_enc->client_finished_label_len; | ||
1135 | } | ||
1136 | |||
1137 | s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s, | ||
1138 | &(s->s3->finish_dgst1), | ||
1139 | &(s->s3->finish_dgst2), | ||
1140 | sender,slen,s->s3->tmp.peer_finish_md); | ||
1141 | |||
1142 | return(1); | ||
1143 | } | ||
1144 | |||
1145 | void ssl3_send_alert(SSL *s, int level, int desc) | ||
1146 | { | ||
1147 | /* Map tls/ssl alert value to correct one */ | ||
1148 | desc=s->method->ssl3_enc->alert_value(desc); | ||
1149 | if (desc < 0) return; | ||
1150 | /* If a fatal one, remove from cache */ | ||
1151 | if ((level == 2) && (s->session != NULL)) | ||
1152 | SSL_CTX_remove_session(s->ctx,s->session); | ||
1153 | |||
1154 | s->s3->alert_dispatch=1; | ||
1155 | s->s3->send_alert[0]=level; | ||
1156 | s->s3->send_alert[1]=desc; | ||
1157 | if (s->s3->wbuf.left == 0) /* data still being written out */ | ||
1158 | ssl3_dispatch_alert(s); | ||
1159 | /* else data is still being written out, we will get written | ||
1160 | * some time in the future */ | ||
1161 | } | ||
1162 | |||
1163 | int ssl3_dispatch_alert(SSL *s) | ||
1164 | { | ||
1165 | int i,j; | ||
1166 | void (*cb)()=NULL; | ||
1167 | |||
1168 | s->s3->alert_dispatch=0; | ||
1169 | i=do_ssl3_write(s,SSL3_RT_ALERT,&s->s3->send_alert[0],2); | ||
1170 | if (i <= 0) | ||
1171 | { | ||
1172 | s->s3->alert_dispatch=1; | ||
1173 | } | ||
1174 | else | ||
1175 | { | ||
1176 | /* If it is important, send it now. If the message | ||
1177 | * does not get sent due to non-blocking IO, we will | ||
1178 | * not worry too much. */ | ||
1179 | if (s->s3->send_alert[0] == SSL3_AL_FATAL) | ||
1180 | (void)BIO_flush(s->wbio); | ||
1181 | |||
1182 | if (s->info_callback != NULL) | ||
1183 | cb=s->info_callback; | ||
1184 | else if (s->ctx->info_callback != NULL) | ||
1185 | cb=s->ctx->info_callback; | ||
1186 | |||
1187 | if (cb != NULL) | ||
1188 | { | ||
1189 | j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1]; | ||
1190 | cb(s,SSL_CB_WRITE_ALERT,j); | ||
1191 | } | ||
1192 | } | ||
1193 | return(i); | ||
1194 | } | ||
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c deleted file mode 100644 index e23ca20bd3..0000000000 --- a/src/lib/libssl/s3_srvr.c +++ /dev/null | |||
@@ -1,1740 +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 | #define REUSE_CIPHER_BUG | ||
60 | #define NETSCAPE_HANG_BUG | ||
61 | |||
62 | |||
63 | #include <stdio.h> | ||
64 | #include <openssl/buffer.h> | ||
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/objects.h> | ||
67 | #include <openssl/md5.h> | ||
68 | #include <openssl/sha.h> | ||
69 | #include <openssl/evp.h> | ||
70 | #include <openssl/x509.h> | ||
71 | #include "ssl_locl.h" | ||
72 | |||
73 | static SSL_METHOD *ssl3_get_server_method(int ver); | ||
74 | static int ssl3_get_client_hello(SSL *s); | ||
75 | static int ssl3_check_client_hello(SSL *s); | ||
76 | static int ssl3_send_server_hello(SSL *s); | ||
77 | static int ssl3_send_server_key_exchange(SSL *s); | ||
78 | static int ssl3_send_certificate_request(SSL *s); | ||
79 | static int ssl3_send_server_done(SSL *s); | ||
80 | static int ssl3_get_client_key_exchange(SSL *s); | ||
81 | static int ssl3_get_client_certificate(SSL *s); | ||
82 | static int ssl3_get_cert_verify(SSL *s); | ||
83 | static int ssl3_send_hello_request(SSL *s); | ||
84 | |||
85 | static SSL_METHOD *ssl3_get_server_method(int ver) | ||
86 | { | ||
87 | if (ver == SSL3_VERSION) | ||
88 | return(SSLv3_server_method()); | ||
89 | else | ||
90 | return(NULL); | ||
91 | } | ||
92 | |||
93 | SSL_METHOD *SSLv3_server_method(void) | ||
94 | { | ||
95 | static int init=1; | ||
96 | static SSL_METHOD SSLv3_server_data; | ||
97 | |||
98 | if (init) | ||
99 | { | ||
100 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), | ||
101 | sizeof(SSL_METHOD)); | ||
102 | SSLv3_server_data.ssl_accept=ssl3_accept; | ||
103 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | ||
104 | init=0; | ||
105 | } | ||
106 | return(&SSLv3_server_data); | ||
107 | } | ||
108 | |||
109 | int ssl3_accept(SSL *s) | ||
110 | { | ||
111 | BUF_MEM *buf; | ||
112 | unsigned long l,Time=time(NULL); | ||
113 | void (*cb)()=NULL; | ||
114 | long num1; | ||
115 | int ret= -1; | ||
116 | int new_state,state,skip=0; | ||
117 | |||
118 | RAND_add(&Time,sizeof(Time),0); | ||
119 | ERR_clear_error(); | ||
120 | clear_sys_error(); | ||
121 | |||
122 | if (s->info_callback != NULL) | ||
123 | cb=s->info_callback; | ||
124 | else if (s->ctx->info_callback != NULL) | ||
125 | cb=s->ctx->info_callback; | ||
126 | |||
127 | /* init things to blank */ | ||
128 | if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s); | ||
129 | s->in_handshake++; | ||
130 | |||
131 | if (s->cert == NULL) | ||
132 | { | ||
133 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET); | ||
134 | return(-1); | ||
135 | } | ||
136 | |||
137 | for (;;) | ||
138 | { | ||
139 | state=s->state; | ||
140 | |||
141 | switch (s->state) | ||
142 | { | ||
143 | case SSL_ST_RENEGOTIATE: | ||
144 | s->new_session=1; | ||
145 | /* s->state=SSL_ST_ACCEPT; */ | ||
146 | |||
147 | case SSL_ST_BEFORE: | ||
148 | case SSL_ST_ACCEPT: | ||
149 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: | ||
150 | case SSL_ST_OK|SSL_ST_ACCEPT: | ||
151 | |||
152 | s->server=1; | ||
153 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | ||
154 | |||
155 | if ((s->version>>8) != 3) | ||
156 | abort(); | ||
157 | s->type=SSL_ST_ACCEPT; | ||
158 | |||
159 | if (s->init_buf == NULL) | ||
160 | { | ||
161 | if ((buf=BUF_MEM_new()) == NULL) | ||
162 | { | ||
163 | ret= -1; | ||
164 | goto end; | ||
165 | } | ||
166 | if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH)) | ||
167 | { | ||
168 | ret= -1; | ||
169 | goto end; | ||
170 | } | ||
171 | s->init_buf=buf; | ||
172 | } | ||
173 | |||
174 | if (!ssl3_setup_buffers(s)) | ||
175 | { | ||
176 | ret= -1; | ||
177 | goto end; | ||
178 | } | ||
179 | |||
180 | /* Ok, we now need to push on a buffering BIO so that | ||
181 | * the output is sent in a way that TCP likes :-) | ||
182 | */ | ||
183 | if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; } | ||
184 | |||
185 | s->init_num=0; | ||
186 | |||
187 | if (s->state != SSL_ST_RENEGOTIATE) | ||
188 | { | ||
189 | ssl3_init_finished_mac(s); | ||
190 | s->state=SSL3_ST_SR_CLNT_HELLO_A; | ||
191 | s->ctx->stats.sess_accept++; | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | s->ctx->stats.sess_accept_renegotiate++; | ||
196 | s->state=SSL3_ST_SW_HELLO_REQ_A; | ||
197 | } | ||
198 | break; | ||
199 | |||
200 | case SSL3_ST_SW_HELLO_REQ_A: | ||
201 | case SSL3_ST_SW_HELLO_REQ_B: | ||
202 | |||
203 | s->shutdown=0; | ||
204 | ret=ssl3_send_hello_request(s); | ||
205 | if (ret <= 0) goto end; | ||
206 | s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C; | ||
207 | s->state=SSL3_ST_SW_FLUSH; | ||
208 | s->init_num=0; | ||
209 | |||
210 | ssl3_init_finished_mac(s); | ||
211 | break; | ||
212 | |||
213 | case SSL3_ST_SW_HELLO_REQ_C: | ||
214 | s->state=SSL_ST_OK; | ||
215 | ret=1; | ||
216 | goto end; | ||
217 | /* break; */ | ||
218 | |||
219 | case SSL3_ST_SR_CLNT_HELLO_A: | ||
220 | case SSL3_ST_SR_CLNT_HELLO_B: | ||
221 | case SSL3_ST_SR_CLNT_HELLO_C: | ||
222 | |||
223 | s->shutdown=0; | ||
224 | ret=ssl3_get_client_hello(s); | ||
225 | if (ret <= 0) goto end; | ||
226 | s->state=SSL3_ST_SW_SRVR_HELLO_A; | ||
227 | s->init_num=0; | ||
228 | break; | ||
229 | |||
230 | case SSL3_ST_SW_SRVR_HELLO_A: | ||
231 | case SSL3_ST_SW_SRVR_HELLO_B: | ||
232 | ret=ssl3_send_server_hello(s); | ||
233 | if (ret <= 0) goto end; | ||
234 | |||
235 | if (s->hit) | ||
236 | s->state=SSL3_ST_SW_CHANGE_A; | ||
237 | else | ||
238 | s->state=SSL3_ST_SW_CERT_A; | ||
239 | s->init_num=0; | ||
240 | break; | ||
241 | |||
242 | case SSL3_ST_SW_CERT_A: | ||
243 | case SSL3_ST_SW_CERT_B: | ||
244 | /* Check if it is anon DH */ | ||
245 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
246 | { | ||
247 | ret=ssl3_send_server_certificate(s); | ||
248 | if (ret <= 0) goto end; | ||
249 | } | ||
250 | else | ||
251 | skip=1; | ||
252 | s->state=SSL3_ST_SW_KEY_EXCH_A; | ||
253 | s->init_num=0; | ||
254 | break; | ||
255 | |||
256 | case SSL3_ST_SW_KEY_EXCH_A: | ||
257 | case SSL3_ST_SW_KEY_EXCH_B: | ||
258 | l=s->s3->tmp.new_cipher->algorithms; | ||
259 | |||
260 | /* clear this, it may get reset by | ||
261 | * send_server_key_exchange */ | ||
262 | if (s->options & SSL_OP_EPHEMERAL_RSA) | ||
263 | s->s3->tmp.use_rsa_tmp=1; | ||
264 | else | ||
265 | s->s3->tmp.use_rsa_tmp=0; | ||
266 | |||
267 | /* only send if a DH key exchange, fortezza or | ||
268 | * RSA but we have a sign only certificate */ | ||
269 | if (s->s3->tmp.use_rsa_tmp | ||
270 | || (l & (SSL_DH|SSL_kFZA)) | ||
271 | || ((l & SSL_kRSA) | ||
272 | && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL | ||
273 | || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) | ||
274 | && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher) | ||
275 | ) | ||
276 | ) | ||
277 | ) | ||
278 | ) | ||
279 | { | ||
280 | ret=ssl3_send_server_key_exchange(s); | ||
281 | if (ret <= 0) goto end; | ||
282 | } | ||
283 | else | ||
284 | skip=1; | ||
285 | |||
286 | s->state=SSL3_ST_SW_CERT_REQ_A; | ||
287 | s->init_num=0; | ||
288 | break; | ||
289 | |||
290 | case SSL3_ST_SW_CERT_REQ_A: | ||
291 | case SSL3_ST_SW_CERT_REQ_B: | ||
292 | if (/* don't request cert unless asked for it: */ | ||
293 | !(s->verify_mode & SSL_VERIFY_PEER) || | ||
294 | /* if SSL_VERIFY_CLIENT_ONCE is set, | ||
295 | * don't request cert during re-negotiation: */ | ||
296 | ((s->session->peer != NULL) && | ||
297 | (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) || | ||
298 | /* never request cert in anonymous ciphersuites | ||
299 | * (see section "Certificate request" in SSL 3 drafts | ||
300 | * and in RFC 2246): */ | ||
301 | ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) && | ||
302 | /* ... except when the application insists on verification | ||
303 | * (against the specs, but s3_clnt.c accepts this for SSL 3) */ | ||
304 | !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))) | ||
305 | { | ||
306 | /* no cert request */ | ||
307 | skip=1; | ||
308 | s->s3->tmp.cert_request=0; | ||
309 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
310 | } | ||
311 | else | ||
312 | { | ||
313 | s->s3->tmp.cert_request=1; | ||
314 | ret=ssl3_send_certificate_request(s); | ||
315 | if (ret <= 0) goto end; | ||
316 | #ifndef NETSCAPE_HANG_BUG | ||
317 | s->state=SSL3_ST_SW_SRVR_DONE_A; | ||
318 | #else | ||
319 | s->state=SSL3_ST_SW_FLUSH; | ||
320 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
321 | #endif | ||
322 | s->init_num=0; | ||
323 | } | ||
324 | break; | ||
325 | |||
326 | case SSL3_ST_SW_SRVR_DONE_A: | ||
327 | case SSL3_ST_SW_SRVR_DONE_B: | ||
328 | ret=ssl3_send_server_done(s); | ||
329 | if (ret <= 0) goto end; | ||
330 | s->s3->tmp.next_state=SSL3_ST_SR_CERT_A; | ||
331 | s->state=SSL3_ST_SW_FLUSH; | ||
332 | s->init_num=0; | ||
333 | break; | ||
334 | |||
335 | case SSL3_ST_SW_FLUSH: | ||
336 | /* number of bytes to be flushed */ | ||
337 | num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL); | ||
338 | if (num1 > 0) | ||
339 | { | ||
340 | s->rwstate=SSL_WRITING; | ||
341 | num1=BIO_flush(s->wbio); | ||
342 | if (num1 <= 0) { ret= -1; goto end; } | ||
343 | s->rwstate=SSL_NOTHING; | ||
344 | } | ||
345 | |||
346 | s->state=s->s3->tmp.next_state; | ||
347 | break; | ||
348 | |||
349 | case SSL3_ST_SR_CERT_A: | ||
350 | case SSL3_ST_SR_CERT_B: | ||
351 | /* Check for second client hello (MS SGC) */ | ||
352 | ret = ssl3_check_client_hello(s); | ||
353 | if (ret <= 0) | ||
354 | goto end; | ||
355 | if (ret == 2) | ||
356 | s->state = SSL3_ST_SR_CLNT_HELLO_C; | ||
357 | else { | ||
358 | /* could be sent for a DH cert, even if we | ||
359 | * have not asked for it :-) */ | ||
360 | ret=ssl3_get_client_certificate(s); | ||
361 | if (ret <= 0) goto end; | ||
362 | s->init_num=0; | ||
363 | s->state=SSL3_ST_SR_KEY_EXCH_A; | ||
364 | } | ||
365 | break; | ||
366 | |||
367 | case SSL3_ST_SR_KEY_EXCH_A: | ||
368 | case SSL3_ST_SR_KEY_EXCH_B: | ||
369 | ret=ssl3_get_client_key_exchange(s); | ||
370 | if (ret <= 0) goto end; | ||
371 | s->state=SSL3_ST_SR_CERT_VRFY_A; | ||
372 | s->init_num=0; | ||
373 | |||
374 | /* We need to get hashes here so if there is | ||
375 | * a client cert, it can be verified */ | ||
376 | s->method->ssl3_enc->cert_verify_mac(s, | ||
377 | &(s->s3->finish_dgst1), | ||
378 | &(s->s3->tmp.cert_verify_md[0])); | ||
379 | s->method->ssl3_enc->cert_verify_mac(s, | ||
380 | &(s->s3->finish_dgst2), | ||
381 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH])); | ||
382 | |||
383 | break; | ||
384 | |||
385 | case SSL3_ST_SR_CERT_VRFY_A: | ||
386 | case SSL3_ST_SR_CERT_VRFY_B: | ||
387 | |||
388 | /* we should decide if we expected this one */ | ||
389 | ret=ssl3_get_cert_verify(s); | ||
390 | if (ret <= 0) goto end; | ||
391 | |||
392 | s->state=SSL3_ST_SR_FINISHED_A; | ||
393 | s->init_num=0; | ||
394 | break; | ||
395 | |||
396 | case SSL3_ST_SR_FINISHED_A: | ||
397 | case SSL3_ST_SR_FINISHED_B: | ||
398 | ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A, | ||
399 | SSL3_ST_SR_FINISHED_B); | ||
400 | if (ret <= 0) goto end; | ||
401 | if (s->hit) | ||
402 | s->state=SSL_ST_OK; | ||
403 | else | ||
404 | s->state=SSL3_ST_SW_CHANGE_A; | ||
405 | s->init_num=0; | ||
406 | break; | ||
407 | |||
408 | case SSL3_ST_SW_CHANGE_A: | ||
409 | case SSL3_ST_SW_CHANGE_B: | ||
410 | |||
411 | s->session->cipher=s->s3->tmp.new_cipher; | ||
412 | if (!s->method->ssl3_enc->setup_key_block(s)) | ||
413 | { ret= -1; goto end; } | ||
414 | |||
415 | ret=ssl3_send_change_cipher_spec(s, | ||
416 | SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B); | ||
417 | |||
418 | if (ret <= 0) goto end; | ||
419 | s->state=SSL3_ST_SW_FINISHED_A; | ||
420 | s->init_num=0; | ||
421 | |||
422 | if (!s->method->ssl3_enc->change_cipher_state(s, | ||
423 | SSL3_CHANGE_CIPHER_SERVER_WRITE)) | ||
424 | { | ||
425 | ret= -1; | ||
426 | goto end; | ||
427 | } | ||
428 | |||
429 | break; | ||
430 | |||
431 | case SSL3_ST_SW_FINISHED_A: | ||
432 | case SSL3_ST_SW_FINISHED_B: | ||
433 | ret=ssl3_send_finished(s, | ||
434 | SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B, | ||
435 | s->method->ssl3_enc->server_finished_label, | ||
436 | s->method->ssl3_enc->server_finished_label_len); | ||
437 | if (ret <= 0) goto end; | ||
438 | s->state=SSL3_ST_SW_FLUSH; | ||
439 | if (s->hit) | ||
440 | s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A; | ||
441 | else | ||
442 | s->s3->tmp.next_state=SSL_ST_OK; | ||
443 | s->init_num=0; | ||
444 | break; | ||
445 | |||
446 | case SSL_ST_OK: | ||
447 | /* clean a few things up */ | ||
448 | ssl3_cleanup_key_block(s); | ||
449 | |||
450 | BUF_MEM_free(s->init_buf); | ||
451 | s->init_buf=NULL; | ||
452 | |||
453 | /* remove buffering on output */ | ||
454 | ssl_free_wbio_buffer(s); | ||
455 | |||
456 | s->new_session=0; | ||
457 | s->init_num=0; | ||
458 | |||
459 | ssl_update_cache(s,SSL_SESS_CACHE_SERVER); | ||
460 | |||
461 | s->ctx->stats.sess_accept_good++; | ||
462 | /* s->server=1; */ | ||
463 | s->handshake_func=ssl3_accept; | ||
464 | ret=1; | ||
465 | |||
466 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | ||
467 | |||
468 | goto end; | ||
469 | /* break; */ | ||
470 | |||
471 | default: | ||
472 | SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE); | ||
473 | ret= -1; | ||
474 | goto end; | ||
475 | /* break; */ | ||
476 | } | ||
477 | |||
478 | if (!s->s3->tmp.reuse_message && !skip) | ||
479 | { | ||
480 | if (s->debug) | ||
481 | { | ||
482 | if ((ret=BIO_flush(s->wbio)) <= 0) | ||
483 | goto end; | ||
484 | } | ||
485 | |||
486 | |||
487 | if ((cb != NULL) && (s->state != state)) | ||
488 | { | ||
489 | new_state=s->state; | ||
490 | s->state=state; | ||
491 | cb(s,SSL_CB_ACCEPT_LOOP,1); | ||
492 | s->state=new_state; | ||
493 | } | ||
494 | } | ||
495 | skip=0; | ||
496 | } | ||
497 | end: | ||
498 | /* BIO_flush(s->wbio); */ | ||
499 | |||
500 | if (cb != NULL) | ||
501 | cb(s,SSL_CB_ACCEPT_EXIT,ret); | ||
502 | s->in_handshake--; | ||
503 | return(ret); | ||
504 | } | ||
505 | |||
506 | static int ssl3_send_hello_request(SSL *s) | ||
507 | { | ||
508 | unsigned char *p; | ||
509 | |||
510 | if (s->state == SSL3_ST_SW_HELLO_REQ_A) | ||
511 | { | ||
512 | p=(unsigned char *)s->init_buf->data; | ||
513 | *(p++)=SSL3_MT_HELLO_REQUEST; | ||
514 | *(p++)=0; | ||
515 | *(p++)=0; | ||
516 | *(p++)=0; | ||
517 | |||
518 | s->state=SSL3_ST_SW_HELLO_REQ_B; | ||
519 | /* number of bytes to write */ | ||
520 | s->init_num=4; | ||
521 | s->init_off=0; | ||
522 | } | ||
523 | |||
524 | /* SSL3_ST_SW_HELLO_REQ_B */ | ||
525 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
526 | } | ||
527 | |||
528 | static int ssl3_check_client_hello(SSL *s) | ||
529 | { | ||
530 | int ok; | ||
531 | long n; | ||
532 | |||
533 | n=ssl3_get_message(s, | ||
534 | SSL3_ST_SR_CERT_A, | ||
535 | SSL3_ST_SR_CERT_B, | ||
536 | -1, | ||
537 | SSL3_RT_MAX_PLAIN_LENGTH, | ||
538 | &ok); | ||
539 | if (!ok) return((int)n); | ||
540 | s->s3->tmp.reuse_message = 1; | ||
541 | if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO) | ||
542 | { | ||
543 | /* Throw away what we have done so far in the current handshake, | ||
544 | * which will now be aborted. (A full SSL_clear would be too much.) | ||
545 | * I hope that tmp.dh is the only thing that may need to be cleared | ||
546 | * when a handshake is not completed ... */ | ||
547 | #ifndef NO_DH | ||
548 | if (s->s3->tmp.dh != NULL) | ||
549 | { | ||
550 | DH_free(s->s3->tmp.dh); | ||
551 | s->s3->tmp.dh = NULL; | ||
552 | } | ||
553 | #endif | ||
554 | return 2; | ||
555 | } | ||
556 | return 1; | ||
557 | } | ||
558 | |||
559 | static int ssl3_get_client_hello(SSL *s) | ||
560 | { | ||
561 | int i,j,ok,al,ret= -1; | ||
562 | long n; | ||
563 | unsigned long id; | ||
564 | unsigned char *p,*d,*q; | ||
565 | SSL_CIPHER *c; | ||
566 | SSL_COMP *comp=NULL; | ||
567 | STACK_OF(SSL_CIPHER) *ciphers=NULL; | ||
568 | |||
569 | /* We do this so that we will respond with our native type. | ||
570 | * If we are TLSv1 and we get SSLv3, we will respond with TLSv1, | ||
571 | * This down switching should be handled by a different method. | ||
572 | * If we are SSLv3, we will respond with SSLv3, even if prompted with | ||
573 | * TLSv1. | ||
574 | */ | ||
575 | if (s->state == SSL3_ST_SR_CLNT_HELLO_A) | ||
576 | { | ||
577 | s->first_packet=1; | ||
578 | s->state=SSL3_ST_SR_CLNT_HELLO_B; | ||
579 | } | ||
580 | n=ssl3_get_message(s, | ||
581 | SSL3_ST_SR_CLNT_HELLO_B, | ||
582 | SSL3_ST_SR_CLNT_HELLO_C, | ||
583 | SSL3_MT_CLIENT_HELLO, | ||
584 | SSL3_RT_MAX_PLAIN_LENGTH, | ||
585 | &ok); | ||
586 | |||
587 | if (!ok) return((int)n); | ||
588 | d=p=(unsigned char *)s->init_buf->data; | ||
589 | |||
590 | /* use version from inside client hello, not from record header | ||
591 | * (may differ: see RFC 2246, Appendix E, second paragraph) */ | ||
592 | s->client_version=(((int)p[0])<<8)|(int)p[1]; | ||
593 | p+=2; | ||
594 | |||
595 | /* load the client random */ | ||
596 | memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE); | ||
597 | p+=SSL3_RANDOM_SIZE; | ||
598 | |||
599 | /* get the session-id */ | ||
600 | j= *(p++); | ||
601 | |||
602 | s->hit=0; | ||
603 | if (j == 0) | ||
604 | { | ||
605 | if (!ssl_get_new_session(s,1)) | ||
606 | goto err; | ||
607 | } | ||
608 | else | ||
609 | { | ||
610 | i=ssl_get_prev_session(s,p,j); | ||
611 | if (i == 1) | ||
612 | { /* previous session */ | ||
613 | s->hit=1; | ||
614 | } | ||
615 | else if (i == -1) | ||
616 | goto err; | ||
617 | else /* i == 0 */ | ||
618 | { | ||
619 | if (!ssl_get_new_session(s,1)) | ||
620 | goto err; | ||
621 | } | ||
622 | } | ||
623 | |||
624 | p+=j; | ||
625 | n2s(p,i); | ||
626 | if ((i == 0) && (j != 0)) | ||
627 | { | ||
628 | /* we need a cipher if we are not resuming a session */ | ||
629 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
630 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED); | ||
631 | goto f_err; | ||
632 | } | ||
633 | if ((i+p) > (d+n)) | ||
634 | { | ||
635 | /* not enough data */ | ||
636 | al=SSL_AD_DECODE_ERROR; | ||
637 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
638 | goto f_err; | ||
639 | } | ||
640 | if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers)) | ||
641 | == NULL)) | ||
642 | { | ||
643 | goto err; | ||
644 | } | ||
645 | p+=i; | ||
646 | |||
647 | /* If it is a hit, check that the cipher is in the list */ | ||
648 | if ((s->hit) && (i > 0)) | ||
649 | { | ||
650 | j=0; | ||
651 | id=s->session->cipher->id; | ||
652 | |||
653 | #ifdef CIPHER_DEBUG | ||
654 | printf("client sent %d ciphers\n",sk_num(ciphers)); | ||
655 | #endif | ||
656 | for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++) | ||
657 | { | ||
658 | c=sk_SSL_CIPHER_value(ciphers,i); | ||
659 | #ifdef CIPHER_DEBUG | ||
660 | printf("client [%2d of %2d]:%s\n", | ||
661 | i,sk_num(ciphers),SSL_CIPHER_get_name(c)); | ||
662 | #endif | ||
663 | if (c->id == id) | ||
664 | { | ||
665 | j=1; | ||
666 | break; | ||
667 | } | ||
668 | } | ||
669 | if (j == 0) | ||
670 | { | ||
671 | if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1)) | ||
672 | { | ||
673 | /* Very bad for multi-threading.... */ | ||
674 | s->session->cipher=sk_SSL_CIPHER_value(ciphers, | ||
675 | 0); | ||
676 | } | ||
677 | else | ||
678 | { | ||
679 | /* we need to have the cipher in the cipher | ||
680 | * list if we are asked to reuse it */ | ||
681 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
682 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING); | ||
683 | goto f_err; | ||
684 | } | ||
685 | } | ||
686 | } | ||
687 | |||
688 | /* compression */ | ||
689 | i= *(p++); | ||
690 | q=p; | ||
691 | for (j=0; j<i; j++) | ||
692 | { | ||
693 | if (p[j] == 0) break; | ||
694 | } | ||
695 | |||
696 | p+=i; | ||
697 | if (j >= i) | ||
698 | { | ||
699 | /* no compress */ | ||
700 | al=SSL_AD_DECODE_ERROR; | ||
701 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED); | ||
702 | goto f_err; | ||
703 | } | ||
704 | |||
705 | /* Worst case, we will use the NULL compression, but if we have other | ||
706 | * options, we will now look for them. We have i-1 compression | ||
707 | * algorithms from the client, starting at q. */ | ||
708 | s->s3->tmp.new_compression=NULL; | ||
709 | if (s->ctx->comp_methods != NULL) | ||
710 | { /* See if we have a match */ | ||
711 | int m,nn,o,v,done=0; | ||
712 | |||
713 | nn=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
714 | for (m=0; m<nn; m++) | ||
715 | { | ||
716 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,m); | ||
717 | v=comp->id; | ||
718 | for (o=0; o<i; o++) | ||
719 | { | ||
720 | if (v == q[o]) | ||
721 | { | ||
722 | done=1; | ||
723 | break; | ||
724 | } | ||
725 | } | ||
726 | if (done) break; | ||
727 | } | ||
728 | if (done) | ||
729 | s->s3->tmp.new_compression=comp; | ||
730 | else | ||
731 | comp=NULL; | ||
732 | } | ||
733 | |||
734 | /* TLS does not mind if there is extra stuff */ | ||
735 | if (s->version == SSL3_VERSION) | ||
736 | { | ||
737 | if (p > (d+n)) | ||
738 | { | ||
739 | /* wrong number of bytes, | ||
740 | * there could be more to follow */ | ||
741 | al=SSL_AD_DECODE_ERROR; | ||
742 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH); | ||
743 | goto f_err; | ||
744 | } | ||
745 | } | ||
746 | |||
747 | /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must | ||
748 | * pick a cipher */ | ||
749 | |||
750 | if (!s->hit) | ||
751 | { | ||
752 | s->session->compress_meth=(comp == NULL)?0:comp->id; | ||
753 | if (s->session->ciphers != NULL) | ||
754 | sk_SSL_CIPHER_free(s->session->ciphers); | ||
755 | s->session->ciphers=ciphers; | ||
756 | if (ciphers == NULL) | ||
757 | { | ||
758 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
759 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED); | ||
760 | goto f_err; | ||
761 | } | ||
762 | ciphers=NULL; | ||
763 | c=ssl3_choose_cipher(s,s->session->ciphers, | ||
764 | ssl_get_ciphers_by_id(s)); | ||
765 | |||
766 | if (c == NULL) | ||
767 | { | ||
768 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
769 | SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER); | ||
770 | goto f_err; | ||
771 | } | ||
772 | s->s3->tmp.new_cipher=c; | ||
773 | } | ||
774 | else | ||
775 | { | ||
776 | /* Session-id reuse */ | ||
777 | #ifdef REUSE_CIPHER_BUG | ||
778 | STACK_OF(SSL_CIPHER) *sk; | ||
779 | SSL_CIPHER *nc=NULL; | ||
780 | SSL_CIPHER *ec=NULL; | ||
781 | |||
782 | if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG) | ||
783 | { | ||
784 | sk=s->session->ciphers; | ||
785 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
786 | { | ||
787 | c=sk_SSL_CIPHER_value(sk,i); | ||
788 | if (c->algorithms & SSL_eNULL) | ||
789 | nc=c; | ||
790 | if (SSL_C_IS_EXPORT(c)) | ||
791 | ec=c; | ||
792 | } | ||
793 | if (nc != NULL) | ||
794 | s->s3->tmp.new_cipher=nc; | ||
795 | else if (ec != NULL) | ||
796 | s->s3->tmp.new_cipher=ec; | ||
797 | else | ||
798 | s->s3->tmp.new_cipher=s->session->cipher; | ||
799 | } | ||
800 | else | ||
801 | #endif | ||
802 | s->s3->tmp.new_cipher=s->session->cipher; | ||
803 | } | ||
804 | |||
805 | /* we now have the following setup. | ||
806 | * client_random | ||
807 | * cipher_list - our prefered list of ciphers | ||
808 | * ciphers - the clients prefered list of ciphers | ||
809 | * compression - basically ignored right now | ||
810 | * ssl version is set - sslv3 | ||
811 | * s->session - The ssl session has been setup. | ||
812 | * s->hit - session reuse flag | ||
813 | * s->tmp.new_cipher - the new cipher to use. | ||
814 | */ | ||
815 | |||
816 | ret=1; | ||
817 | if (0) | ||
818 | { | ||
819 | f_err: | ||
820 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
821 | } | ||
822 | err: | ||
823 | if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers); | ||
824 | return(ret); | ||
825 | } | ||
826 | |||
827 | static int ssl3_send_server_hello(SSL *s) | ||
828 | { | ||
829 | unsigned char *buf; | ||
830 | unsigned char *p,*d; | ||
831 | int i,sl; | ||
832 | unsigned long l,Time; | ||
833 | |||
834 | if (s->state == SSL3_ST_SW_SRVR_HELLO_A) | ||
835 | { | ||
836 | buf=(unsigned char *)s->init_buf->data; | ||
837 | p=s->s3->server_random; | ||
838 | Time=time(NULL); /* Time */ | ||
839 | l2n(Time,p); | ||
840 | RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time)); | ||
841 | /* Do the message type and length last */ | ||
842 | d=p= &(buf[4]); | ||
843 | |||
844 | *(p++)=s->version>>8; | ||
845 | *(p++)=s->version&0xff; | ||
846 | |||
847 | /* Random stuff */ | ||
848 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
849 | p+=SSL3_RANDOM_SIZE; | ||
850 | |||
851 | /* now in theory we have 3 options to sending back the | ||
852 | * session id. If it is a re-use, we send back the | ||
853 | * old session-id, if it is a new session, we send | ||
854 | * back the new session-id or we send back a 0 length | ||
855 | * session-id if we want it to be single use. | ||
856 | * Currently I will not implement the '0' length session-id | ||
857 | * 12-Jan-98 - I'll now support the '0' length stuff. | ||
858 | */ | ||
859 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) | ||
860 | s->session->session_id_length=0; | ||
861 | |||
862 | sl=s->session->session_id_length; | ||
863 | *(p++)=sl; | ||
864 | memcpy(p,s->session->session_id,sl); | ||
865 | p+=sl; | ||
866 | |||
867 | /* put the cipher */ | ||
868 | i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p); | ||
869 | p+=i; | ||
870 | |||
871 | /* put the compression method */ | ||
872 | if (s->s3->tmp.new_compression == NULL) | ||
873 | *(p++)=0; | ||
874 | else | ||
875 | *(p++)=s->s3->tmp.new_compression->id; | ||
876 | |||
877 | /* do the header */ | ||
878 | l=(p-d); | ||
879 | d=buf; | ||
880 | *(d++)=SSL3_MT_SERVER_HELLO; | ||
881 | l2n3(l,d); | ||
882 | |||
883 | s->state=SSL3_ST_CW_CLNT_HELLO_B; | ||
884 | /* number of bytes to write */ | ||
885 | s->init_num=p-buf; | ||
886 | s->init_off=0; | ||
887 | } | ||
888 | |||
889 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
890 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
891 | } | ||
892 | |||
893 | static int ssl3_send_server_done(SSL *s) | ||
894 | { | ||
895 | unsigned char *p; | ||
896 | |||
897 | if (s->state == SSL3_ST_SW_SRVR_DONE_A) | ||
898 | { | ||
899 | p=(unsigned char *)s->init_buf->data; | ||
900 | |||
901 | /* do the header */ | ||
902 | *(p++)=SSL3_MT_SERVER_DONE; | ||
903 | *(p++)=0; | ||
904 | *(p++)=0; | ||
905 | *(p++)=0; | ||
906 | |||
907 | s->state=SSL3_ST_SW_SRVR_DONE_B; | ||
908 | /* number of bytes to write */ | ||
909 | s->init_num=4; | ||
910 | s->init_off=0; | ||
911 | } | ||
912 | |||
913 | /* SSL3_ST_CW_CLNT_HELLO_B */ | ||
914 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
915 | } | ||
916 | |||
917 | static int ssl3_send_server_key_exchange(SSL *s) | ||
918 | { | ||
919 | #ifndef NO_RSA | ||
920 | unsigned char *q; | ||
921 | int j,num; | ||
922 | RSA *rsa; | ||
923 | unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
924 | unsigned int u; | ||
925 | #endif | ||
926 | #ifndef NO_DH | ||
927 | DH *dh=NULL,*dhp; | ||
928 | #endif | ||
929 | EVP_PKEY *pkey; | ||
930 | unsigned char *p,*d; | ||
931 | int al,i; | ||
932 | unsigned long type; | ||
933 | int n; | ||
934 | CERT *cert; | ||
935 | BIGNUM *r[4]; | ||
936 | int nr[4],kn; | ||
937 | BUF_MEM *buf; | ||
938 | EVP_MD_CTX md_ctx; | ||
939 | |||
940 | if (s->state == SSL3_ST_SW_KEY_EXCH_A) | ||
941 | { | ||
942 | type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK; | ||
943 | cert=s->cert; | ||
944 | |||
945 | buf=s->init_buf; | ||
946 | |||
947 | r[0]=r[1]=r[2]=r[3]=NULL; | ||
948 | n=0; | ||
949 | #ifndef NO_RSA | ||
950 | if (type & SSL_kRSA) | ||
951 | { | ||
952 | rsa=cert->rsa_tmp; | ||
953 | if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL)) | ||
954 | { | ||
955 | rsa=s->cert->rsa_tmp_cb(s, | ||
956 | SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
957 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
958 | if(rsa == NULL) | ||
959 | { | ||
960 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
961 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY); | ||
962 | goto f_err; | ||
963 | } | ||
964 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA); | ||
965 | cert->rsa_tmp=rsa; | ||
966 | } | ||
967 | if (rsa == NULL) | ||
968 | { | ||
969 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
970 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY); | ||
971 | goto f_err; | ||
972 | } | ||
973 | r[0]=rsa->n; | ||
974 | r[1]=rsa->e; | ||
975 | s->s3->tmp.use_rsa_tmp=1; | ||
976 | } | ||
977 | else | ||
978 | #endif | ||
979 | #ifndef NO_DH | ||
980 | if (type & SSL_kEDH) | ||
981 | { | ||
982 | dhp=cert->dh_tmp; | ||
983 | if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL)) | ||
984 | dhp=s->cert->dh_tmp_cb(s, | ||
985 | !SSL_C_IS_EXPORT(s->s3->tmp.new_cipher), | ||
986 | SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)); | ||
987 | if (dhp == NULL) | ||
988 | { | ||
989 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
990 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
991 | goto f_err; | ||
992 | } | ||
993 | |||
994 | if (s->s3->tmp.dh != NULL) | ||
995 | { | ||
996 | DH_free(dh); | ||
997 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, SSL_R_INTERNAL_ERROR); | ||
998 | goto err; | ||
999 | } | ||
1000 | |||
1001 | if ((dh=DHparams_dup(dhp)) == NULL) | ||
1002 | { | ||
1003 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1004 | goto err; | ||
1005 | } | ||
1006 | |||
1007 | s->s3->tmp.dh=dh; | ||
1008 | if ((dhp->pub_key == NULL || | ||
1009 | dhp->priv_key == NULL || | ||
1010 | (s->options & SSL_OP_SINGLE_DH_USE))) | ||
1011 | { | ||
1012 | if(!DH_generate_key(dh)) | ||
1013 | { | ||
1014 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, | ||
1015 | ERR_R_DH_LIB); | ||
1016 | goto err; | ||
1017 | } | ||
1018 | } | ||
1019 | else | ||
1020 | { | ||
1021 | dh->pub_key=BN_dup(dhp->pub_key); | ||
1022 | dh->priv_key=BN_dup(dhp->priv_key); | ||
1023 | if ((dh->pub_key == NULL) || | ||
1024 | (dh->priv_key == NULL)) | ||
1025 | { | ||
1026 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1027 | goto err; | ||
1028 | } | ||
1029 | } | ||
1030 | r[0]=dh->p; | ||
1031 | r[1]=dh->g; | ||
1032 | r[2]=dh->pub_key; | ||
1033 | } | ||
1034 | else | ||
1035 | #endif | ||
1036 | { | ||
1037 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1038 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | ||
1039 | goto f_err; | ||
1040 | } | ||
1041 | for (i=0; r[i] != NULL; i++) | ||
1042 | { | ||
1043 | nr[i]=BN_num_bytes(r[i]); | ||
1044 | n+=2+nr[i]; | ||
1045 | } | ||
1046 | |||
1047 | if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL)) | ||
1048 | { | ||
1049 | if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher)) | ||
1050 | == NULL) | ||
1051 | { | ||
1052 | al=SSL_AD_DECODE_ERROR; | ||
1053 | goto f_err; | ||
1054 | } | ||
1055 | kn=EVP_PKEY_size(pkey); | ||
1056 | } | ||
1057 | else | ||
1058 | { | ||
1059 | pkey=NULL; | ||
1060 | kn=0; | ||
1061 | } | ||
1062 | |||
1063 | if (!BUF_MEM_grow(buf,n+4+kn)) | ||
1064 | { | ||
1065 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); | ||
1066 | goto err; | ||
1067 | } | ||
1068 | d=(unsigned char *)s->init_buf->data; | ||
1069 | p= &(d[4]); | ||
1070 | |||
1071 | for (i=0; r[i] != NULL; i++) | ||
1072 | { | ||
1073 | s2n(nr[i],p); | ||
1074 | BN_bn2bin(r[i],p); | ||
1075 | p+=nr[i]; | ||
1076 | } | ||
1077 | |||
1078 | /* not anonymous */ | ||
1079 | if (pkey != NULL) | ||
1080 | { | ||
1081 | /* n is the length of the params, they start at &(d[4]) | ||
1082 | * and p points to the space at the end. */ | ||
1083 | #ifndef NO_RSA | ||
1084 | if (pkey->type == EVP_PKEY_RSA) | ||
1085 | { | ||
1086 | q=md_buf; | ||
1087 | j=0; | ||
1088 | for (num=2; num > 0; num--) | ||
1089 | { | ||
1090 | EVP_DigestInit(&md_ctx,(num == 2) | ||
1091 | ?s->ctx->md5:s->ctx->sha1); | ||
1092 | EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1093 | EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1094 | EVP_DigestUpdate(&md_ctx,&(d[4]),n); | ||
1095 | EVP_DigestFinal(&md_ctx,q, | ||
1096 | (unsigned int *)&i); | ||
1097 | q+=i; | ||
1098 | j+=i; | ||
1099 | } | ||
1100 | if (RSA_sign(NID_md5_sha1, md_buf, j, | ||
1101 | &(p[2]), &u, pkey->pkey.rsa) <= 0) | ||
1102 | { | ||
1103 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA); | ||
1104 | goto err; | ||
1105 | } | ||
1106 | s2n(u,p); | ||
1107 | n+=u+2; | ||
1108 | } | ||
1109 | else | ||
1110 | #endif | ||
1111 | #if !defined(NO_DSA) | ||
1112 | if (pkey->type == EVP_PKEY_DSA) | ||
1113 | { | ||
1114 | /* lets do DSS */ | ||
1115 | EVP_SignInit(&md_ctx,EVP_dss1()); | ||
1116 | EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE); | ||
1117 | EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE); | ||
1118 | EVP_SignUpdate(&md_ctx,&(d[4]),n); | ||
1119 | if (!EVP_SignFinal(&md_ctx,&(p[2]), | ||
1120 | (unsigned int *)&i,pkey)) | ||
1121 | { | ||
1122 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA); | ||
1123 | goto err; | ||
1124 | } | ||
1125 | s2n(i,p); | ||
1126 | n+=i+2; | ||
1127 | } | ||
1128 | else | ||
1129 | #endif | ||
1130 | { | ||
1131 | /* Is this error check actually needed? */ | ||
1132 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1133 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE); | ||
1134 | goto f_err; | ||
1135 | } | ||
1136 | } | ||
1137 | |||
1138 | *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE; | ||
1139 | l2n3(n,d); | ||
1140 | |||
1141 | /* we should now have things packed up, so lets send | ||
1142 | * it off */ | ||
1143 | s->init_num=n+4; | ||
1144 | s->init_off=0; | ||
1145 | } | ||
1146 | |||
1147 | s->state = SSL3_ST_SW_KEY_EXCH_B; | ||
1148 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1149 | f_err: | ||
1150 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1151 | err: | ||
1152 | return(-1); | ||
1153 | } | ||
1154 | |||
1155 | static int ssl3_send_certificate_request(SSL *s) | ||
1156 | { | ||
1157 | unsigned char *p,*d; | ||
1158 | int i,j,nl,off,n; | ||
1159 | STACK_OF(X509_NAME) *sk=NULL; | ||
1160 | X509_NAME *name; | ||
1161 | BUF_MEM *buf; | ||
1162 | |||
1163 | if (s->state == SSL3_ST_SW_CERT_REQ_A) | ||
1164 | { | ||
1165 | buf=s->init_buf; | ||
1166 | |||
1167 | d=p=(unsigned char *)&(buf->data[4]); | ||
1168 | |||
1169 | /* get the list of acceptable cert types */ | ||
1170 | p++; | ||
1171 | n=ssl3_get_req_cert_type(s,p); | ||
1172 | d[0]=n; | ||
1173 | p+=n; | ||
1174 | n++; | ||
1175 | |||
1176 | off=n; | ||
1177 | p+=2; | ||
1178 | n+=2; | ||
1179 | |||
1180 | sk=SSL_get_client_CA_list(s); | ||
1181 | nl=0; | ||
1182 | if (sk != NULL) | ||
1183 | { | ||
1184 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
1185 | { | ||
1186 | name=sk_X509_NAME_value(sk,i); | ||
1187 | j=i2d_X509_NAME(name,NULL); | ||
1188 | if (!BUF_MEM_grow(buf,4+n+j+2)) | ||
1189 | { | ||
1190 | SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); | ||
1191 | goto err; | ||
1192 | } | ||
1193 | p=(unsigned char *)&(buf->data[4+n]); | ||
1194 | if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) | ||
1195 | { | ||
1196 | s2n(j,p); | ||
1197 | i2d_X509_NAME(name,&p); | ||
1198 | n+=2+j; | ||
1199 | nl+=2+j; | ||
1200 | } | ||
1201 | else | ||
1202 | { | ||
1203 | d=p; | ||
1204 | i2d_X509_NAME(name,&p); | ||
1205 | j-=2; s2n(j,d); j+=2; | ||
1206 | n+=j; | ||
1207 | nl+=j; | ||
1208 | } | ||
1209 | } | ||
1210 | } | ||
1211 | /* else no CA names */ | ||
1212 | p=(unsigned char *)&(buf->data[4+off]); | ||
1213 | s2n(nl,p); | ||
1214 | |||
1215 | d=(unsigned char *)buf->data; | ||
1216 | *(d++)=SSL3_MT_CERTIFICATE_REQUEST; | ||
1217 | l2n3(n,d); | ||
1218 | |||
1219 | /* we should now have things packed up, so lets send | ||
1220 | * it off */ | ||
1221 | |||
1222 | s->init_num=n+4; | ||
1223 | s->init_off=0; | ||
1224 | #ifdef NETSCAPE_HANG_BUG | ||
1225 | p=(unsigned char *)s->init_buf->data + s->init_num; | ||
1226 | |||
1227 | /* do the header */ | ||
1228 | *(p++)=SSL3_MT_SERVER_DONE; | ||
1229 | *(p++)=0; | ||
1230 | *(p++)=0; | ||
1231 | *(p++)=0; | ||
1232 | s->init_num += 4; | ||
1233 | #endif | ||
1234 | |||
1235 | } | ||
1236 | |||
1237 | /* SSL3_ST_SW_CERT_REQ_B */ | ||
1238 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1239 | err: | ||
1240 | return(-1); | ||
1241 | } | ||
1242 | |||
1243 | static int ssl3_get_client_key_exchange(SSL *s) | ||
1244 | { | ||
1245 | int i,al,ok; | ||
1246 | long n; | ||
1247 | unsigned long l; | ||
1248 | unsigned char *p; | ||
1249 | #ifndef NO_RSA | ||
1250 | RSA *rsa=NULL; | ||
1251 | EVP_PKEY *pkey=NULL; | ||
1252 | #endif | ||
1253 | #ifndef NO_DH | ||
1254 | BIGNUM *pub=NULL; | ||
1255 | DH *dh_srvr; | ||
1256 | #endif | ||
1257 | |||
1258 | n=ssl3_get_message(s, | ||
1259 | SSL3_ST_SR_KEY_EXCH_A, | ||
1260 | SSL3_ST_SR_KEY_EXCH_B, | ||
1261 | SSL3_MT_CLIENT_KEY_EXCHANGE, | ||
1262 | 400, /* ???? */ | ||
1263 | &ok); | ||
1264 | |||
1265 | if (!ok) return((int)n); | ||
1266 | p=(unsigned char *)s->init_buf->data; | ||
1267 | |||
1268 | l=s->s3->tmp.new_cipher->algorithms; | ||
1269 | |||
1270 | #ifndef NO_RSA | ||
1271 | if (l & SSL_kRSA) | ||
1272 | { | ||
1273 | /* FIX THIS UP EAY EAY EAY EAY */ | ||
1274 | if (s->s3->tmp.use_rsa_tmp) | ||
1275 | { | ||
1276 | if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL)) | ||
1277 | rsa=s->cert->rsa_tmp; | ||
1278 | /* Don't do a callback because rsa_tmp should | ||
1279 | * be sent already */ | ||
1280 | if (rsa == NULL) | ||
1281 | { | ||
1282 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1283 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY); | ||
1284 | goto f_err; | ||
1285 | |||
1286 | } | ||
1287 | } | ||
1288 | else | ||
1289 | { | ||
1290 | pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey; | ||
1291 | if ( (pkey == NULL) || | ||
1292 | (pkey->type != EVP_PKEY_RSA) || | ||
1293 | (pkey->pkey.rsa == NULL)) | ||
1294 | { | ||
1295 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1296 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE); | ||
1297 | goto f_err; | ||
1298 | } | ||
1299 | rsa=pkey->pkey.rsa; | ||
1300 | } | ||
1301 | |||
1302 | /* TLS */ | ||
1303 | if (s->version > SSL3_VERSION) | ||
1304 | { | ||
1305 | n2s(p,i); | ||
1306 | if (n != i+2) | ||
1307 | { | ||
1308 | if (!(s->options & SSL_OP_TLS_D5_BUG)) | ||
1309 | { | ||
1310 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG); | ||
1311 | goto err; | ||
1312 | } | ||
1313 | else | ||
1314 | p-=2; | ||
1315 | } | ||
1316 | else | ||
1317 | n=i; | ||
1318 | } | ||
1319 | |||
1320 | i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING); | ||
1321 | |||
1322 | if (i != SSL_MAX_MASTER_KEY_LENGTH) | ||
1323 | { | ||
1324 | al=SSL_AD_DECODE_ERROR; | ||
1325 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | ||
1326 | goto f_err; | ||
1327 | } | ||
1328 | |||
1329 | if ((p[0] != (s->client_version>>8)) || (p[1] != (s->client_version & 0xff))) | ||
1330 | { | ||
1331 | al=SSL_AD_DECODE_ERROR; | ||
1332 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); | ||
1333 | goto f_err; | ||
1334 | } | ||
1335 | |||
1336 | s->session->master_key_length= | ||
1337 | s->method->ssl3_enc->generate_master_secret(s, | ||
1338 | s->session->master_key, | ||
1339 | p,i); | ||
1340 | memset(p,0,i); | ||
1341 | } | ||
1342 | else | ||
1343 | #endif | ||
1344 | #ifndef NO_DH | ||
1345 | if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | ||
1346 | { | ||
1347 | n2s(p,i); | ||
1348 | if (n != i+2) | ||
1349 | { | ||
1350 | if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG)) | ||
1351 | { | ||
1352 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG); | ||
1353 | goto err; | ||
1354 | } | ||
1355 | else | ||
1356 | { | ||
1357 | p-=2; | ||
1358 | i=(int)n; | ||
1359 | } | ||
1360 | } | ||
1361 | |||
1362 | if (n == 0L) /* the parameters are in the cert */ | ||
1363 | { | ||
1364 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1365 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS); | ||
1366 | goto f_err; | ||
1367 | } | ||
1368 | else | ||
1369 | { | ||
1370 | if (s->s3->tmp.dh == NULL) | ||
1371 | { | ||
1372 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1373 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY); | ||
1374 | goto f_err; | ||
1375 | } | ||
1376 | else | ||
1377 | dh_srvr=s->s3->tmp.dh; | ||
1378 | } | ||
1379 | |||
1380 | pub=BN_bin2bn(p,i,NULL); | ||
1381 | if (pub == NULL) | ||
1382 | { | ||
1383 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB); | ||
1384 | goto err; | ||
1385 | } | ||
1386 | |||
1387 | i=DH_compute_key(p,pub,dh_srvr); | ||
1388 | |||
1389 | if (i <= 0) | ||
1390 | { | ||
1391 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB); | ||
1392 | goto err; | ||
1393 | } | ||
1394 | |||
1395 | DH_free(s->s3->tmp.dh); | ||
1396 | s->s3->tmp.dh=NULL; | ||
1397 | |||
1398 | BN_clear_free(pub); | ||
1399 | pub=NULL; | ||
1400 | s->session->master_key_length= | ||
1401 | s->method->ssl3_enc->generate_master_secret(s, | ||
1402 | s->session->master_key,p,i); | ||
1403 | } | ||
1404 | else | ||
1405 | #endif | ||
1406 | { | ||
1407 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1408 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE); | ||
1409 | goto f_err; | ||
1410 | } | ||
1411 | |||
1412 | return(1); | ||
1413 | f_err: | ||
1414 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1415 | #if !defined(NO_DH) || !defined(NO_RSA) | ||
1416 | err: | ||
1417 | #endif | ||
1418 | return(-1); | ||
1419 | } | ||
1420 | |||
1421 | static int ssl3_get_cert_verify(SSL *s) | ||
1422 | { | ||
1423 | EVP_PKEY *pkey=NULL; | ||
1424 | unsigned char *p; | ||
1425 | int al,ok,ret=0; | ||
1426 | long n; | ||
1427 | int type=0,i,j; | ||
1428 | X509 *peer; | ||
1429 | |||
1430 | n=ssl3_get_message(s, | ||
1431 | SSL3_ST_SR_CERT_VRFY_A, | ||
1432 | SSL3_ST_SR_CERT_VRFY_B, | ||
1433 | -1, | ||
1434 | 512, /* 512? */ | ||
1435 | &ok); | ||
1436 | |||
1437 | if (!ok) return((int)n); | ||
1438 | |||
1439 | if (s->session->peer != NULL) | ||
1440 | { | ||
1441 | peer=s->session->peer; | ||
1442 | pkey=X509_get_pubkey(peer); | ||
1443 | type=X509_certificate_type(peer,pkey); | ||
1444 | } | ||
1445 | else | ||
1446 | { | ||
1447 | peer=NULL; | ||
1448 | pkey=NULL; | ||
1449 | } | ||
1450 | |||
1451 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY) | ||
1452 | { | ||
1453 | s->s3->tmp.reuse_message=1; | ||
1454 | if ((peer != NULL) && (type | EVP_PKT_SIGN)) | ||
1455 | { | ||
1456 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1457 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE); | ||
1458 | goto f_err; | ||
1459 | } | ||
1460 | ret=1; | ||
1461 | goto end; | ||
1462 | } | ||
1463 | |||
1464 | if (peer == NULL) | ||
1465 | { | ||
1466 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED); | ||
1467 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1468 | goto f_err; | ||
1469 | } | ||
1470 | |||
1471 | if (!(type & EVP_PKT_SIGN)) | ||
1472 | { | ||
1473 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE); | ||
1474 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
1475 | goto f_err; | ||
1476 | } | ||
1477 | |||
1478 | if (s->s3->change_cipher_spec) | ||
1479 | { | ||
1480 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY); | ||
1481 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1482 | goto f_err; | ||
1483 | } | ||
1484 | |||
1485 | /* we now have a signature that we need to verify */ | ||
1486 | p=(unsigned char *)s->init_buf->data; | ||
1487 | n2s(p,i); | ||
1488 | n-=2; | ||
1489 | if (i > n) | ||
1490 | { | ||
1491 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH); | ||
1492 | al=SSL_AD_DECODE_ERROR; | ||
1493 | goto f_err; | ||
1494 | } | ||
1495 | |||
1496 | j=EVP_PKEY_size(pkey); | ||
1497 | if ((i > j) || (n > j) || (n <= 0)) | ||
1498 | { | ||
1499 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE); | ||
1500 | al=SSL_AD_DECODE_ERROR; | ||
1501 | goto f_err; | ||
1502 | } | ||
1503 | |||
1504 | #ifndef NO_RSA | ||
1505 | if (pkey->type == EVP_PKEY_RSA) | ||
1506 | { | ||
1507 | i=RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md, | ||
1508 | MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, p, i, | ||
1509 | pkey->pkey.rsa); | ||
1510 | if (i < 0) | ||
1511 | { | ||
1512 | al=SSL_AD_DECRYPT_ERROR; | ||
1513 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT); | ||
1514 | goto f_err; | ||
1515 | } | ||
1516 | if (i == 0) | ||
1517 | { | ||
1518 | al=SSL_AD_DECRYPT_ERROR; | ||
1519 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE); | ||
1520 | goto f_err; | ||
1521 | } | ||
1522 | } | ||
1523 | else | ||
1524 | #endif | ||
1525 | #ifndef NO_DSA | ||
1526 | if (pkey->type == EVP_PKEY_DSA) | ||
1527 | { | ||
1528 | j=DSA_verify(pkey->save_type, | ||
1529 | &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]), | ||
1530 | SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa); | ||
1531 | if (j <= 0) | ||
1532 | { | ||
1533 | /* bad signature */ | ||
1534 | al=SSL_AD_DECRYPT_ERROR; | ||
1535 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE); | ||
1536 | goto f_err; | ||
1537 | } | ||
1538 | } | ||
1539 | else | ||
1540 | #endif | ||
1541 | { | ||
1542 | SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR); | ||
1543 | al=SSL_AD_UNSUPPORTED_CERTIFICATE; | ||
1544 | goto f_err; | ||
1545 | } | ||
1546 | |||
1547 | |||
1548 | ret=1; | ||
1549 | if (0) | ||
1550 | { | ||
1551 | f_err: | ||
1552 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1553 | } | ||
1554 | end: | ||
1555 | EVP_PKEY_free(pkey); | ||
1556 | return(ret); | ||
1557 | } | ||
1558 | |||
1559 | static int ssl3_get_client_certificate(SSL *s) | ||
1560 | { | ||
1561 | int i,ok,al,ret= -1; | ||
1562 | X509 *x=NULL; | ||
1563 | unsigned long l,nc,llen,n; | ||
1564 | unsigned char *p,*d,*q; | ||
1565 | STACK_OF(X509) *sk=NULL; | ||
1566 | |||
1567 | n=ssl3_get_message(s, | ||
1568 | SSL3_ST_SR_CERT_A, | ||
1569 | SSL3_ST_SR_CERT_B, | ||
1570 | -1, | ||
1571 | #if defined(MSDOS) && !defined(WIN32) | ||
1572 | 1024*30, /* 30k max cert list :-) */ | ||
1573 | #else | ||
1574 | 1024*100, /* 100k max cert list :-) */ | ||
1575 | #endif | ||
1576 | &ok); | ||
1577 | |||
1578 | if (!ok) return((int)n); | ||
1579 | |||
1580 | if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) | ||
1581 | { | ||
1582 | if ( (s->verify_mode & SSL_VERIFY_PEER) && | ||
1583 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
1584 | { | ||
1585 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
1586 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1587 | goto f_err; | ||
1588 | } | ||
1589 | /* If tls asked for a client cert, the client must return a 0 list */ | ||
1590 | if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request) | ||
1591 | { | ||
1592 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST); | ||
1593 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1594 | goto f_err; | ||
1595 | } | ||
1596 | s->s3->tmp.reuse_message=1; | ||
1597 | return(1); | ||
1598 | } | ||
1599 | |||
1600 | if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) | ||
1601 | { | ||
1602 | al=SSL_AD_UNEXPECTED_MESSAGE; | ||
1603 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE); | ||
1604 | goto f_err; | ||
1605 | } | ||
1606 | d=p=(unsigned char *)s->init_buf->data; | ||
1607 | |||
1608 | if ((sk=sk_X509_new_null()) == NULL) | ||
1609 | { | ||
1610 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
1611 | goto err; | ||
1612 | } | ||
1613 | |||
1614 | n2l3(p,llen); | ||
1615 | if (llen+3 != n) | ||
1616 | { | ||
1617 | al=SSL_AD_DECODE_ERROR; | ||
1618 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH); | ||
1619 | goto f_err; | ||
1620 | } | ||
1621 | for (nc=0; nc<llen; ) | ||
1622 | { | ||
1623 | n2l3(p,l); | ||
1624 | if ((l+nc+3) > llen) | ||
1625 | { | ||
1626 | al=SSL_AD_DECODE_ERROR; | ||
1627 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
1628 | goto f_err; | ||
1629 | } | ||
1630 | |||
1631 | q=p; | ||
1632 | x=d2i_X509(NULL,&p,l); | ||
1633 | if (x == NULL) | ||
1634 | { | ||
1635 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB); | ||
1636 | goto err; | ||
1637 | } | ||
1638 | if (p != (q+l)) | ||
1639 | { | ||
1640 | al=SSL_AD_DECODE_ERROR; | ||
1641 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | ||
1642 | goto f_err; | ||
1643 | } | ||
1644 | if (!sk_X509_push(sk,x)) | ||
1645 | { | ||
1646 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
1647 | goto err; | ||
1648 | } | ||
1649 | x=NULL; | ||
1650 | nc+=l+3; | ||
1651 | } | ||
1652 | |||
1653 | if (sk_X509_num(sk) <= 0) | ||
1654 | { | ||
1655 | /* TLS does not mind 0 certs returned */ | ||
1656 | if (s->version == SSL3_VERSION) | ||
1657 | { | ||
1658 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1659 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED); | ||
1660 | goto f_err; | ||
1661 | } | ||
1662 | /* Fail for TLS only if we required a certificate */ | ||
1663 | else if ((s->verify_mode & SSL_VERIFY_PEER) && | ||
1664 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) | ||
1665 | { | ||
1666 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | ||
1667 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1668 | goto f_err; | ||
1669 | } | ||
1670 | } | ||
1671 | else | ||
1672 | { | ||
1673 | i=ssl_verify_cert_chain(s,sk); | ||
1674 | if (!i) | ||
1675 | { | ||
1676 | al=ssl_verify_alarm_type(s->verify_result); | ||
1677 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED); | ||
1678 | goto f_err; | ||
1679 | } | ||
1680 | } | ||
1681 | |||
1682 | if (s->session->peer != NULL) /* This should not be needed */ | ||
1683 | X509_free(s->session->peer); | ||
1684 | s->session->peer=sk_X509_shift(sk); | ||
1685 | s->session->verify_result = s->verify_result; | ||
1686 | |||
1687 | /* With the current implementation, sess_cert will always be NULL | ||
1688 | * when we arrive here. */ | ||
1689 | if (s->session->sess_cert == NULL) | ||
1690 | { | ||
1691 | s->session->sess_cert = ssl_sess_cert_new(); | ||
1692 | if (s->session->sess_cert == NULL) | ||
1693 | { | ||
1694 | SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE); | ||
1695 | goto err; | ||
1696 | } | ||
1697 | } | ||
1698 | if (s->session->sess_cert->cert_chain != NULL) | ||
1699 | sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free); | ||
1700 | s->session->sess_cert->cert_chain=sk; | ||
1701 | /* Inconsistency alert: cert_chain does *not* include the | ||
1702 | * peer's own certificate, while we do include it in s3_clnt.c */ | ||
1703 | |||
1704 | sk=NULL; | ||
1705 | |||
1706 | ret=1; | ||
1707 | if (0) | ||
1708 | { | ||
1709 | f_err: | ||
1710 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | ||
1711 | } | ||
1712 | err: | ||
1713 | if (x != NULL) X509_free(x); | ||
1714 | if (sk != NULL) sk_X509_pop_free(sk,X509_free); | ||
1715 | return(ret); | ||
1716 | } | ||
1717 | |||
1718 | int ssl3_send_server_certificate(SSL *s) | ||
1719 | { | ||
1720 | unsigned long l; | ||
1721 | X509 *x; | ||
1722 | |||
1723 | if (s->state == SSL3_ST_SW_CERT_A) | ||
1724 | { | ||
1725 | x=ssl_get_server_send_cert(s); | ||
1726 | if (x == NULL) | ||
1727 | { | ||
1728 | SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR); | ||
1729 | return(0); | ||
1730 | } | ||
1731 | |||
1732 | l=ssl3_output_cert_chain(s,x); | ||
1733 | s->state=SSL3_ST_SW_CERT_B; | ||
1734 | s->init_num=(int)l; | ||
1735 | s->init_off=0; | ||
1736 | } | ||
1737 | |||
1738 | /* SSL3_ST_SW_CERT_B */ | ||
1739 | return(ssl3_do_write(s,SSL3_RT_HANDSHAKE)); | ||
1740 | } | ||
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version deleted file mode 100644 index c87e1c60d4..0000000000 --- a/src/lib/libssl/shlib_version +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | major=2 | ||
2 | minor=4 | ||
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h deleted file mode 100644 index bb846f491c..0000000000 --- a/src/lib/libssl/ssl.h +++ /dev/null | |||
@@ -1,1533 +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 | #ifndef HEADER_SSL_H | ||
60 | #define HEADER_SSL_H | ||
61 | |||
62 | #ifdef __cplusplus | ||
63 | extern "C" { | ||
64 | #endif | ||
65 | |||
66 | #include <openssl/safestack.h> | ||
67 | |||
68 | /* SSLeay version number for ASN.1 encoding of the session information */ | ||
69 | /* Version 0 - initial version | ||
70 | * Version 1 - added the optional peer certificate | ||
71 | */ | ||
72 | #define SSL_SESSION_ASN1_VERSION 0x0001 | ||
73 | |||
74 | /* text strings for the ciphers */ | ||
75 | #define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5 | ||
76 | #define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5 | ||
77 | #define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 | ||
78 | #define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5 | ||
79 | #define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 | ||
80 | #define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5 | ||
81 | #define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5 | ||
82 | #define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA | ||
83 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 | ||
84 | #define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA | ||
85 | |||
86 | #define SSL_MAX_SSL_SESSION_ID_LENGTH 32 | ||
87 | #define SSL_MAX_SID_CTX_LENGTH 32 | ||
88 | |||
89 | #define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8) | ||
90 | #define SSL_MAX_KEY_ARG_LENGTH 8 | ||
91 | #define SSL_MAX_MASTER_KEY_LENGTH 48 | ||
92 | |||
93 | /* These are used to specify which ciphers to use and not to use */ | ||
94 | #define SSL_TXT_LOW "LOW" | ||
95 | #define SSL_TXT_MEDIUM "MEDIUM" | ||
96 | #define SSL_TXT_HIGH "HIGH" | ||
97 | #define SSL_TXT_kFZA "kFZA" | ||
98 | #define SSL_TXT_aFZA "aFZA" | ||
99 | #define SSL_TXT_eFZA "eFZA" | ||
100 | #define SSL_TXT_FZA "FZA" | ||
101 | |||
102 | #define SSL_TXT_aNULL "aNULL" | ||
103 | #define SSL_TXT_eNULL "eNULL" | ||
104 | #define SSL_TXT_NULL "NULL" | ||
105 | |||
106 | #define SSL_TXT_kRSA "kRSA" | ||
107 | #define SSL_TXT_kDHr "kDHr" | ||
108 | #define SSL_TXT_kDHd "kDHd" | ||
109 | #define SSL_TXT_kEDH "kEDH" | ||
110 | #define SSL_TXT_aRSA "aRSA" | ||
111 | #define SSL_TXT_aDSS "aDSS" | ||
112 | #define SSL_TXT_aDH "aDH" | ||
113 | #define SSL_TXT_DSS "DSS" | ||
114 | #define SSL_TXT_DH "DH" | ||
115 | #define SSL_TXT_EDH "EDH" | ||
116 | #define SSL_TXT_ADH "ADH" | ||
117 | #define SSL_TXT_RSA "RSA" | ||
118 | #define SSL_TXT_DES "DES" | ||
119 | #define SSL_TXT_3DES "3DES" | ||
120 | #define SSL_TXT_RC4 "RC4" | ||
121 | #define SSL_TXT_RC2 "RC2" | ||
122 | #define SSL_TXT_IDEA "IDEA" | ||
123 | #define SSL_TXT_MD5 "MD5" | ||
124 | #define SSL_TXT_SHA1 "SHA1" | ||
125 | #define SSL_TXT_SHA "SHA" | ||
126 | #define SSL_TXT_EXP "EXP" | ||
127 | #define SSL_TXT_EXPORT "EXPORT" | ||
128 | #define SSL_TXT_EXP40 "EXPORT40" | ||
129 | #define SSL_TXT_EXP56 "EXPORT56" | ||
130 | #define SSL_TXT_SSLV2 "SSLv2" | ||
131 | #define SSL_TXT_SSLV3 "SSLv3" | ||
132 | #define SSL_TXT_TLSV1 "TLSv1" | ||
133 | #define SSL_TXT_ALL "ALL" | ||
134 | |||
135 | /* 'DEFAULT' at the start of the cipher list insert the following string | ||
136 | * in addition to this being the default cipher string */ | ||
137 | #define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH" | ||
138 | |||
139 | /* Used in SSL_set_shutdown()/SSL_get_shutdown(); */ | ||
140 | #define SSL_SENT_SHUTDOWN 1 | ||
141 | #define SSL_RECEIVED_SHUTDOWN 2 | ||
142 | |||
143 | #include <openssl/crypto.h> | ||
144 | #include <openssl/lhash.h> | ||
145 | #include <openssl/buffer.h> | ||
146 | #include <openssl/bio.h> | ||
147 | #include <openssl/pem.h> | ||
148 | #include <openssl/x509.h> | ||
149 | |||
150 | #if (defined(NO_RSA) || defined(NO_MD5)) && !defined(NO_SSL2) | ||
151 | #define NO_SSL2 | ||
152 | #endif | ||
153 | |||
154 | #define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1 | ||
155 | #define SSL_FILETYPE_PEM X509_FILETYPE_PEM | ||
156 | |||
157 | /* This is needed to stop compilers complaining about the | ||
158 | * 'struct ssl_st *' function parameters used to prototype callbacks | ||
159 | * in SSL_CTX. */ | ||
160 | typedef struct ssl_st *ssl_crock_st; | ||
161 | |||
162 | /* used to hold info on the particular ciphers used */ | ||
163 | typedef struct ssl_cipher_st | ||
164 | { | ||
165 | int valid; | ||
166 | const char *name; /* text name */ | ||
167 | unsigned long id; /* id, 4 bytes, first is version */ | ||
168 | unsigned long algorithms; /* what ciphers are used */ | ||
169 | unsigned long algo_strength; /* strength and export flags */ | ||
170 | unsigned long algorithm2; /* Extra flags */ | ||
171 | int strength_bits; /* Number of bits really used */ | ||
172 | int alg_bits; /* Number of bits for algorithm */ | ||
173 | unsigned long mask; /* used for matching */ | ||
174 | unsigned long mask_strength; /* also used for matching */ | ||
175 | } SSL_CIPHER; | ||
176 | |||
177 | DECLARE_STACK_OF(SSL_CIPHER) | ||
178 | |||
179 | typedef struct ssl_st SSL; | ||
180 | typedef struct ssl_ctx_st SSL_CTX; | ||
181 | |||
182 | /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */ | ||
183 | typedef struct ssl_method_st | ||
184 | { | ||
185 | int version; | ||
186 | int (*ssl_new)(SSL *s); | ||
187 | void (*ssl_clear)(SSL *s); | ||
188 | void (*ssl_free)(SSL *s); | ||
189 | int (*ssl_accept)(SSL *s); | ||
190 | int (*ssl_connect)(SSL *s); | ||
191 | int (*ssl_read)(SSL *s,void *buf,int len); | ||
192 | int (*ssl_peek)(SSL *s,char *buf,int len); | ||
193 | int (*ssl_write)(SSL *s,const void *buf,int len); | ||
194 | int (*ssl_shutdown)(SSL *s); | ||
195 | int (*ssl_renegotiate)(SSL *s); | ||
196 | int (*ssl_renegotiate_check)(SSL *s); | ||
197 | long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg); | ||
198 | long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg); | ||
199 | SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr); | ||
200 | int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr); | ||
201 | int (*ssl_pending)(SSL *s); | ||
202 | int (*num_ciphers)(void); | ||
203 | SSL_CIPHER *(*get_cipher)(unsigned ncipher); | ||
204 | struct ssl_method_st *(*get_ssl_method)(int version); | ||
205 | long (*get_timeout)(void); | ||
206 | struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */ | ||
207 | int (*ssl_version)(); | ||
208 | long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)()); | ||
209 | long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)()); | ||
210 | } SSL_METHOD; | ||
211 | |||
212 | /* Lets make this into an ASN.1 type structure as follows | ||
213 | * SSL_SESSION_ID ::= SEQUENCE { | ||
214 | * version INTEGER, -- structure version number | ||
215 | * SSLversion INTEGER, -- SSL version number | ||
216 | * Cipher OCTET_STRING, -- the 3 byte cipher ID | ||
217 | * Session_ID OCTET_STRING, -- the Session ID | ||
218 | * Master_key OCTET_STRING, -- the master key | ||
219 | * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument | ||
220 | * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time | ||
221 | * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds | ||
222 | * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate | ||
223 | * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context | ||
224 | * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer' | ||
225 | * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX | ||
226 | * } | ||
227 | * Look in ssl/ssl_asn1.c for more details | ||
228 | * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-). | ||
229 | */ | ||
230 | typedef struct ssl_session_st | ||
231 | { | ||
232 | int ssl_version; /* what ssl version session info is | ||
233 | * being kept in here? */ | ||
234 | |||
235 | /* only really used in SSLv2 */ | ||
236 | unsigned int key_arg_length; | ||
237 | unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH]; | ||
238 | int master_key_length; | ||
239 | unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH]; | ||
240 | /* session_id - valid? */ | ||
241 | unsigned int session_id_length; | ||
242 | unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH]; | ||
243 | /* this is used to determine whether the session is being reused in | ||
244 | * the appropriate context. It is up to the application to set this, | ||
245 | * via SSL_new */ | ||
246 | unsigned int sid_ctx_length; | ||
247 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
248 | |||
249 | int not_resumable; | ||
250 | |||
251 | /* The cert is the certificate used to establish this connection */ | ||
252 | struct sess_cert_st /* SESS_CERT */ *sess_cert; | ||
253 | |||
254 | /* This is the cert for the other end. | ||
255 | * On clients, it will be the same as sess_cert->peer_key->x509 | ||
256 | * (the latter is not enough as sess_cert is not retained | ||
257 | * in the external representation of sessions, see ssl_asn1.c). */ | ||
258 | X509 *peer; | ||
259 | /* when app_verify_callback accepts a session where the peer's certificate | ||
260 | * is not ok, we must remember the error for session reuse: */ | ||
261 | long verify_result; /* only for servers */ | ||
262 | |||
263 | int references; | ||
264 | long timeout; | ||
265 | long time; | ||
266 | |||
267 | int compress_meth; /* Need to lookup the method */ | ||
268 | |||
269 | SSL_CIPHER *cipher; | ||
270 | unsigned long cipher_id; /* when ASN.1 loaded, this | ||
271 | * needs to be used to load | ||
272 | * the 'cipher' structure */ | ||
273 | |||
274 | STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */ | ||
275 | |||
276 | CRYPTO_EX_DATA ex_data; /* application specific data */ | ||
277 | |||
278 | /* These are used to make removal of session-ids more | ||
279 | * efficient and to implement a maximum cache size. */ | ||
280 | struct ssl_session_st *prev,*next; | ||
281 | } SSL_SESSION; | ||
282 | |||
283 | #define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L | ||
284 | #define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L | ||
285 | #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L | ||
286 | #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L | ||
287 | #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L | ||
288 | #define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L | ||
289 | #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L | ||
290 | #define SSL_OP_TLS_D5_BUG 0x00000100L | ||
291 | #define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L | ||
292 | #define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L | ||
293 | |||
294 | /* If set, always create a new key when using tmp_dh parameters */ | ||
295 | #define SSL_OP_SINGLE_DH_USE 0x00100000L | ||
296 | /* Set to also use the tmp_rsa key when doing RSA operations. */ | ||
297 | #define SSL_OP_EPHEMERAL_RSA 0x00200000L | ||
298 | |||
299 | /* The next flag deliberately changes the ciphertest, this is a check | ||
300 | * for the PKCS#1 attack */ | ||
301 | #define SSL_OP_PKCS1_CHECK_1 0x08000000L | ||
302 | #define SSL_OP_PKCS1_CHECK_2 0x10000000L | ||
303 | #define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L | ||
304 | /* SSL_OP_NON_EXPORT_FIRST looks utterly broken .. */ | ||
305 | #define SSL_OP_NON_EXPORT_FIRST 0x40000000L | ||
306 | #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L | ||
307 | #define SSL_OP_ALL 0x000FFFFFL | ||
308 | |||
309 | #define SSL_OP_NO_SSLv2 0x01000000L | ||
310 | #define SSL_OP_NO_SSLv3 0x02000000L | ||
311 | #define SSL_OP_NO_TLSv1 0x04000000L | ||
312 | |||
313 | /* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success | ||
314 | * when just a single record has been written): */ | ||
315 | #define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L | ||
316 | /* Make it possible to retry SSL_write() with changed buffer location | ||
317 | * (buffer contents must stay the same!); this is not the default to avoid | ||
318 | * the misconception that non-blocking SSL_write() behaves like | ||
319 | * non-blocking write(): */ | ||
320 | #define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L | ||
321 | |||
322 | /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, | ||
323 | * they cannot be used to clear bits. */ | ||
324 | |||
325 | #define SSL_CTX_set_options(ctx,op) \ | ||
326 | SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL) | ||
327 | #define SSL_CTX_get_options(ctx) \ | ||
328 | SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL) | ||
329 | #define SSL_set_options(ssl,op) \ | ||
330 | SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL) | ||
331 | #define SSL_get_options(ssl) \ | ||
332 | SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL) | ||
333 | |||
334 | #define SSL_CTX_set_mode(ctx,op) \ | ||
335 | SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL) | ||
336 | #define SSL_CTX_get_mode(ctx) \ | ||
337 | SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL) | ||
338 | #define SSL_set_mode(ssl,op) \ | ||
339 | SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL) | ||
340 | #define SSL_get_mode(ssl) \ | ||
341 | SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL) | ||
342 | |||
343 | #define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20) | ||
344 | |||
345 | typedef struct ssl_comp_st | ||
346 | { | ||
347 | int id; | ||
348 | char *name; | ||
349 | #ifdef HEADER_COMP_H | ||
350 | COMP_METHOD *method; | ||
351 | #else | ||
352 | char *method; | ||
353 | #endif | ||
354 | } SSL_COMP; | ||
355 | |||
356 | DECLARE_STACK_OF(SSL_COMP) | ||
357 | |||
358 | struct ssl_ctx_st | ||
359 | { | ||
360 | SSL_METHOD *method; | ||
361 | unsigned long options; | ||
362 | unsigned long mode; | ||
363 | |||
364 | STACK_OF(SSL_CIPHER) *cipher_list; | ||
365 | /* same as above but sorted for lookup */ | ||
366 | STACK_OF(SSL_CIPHER) *cipher_list_by_id; | ||
367 | |||
368 | struct x509_store_st /* X509_STORE */ *cert_store; | ||
369 | struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */ | ||
370 | /* Most session-ids that will be cached, default is | ||
371 | * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */ | ||
372 | unsigned long session_cache_size; | ||
373 | struct ssl_session_st *session_cache_head; | ||
374 | struct ssl_session_st *session_cache_tail; | ||
375 | |||
376 | /* This can have one of 2 values, ored together, | ||
377 | * SSL_SESS_CACHE_CLIENT, | ||
378 | * SSL_SESS_CACHE_SERVER, | ||
379 | * Default is SSL_SESSION_CACHE_SERVER, which means only | ||
380 | * SSL_accept which cache SSL_SESSIONS. */ | ||
381 | int session_cache_mode; | ||
382 | |||
383 | /* If timeout is not 0, it is the default timeout value set | ||
384 | * when SSL_new() is called. This has been put in to make | ||
385 | * life easier to set things up */ | ||
386 | long session_timeout; | ||
387 | |||
388 | /* If this callback is not null, it will be called each | ||
389 | * time a session id is added to the cache. If this function | ||
390 | * returns 1, it means that the callback will do a | ||
391 | * SSL_SESSION_free() when it has finished using it. Otherwise, | ||
392 | * on 0, it means the callback has finished with it. | ||
393 | * If remove_session_cb is not null, it will be called when | ||
394 | * a session-id is removed from the cache. After the call, | ||
395 | * OpenSSL will SSL_SESSION_free() it. */ | ||
396 | int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess); | ||
397 | void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess); | ||
398 | SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, | ||
399 | unsigned char *data,int len,int *copy); | ||
400 | struct | ||
401 | { | ||
402 | int sess_connect; /* SSL new conn - started */ | ||
403 | int sess_connect_renegotiate;/* SSL reneg - requested */ | ||
404 | int sess_connect_good; /* SSL new conne/reneg - finished */ | ||
405 | int sess_accept; /* SSL new accept - started */ | ||
406 | int sess_accept_renegotiate;/* SSL reneg - requested */ | ||
407 | int sess_accept_good; /* SSL accept/reneg - finished */ | ||
408 | int sess_miss; /* session lookup misses */ | ||
409 | int sess_timeout; /* reuse attempt on timeouted session */ | ||
410 | int sess_cache_full; /* session removed due to full cache */ | ||
411 | int sess_hit; /* session reuse actually done */ | ||
412 | int sess_cb_hit; /* session-id that was not | ||
413 | * in the cache was | ||
414 | * passed back via the callback. This | ||
415 | * indicates that the application is | ||
416 | * supplying session-id's from other | ||
417 | * processes - spooky :-) */ | ||
418 | } stats; | ||
419 | |||
420 | int references; | ||
421 | |||
422 | /**/ void (*info_callback)(); | ||
423 | |||
424 | /* if defined, these override the X509_verify_cert() calls */ | ||
425 | /**/ int (*app_verify_callback)(); | ||
426 | /**/ char *app_verify_arg; /* never used; should be void * */ | ||
427 | |||
428 | /* default values to use in SSL structures */ | ||
429 | /**/ struct cert_st /* CERT */ *cert; | ||
430 | /**/ int read_ahead; | ||
431 | /**/ int verify_mode; | ||
432 | /**/ int verify_depth; | ||
433 | /**/ unsigned int sid_ctx_length; | ||
434 | /**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
435 | /**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); | ||
436 | |||
437 | int purpose; /* Purpose setting */ | ||
438 | int trust; /* Trust setting */ | ||
439 | |||
440 | /* Default password callback. */ | ||
441 | /**/ pem_password_cb *default_passwd_callback; | ||
442 | |||
443 | /* Default password callback user data. */ | ||
444 | /**/ void *default_passwd_callback_userdata; | ||
445 | |||
446 | /* get client cert callback */ | ||
447 | /**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */); | ||
448 | |||
449 | /* what we put in client cert requests */ | ||
450 | STACK_OF(X509_NAME) *client_CA; | ||
451 | |||
452 | /**/ int quiet_shutdown; | ||
453 | |||
454 | CRYPTO_EX_DATA ex_data; | ||
455 | |||
456 | const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */ | ||
457 | const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */ | ||
458 | const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */ | ||
459 | |||
460 | STACK_OF(X509) *extra_certs; | ||
461 | STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */ | ||
462 | }; | ||
463 | |||
464 | #define SSL_SESS_CACHE_OFF 0x0000 | ||
465 | #define SSL_SESS_CACHE_CLIENT 0x0001 | ||
466 | #define SSL_SESS_CACHE_SERVER 0x0002 | ||
467 | #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) | ||
468 | #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 | ||
469 | /* This one, when set, makes the server session-id lookup not look | ||
470 | * in the cache. If there is an application get_session callback | ||
471 | * defined, this will still get called. */ | ||
472 | #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 | ||
473 | |||
474 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx); | ||
475 | #define SSL_CTX_sess_number(ctx) \ | ||
476 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL) | ||
477 | #define SSL_CTX_sess_connect(ctx) \ | ||
478 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL) | ||
479 | #define SSL_CTX_sess_connect_good(ctx) \ | ||
480 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL) | ||
481 | #define SSL_CTX_sess_connect_renegotiate(ctx) \ | ||
482 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL) | ||
483 | #define SSL_CTX_sess_accept(ctx) \ | ||
484 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL) | ||
485 | #define SSL_CTX_sess_accept_renegotiate(ctx) \ | ||
486 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL) | ||
487 | #define SSL_CTX_sess_accept_good(ctx) \ | ||
488 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL) | ||
489 | #define SSL_CTX_sess_hits(ctx) \ | ||
490 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL) | ||
491 | #define SSL_CTX_sess_cb_hits(ctx) \ | ||
492 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL) | ||
493 | #define SSL_CTX_sess_misses(ctx) \ | ||
494 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL) | ||
495 | #define SSL_CTX_sess_timeouts(ctx) \ | ||
496 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL) | ||
497 | #define SSL_CTX_sess_cache_full(ctx) \ | ||
498 | SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL) | ||
499 | |||
500 | #define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb)) | ||
501 | #define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb) | ||
502 | #define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb)) | ||
503 | #define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb) | ||
504 | #define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb)) | ||
505 | #define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb) | ||
506 | #define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb)) | ||
507 | #define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback) | ||
508 | #define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb)) | ||
509 | #define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb) | ||
510 | |||
511 | #define SSL_NOTHING 1 | ||
512 | #define SSL_WRITING 2 | ||
513 | #define SSL_READING 3 | ||
514 | #define SSL_X509_LOOKUP 4 | ||
515 | |||
516 | /* These will only be used when doing non-blocking IO */ | ||
517 | #define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING) | ||
518 | #define SSL_want_read(s) (SSL_want(s) == SSL_READING) | ||
519 | #define SSL_want_write(s) (SSL_want(s) == SSL_WRITING) | ||
520 | #define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP) | ||
521 | |||
522 | struct ssl_st | ||
523 | { | ||
524 | /* protocol version | ||
525 | * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION) | ||
526 | */ | ||
527 | int version; | ||
528 | int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */ | ||
529 | |||
530 | SSL_METHOD *method; /* SSLv3 */ | ||
531 | |||
532 | /* There are 2 BIO's even though they are normally both the | ||
533 | * same. This is so data can be read and written to different | ||
534 | * handlers */ | ||
535 | |||
536 | #ifdef HEADER_BIO_H | ||
537 | BIO *rbio; /* used by SSL_read */ | ||
538 | BIO *wbio; /* used by SSL_write */ | ||
539 | BIO *bbio; /* used during session-id reuse to concatinate | ||
540 | * messages */ | ||
541 | #else | ||
542 | char *rbio; /* used by SSL_read */ | ||
543 | char *wbio; /* used by SSL_write */ | ||
544 | char *bbio; | ||
545 | #endif | ||
546 | /* This holds a variable that indicates what we were doing | ||
547 | * when a 0 or -1 is returned. This is needed for | ||
548 | * non-blocking IO so we know what request needs re-doing when | ||
549 | * in SSL_accept or SSL_connect */ | ||
550 | int rwstate; | ||
551 | |||
552 | /* true when we are actually in SSL_accept() or SSL_connect() */ | ||
553 | int in_handshake; | ||
554 | int (*handshake_func)(); | ||
555 | |||
556 | /* Imagine that here's a boolean member "init" that is | ||
557 | * switched as soon as SSL_set_{accept/connect}_state | ||
558 | * is called for the first time, so that "state" and | ||
559 | * "handshake_func" are properly initialized. But as | ||
560 | * handshake_func is == 0 until then, we use this | ||
561 | * test instead of an "init" member. | ||
562 | */ | ||
563 | |||
564 | int server; /* are we the server side? - mostly used by SSL_clear*/ | ||
565 | |||
566 | int new_session;/* 1 if we are to use a new session */ | ||
567 | int quiet_shutdown;/* don't send shutdown packets */ | ||
568 | int shutdown; /* we have shut things down, 0x01 sent, 0x02 | ||
569 | * for received */ | ||
570 | int state; /* where we are */ | ||
571 | int rstate; /* where we are when reading */ | ||
572 | |||
573 | BUF_MEM *init_buf; /* buffer used during init */ | ||
574 | int init_num; /* amount read/written */ | ||
575 | int init_off; /* amount read/written */ | ||
576 | |||
577 | /* used internally to point at a raw packet */ | ||
578 | unsigned char *packet; | ||
579 | unsigned int packet_length; | ||
580 | |||
581 | struct ssl2_state_st *s2; /* SSLv2 variables */ | ||
582 | struct ssl3_state_st *s3; /* SSLv3 variables */ | ||
583 | |||
584 | int read_ahead; /* Read as many input bytes as possible | ||
585 | * (for non-blocking reads) */ | ||
586 | int hit; /* reusing a previous session */ | ||
587 | |||
588 | int purpose; /* Purpose setting */ | ||
589 | int trust; /* Trust setting */ | ||
590 | |||
591 | /* crypto */ | ||
592 | STACK_OF(SSL_CIPHER) *cipher_list; | ||
593 | STACK_OF(SSL_CIPHER) *cipher_list_by_id; | ||
594 | |||
595 | /* These are the ones being used, the ones in SSL_SESSION are | ||
596 | * the ones to be 'copied' into these ones */ | ||
597 | |||
598 | EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */ | ||
599 | const EVP_MD *read_hash; /* used for mac generation */ | ||
600 | #ifdef HEADER_COMP_H | ||
601 | COMP_CTX *expand; /* uncompress */ | ||
602 | #else | ||
603 | char *expand; | ||
604 | #endif | ||
605 | |||
606 | EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */ | ||
607 | const EVP_MD *write_hash; /* used for mac generation */ | ||
608 | #ifdef HEADER_COMP_H | ||
609 | COMP_CTX *compress; /* compression */ | ||
610 | #else | ||
611 | char *compress; | ||
612 | #endif | ||
613 | |||
614 | /* session info */ | ||
615 | |||
616 | /* client cert? */ | ||
617 | /* This is used to hold the server certificate used */ | ||
618 | struct cert_st /* CERT */ *cert; | ||
619 | |||
620 | /* the session_id_context is used to ensure sessions are only reused | ||
621 | * in the appropriate context */ | ||
622 | unsigned int sid_ctx_length; | ||
623 | unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH]; | ||
624 | |||
625 | /* This can also be in the session once a session is established */ | ||
626 | SSL_SESSION *session; | ||
627 | |||
628 | /* Used in SSL2 and SSL3 */ | ||
629 | int verify_mode; /* 0 don't care about verify failure. | ||
630 | * 1 fail if verify fails */ | ||
631 | int verify_depth; | ||
632 | int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */ | ||
633 | void (*info_callback)(); /* optional informational callback */ | ||
634 | |||
635 | int error; /* error bytes to be written */ | ||
636 | int error_code; /* actual code */ | ||
637 | |||
638 | SSL_CTX *ctx; | ||
639 | /* set this flag to 1 and a sleep(1) is put into all SSL_read() | ||
640 | * and SSL_write() calls, good for nbio debuging :-) */ | ||
641 | int debug; | ||
642 | |||
643 | /* extra application data */ | ||
644 | long verify_result; | ||
645 | CRYPTO_EX_DATA ex_data; | ||
646 | |||
647 | /* for server side, keep the list of CA_dn we can use */ | ||
648 | STACK_OF(X509_NAME) *client_CA; | ||
649 | |||
650 | int references; | ||
651 | unsigned long options; /* protocol behaviour */ | ||
652 | unsigned long mode; /* API behaviour */ | ||
653 | int first_packet; | ||
654 | int client_version; /* what was passed, used for | ||
655 | * SSLv3/TLS rollback check */ | ||
656 | }; | ||
657 | |||
658 | #include <openssl/ssl2.h> | ||
659 | #include <openssl/ssl3.h> | ||
660 | #include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */ | ||
661 | #include <openssl/ssl23.h> | ||
662 | |||
663 | /* compatibility */ | ||
664 | #define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg)) | ||
665 | #define SSL_get_app_data(s) (SSL_get_ex_data(s,0)) | ||
666 | #define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a)) | ||
667 | #define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0)) | ||
668 | #define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0)) | ||
669 | #define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg)) | ||
670 | |||
671 | /* The following are the possible values for ssl->state are are | ||
672 | * used to indicate where we are up to in the SSL connection establishment. | ||
673 | * The macros that follow are about the only things you should need to use | ||
674 | * and even then, only when using non-blocking IO. | ||
675 | * It can also be useful to work out where you were when the connection | ||
676 | * failed */ | ||
677 | |||
678 | #define SSL_ST_CONNECT 0x1000 | ||
679 | #define SSL_ST_ACCEPT 0x2000 | ||
680 | #define SSL_ST_MASK 0x0FFF | ||
681 | #define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT) | ||
682 | #define SSL_ST_BEFORE 0x4000 | ||
683 | #define SSL_ST_OK 0x03 | ||
684 | #define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT) | ||
685 | |||
686 | #define SSL_CB_LOOP 0x01 | ||
687 | #define SSL_CB_EXIT 0x02 | ||
688 | #define SSL_CB_READ 0x04 | ||
689 | #define SSL_CB_WRITE 0x08 | ||
690 | #define SSL_CB_ALERT 0x4000 /* used in callback */ | ||
691 | #define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ) | ||
692 | #define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE) | ||
693 | #define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP) | ||
694 | #define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT) | ||
695 | #define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP) | ||
696 | #define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT) | ||
697 | #define SSL_CB_HANDSHAKE_START 0x10 | ||
698 | #define SSL_CB_HANDSHAKE_DONE 0x20 | ||
699 | |||
700 | /* Is the SSL_connection established? */ | ||
701 | #define SSL_get_state(a) SSL_state(a) | ||
702 | #define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK) | ||
703 | #define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT) | ||
704 | #define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE) | ||
705 | #define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT) | ||
706 | #define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT) | ||
707 | |||
708 | /* The following 2 states are kept in ssl->rstate when reads fail, | ||
709 | * you should not need these */ | ||
710 | #define SSL_ST_READ_HEADER 0xF0 | ||
711 | #define SSL_ST_READ_BODY 0xF1 | ||
712 | #define SSL_ST_READ_DONE 0xF2 | ||
713 | |||
714 | /* Obtain latest Finished message | ||
715 | * -- that we sent (SSL_get_finished) | ||
716 | * -- that we expected from peer (SSL_get_peer_finished). | ||
717 | * Returns length (0 == no Finished so far), copies up to 'count' bytes. */ | ||
718 | size_t SSL_get_finished(SSL *s, void *buf, size_t count); | ||
719 | size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count); | ||
720 | |||
721 | /* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options | ||
722 | * are 'ored' with SSL_VERIFY_PEER if they are desired */ | ||
723 | #define SSL_VERIFY_NONE 0x00 | ||
724 | #define SSL_VERIFY_PEER 0x01 | ||
725 | #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02 | ||
726 | #define SSL_VERIFY_CLIENT_ONCE 0x04 | ||
727 | |||
728 | #define OpenSSL_add_ssl_algorithms() SSL_library_init() | ||
729 | #define SSLeay_add_ssl_algorithms() SSL_library_init() | ||
730 | |||
731 | /* this is for backward compatibility */ | ||
732 | #if 0 /* NEW_SSLEAY */ | ||
733 | #define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c) | ||
734 | #define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n) | ||
735 | #define SSL_add_session(a,b) SSL_CTX_add_session((a),(b)) | ||
736 | #define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b)) | ||
737 | #define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b)) | ||
738 | #endif | ||
739 | /* More backward compatibility */ | ||
740 | #define SSL_get_cipher(s) \ | ||
741 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
742 | #define SSL_get_cipher_bits(s,np) \ | ||
743 | SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np) | ||
744 | #define SSL_get_cipher_version(s) \ | ||
745 | SSL_CIPHER_get_version(SSL_get_current_cipher(s)) | ||
746 | #define SSL_get_cipher_name(s) \ | ||
747 | SSL_CIPHER_get_name(SSL_get_current_cipher(s)) | ||
748 | #define SSL_get_time(a) SSL_SESSION_get_time(a) | ||
749 | #define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b)) | ||
750 | #define SSL_get_timeout(a) SSL_SESSION_get_timeout(a) | ||
751 | #define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b)) | ||
752 | |||
753 | #if 1 /*SSLEAY_MACROS*/ | ||
754 | #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \ | ||
755 | (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \ | ||
756 | (bp),(unsigned char **)(s_id)) | ||
757 | #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \ | ||
758 | bp,(unsigned char *)s_id) | ||
759 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ | ||
760 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) | ||
761 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ | ||
762 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) | ||
763 | #define PEM_write_SSL_SESSION(fp,x) \ | ||
764 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | ||
765 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
766 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | ||
767 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | ||
768 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) | ||
769 | #endif | ||
770 | |||
771 | #define SSL_AD_REASON_OFFSET 1000 | ||
772 | /* These alert types are for SSLv3 and TLSv1 */ | ||
773 | #define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY | ||
774 | #define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */ | ||
775 | #define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */ | ||
776 | #define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED | ||
777 | #define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW | ||
778 | #define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */ | ||
779 | #define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */ | ||
780 | #define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */ | ||
781 | #define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE | ||
782 | #define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE | ||
783 | #define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED | ||
784 | #define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED | ||
785 | #define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN | ||
786 | #define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */ | ||
787 | #define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */ | ||
788 | #define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */ | ||
789 | #define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */ | ||
790 | #define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR | ||
791 | #define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */ | ||
792 | #define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */ | ||
793 | #define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */ | ||
794 | #define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */ | ||
795 | #define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED | ||
796 | #define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION | ||
797 | |||
798 | #define SSL_ERROR_NONE 0 | ||
799 | #define SSL_ERROR_SSL 1 | ||
800 | #define SSL_ERROR_WANT_READ 2 | ||
801 | #define SSL_ERROR_WANT_WRITE 3 | ||
802 | #define SSL_ERROR_WANT_X509_LOOKUP 4 | ||
803 | #define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */ | ||
804 | #define SSL_ERROR_ZERO_RETURN 6 | ||
805 | #define SSL_ERROR_WANT_CONNECT 7 | ||
806 | |||
807 | #define SSL_CTRL_NEED_TMP_RSA 1 | ||
808 | #define SSL_CTRL_SET_TMP_RSA 2 | ||
809 | #define SSL_CTRL_SET_TMP_DH 3 | ||
810 | #define SSL_CTRL_SET_TMP_RSA_CB 4 | ||
811 | #define SSL_CTRL_SET_TMP_DH_CB 5 | ||
812 | /* Add these ones */ | ||
813 | #define SSL_CTRL_GET_SESSION_REUSED 6 | ||
814 | #define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7 | ||
815 | #define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8 | ||
816 | #define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9 | ||
817 | #define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10 | ||
818 | #define SSL_CTRL_GET_FLAGS 11 | ||
819 | #define SSL_CTRL_EXTRA_CHAIN_CERT 12 | ||
820 | |||
821 | /* Stats */ | ||
822 | #define SSL_CTRL_SESS_NUMBER 20 | ||
823 | #define SSL_CTRL_SESS_CONNECT 21 | ||
824 | #define SSL_CTRL_SESS_CONNECT_GOOD 22 | ||
825 | #define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23 | ||
826 | #define SSL_CTRL_SESS_ACCEPT 24 | ||
827 | #define SSL_CTRL_SESS_ACCEPT_GOOD 25 | ||
828 | #define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26 | ||
829 | #define SSL_CTRL_SESS_HIT 27 | ||
830 | #define SSL_CTRL_SESS_CB_HIT 28 | ||
831 | #define SSL_CTRL_SESS_MISSES 29 | ||
832 | #define SSL_CTRL_SESS_TIMEOUTS 30 | ||
833 | #define SSL_CTRL_SESS_CACHE_FULL 31 | ||
834 | #define SSL_CTRL_OPTIONS 32 | ||
835 | #define SSL_CTRL_MODE 33 | ||
836 | |||
837 | #define SSL_CTRL_GET_READ_AHEAD 40 | ||
838 | #define SSL_CTRL_SET_READ_AHEAD 41 | ||
839 | #define SSL_CTRL_SET_SESS_CACHE_SIZE 42 | ||
840 | #define SSL_CTRL_GET_SESS_CACHE_SIZE 43 | ||
841 | #define SSL_CTRL_SET_SESS_CACHE_MODE 44 | ||
842 | #define SSL_CTRL_GET_SESS_CACHE_MODE 45 | ||
843 | |||
844 | #define SSL_session_reused(ssl) \ | ||
845 | SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL) | ||
846 | #define SSL_num_renegotiations(ssl) \ | ||
847 | SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL) | ||
848 | #define SSL_clear_num_renegotiations(ssl) \ | ||
849 | SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL) | ||
850 | #define SSL_total_renegotiations(ssl) \ | ||
851 | SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL) | ||
852 | |||
853 | #define SSL_CTX_need_tmp_RSA(ctx) \ | ||
854 | SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL) | ||
855 | #define SSL_CTX_set_tmp_rsa(ctx,rsa) \ | ||
856 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | ||
857 | #define SSL_CTX_set_tmp_dh(ctx,dh) \ | ||
858 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | ||
859 | |||
860 | #define SSL_need_tmp_RSA(ssl) \ | ||
861 | SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL) | ||
862 | #define SSL_set_tmp_rsa(ssl,rsa) \ | ||
863 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa) | ||
864 | #define SSL_set_tmp_dh(ssl,dh) \ | ||
865 | SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh) | ||
866 | |||
867 | #define SSL_CTX_add_extra_chain_cert(ctx,x509) \ | ||
868 | SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) | ||
869 | |||
870 | /* VMS uses only 31 characters for symbols. */ | ||
871 | #ifdef VMS | ||
872 | #undef SSL_CTX_set_cert_verify_callback | ||
873 | #define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb | ||
874 | #undef SSL_CTX_use_certificate_chain_file | ||
875 | #define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file | ||
876 | #undef SSL_CTX_set_default_verify_paths | ||
877 | #define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths | ||
878 | #undef SSL_get_ex_data_X509_STORE_CTX_idx | ||
879 | #define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i | ||
880 | #undef SSL_add_file_cert_subjects_to_stack | ||
881 | #define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack | ||
882 | #undef SSL_add_dir_cert_subjects_to_stack | ||
883 | #define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack | ||
884 | #endif | ||
885 | |||
886 | #ifdef HEADER_BIO_H | ||
887 | BIO_METHOD *BIO_f_ssl(void); | ||
888 | BIO *BIO_new_ssl(SSL_CTX *ctx,int client); | ||
889 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx); | ||
890 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx); | ||
891 | int BIO_ssl_copy_session_id(BIO *to,BIO *from); | ||
892 | void BIO_ssl_shutdown(BIO *ssl_bio); | ||
893 | |||
894 | #endif | ||
895 | |||
896 | int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str); | ||
897 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth); | ||
898 | void SSL_CTX_free(SSL_CTX *); | ||
899 | long SSL_CTX_set_timeout(SSL_CTX *ctx,long t); | ||
900 | long SSL_CTX_get_timeout(SSL_CTX *ctx); | ||
901 | X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *); | ||
902 | void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *); | ||
903 | int SSL_want(SSL *s); | ||
904 | int SSL_clear(SSL *s); | ||
905 | |||
906 | void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm); | ||
907 | |||
908 | SSL_CIPHER *SSL_get_current_cipher(SSL *s); | ||
909 | int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits); | ||
910 | char * SSL_CIPHER_get_version(SSL_CIPHER *c); | ||
911 | const char * SSL_CIPHER_get_name(SSL_CIPHER *c); | ||
912 | |||
913 | int SSL_get_fd(SSL *s); | ||
914 | const char * SSL_get_cipher_list(SSL *s,int n); | ||
915 | char * SSL_get_shared_ciphers(SSL *s, char *buf, int len); | ||
916 | int SSL_get_read_ahead(SSL * s); | ||
917 | int SSL_pending(SSL *s); | ||
918 | #ifndef NO_SOCK | ||
919 | int SSL_set_fd(SSL *s, int fd); | ||
920 | int SSL_set_rfd(SSL *s, int fd); | ||
921 | int SSL_set_wfd(SSL *s, int fd); | ||
922 | #endif | ||
923 | #ifdef HEADER_BIO_H | ||
924 | void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio); | ||
925 | BIO * SSL_get_rbio(SSL *s); | ||
926 | BIO * SSL_get_wbio(SSL *s); | ||
927 | #endif | ||
928 | int SSL_set_cipher_list(SSL *s, const char *str); | ||
929 | void SSL_set_read_ahead(SSL *s, int yes); | ||
930 | int SSL_get_verify_mode(SSL *s); | ||
931 | int SSL_get_verify_depth(SSL *s); | ||
932 | int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *); | ||
933 | void SSL_set_verify(SSL *s, int mode, | ||
934 | int (*callback)(int ok,X509_STORE_CTX *ctx)); | ||
935 | void SSL_set_verify_depth(SSL *s, int depth); | ||
936 | #ifndef NO_RSA | ||
937 | int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa); | ||
938 | #endif | ||
939 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len); | ||
940 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey); | ||
941 | int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len); | ||
942 | int SSL_use_certificate(SSL *ssl, X509 *x); | ||
943 | int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len); | ||
944 | |||
945 | #ifndef NO_STDIO | ||
946 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); | ||
947 | int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); | ||
948 | int SSL_use_certificate_file(SSL *ssl, const char *file, int type); | ||
949 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); | ||
950 | int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); | ||
951 | int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); | ||
952 | int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */ | ||
953 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); | ||
954 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | ||
955 | const char *file); | ||
956 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | ||
957 | const char *dir); | ||
958 | #endif | ||
959 | |||
960 | void ERR_load_SSL_strings(void ); | ||
961 | void SSL_load_error_strings(void ); | ||
962 | char * SSL_state_string(SSL *s); | ||
963 | char * SSL_rstate_string(SSL *s); | ||
964 | char * SSL_state_string_long(SSL *s); | ||
965 | char * SSL_rstate_string_long(SSL *s); | ||
966 | long SSL_SESSION_get_time(SSL_SESSION *s); | ||
967 | long SSL_SESSION_set_time(SSL_SESSION *s, long t); | ||
968 | long SSL_SESSION_get_timeout(SSL_SESSION *s); | ||
969 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t); | ||
970 | void SSL_copy_session_id(SSL *to,SSL *from); | ||
971 | |||
972 | SSL_SESSION *SSL_SESSION_new(void); | ||
973 | unsigned long SSL_SESSION_hash(SSL_SESSION *a); | ||
974 | int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b); | ||
975 | #ifndef NO_FP_API | ||
976 | int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses); | ||
977 | #endif | ||
978 | #ifdef HEADER_BIO_H | ||
979 | int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses); | ||
980 | #endif | ||
981 | void SSL_SESSION_free(SSL_SESSION *ses); | ||
982 | int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp); | ||
983 | int SSL_set_session(SSL *to, SSL_SESSION *session); | ||
984 | int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c); | ||
985 | int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c); | ||
986 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length); | ||
987 | |||
988 | #ifdef HEADER_X509_H | ||
989 | X509 * SSL_get_peer_certificate(SSL *s); | ||
990 | #endif | ||
991 | |||
992 | STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s); | ||
993 | |||
994 | #ifdef VMS | ||
995 | #define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud | ||
996 | #endif | ||
997 | |||
998 | int SSL_CTX_get_verify_mode(SSL_CTX *ctx); | ||
999 | int SSL_CTX_get_verify_depth(SSL_CTX *ctx); | ||
1000 | int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *); | ||
1001 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode, | ||
1002 | int (*callback)(int, X509_STORE_CTX *)); | ||
1003 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth); | ||
1004 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg); | ||
1005 | #ifndef NO_RSA | ||
1006 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa); | ||
1007 | #endif | ||
1008 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len); | ||
1009 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey); | ||
1010 | int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx, | ||
1011 | unsigned char *d, long len); | ||
1012 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x); | ||
1013 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d); | ||
1014 | |||
1015 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb); | ||
1016 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u); | ||
1017 | |||
1018 | int SSL_CTX_check_private_key(SSL_CTX *ctx); | ||
1019 | int SSL_check_private_key(SSL *ctx); | ||
1020 | |||
1021 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, | ||
1022 | unsigned int sid_ctx_len); | ||
1023 | |||
1024 | SSL * SSL_new(SSL_CTX *ctx); | ||
1025 | int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, | ||
1026 | unsigned int sid_ctx_len); | ||
1027 | |||
1028 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose); | ||
1029 | int SSL_set_purpose(SSL *s, int purpose); | ||
1030 | int SSL_CTX_set_trust(SSL_CTX *s, int trust); | ||
1031 | int SSL_set_trust(SSL *s, int trust); | ||
1032 | |||
1033 | void SSL_free(SSL *ssl); | ||
1034 | int SSL_accept(SSL *ssl); | ||
1035 | int SSL_connect(SSL *ssl); | ||
1036 | int SSL_read(SSL *ssl,char *buf,int num); | ||
1037 | int SSL_peek(SSL *ssl,char *buf,int num); | ||
1038 | int SSL_write(SSL *ssl,const char *buf,int num); | ||
1039 | long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg); | ||
1040 | long SSL_callback_ctrl(SSL *, int, void (*)()); | ||
1041 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg); | ||
1042 | long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)()); | ||
1043 | |||
1044 | int SSL_get_error(SSL *s,int ret_code); | ||
1045 | const char *SSL_get_version(SSL *s); | ||
1046 | |||
1047 | /* This sets the 'default' SSL version that SSL_new() will create */ | ||
1048 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth); | ||
1049 | |||
1050 | SSL_METHOD *SSLv2_method(void); /* SSLv2 */ | ||
1051 | SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */ | ||
1052 | SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */ | ||
1053 | |||
1054 | SSL_METHOD *SSLv3_method(void); /* SSLv3 */ | ||
1055 | SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */ | ||
1056 | SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */ | ||
1057 | |||
1058 | SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */ | ||
1059 | SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */ | ||
1060 | SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */ | ||
1061 | |||
1062 | SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */ | ||
1063 | SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */ | ||
1064 | SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */ | ||
1065 | |||
1066 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s); | ||
1067 | |||
1068 | int SSL_do_handshake(SSL *s); | ||
1069 | int SSL_renegotiate(SSL *s); | ||
1070 | int SSL_shutdown(SSL *s); | ||
1071 | |||
1072 | SSL_METHOD *SSL_get_ssl_method(SSL *s); | ||
1073 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *method); | ||
1074 | char *SSL_alert_type_string_long(int value); | ||
1075 | char *SSL_alert_type_string(int value); | ||
1076 | char *SSL_alert_desc_string_long(int value); | ||
1077 | char *SSL_alert_desc_string(int value); | ||
1078 | |||
1079 | void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list); | ||
1080 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list); | ||
1081 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s); | ||
1082 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s); | ||
1083 | int SSL_add_client_CA(SSL *ssl,X509 *x); | ||
1084 | int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x); | ||
1085 | |||
1086 | void SSL_set_connect_state(SSL *s); | ||
1087 | void SSL_set_accept_state(SSL *s); | ||
1088 | |||
1089 | long SSL_get_default_timeout(SSL *s); | ||
1090 | |||
1091 | int SSL_library_init(void ); | ||
1092 | |||
1093 | char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size); | ||
1094 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk); | ||
1095 | |||
1096 | SSL *SSL_dup(SSL *ssl); | ||
1097 | |||
1098 | X509 *SSL_get_certificate(SSL *ssl); | ||
1099 | /* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl); | ||
1100 | |||
1101 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode); | ||
1102 | int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx); | ||
1103 | void SSL_set_quiet_shutdown(SSL *ssl,int mode); | ||
1104 | int SSL_get_quiet_shutdown(SSL *ssl); | ||
1105 | void SSL_set_shutdown(SSL *ssl,int mode); | ||
1106 | int SSL_get_shutdown(SSL *ssl); | ||
1107 | int SSL_version(SSL *ssl); | ||
1108 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx); | ||
1109 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | ||
1110 | const char *CApath); | ||
1111 | #define SSL_get0_session SSL_get_session /* just peek at pointer */ | ||
1112 | SSL_SESSION *SSL_get_session(SSL *ssl); | ||
1113 | SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */ | ||
1114 | SSL_CTX *SSL_get_SSL_CTX(SSL *ssl); | ||
1115 | void SSL_set_info_callback(SSL *ssl,void (*cb)()); | ||
1116 | void (*SSL_get_info_callback(SSL *ssl))(); | ||
1117 | int SSL_state(SSL *ssl); | ||
1118 | |||
1119 | void SSL_set_verify_result(SSL *ssl,long v); | ||
1120 | long SSL_get_verify_result(SSL *ssl); | ||
1121 | |||
1122 | int SSL_set_ex_data(SSL *ssl,int idx,void *data); | ||
1123 | void *SSL_get_ex_data(SSL *ssl,int idx); | ||
1124 | int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1125 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1126 | |||
1127 | int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data); | ||
1128 | void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx); | ||
1129 | int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1130 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1131 | |||
1132 | int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data); | ||
1133 | void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx); | ||
1134 | int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
1135 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
1136 | |||
1137 | int SSL_get_ex_data_X509_STORE_CTX_idx(void ); | ||
1138 | |||
1139 | #define SSL_CTX_sess_set_cache_size(ctx,t) \ | ||
1140 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL) | ||
1141 | #define SSL_CTX_sess_get_cache_size(ctx) \ | ||
1142 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL) | ||
1143 | #define SSL_CTX_set_session_cache_mode(ctx,m) \ | ||
1144 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL) | ||
1145 | #define SSL_CTX_get_session_cache_mode(ctx) \ | ||
1146 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL) | ||
1147 | |||
1148 | #define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx) | ||
1149 | #define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m) | ||
1150 | #define SSL_CTX_get_read_ahead(ctx) \ | ||
1151 | SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL) | ||
1152 | #define SSL_CTX_set_read_ahead(ctx,m) \ | ||
1153 | SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,0,NULL) | ||
1154 | |||
1155 | /* NB: the keylength is only applicable when is_export is true */ | ||
1156 | #ifndef NO_RSA | ||
1157 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, | ||
1158 | RSA *(*cb)(SSL *ssl,int is_export, | ||
1159 | int keylength)); | ||
1160 | |||
1161 | void SSL_set_tmp_rsa_callback(SSL *ssl, | ||
1162 | RSA *(*cb)(SSL *ssl,int is_export, | ||
1163 | int keylength)); | ||
1164 | #endif | ||
1165 | #ifndef NO_DH | ||
1166 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, | ||
1167 | DH *(*dh)(SSL *ssl,int is_export, | ||
1168 | int keylength)); | ||
1169 | void SSL_set_tmp_dh_callback(SSL *ssl, | ||
1170 | DH *(*dh)(SSL *ssl,int is_export, | ||
1171 | int keylength)); | ||
1172 | #endif | ||
1173 | |||
1174 | #ifdef HEADER_COMP_H | ||
1175 | int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm); | ||
1176 | #else | ||
1177 | int SSL_COMP_add_compression_method(int id,char *cm); | ||
1178 | #endif | ||
1179 | |||
1180 | /* BEGIN ERROR CODES */ | ||
1181 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
1182 | * made after this point may be overwritten when the script is next run. | ||
1183 | */ | ||
1184 | |||
1185 | /* Error codes for the SSL functions. */ | ||
1186 | |||
1187 | /* Function codes. */ | ||
1188 | #define SSL_F_CLIENT_CERTIFICATE 100 | ||
1189 | #define SSL_F_CLIENT_HELLO 101 | ||
1190 | #define SSL_F_CLIENT_MASTER_KEY 102 | ||
1191 | #define SSL_F_D2I_SSL_SESSION 103 | ||
1192 | #define SSL_F_DO_SSL3_WRITE 104 | ||
1193 | #define SSL_F_GET_CLIENT_FINISHED 105 | ||
1194 | #define SSL_F_GET_CLIENT_HELLO 106 | ||
1195 | #define SSL_F_GET_CLIENT_MASTER_KEY 107 | ||
1196 | #define SSL_F_GET_SERVER_FINISHED 108 | ||
1197 | #define SSL_F_GET_SERVER_HELLO 109 | ||
1198 | #define SSL_F_GET_SERVER_VERIFY 110 | ||
1199 | #define SSL_F_I2D_SSL_SESSION 111 | ||
1200 | #define SSL_F_READ_N 112 | ||
1201 | #define SSL_F_REQUEST_CERTIFICATE 113 | ||
1202 | #define SSL_F_SERVER_HELLO 114 | ||
1203 | #define SSL_F_SSL23_ACCEPT 115 | ||
1204 | #define SSL_F_SSL23_CLIENT_HELLO 116 | ||
1205 | #define SSL_F_SSL23_CONNECT 117 | ||
1206 | #define SSL_F_SSL23_GET_CLIENT_HELLO 118 | ||
1207 | #define SSL_F_SSL23_GET_SERVER_HELLO 119 | ||
1208 | #define SSL_F_SSL23_READ 120 | ||
1209 | #define SSL_F_SSL23_WRITE 121 | ||
1210 | #define SSL_F_SSL2_ACCEPT 122 | ||
1211 | #define SSL_F_SSL2_CONNECT 123 | ||
1212 | #define SSL_F_SSL2_ENC_INIT 124 | ||
1213 | #define SSL_F_SSL2_READ 125 | ||
1214 | #define SSL_F_SSL2_SET_CERTIFICATE 126 | ||
1215 | #define SSL_F_SSL2_WRITE 127 | ||
1216 | #define SSL_F_SSL3_ACCEPT 128 | ||
1217 | #define SSL_F_SSL3_CALLBACK_CTRL 233 | ||
1218 | #define SSL_F_SSL3_CHANGE_CIPHER_STATE 129 | ||
1219 | #define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130 | ||
1220 | #define SSL_F_SSL3_CLIENT_HELLO 131 | ||
1221 | #define SSL_F_SSL3_CONNECT 132 | ||
1222 | #define SSL_F_SSL3_CTRL 213 | ||
1223 | #define SSL_F_SSL3_CTX_CTRL 133 | ||
1224 | #define SSL_F_SSL3_ENC 134 | ||
1225 | #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135 | ||
1226 | #define SSL_F_SSL3_GET_CERT_VERIFY 136 | ||
1227 | #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137 | ||
1228 | #define SSL_F_SSL3_GET_CLIENT_HELLO 138 | ||
1229 | #define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139 | ||
1230 | #define SSL_F_SSL3_GET_FINISHED 140 | ||
1231 | #define SSL_F_SSL3_GET_KEY_EXCHANGE 141 | ||
1232 | #define SSL_F_SSL3_GET_MESSAGE 142 | ||
1233 | #define SSL_F_SSL3_GET_RECORD 143 | ||
1234 | #define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144 | ||
1235 | #define SSL_F_SSL3_GET_SERVER_DONE 145 | ||
1236 | #define SSL_F_SSL3_GET_SERVER_HELLO 146 | ||
1237 | #define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147 | ||
1238 | #define SSL_F_SSL3_READ_BYTES 148 | ||
1239 | #define SSL_F_SSL3_READ_N 149 | ||
1240 | #define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150 | ||
1241 | #define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151 | ||
1242 | #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152 | ||
1243 | #define SSL_F_SSL3_SEND_CLIENT_VERIFY 153 | ||
1244 | #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154 | ||
1245 | #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155 | ||
1246 | #define SSL_F_SSL3_SETUP_BUFFERS 156 | ||
1247 | #define SSL_F_SSL3_SETUP_KEY_BLOCK 157 | ||
1248 | #define SSL_F_SSL3_WRITE_BYTES 158 | ||
1249 | #define SSL_F_SSL3_WRITE_PENDING 159 | ||
1250 | #define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215 | ||
1251 | #define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216 | ||
1252 | #define SSL_F_SSL_BAD_METHOD 160 | ||
1253 | #define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161 | ||
1254 | #define SSL_F_SSL_CERT_DUP 221 | ||
1255 | #define SSL_F_SSL_CERT_INST 222 | ||
1256 | #define SSL_F_SSL_CERT_INSTANTIATE 214 | ||
1257 | #define SSL_F_SSL_CERT_NEW 162 | ||
1258 | #define SSL_F_SSL_CHECK_PRIVATE_KEY 163 | ||
1259 | #define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230 | ||
1260 | #define SSL_F_SSL_CIPHER_STRENGTH_SORT 231 | ||
1261 | #define SSL_F_SSL_CLEAR 164 | ||
1262 | #define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165 | ||
1263 | #define SSL_F_SSL_CREATE_CIPHER_LIST 166 | ||
1264 | #define SSL_F_SSL_CTRL 232 | ||
1265 | #define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168 | ||
1266 | #define SSL_F_SSL_CTX_NEW 169 | ||
1267 | #define SSL_F_SSL_CTX_SET_PURPOSE 226 | ||
1268 | #define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219 | ||
1269 | #define SSL_F_SSL_CTX_SET_SSL_VERSION 170 | ||
1270 | #define SSL_F_SSL_CTX_SET_TRUST 229 | ||
1271 | #define SSL_F_SSL_CTX_USE_CERTIFICATE 171 | ||
1272 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172 | ||
1273 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220 | ||
1274 | #define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173 | ||
1275 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY 174 | ||
1276 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175 | ||
1277 | #define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176 | ||
1278 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177 | ||
1279 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178 | ||
1280 | #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179 | ||
1281 | #define SSL_F_SSL_DO_HANDSHAKE 180 | ||
1282 | #define SSL_F_SSL_GET_NEW_SESSION 181 | ||
1283 | #define SSL_F_SSL_GET_PREV_SESSION 217 | ||
1284 | #define SSL_F_SSL_GET_SERVER_SEND_CERT 182 | ||
1285 | #define SSL_F_SSL_GET_SIGN_PKEY 183 | ||
1286 | #define SSL_F_SSL_INIT_WBIO_BUFFER 184 | ||
1287 | #define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185 | ||
1288 | #define SSL_F_SSL_NEW 186 | ||
1289 | #define SSL_F_SSL_READ 223 | ||
1290 | #define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187 | ||
1291 | #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188 | ||
1292 | #define SSL_F_SSL_SESSION_NEW 189 | ||
1293 | #define SSL_F_SSL_SESSION_PRINT_FP 190 | ||
1294 | #define SSL_F_SSL_SESS_CERT_NEW 225 | ||
1295 | #define SSL_F_SSL_SET_CERT 191 | ||
1296 | #define SSL_F_SSL_SET_FD 192 | ||
1297 | #define SSL_F_SSL_SET_PKEY 193 | ||
1298 | #define SSL_F_SSL_SET_PURPOSE 227 | ||
1299 | #define SSL_F_SSL_SET_RFD 194 | ||
1300 | #define SSL_F_SSL_SET_SESSION 195 | ||
1301 | #define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218 | ||
1302 | #define SSL_F_SSL_SET_TRUST 228 | ||
1303 | #define SSL_F_SSL_SET_WFD 196 | ||
1304 | #define SSL_F_SSL_SHUTDOWN 224 | ||
1305 | #define SSL_F_SSL_UNDEFINED_FUNCTION 197 | ||
1306 | #define SSL_F_SSL_USE_CERTIFICATE 198 | ||
1307 | #define SSL_F_SSL_USE_CERTIFICATE_ASN1 199 | ||
1308 | #define SSL_F_SSL_USE_CERTIFICATE_FILE 200 | ||
1309 | #define SSL_F_SSL_USE_PRIVATEKEY 201 | ||
1310 | #define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202 | ||
1311 | #define SSL_F_SSL_USE_PRIVATEKEY_FILE 203 | ||
1312 | #define SSL_F_SSL_USE_RSAPRIVATEKEY 204 | ||
1313 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205 | ||
1314 | #define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206 | ||
1315 | #define SSL_F_SSL_VERIFY_CERT_CHAIN 207 | ||
1316 | #define SSL_F_SSL_WRITE 208 | ||
1317 | #define SSL_F_TLS1_CHANGE_CIPHER_STATE 209 | ||
1318 | #define SSL_F_TLS1_ENC 210 | ||
1319 | #define SSL_F_TLS1_SETUP_KEY_BLOCK 211 | ||
1320 | #define SSL_F_WRITE_PENDING 212 | ||
1321 | |||
1322 | /* Reason codes. */ | ||
1323 | #define SSL_R_APP_DATA_IN_HANDSHAKE 100 | ||
1324 | #define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272 | ||
1325 | #define SSL_R_BAD_ALERT_RECORD 101 | ||
1326 | #define SSL_R_BAD_AUTHENTICATION_TYPE 102 | ||
1327 | #define SSL_R_BAD_CHANGE_CIPHER_SPEC 103 | ||
1328 | #define SSL_R_BAD_CHECKSUM 104 | ||
1329 | #define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106 | ||
1330 | #define SSL_R_BAD_DECOMPRESSION 107 | ||
1331 | #define SSL_R_BAD_DH_G_LENGTH 108 | ||
1332 | #define SSL_R_BAD_DH_PUB_KEY_LENGTH 109 | ||
1333 | #define SSL_R_BAD_DH_P_LENGTH 110 | ||
1334 | #define SSL_R_BAD_DIGEST_LENGTH 111 | ||
1335 | #define SSL_R_BAD_DSA_SIGNATURE 112 | ||
1336 | #define SSL_R_BAD_HELLO_REQUEST 105 | ||
1337 | #define SSL_R_BAD_LENGTH 271 | ||
1338 | #define SSL_R_BAD_MAC_DECODE 113 | ||
1339 | #define SSL_R_BAD_MESSAGE_TYPE 114 | ||
1340 | #define SSL_R_BAD_PACKET_LENGTH 115 | ||
1341 | #define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116 | ||
1342 | #define SSL_R_BAD_RESPONSE_ARGUMENT 117 | ||
1343 | #define SSL_R_BAD_RSA_DECRYPT 118 | ||
1344 | #define SSL_R_BAD_RSA_ENCRYPT 119 | ||
1345 | #define SSL_R_BAD_RSA_E_LENGTH 120 | ||
1346 | #define SSL_R_BAD_RSA_MODULUS_LENGTH 121 | ||
1347 | #define SSL_R_BAD_RSA_SIGNATURE 122 | ||
1348 | #define SSL_R_BAD_SIGNATURE 123 | ||
1349 | #define SSL_R_BAD_SSL_FILETYPE 124 | ||
1350 | #define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125 | ||
1351 | #define SSL_R_BAD_STATE 126 | ||
1352 | #define SSL_R_BAD_WRITE_RETRY 127 | ||
1353 | #define SSL_R_BIO_NOT_SET 128 | ||
1354 | #define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129 | ||
1355 | #define SSL_R_BN_LIB 130 | ||
1356 | #define SSL_R_CA_DN_LENGTH_MISMATCH 131 | ||
1357 | #define SSL_R_CA_DN_TOO_LONG 132 | ||
1358 | #define SSL_R_CCS_RECEIVED_EARLY 133 | ||
1359 | #define SSL_R_CERTIFICATE_VERIFY_FAILED 134 | ||
1360 | #define SSL_R_CERT_LENGTH_MISMATCH 135 | ||
1361 | #define SSL_R_CHALLENGE_IS_DIFFERENT 136 | ||
1362 | #define SSL_R_CIPHER_CODE_WRONG_LENGTH 137 | ||
1363 | #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138 | ||
1364 | #define SSL_R_CIPHER_TABLE_SRC_ERROR 139 | ||
1365 | #define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140 | ||
1366 | #define SSL_R_COMPRESSION_FAILURE 141 | ||
1367 | #define SSL_R_COMPRESSION_LIBRARY_ERROR 142 | ||
1368 | #define SSL_R_CONNECTION_ID_IS_DIFFERENT 143 | ||
1369 | #define SSL_R_CONNECTION_TYPE_NOT_SET 144 | ||
1370 | #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145 | ||
1371 | #define SSL_R_DATA_LENGTH_TOO_LONG 146 | ||
1372 | #define SSL_R_DECRYPTION_FAILED 147 | ||
1373 | #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148 | ||
1374 | #define SSL_R_DIGEST_CHECK_FAILED 149 | ||
1375 | #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150 | ||
1376 | #define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 1092 | ||
1377 | #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151 | ||
1378 | #define SSL_R_EXCESSIVE_MESSAGE_SIZE 152 | ||
1379 | #define SSL_R_EXTRA_DATA_IN_MESSAGE 153 | ||
1380 | #define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154 | ||
1381 | #define SSL_R_HTTPS_PROXY_REQUEST 155 | ||
1382 | #define SSL_R_HTTP_REQUEST 156 | ||
1383 | #define SSL_R_INTERNAL_ERROR 157 | ||
1384 | #define SSL_R_INVALID_CHALLENGE_LENGTH 158 | ||
1385 | #define SSL_R_INVALID_COMMAND 280 | ||
1386 | #define SSL_R_INVALID_PURPOSE 278 | ||
1387 | #define SSL_R_INVALID_TRUST 279 | ||
1388 | #define SSL_R_LENGTH_MISMATCH 159 | ||
1389 | #define SSL_R_LENGTH_TOO_SHORT 160 | ||
1390 | #define SSL_R_LIBRARY_BUG 274 | ||
1391 | #define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 | ||
1392 | #define SSL_R_MISSING_DH_DSA_CERT 162 | ||
1393 | #define SSL_R_MISSING_DH_KEY 163 | ||
1394 | #define SSL_R_MISSING_DH_RSA_CERT 164 | ||
1395 | #define SSL_R_MISSING_DSA_SIGNING_CERT 165 | ||
1396 | #define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166 | ||
1397 | #define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167 | ||
1398 | #define SSL_R_MISSING_RSA_CERTIFICATE 168 | ||
1399 | #define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169 | ||
1400 | #define SSL_R_MISSING_RSA_SIGNING_CERT 170 | ||
1401 | #define SSL_R_MISSING_TMP_DH_KEY 171 | ||
1402 | #define SSL_R_MISSING_TMP_RSA_KEY 172 | ||
1403 | #define SSL_R_MISSING_TMP_RSA_PKEY 173 | ||
1404 | #define SSL_R_MISSING_VERIFY_MESSAGE 174 | ||
1405 | #define SSL_R_NON_SSLV2_INITIAL_PACKET 175 | ||
1406 | #define SSL_R_NO_CERTIFICATES_RETURNED 176 | ||
1407 | #define SSL_R_NO_CERTIFICATE_ASSIGNED 177 | ||
1408 | #define SSL_R_NO_CERTIFICATE_RETURNED 178 | ||
1409 | #define SSL_R_NO_CERTIFICATE_SET 179 | ||
1410 | #define SSL_R_NO_CERTIFICATE_SPECIFIED 180 | ||
1411 | #define SSL_R_NO_CIPHERS_AVAILABLE 181 | ||
1412 | #define SSL_R_NO_CIPHERS_PASSED 182 | ||
1413 | #define SSL_R_NO_CIPHERS_SPECIFIED 183 | ||
1414 | #define SSL_R_NO_CIPHER_LIST 184 | ||
1415 | #define SSL_R_NO_CIPHER_MATCH 185 | ||
1416 | #define SSL_R_NO_CLIENT_CERT_RECEIVED 186 | ||
1417 | #define SSL_R_NO_COMPRESSION_SPECIFIED 187 | ||
1418 | #define SSL_R_NO_METHOD_SPECIFIED 188 | ||
1419 | #define SSL_R_NO_PRIVATEKEY 189 | ||
1420 | #define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190 | ||
1421 | #define SSL_R_NO_PROTOCOLS_AVAILABLE 191 | ||
1422 | #define SSL_R_NO_PUBLICKEY 192 | ||
1423 | #define SSL_R_NO_SHARED_CIPHER 193 | ||
1424 | #define SSL_R_NO_VERIFY_CALLBACK 194 | ||
1425 | #define SSL_R_NULL_SSL_CTX 195 | ||
1426 | #define SSL_R_NULL_SSL_METHOD_PASSED 196 | ||
1427 | #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197 | ||
1428 | #define SSL_R_PACKET_LENGTH_TOO_LONG 198 | ||
1429 | #define SSL_R_PATH_TOO_LONG 270 | ||
1430 | #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199 | ||
1431 | #define SSL_R_PEER_ERROR 200 | ||
1432 | #define SSL_R_PEER_ERROR_CERTIFICATE 201 | ||
1433 | #define SSL_R_PEER_ERROR_NO_CERTIFICATE 202 | ||
1434 | #define SSL_R_PEER_ERROR_NO_CIPHER 203 | ||
1435 | #define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204 | ||
1436 | #define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205 | ||
1437 | #define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206 | ||
1438 | #define SSL_R_PROTOCOL_IS_SHUTDOWN 207 | ||
1439 | #define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208 | ||
1440 | #define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209 | ||
1441 | #define SSL_R_PUBLIC_KEY_NOT_RSA 210 | ||
1442 | #define SSL_R_READ_BIO_NOT_SET 211 | ||
1443 | #define SSL_R_READ_WRONG_PACKET_TYPE 212 | ||
1444 | #define SSL_R_RECORD_LENGTH_MISMATCH 213 | ||
1445 | #define SSL_R_RECORD_TOO_LARGE 214 | ||
1446 | #define SSL_R_REQUIRED_CIPHER_MISSING 215 | ||
1447 | #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216 | ||
1448 | #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217 | ||
1449 | #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218 | ||
1450 | #define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277 | ||
1451 | #define SSL_R_SHORT_READ 219 | ||
1452 | #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220 | ||
1453 | #define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221 | ||
1454 | #define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222 | ||
1455 | #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 | ||
1456 | #define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 | ||
1457 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 | ||
1458 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 | ||
1459 | #define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 | ||
1460 | #define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 | ||
1461 | #define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 | ||
1462 | #define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 | ||
1463 | #define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 | ||
1464 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223 | ||
1465 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224 | ||
1466 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225 | ||
1467 | #define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226 | ||
1468 | #define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 | ||
1469 | #define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227 | ||
1470 | #define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 | ||
1471 | #define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228 | ||
1472 | #define SSL_R_SSL_HANDSHAKE_FAILURE 229 | ||
1473 | #define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230 | ||
1474 | #define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273 | ||
1475 | #define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231 | ||
1476 | #define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 | ||
1477 | #define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 | ||
1478 | #define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 | ||
1479 | #define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 | ||
1480 | #define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060 | ||
1481 | #define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 | ||
1482 | #define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 | ||
1483 | #define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 | ||
1484 | #define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 | ||
1485 | #define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 | ||
1486 | #define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 | ||
1487 | #define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090 | ||
1488 | #define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232 | ||
1489 | #define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233 | ||
1490 | #define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234 | ||
1491 | #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235 | ||
1492 | #define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236 | ||
1493 | #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237 | ||
1494 | #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238 | ||
1495 | #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239 | ||
1496 | #define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240 | ||
1497 | #define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241 | ||
1498 | #define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242 | ||
1499 | #define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243 | ||
1500 | #define SSL_R_UNEXPECTED_MESSAGE 244 | ||
1501 | #define SSL_R_UNEXPECTED_RECORD 245 | ||
1502 | #define SSL_R_UNINITIALIZED 276 | ||
1503 | #define SSL_R_UNKNOWN_ALERT_TYPE 246 | ||
1504 | #define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247 | ||
1505 | #define SSL_R_UNKNOWN_CIPHER_RETURNED 248 | ||
1506 | #define SSL_R_UNKNOWN_CIPHER_TYPE 249 | ||
1507 | #define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250 | ||
1508 | #define SSL_R_UNKNOWN_PKEY_TYPE 251 | ||
1509 | #define SSL_R_UNKNOWN_PROTOCOL 252 | ||
1510 | #define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253 | ||
1511 | #define SSL_R_UNKNOWN_SSL_VERSION 254 | ||
1512 | #define SSL_R_UNKNOWN_STATE 255 | ||
1513 | #define SSL_R_UNSUPPORTED_CIPHER 256 | ||
1514 | #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257 | ||
1515 | #define SSL_R_UNSUPPORTED_OPTION 1091 | ||
1516 | #define SSL_R_UNSUPPORTED_PROTOCOL 258 | ||
1517 | #define SSL_R_UNSUPPORTED_SSL_VERSION 259 | ||
1518 | #define SSL_R_WRITE_BIO_NOT_SET 260 | ||
1519 | #define SSL_R_WRONG_CIPHER_RETURNED 261 | ||
1520 | #define SSL_R_WRONG_MESSAGE_TYPE 262 | ||
1521 | #define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263 | ||
1522 | #define SSL_R_WRONG_SIGNATURE_LENGTH 264 | ||
1523 | #define SSL_R_WRONG_SIGNATURE_SIZE 265 | ||
1524 | #define SSL_R_WRONG_SSL_VERSION 266 | ||
1525 | #define SSL_R_WRONG_VERSION_NUMBER 267 | ||
1526 | #define SSL_R_X509_LIB 268 | ||
1527 | #define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269 | ||
1528 | |||
1529 | #ifdef __cplusplus | ||
1530 | } | ||
1531 | #endif | ||
1532 | #endif | ||
1533 | |||
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h deleted file mode 100644 index 01d41c88c5..0000000000 --- a/src/lib/libssl/ssl2.h +++ /dev/null | |||
@@ -1,265 +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 | #define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)32767 | ||
137 | #define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /**/ | ||
138 | |||
139 | #define SSL2_CHALLENGE_LENGTH 16 | ||
140 | /*#define SSL2_CHALLENGE_LENGTH 32 */ | ||
141 | #define SSL2_MIN_CHALLENGE_LENGTH 16 | ||
142 | #define SSL2_MAX_CHALLENGE_LENGTH 32 | ||
143 | #define SSL2_CONNECTION_ID_LENGTH 16 | ||
144 | #define SSL2_MAX_CONNECTION_ID_LENGTH 16 | ||
145 | #define SSL2_SSL_SESSION_ID_LENGTH 16 | ||
146 | #define SSL2_MAX_CERT_CHALLENGE_LENGTH 32 | ||
147 | #define SSL2_MIN_CERT_CHALLENGE_LENGTH 16 | ||
148 | #define SSL2_MAX_KEY_MATERIAL_LENGTH 24 | ||
149 | |||
150 | #ifndef HEADER_SSL_LOCL_H | ||
151 | #define CERT char | ||
152 | #endif | ||
153 | |||
154 | typedef struct ssl2_state_st | ||
155 | { | ||
156 | int three_byte_header; | ||
157 | int clear_text; /* clear text */ | ||
158 | int escape; /* not used in SSLv2 */ | ||
159 | int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */ | ||
160 | |||
161 | /* non-blocking io info, used to make sure the same | ||
162 | * args were passwd */ | ||
163 | unsigned int wnum; /* number of bytes sent so far */ | ||
164 | int wpend_tot; | ||
165 | const unsigned char *wpend_buf; | ||
166 | |||
167 | int wpend_off; /* offset to data to write */ | ||
168 | int wpend_len; /* number of bytes passwd to write */ | ||
169 | int wpend_ret; /* number of bytes to return to caller */ | ||
170 | |||
171 | /* buffer raw data */ | ||
172 | int rbuf_left; | ||
173 | int rbuf_offs; | ||
174 | unsigned char *rbuf; | ||
175 | unsigned char *wbuf; | ||
176 | |||
177 | unsigned char *write_ptr;/* used to point to the start due to | ||
178 | * 2/3 byte header. */ | ||
179 | |||
180 | unsigned int padding; | ||
181 | unsigned int rlength; /* passed to ssl2_enc */ | ||
182 | int ract_data_length; /* Set when things are encrypted. */ | ||
183 | unsigned int wlength; /* passed to ssl2_enc */ | ||
184 | int wact_data_length; /* Set when things are decrypted. */ | ||
185 | unsigned char *ract_data; | ||
186 | unsigned char *wact_data; | ||
187 | unsigned char *mac_data; | ||
188 | unsigned char *pad_data; | ||
189 | |||
190 | unsigned char *read_key; | ||
191 | unsigned char *write_key; | ||
192 | |||
193 | /* Stuff specifically to do with this SSL session */ | ||
194 | unsigned int challenge_length; | ||
195 | unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH]; | ||
196 | unsigned int conn_id_length; | ||
197 | unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH]; | ||
198 | unsigned int key_material_length; | ||
199 | unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2]; | ||
200 | |||
201 | unsigned long read_sequence; | ||
202 | unsigned long write_sequence; | ||
203 | |||
204 | struct { | ||
205 | unsigned int conn_id_length; | ||
206 | unsigned int cert_type; | ||
207 | unsigned int cert_length; | ||
208 | int csl; | ||
209 | int clear; | ||
210 | unsigned int enc; | ||
211 | unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH]; | ||
212 | int cipher_spec_length; | ||
213 | unsigned int session_id_length; | ||
214 | unsigned int clen; | ||
215 | unsigned int rlen; | ||
216 | } tmp; | ||
217 | } SSL2_STATE; | ||
218 | |||
219 | /* SSLv2 */ | ||
220 | /* client */ | ||
221 | #define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT) | ||
222 | #define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT) | ||
223 | #define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT) | ||
224 | #define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT) | ||
225 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT) | ||
226 | #define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT) | ||
227 | #define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT) | ||
228 | #define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT) | ||
229 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT) | ||
230 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT) | ||
231 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT) | ||
232 | #define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT) | ||
233 | #define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT) | ||
234 | #define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT) | ||
235 | #define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT) | ||
236 | #define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT) | ||
237 | #define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT) | ||
238 | #define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT) | ||
239 | /* server */ | ||
240 | #define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT) | ||
241 | #define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT) | ||
242 | #define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT) | ||
243 | #define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT) | ||
244 | #define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT) | ||
245 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT) | ||
246 | #define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT) | ||
247 | #define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT) | ||
248 | #define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT) | ||
249 | #define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT) | ||
250 | #define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT) | ||
251 | #define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT) | ||
252 | #define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT) | ||
253 | #define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT) | ||
254 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT) | ||
255 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT) | ||
256 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT) | ||
257 | #define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT) | ||
258 | #define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT) | ||
259 | #define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT) | ||
260 | |||
261 | #ifdef __cplusplus | ||
262 | } | ||
263 | #endif | ||
264 | #endif | ||
265 | |||
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 f616763830..0000000000 --- a/src/lib/libssl/ssl3.h +++ /dev/null | |||
@@ -1,426 +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 | #ifndef HEADER_SSL3_H | ||
60 | #define HEADER_SSL3_H | ||
61 | |||
62 | #include <openssl/buffer.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/ssl.h> | ||
65 | |||
66 | #ifdef __cplusplus | ||
67 | extern "C" { | ||
68 | #endif | ||
69 | |||
70 | #define SSL3_CK_RSA_NULL_MD5 0x03000001 | ||
71 | #define SSL3_CK_RSA_NULL_SHA 0x03000002 | ||
72 | #define SSL3_CK_RSA_RC4_40_MD5 0x03000003 | ||
73 | #define SSL3_CK_RSA_RC4_128_MD5 0x03000004 | ||
74 | #define SSL3_CK_RSA_RC4_128_SHA 0x03000005 | ||
75 | #define SSL3_CK_RSA_RC2_40_MD5 0x03000006 | ||
76 | #define SSL3_CK_RSA_IDEA_128_SHA 0x03000007 | ||
77 | #define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008 | ||
78 | #define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009 | ||
79 | #define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A | ||
80 | |||
81 | #define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B | ||
82 | #define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C | ||
83 | #define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D | ||
84 | #define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E | ||
85 | #define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F | ||
86 | #define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010 | ||
87 | |||
88 | #define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011 | ||
89 | #define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012 | ||
90 | #define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013 | ||
91 | #define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014 | ||
92 | #define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015 | ||
93 | #define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016 | ||
94 | |||
95 | #define SSL3_CK_ADH_RC4_40_MD5 0x03000017 | ||
96 | #define SSL3_CK_ADH_RC4_128_MD5 0x03000018 | ||
97 | #define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019 | ||
98 | #define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A | ||
99 | #define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B | ||
100 | |||
101 | #define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C | ||
102 | #define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D | ||
103 | #define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E | ||
104 | |||
105 | #define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" | ||
106 | #define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" | ||
107 | #define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5" | ||
108 | #define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5" | ||
109 | #define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA" | ||
110 | #define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5" | ||
111 | #define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA" | ||
112 | #define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA" | ||
113 | #define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA" | ||
114 | #define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA" | ||
115 | |||
116 | #define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA" | ||
117 | #define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA" | ||
118 | #define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA" | ||
119 | #define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA" | ||
120 | #define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA" | ||
121 | #define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA" | ||
122 | |||
123 | #define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA" | ||
124 | #define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA" | ||
125 | #define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA" | ||
126 | #define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA" | ||
127 | #define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA" | ||
128 | #define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA" | ||
129 | |||
130 | #define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5" | ||
131 | #define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5" | ||
132 | #define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA" | ||
133 | #define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA" | ||
134 | #define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA" | ||
135 | |||
136 | #define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA" | ||
137 | #define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" | ||
138 | #define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" | ||
139 | |||
140 | #define SSL3_SSL_SESSION_ID_LENGTH 32 | ||
141 | #define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 | ||
142 | |||
143 | #define SSL3_MASTER_SECRET_SIZE 48 | ||
144 | #define SSL3_RANDOM_SIZE 32 | ||
145 | #define SSL3_SESSION_ID_SIZE 32 | ||
146 | #define SSL3_RT_HEADER_LENGTH 5 | ||
147 | |||
148 | /* Due to MS stuffing up, this can change.... */ | ||
149 | #if defined(WIN16) || (defined(MSDOS) && !defined(WIN32)) | ||
150 | #define SSL3_RT_MAX_EXTRA (14000) | ||
151 | #else | ||
152 | #define SSL3_RT_MAX_EXTRA (16384) | ||
153 | #endif | ||
154 | |||
155 | #define SSL3_RT_MAX_PLAIN_LENGTH 16384 | ||
156 | #define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH) | ||
157 | #define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH) | ||
158 | #define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH) | ||
159 | #define SSL3_RT_MAX_DATA_SIZE (1024*1024) | ||
160 | |||
161 | #define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54" | ||
162 | #define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52" | ||
163 | |||
164 | #define SSL3_VERSION 0x0300 | ||
165 | #define SSL3_VERSION_MAJOR 0x03 | ||
166 | #define SSL3_VERSION_MINOR 0x00 | ||
167 | |||
168 | #define SSL3_RT_CHANGE_CIPHER_SPEC 20 | ||
169 | #define SSL3_RT_ALERT 21 | ||
170 | #define SSL3_RT_HANDSHAKE 22 | ||
171 | #define SSL3_RT_APPLICATION_DATA 23 | ||
172 | |||
173 | #define SSL3_AL_WARNING 1 | ||
174 | #define SSL3_AL_FATAL 2 | ||
175 | |||
176 | #define SSL3_AD_CLOSE_NOTIFY 0 | ||
177 | #define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */ | ||
178 | #define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */ | ||
179 | #define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */ | ||
180 | #define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */ | ||
181 | #define SSL3_AD_NO_CERTIFICATE 41 | ||
182 | #define SSL3_AD_BAD_CERTIFICATE 42 | ||
183 | #define SSL3_AD_UNSUPPORTED_CERTIFICATE 43 | ||
184 | #define SSL3_AD_CERTIFICATE_REVOKED 44 | ||
185 | #define SSL3_AD_CERTIFICATE_EXPIRED 45 | ||
186 | #define SSL3_AD_CERTIFICATE_UNKNOWN 46 | ||
187 | #define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */ | ||
188 | |||
189 | typedef struct ssl3_record_st | ||
190 | { | ||
191 | /*r */ int type; /* type of record */ | ||
192 | /*rw*/ unsigned int length; /* How many bytes available */ | ||
193 | /*r */ unsigned int off; /* read/write offset into 'buf' */ | ||
194 | /*rw*/ unsigned char *data; /* pointer to the record data */ | ||
195 | /*rw*/ unsigned char *input; /* where the decode bytes are */ | ||
196 | /*r */ unsigned char *comp; /* only used with decompression - malloc()ed */ | ||
197 | } SSL3_RECORD; | ||
198 | |||
199 | typedef struct ssl3_buffer_st | ||
200 | { | ||
201 | unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes (more if | ||
202 | * SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER is set) */ | ||
203 | int offset; /* where to 'copy from' */ | ||
204 | int left; /* how many bytes left */ | ||
205 | } SSL3_BUFFER; | ||
206 | |||
207 | #define SSL3_CT_RSA_SIGN 1 | ||
208 | #define SSL3_CT_DSS_SIGN 2 | ||
209 | #define SSL3_CT_RSA_FIXED_DH 3 | ||
210 | #define SSL3_CT_DSS_FIXED_DH 4 | ||
211 | #define SSL3_CT_RSA_EPHEMERAL_DH 5 | ||
212 | #define SSL3_CT_DSS_EPHEMERAL_DH 6 | ||
213 | #define SSL3_CT_FORTEZZA_DMS 20 | ||
214 | #define SSL3_CT_NUMBER 7 | ||
215 | |||
216 | #define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001 | ||
217 | #define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002 | ||
218 | #define SSL3_FLAGS_POP_BUFFER 0x0004 | ||
219 | #define TLS1_FLAGS_TLS_PADDING_BUG 0x0008 | ||
220 | |||
221 | typedef struct ssl3_state_st | ||
222 | { | ||
223 | long flags; | ||
224 | int delay_buf_pop_ret; | ||
225 | |||
226 | unsigned char read_sequence[8]; | ||
227 | unsigned char read_mac_secret[EVP_MAX_MD_SIZE]; | ||
228 | unsigned char write_sequence[8]; | ||
229 | unsigned char write_mac_secret[EVP_MAX_MD_SIZE]; | ||
230 | |||
231 | unsigned char server_random[SSL3_RANDOM_SIZE]; | ||
232 | unsigned char client_random[SSL3_RANDOM_SIZE]; | ||
233 | |||
234 | SSL3_BUFFER rbuf; /* read IO goes into here */ | ||
235 | SSL3_BUFFER wbuf; /* write IO goes into here */ | ||
236 | |||
237 | SSL3_RECORD rrec; /* each decoded record goes in here */ | ||
238 | SSL3_RECORD wrec; /* goes out from here */ | ||
239 | |||
240 | /* storage for Alert/Handshake protocol data received but not | ||
241 | * yet processed by ssl3_read_bytes: */ | ||
242 | unsigned char alert_fragment[2]; | ||
243 | unsigned int alert_fragment_len; | ||
244 | unsigned char handshake_fragment[4]; | ||
245 | unsigned int handshake_fragment_len; | ||
246 | |||
247 | /* partial write - check the numbers match */ | ||
248 | unsigned int wnum; /* number of bytes sent so far */ | ||
249 | int wpend_tot; /* number bytes written */ | ||
250 | int wpend_type; | ||
251 | int wpend_ret; /* number of bytes submitted */ | ||
252 | const unsigned char *wpend_buf; | ||
253 | |||
254 | /* used during startup, digest all incoming/outgoing packets */ | ||
255 | EVP_MD_CTX finish_dgst1; | ||
256 | EVP_MD_CTX finish_dgst2; | ||
257 | |||
258 | /* this is set whenerver we see a change_cipher_spec message | ||
259 | * come in when we are not looking for one */ | ||
260 | int change_cipher_spec; | ||
261 | |||
262 | int warn_alert; | ||
263 | int fatal_alert; | ||
264 | /* we allow one fatal and one warning alert to be outstanding, | ||
265 | * send close alert via the warning alert */ | ||
266 | int alert_dispatch; | ||
267 | unsigned char send_alert[2]; | ||
268 | |||
269 | /* This flag is set when we should renegotiate ASAP, basically when | ||
270 | * there is no more data in the read or write buffers */ | ||
271 | int renegotiate; | ||
272 | int total_renegotiations; | ||
273 | int num_renegotiations; | ||
274 | |||
275 | int in_read_app_data; | ||
276 | |||
277 | struct { | ||
278 | /* actually only needs to be 16+20 */ | ||
279 | unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2]; | ||
280 | |||
281 | /* actually only need to be 16+20 for SSLv3 and 12 for TLS */ | ||
282 | unsigned char finish_md[EVP_MAX_MD_SIZE*2]; | ||
283 | int finish_md_len; | ||
284 | unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2]; | ||
285 | int peer_finish_md_len; | ||
286 | |||
287 | unsigned long message_size; | ||
288 | int message_type; | ||
289 | |||
290 | /* used to hold the new cipher we are going to use */ | ||
291 | SSL_CIPHER *new_cipher; | ||
292 | #ifndef NO_DH | ||
293 | DH *dh; | ||
294 | #endif | ||
295 | /* used when SSL_ST_FLUSH_DATA is entered */ | ||
296 | int next_state; | ||
297 | |||
298 | int reuse_message; | ||
299 | |||
300 | /* used for certificate requests */ | ||
301 | int cert_req; | ||
302 | int ctype_num; | ||
303 | char ctype[SSL3_CT_NUMBER]; | ||
304 | STACK_OF(X509_NAME) *ca_names; | ||
305 | |||
306 | int use_rsa_tmp; | ||
307 | |||
308 | int key_block_length; | ||
309 | unsigned char *key_block; | ||
310 | |||
311 | const EVP_CIPHER *new_sym_enc; | ||
312 | const EVP_MD *new_hash; | ||
313 | #ifdef HEADER_COMP_H | ||
314 | const SSL_COMP *new_compression; | ||
315 | #else | ||
316 | char *new_compression; | ||
317 | #endif | ||
318 | int cert_request; | ||
319 | } tmp; | ||
320 | |||
321 | } SSL3_STATE; | ||
322 | |||
323 | /* SSLv3 */ | ||
324 | /*client */ | ||
325 | /* extra state */ | ||
326 | #define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT) | ||
327 | /* write to server */ | ||
328 | #define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT) | ||
329 | #define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT) | ||
330 | /* read from server */ | ||
331 | #define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT) | ||
332 | #define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT) | ||
333 | #define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT) | ||
334 | #define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT) | ||
335 | #define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT) | ||
336 | #define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT) | ||
337 | #define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT) | ||
338 | #define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT) | ||
339 | #define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT) | ||
340 | #define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT) | ||
341 | /* write to server */ | ||
342 | #define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT) | ||
343 | #define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT) | ||
344 | #define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT) | ||
345 | #define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT) | ||
346 | #define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT) | ||
347 | #define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT) | ||
348 | #define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT) | ||
349 | #define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT) | ||
350 | #define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT) | ||
351 | #define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT) | ||
352 | #define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT) | ||
353 | #define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT) | ||
354 | /* read from server */ | ||
355 | #define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT) | ||
356 | #define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT) | ||
357 | #define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT) | ||
358 | #define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT) | ||
359 | |||
360 | /* server */ | ||
361 | /* extra state */ | ||
362 | #define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT) | ||
363 | /* read from client */ | ||
364 | /* Do not change the number values, they do matter */ | ||
365 | #define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT) | ||
366 | #define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT) | ||
367 | #define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT) | ||
368 | /* write to client */ | ||
369 | #define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT) | ||
370 | #define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT) | ||
371 | #define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT) | ||
372 | #define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT) | ||
373 | #define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT) | ||
374 | #define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT) | ||
375 | #define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT) | ||
376 | #define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT) | ||
377 | #define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT) | ||
378 | #define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT) | ||
379 | #define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT) | ||
380 | #define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT) | ||
381 | #define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT) | ||
382 | /* read from client */ | ||
383 | #define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT) | ||
384 | #define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT) | ||
385 | #define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT) | ||
386 | #define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT) | ||
387 | #define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT) | ||
388 | #define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT) | ||
389 | #define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT) | ||
390 | #define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT) | ||
391 | #define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT) | ||
392 | #define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT) | ||
393 | /* write to client */ | ||
394 | #define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT) | ||
395 | #define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT) | ||
396 | #define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT) | ||
397 | #define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT) | ||
398 | |||
399 | #define SSL3_MT_HELLO_REQUEST 0 | ||
400 | #define SSL3_MT_CLIENT_HELLO 1 | ||
401 | #define SSL3_MT_SERVER_HELLO 2 | ||
402 | #define SSL3_MT_CERTIFICATE 11 | ||
403 | #define SSL3_MT_SERVER_KEY_EXCHANGE 12 | ||
404 | #define SSL3_MT_CERTIFICATE_REQUEST 13 | ||
405 | #define SSL3_MT_SERVER_DONE 14 | ||
406 | #define SSL3_MT_CERTIFICATE_VERIFY 15 | ||
407 | #define SSL3_MT_CLIENT_KEY_EXCHANGE 16 | ||
408 | #define SSL3_MT_FINISHED 20 | ||
409 | |||
410 | #define SSL3_MT_CCS 1 | ||
411 | |||
412 | /* These are used when changing over to a new cipher */ | ||
413 | #define SSL3_CC_READ 0x01 | ||
414 | #define SSL3_CC_WRITE 0x02 | ||
415 | #define SSL3_CC_CLIENT 0x10 | ||
416 | #define SSL3_CC_SERVER 0x20 | ||
417 | #define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE) | ||
418 | #define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ) | ||
419 | #define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ) | ||
420 | #define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE) | ||
421 | |||
422 | #ifdef __cplusplus | ||
423 | } | ||
424 | #endif | ||
425 | #endif | ||
426 | |||
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c deleted file mode 100644 index a91ee6d22e..0000000000 --- a/src/lib/libssl/ssl_algs.c +++ /dev/null | |||
@@ -1,103 +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 | #ifndef NO_DES | ||
67 | EVP_add_cipher(EVP_des_cbc()); | ||
68 | EVP_add_cipher(EVP_des_ede3_cbc()); | ||
69 | #endif | ||
70 | #ifndef NO_IDEA | ||
71 | EVP_add_cipher(EVP_idea_cbc()); | ||
72 | #endif | ||
73 | #ifndef NO_RC4 | ||
74 | EVP_add_cipher(EVP_rc4()); | ||
75 | #endif | ||
76 | #ifndef NO_RC2 | ||
77 | EVP_add_cipher(EVP_rc2_cbc()); | ||
78 | #endif | ||
79 | |||
80 | #ifndef NO_MD2 | ||
81 | EVP_add_digest(EVP_md2()); | ||
82 | #endif | ||
83 | #ifndef NO_MD5 | ||
84 | EVP_add_digest(EVP_md5()); | ||
85 | EVP_add_digest_alias(SN_md5,"ssl2-md5"); | ||
86 | EVP_add_digest_alias(SN_md5,"ssl3-md5"); | ||
87 | #endif | ||
88 | #ifndef NO_SHA | ||
89 | EVP_add_digest(EVP_sha1()); /* RSA with sha1 */ | ||
90 | EVP_add_digest_alias(SN_sha1,"ssl3-sha1"); | ||
91 | #endif | ||
92 | #if !defined(NO_SHA) && !defined(NO_DSA) | ||
93 | EVP_add_digest(EVP_dss1()); /* DSA with sha1 */ | ||
94 | #endif | ||
95 | |||
96 | /* If you want support for phased out ciphers, add the following */ | ||
97 | #if 0 | ||
98 | EVP_add_digest(EVP_sha()); | ||
99 | EVP_add_digest(EVP_dss()); | ||
100 | #endif | ||
101 | return(1); | ||
102 | } | ||
103 | |||
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c deleted file mode 100644 index e77cdddfd3..0000000000 --- a/src/lib/libssl/ssl_asn1.c +++ /dev/null | |||
@@ -1,349 +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 <openssl/asn1_mac.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | #include "ssl_locl.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 | ASN1_INTEGER time; | ||
76 | ASN1_INTEGER timeout; | ||
77 | ASN1_INTEGER verify_result; | ||
78 | } SSL_SESSION_ASN1; | ||
79 | |||
80 | int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) | ||
81 | { | ||
82 | #define LSIZE2 (sizeof(long)*2) | ||
83 | int v1=0,v2=0,v3=0,v4=0,v5=0; | ||
84 | unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2]; | ||
85 | unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2]; | ||
86 | long l; | ||
87 | SSL_SESSION_ASN1 a; | ||
88 | M_ASN1_I2D_vars(in); | ||
89 | |||
90 | if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0))) | ||
91 | return(0); | ||
92 | |||
93 | /* Note that I cheat in the following 2 assignments. I know | ||
94 | * that if the ASN1_INTEGER passed to ASN1_INTEGER_set | ||
95 | * is > sizeof(long)+1, the buffer will not be re-Malloc()ed. | ||
96 | * This is a bit evil but makes things simple, no dynamic allocation | ||
97 | * to clean up :-) */ | ||
98 | a.version.length=LSIZE2; | ||
99 | a.version.type=V_ASN1_INTEGER; | ||
100 | a.version.data=ibuf1; | ||
101 | ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION); | ||
102 | |||
103 | a.ssl_version.length=LSIZE2; | ||
104 | a.ssl_version.type=V_ASN1_INTEGER; | ||
105 | a.ssl_version.data=ibuf2; | ||
106 | ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version); | ||
107 | |||
108 | a.cipher.type=V_ASN1_OCTET_STRING; | ||
109 | a.cipher.data=buf; | ||
110 | |||
111 | if (in->cipher == NULL) | ||
112 | l=in->cipher_id; | ||
113 | else | ||
114 | l=in->cipher->id; | ||
115 | if (in->ssl_version == SSL2_VERSION) | ||
116 | { | ||
117 | a.cipher.length=3; | ||
118 | buf[0]=((unsigned char)(l>>16L))&0xff; | ||
119 | buf[1]=((unsigned char)(l>> 8L))&0xff; | ||
120 | buf[2]=((unsigned char)(l ))&0xff; | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | a.cipher.length=2; | ||
125 | buf[0]=((unsigned char)(l>>8L))&0xff; | ||
126 | buf[1]=((unsigned char)(l ))&0xff; | ||
127 | } | ||
128 | |||
129 | a.master_key.length=in->master_key_length; | ||
130 | a.master_key.type=V_ASN1_OCTET_STRING; | ||
131 | a.master_key.data=in->master_key; | ||
132 | |||
133 | a.session_id.length=in->session_id_length; | ||
134 | a.session_id.type=V_ASN1_OCTET_STRING; | ||
135 | a.session_id.data=in->session_id; | ||
136 | |||
137 | a.session_id_context.length=in->sid_ctx_length; | ||
138 | a.session_id_context.type=V_ASN1_OCTET_STRING; | ||
139 | a.session_id_context.data=in->sid_ctx; | ||
140 | |||
141 | a.key_arg.length=in->key_arg_length; | ||
142 | a.key_arg.type=V_ASN1_OCTET_STRING; | ||
143 | a.key_arg.data=in->key_arg; | ||
144 | |||
145 | if (in->time != 0L) | ||
146 | { | ||
147 | a.time.length=LSIZE2; | ||
148 | a.time.type=V_ASN1_INTEGER; | ||
149 | a.time.data=ibuf3; | ||
150 | ASN1_INTEGER_set(&(a.time),in->time); | ||
151 | } | ||
152 | |||
153 | if (in->timeout != 0L) | ||
154 | { | ||
155 | a.timeout.length=LSIZE2; | ||
156 | a.timeout.type=V_ASN1_INTEGER; | ||
157 | a.timeout.data=ibuf4; | ||
158 | ASN1_INTEGER_set(&(a.timeout),in->timeout); | ||
159 | } | ||
160 | |||
161 | if (in->verify_result != X509_V_OK) | ||
162 | { | ||
163 | a.verify_result.length=LSIZE2; | ||
164 | a.verify_result.type=V_ASN1_INTEGER; | ||
165 | a.verify_result.data=ibuf5; | ||
166 | ASN1_INTEGER_set(&a.verify_result,in->verify_result); | ||
167 | } | ||
168 | |||
169 | M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER); | ||
170 | M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
171 | M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
172 | M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
173 | M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
174 | if (in->key_arg_length > 0) | ||
175 | M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING); | ||
176 | if (in->time != 0L) | ||
177 | M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
178 | if (in->timeout != 0L) | ||
179 | M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
180 | if (in->peer != NULL) | ||
181 | M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3); | ||
182 | M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4); | ||
183 | if (in->verify_result != X509_V_OK) | ||
184 | M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5); | ||
185 | |||
186 | M_ASN1_I2D_seq_total(); | ||
187 | |||
188 | M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER); | ||
189 | M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER); | ||
190 | M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING); | ||
191 | M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING); | ||
192 | M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING); | ||
193 | if (in->key_arg_length > 0) | ||
194 | M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0); | ||
195 | if (in->time != 0L) | ||
196 | M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1); | ||
197 | if (in->timeout != 0L) | ||
198 | M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2); | ||
199 | if (in->peer != NULL) | ||
200 | M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3); | ||
201 | M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4, | ||
202 | v4); | ||
203 | if (in->verify_result != X509_V_OK) | ||
204 | M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5); | ||
205 | M_ASN1_I2D_finish(); | ||
206 | } | ||
207 | |||
208 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, | ||
209 | long length) | ||
210 | { | ||
211 | int version,ssl_version=0,i; | ||
212 | long id; | ||
213 | ASN1_INTEGER ai,*aip; | ||
214 | ASN1_OCTET_STRING os,*osp; | ||
215 | M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new); | ||
216 | |||
217 | aip= &ai; | ||
218 | osp= &os; | ||
219 | |||
220 | M_ASN1_D2I_Init(); | ||
221 | M_ASN1_D2I_start_sequence(); | ||
222 | |||
223 | ai.data=NULL; ai.length=0; | ||
224 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
225 | version=(int)ASN1_INTEGER_get(aip); | ||
226 | if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; } | ||
227 | |||
228 | /* we don't care about the version right now :-) */ | ||
229 | M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER); | ||
230 | ssl_version=(int)ASN1_INTEGER_get(aip); | ||
231 | ret->ssl_version=ssl_version; | ||
232 | if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; } | ||
233 | |||
234 | os.data=NULL; os.length=0; | ||
235 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
236 | if (ssl_version == SSL2_VERSION) | ||
237 | { | ||
238 | if (os.length != 3) | ||
239 | { | ||
240 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
241 | goto err; | ||
242 | } | ||
243 | id=0x02000000L| | ||
244 | ((unsigned long)os.data[0]<<16L)| | ||
245 | ((unsigned long)os.data[1]<< 8L)| | ||
246 | (unsigned long)os.data[2]; | ||
247 | } | ||
248 | else if ((ssl_version>>8) == 3) | ||
249 | { | ||
250 | if (os.length != 2) | ||
251 | { | ||
252 | c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH; | ||
253 | goto err; | ||
254 | } | ||
255 | id=0x03000000L| | ||
256 | ((unsigned long)os.data[0]<<8L)| | ||
257 | (unsigned long)os.data[1]; | ||
258 | } | ||
259 | else | ||
260 | { | ||
261 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION); | ||
262 | return(NULL); | ||
263 | } | ||
264 | |||
265 | ret->cipher=NULL; | ||
266 | ret->cipher_id=id; | ||
267 | |||
268 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
269 | if ((ssl_version>>8) == SSL3_VERSION) | ||
270 | i=SSL3_MAX_SSL_SESSION_ID_LENGTH; | ||
271 | else /* if (ssl_version == SSL2_VERSION) */ | ||
272 | i=SSL2_MAX_SSL_SESSION_ID_LENGTH; | ||
273 | |||
274 | if (os.length > i) | ||
275 | os.length=i; | ||
276 | |||
277 | ret->session_id_length=os.length; | ||
278 | memcpy(ret->session_id,os.data,os.length); | ||
279 | |||
280 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | ||
281 | if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH) | ||
282 | ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | ||
283 | else | ||
284 | ret->master_key_length=os.length; | ||
285 | memcpy(ret->master_key,os.data,ret->master_key_length); | ||
286 | |||
287 | os.length=0; | ||
288 | M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING); | ||
289 | if (os.length > SSL_MAX_KEY_ARG_LENGTH) | ||
290 | ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH; | ||
291 | else | ||
292 | ret->key_arg_length=os.length; | ||
293 | memcpy(ret->key_arg,os.data,ret->key_arg_length); | ||
294 | if (os.data != NULL) Free(os.data); | ||
295 | |||
296 | ai.length=0; | ||
297 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1); | ||
298 | if (ai.data != NULL) | ||
299 | { | ||
300 | ret->time=ASN1_INTEGER_get(aip); | ||
301 | Free(ai.data); ai.data=NULL; ai.length=0; | ||
302 | } | ||
303 | else | ||
304 | ret->time=time(NULL); | ||
305 | |||
306 | ai.length=0; | ||
307 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2); | ||
308 | if (ai.data != NULL) | ||
309 | { | ||
310 | ret->timeout=ASN1_INTEGER_get(aip); | ||
311 | Free(ai.data); ai.data=NULL; ai.length=0; | ||
312 | } | ||
313 | else | ||
314 | ret->timeout=3; | ||
315 | |||
316 | if (ret->peer != NULL) | ||
317 | { | ||
318 | X509_free(ret->peer); | ||
319 | ret->peer=NULL; | ||
320 | } | ||
321 | M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3); | ||
322 | |||
323 | os.length=0; | ||
324 | os.data=NULL; | ||
325 | M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4); | ||
326 | |||
327 | if(os.data != NULL) | ||
328 | { | ||
329 | if (os.length > SSL_MAX_SID_CTX_LENGTH) | ||
330 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH); | ||
331 | ret->sid_ctx_length=os.length; | ||
332 | memcpy(ret->sid_ctx,os.data,os.length); | ||
333 | Free(os.data); os.data=NULL; os.length=0; | ||
334 | } | ||
335 | else | ||
336 | ret->sid_ctx_length=0; | ||
337 | |||
338 | ai.length=0; | ||
339 | M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5); | ||
340 | if (ai.data != NULL) | ||
341 | { | ||
342 | ret->verify_result=ASN1_INTEGER_get(aip); | ||
343 | Free(ai.data); ai.data=NULL; ai.length=0; | ||
344 | } | ||
345 | else | ||
346 | ret->verify_result=X509_V_OK; | ||
347 | |||
348 | M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION); | ||
349 | } | ||
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c deleted file mode 100644 index f2335d5650..0000000000 --- a/src/lib/libssl/ssl_cert.c +++ /dev/null | |||
@@ -1,753 +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 "openssl/e_os.h" | ||
110 | |||
111 | #ifndef NO_SYS_TYPES_H | ||
112 | # include <sys/types.h> | ||
113 | #endif | ||
114 | |||
115 | #if !defined(WIN32) && !defined(VSM) && !defined(NeXT) && !defined(MAC_OS_pre_X) | ||
116 | #include <dirent.h> | ||
117 | #endif | ||
118 | |||
119 | #ifdef NeXT | ||
120 | #include <sys/dir.h> | ||
121 | #define dirent direct | ||
122 | #endif | ||
123 | |||
124 | #include <openssl/objects.h> | ||
125 | #include <openssl/bio.h> | ||
126 | #include <openssl/pem.h> | ||
127 | #include <openssl/x509v3.h> | ||
128 | #include "ssl_locl.h" | ||
129 | |||
130 | int SSL_get_ex_data_X509_STORE_CTX_idx(void) | ||
131 | { | ||
132 | static int ssl_x509_store_ctx_idx= -1; | ||
133 | |||
134 | if (ssl_x509_store_ctx_idx < 0) | ||
135 | { | ||
136 | ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index( | ||
137 | 0,"SSL for verify callback",NULL,NULL,NULL); | ||
138 | } | ||
139 | return(ssl_x509_store_ctx_idx); | ||
140 | } | ||
141 | |||
142 | CERT *ssl_cert_new(void) | ||
143 | { | ||
144 | CERT *ret; | ||
145 | |||
146 | ret=(CERT *)Malloc(sizeof(CERT)); | ||
147 | if (ret == NULL) | ||
148 | { | ||
149 | SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE); | ||
150 | return(NULL); | ||
151 | } | ||
152 | memset(ret,0,sizeof(CERT)); | ||
153 | |||
154 | ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]); | ||
155 | ret->references=1; | ||
156 | |||
157 | return(ret); | ||
158 | } | ||
159 | |||
160 | CERT *ssl_cert_dup(CERT *cert) | ||
161 | { | ||
162 | CERT *ret; | ||
163 | int i; | ||
164 | |||
165 | ret = (CERT *)Malloc(sizeof(CERT)); | ||
166 | if (ret == NULL) | ||
167 | { | ||
168 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE); | ||
169 | return(NULL); | ||
170 | } | ||
171 | |||
172 | memset(ret, 0, sizeof(CERT)); | ||
173 | |||
174 | ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]]; | ||
175 | /* or ret->key = ret->pkeys + (cert->key - cert->pkeys), | ||
176 | * if you find that more readable */ | ||
177 | |||
178 | ret->valid = cert->valid; | ||
179 | ret->mask = cert->mask; | ||
180 | ret->export_mask = cert->export_mask; | ||
181 | |||
182 | #ifndef NO_RSA | ||
183 | if (cert->rsa_tmp != NULL) | ||
184 | { | ||
185 | ret->rsa_tmp = cert->rsa_tmp; | ||
186 | CRYPTO_add(&ret->rsa_tmp->references, 1, CRYPTO_LOCK_RSA); | ||
187 | } | ||
188 | ret->rsa_tmp_cb = cert->rsa_tmp_cb; | ||
189 | #endif | ||
190 | |||
191 | #ifndef NO_DH | ||
192 | if (cert->dh_tmp != NULL) | ||
193 | { | ||
194 | /* DH parameters don't have a reference count */ | ||
195 | ret->dh_tmp = DHparams_dup(cert->dh_tmp); | ||
196 | if (ret->dh_tmp == NULL) | ||
197 | { | ||
198 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB); | ||
199 | goto err; | ||
200 | } | ||
201 | if (cert->dh_tmp->priv_key) | ||
202 | { | ||
203 | BIGNUM *b = BN_dup(cert->dh_tmp->priv_key); | ||
204 | if (!b) | ||
205 | { | ||
206 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB); | ||
207 | goto err; | ||
208 | } | ||
209 | ret->dh_tmp->priv_key = b; | ||
210 | } | ||
211 | if (cert->dh_tmp->pub_key) | ||
212 | { | ||
213 | BIGNUM *b = BN_dup(cert->dh_tmp->pub_key); | ||
214 | if (!b) | ||
215 | { | ||
216 | SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB); | ||
217 | goto err; | ||
218 | } | ||
219 | ret->dh_tmp->pub_key = b; | ||
220 | } | ||
221 | } | ||
222 | ret->dh_tmp_cb = cert->dh_tmp_cb; | ||
223 | #endif | ||
224 | |||
225 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
226 | { | ||
227 | if (cert->pkeys[i].x509 != NULL) | ||
228 | { | ||
229 | ret->pkeys[i].x509 = cert->pkeys[i].x509; | ||
230 | CRYPTO_add(&ret->pkeys[i].x509->references, 1, | ||
231 | CRYPTO_LOCK_X509); | ||
232 | } | ||
233 | |||
234 | if (cert->pkeys[i].privatekey != NULL) | ||
235 | { | ||
236 | ret->pkeys[i].privatekey = cert->pkeys[i].privatekey; | ||
237 | CRYPTO_add(&ret->pkeys[i].privatekey->references, 1, | ||
238 | CRYPTO_LOCK_EVP_PKEY); | ||
239 | |||
240 | switch(i) | ||
241 | { | ||
242 | /* If there was anything special to do for | ||
243 | * certain types of keys, we'd do it here. | ||
244 | * (Nothing at the moment, I think.) */ | ||
245 | |||
246 | case SSL_PKEY_RSA_ENC: | ||
247 | case SSL_PKEY_RSA_SIGN: | ||
248 | /* We have an RSA key. */ | ||
249 | break; | ||
250 | |||
251 | case SSL_PKEY_DSA_SIGN: | ||
252 | /* We have a DSA key. */ | ||
253 | break; | ||
254 | |||
255 | case SSL_PKEY_DH_RSA: | ||
256 | case SSL_PKEY_DH_DSA: | ||
257 | /* We have a DH key. */ | ||
258 | break; | ||
259 | |||
260 | default: | ||
261 | /* Can't happen. */ | ||
262 | SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG); | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
267 | /* ret->extra_certs *should* exist, but currently the own certificate | ||
268 | * chain is held inside SSL_CTX */ | ||
269 | |||
270 | ret->references=1; | ||
271 | |||
272 | return(ret); | ||
273 | |||
274 | err: | ||
275 | #ifndef NO_RSA | ||
276 | if (ret->rsa_tmp != NULL) | ||
277 | RSA_free(ret->rsa_tmp); | ||
278 | #endif | ||
279 | #ifndef NO_DH | ||
280 | if (ret->dh_tmp != NULL) | ||
281 | DH_free(ret->dh_tmp); | ||
282 | #endif | ||
283 | |||
284 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
285 | { | ||
286 | if (ret->pkeys[i].x509 != NULL) | ||
287 | X509_free(ret->pkeys[i].x509); | ||
288 | if (ret->pkeys[i].privatekey != NULL) | ||
289 | EVP_PKEY_free(ret->pkeys[i].privatekey); | ||
290 | } | ||
291 | |||
292 | return NULL; | ||
293 | } | ||
294 | |||
295 | |||
296 | void ssl_cert_free(CERT *c) | ||
297 | { | ||
298 | int i; | ||
299 | |||
300 | if(c == NULL) | ||
301 | return; | ||
302 | |||
303 | i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT); | ||
304 | #ifdef REF_PRINT | ||
305 | REF_PRINT("CERT",c); | ||
306 | #endif | ||
307 | if (i > 0) return; | ||
308 | #ifdef REF_CHECK | ||
309 | if (i < 0) | ||
310 | { | ||
311 | fprintf(stderr,"ssl_cert_free, bad reference count\n"); | ||
312 | abort(); /* ok */ | ||
313 | } | ||
314 | #endif | ||
315 | |||
316 | #ifndef NO_RSA | ||
317 | if (c->rsa_tmp) RSA_free(c->rsa_tmp); | ||
318 | #endif | ||
319 | #ifndef NO_DH | ||
320 | if (c->dh_tmp) DH_free(c->dh_tmp); | ||
321 | #endif | ||
322 | |||
323 | for (i=0; i<SSL_PKEY_NUM; i++) | ||
324 | { | ||
325 | if (c->pkeys[i].x509 != NULL) | ||
326 | X509_free(c->pkeys[i].x509); | ||
327 | if (c->pkeys[i].privatekey != NULL) | ||
328 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
329 | #if 0 | ||
330 | if (c->pkeys[i].publickey != NULL) | ||
331 | EVP_PKEY_free(c->pkeys[i].publickey); | ||
332 | #endif | ||
333 | } | ||
334 | Free(c); | ||
335 | } | ||
336 | |||
337 | int ssl_cert_inst(CERT **o) | ||
338 | { | ||
339 | /* Create a CERT if there isn't already one | ||
340 | * (which cannot really happen, as it is initially created in | ||
341 | * SSL_CTX_new; but the earlier code usually allows for that one | ||
342 | * being non-existant, so we follow that behaviour, as it might | ||
343 | * turn out that there actually is a reason for it -- but I'm | ||
344 | * not sure that *all* of the existing code could cope with | ||
345 | * s->cert being NULL, otherwise we could do without the | ||
346 | * initialization in SSL_CTX_new). | ||
347 | */ | ||
348 | |||
349 | if (o == NULL) | ||
350 | { | ||
351 | SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER); | ||
352 | return(0); | ||
353 | } | ||
354 | if (*o == NULL) | ||
355 | { | ||
356 | if ((*o = ssl_cert_new()) == NULL) | ||
357 | { | ||
358 | SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE); | ||
359 | return(0); | ||
360 | } | ||
361 | } | ||
362 | return(1); | ||
363 | } | ||
364 | |||
365 | |||
366 | SESS_CERT *ssl_sess_cert_new(void) | ||
367 | { | ||
368 | SESS_CERT *ret; | ||
369 | |||
370 | ret = Malloc(sizeof *ret); | ||
371 | if (ret == NULL) | ||
372 | { | ||
373 | SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE); | ||
374 | return NULL; | ||
375 | } | ||
376 | |||
377 | memset(ret, 0 ,sizeof *ret); | ||
378 | ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]); | ||
379 | ret->references = 1; | ||
380 | |||
381 | return ret; | ||
382 | } | ||
383 | |||
384 | void ssl_sess_cert_free(SESS_CERT *sc) | ||
385 | { | ||
386 | int i; | ||
387 | |||
388 | if (sc == NULL) | ||
389 | return; | ||
390 | |||
391 | i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT); | ||
392 | #ifdef REF_PRINT | ||
393 | REF_PRINT("SESS_CERT", sc); | ||
394 | #endif | ||
395 | if (i > 0) | ||
396 | return; | ||
397 | #ifdef REF_CHECK | ||
398 | if (i < 0) | ||
399 | { | ||
400 | fprintf(stderr,"ssl_sess_cert_free, bad reference count\n"); | ||
401 | abort(); /* ok */ | ||
402 | } | ||
403 | #endif | ||
404 | |||
405 | /* i == 0 */ | ||
406 | if (sc->cert_chain != NULL) | ||
407 | sk_X509_pop_free(sc->cert_chain, X509_free); | ||
408 | for (i = 0; i < SSL_PKEY_NUM; i++) | ||
409 | { | ||
410 | if (sc->peer_pkeys[i].x509 != NULL) | ||
411 | X509_free(sc->peer_pkeys[i].x509); | ||
412 | #if 0 /* We don't have the peer's private key. These lines are just | ||
413 | * here as a reminder that we're still using a not-quite-appropriate | ||
414 | * data structure. */ | ||
415 | if (sc->peer_pkeys[i].privatekey != NULL) | ||
416 | EVP_PKEY_free(sc->peer_pkeys[i].privatekey); | ||
417 | #endif | ||
418 | } | ||
419 | |||
420 | #ifndef NO_RSA | ||
421 | if (sc->peer_rsa_tmp != NULL) | ||
422 | RSA_free(sc->peer_rsa_tmp); | ||
423 | #endif | ||
424 | #ifndef NO_DH | ||
425 | if (sc->peer_dh_tmp != NULL) | ||
426 | DH_free(sc->peer_dh_tmp); | ||
427 | #endif | ||
428 | |||
429 | Free(sc); | ||
430 | } | ||
431 | |||
432 | int ssl_set_peer_cert_type(SESS_CERT *sc,int type) | ||
433 | { | ||
434 | sc->peer_cert_type = type; | ||
435 | return(1); | ||
436 | } | ||
437 | |||
438 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk) | ||
439 | { | ||
440 | X509 *x; | ||
441 | int i; | ||
442 | X509_STORE_CTX ctx; | ||
443 | |||
444 | if ((sk == NULL) || (sk_X509_num(sk) == 0)) | ||
445 | return(0); | ||
446 | |||
447 | x=sk_X509_value(sk,0); | ||
448 | X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk); | ||
449 | if (SSL_get_verify_depth(s) >= 0) | ||
450 | X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s)); | ||
451 | X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s); | ||
452 | /* We need to set the verify purpose. The purpose can be determined by | ||
453 | * the context: if its a server it will verify SSL client certificates | ||
454 | * or vice versa. | ||
455 | */ | ||
456 | |||
457 | if(s->server) i = X509_PURPOSE_SSL_CLIENT; | ||
458 | else i = X509_PURPOSE_SSL_SERVER; | ||
459 | |||
460 | X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust); | ||
461 | |||
462 | if (s->ctx->app_verify_callback != NULL) | ||
463 | i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */ | ||
464 | else | ||
465 | { | ||
466 | #ifndef NO_X509_VERIFY | ||
467 | i=X509_verify_cert(&ctx); | ||
468 | #else | ||
469 | i=0; | ||
470 | ctx.error=X509_V_ERR_APPLICATION_VERIFICATION; | ||
471 | SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK); | ||
472 | #endif | ||
473 | } | ||
474 | |||
475 | s->verify_result=ctx.error; | ||
476 | X509_STORE_CTX_cleanup(&ctx); | ||
477 | |||
478 | return(i); | ||
479 | } | ||
480 | |||
481 | static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *list) | ||
482 | { | ||
483 | if (*ca_list != NULL) | ||
484 | sk_X509_NAME_pop_free(*ca_list,X509_NAME_free); | ||
485 | |||
486 | *ca_list=list; | ||
487 | } | ||
488 | |||
489 | STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk) | ||
490 | { | ||
491 | int i; | ||
492 | STACK_OF(X509_NAME) *ret; | ||
493 | X509_NAME *name; | ||
494 | |||
495 | ret=sk_X509_NAME_new_null(); | ||
496 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
497 | { | ||
498 | name=X509_NAME_dup(sk_X509_NAME_value(sk,i)); | ||
499 | if ((name == NULL) || !sk_X509_NAME_push(ret,name)) | ||
500 | { | ||
501 | sk_X509_NAME_pop_free(ret,X509_NAME_free); | ||
502 | return(NULL); | ||
503 | } | ||
504 | } | ||
505 | return(ret); | ||
506 | } | ||
507 | |||
508 | void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list) | ||
509 | { | ||
510 | set_client_CA_list(&(s->client_CA),list); | ||
511 | } | ||
512 | |||
513 | void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *list) | ||
514 | { | ||
515 | set_client_CA_list(&(ctx->client_CA),list); | ||
516 | } | ||
517 | |||
518 | STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx) | ||
519 | { | ||
520 | return(ctx->client_CA); | ||
521 | } | ||
522 | |||
523 | STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s) | ||
524 | { | ||
525 | if (s->type == SSL_ST_CONNECT) | ||
526 | { /* we are in the client */ | ||
527 | if (((s->version>>8) == SSL3_VERSION_MAJOR) && | ||
528 | (s->s3 != NULL)) | ||
529 | return(s->s3->tmp.ca_names); | ||
530 | else | ||
531 | return(NULL); | ||
532 | } | ||
533 | else | ||
534 | { | ||
535 | if (s->client_CA != NULL) | ||
536 | return(s->client_CA); | ||
537 | else | ||
538 | return(s->ctx->client_CA); | ||
539 | } | ||
540 | } | ||
541 | |||
542 | static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x) | ||
543 | { | ||
544 | X509_NAME *name; | ||
545 | |||
546 | if (x == NULL) return(0); | ||
547 | if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL)) | ||
548 | return(0); | ||
549 | |||
550 | if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL) | ||
551 | return(0); | ||
552 | |||
553 | if (!sk_X509_NAME_push(*sk,name)) | ||
554 | { | ||
555 | X509_NAME_free(name); | ||
556 | return(0); | ||
557 | } | ||
558 | return(1); | ||
559 | } | ||
560 | |||
561 | int SSL_add_client_CA(SSL *ssl,X509 *x) | ||
562 | { | ||
563 | return(add_client_CA(&(ssl->client_CA),x)); | ||
564 | } | ||
565 | |||
566 | int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x) | ||
567 | { | ||
568 | return(add_client_CA(&(ctx->client_CA),x)); | ||
569 | } | ||
570 | |||
571 | static int xname_cmp(X509_NAME **a,X509_NAME **b) | ||
572 | { | ||
573 | return(X509_NAME_cmp(*a,*b)); | ||
574 | } | ||
575 | |||
576 | #ifndef NO_STDIO | ||
577 | /*! | ||
578 | * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed; | ||
579 | * it doesn't really have anything to do with clients (except that a common use | ||
580 | * for a stack of CAs is to send it to the client). Actually, it doesn't have | ||
581 | * much to do with CAs, either, since it will load any old cert. | ||
582 | * \param file the file containing one or more certs. | ||
583 | * \return a ::STACK containing the certs. | ||
584 | */ | ||
585 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) | ||
586 | { | ||
587 | BIO *in; | ||
588 | X509 *x=NULL; | ||
589 | X509_NAME *xn=NULL; | ||
590 | STACK_OF(X509_NAME) *ret,*sk; | ||
591 | |||
592 | ret=sk_X509_NAME_new(NULL); | ||
593 | sk=sk_X509_NAME_new(xname_cmp); | ||
594 | |||
595 | in=BIO_new(BIO_s_file_internal()); | ||
596 | |||
597 | if ((ret == NULL) || (sk == NULL) || (in == NULL)) | ||
598 | { | ||
599 | SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE); | ||
600 | goto err; | ||
601 | } | ||
602 | |||
603 | if (!BIO_read_filename(in,file)) | ||
604 | goto err; | ||
605 | |||
606 | for (;;) | ||
607 | { | ||
608 | if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL) | ||
609 | break; | ||
610 | if ((xn=X509_get_subject_name(x)) == NULL) goto err; | ||
611 | /* check for duplicates */ | ||
612 | xn=X509_NAME_dup(xn); | ||
613 | if (xn == NULL) goto err; | ||
614 | if (sk_X509_NAME_find(sk,xn) >= 0) | ||
615 | X509_NAME_free(xn); | ||
616 | else | ||
617 | { | ||
618 | sk_X509_NAME_push(sk,xn); | ||
619 | sk_X509_NAME_push(ret,xn); | ||
620 | } | ||
621 | } | ||
622 | |||
623 | if (0) | ||
624 | { | ||
625 | err: | ||
626 | if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free); | ||
627 | ret=NULL; | ||
628 | } | ||
629 | if (sk != NULL) sk_X509_NAME_free(sk); | ||
630 | if (in != NULL) BIO_free(in); | ||
631 | if (x != NULL) X509_free(x); | ||
632 | return(ret); | ||
633 | } | ||
634 | #endif | ||
635 | |||
636 | /*! | ||
637 | * Add a file of certs to a stack. | ||
638 | * \param stack the stack to add to. | ||
639 | * \param file the file to add from. All certs in this file that are not | ||
640 | * already in the stack will be added. | ||
641 | * \return 1 for success, 0 for failure. Note that in the case of failure some | ||
642 | * certs may have been added to \c stack. | ||
643 | */ | ||
644 | |||
645 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
646 | const char *file) | ||
647 | { | ||
648 | BIO *in; | ||
649 | X509 *x=NULL; | ||
650 | X509_NAME *xn=NULL; | ||
651 | int ret=1; | ||
652 | int (*oldcmp)(X509_NAME **a, X509_NAME **b); | ||
653 | |||
654 | oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp); | ||
655 | |||
656 | in=BIO_new(BIO_s_file_internal()); | ||
657 | |||
658 | if (in == NULL) | ||
659 | { | ||
660 | SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE); | ||
661 | goto err; | ||
662 | } | ||
663 | |||
664 | if (!BIO_read_filename(in,file)) | ||
665 | goto err; | ||
666 | |||
667 | for (;;) | ||
668 | { | ||
669 | if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL) | ||
670 | break; | ||
671 | if ((xn=X509_get_subject_name(x)) == NULL) goto err; | ||
672 | xn=X509_NAME_dup(xn); | ||
673 | if (xn == NULL) goto err; | ||
674 | if (sk_X509_NAME_find(stack,xn) >= 0) | ||
675 | X509_NAME_free(xn); | ||
676 | else | ||
677 | sk_X509_NAME_push(stack,xn); | ||
678 | } | ||
679 | |||
680 | if (0) | ||
681 | { | ||
682 | err: | ||
683 | ret=0; | ||
684 | } | ||
685 | if(in != NULL) | ||
686 | BIO_free(in); | ||
687 | if(x != NULL) | ||
688 | X509_free(x); | ||
689 | |||
690 | sk_X509_NAME_set_cmp_func(stack,oldcmp); | ||
691 | |||
692 | return ret; | ||
693 | } | ||
694 | |||
695 | /*! | ||
696 | * Add a directory of certs to a stack. | ||
697 | * \param stack the stack to append to. | ||
698 | * \param dir the directory to append from. All files in this directory will be | ||
699 | * examined as potential certs. Any that are acceptable to | ||
700 | * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be | ||
701 | * included. | ||
702 | * \return 1 for success, 0 for failure. Note that in the case of failure some | ||
703 | * certs may have been added to \c stack. | ||
704 | */ | ||
705 | |||
706 | #ifndef WIN32 | ||
707 | #ifndef VMS /* XXXX This may be fixed in the future */ | ||
708 | #ifndef MAC_OS_pre_X | ||
709 | |||
710 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | ||
711 | const char *dir) | ||
712 | { | ||
713 | DIR *d; | ||
714 | struct dirent *dstruct; | ||
715 | int ret = 0; | ||
716 | |||
717 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | ||
718 | d = opendir(dir); | ||
719 | |||
720 | /* Note that a side effect is that the CAs will be sorted by name */ | ||
721 | if(!d) | ||
722 | { | ||
723 | SYSerr(SYS_F_OPENDIR, get_last_sys_error()); | ||
724 | ERR_add_error_data(3, "opendir('", dir, "')"); | ||
725 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); | ||
726 | goto err; | ||
727 | } | ||
728 | |||
729 | while((dstruct=readdir(d))) | ||
730 | { | ||
731 | char buf[1024]; | ||
732 | |||
733 | if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf) | ||
734 | { | ||
735 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | ||
736 | goto err; | ||
737 | } | ||
738 | |||
739 | sprintf(buf,"%s/%s",dir,dstruct->d_name); | ||
740 | if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) | ||
741 | goto err; | ||
742 | } | ||
743 | ret = 1; | ||
744 | |||
745 | err: | ||
746 | closedir(d); | ||
747 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | ||
748 | return ret; | ||
749 | } | ||
750 | |||
751 | #endif | ||
752 | #endif | ||
753 | #endif | ||
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c deleted file mode 100644 index 7436a50ad1..0000000000 --- a/src/lib/libssl/ssl_ciph.c +++ /dev/null | |||
@@ -1,1069 +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 "ssl_locl.h" | ||
63 | |||
64 | #define SSL_ENC_DES_IDX 0 | ||
65 | #define SSL_ENC_3DES_IDX 1 | ||
66 | #define SSL_ENC_RC4_IDX 2 | ||
67 | #define SSL_ENC_RC2_IDX 3 | ||
68 | #define SSL_ENC_IDEA_IDX 4 | ||
69 | #define SSL_ENC_eFZA_IDX 5 | ||
70 | #define SSL_ENC_NULL_IDX 6 | ||
71 | #define SSL_ENC_NUM_IDX 7 | ||
72 | |||
73 | static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={ | ||
74 | NULL,NULL,NULL,NULL,NULL,NULL, | ||
75 | }; | ||
76 | |||
77 | static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL; | ||
78 | |||
79 | #define SSL_MD_MD5_IDX 0 | ||
80 | #define SSL_MD_SHA1_IDX 1 | ||
81 | #define SSL_MD_NUM_IDX 2 | ||
82 | static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={ | ||
83 | NULL,NULL, | ||
84 | }; | ||
85 | |||
86 | #define CIPHER_ADD 1 | ||
87 | #define CIPHER_KILL 2 | ||
88 | #define CIPHER_DEL 3 | ||
89 | #define CIPHER_ORD 4 | ||
90 | #define CIPHER_SPECIAL 5 | ||
91 | |||
92 | typedef struct cipher_order_st | ||
93 | { | ||
94 | SSL_CIPHER *cipher; | ||
95 | int active; | ||
96 | int dead; | ||
97 | struct cipher_order_st *next,*prev; | ||
98 | } CIPHER_ORDER; | ||
99 | |||
100 | static const SSL_CIPHER cipher_aliases[]={ | ||
101 | /* Don't include eNULL unless specifically enabled */ | ||
102 | {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */ | ||
103 | {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
104 | {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
105 | {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
106 | {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
107 | {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
108 | {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0}, | ||
109 | {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0}, | ||
110 | |||
111 | {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
112 | {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
113 | {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
114 | {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0}, | ||
115 | {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
116 | {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0}, | ||
117 | |||
118 | {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0}, | ||
119 | {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0}, | ||
120 | {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0}, | ||
121 | {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0}, | ||
122 | {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0}, | ||
123 | {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, | ||
124 | {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0}, | ||
125 | |||
126 | {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0}, | ||
127 | {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0}, | ||
128 | {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0}, | ||
129 | |||
130 | {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0}, | ||
131 | {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0}, | ||
132 | {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0}, | ||
133 | {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0}, | ||
134 | |||
135 | {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0}, | ||
136 | {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0}, | ||
137 | {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0}, | ||
138 | |||
139 | {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK}, | ||
140 | {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK}, | ||
141 | {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK}, | ||
142 | {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK}, | ||
143 | {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK}, | ||
144 | {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK}, | ||
145 | {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK}, | ||
146 | }; | ||
147 | |||
148 | static int init_ciphers=1; | ||
149 | |||
150 | static void load_ciphers(void) | ||
151 | { | ||
152 | init_ciphers=0; | ||
153 | ssl_cipher_methods[SSL_ENC_DES_IDX]= | ||
154 | EVP_get_cipherbyname(SN_des_cbc); | ||
155 | ssl_cipher_methods[SSL_ENC_3DES_IDX]= | ||
156 | EVP_get_cipherbyname(SN_des_ede3_cbc); | ||
157 | ssl_cipher_methods[SSL_ENC_RC4_IDX]= | ||
158 | EVP_get_cipherbyname(SN_rc4); | ||
159 | ssl_cipher_methods[SSL_ENC_RC2_IDX]= | ||
160 | EVP_get_cipherbyname(SN_rc2_cbc); | ||
161 | ssl_cipher_methods[SSL_ENC_IDEA_IDX]= | ||
162 | EVP_get_cipherbyname(SN_idea_cbc); | ||
163 | |||
164 | ssl_digest_methods[SSL_MD_MD5_IDX]= | ||
165 | EVP_get_digestbyname(SN_md5); | ||
166 | ssl_digest_methods[SSL_MD_SHA1_IDX]= | ||
167 | EVP_get_digestbyname(SN_sha1); | ||
168 | } | ||
169 | |||
170 | int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc, | ||
171 | const EVP_MD **md, SSL_COMP **comp) | ||
172 | { | ||
173 | int i; | ||
174 | SSL_CIPHER *c; | ||
175 | |||
176 | c=s->cipher; | ||
177 | if (c == NULL) return(0); | ||
178 | if (comp != NULL) | ||
179 | { | ||
180 | SSL_COMP ctmp; | ||
181 | |||
182 | if (s->compress_meth == 0) | ||
183 | *comp=NULL; | ||
184 | else if (ssl_comp_methods == NULL) | ||
185 | { | ||
186 | /* bad */ | ||
187 | *comp=NULL; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | |||
192 | ctmp.id=s->compress_meth; | ||
193 | i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp); | ||
194 | if (i >= 0) | ||
195 | *comp=sk_SSL_COMP_value(ssl_comp_methods,i); | ||
196 | else | ||
197 | *comp=NULL; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | if ((enc == NULL) || (md == NULL)) return(0); | ||
202 | |||
203 | switch (c->algorithms & SSL_ENC_MASK) | ||
204 | { | ||
205 | case SSL_DES: | ||
206 | i=SSL_ENC_DES_IDX; | ||
207 | break; | ||
208 | case SSL_3DES: | ||
209 | i=SSL_ENC_3DES_IDX; | ||
210 | break; | ||
211 | case SSL_RC4: | ||
212 | i=SSL_ENC_RC4_IDX; | ||
213 | break; | ||
214 | case SSL_RC2: | ||
215 | i=SSL_ENC_RC2_IDX; | ||
216 | break; | ||
217 | case SSL_IDEA: | ||
218 | i=SSL_ENC_IDEA_IDX; | ||
219 | break; | ||
220 | case SSL_eNULL: | ||
221 | i=SSL_ENC_NULL_IDX; | ||
222 | break; | ||
223 | default: | ||
224 | i= -1; | ||
225 | break; | ||
226 | } | ||
227 | |||
228 | if ((i < 0) || (i > SSL_ENC_NUM_IDX)) | ||
229 | *enc=NULL; | ||
230 | else | ||
231 | { | ||
232 | if (i == SSL_ENC_NULL_IDX) | ||
233 | *enc=EVP_enc_null(); | ||
234 | else | ||
235 | *enc=ssl_cipher_methods[i]; | ||
236 | } | ||
237 | |||
238 | switch (c->algorithms & SSL_MAC_MASK) | ||
239 | { | ||
240 | case SSL_MD5: | ||
241 | i=SSL_MD_MD5_IDX; | ||
242 | break; | ||
243 | case SSL_SHA1: | ||
244 | i=SSL_MD_SHA1_IDX; | ||
245 | break; | ||
246 | default: | ||
247 | i= -1; | ||
248 | break; | ||
249 | } | ||
250 | if ((i < 0) || (i > SSL_MD_NUM_IDX)) | ||
251 | *md=NULL; | ||
252 | else | ||
253 | *md=ssl_digest_methods[i]; | ||
254 | |||
255 | if ((*enc != NULL) && (*md != NULL)) | ||
256 | return(1); | ||
257 | else | ||
258 | return(0); | ||
259 | } | ||
260 | |||
261 | #define ITEM_SEP(a) \ | ||
262 | (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ',')) | ||
263 | |||
264 | static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr, | ||
265 | CIPHER_ORDER **tail) | ||
266 | { | ||
267 | if (curr == *tail) return; | ||
268 | if (curr == *head) | ||
269 | *head=curr->next; | ||
270 | if (curr->prev != NULL) | ||
271 | curr->prev->next=curr->next; | ||
272 | if (curr->next != NULL) /* should always be true */ | ||
273 | curr->next->prev=curr->prev; | ||
274 | (*tail)->next=curr; | ||
275 | curr->prev= *tail; | ||
276 | curr->next=NULL; | ||
277 | *tail=curr; | ||
278 | } | ||
279 | |||
280 | static unsigned long ssl_cipher_get_disabled(void) | ||
281 | { | ||
282 | unsigned long mask; | ||
283 | |||
284 | mask = SSL_kFZA; | ||
285 | #ifdef NO_RSA | ||
286 | mask |= SSL_aRSA|SSL_kRSA; | ||
287 | #endif | ||
288 | #ifdef NO_DSA | ||
289 | mask |= SSL_aDSS; | ||
290 | #endif | ||
291 | #ifdef NO_DH | ||
292 | mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH; | ||
293 | #endif | ||
294 | |||
295 | #ifdef SSL_FORBID_ENULL | ||
296 | mask |= SSL_eNULL; | ||
297 | #endif | ||
298 | |||
299 | mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0; | ||
300 | mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0; | ||
301 | mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0; | ||
302 | mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0; | ||
303 | mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0; | ||
304 | mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0; | ||
305 | |||
306 | mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0; | ||
307 | mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0; | ||
308 | |||
309 | return(mask); | ||
310 | } | ||
311 | |||
312 | static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, | ||
313 | int num_of_ciphers, unsigned long mask, CIPHER_ORDER *list, | ||
314 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | ||
315 | { | ||
316 | int i, list_num; | ||
317 | SSL_CIPHER *c; | ||
318 | |||
319 | /* | ||
320 | * We have num_of_ciphers descriptions compiled in, depending on the | ||
321 | * method selected (SSLv2 and/or SSLv3, TLSv1 etc). | ||
322 | * These will later be sorted in a linked list with at most num | ||
323 | * entries. | ||
324 | */ | ||
325 | |||
326 | /* Get the initial list of ciphers */ | ||
327 | list_num = 0; /* actual count of ciphers */ | ||
328 | for (i = 0; i < num_of_ciphers; i++) | ||
329 | { | ||
330 | c = ssl_method->get_cipher(i); | ||
331 | /* drop those that use any of that is not available */ | ||
332 | if ((c != NULL) && c->valid && !(c->algorithms & mask)) | ||
333 | { | ||
334 | list[list_num].cipher = c; | ||
335 | list[list_num].next = NULL; | ||
336 | list[list_num].prev = NULL; | ||
337 | list[list_num].active = 0; | ||
338 | list_num++; | ||
339 | /* | ||
340 | if (!sk_push(ca_list,(char *)c)) goto err; | ||
341 | */ | ||
342 | } | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * Prepare linked list from list entries | ||
347 | */ | ||
348 | for (i = 1; i < list_num - 1; i++) | ||
349 | { | ||
350 | list[i].prev = &(list[i-1]); | ||
351 | list[i].next = &(list[i+1]); | ||
352 | } | ||
353 | if (list_num > 0) | ||
354 | { | ||
355 | (*head_p) = &(list[0]); | ||
356 | (*head_p)->prev = NULL; | ||
357 | (*head_p)->next = &(list[1]); | ||
358 | (*tail_p) = &(list[list_num - 1]); | ||
359 | (*tail_p)->prev = &(list[list_num - 2]); | ||
360 | (*tail_p)->next = NULL; | ||
361 | } | ||
362 | } | ||
363 | |||
364 | static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list, | ||
365 | int num_of_group_aliases, unsigned long mask, | ||
366 | CIPHER_ORDER *head) | ||
367 | { | ||
368 | CIPHER_ORDER *ciph_curr; | ||
369 | SSL_CIPHER **ca_curr; | ||
370 | int i; | ||
371 | |||
372 | /* | ||
373 | * First, add the real ciphers as already collected | ||
374 | */ | ||
375 | ciph_curr = head; | ||
376 | ca_curr = ca_list; | ||
377 | while (ciph_curr != NULL) | ||
378 | { | ||
379 | *ca_curr = ciph_curr->cipher; | ||
380 | ca_curr++; | ||
381 | ciph_curr = ciph_curr->next; | ||
382 | } | ||
383 | |||
384 | /* | ||
385 | * Now we add the available ones from the cipher_aliases[] table. | ||
386 | * They represent either an algorithm, that must be fully | ||
387 | * supported (not match any bit in mask) or represent a cipher | ||
388 | * strength value (will be added in any case because algorithms=0). | ||
389 | */ | ||
390 | for (i = 0; i < num_of_group_aliases; i++) | ||
391 | { | ||
392 | if ((i == 0) || /* always fetch "ALL" */ | ||
393 | !(cipher_aliases[i].algorithms & mask)) | ||
394 | { | ||
395 | *ca_curr = (SSL_CIPHER *)(cipher_aliases + i); | ||
396 | ca_curr++; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | *ca_curr = NULL; /* end of list */ | ||
401 | } | ||
402 | |||
403 | static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask, | ||
404 | unsigned long algo_strength, unsigned long mask_strength, | ||
405 | int rule, int strength_bits, CIPHER_ORDER *list, | ||
406 | CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p) | ||
407 | { | ||
408 | CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2; | ||
409 | SSL_CIPHER *cp; | ||
410 | unsigned long ma, ma_s; | ||
411 | |||
412 | #ifdef CIPHER_DEBUG | ||
413 | printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n", | ||
414 | rule, algorithms, mask, algo_strength, mask_strength, | ||
415 | strength_bits); | ||
416 | #endif | ||
417 | |||
418 | curr = head = *head_p; | ||
419 | curr2 = head; | ||
420 | tail2 = tail = *tail_p; | ||
421 | for (;;) | ||
422 | { | ||
423 | if ((curr == NULL) || (curr == tail2)) break; | ||
424 | curr = curr2; | ||
425 | curr2 = curr->next; | ||
426 | |||
427 | cp = curr->cipher; | ||
428 | |||
429 | /* | ||
430 | * Selection criteria is either the number of strength_bits | ||
431 | * or the algorithm used. | ||
432 | */ | ||
433 | if (strength_bits == -1) | ||
434 | { | ||
435 | ma = mask & cp->algorithms; | ||
436 | ma_s = mask_strength & cp->algo_strength; | ||
437 | |||
438 | #ifdef CIPHER_DEBUG | ||
439 | printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength); | ||
440 | printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength); | ||
441 | #endif | ||
442 | /* | ||
443 | * Select: if none of the mask bit was met from the | ||
444 | * cipher or not all of the bits were met, the | ||
445 | * selection does not apply. | ||
446 | */ | ||
447 | if (((ma == 0) && (ma_s == 0)) || | ||
448 | ((ma & algorithms) != ma) || | ||
449 | ((ma_s & algo_strength) != ma_s)) | ||
450 | continue; /* does not apply */ | ||
451 | } | ||
452 | else if (strength_bits != cp->strength_bits) | ||
453 | continue; /* does not apply */ | ||
454 | |||
455 | #ifdef CIPHER_DEBUG | ||
456 | printf("Action = %d\n", rule); | ||
457 | #endif | ||
458 | |||
459 | /* add the cipher if it has not been added yet. */ | ||
460 | if (rule == CIPHER_ADD) | ||
461 | { | ||
462 | if (!curr->active) | ||
463 | { | ||
464 | ll_append_tail(&head, curr, &tail); | ||
465 | curr->active = 1; | ||
466 | } | ||
467 | } | ||
468 | /* Move the added cipher to this location */ | ||
469 | else if (rule == CIPHER_ORD) | ||
470 | { | ||
471 | if (curr->active) | ||
472 | { | ||
473 | ll_append_tail(&head, curr, &tail); | ||
474 | } | ||
475 | } | ||
476 | else if (rule == CIPHER_DEL) | ||
477 | curr->active = 0; | ||
478 | else if (rule == CIPHER_KILL) | ||
479 | { | ||
480 | if (head == curr) | ||
481 | head = curr->next; | ||
482 | else | ||
483 | curr->prev->next = curr->next; | ||
484 | if (tail == curr) | ||
485 | tail = curr->prev; | ||
486 | curr->active = 0; | ||
487 | if (curr->next != NULL) | ||
488 | curr->next->prev = curr->prev; | ||
489 | if (curr->prev != NULL) | ||
490 | curr->prev->next = curr->next; | ||
491 | curr->next = NULL; | ||
492 | curr->prev = NULL; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | *head_p = head; | ||
497 | *tail_p = tail; | ||
498 | } | ||
499 | |||
500 | static int ssl_cipher_strength_sort(CIPHER_ORDER *list, CIPHER_ORDER **head_p, | ||
501 | CIPHER_ORDER **tail_p) | ||
502 | { | ||
503 | int max_strength_bits, i, *number_uses; | ||
504 | CIPHER_ORDER *curr; | ||
505 | |||
506 | /* | ||
507 | * This routine sorts the ciphers with descending strength. The sorting | ||
508 | * must keep the pre-sorted sequence, so we apply the normal sorting | ||
509 | * routine as '+' movement to the end of the list. | ||
510 | */ | ||
511 | max_strength_bits = 0; | ||
512 | curr = *head_p; | ||
513 | while (curr != NULL) | ||
514 | { | ||
515 | if (curr->active && | ||
516 | (curr->cipher->strength_bits > max_strength_bits)) | ||
517 | max_strength_bits = curr->cipher->strength_bits; | ||
518 | curr = curr->next; | ||
519 | } | ||
520 | |||
521 | number_uses = Malloc((max_strength_bits + 1) * sizeof(int)); | ||
522 | if (!number_uses) | ||
523 | { | ||
524 | SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE); | ||
525 | return(0); | ||
526 | } | ||
527 | memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int)); | ||
528 | |||
529 | /* | ||
530 | * Now find the strength_bits values actually used | ||
531 | */ | ||
532 | curr = *head_p; | ||
533 | while (curr != NULL) | ||
534 | { | ||
535 | if (curr->active) | ||
536 | number_uses[curr->cipher->strength_bits]++; | ||
537 | curr = curr->next; | ||
538 | } | ||
539 | /* | ||
540 | * Go through the list of used strength_bits values in descending | ||
541 | * order. | ||
542 | */ | ||
543 | for (i = max_strength_bits; i >= 0; i--) | ||
544 | if (number_uses[i] > 0) | ||
545 | ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i, | ||
546 | list, head_p, tail_p); | ||
547 | |||
548 | Free(number_uses); | ||
549 | return(1); | ||
550 | } | ||
551 | |||
552 | static int ssl_cipher_process_rulestr(const char *rule_str, | ||
553 | CIPHER_ORDER *list, CIPHER_ORDER **head_p, | ||
554 | CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list) | ||
555 | { | ||
556 | unsigned long algorithms, mask, algo_strength, mask_strength; | ||
557 | const char *l, *start, *buf; | ||
558 | int j, multi, found, rule, retval, ok, buflen; | ||
559 | char ch; | ||
560 | |||
561 | retval = 1; | ||
562 | l = rule_str; | ||
563 | for (;;) | ||
564 | { | ||
565 | ch = *l; | ||
566 | |||
567 | if (ch == '\0') | ||
568 | break; /* done */ | ||
569 | if (ch == '-') | ||
570 | { rule = CIPHER_DEL; l++; } | ||
571 | else if (ch == '+') | ||
572 | { rule = CIPHER_ORD; l++; } | ||
573 | else if (ch == '!') | ||
574 | { rule = CIPHER_KILL; l++; } | ||
575 | else if (ch == '@') | ||
576 | { rule = CIPHER_SPECIAL; l++; } | ||
577 | else | ||
578 | { rule = CIPHER_ADD; } | ||
579 | |||
580 | if (ITEM_SEP(ch)) | ||
581 | { | ||
582 | l++; | ||
583 | continue; | ||
584 | } | ||
585 | |||
586 | algorithms = mask = algo_strength = mask_strength = 0; | ||
587 | |||
588 | start=l; | ||
589 | for (;;) | ||
590 | { | ||
591 | ch = *l; | ||
592 | buf = l; | ||
593 | buflen = 0; | ||
594 | #ifndef CHARSET_EBCDIC | ||
595 | while ( ((ch >= 'A') && (ch <= 'Z')) || | ||
596 | ((ch >= '0') && (ch <= '9')) || | ||
597 | ((ch >= 'a') && (ch <= 'z')) || | ||
598 | (ch == '-')) | ||
599 | #else | ||
600 | while ( isalnum(ch) || (ch == '-')) | ||
601 | #endif | ||
602 | { | ||
603 | ch = *(++l); | ||
604 | buflen++; | ||
605 | } | ||
606 | |||
607 | if (buflen == 0) | ||
608 | { | ||
609 | /* | ||
610 | * We hit something we cannot deal with, | ||
611 | * it is no command or separator nor | ||
612 | * alphanumeric, so we call this an error. | ||
613 | */ | ||
614 | SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, | ||
615 | SSL_R_INVALID_COMMAND); | ||
616 | retval = found = 0; | ||
617 | l++; | ||
618 | break; | ||
619 | } | ||
620 | |||
621 | if (rule == CIPHER_SPECIAL) | ||
622 | { | ||
623 | found = 0; /* unused -- avoid compiler warning */ | ||
624 | break; /* special treatment */ | ||
625 | } | ||
626 | |||
627 | /* check for multi-part specification */ | ||
628 | if (ch == '+') | ||
629 | { | ||
630 | multi=1; | ||
631 | l++; | ||
632 | } | ||
633 | else | ||
634 | multi=0; | ||
635 | |||
636 | /* | ||
637 | * Now search for the cipher alias in the ca_list. Be careful | ||
638 | * with the strncmp, because the "buflen" limitation | ||
639 | * will make the rule "ADH:SOME" and the cipher | ||
640 | * "ADH-MY-CIPHER" look like a match for buflen=3. | ||
641 | * So additionally check whether the cipher name found | ||
642 | * has the correct length. We can save a strlen() call: | ||
643 | * just checking for the '\0' at the right place is | ||
644 | * sufficient, we have to strncmp() anyway. | ||
645 | */ | ||
646 | j = found = 0; | ||
647 | while (ca_list[j]) | ||
648 | { | ||
649 | if ((ca_list[j]->name[buflen] == '\0') && | ||
650 | !strncmp(buf, ca_list[j]->name, buflen)) | ||
651 | { | ||
652 | found = 1; | ||
653 | break; | ||
654 | } | ||
655 | else | ||
656 | j++; | ||
657 | } | ||
658 | if (!found) | ||
659 | break; /* ignore this entry */ | ||
660 | |||
661 | algorithms |= ca_list[j]->algorithms; | ||
662 | mask |= ca_list[j]->mask; | ||
663 | algo_strength |= ca_list[j]->algo_strength; | ||
664 | mask_strength |= ca_list[j]->mask_strength; | ||
665 | |||
666 | if (!multi) break; | ||
667 | } | ||
668 | |||
669 | /* | ||
670 | * Ok, we have the rule, now apply it | ||
671 | */ | ||
672 | if (rule == CIPHER_SPECIAL) | ||
673 | { /* special command */ | ||
674 | ok = 0; | ||
675 | if ((buflen == 8) && | ||
676 | !strncmp(buf, "STRENGTH", 8)) | ||
677 | ok = ssl_cipher_strength_sort(list, | ||
678 | head_p, tail_p); | ||
679 | else | ||
680 | SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, | ||
681 | SSL_R_INVALID_COMMAND); | ||
682 | if (ok == 0) | ||
683 | retval = 0; | ||
684 | /* | ||
685 | * We do not support any "multi" options | ||
686 | * together with "@", so throw away the | ||
687 | * rest of the command, if any left, until | ||
688 | * end or ':' is found. | ||
689 | */ | ||
690 | while ((*l != '\0') && ITEM_SEP(*l)) | ||
691 | l++; | ||
692 | } | ||
693 | else if (found) | ||
694 | { | ||
695 | ssl_cipher_apply_rule(algorithms, mask, | ||
696 | algo_strength, mask_strength, rule, -1, | ||
697 | list, head_p, tail_p); | ||
698 | } | ||
699 | else | ||
700 | { | ||
701 | while ((*l != '\0') && ITEM_SEP(*l)) | ||
702 | l++; | ||
703 | } | ||
704 | if (*l == '\0') break; /* done */ | ||
705 | } | ||
706 | |||
707 | return(retval); | ||
708 | } | ||
709 | |||
710 | STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | ||
711 | STACK_OF(SSL_CIPHER) **cipher_list, | ||
712 | STACK_OF(SSL_CIPHER) **cipher_list_by_id, | ||
713 | const char *rule_str) | ||
714 | { | ||
715 | int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases; | ||
716 | unsigned long disabled_mask; | ||
717 | STACK_OF(SSL_CIPHER) *cipherstack; | ||
718 | const char *rule_p; | ||
719 | CIPHER_ORDER *list = NULL, *head = NULL, *tail = NULL, *curr; | ||
720 | SSL_CIPHER **ca_list = NULL; | ||
721 | |||
722 | /* | ||
723 | * Return with error if nothing to do. | ||
724 | */ | ||
725 | if (rule_str == NULL) return(NULL); | ||
726 | |||
727 | if (init_ciphers) load_ciphers(); | ||
728 | |||
729 | /* | ||
730 | * To reduce the work to do we only want to process the compiled | ||
731 | * in algorithms, so we first get the mask of disabled ciphers. | ||
732 | */ | ||
733 | disabled_mask = ssl_cipher_get_disabled(); | ||
734 | |||
735 | /* | ||
736 | * Now we have to collect the available ciphers from the compiled | ||
737 | * in ciphers. We cannot get more than the number compiled in, so | ||
738 | * it is used for allocation. | ||
739 | */ | ||
740 | num_of_ciphers = ssl_method->num_ciphers(); | ||
741 | list = (CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER) * num_of_ciphers); | ||
742 | if (list == NULL) | ||
743 | { | ||
744 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
745 | return(NULL); /* Failure */ | ||
746 | } | ||
747 | |||
748 | ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask, | ||
749 | list, &head, &tail); | ||
750 | |||
751 | /* | ||
752 | * We also need cipher aliases for selecting based on the rule_str. | ||
753 | * There might be two types of entries in the rule_str: 1) names | ||
754 | * of ciphers themselves 2) aliases for groups of ciphers. | ||
755 | * For 1) we need the available ciphers and for 2) the cipher | ||
756 | * groups of cipher_aliases added together in one list (otherwise | ||
757 | * we would be happy with just the cipher_aliases table). | ||
758 | */ | ||
759 | num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER); | ||
760 | num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1; | ||
761 | ca_list = | ||
762 | (SSL_CIPHER **)Malloc(sizeof(SSL_CIPHER *) * num_of_alias_max); | ||
763 | if (ca_list == NULL) | ||
764 | { | ||
765 | Free(list); | ||
766 | SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
767 | return(NULL); /* Failure */ | ||
768 | } | ||
769 | ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask, | ||
770 | head); | ||
771 | |||
772 | /* | ||
773 | * If the rule_string begins with DEFAULT, apply the default rule | ||
774 | * before using the (possibly available) additional rules. | ||
775 | */ | ||
776 | ok = 1; | ||
777 | rule_p = rule_str; | ||
778 | if (strncmp(rule_str,"DEFAULT",7) == 0) | ||
779 | { | ||
780 | ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST, | ||
781 | list, &head, &tail, ca_list); | ||
782 | rule_p += 7; | ||
783 | if (*rule_p == ':') | ||
784 | rule_p++; | ||
785 | } | ||
786 | |||
787 | if (ok && (strlen(rule_p) > 0)) | ||
788 | ok = ssl_cipher_process_rulestr(rule_p, list, &head, &tail, | ||
789 | ca_list); | ||
790 | |||
791 | Free(ca_list); /* Not needed anymore */ | ||
792 | |||
793 | if (!ok) | ||
794 | { /* Rule processing failure */ | ||
795 | Free(list); | ||
796 | return(NULL); | ||
797 | } | ||
798 | /* | ||
799 | * Allocate new "cipherstack" for the result, return with error | ||
800 | * if we cannot get one. | ||
801 | */ | ||
802 | if ((cipherstack = sk_SSL_CIPHER_new(NULL)) == NULL) | ||
803 | { | ||
804 | Free(list); | ||
805 | return(NULL); | ||
806 | } | ||
807 | |||
808 | /* | ||
809 | * The cipher selection for the list is done. The ciphers are added | ||
810 | * to the resulting precedence to the STACK_OF(SSL_CIPHER). | ||
811 | */ | ||
812 | for (curr = head; curr != NULL; curr = curr->next) | ||
813 | { | ||
814 | if (curr->active) | ||
815 | { | ||
816 | sk_SSL_CIPHER_push(cipherstack, curr->cipher); | ||
817 | #ifdef CIPHER_DEBUG | ||
818 | printf("<%s>\n",curr->cipher->name); | ||
819 | #endif | ||
820 | } | ||
821 | } | ||
822 | Free(list); /* Not needed any longer */ | ||
823 | |||
824 | /* | ||
825 | * The following passage is a little bit odd. If pointer variables | ||
826 | * were supplied to hold STACK_OF(SSL_CIPHER) return information, | ||
827 | * the old memory pointed to is free()ed. Then, however, the | ||
828 | * cipher_list entry will be assigned just a copy of the returned | ||
829 | * cipher stack. For cipher_list_by_id a copy of the cipher stack | ||
830 | * will be created. See next comment... | ||
831 | */ | ||
832 | if (cipher_list != NULL) | ||
833 | { | ||
834 | if (*cipher_list != NULL) | ||
835 | sk_SSL_CIPHER_free(*cipher_list); | ||
836 | *cipher_list = cipherstack; | ||
837 | } | ||
838 | |||
839 | if (cipher_list_by_id != NULL) | ||
840 | { | ||
841 | if (*cipher_list_by_id != NULL) | ||
842 | sk_SSL_CIPHER_free(*cipher_list_by_id); | ||
843 | *cipher_list_by_id = sk_SSL_CIPHER_dup(cipherstack); | ||
844 | } | ||
845 | |||
846 | /* | ||
847 | * Now it is getting really strange. If something failed during | ||
848 | * the previous pointer assignment or if one of the pointers was | ||
849 | * not requested, the error condition is met. That might be | ||
850 | * discussable. The strange thing is however that in this case | ||
851 | * the memory "ret" pointed to is "free()ed" and hence the pointer | ||
852 | * cipher_list becomes wild. The memory reserved for | ||
853 | * cipher_list_by_id however is not "free()ed" and stays intact. | ||
854 | */ | ||
855 | if ( (cipher_list_by_id == NULL) || | ||
856 | (*cipher_list_by_id == NULL) || | ||
857 | (cipher_list == NULL) || | ||
858 | (*cipher_list == NULL)) | ||
859 | { | ||
860 | sk_SSL_CIPHER_free(cipherstack); | ||
861 | return(NULL); | ||
862 | } | ||
863 | |||
864 | sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp); | ||
865 | |||
866 | return(cipherstack); | ||
867 | } | ||
868 | |||
869 | char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len) | ||
870 | { | ||
871 | int is_export,pkl,kl; | ||
872 | char *ver,*exp; | ||
873 | char *kx,*au,*enc,*mac; | ||
874 | unsigned long alg,alg2,alg_s; | ||
875 | static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n"; | ||
876 | |||
877 | alg=cipher->algorithms; | ||
878 | alg_s=cipher->algo_strength; | ||
879 | alg2=cipher->algorithm2; | ||
880 | |||
881 | is_export=SSL_C_IS_EXPORT(cipher); | ||
882 | pkl=SSL_C_EXPORT_PKEYLENGTH(cipher); | ||
883 | kl=SSL_C_EXPORT_KEYLENGTH(cipher); | ||
884 | exp=is_export?" export":""; | ||
885 | |||
886 | if (alg & SSL_SSLV2) | ||
887 | ver="SSLv2"; | ||
888 | else if (alg & SSL_SSLV3) | ||
889 | ver="SSLv3"; | ||
890 | else | ||
891 | ver="unknown"; | ||
892 | |||
893 | switch (alg&SSL_MKEY_MASK) | ||
894 | { | ||
895 | case SSL_kRSA: | ||
896 | kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA"; | ||
897 | break; | ||
898 | case SSL_kDHr: | ||
899 | kx="DH/RSA"; | ||
900 | break; | ||
901 | case SSL_kDHd: | ||
902 | kx="DH/DSS"; | ||
903 | break; | ||
904 | case SSL_kFZA: | ||
905 | kx="Fortezza"; | ||
906 | break; | ||
907 | case SSL_kEDH: | ||
908 | kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH"; | ||
909 | break; | ||
910 | default: | ||
911 | kx="unknown"; | ||
912 | } | ||
913 | |||
914 | switch (alg&SSL_AUTH_MASK) | ||
915 | { | ||
916 | case SSL_aRSA: | ||
917 | au="RSA"; | ||
918 | break; | ||
919 | case SSL_aDSS: | ||
920 | au="DSS"; | ||
921 | break; | ||
922 | case SSL_aDH: | ||
923 | au="DH"; | ||
924 | break; | ||
925 | case SSL_aFZA: | ||
926 | case SSL_aNULL: | ||
927 | au="None"; | ||
928 | break; | ||
929 | default: | ||
930 | au="unknown"; | ||
931 | break; | ||
932 | } | ||
933 | |||
934 | switch (alg&SSL_ENC_MASK) | ||
935 | { | ||
936 | case SSL_DES: | ||
937 | enc=(is_export && kl == 5)?"DES(40)":"DES(56)"; | ||
938 | break; | ||
939 | case SSL_3DES: | ||
940 | enc="3DES(168)"; | ||
941 | break; | ||
942 | case SSL_RC4: | ||
943 | enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)") | ||
944 | :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)"); | ||
945 | break; | ||
946 | case SSL_RC2: | ||
947 | enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)"; | ||
948 | break; | ||
949 | case SSL_IDEA: | ||
950 | enc="IDEA(128)"; | ||
951 | break; | ||
952 | case SSL_eFZA: | ||
953 | enc="Fortezza"; | ||
954 | break; | ||
955 | case SSL_eNULL: | ||
956 | enc="None"; | ||
957 | break; | ||
958 | default: | ||
959 | enc="unknown"; | ||
960 | break; | ||
961 | } | ||
962 | |||
963 | switch (alg&SSL_MAC_MASK) | ||
964 | { | ||
965 | case SSL_MD5: | ||
966 | mac="MD5"; | ||
967 | break; | ||
968 | case SSL_SHA1: | ||
969 | mac="SHA1"; | ||
970 | break; | ||
971 | default: | ||
972 | mac="unknown"; | ||
973 | break; | ||
974 | } | ||
975 | |||
976 | if (buf == NULL) | ||
977 | { | ||
978 | buf=Malloc(128); | ||
979 | if (buf == NULL) return("Malloc Error"); | ||
980 | } | ||
981 | else if (len < 128) | ||
982 | return("Buffer too small"); | ||
983 | |||
984 | sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp); | ||
985 | return(buf); | ||
986 | } | ||
987 | |||
988 | char *SSL_CIPHER_get_version(SSL_CIPHER *c) | ||
989 | { | ||
990 | int i; | ||
991 | |||
992 | if (c == NULL) return("(NONE)"); | ||
993 | i=(int)(c->id>>24L); | ||
994 | if (i == 3) | ||
995 | return("TLSv1/SSLv3"); | ||
996 | else if (i == 2) | ||
997 | return("SSLv2"); | ||
998 | else | ||
999 | return("unknown"); | ||
1000 | } | ||
1001 | |||
1002 | /* return the actual cipher being used */ | ||
1003 | const char *SSL_CIPHER_get_name(SSL_CIPHER *c) | ||
1004 | { | ||
1005 | if (c != NULL) | ||
1006 | return(c->name); | ||
1007 | return("(NONE)"); | ||
1008 | } | ||
1009 | |||
1010 | /* number of bits for symmetric cipher */ | ||
1011 | int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits) | ||
1012 | { | ||
1013 | int ret=0; | ||
1014 | |||
1015 | if (c != NULL) | ||
1016 | { | ||
1017 | if (alg_bits != NULL) *alg_bits = c->alg_bits; | ||
1018 | ret = c->strength_bits; | ||
1019 | } | ||
1020 | return(ret); | ||
1021 | } | ||
1022 | |||
1023 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n) | ||
1024 | { | ||
1025 | SSL_COMP *ctmp; | ||
1026 | int i,nn; | ||
1027 | |||
1028 | if ((n == 0) || (sk == NULL)) return(NULL); | ||
1029 | nn=sk_SSL_COMP_num(sk); | ||
1030 | for (i=0; i<nn; i++) | ||
1031 | { | ||
1032 | ctmp=sk_SSL_COMP_value(sk,i); | ||
1033 | if (ctmp->id == n) | ||
1034 | return(ctmp); | ||
1035 | } | ||
1036 | return(NULL); | ||
1037 | } | ||
1038 | |||
1039 | static int sk_comp_cmp(SSL_COMP **a,SSL_COMP **b) | ||
1040 | { | ||
1041 | return((*a)->id-(*b)->id); | ||
1042 | } | ||
1043 | |||
1044 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void) | ||
1045 | { | ||
1046 | return(ssl_comp_methods); | ||
1047 | } | ||
1048 | |||
1049 | int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) | ||
1050 | { | ||
1051 | SSL_COMP *comp; | ||
1052 | STACK_OF(SSL_COMP) *sk; | ||
1053 | |||
1054 | comp=(SSL_COMP *)Malloc(sizeof(SSL_COMP)); | ||
1055 | comp->id=id; | ||
1056 | comp->method=cm; | ||
1057 | if (ssl_comp_methods == NULL) | ||
1058 | sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp); | ||
1059 | else | ||
1060 | sk=ssl_comp_methods; | ||
1061 | if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp)) | ||
1062 | { | ||
1063 | SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE); | ||
1064 | return(0); | ||
1065 | } | ||
1066 | else | ||
1067 | return(1); | ||
1068 | } | ||
1069 | |||
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c deleted file mode 100644 index 642c3f93e7..0000000000 --- a/src/lib/libssl/ssl_err.c +++ /dev/null | |||
@@ -1,430 +0,0 @@ | |||
1 | /* ssl/ssl_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 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 NO_ERR | ||
67 | static ERR_STRING_DATA SSL_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"}, | ||
70 | {ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"}, | ||
71 | {ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"}, | ||
72 | {ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"}, | ||
73 | {ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"}, | ||
74 | {ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"}, | ||
75 | {ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"}, | ||
76 | {ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"}, | ||
77 | {ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"}, | ||
78 | {ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"}, | ||
79 | {ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"}, | ||
80 | {ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"}, | ||
81 | {ERR_PACK(0,SSL_F_READ_N,0), "READ_N"}, | ||
82 | {ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"}, | ||
83 | {ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"}, | ||
84 | {ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"}, | ||
85 | {ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"}, | ||
86 | {ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"}, | ||
87 | {ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"}, | ||
88 | {ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"}, | ||
89 | {ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"}, | ||
90 | {ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"}, | ||
91 | {ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"}, | ||
92 | {ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"}, | ||
93 | {ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"}, | ||
94 | {ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"}, | ||
95 | {ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"}, | ||
96 | {ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"}, | ||
97 | {ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"}, | ||
98 | {ERR_PACK(0,SSL_F_SSL3_CALLBACK_CTRL,0), "SSL3_CALLBACK_CTRL"}, | ||
99 | {ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"}, | ||
100 | {ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"}, | ||
101 | {ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"}, | ||
102 | {ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"}, | ||
103 | {ERR_PACK(0,SSL_F_SSL3_CTRL,0), "SSL3_CTRL"}, | ||
104 | {ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"}, | ||
105 | {ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"}, | ||
106 | {ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"}, | ||
107 | {ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"}, | ||
108 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"}, | ||
109 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"}, | ||
110 | {ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"}, | ||
111 | {ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"}, | ||
112 | {ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"}, | ||
113 | {ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"}, | ||
114 | {ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"}, | ||
115 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"}, | ||
116 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"}, | ||
117 | {ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"}, | ||
118 | {ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"}, | ||
119 | {ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"}, | ||
120 | {ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"}, | ||
121 | {ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"}, | ||
122 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"}, | ||
123 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"}, | ||
124 | {ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"}, | ||
125 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"}, | ||
126 | {ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"}, | ||
127 | {ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"}, | ||
128 | {ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"}, | ||
129 | {ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"}, | ||
130 | {ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"}, | ||
131 | {ERR_PACK(0,SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,0), "SSL_add_dir_cert_subjects_to_stack"}, | ||
132 | {ERR_PACK(0,SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,0), "SSL_add_file_cert_subjects_to_stack"}, | ||
133 | {ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"}, | ||
134 | {ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"}, | ||
135 | {ERR_PACK(0,SSL_F_SSL_CERT_DUP,0), "SSL_CERT_DUP"}, | ||
136 | {ERR_PACK(0,SSL_F_SSL_CERT_INST,0), "SSL_CERT_INST"}, | ||
137 | {ERR_PACK(0,SSL_F_SSL_CERT_INSTANTIATE,0), "SSL_CERT_INSTANTIATE"}, | ||
138 | {ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"}, | ||
139 | {ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"}, | ||
140 | {ERR_PACK(0,SSL_F_SSL_CIPHER_PROCESS_RULESTR,0), "SSL_CIPHER_PROCESS_RULESTR"}, | ||
141 | {ERR_PACK(0,SSL_F_SSL_CIPHER_STRENGTH_SORT,0), "SSL_CIPHER_STRENGTH_SORT"}, | ||
142 | {ERR_PACK(0,SSL_F_SSL_CLEAR,0), "SSL_clear"}, | ||
143 | {ERR_PACK(0,SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,0), "SSL_COMP_add_compression_method"}, | ||
144 | {ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"}, | ||
145 | {ERR_PACK(0,SSL_F_SSL_CTRL,0), "SSL_ctrl"}, | ||
146 | {ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"}, | ||
147 | {ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"}, | ||
148 | {ERR_PACK(0,SSL_F_SSL_CTX_SET_PURPOSE,0), "SSL_CTX_set_purpose"}, | ||
149 | {ERR_PACK(0,SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,0), "SSL_CTX_set_session_id_context"}, | ||
150 | {ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"}, | ||
151 | {ERR_PACK(0,SSL_F_SSL_CTX_SET_TRUST,0), "SSL_CTX_set_trust"}, | ||
152 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"}, | ||
153 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"}, | ||
154 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,0), "SSL_CTX_use_certificate_chain_file"}, | ||
155 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"}, | ||
156 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"}, | ||
157 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"}, | ||
158 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"}, | ||
159 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"}, | ||
160 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"}, | ||
161 | {ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"}, | ||
162 | {ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"}, | ||
163 | {ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"}, | ||
164 | {ERR_PACK(0,SSL_F_SSL_GET_PREV_SESSION,0), "SSL_GET_PREV_SESSION"}, | ||
165 | {ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"}, | ||
166 | {ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"}, | ||
167 | {ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"}, | ||
168 | {ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"}, | ||
169 | {ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"}, | ||
170 | {ERR_PACK(0,SSL_F_SSL_READ,0), "SSL_read"}, | ||
171 | {ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"}, | ||
172 | {ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"}, | ||
173 | {ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"}, | ||
174 | {ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"}, | ||
175 | {ERR_PACK(0,SSL_F_SSL_SESS_CERT_NEW,0), "SSL_SESS_CERT_NEW"}, | ||
176 | {ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"}, | ||
177 | {ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"}, | ||
178 | {ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"}, | ||
179 | {ERR_PACK(0,SSL_F_SSL_SET_PURPOSE,0), "SSL_set_purpose"}, | ||
180 | {ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"}, | ||
181 | {ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"}, | ||
182 | {ERR_PACK(0,SSL_F_SSL_SET_SESSION_ID_CONTEXT,0), "SSL_set_session_id_context"}, | ||
183 | {ERR_PACK(0,SSL_F_SSL_SET_TRUST,0), "SSL_set_trust"}, | ||
184 | {ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"}, | ||
185 | {ERR_PACK(0,SSL_F_SSL_SHUTDOWN,0), "SSL_shutdown"}, | ||
186 | {ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"}, | ||
187 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"}, | ||
188 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"}, | ||
189 | {ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"}, | ||
190 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"}, | ||
191 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"}, | ||
192 | {ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"}, | ||
193 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"}, | ||
194 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"}, | ||
195 | {ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"}, | ||
196 | {ERR_PACK(0,SSL_F_SSL_VERIFY_CERT_CHAIN,0), "SSL_VERIFY_CERT_CHAIN"}, | ||
197 | {ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"}, | ||
198 | {ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"}, | ||
199 | {ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"}, | ||
200 | {ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"}, | ||
201 | {ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"}, | ||
202 | {0,NULL} | ||
203 | }; | ||
204 | |||
205 | static ERR_STRING_DATA SSL_str_reasons[]= | ||
206 | { | ||
207 | {SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"}, | ||
208 | {SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT,"attempt to reuse session in different context"}, | ||
209 | {SSL_R_BAD_ALERT_RECORD ,"bad alert record"}, | ||
210 | {SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"}, | ||
211 | {SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"}, | ||
212 | {SSL_R_BAD_CHECKSUM ,"bad checksum"}, | ||
213 | {SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"}, | ||
214 | {SSL_R_BAD_DECOMPRESSION ,"bad decompression"}, | ||
215 | {SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"}, | ||
216 | {SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"}, | ||
217 | {SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"}, | ||
218 | {SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"}, | ||
219 | {SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"}, | ||
220 | {SSL_R_BAD_HELLO_REQUEST ,"bad hello request"}, | ||
221 | {SSL_R_BAD_LENGTH ,"bad length"}, | ||
222 | {SSL_R_BAD_MAC_DECODE ,"bad mac decode"}, | ||
223 | {SSL_R_BAD_MESSAGE_TYPE ,"bad message type"}, | ||
224 | {SSL_R_BAD_PACKET_LENGTH ,"bad packet length"}, | ||
225 | {SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"}, | ||
226 | {SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"}, | ||
227 | {SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"}, | ||
228 | {SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"}, | ||
229 | {SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"}, | ||
230 | {SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"}, | ||
231 | {SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"}, | ||
232 | {SSL_R_BAD_SIGNATURE ,"bad signature"}, | ||
233 | {SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"}, | ||
234 | {SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"}, | ||
235 | {SSL_R_BAD_STATE ,"bad state"}, | ||
236 | {SSL_R_BAD_WRITE_RETRY ,"bad write retry"}, | ||
237 | {SSL_R_BIO_NOT_SET ,"bio not set"}, | ||
238 | {SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"}, | ||
239 | {SSL_R_BN_LIB ,"bn lib"}, | ||
240 | {SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"}, | ||
241 | {SSL_R_CA_DN_TOO_LONG ,"ca dn too long"}, | ||
242 | {SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"}, | ||
243 | {SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"}, | ||
244 | {SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"}, | ||
245 | {SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"}, | ||
246 | {SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"}, | ||
247 | {SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"}, | ||
248 | {SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"}, | ||
249 | {SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"}, | ||
250 | {SSL_R_COMPRESSION_FAILURE ,"compression failure"}, | ||
251 | {SSL_R_COMPRESSION_LIBRARY_ERROR ,"compression library error"}, | ||
252 | {SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"}, | ||
253 | {SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"}, | ||
254 | {SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"}, | ||
255 | {SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"}, | ||
256 | {SSL_R_DECRYPTION_FAILED ,"decryption failed"}, | ||
257 | {SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"}, | ||
258 | {SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"}, | ||
259 | {SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"}, | ||
260 | {SSL_R_ERROR_GENERATING_TMP_RSA_KEY ,"error generating tmp rsa key"}, | ||
261 | {SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"}, | ||
262 | {SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"}, | ||
263 | {SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"}, | ||
264 | {SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"}, | ||
265 | {SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"}, | ||
266 | {SSL_R_HTTP_REQUEST ,"http request"}, | ||
267 | {SSL_R_INTERNAL_ERROR ,"internal error"}, | ||
268 | {SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"}, | ||
269 | {SSL_R_INVALID_COMMAND ,"invalid command"}, | ||
270 | {SSL_R_INVALID_PURPOSE ,"invalid purpose"}, | ||
271 | {SSL_R_INVALID_TRUST ,"invalid trust"}, | ||
272 | {SSL_R_LENGTH_MISMATCH ,"length mismatch"}, | ||
273 | {SSL_R_LENGTH_TOO_SHORT ,"length too short"}, | ||
274 | {SSL_R_LIBRARY_BUG ,"library bug"}, | ||
275 | {SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"}, | ||
276 | {SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"}, | ||
277 | {SSL_R_MISSING_DH_KEY ,"missing dh key"}, | ||
278 | {SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"}, | ||
279 | {SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"}, | ||
280 | {SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"}, | ||
281 | {SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"}, | ||
282 | {SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"}, | ||
283 | {SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"}, | ||
284 | {SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"}, | ||
285 | {SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"}, | ||
286 | {SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"}, | ||
287 | {SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"}, | ||
288 | {SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"}, | ||
289 | {SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"}, | ||
290 | {SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"}, | ||
291 | {SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"}, | ||
292 | {SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"}, | ||
293 | {SSL_R_NO_CERTIFICATE_SET ,"no certificate set"}, | ||
294 | {SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"}, | ||
295 | {SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"}, | ||
296 | {SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"}, | ||
297 | {SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"}, | ||
298 | {SSL_R_NO_CIPHER_LIST ,"no cipher list"}, | ||
299 | {SSL_R_NO_CIPHER_MATCH ,"no cipher match"}, | ||
300 | {SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"}, | ||
301 | {SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"}, | ||
302 | {SSL_R_NO_METHOD_SPECIFIED ,"no method specified"}, | ||
303 | {SSL_R_NO_PRIVATEKEY ,"no privatekey"}, | ||
304 | {SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"}, | ||
305 | {SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"}, | ||
306 | {SSL_R_NO_PUBLICKEY ,"no publickey"}, | ||
307 | {SSL_R_NO_SHARED_CIPHER ,"no shared cipher"}, | ||
308 | {SSL_R_NO_VERIFY_CALLBACK ,"no verify callback"}, | ||
309 | {SSL_R_NULL_SSL_CTX ,"null ssl ctx"}, | ||
310 | {SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"}, | ||
311 | {SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"}, | ||
312 | {SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"}, | ||
313 | {SSL_R_PATH_TOO_LONG ,"path too long"}, | ||
314 | {SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"}, | ||
315 | {SSL_R_PEER_ERROR ,"peer error"}, | ||
316 | {SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"}, | ||
317 | {SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"}, | ||
318 | {SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"}, | ||
319 | {SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"}, | ||
320 | {SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"}, | ||
321 | {SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"}, | ||
322 | {SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"}, | ||
323 | {SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"}, | ||
324 | {SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"}, | ||
325 | {SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, | ||
326 | {SSL_R_READ_BIO_NOT_SET ,"read bio not set"}, | ||
327 | {SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"}, | ||
328 | {SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"}, | ||
329 | {SSL_R_RECORD_TOO_LARGE ,"record too large"}, | ||
330 | {SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"}, | ||
331 | {SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"}, | ||
332 | {SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"}, | ||
333 | {SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"}, | ||
334 | {SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"}, | ||
335 | {SSL_R_SHORT_READ ,"short read"}, | ||
336 | {SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"}, | ||
337 | {SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"}, | ||
338 | {SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"}, | ||
339 | {SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"}, | ||
340 | {SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"}, | ||
341 | {SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"}, | ||
342 | {SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"}, | ||
343 | {SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"}, | ||
344 | {SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"}, | ||
345 | {SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"}, | ||
346 | {SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"}, | ||
347 | {SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"}, | ||
348 | {SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"}, | ||
349 | {SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"}, | ||
350 | {SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"}, | ||
351 | {SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"}, | ||
352 | {SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"}, | ||
353 | {SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"}, | ||
354 | {SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"}, | ||
355 | {SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"}, | ||
356 | {SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"}, | ||
357 | {SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"}, | ||
358 | {SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"}, | ||
359 | {SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"}, | ||
360 | {SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"}, | ||
361 | {SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"}, | ||
362 | {SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"}, | ||
363 | {SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"}, | ||
364 | {SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION ,"tlsv1 alert export restriction"}, | ||
365 | {SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"}, | ||
366 | {SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"}, | ||
367 | {SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"}, | ||
368 | {SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"}, | ||
369 | {SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"}, | ||
370 | {SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"}, | ||
371 | {SSL_R_TLSV1_ALERT_USER_CANCELLED ,"tlsv1 alert user cancelled"}, | ||
372 | {SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"}, | ||
373 | {SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"}, | ||
374 | {SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"}, | ||
375 | {SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"}, | ||
376 | {SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"}, | ||
377 | {SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"}, | ||
378 | {SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"}, | ||
379 | {SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"}, | ||
380 | {SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"}, | ||
381 | {SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"}, | ||
382 | {SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"}, | ||
383 | {SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"}, | ||
384 | {SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"}, | ||
385 | {SSL_R_UNEXPECTED_RECORD ,"unexpected record"}, | ||
386 | {SSL_R_UNINITIALIZED ,"uninitialized"}, | ||
387 | {SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"}, | ||
388 | {SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"}, | ||
389 | {SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"}, | ||
390 | {SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"}, | ||
391 | {SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"}, | ||
392 | {SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"}, | ||
393 | {SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"}, | ||
394 | {SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"}, | ||
395 | {SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"}, | ||
396 | {SSL_R_UNKNOWN_STATE ,"unknown state"}, | ||
397 | {SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
398 | {SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"}, | ||
399 | {SSL_R_UNSUPPORTED_OPTION ,"unsupported option"}, | ||
400 | {SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"}, | ||
401 | {SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"}, | ||
402 | {SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"}, | ||
403 | {SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"}, | ||
404 | {SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"}, | ||
405 | {SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"}, | ||
406 | {SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, | ||
407 | {SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"}, | ||
408 | {SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"}, | ||
409 | {SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"}, | ||
410 | {SSL_R_X509_LIB ,"x509 lib"}, | ||
411 | {SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"}, | ||
412 | {0,NULL} | ||
413 | }; | ||
414 | |||
415 | #endif | ||
416 | |||
417 | void ERR_load_SSL_strings(void) | ||
418 | { | ||
419 | static int init=1; | ||
420 | |||
421 | if (init) | ||
422 | { | ||
423 | init=0; | ||
424 | #ifndef NO_ERR | ||
425 | ERR_load_strings(ERR_LIB_SSL,SSL_str_functs); | ||
426 | ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons); | ||
427 | #endif | ||
428 | |||
429 | } | ||
430 | } | ||
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c deleted file mode 100644 index cc089a612b..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 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 c515c41b4e..0000000000 --- a/src/lib/libssl/ssl_lib.c +++ /dev/null | |||
@@ -1,2061 +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 | #include <stdio.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/lhash.h> | ||
64 | #include <openssl/x509v3.h> | ||
65 | #include "ssl_locl.h" | ||
66 | |||
67 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; | ||
68 | |||
69 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_meth=NULL; | ||
70 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_ctx_meth=NULL; | ||
71 | static int ssl_meth_num=0; | ||
72 | static int ssl_ctx_meth_num=0; | ||
73 | |||
74 | OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={ | ||
75 | /* evil casts, but these functions are only called if there's a library bug */ | ||
76 | (int (*)(SSL *,int))ssl_undefined_function, | ||
77 | (int (*)(SSL *, unsigned char *, int))ssl_undefined_function, | ||
78 | ssl_undefined_function, | ||
79 | (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function, | ||
80 | (int (*)(SSL*, int))ssl_undefined_function, | ||
81 | (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function | ||
82 | }; | ||
83 | |||
84 | int SSL_clear(SSL *s) | ||
85 | { | ||
86 | int state; | ||
87 | |||
88 | if (s->method == NULL) | ||
89 | { | ||
90 | SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED); | ||
91 | return(0); | ||
92 | } | ||
93 | |||
94 | s->error=0; | ||
95 | s->hit=0; | ||
96 | s->shutdown=0; | ||
97 | |||
98 | #if 0 /* Disabled since version 1.10 of this file (early return not | ||
99 | * needed because SSL_clear is not called when doing renegotiation) */ | ||
100 | /* This is set if we are doing dynamic renegotiation so keep | ||
101 | * the old cipher. It is sort of a SSL_clear_lite :-) */ | ||
102 | if (s->new_session) return(1); | ||
103 | #else | ||
104 | if (s->new_session) | ||
105 | { | ||
106 | SSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR); | ||
107 | return 0; | ||
108 | } | ||
109 | #endif | ||
110 | |||
111 | state=s->state; /* Keep to check if we throw away the session-id */ | ||
112 | s->type=0; | ||
113 | |||
114 | s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT); | ||
115 | |||
116 | s->version=s->method->version; | ||
117 | s->client_version=s->version; | ||
118 | s->rwstate=SSL_NOTHING; | ||
119 | s->rstate=SSL_ST_READ_HEADER; | ||
120 | s->read_ahead=s->ctx->read_ahead; | ||
121 | |||
122 | if (s->init_buf != NULL) | ||
123 | { | ||
124 | BUF_MEM_free(s->init_buf); | ||
125 | s->init_buf=NULL; | ||
126 | } | ||
127 | |||
128 | ssl_clear_cipher_ctx(s); | ||
129 | |||
130 | if (ssl_clear_bad_session(s)) | ||
131 | { | ||
132 | SSL_SESSION_free(s->session); | ||
133 | s->session=NULL; | ||
134 | } | ||
135 | |||
136 | s->first_packet=0; | ||
137 | |||
138 | #if 1 | ||
139 | /* Check to see if we were changed into a different method, if | ||
140 | * so, revert back if we are not doing session-id reuse. */ | ||
141 | if ((s->session == NULL) && (s->method != s->ctx->method)) | ||
142 | { | ||
143 | s->method->ssl_free(s); | ||
144 | s->method=s->ctx->method; | ||
145 | if (!s->method->ssl_new(s)) | ||
146 | return(0); | ||
147 | } | ||
148 | else | ||
149 | #endif | ||
150 | s->method->ssl_clear(s); | ||
151 | return(1); | ||
152 | } | ||
153 | |||
154 | /** Used to change an SSL_CTXs default SSL method type */ | ||
155 | int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth) | ||
156 | { | ||
157 | STACK_OF(SSL_CIPHER) *sk; | ||
158 | |||
159 | ctx->method=meth; | ||
160 | |||
161 | sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list), | ||
162 | &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST); | ||
163 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) | ||
164 | { | ||
165 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | ||
166 | return(0); | ||
167 | } | ||
168 | return(1); | ||
169 | } | ||
170 | |||
171 | SSL *SSL_new(SSL_CTX *ctx) | ||
172 | { | ||
173 | SSL *s; | ||
174 | |||
175 | if (ctx == NULL) | ||
176 | { | ||
177 | SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX); | ||
178 | return(NULL); | ||
179 | } | ||
180 | if (ctx->method == NULL) | ||
181 | { | ||
182 | SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION); | ||
183 | return(NULL); | ||
184 | } | ||
185 | |||
186 | s=(SSL *)Malloc(sizeof(SSL)); | ||
187 | if (s == NULL) goto err; | ||
188 | memset(s,0,sizeof(SSL)); | ||
189 | |||
190 | if (ctx->cert != NULL) | ||
191 | { | ||
192 | /* Earlier library versions used to copy the pointer to | ||
193 | * the CERT, not its contents; only when setting new | ||
194 | * parameters for the per-SSL copy, ssl_cert_new would be | ||
195 | * called (and the direct reference to the per-SSL_CTX | ||
196 | * settings would be lost, but those still were indirectly | ||
197 | * accessed for various purposes, and for that reason they | ||
198 | * used to be known as s->ctx->default_cert). | ||
199 | * Now we don't look at the SSL_CTX's CERT after having | ||
200 | * duplicated it once. */ | ||
201 | |||
202 | s->cert = ssl_cert_dup(ctx->cert); | ||
203 | if (s->cert == NULL) | ||
204 | goto err; | ||
205 | } | ||
206 | else | ||
207 | s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */ | ||
208 | s->sid_ctx_length=ctx->sid_ctx_length; | ||
209 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); | ||
210 | s->verify_mode=ctx->verify_mode; | ||
211 | s->verify_depth=ctx->verify_depth; | ||
212 | s->verify_callback=ctx->default_verify_callback; | ||
213 | s->purpose = ctx->purpose; | ||
214 | s->trust = ctx->trust; | ||
215 | CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); | ||
216 | s->ctx=ctx; | ||
217 | |||
218 | s->verify_result=X509_V_OK; | ||
219 | |||
220 | s->method=ctx->method; | ||
221 | |||
222 | if (!s->method->ssl_new(s)) | ||
223 | goto err; | ||
224 | |||
225 | s->quiet_shutdown=ctx->quiet_shutdown; | ||
226 | s->references=1; | ||
227 | s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1; | ||
228 | s->options=ctx->options; | ||
229 | s->mode=ctx->mode; | ||
230 | SSL_clear(s); | ||
231 | |||
232 | CRYPTO_new_ex_data(ssl_meth,s,&s->ex_data); | ||
233 | |||
234 | return(s); | ||
235 | err: | ||
236 | if (s != NULL) | ||
237 | { | ||
238 | if (s->cert != NULL) | ||
239 | ssl_cert_free(s->cert); | ||
240 | if (s->ctx != NULL) | ||
241 | SSL_CTX_free(s->ctx); /* decrement reference count */ | ||
242 | Free(s); | ||
243 | } | ||
244 | SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE); | ||
245 | return(NULL); | ||
246 | } | ||
247 | |||
248 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, | ||
249 | unsigned int sid_ctx_len) | ||
250 | { | ||
251 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | ||
252 | { | ||
253 | SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
254 | return 0; | ||
255 | } | ||
256 | ctx->sid_ctx_length=sid_ctx_len; | ||
257 | memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len); | ||
258 | |||
259 | return 1; | ||
260 | } | ||
261 | |||
262 | int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx, | ||
263 | unsigned int sid_ctx_len) | ||
264 | { | ||
265 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | ||
266 | { | ||
267 | SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | ||
268 | return 0; | ||
269 | } | ||
270 | ssl->sid_ctx_length=sid_ctx_len; | ||
271 | memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len); | ||
272 | |||
273 | return 1; | ||
274 | } | ||
275 | |||
276 | int SSL_CTX_set_purpose(SSL_CTX *s, int purpose) | ||
277 | { | ||
278 | if(X509_PURPOSE_get_by_id(purpose) == -1) { | ||
279 | SSLerr(SSL_F_SSL_CTX_SET_PURPOSE, SSL_R_INVALID_PURPOSE); | ||
280 | return 0; | ||
281 | } | ||
282 | s->purpose = purpose; | ||
283 | return 1; | ||
284 | } | ||
285 | |||
286 | int SSL_set_purpose(SSL *s, int purpose) | ||
287 | { | ||
288 | if(X509_PURPOSE_get_by_id(purpose) == -1) { | ||
289 | SSLerr(SSL_F_SSL_SET_PURPOSE, SSL_R_INVALID_PURPOSE); | ||
290 | return 0; | ||
291 | } | ||
292 | s->purpose = purpose; | ||
293 | return 1; | ||
294 | } | ||
295 | |||
296 | int SSL_CTX_set_trust(SSL_CTX *s, int trust) | ||
297 | { | ||
298 | if(X509_TRUST_get_by_id(trust) == -1) { | ||
299 | SSLerr(SSL_F_SSL_CTX_SET_TRUST, SSL_R_INVALID_TRUST); | ||
300 | return 0; | ||
301 | } | ||
302 | s->trust = trust; | ||
303 | return 1; | ||
304 | } | ||
305 | |||
306 | int SSL_set_trust(SSL *s, int trust) | ||
307 | { | ||
308 | if(X509_TRUST_get_by_id(trust) == -1) { | ||
309 | SSLerr(SSL_F_SSL_SET_TRUST, SSL_R_INVALID_TRUST); | ||
310 | return 0; | ||
311 | } | ||
312 | s->trust = trust; | ||
313 | return 1; | ||
314 | } | ||
315 | |||
316 | void SSL_free(SSL *s) | ||
317 | { | ||
318 | int i; | ||
319 | |||
320 | if(s == NULL) | ||
321 | return; | ||
322 | |||
323 | i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL); | ||
324 | #ifdef REF_PRINT | ||
325 | REF_PRINT("SSL",s); | ||
326 | #endif | ||
327 | if (i > 0) return; | ||
328 | #ifdef REF_CHECK | ||
329 | if (i < 0) | ||
330 | { | ||
331 | fprintf(stderr,"SSL_free, bad reference count\n"); | ||
332 | abort(); /* ok */ | ||
333 | } | ||
334 | #endif | ||
335 | |||
336 | CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data); | ||
337 | |||
338 | if (s->bbio != NULL) | ||
339 | { | ||
340 | /* If the buffering BIO is in place, pop it off */ | ||
341 | if (s->bbio == s->wbio) | ||
342 | { | ||
343 | s->wbio=BIO_pop(s->wbio); | ||
344 | } | ||
345 | BIO_free(s->bbio); | ||
346 | s->bbio=NULL; | ||
347 | } | ||
348 | if (s->rbio != NULL) | ||
349 | BIO_free_all(s->rbio); | ||
350 | if ((s->wbio != NULL) && (s->wbio != s->rbio)) | ||
351 | BIO_free_all(s->wbio); | ||
352 | |||
353 | if (s->init_buf != NULL) BUF_MEM_free(s->init_buf); | ||
354 | |||
355 | /* add extra stuff */ | ||
356 | if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list); | ||
357 | if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id); | ||
358 | |||
359 | /* Make the next call work :-) */ | ||
360 | if (s->session != NULL) | ||
361 | { | ||
362 | ssl_clear_bad_session(s); | ||
363 | SSL_SESSION_free(s->session); | ||
364 | } | ||
365 | |||
366 | ssl_clear_cipher_ctx(s); | ||
367 | |||
368 | if (s->cert != NULL) ssl_cert_free(s->cert); | ||
369 | /* Free up if allocated */ | ||
370 | |||
371 | if (s->ctx) SSL_CTX_free(s->ctx); | ||
372 | |||
373 | if (s->client_CA != NULL) | ||
374 | sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free); | ||
375 | |||
376 | if (s->method != NULL) s->method->ssl_free(s); | ||
377 | |||
378 | Free(s); | ||
379 | } | ||
380 | |||
381 | void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio) | ||
382 | { | ||
383 | /* If the output buffering BIO is still in place, remove it | ||
384 | */ | ||
385 | if (s->bbio != NULL) | ||
386 | { | ||
387 | if (s->wbio == s->bbio) | ||
388 | { | ||
389 | s->wbio=s->wbio->next_bio; | ||
390 | s->bbio->next_bio=NULL; | ||
391 | } | ||
392 | } | ||
393 | if ((s->rbio != NULL) && (s->rbio != rbio)) | ||
394 | BIO_free_all(s->rbio); | ||
395 | if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio)) | ||
396 | BIO_free_all(s->wbio); | ||
397 | s->rbio=rbio; | ||
398 | s->wbio=wbio; | ||
399 | } | ||
400 | |||
401 | BIO *SSL_get_rbio(SSL *s) | ||
402 | { return(s->rbio); } | ||
403 | |||
404 | BIO *SSL_get_wbio(SSL *s) | ||
405 | { return(s->wbio); } | ||
406 | |||
407 | int SSL_get_fd(SSL *s) | ||
408 | { | ||
409 | int ret= -1; | ||
410 | BIO *b,*r; | ||
411 | |||
412 | b=SSL_get_rbio(s); | ||
413 | r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR); | ||
414 | if (r != NULL) | ||
415 | BIO_get_fd(r,&ret); | ||
416 | return(ret); | ||
417 | } | ||
418 | |||
419 | #ifndef NO_SOCK | ||
420 | int SSL_set_fd(SSL *s,int fd) | ||
421 | { | ||
422 | int ret=0; | ||
423 | BIO *bio=NULL; | ||
424 | |||
425 | bio=BIO_new(BIO_s_socket()); | ||
426 | |||
427 | if (bio == NULL) | ||
428 | { | ||
429 | SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB); | ||
430 | goto err; | ||
431 | } | ||
432 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
433 | SSL_set_bio(s,bio,bio); | ||
434 | ret=1; | ||
435 | err: | ||
436 | return(ret); | ||
437 | } | ||
438 | |||
439 | int SSL_set_wfd(SSL *s,int fd) | ||
440 | { | ||
441 | int ret=0; | ||
442 | BIO *bio=NULL; | ||
443 | |||
444 | if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET) | ||
445 | || ((int)BIO_get_fd(s->rbio,NULL) != fd)) | ||
446 | { | ||
447 | bio=BIO_new(BIO_s_socket()); | ||
448 | |||
449 | if (bio == NULL) | ||
450 | { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; } | ||
451 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
452 | SSL_set_bio(s,SSL_get_rbio(s),bio); | ||
453 | } | ||
454 | else | ||
455 | SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s)); | ||
456 | ret=1; | ||
457 | err: | ||
458 | return(ret); | ||
459 | } | ||
460 | |||
461 | int SSL_set_rfd(SSL *s,int fd) | ||
462 | { | ||
463 | int ret=0; | ||
464 | BIO *bio=NULL; | ||
465 | |||
466 | if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET) | ||
467 | || ((int)BIO_get_fd(s->wbio,NULL) != fd)) | ||
468 | { | ||
469 | bio=BIO_new(BIO_s_socket()); | ||
470 | |||
471 | if (bio == NULL) | ||
472 | { | ||
473 | SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB); | ||
474 | goto err; | ||
475 | } | ||
476 | BIO_set_fd(bio,fd,BIO_NOCLOSE); | ||
477 | SSL_set_bio(s,bio,SSL_get_wbio(s)); | ||
478 | } | ||
479 | else | ||
480 | SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s)); | ||
481 | ret=1; | ||
482 | err: | ||
483 | return(ret); | ||
484 | } | ||
485 | #endif | ||
486 | |||
487 | |||
488 | /* return length of latest Finished message we sent, copy to 'buf' */ | ||
489 | size_t SSL_get_finished(SSL *s, void *buf, size_t count) | ||
490 | { | ||
491 | size_t ret = 0; | ||
492 | |||
493 | if (s->s3 != NULL) | ||
494 | { | ||
495 | ret = s->s3->tmp.finish_md_len; | ||
496 | if (count > ret) | ||
497 | count = ret; | ||
498 | memcpy(buf, s->s3->tmp.finish_md, count); | ||
499 | } | ||
500 | return ret; | ||
501 | } | ||
502 | |||
503 | /* return length of latest Finished message we expected, copy to 'buf' */ | ||
504 | size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count) | ||
505 | { | ||
506 | size_t ret = 0; | ||
507 | |||
508 | if (s->s3 != NULL) | ||
509 | { | ||
510 | ret = s->s3->tmp.peer_finish_md_len; | ||
511 | if (count > ret) | ||
512 | count = ret; | ||
513 | memcpy(buf, s->s3->tmp.peer_finish_md, count); | ||
514 | } | ||
515 | return ret; | ||
516 | } | ||
517 | |||
518 | |||
519 | int SSL_get_verify_mode(SSL *s) | ||
520 | { | ||
521 | return(s->verify_mode); | ||
522 | } | ||
523 | |||
524 | int SSL_get_verify_depth(SSL *s) | ||
525 | { | ||
526 | return(s->verify_depth); | ||
527 | } | ||
528 | |||
529 | int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *) | ||
530 | { | ||
531 | return(s->verify_callback); | ||
532 | } | ||
533 | |||
534 | int SSL_CTX_get_verify_mode(SSL_CTX *ctx) | ||
535 | { | ||
536 | return(ctx->verify_mode); | ||
537 | } | ||
538 | |||
539 | int SSL_CTX_get_verify_depth(SSL_CTX *ctx) | ||
540 | { | ||
541 | return(ctx->verify_depth); | ||
542 | } | ||
543 | |||
544 | int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *) | ||
545 | { | ||
546 | return(ctx->default_verify_callback); | ||
547 | } | ||
548 | |||
549 | void SSL_set_verify(SSL *s,int mode, | ||
550 | int (*callback)(int ok,X509_STORE_CTX *ctx)) | ||
551 | { | ||
552 | s->verify_mode=mode; | ||
553 | if (callback != NULL) | ||
554 | s->verify_callback=callback; | ||
555 | } | ||
556 | |||
557 | void SSL_set_verify_depth(SSL *s,int depth) | ||
558 | { | ||
559 | s->verify_depth=depth; | ||
560 | } | ||
561 | |||
562 | void SSL_set_read_ahead(SSL *s,int yes) | ||
563 | { | ||
564 | s->read_ahead=yes; | ||
565 | } | ||
566 | |||
567 | int SSL_get_read_ahead(SSL *s) | ||
568 | { | ||
569 | return(s->read_ahead); | ||
570 | } | ||
571 | |||
572 | int SSL_pending(SSL *s) | ||
573 | { | ||
574 | return(s->method->ssl_pending(s)); | ||
575 | } | ||
576 | |||
577 | X509 *SSL_get_peer_certificate(SSL *s) | ||
578 | { | ||
579 | X509 *r; | ||
580 | |||
581 | if ((s == NULL) || (s->session == NULL)) | ||
582 | r=NULL; | ||
583 | else | ||
584 | r=s->session->peer; | ||
585 | |||
586 | if (r == NULL) return(r); | ||
587 | |||
588 | CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509); | ||
589 | |||
590 | return(r); | ||
591 | } | ||
592 | |||
593 | STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s) | ||
594 | { | ||
595 | STACK_OF(X509) *r; | ||
596 | |||
597 | if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL)) | ||
598 | r=NULL; | ||
599 | else | ||
600 | r=s->session->sess_cert->cert_chain; | ||
601 | |||
602 | /* If we are a client, cert_chain includes the peer's own | ||
603 | * certificate; if we are a server, it does not. */ | ||
604 | |||
605 | return(r); | ||
606 | } | ||
607 | |||
608 | /* Now in theory, since the calling process own 't' it should be safe to | ||
609 | * modify. We need to be able to read f without being hassled */ | ||
610 | void SSL_copy_session_id(SSL *t,SSL *f) | ||
611 | { | ||
612 | CERT *tmp; | ||
613 | |||
614 | /* Do we need to to SSL locking? */ | ||
615 | SSL_set_session(t,SSL_get_session(f)); | ||
616 | |||
617 | /* what if we are setup as SSLv2 but want to talk SSLv3 or | ||
618 | * vice-versa */ | ||
619 | if (t->method != f->method) | ||
620 | { | ||
621 | t->method->ssl_free(t); /* cleanup current */ | ||
622 | t->method=f->method; /* change method */ | ||
623 | t->method->ssl_new(t); /* setup new */ | ||
624 | } | ||
625 | |||
626 | tmp=t->cert; | ||
627 | if (f->cert != NULL) | ||
628 | { | ||
629 | CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT); | ||
630 | t->cert=f->cert; | ||
631 | } | ||
632 | else | ||
633 | t->cert=NULL; | ||
634 | if (tmp != NULL) ssl_cert_free(tmp); | ||
635 | SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length); | ||
636 | } | ||
637 | |||
638 | /* Fix this so it checks all the valid key/cert options */ | ||
639 | int SSL_CTX_check_private_key(SSL_CTX *ctx) | ||
640 | { | ||
641 | if ( (ctx == NULL) || | ||
642 | (ctx->cert == NULL) || | ||
643 | (ctx->cert->key->x509 == NULL)) | ||
644 | { | ||
645 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
646 | return(0); | ||
647 | } | ||
648 | if (ctx->cert->key->privatekey == NULL) | ||
649 | { | ||
650 | SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
651 | return(0); | ||
652 | } | ||
653 | return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey)); | ||
654 | } | ||
655 | |||
656 | /* Fix this function so that it takes an optional type parameter */ | ||
657 | int SSL_check_private_key(SSL *ssl) | ||
658 | { | ||
659 | if (ssl == NULL) | ||
660 | { | ||
661 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER); | ||
662 | return(0); | ||
663 | } | ||
664 | if (ssl->cert == NULL) | ||
665 | { | ||
666 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
667 | return 0; | ||
668 | } | ||
669 | if (ssl->cert->key->x509 == NULL) | ||
670 | { | ||
671 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED); | ||
672 | return(0); | ||
673 | } | ||
674 | if (ssl->cert->key->privatekey == NULL) | ||
675 | { | ||
676 | SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED); | ||
677 | return(0); | ||
678 | } | ||
679 | return(X509_check_private_key(ssl->cert->key->x509, | ||
680 | ssl->cert->key->privatekey)); | ||
681 | } | ||
682 | |||
683 | int SSL_accept(SSL *s) | ||
684 | { | ||
685 | if (s->handshake_func == 0) | ||
686 | /* Not properly initialized yet */ | ||
687 | SSL_set_accept_state(s); | ||
688 | |||
689 | return(s->method->ssl_accept(s)); | ||
690 | } | ||
691 | |||
692 | int SSL_connect(SSL *s) | ||
693 | { | ||
694 | if (s->handshake_func == 0) | ||
695 | /* Not properly initialized yet */ | ||
696 | SSL_set_connect_state(s); | ||
697 | |||
698 | return(s->method->ssl_connect(s)); | ||
699 | } | ||
700 | |||
701 | long SSL_get_default_timeout(SSL *s) | ||
702 | { | ||
703 | return(s->method->get_timeout()); | ||
704 | } | ||
705 | |||
706 | int SSL_read(SSL *s,char *buf,int num) | ||
707 | { | ||
708 | if (s->handshake_func == 0) | ||
709 | { | ||
710 | SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED); | ||
711 | return -1; | ||
712 | } | ||
713 | |||
714 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
715 | { | ||
716 | s->rwstate=SSL_NOTHING; | ||
717 | return(0); | ||
718 | } | ||
719 | return(s->method->ssl_read(s,buf,num)); | ||
720 | } | ||
721 | |||
722 | int SSL_peek(SSL *s,char *buf,int num) | ||
723 | { | ||
724 | if (s->shutdown & SSL_RECEIVED_SHUTDOWN) | ||
725 | { | ||
726 | return(0); | ||
727 | } | ||
728 | return(s->method->ssl_peek(s,buf,num)); | ||
729 | } | ||
730 | |||
731 | int SSL_write(SSL *s,const char *buf,int num) | ||
732 | { | ||
733 | if (s->handshake_func == 0) | ||
734 | { | ||
735 | SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED); | ||
736 | return -1; | ||
737 | } | ||
738 | |||
739 | if (s->shutdown & SSL_SENT_SHUTDOWN) | ||
740 | { | ||
741 | s->rwstate=SSL_NOTHING; | ||
742 | SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN); | ||
743 | return(-1); | ||
744 | } | ||
745 | return(s->method->ssl_write(s,buf,num)); | ||
746 | } | ||
747 | |||
748 | int SSL_shutdown(SSL *s) | ||
749 | { | ||
750 | /* Note that this function behaves differently from what one might | ||
751 | * expect. Return values are 0 for no success (yet), | ||
752 | * 1 for success; but calling it once is usually not enough, | ||
753 | * even if blocking I/O is used (see ssl3_shutdown). | ||
754 | */ | ||
755 | |||
756 | if (s->handshake_func == 0) | ||
757 | { | ||
758 | SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED); | ||
759 | return -1; | ||
760 | } | ||
761 | |||
762 | if ((s != NULL) && !SSL_in_init(s)) | ||
763 | return(s->method->ssl_shutdown(s)); | ||
764 | else | ||
765 | return(1); | ||
766 | } | ||
767 | |||
768 | int SSL_renegotiate(SSL *s) | ||
769 | { | ||
770 | s->new_session=1; | ||
771 | return(s->method->ssl_renegotiate(s)); | ||
772 | } | ||
773 | |||
774 | long SSL_ctrl(SSL *s,int cmd,long larg,char *parg) | ||
775 | { | ||
776 | long l; | ||
777 | |||
778 | switch (cmd) | ||
779 | { | ||
780 | case SSL_CTRL_GET_READ_AHEAD: | ||
781 | return(s->read_ahead); | ||
782 | case SSL_CTRL_SET_READ_AHEAD: | ||
783 | l=s->read_ahead; | ||
784 | s->read_ahead=larg; | ||
785 | return(l); | ||
786 | case SSL_CTRL_OPTIONS: | ||
787 | return(s->options|=larg); | ||
788 | case SSL_CTRL_MODE: | ||
789 | return(s->mode|=larg); | ||
790 | default: | ||
791 | return(s->method->ssl_ctrl(s,cmd,larg,parg)); | ||
792 | } | ||
793 | } | ||
794 | |||
795 | long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)()) | ||
796 | { | ||
797 | switch(cmd) | ||
798 | { | ||
799 | default: | ||
800 | return(s->method->ssl_callback_ctrl(s,cmd,fp)); | ||
801 | } | ||
802 | } | ||
803 | |||
804 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx) | ||
805 | { | ||
806 | return ctx->sessions; | ||
807 | } | ||
808 | |||
809 | long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg) | ||
810 | { | ||
811 | long l; | ||
812 | |||
813 | switch (cmd) | ||
814 | { | ||
815 | case SSL_CTRL_GET_READ_AHEAD: | ||
816 | return(ctx->read_ahead); | ||
817 | case SSL_CTRL_SET_READ_AHEAD: | ||
818 | l=ctx->read_ahead; | ||
819 | ctx->read_ahead=larg; | ||
820 | return(l); | ||
821 | |||
822 | case SSL_CTRL_SET_SESS_CACHE_SIZE: | ||
823 | l=ctx->session_cache_size; | ||
824 | ctx->session_cache_size=larg; | ||
825 | return(l); | ||
826 | case SSL_CTRL_GET_SESS_CACHE_SIZE: | ||
827 | return(ctx->session_cache_size); | ||
828 | case SSL_CTRL_SET_SESS_CACHE_MODE: | ||
829 | l=ctx->session_cache_mode; | ||
830 | ctx->session_cache_mode=larg; | ||
831 | return(l); | ||
832 | case SSL_CTRL_GET_SESS_CACHE_MODE: | ||
833 | return(ctx->session_cache_mode); | ||
834 | |||
835 | case SSL_CTRL_SESS_NUMBER: | ||
836 | return(ctx->sessions->num_items); | ||
837 | case SSL_CTRL_SESS_CONNECT: | ||
838 | return(ctx->stats.sess_connect); | ||
839 | case SSL_CTRL_SESS_CONNECT_GOOD: | ||
840 | return(ctx->stats.sess_connect_good); | ||
841 | case SSL_CTRL_SESS_CONNECT_RENEGOTIATE: | ||
842 | return(ctx->stats.sess_connect_renegotiate); | ||
843 | case SSL_CTRL_SESS_ACCEPT: | ||
844 | return(ctx->stats.sess_accept); | ||
845 | case SSL_CTRL_SESS_ACCEPT_GOOD: | ||
846 | return(ctx->stats.sess_accept_good); | ||
847 | case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE: | ||
848 | return(ctx->stats.sess_accept_renegotiate); | ||
849 | case SSL_CTRL_SESS_HIT: | ||
850 | return(ctx->stats.sess_hit); | ||
851 | case SSL_CTRL_SESS_CB_HIT: | ||
852 | return(ctx->stats.sess_cb_hit); | ||
853 | case SSL_CTRL_SESS_MISSES: | ||
854 | return(ctx->stats.sess_miss); | ||
855 | case SSL_CTRL_SESS_TIMEOUTS: | ||
856 | return(ctx->stats.sess_timeout); | ||
857 | case SSL_CTRL_SESS_CACHE_FULL: | ||
858 | return(ctx->stats.sess_cache_full); | ||
859 | case SSL_CTRL_OPTIONS: | ||
860 | return(ctx->options|=larg); | ||
861 | case SSL_CTRL_MODE: | ||
862 | return(ctx->mode|=larg); | ||
863 | default: | ||
864 | return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg)); | ||
865 | } | ||
866 | } | ||
867 | |||
868 | long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)()) | ||
869 | { | ||
870 | switch(cmd) | ||
871 | { | ||
872 | default: | ||
873 | return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp)); | ||
874 | } | ||
875 | } | ||
876 | |||
877 | int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b) | ||
878 | { | ||
879 | long l; | ||
880 | |||
881 | l=a->id-b->id; | ||
882 | if (l == 0L) | ||
883 | return(0); | ||
884 | else | ||
885 | return((l > 0)?1:-1); | ||
886 | } | ||
887 | |||
888 | int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp) | ||
889 | { | ||
890 | long l; | ||
891 | |||
892 | l=(*ap)->id-(*bp)->id; | ||
893 | if (l == 0L) | ||
894 | return(0); | ||
895 | else | ||
896 | return((l > 0)?1:-1); | ||
897 | } | ||
898 | |||
899 | /** return a STACK of the ciphers available for the SSL and in order of | ||
900 | * preference */ | ||
901 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) | ||
902 | { | ||
903 | if ((s != NULL) && (s->cipher_list != NULL)) | ||
904 | { | ||
905 | return(s->cipher_list); | ||
906 | } | ||
907 | else if ((s->ctx != NULL) && | ||
908 | (s->ctx->cipher_list != NULL)) | ||
909 | { | ||
910 | return(s->ctx->cipher_list); | ||
911 | } | ||
912 | return(NULL); | ||
913 | } | ||
914 | |||
915 | /** return a STACK of the ciphers available for the SSL and in order of | ||
916 | * algorithm id */ | ||
917 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) | ||
918 | { | ||
919 | if ((s != NULL) && (s->cipher_list_by_id != NULL)) | ||
920 | { | ||
921 | return(s->cipher_list_by_id); | ||
922 | } | ||
923 | else if ((s != NULL) && (s->ctx != NULL) && | ||
924 | (s->ctx->cipher_list_by_id != NULL)) | ||
925 | { | ||
926 | return(s->ctx->cipher_list_by_id); | ||
927 | } | ||
928 | return(NULL); | ||
929 | } | ||
930 | |||
931 | /** The old interface to get the same thing as SSL_get_ciphers() */ | ||
932 | const char *SSL_get_cipher_list(SSL *s,int n) | ||
933 | { | ||
934 | SSL_CIPHER *c; | ||
935 | STACK_OF(SSL_CIPHER) *sk; | ||
936 | |||
937 | if (s == NULL) return(NULL); | ||
938 | sk=SSL_get_ciphers(s); | ||
939 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n)) | ||
940 | return(NULL); | ||
941 | c=sk_SSL_CIPHER_value(sk,n); | ||
942 | if (c == NULL) return(NULL); | ||
943 | return(c->name); | ||
944 | } | ||
945 | |||
946 | /** specify the ciphers to be used by default by the SSL_CTX */ | ||
947 | int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) | ||
948 | { | ||
949 | STACK_OF(SSL_CIPHER) *sk; | ||
950 | |||
951 | sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list, | ||
952 | &ctx->cipher_list_by_id,str); | ||
953 | /* XXXX */ | ||
954 | return((sk == NULL)?0:1); | ||
955 | } | ||
956 | |||
957 | /** specify the ciphers to be used by the SSL */ | ||
958 | int SSL_set_cipher_list(SSL *s,const char *str) | ||
959 | { | ||
960 | STACK_OF(SSL_CIPHER) *sk; | ||
961 | |||
962 | sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list, | ||
963 | &s->cipher_list_by_id,str); | ||
964 | /* XXXX */ | ||
965 | return((sk == NULL)?0:1); | ||
966 | } | ||
967 | |||
968 | /* works well for SSLv2, not so good for SSLv3 */ | ||
969 | char *SSL_get_shared_ciphers(SSL *s,char *buf,int len) | ||
970 | { | ||
971 | char *p; | ||
972 | const char *cp; | ||
973 | STACK_OF(SSL_CIPHER) *sk; | ||
974 | SSL_CIPHER *c; | ||
975 | int i; | ||
976 | |||
977 | if ((s->session == NULL) || (s->session->ciphers == NULL) || | ||
978 | (len < 2)) | ||
979 | return(NULL); | ||
980 | |||
981 | p=buf; | ||
982 | sk=s->session->ciphers; | ||
983 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
984 | { | ||
985 | /* Decrement for either the ':' or a '\0' */ | ||
986 | len--; | ||
987 | c=sk_SSL_CIPHER_value(sk,i); | ||
988 | for (cp=c->name; *cp; ) | ||
989 | { | ||
990 | if (len-- == 0) | ||
991 | { | ||
992 | *p='\0'; | ||
993 | return(buf); | ||
994 | } | ||
995 | else | ||
996 | *(p++)= *(cp++); | ||
997 | } | ||
998 | *(p++)=':'; | ||
999 | } | ||
1000 | p[-1]='\0'; | ||
1001 | return(buf); | ||
1002 | } | ||
1003 | |||
1004 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p) | ||
1005 | { | ||
1006 | int i,j=0; | ||
1007 | SSL_CIPHER *c; | ||
1008 | unsigned char *q; | ||
1009 | |||
1010 | if (sk == NULL) return(0); | ||
1011 | q=p; | ||
1012 | |||
1013 | for (i=0; i<sk_SSL_CIPHER_num(sk); i++) | ||
1014 | { | ||
1015 | c=sk_SSL_CIPHER_value(sk,i); | ||
1016 | j=ssl_put_cipher_by_char(s,c,p); | ||
1017 | p+=j; | ||
1018 | } | ||
1019 | return(p-q); | ||
1020 | } | ||
1021 | |||
1022 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | ||
1023 | STACK_OF(SSL_CIPHER) **skp) | ||
1024 | { | ||
1025 | SSL_CIPHER *c; | ||
1026 | STACK_OF(SSL_CIPHER) *sk; | ||
1027 | int i,n; | ||
1028 | |||
1029 | n=ssl_put_cipher_by_char(s,NULL,NULL); | ||
1030 | if ((num%n) != 0) | ||
1031 | { | ||
1032 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); | ||
1033 | return(NULL); | ||
1034 | } | ||
1035 | if ((skp == NULL) || (*skp == NULL)) | ||
1036 | sk=sk_SSL_CIPHER_new(NULL); /* change perhaps later */ | ||
1037 | else | ||
1038 | { | ||
1039 | sk= *skp; | ||
1040 | sk_SSL_CIPHER_zero(sk); | ||
1041 | } | ||
1042 | |||
1043 | for (i=0; i<num; i+=n) | ||
1044 | { | ||
1045 | c=ssl_get_cipher_by_char(s,p); | ||
1046 | p+=n; | ||
1047 | if (c != NULL) | ||
1048 | { | ||
1049 | if (!sk_SSL_CIPHER_push(sk,c)) | ||
1050 | { | ||
1051 | SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE); | ||
1052 | goto err; | ||
1053 | } | ||
1054 | } | ||
1055 | } | ||
1056 | |||
1057 | if (skp != NULL) | ||
1058 | *skp=sk; | ||
1059 | return(sk); | ||
1060 | err: | ||
1061 | if ((skp == NULL) || (*skp == NULL)) | ||
1062 | sk_SSL_CIPHER_free(sk); | ||
1063 | return(NULL); | ||
1064 | } | ||
1065 | |||
1066 | unsigned long SSL_SESSION_hash(SSL_SESSION *a) | ||
1067 | { | ||
1068 | unsigned long l; | ||
1069 | |||
1070 | l=(unsigned long) | ||
1071 | ((unsigned int) a->session_id[0] )| | ||
1072 | ((unsigned int) a->session_id[1]<< 8L)| | ||
1073 | ((unsigned long)a->session_id[2]<<16L)| | ||
1074 | ((unsigned long)a->session_id[3]<<24L); | ||
1075 | return(l); | ||
1076 | } | ||
1077 | |||
1078 | int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b) | ||
1079 | { | ||
1080 | if (a->ssl_version != b->ssl_version) | ||
1081 | return(1); | ||
1082 | if (a->session_id_length != b->session_id_length) | ||
1083 | return(1); | ||
1084 | return(memcmp(a->session_id,b->session_id,a->session_id_length)); | ||
1085 | } | ||
1086 | |||
1087 | SSL_CTX *SSL_CTX_new(SSL_METHOD *meth) | ||
1088 | { | ||
1089 | SSL_CTX *ret=NULL; | ||
1090 | |||
1091 | if (meth == NULL) | ||
1092 | { | ||
1093 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED); | ||
1094 | return(NULL); | ||
1095 | } | ||
1096 | |||
1097 | if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) | ||
1098 | { | ||
1099 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS); | ||
1100 | goto err; | ||
1101 | } | ||
1102 | ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX)); | ||
1103 | if (ret == NULL) | ||
1104 | goto err; | ||
1105 | |||
1106 | memset(ret,0,sizeof(SSL_CTX)); | ||
1107 | |||
1108 | ret->method=meth; | ||
1109 | |||
1110 | ret->cert_store=NULL; | ||
1111 | ret->session_cache_mode=SSL_SESS_CACHE_SERVER; | ||
1112 | ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT; | ||
1113 | ret->session_cache_head=NULL; | ||
1114 | ret->session_cache_tail=NULL; | ||
1115 | |||
1116 | /* We take the system default */ | ||
1117 | ret->session_timeout=meth->get_timeout(); | ||
1118 | |||
1119 | ret->new_session_cb=NULL; | ||
1120 | ret->remove_session_cb=NULL; | ||
1121 | ret->get_session_cb=NULL; | ||
1122 | |||
1123 | memset((char *)&ret->stats,0,sizeof(ret->stats)); | ||
1124 | |||
1125 | ret->references=1; | ||
1126 | ret->quiet_shutdown=0; | ||
1127 | |||
1128 | /* ret->cipher=NULL;*/ | ||
1129 | /* ret->s2->challenge=NULL; | ||
1130 | ret->master_key=NULL; | ||
1131 | ret->key_arg=NULL; | ||
1132 | ret->s2->conn_id=NULL; */ | ||
1133 | |||
1134 | ret->info_callback=NULL; | ||
1135 | |||
1136 | ret->app_verify_callback=NULL; | ||
1137 | ret->app_verify_arg=NULL; | ||
1138 | |||
1139 | ret->read_ahead=0; | ||
1140 | ret->verify_mode=SSL_VERIFY_NONE; | ||
1141 | ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */ | ||
1142 | ret->default_verify_callback=NULL; | ||
1143 | if ((ret->cert=ssl_cert_new()) == NULL) | ||
1144 | goto err; | ||
1145 | |||
1146 | ret->default_passwd_callback=NULL; | ||
1147 | ret->default_passwd_callback_userdata=NULL; | ||
1148 | ret->client_cert_cb=NULL; | ||
1149 | |||
1150 | ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp); | ||
1151 | if (ret->sessions == NULL) goto err; | ||
1152 | ret->cert_store=X509_STORE_new(); | ||
1153 | if (ret->cert_store == NULL) goto err; | ||
1154 | |||
1155 | ssl_create_cipher_list(ret->method, | ||
1156 | &ret->cipher_list,&ret->cipher_list_by_id, | ||
1157 | SSL_DEFAULT_CIPHER_LIST); | ||
1158 | if (ret->cipher_list == NULL | ||
1159 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) | ||
1160 | { | ||
1161 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS); | ||
1162 | goto err2; | ||
1163 | } | ||
1164 | |||
1165 | if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL) | ||
1166 | { | ||
1167 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); | ||
1168 | goto err2; | ||
1169 | } | ||
1170 | if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL) | ||
1171 | { | ||
1172 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES); | ||
1173 | goto err2; | ||
1174 | } | ||
1175 | if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL) | ||
1176 | { | ||
1177 | SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES); | ||
1178 | goto err2; | ||
1179 | } | ||
1180 | |||
1181 | if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL) | ||
1182 | goto err; | ||
1183 | |||
1184 | CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data); | ||
1185 | |||
1186 | ret->extra_certs=NULL; | ||
1187 | ret->comp_methods=SSL_COMP_get_compression_methods(); | ||
1188 | |||
1189 | return(ret); | ||
1190 | err: | ||
1191 | SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE); | ||
1192 | err2: | ||
1193 | if (ret != NULL) SSL_CTX_free(ret); | ||
1194 | return(NULL); | ||
1195 | } | ||
1196 | |||
1197 | static void SSL_COMP_free(SSL_COMP *comp) | ||
1198 | { Free(comp); } | ||
1199 | |||
1200 | void SSL_CTX_free(SSL_CTX *a) | ||
1201 | { | ||
1202 | int i; | ||
1203 | |||
1204 | if (a == NULL) return; | ||
1205 | |||
1206 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX); | ||
1207 | #ifdef REF_PRINT | ||
1208 | REF_PRINT("SSL_CTX",a); | ||
1209 | #endif | ||
1210 | if (i > 0) return; | ||
1211 | #ifdef REF_CHECK | ||
1212 | if (i < 0) | ||
1213 | { | ||
1214 | fprintf(stderr,"SSL_CTX_free, bad reference count\n"); | ||
1215 | abort(); /* ok */ | ||
1216 | } | ||
1217 | #endif | ||
1218 | CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data); | ||
1219 | |||
1220 | if (a->sessions != NULL) | ||
1221 | { | ||
1222 | SSL_CTX_flush_sessions(a,0); | ||
1223 | lh_free(a->sessions); | ||
1224 | } | ||
1225 | if (a->cert_store != NULL) | ||
1226 | X509_STORE_free(a->cert_store); | ||
1227 | if (a->cipher_list != NULL) | ||
1228 | sk_SSL_CIPHER_free(a->cipher_list); | ||
1229 | if (a->cipher_list_by_id != NULL) | ||
1230 | sk_SSL_CIPHER_free(a->cipher_list_by_id); | ||
1231 | if (a->cert != NULL) | ||
1232 | ssl_cert_free(a->cert); | ||
1233 | if (a->client_CA != NULL) | ||
1234 | sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free); | ||
1235 | if (a->extra_certs != NULL) | ||
1236 | sk_X509_pop_free(a->extra_certs,X509_free); | ||
1237 | if (a->comp_methods != NULL) | ||
1238 | sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free); | ||
1239 | Free(a); | ||
1240 | } | ||
1241 | |||
1242 | void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) | ||
1243 | { | ||
1244 | ctx->default_passwd_callback=cb; | ||
1245 | } | ||
1246 | |||
1247 | void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u) | ||
1248 | { | ||
1249 | ctx->default_passwd_callback_userdata=u; | ||
1250 | } | ||
1251 | |||
1252 | void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,int (*cb)(),char *arg) | ||
1253 | { | ||
1254 | /* now | ||
1255 | * int (*cb)(X509_STORE_CTX *), | ||
1256 | * but should be | ||
1257 | * int (*cb)(X509_STORE_CTX *, void *arg) | ||
1258 | */ | ||
1259 | ctx->app_verify_callback=cb; | ||
1260 | ctx->app_verify_arg=arg; /* never used */ | ||
1261 | } | ||
1262 | |||
1263 | void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *)) | ||
1264 | { | ||
1265 | ctx->verify_mode=mode; | ||
1266 | ctx->default_verify_callback=cb; | ||
1267 | /* This needs cleaning up EAY EAY EAY */ | ||
1268 | X509_STORE_set_verify_cb_func(ctx->cert_store,cb); | ||
1269 | } | ||
1270 | |||
1271 | void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth) | ||
1272 | { | ||
1273 | ctx->verify_depth=depth; | ||
1274 | } | ||
1275 | |||
1276 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher) | ||
1277 | { | ||
1278 | CERT_PKEY *cpk; | ||
1279 | int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign; | ||
1280 | int rsa_enc_export,dh_rsa_export,dh_dsa_export; | ||
1281 | int rsa_tmp_export,dh_tmp_export,kl; | ||
1282 | unsigned long mask,emask; | ||
1283 | |||
1284 | if (c == NULL) return; | ||
1285 | |||
1286 | kl=SSL_C_EXPORT_PKEYLENGTH(cipher); | ||
1287 | |||
1288 | #ifndef NO_RSA | ||
1289 | rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL); | ||
1290 | rsa_tmp_export=(c->rsa_tmp_cb != NULL || | ||
1291 | (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl)); | ||
1292 | #else | ||
1293 | rsa_tmp=rsa_tmp_export=0; | ||
1294 | #endif | ||
1295 | #ifndef NO_DH | ||
1296 | dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL); | ||
1297 | dh_tmp_export=(c->dh_tmp_cb != NULL || | ||
1298 | (dh_tmp && DH_size(c->dh_tmp)*8 <= kl)); | ||
1299 | #else | ||
1300 | dh_tmp=dh_tmp_export=0; | ||
1301 | #endif | ||
1302 | |||
1303 | cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]); | ||
1304 | rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1305 | rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1306 | cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]); | ||
1307 | rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1308 | cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]); | ||
1309 | dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1310 | cpk= &(c->pkeys[SSL_PKEY_DH_RSA]); | ||
1311 | dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1312 | dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1313 | cpk= &(c->pkeys[SSL_PKEY_DH_DSA]); | ||
1314 | /* FIX THIS EAY EAY EAY */ | ||
1315 | dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL); | ||
1316 | dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl); | ||
1317 | |||
1318 | mask=0; | ||
1319 | emask=0; | ||
1320 | |||
1321 | #ifdef CIPHER_DEBUG | ||
1322 | printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n", | ||
1323 | rsa_tmp,rsa_tmp_export,dh_tmp, | ||
1324 | rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa); | ||
1325 | #endif | ||
1326 | |||
1327 | if (rsa_enc || (rsa_tmp && rsa_sign)) | ||
1328 | mask|=SSL_kRSA; | ||
1329 | if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc))) | ||
1330 | emask|=SSL_kRSA; | ||
1331 | |||
1332 | #if 0 | ||
1333 | /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */ | ||
1334 | if ( (dh_tmp || dh_rsa || dh_dsa) && | ||
1335 | (rsa_enc || rsa_sign || dsa_sign)) | ||
1336 | mask|=SSL_kEDH; | ||
1337 | if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) && | ||
1338 | (rsa_enc || rsa_sign || dsa_sign)) | ||
1339 | emask|=SSL_kEDH; | ||
1340 | #endif | ||
1341 | |||
1342 | if (dh_tmp_export) | ||
1343 | emask|=SSL_kEDH; | ||
1344 | |||
1345 | if (dh_tmp) | ||
1346 | mask|=SSL_kEDH; | ||
1347 | |||
1348 | if (dh_rsa) mask|=SSL_kDHr; | ||
1349 | if (dh_rsa_export) emask|=SSL_kDHr; | ||
1350 | |||
1351 | if (dh_dsa) mask|=SSL_kDHd; | ||
1352 | if (dh_dsa_export) emask|=SSL_kDHd; | ||
1353 | |||
1354 | if (rsa_enc || rsa_sign) | ||
1355 | { | ||
1356 | mask|=SSL_aRSA; | ||
1357 | emask|=SSL_aRSA; | ||
1358 | } | ||
1359 | |||
1360 | if (dsa_sign) | ||
1361 | { | ||
1362 | mask|=SSL_aDSS; | ||
1363 | emask|=SSL_aDSS; | ||
1364 | } | ||
1365 | |||
1366 | mask|=SSL_aNULL; | ||
1367 | emask|=SSL_aNULL; | ||
1368 | |||
1369 | c->mask=mask; | ||
1370 | c->export_mask=emask; | ||
1371 | c->valid=1; | ||
1372 | } | ||
1373 | |||
1374 | /* THIS NEEDS CLEANING UP */ | ||
1375 | X509 *ssl_get_server_send_cert(SSL *s) | ||
1376 | { | ||
1377 | unsigned long alg,mask,kalg; | ||
1378 | CERT *c; | ||
1379 | int i,is_export; | ||
1380 | |||
1381 | c=s->cert; | ||
1382 | ssl_set_cert_masks(c, s->s3->tmp.new_cipher); | ||
1383 | alg=s->s3->tmp.new_cipher->algorithms; | ||
1384 | is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | ||
1385 | mask=is_export?c->export_mask:c->mask; | ||
1386 | kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK); | ||
1387 | |||
1388 | if (kalg & SSL_kDHr) | ||
1389 | i=SSL_PKEY_DH_RSA; | ||
1390 | else if (kalg & SSL_kDHd) | ||
1391 | i=SSL_PKEY_DH_DSA; | ||
1392 | else if (kalg & SSL_aDSS) | ||
1393 | i=SSL_PKEY_DSA_SIGN; | ||
1394 | else if (kalg & SSL_aRSA) | ||
1395 | { | ||
1396 | if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL) | ||
1397 | i=SSL_PKEY_RSA_SIGN; | ||
1398 | else | ||
1399 | i=SSL_PKEY_RSA_ENC; | ||
1400 | } | ||
1401 | else /* if (kalg & SSL_aNULL) */ | ||
1402 | { | ||
1403 | SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR); | ||
1404 | return(NULL); | ||
1405 | } | ||
1406 | if (c->pkeys[i].x509 == NULL) return(NULL); | ||
1407 | return(c->pkeys[i].x509); | ||
1408 | } | ||
1409 | |||
1410 | EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher) | ||
1411 | { | ||
1412 | unsigned long alg; | ||
1413 | CERT *c; | ||
1414 | |||
1415 | alg=cipher->algorithms; | ||
1416 | c=s->cert; | ||
1417 | |||
1418 | if ((alg & SSL_aDSS) && | ||
1419 | (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL)) | ||
1420 | return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey); | ||
1421 | else if (alg & SSL_aRSA) | ||
1422 | { | ||
1423 | if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL) | ||
1424 | return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey); | ||
1425 | else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL) | ||
1426 | return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey); | ||
1427 | else | ||
1428 | return(NULL); | ||
1429 | } | ||
1430 | else /* if (alg & SSL_aNULL) */ | ||
1431 | { | ||
1432 | SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR); | ||
1433 | return(NULL); | ||
1434 | } | ||
1435 | } | ||
1436 | |||
1437 | void ssl_update_cache(SSL *s,int mode) | ||
1438 | { | ||
1439 | int i; | ||
1440 | |||
1441 | /* If the session_id_length is 0, we are not supposed to cache it, | ||
1442 | * and it would be rather hard to do anyway :-) */ | ||
1443 | if (s->session->session_id_length == 0) return; | ||
1444 | |||
1445 | if ((s->ctx->session_cache_mode & mode) | ||
1446 | && (!s->hit) | ||
1447 | && SSL_CTX_add_session(s->ctx,s->session) | ||
1448 | && (s->ctx->new_session_cb != NULL)) | ||
1449 | { | ||
1450 | CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
1451 | if (!s->ctx->new_session_cb(s,s->session)) | ||
1452 | SSL_SESSION_free(s->session); | ||
1453 | } | ||
1454 | |||
1455 | /* auto flush every 255 connections */ | ||
1456 | i=s->ctx->session_cache_mode; | ||
1457 | if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && | ||
1458 | ((i & mode) == mode)) | ||
1459 | { | ||
1460 | if ( (((mode & SSL_SESS_CACHE_CLIENT) | ||
1461 | ?s->ctx->stats.sess_connect_good | ||
1462 | :s->ctx->stats.sess_accept_good) & 0xff) == 0xff) | ||
1463 | { | ||
1464 | SSL_CTX_flush_sessions(s->ctx,time(NULL)); | ||
1465 | } | ||
1466 | } | ||
1467 | } | ||
1468 | |||
1469 | SSL_METHOD *SSL_get_ssl_method(SSL *s) | ||
1470 | { | ||
1471 | return(s->method); | ||
1472 | } | ||
1473 | |||
1474 | int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth) | ||
1475 | { | ||
1476 | int conn= -1; | ||
1477 | int ret=1; | ||
1478 | |||
1479 | if (s->method != meth) | ||
1480 | { | ||
1481 | if (s->handshake_func != NULL) | ||
1482 | conn=(s->handshake_func == s->method->ssl_connect); | ||
1483 | |||
1484 | if (s->method->version == meth->version) | ||
1485 | s->method=meth; | ||
1486 | else | ||
1487 | { | ||
1488 | s->method->ssl_free(s); | ||
1489 | s->method=meth; | ||
1490 | ret=s->method->ssl_new(s); | ||
1491 | } | ||
1492 | |||
1493 | if (conn == 1) | ||
1494 | s->handshake_func=meth->ssl_connect; | ||
1495 | else if (conn == 0) | ||
1496 | s->handshake_func=meth->ssl_accept; | ||
1497 | } | ||
1498 | return(ret); | ||
1499 | } | ||
1500 | |||
1501 | int SSL_get_error(SSL *s,int i) | ||
1502 | { | ||
1503 | int reason; | ||
1504 | unsigned long l; | ||
1505 | BIO *bio; | ||
1506 | |||
1507 | if (i > 0) return(SSL_ERROR_NONE); | ||
1508 | |||
1509 | /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake | ||
1510 | * etc, where we do encode the error */ | ||
1511 | if ((l=ERR_peek_error()) != 0) | ||
1512 | { | ||
1513 | if (ERR_GET_LIB(l) == ERR_LIB_SYS) | ||
1514 | return(SSL_ERROR_SYSCALL); | ||
1515 | else | ||
1516 | return(SSL_ERROR_SSL); | ||
1517 | } | ||
1518 | |||
1519 | if ((i < 0) && SSL_want_read(s)) | ||
1520 | { | ||
1521 | bio=SSL_get_rbio(s); | ||
1522 | if (BIO_should_read(bio)) | ||
1523 | return(SSL_ERROR_WANT_READ); | ||
1524 | else if (BIO_should_write(bio)) | ||
1525 | /* This one doesn't make too much sense ... We never try | ||
1526 | * to write to the rbio, and an application program where | ||
1527 | * rbio and wbio are separate couldn't even know what it | ||
1528 | * should wait for. | ||
1529 | * However if we ever set s->rwstate incorrectly | ||
1530 | * (so that we have SSL_want_read(s) instead of | ||
1531 | * SSL_want_write(s)) and rbio and wbio *are* the same, | ||
1532 | * this test works around that bug; so it might be safer | ||
1533 | * to keep it. */ | ||
1534 | return(SSL_ERROR_WANT_WRITE); | ||
1535 | else if (BIO_should_io_special(bio)) | ||
1536 | { | ||
1537 | reason=BIO_get_retry_reason(bio); | ||
1538 | if (reason == BIO_RR_CONNECT) | ||
1539 | return(SSL_ERROR_WANT_CONNECT); | ||
1540 | else | ||
1541 | return(SSL_ERROR_SYSCALL); /* unknown */ | ||
1542 | } | ||
1543 | } | ||
1544 | |||
1545 | if ((i < 0) && SSL_want_write(s)) | ||
1546 | { | ||
1547 | bio=SSL_get_wbio(s); | ||
1548 | if (BIO_should_write(bio)) | ||
1549 | return(SSL_ERROR_WANT_WRITE); | ||
1550 | else if (BIO_should_read(bio)) | ||
1551 | /* See above (SSL_want_read(s) with BIO_should_write(bio)) */ | ||
1552 | return(SSL_ERROR_WANT_READ); | ||
1553 | else if (BIO_should_io_special(bio)) | ||
1554 | { | ||
1555 | reason=BIO_get_retry_reason(bio); | ||
1556 | if (reason == BIO_RR_CONNECT) | ||
1557 | return(SSL_ERROR_WANT_CONNECT); | ||
1558 | else | ||
1559 | return(SSL_ERROR_SYSCALL); | ||
1560 | } | ||
1561 | } | ||
1562 | if ((i < 0) && SSL_want_x509_lookup(s)) | ||
1563 | { | ||
1564 | return(SSL_ERROR_WANT_X509_LOOKUP); | ||
1565 | } | ||
1566 | |||
1567 | if (i == 0) | ||
1568 | { | ||
1569 | if (s->version == SSL2_VERSION) | ||
1570 | { | ||
1571 | /* assume it is the socket being closed */ | ||
1572 | return(SSL_ERROR_ZERO_RETURN); | ||
1573 | } | ||
1574 | else | ||
1575 | { | ||
1576 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && | ||
1577 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) | ||
1578 | return(SSL_ERROR_ZERO_RETURN); | ||
1579 | } | ||
1580 | } | ||
1581 | return(SSL_ERROR_SYSCALL); | ||
1582 | } | ||
1583 | |||
1584 | int SSL_do_handshake(SSL *s) | ||
1585 | { | ||
1586 | int ret=1; | ||
1587 | |||
1588 | if (s->handshake_func == NULL) | ||
1589 | { | ||
1590 | SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET); | ||
1591 | return(-1); | ||
1592 | } | ||
1593 | |||
1594 | s->method->ssl_renegotiate_check(s); | ||
1595 | |||
1596 | if (SSL_in_init(s) || SSL_in_before(s)) | ||
1597 | { | ||
1598 | ret=s->handshake_func(s); | ||
1599 | } | ||
1600 | return(ret); | ||
1601 | } | ||
1602 | |||
1603 | /* For the next 2 functions, SSL_clear() sets shutdown and so | ||
1604 | * one of these calls will reset it */ | ||
1605 | void SSL_set_accept_state(SSL *s) | ||
1606 | { | ||
1607 | s->server=1; | ||
1608 | s->shutdown=0; | ||
1609 | s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE; | ||
1610 | s->handshake_func=s->method->ssl_accept; | ||
1611 | /* clear the current cipher */ | ||
1612 | ssl_clear_cipher_ctx(s); | ||
1613 | } | ||
1614 | |||
1615 | void SSL_set_connect_state(SSL *s) | ||
1616 | { | ||
1617 | s->server=0; | ||
1618 | s->shutdown=0; | ||
1619 | s->state=SSL_ST_CONNECT|SSL_ST_BEFORE; | ||
1620 | s->handshake_func=s->method->ssl_connect; | ||
1621 | /* clear the current cipher */ | ||
1622 | ssl_clear_cipher_ctx(s); | ||
1623 | } | ||
1624 | |||
1625 | int ssl_undefined_function(SSL *s) | ||
1626 | { | ||
1627 | SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1628 | return(0); | ||
1629 | } | ||
1630 | |||
1631 | SSL_METHOD *ssl_bad_method(int ver) | ||
1632 | { | ||
1633 | SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1634 | return(NULL); | ||
1635 | } | ||
1636 | |||
1637 | const char *SSL_get_version(SSL *s) | ||
1638 | { | ||
1639 | if (s->version == TLS1_VERSION) | ||
1640 | return("TLSv1"); | ||
1641 | else if (s->version == SSL3_VERSION) | ||
1642 | return("SSLv3"); | ||
1643 | else if (s->version == SSL2_VERSION) | ||
1644 | return("SSLv2"); | ||
1645 | else | ||
1646 | return("unknown"); | ||
1647 | } | ||
1648 | |||
1649 | SSL *SSL_dup(SSL *s) | ||
1650 | { | ||
1651 | STACK_OF(X509_NAME) *sk; | ||
1652 | X509_NAME *xn; | ||
1653 | SSL *ret; | ||
1654 | int i; | ||
1655 | |||
1656 | if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL) | ||
1657 | return(NULL); | ||
1658 | |||
1659 | if (s->session != NULL) | ||
1660 | { | ||
1661 | /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */ | ||
1662 | SSL_copy_session_id(ret,s); | ||
1663 | } | ||
1664 | else | ||
1665 | { | ||
1666 | /* No session has been established yet, so we have to expect | ||
1667 | * that s->cert or ret->cert will be changed later -- | ||
1668 | * they should not both point to the same object, | ||
1669 | * and thus we can't use SSL_copy_session_id. */ | ||
1670 | |||
1671 | ret->method = s->method; | ||
1672 | ret->method->ssl_new(ret); | ||
1673 | |||
1674 | if (s->cert != NULL) | ||
1675 | { | ||
1676 | ret->cert = ssl_cert_dup(s->cert); | ||
1677 | if (ret->cert == NULL) | ||
1678 | goto err; | ||
1679 | } | ||
1680 | |||
1681 | SSL_set_session_id_context(ret, | ||
1682 | s->sid_ctx, s->sid_ctx_length); | ||
1683 | } | ||
1684 | |||
1685 | SSL_set_read_ahead(ret,SSL_get_read_ahead(s)); | ||
1686 | SSL_set_verify(ret,SSL_get_verify_mode(s), | ||
1687 | SSL_get_verify_callback(s)); | ||
1688 | SSL_set_verify_depth(ret,SSL_get_verify_depth(s)); | ||
1689 | |||
1690 | SSL_set_info_callback(ret,SSL_get_info_callback(s)); | ||
1691 | |||
1692 | ret->debug=s->debug; | ||
1693 | ret->options=s->options; | ||
1694 | |||
1695 | /* copy app data, a little dangerous perhaps */ | ||
1696 | if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data)) | ||
1697 | goto err; | ||
1698 | |||
1699 | /* setup rbio, and wbio */ | ||
1700 | if (s->rbio != NULL) | ||
1701 | { | ||
1702 | if (!BIO_dup_state(s->rbio,(char *)&ret->rbio)) | ||
1703 | goto err; | ||
1704 | } | ||
1705 | if (s->wbio != NULL) | ||
1706 | { | ||
1707 | if (s->wbio != s->rbio) | ||
1708 | { | ||
1709 | if (!BIO_dup_state(s->wbio,(char *)&ret->wbio)) | ||
1710 | goto err; | ||
1711 | } | ||
1712 | else | ||
1713 | ret->wbio=ret->rbio; | ||
1714 | } | ||
1715 | |||
1716 | /* dup the cipher_list and cipher_list_by_id stacks */ | ||
1717 | if (s->cipher_list != NULL) | ||
1718 | { | ||
1719 | if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL) | ||
1720 | goto err; | ||
1721 | } | ||
1722 | if (s->cipher_list_by_id != NULL) | ||
1723 | if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id)) | ||
1724 | == NULL) | ||
1725 | goto err; | ||
1726 | |||
1727 | /* Dup the client_CA list */ | ||
1728 | if (s->client_CA != NULL) | ||
1729 | { | ||
1730 | if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err; | ||
1731 | ret->client_CA=sk; | ||
1732 | for (i=0; i<sk_X509_NAME_num(sk); i++) | ||
1733 | { | ||
1734 | xn=sk_X509_NAME_value(sk,i); | ||
1735 | if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL) | ||
1736 | { | ||
1737 | X509_NAME_free(xn); | ||
1738 | goto err; | ||
1739 | } | ||
1740 | } | ||
1741 | } | ||
1742 | |||
1743 | ret->shutdown=s->shutdown; | ||
1744 | ret->state=s->state; | ||
1745 | ret->handshake_func=s->handshake_func; | ||
1746 | ret->server=s->server; | ||
1747 | |||
1748 | if (0) | ||
1749 | { | ||
1750 | err: | ||
1751 | if (ret != NULL) SSL_free(ret); | ||
1752 | ret=NULL; | ||
1753 | } | ||
1754 | return(ret); | ||
1755 | } | ||
1756 | |||
1757 | void ssl_clear_cipher_ctx(SSL *s) | ||
1758 | { | ||
1759 | if (s->enc_read_ctx != NULL) | ||
1760 | { | ||
1761 | EVP_CIPHER_CTX_cleanup(s->enc_read_ctx); | ||
1762 | Free(s->enc_read_ctx); | ||
1763 | s->enc_read_ctx=NULL; | ||
1764 | } | ||
1765 | if (s->enc_write_ctx != NULL) | ||
1766 | { | ||
1767 | EVP_CIPHER_CTX_cleanup(s->enc_write_ctx); | ||
1768 | Free(s->enc_write_ctx); | ||
1769 | s->enc_write_ctx=NULL; | ||
1770 | } | ||
1771 | if (s->expand != NULL) | ||
1772 | { | ||
1773 | COMP_CTX_free(s->expand); | ||
1774 | s->expand=NULL; | ||
1775 | } | ||
1776 | if (s->compress != NULL) | ||
1777 | { | ||
1778 | COMP_CTX_free(s->compress); | ||
1779 | s->compress=NULL; | ||
1780 | } | ||
1781 | } | ||
1782 | |||
1783 | /* Fix this function so that it takes an optional type parameter */ | ||
1784 | X509 *SSL_get_certificate(SSL *s) | ||
1785 | { | ||
1786 | if (s->cert != NULL) | ||
1787 | return(s->cert->key->x509); | ||
1788 | else | ||
1789 | return(NULL); | ||
1790 | } | ||
1791 | |||
1792 | /* Fix this function so that it takes an optional type parameter */ | ||
1793 | EVP_PKEY *SSL_get_privatekey(SSL *s) | ||
1794 | { | ||
1795 | if (s->cert != NULL) | ||
1796 | return(s->cert->key->privatekey); | ||
1797 | else | ||
1798 | return(NULL); | ||
1799 | } | ||
1800 | |||
1801 | SSL_CIPHER *SSL_get_current_cipher(SSL *s) | ||
1802 | { | ||
1803 | if ((s->session != NULL) && (s->session->cipher != NULL)) | ||
1804 | return(s->session->cipher); | ||
1805 | return(NULL); | ||
1806 | } | ||
1807 | |||
1808 | int ssl_init_wbio_buffer(SSL *s,int push) | ||
1809 | { | ||
1810 | BIO *bbio; | ||
1811 | |||
1812 | if (s->bbio == NULL) | ||
1813 | { | ||
1814 | bbio=BIO_new(BIO_f_buffer()); | ||
1815 | if (bbio == NULL) return(0); | ||
1816 | s->bbio=bbio; | ||
1817 | } | ||
1818 | else | ||
1819 | { | ||
1820 | bbio=s->bbio; | ||
1821 | if (s->bbio == s->wbio) | ||
1822 | s->wbio=BIO_pop(s->wbio); | ||
1823 | } | ||
1824 | (void)BIO_reset(bbio); | ||
1825 | /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */ | ||
1826 | if (!BIO_set_read_buffer_size(bbio,1)) | ||
1827 | { | ||
1828 | SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB); | ||
1829 | return(0); | ||
1830 | } | ||
1831 | if (push) | ||
1832 | { | ||
1833 | if (s->wbio != bbio) | ||
1834 | s->wbio=BIO_push(bbio,s->wbio); | ||
1835 | } | ||
1836 | else | ||
1837 | { | ||
1838 | if (s->wbio == bbio) | ||
1839 | s->wbio=BIO_pop(bbio); | ||
1840 | } | ||
1841 | return(1); | ||
1842 | } | ||
1843 | |||
1844 | void ssl_free_wbio_buffer(SSL *s) | ||
1845 | { | ||
1846 | BIO *under; | ||
1847 | |||
1848 | if (s->bbio == NULL) return; | ||
1849 | |||
1850 | if (s->bbio == s->wbio) | ||
1851 | { | ||
1852 | /* remove buffering */ | ||
1853 | under=BIO_pop(s->wbio); | ||
1854 | if (under != NULL) | ||
1855 | s->wbio=under; | ||
1856 | else | ||
1857 | abort(); /* ok */ | ||
1858 | } | ||
1859 | BIO_free(s->bbio); | ||
1860 | s->bbio=NULL; | ||
1861 | } | ||
1862 | |||
1863 | void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode) | ||
1864 | { | ||
1865 | ctx->quiet_shutdown=mode; | ||
1866 | } | ||
1867 | |||
1868 | int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx) | ||
1869 | { | ||
1870 | return(ctx->quiet_shutdown); | ||
1871 | } | ||
1872 | |||
1873 | void SSL_set_quiet_shutdown(SSL *s,int mode) | ||
1874 | { | ||
1875 | s->quiet_shutdown=mode; | ||
1876 | } | ||
1877 | |||
1878 | int SSL_get_quiet_shutdown(SSL *s) | ||
1879 | { | ||
1880 | return(s->quiet_shutdown); | ||
1881 | } | ||
1882 | |||
1883 | void SSL_set_shutdown(SSL *s,int mode) | ||
1884 | { | ||
1885 | s->shutdown=mode; | ||
1886 | } | ||
1887 | |||
1888 | int SSL_get_shutdown(SSL *s) | ||
1889 | { | ||
1890 | return(s->shutdown); | ||
1891 | } | ||
1892 | |||
1893 | int SSL_version(SSL *s) | ||
1894 | { | ||
1895 | return(s->version); | ||
1896 | } | ||
1897 | |||
1898 | SSL_CTX *SSL_get_SSL_CTX(SSL *ssl) | ||
1899 | { | ||
1900 | return(ssl->ctx); | ||
1901 | } | ||
1902 | |||
1903 | #ifndef NO_STDIO | ||
1904 | int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) | ||
1905 | { | ||
1906 | return(X509_STORE_set_default_paths(ctx->cert_store)); | ||
1907 | } | ||
1908 | |||
1909 | int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile, | ||
1910 | const char *CApath) | ||
1911 | { | ||
1912 | return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath)); | ||
1913 | } | ||
1914 | #endif | ||
1915 | |||
1916 | void SSL_set_info_callback(SSL *ssl,void (*cb)()) | ||
1917 | { | ||
1918 | ssl->info_callback=cb; | ||
1919 | } | ||
1920 | |||
1921 | void (*SSL_get_info_callback(SSL *ssl))(void) | ||
1922 | { | ||
1923 | return((void (*)())ssl->info_callback); | ||
1924 | } | ||
1925 | |||
1926 | int SSL_state(SSL *ssl) | ||
1927 | { | ||
1928 | return(ssl->state); | ||
1929 | } | ||
1930 | |||
1931 | void SSL_set_verify_result(SSL *ssl,long arg) | ||
1932 | { | ||
1933 | ssl->verify_result=arg; | ||
1934 | } | ||
1935 | |||
1936 | long SSL_get_verify_result(SSL *ssl) | ||
1937 | { | ||
1938 | return(ssl->verify_result); | ||
1939 | } | ||
1940 | |||
1941 | int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, | ||
1942 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) | ||
1943 | { | ||
1944 | ssl_meth_num++; | ||
1945 | return(CRYPTO_get_ex_new_index(ssl_meth_num-1, | ||
1946 | &ssl_meth,argl,argp,new_func,dup_func,free_func)); | ||
1947 | } | ||
1948 | |||
1949 | int SSL_set_ex_data(SSL *s,int idx,void *arg) | ||
1950 | { | ||
1951 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
1952 | } | ||
1953 | |||
1954 | void *SSL_get_ex_data(SSL *s,int idx) | ||
1955 | { | ||
1956 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
1957 | } | ||
1958 | |||
1959 | int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func, | ||
1960 | CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func) | ||
1961 | { | ||
1962 | ssl_ctx_meth_num++; | ||
1963 | return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1, | ||
1964 | &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func)); | ||
1965 | } | ||
1966 | |||
1967 | int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg) | ||
1968 | { | ||
1969 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
1970 | } | ||
1971 | |||
1972 | void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx) | ||
1973 | { | ||
1974 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
1975 | } | ||
1976 | |||
1977 | int ssl_ok(SSL *s) | ||
1978 | { | ||
1979 | return(1); | ||
1980 | } | ||
1981 | |||
1982 | X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx) | ||
1983 | { | ||
1984 | return(ctx->cert_store); | ||
1985 | } | ||
1986 | |||
1987 | void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store) | ||
1988 | { | ||
1989 | if (ctx->cert_store != NULL) | ||
1990 | X509_STORE_free(ctx->cert_store); | ||
1991 | ctx->cert_store=store; | ||
1992 | } | ||
1993 | |||
1994 | int SSL_want(SSL *s) | ||
1995 | { | ||
1996 | return(s->rwstate); | ||
1997 | } | ||
1998 | |||
1999 | /*! | ||
2000 | * \brief Set the callback for generating temporary RSA keys. | ||
2001 | * \param ctx the SSL context. | ||
2002 | * \param cb the callback | ||
2003 | */ | ||
2004 | |||
2005 | #ifndef NO_RSA | ||
2006 | void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl, | ||
2007 | int is_export, | ||
2008 | int keylength)) | ||
2009 | { | ||
2010 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
2011 | } | ||
2012 | |||
2013 | void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl, | ||
2014 | int is_export, | ||
2015 | int keylength)) | ||
2016 | { | ||
2017 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb); | ||
2018 | } | ||
2019 | #endif | ||
2020 | |||
2021 | #ifdef DOXYGEN | ||
2022 | /*! | ||
2023 | * \brief The RSA temporary key callback function. | ||
2024 | * \param ssl the SSL session. | ||
2025 | * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite. | ||
2026 | * \param keylength if \c is_export is \c TRUE, then \c keylength is the size | ||
2027 | * of the required key in bits. | ||
2028 | * \return the temporary RSA key. | ||
2029 | * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback | ||
2030 | */ | ||
2031 | |||
2032 | RSA *cb(SSL *ssl,int is_export,int keylength) | ||
2033 | {} | ||
2034 | #endif | ||
2035 | |||
2036 | /*! | ||
2037 | * \brief Set the callback for generating temporary DH keys. | ||
2038 | * \param ctx the SSL context. | ||
2039 | * \param dh the callback | ||
2040 | */ | ||
2041 | |||
2042 | #ifndef NO_DH | ||
2043 | void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export, | ||
2044 | int keylength)) | ||
2045 | { | ||
2046 | SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
2047 | } | ||
2048 | |||
2049 | void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export, | ||
2050 | int keylength)) | ||
2051 | { | ||
2052 | SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh); | ||
2053 | } | ||
2054 | #endif | ||
2055 | |||
2056 | #if defined(_WINDLL) && defined(WIN16) | ||
2057 | #include "../crypto/bio/bss_file.c" | ||
2058 | #endif | ||
2059 | |||
2060 | IMPLEMENT_STACK_OF(SSL_CIPHER) | ||
2061 | 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 9a52bab254..0000000000 --- a/src/lib/libssl/ssl_locl.h +++ /dev/null | |||
@@ -1,555 +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 | #ifndef HEADER_SSL_LOCL_H | ||
60 | #define HEADER_SSL_LOCL_H | ||
61 | #include <stdlib.h> | ||
62 | #include <time.h> | ||
63 | #include <string.h> | ||
64 | #include <errno.h> | ||
65 | |||
66 | #include "openssl/e_os.h" | ||
67 | |||
68 | #include <openssl/buffer.h> | ||
69 | #include <openssl/comp.h> | ||
70 | #include <openssl/bio.h> | ||
71 | #include <openssl/crypto.h> | ||
72 | #include <openssl/evp.h> | ||
73 | #include <openssl/stack.h> | ||
74 | #include <openssl/x509.h> | ||
75 | #include <openssl/err.h> | ||
76 | #include <openssl/ssl.h> | ||
77 | |||
78 | #define PKCS1_CHECK | ||
79 | |||
80 | #define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ | ||
81 | l|=(((unsigned long)(*((c)++)))<< 8), \ | ||
82 | l|=(((unsigned long)(*((c)++)))<<16), \ | ||
83 | l|=(((unsigned long)(*((c)++)))<<24)) | ||
84 | |||
85 | /* NOTE - c is not incremented as per c2l */ | ||
86 | #define c2ln(c,l1,l2,n) { \ | ||
87 | c+=n; \ | ||
88 | l1=l2=0; \ | ||
89 | switch (n) { \ | ||
90 | case 8: l2 =((unsigned long)(*(--(c))))<<24; \ | ||
91 | case 7: l2|=((unsigned long)(*(--(c))))<<16; \ | ||
92 | case 6: l2|=((unsigned long)(*(--(c))))<< 8; \ | ||
93 | case 5: l2|=((unsigned long)(*(--(c)))); \ | ||
94 | case 4: l1 =((unsigned long)(*(--(c))))<<24; \ | ||
95 | case 3: l1|=((unsigned long)(*(--(c))))<<16; \ | ||
96 | case 2: l1|=((unsigned long)(*(--(c))))<< 8; \ | ||
97 | case 1: l1|=((unsigned long)(*(--(c)))); \ | ||
98 | } \ | ||
99 | } | ||
100 | |||
101 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
102 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
103 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
104 | *((c)++)=(unsigned char)(((l)>>24)&0xff)) | ||
105 | |||
106 | #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \ | ||
107 | l|=((unsigned long)(*((c)++)))<<16, \ | ||
108 | l|=((unsigned long)(*((c)++)))<< 8, \ | ||
109 | l|=((unsigned long)(*((c)++)))) | ||
110 | |||
111 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ | ||
112 | *((c)++)=(unsigned char)(((l)>>16)&0xff), \ | ||
113 | *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ | ||
114 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
115 | |||
116 | /* NOTE - c is not incremented as per l2c */ | ||
117 | #define l2cn(l1,l2,c,n) { \ | ||
118 | c+=n; \ | ||
119 | switch (n) { \ | ||
120 | case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ | ||
121 | case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ | ||
122 | case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ | ||
123 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
124 | case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ | ||
125 | case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ | ||
126 | case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ | ||
127 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
128 | } \ | ||
129 | } | ||
130 | |||
131 | #define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \ | ||
132 | (((unsigned int)(c[1])) )),c+=2) | ||
133 | #define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \ | ||
134 | c[1]=(unsigned char)(((s) )&0xff)),c+=2) | ||
135 | |||
136 | #define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \ | ||
137 | (((unsigned long)(c[1]))<< 8)| \ | ||
138 | (((unsigned long)(c[2])) )),c+=3) | ||
139 | |||
140 | #define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \ | ||
141 | c[1]=(unsigned char)(((l)>> 8)&0xff), \ | ||
142 | c[2]=(unsigned char)(((l) )&0xff)),c+=3) | ||
143 | |||
144 | /* LOCAL STUFF */ | ||
145 | |||
146 | #define SSL_DECRYPT 0 | ||
147 | #define SSL_ENCRYPT 1 | ||
148 | |||
149 | #define TWO_BYTE_BIT 0x80 | ||
150 | #define SEC_ESC_BIT 0x40 | ||
151 | #define TWO_BYTE_MASK 0x7fff | ||
152 | #define THREE_BYTE_MASK 0x3fff | ||
153 | |||
154 | #define INC32(a) ((a)=((a)+1)&0xffffffffL) | ||
155 | #define DEC32(a) ((a)=((a)-1)&0xffffffffL) | ||
156 | #define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */ | ||
157 | |||
158 | /* | ||
159 | * Define the Bitmasks for SSL_CIPHER.algorithms. | ||
160 | * This bits are used packed as dense as possible. If new methods/ciphers | ||
161 | * etc will be added, the bits a likely to change, so this information | ||
162 | * is for internal library use only, even though SSL_CIPHER.algorithms | ||
163 | * can be publicly accessed. | ||
164 | * Use the according functions for cipher management instead. | ||
165 | * | ||
166 | * The bit mask handling in the selection and sorting scheme in | ||
167 | * ssl_create_cipher_list() has only limited capabilities, reflecting | ||
168 | * that the different entities within are mutually exclusive: | ||
169 | * ONLY ONE BIT PER MASK CAN BE SET AT A TIME. | ||
170 | */ | ||
171 | #define SSL_MKEY_MASK 0x0000001FL | ||
172 | #define SSL_kRSA 0x00000001L /* RSA key exchange */ | ||
173 | #define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */ | ||
174 | #define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */ | ||
175 | #define SSL_kFZA 0x00000008L | ||
176 | #define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */ | ||
177 | #define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL)) | ||
178 | |||
179 | #define SSL_AUTH_MASK 0x000003e0L | ||
180 | #define SSL_aRSA 0x00000020L /* Authenticate with RSA */ | ||
181 | #define SSL_aDSS 0x00000040L /* Authenticate with DSS */ | ||
182 | #define SSL_DSS SSL_aDSS | ||
183 | #define SSL_aFZA 0x00000080L | ||
184 | #define SSL_aNULL 0x00000100L /* no Authenticate, ADH */ | ||
185 | #define SSL_aDH 0x00000200L /* no Authenticate, ADH */ | ||
186 | |||
187 | #define SSL_NULL (SSL_eNULL) | ||
188 | #define SSL_ADH (SSL_kEDH|SSL_aNULL) | ||
189 | #define SSL_RSA (SSL_kRSA|SSL_aRSA) | ||
190 | #define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH) | ||
191 | #define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA) | ||
192 | |||
193 | #define SSL_ENC_MASK 0x0001Fc00L | ||
194 | #define SSL_DES 0x00000400L | ||
195 | #define SSL_3DES 0x00000800L | ||
196 | #define SSL_RC4 0x00001000L | ||
197 | #define SSL_RC2 0x00002000L | ||
198 | #define SSL_IDEA 0x00004000L | ||
199 | #define SSL_eFZA 0x00008000L | ||
200 | #define SSL_eNULL 0x00010000L | ||
201 | |||
202 | #define SSL_MAC_MASK 0x00060000L | ||
203 | #define SSL_MD5 0x00020000L | ||
204 | #define SSL_SHA1 0x00040000L | ||
205 | #define SSL_SHA (SSL_SHA1) | ||
206 | |||
207 | #define SSL_SSL_MASK 0x00180000L | ||
208 | #define SSL_SSLV2 0x00080000L | ||
209 | #define SSL_SSLV3 0x00100000L | ||
210 | #define SSL_TLSV1 SSL_SSLV3 /* for now */ | ||
211 | |||
212 | /* we have used 001fffff - 11 bits left to go */ | ||
213 | |||
214 | /* | ||
215 | * Export and cipher strength information. For each cipher we have to decide | ||
216 | * whether it is exportable or not. This information is likely to change | ||
217 | * over time, since the export control rules are no static technical issue. | ||
218 | * | ||
219 | * Independent of the export flag the cipher strength is sorted into classes. | ||
220 | * SSL_EXP40 was denoting the 40bit US export limit of past times, which now | ||
221 | * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change | ||
222 | * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more, | ||
223 | * since SSL_EXP64 could be similar to SSL_LOW. | ||
224 | * For this reason SSL_MICRO and SSL_MINI macros are included to widen the | ||
225 | * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed | ||
226 | * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would | ||
227 | * be possible. | ||
228 | */ | ||
229 | #define SSL_EXP_MASK 0x00000003L | ||
230 | #define SSL_NOT_EXP 0x00000001L | ||
231 | #define SSL_EXPORT 0x00000002L | ||
232 | |||
233 | #define SSL_STRONG_MASK 0x0000007cL | ||
234 | #define SSL_EXP40 0x00000004L | ||
235 | #define SSL_MICRO (SSL_EXP40) | ||
236 | #define SSL_EXP56 0x00000008L | ||
237 | #define SSL_MINI (SSL_EXP56) | ||
238 | #define SSL_LOW 0x00000010L | ||
239 | #define SSL_MEDIUM 0x00000020L | ||
240 | #define SSL_HIGH 0x00000040L | ||
241 | |||
242 | /* we have used 0000007f - 25 bits left to go */ | ||
243 | |||
244 | /* | ||
245 | * Macros to check the export status and cipher strength for export ciphers. | ||
246 | * Even though the macros for EXPORT and EXPORT40/56 have similar names, | ||
247 | * their meaning is different: | ||
248 | * *_EXPORT macros check the 'exportable' status. | ||
249 | * *_EXPORT40/56 macros are used to check whether a certain cipher strength | ||
250 | * is given. | ||
251 | * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct | ||
252 | * algorithm structure element to be passed (algorithms, algo_strength) and no | ||
253 | * typechecking can be done as they are all of type unsigned long, their | ||
254 | * direct usage is discouraged. | ||
255 | * Use the SSL_C_* macros instead. | ||
256 | */ | ||
257 | #define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT) | ||
258 | #define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56) | ||
259 | #define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40) | ||
260 | #define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength) | ||
261 | #define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength) | ||
262 | #define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength) | ||
263 | |||
264 | #define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \ | ||
265 | ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7) | ||
266 | #define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024) | ||
267 | #define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \ | ||
268 | (c)->algo_strength) | ||
269 | #define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength) | ||
270 | |||
271 | |||
272 | #define SSL_ALL 0xffffffffL | ||
273 | #define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\ | ||
274 | SSL_MAC_MASK) | ||
275 | #define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK) | ||
276 | |||
277 | /* Mostly for SSLv3 */ | ||
278 | #define SSL_PKEY_RSA_ENC 0 | ||
279 | #define SSL_PKEY_RSA_SIGN 1 | ||
280 | #define SSL_PKEY_DSA_SIGN 2 | ||
281 | #define SSL_PKEY_DH_RSA 3 | ||
282 | #define SSL_PKEY_DH_DSA 4 | ||
283 | #define SSL_PKEY_NUM 5 | ||
284 | |||
285 | /* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) | | ||
286 | * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN) | ||
287 | * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN) | ||
288 | * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN | ||
289 | * SSL_aRSA <- RSA_ENC | RSA_SIGN | ||
290 | * SSL_aDSS <- DSA_SIGN | ||
291 | */ | ||
292 | |||
293 | /* | ||
294 | #define CERT_INVALID 0 | ||
295 | #define CERT_PUBLIC_KEY 1 | ||
296 | #define CERT_PRIVATE_KEY 2 | ||
297 | */ | ||
298 | |||
299 | typedef struct cert_pkey_st | ||
300 | { | ||
301 | X509 *x509; | ||
302 | EVP_PKEY *privatekey; | ||
303 | } CERT_PKEY; | ||
304 | |||
305 | typedef struct cert_st | ||
306 | { | ||
307 | /* Current active set */ | ||
308 | CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array | ||
309 | * Probably it would make more sense to store | ||
310 | * an index, not a pointer. */ | ||
311 | |||
312 | /* The following masks are for the key and auth | ||
313 | * algorithms that are supported by the certs below */ | ||
314 | int valid; | ||
315 | unsigned long mask; | ||
316 | unsigned long export_mask; | ||
317 | #ifndef NO_RSA | ||
318 | RSA *rsa_tmp; | ||
319 | RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize); | ||
320 | #endif | ||
321 | #ifndef NO_DH | ||
322 | DH *dh_tmp; | ||
323 | DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize); | ||
324 | #endif | ||
325 | |||
326 | CERT_PKEY pkeys[SSL_PKEY_NUM]; | ||
327 | |||
328 | int references; /* >1 only if SSL_copy_session_id is used */ | ||
329 | } CERT; | ||
330 | |||
331 | |||
332 | typedef struct sess_cert_st | ||
333 | { | ||
334 | STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */ | ||
335 | |||
336 | /* The 'peer_...' members are used only by clients. */ | ||
337 | int peer_cert_type; | ||
338 | |||
339 | CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */ | ||
340 | CERT_PKEY peer_pkeys[SSL_PKEY_NUM]; | ||
341 | /* Obviously we don't have the private keys of these, | ||
342 | * so maybe we shouldn't even use the CERT_PKEY type here. */ | ||
343 | |||
344 | #ifndef NO_RSA | ||
345 | RSA *peer_rsa_tmp; /* not used for SSL 2 */ | ||
346 | #endif | ||
347 | #ifndef NO_DH | ||
348 | DH *peer_dh_tmp; /* not used for SSL 2 */ | ||
349 | #endif | ||
350 | |||
351 | int references; /* actually always 1 at the moment */ | ||
352 | } SESS_CERT; | ||
353 | |||
354 | |||
355 | /*#define MAC_DEBUG */ | ||
356 | |||
357 | /*#define ERR_DEBUG */ | ||
358 | /*#define ABORT_DEBUG */ | ||
359 | /*#define PKT_DEBUG 1 */ | ||
360 | /*#define DES_DEBUG */ | ||
361 | /*#define DES_OFB_DEBUG */ | ||
362 | /*#define SSL_DEBUG */ | ||
363 | /*#define RSA_DEBUG */ | ||
364 | /*#define IDEA_DEBUG */ | ||
365 | |||
366 | #define FP_ICC (int (*)(const void *,const void *)) | ||
367 | #define ssl_put_cipher_by_char(ssl,ciph,ptr) \ | ||
368 | ((ssl)->method->put_cipher_by_char((ciph),(ptr))) | ||
369 | #define ssl_get_cipher_by_char(ssl,ptr) \ | ||
370 | ((ssl)->method->get_cipher_by_char(ptr)) | ||
371 | |||
372 | /* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff | ||
373 | * It is a bit of a mess of functions, but hell, think of it as | ||
374 | * an opaque structure :-) */ | ||
375 | typedef struct ssl3_enc_method | ||
376 | { | ||
377 | int (*enc)(SSL *, int); | ||
378 | int (*mac)(SSL *, unsigned char *, int); | ||
379 | int (*setup_key_block)(SSL *); | ||
380 | int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int); | ||
381 | int (*change_cipher_state)(SSL *, int); | ||
382 | int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *); | ||
383 | int finish_mac_length; | ||
384 | int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *); | ||
385 | const char *client_finished_label; | ||
386 | int client_finished_label_len; | ||
387 | const char *server_finished_label; | ||
388 | int server_finished_label_len; | ||
389 | int (*alert_value)(int); | ||
390 | } SSL3_ENC_METHOD; | ||
391 | |||
392 | /* Used for holding the relevant compression methods loaded into SSL_CTX */ | ||
393 | typedef struct ssl3_comp_st | ||
394 | { | ||
395 | int comp_id; /* The identifier byte for this compression type */ | ||
396 | char *name; /* Text name used for the compression type */ | ||
397 | COMP_METHOD *method; /* The method :-) */ | ||
398 | } SSL3_COMP; | ||
399 | |||
400 | OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method; | ||
401 | OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[]; | ||
402 | OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[]; | ||
403 | |||
404 | #ifdef VMS | ||
405 | #undef SSL_COMP_get_compression_methods | ||
406 | #define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods | ||
407 | #endif | ||
408 | |||
409 | |||
410 | SSL_METHOD *ssl_bad_method(int ver); | ||
411 | SSL_METHOD *sslv2_base_method(void); | ||
412 | SSL_METHOD *sslv23_base_method(void); | ||
413 | SSL_METHOD *sslv3_base_method(void); | ||
414 | |||
415 | void ssl_clear_cipher_ctx(SSL *s); | ||
416 | int ssl_clear_bad_session(SSL *s); | ||
417 | CERT *ssl_cert_new(void); | ||
418 | CERT *ssl_cert_dup(CERT *cert); | ||
419 | int ssl_cert_inst(CERT **o); | ||
420 | void ssl_cert_free(CERT *c); | ||
421 | SESS_CERT *ssl_sess_cert_new(void); | ||
422 | void ssl_sess_cert_free(SESS_CERT *sc); | ||
423 | int ssl_set_peer_cert_type(SESS_CERT *c, int type); | ||
424 | int ssl_get_new_session(SSL *s, int session); | ||
425 | int ssl_get_prev_session(SSL *s, unsigned char *session,int len); | ||
426 | int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b); | ||
427 | int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp); | ||
428 | STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, | ||
429 | STACK_OF(SSL_CIPHER) **skp); | ||
430 | int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p); | ||
431 | STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, | ||
432 | STACK_OF(SSL_CIPHER) **pref, | ||
433 | STACK_OF(SSL_CIPHER) **sorted, | ||
434 | const char *rule_str); | ||
435 | void ssl_update_cache(SSL *s, int mode); | ||
436 | int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md, | ||
437 | SSL_COMP **comp); | ||
438 | int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk); | ||
439 | int ssl_undefined_function(SSL *s); | ||
440 | X509 *ssl_get_server_send_cert(SSL *); | ||
441 | EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *); | ||
442 | int ssl_cert_type(X509 *x,EVP_PKEY *pkey); | ||
443 | void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher); | ||
444 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); | ||
445 | int ssl_verify_alarm_type(long type); | ||
446 | |||
447 | int ssl2_enc_init(SSL *s, int client); | ||
448 | void ssl2_generate_key_material(SSL *s); | ||
449 | void ssl2_enc(SSL *s,int send_data); | ||
450 | void ssl2_mac(SSL *s,unsigned char *mac,int send_data); | ||
451 | SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p); | ||
452 | int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | ||
453 | int ssl2_part_read(SSL *s, unsigned long f, int i); | ||
454 | int ssl2_do_write(SSL *s); | ||
455 | int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data); | ||
456 | void ssl2_return_error(SSL *s,int reason); | ||
457 | void ssl2_write_error(SSL *s); | ||
458 | int ssl2_num_ciphers(void); | ||
459 | SSL_CIPHER *ssl2_get_cipher(unsigned int u); | ||
460 | int ssl2_new(SSL *s); | ||
461 | void ssl2_free(SSL *s); | ||
462 | int ssl2_accept(SSL *s); | ||
463 | int ssl2_connect(SSL *s); | ||
464 | int ssl2_read(SSL *s, void *buf, int len); | ||
465 | int ssl2_peek(SSL *s, char *buf, int len); | ||
466 | int ssl2_write(SSL *s, const void *buf, int len); | ||
467 | int ssl2_shutdown(SSL *s); | ||
468 | void ssl2_clear(SSL *s); | ||
469 | long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
470 | long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg); | ||
471 | long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
472 | long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | ||
473 | int ssl2_pending(SSL *s); | ||
474 | |||
475 | SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p); | ||
476 | int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p); | ||
477 | void ssl3_init_finished_mac(SSL *s); | ||
478 | int ssl3_send_server_certificate(SSL *s); | ||
479 | int ssl3_get_finished(SSL *s,int state_a,int state_b); | ||
480 | int ssl3_setup_key_block(SSL *s); | ||
481 | int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b); | ||
482 | int ssl3_change_cipher_state(SSL *s,int which); | ||
483 | void ssl3_cleanup_key_block(SSL *s); | ||
484 | int ssl3_do_write(SSL *s,int type); | ||
485 | void ssl3_send_alert(SSL *s,int level, int desc); | ||
486 | int ssl3_generate_master_secret(SSL *s, unsigned char *out, | ||
487 | unsigned char *p, int len); | ||
488 | int ssl3_get_req_cert_type(SSL *s,unsigned char *p); | ||
489 | long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok); | ||
490 | int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen); | ||
491 | int ssl3_num_ciphers(void); | ||
492 | SSL_CIPHER *ssl3_get_cipher(unsigned int u); | ||
493 | int ssl3_renegotiate(SSL *ssl); | ||
494 | int ssl3_renegotiate_check(SSL *ssl); | ||
495 | int ssl3_dispatch_alert(SSL *s); | ||
496 | int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len); | ||
497 | int ssl3_write_bytes(SSL *s, int type, const void *buf, int len); | ||
498 | int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2, | ||
499 | const char *sender, int slen,unsigned char *p); | ||
500 | int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
501 | void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len); | ||
502 | int ssl3_enc(SSL *s, int send_data); | ||
503 | int ssl3_mac(SSL *ssl, unsigned char *md, int send_data); | ||
504 | unsigned long ssl3_output_cert_chain(SSL *s, X509 *x); | ||
505 | SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *have, | ||
506 | STACK_OF(SSL_CIPHER) *pref); | ||
507 | int ssl3_setup_buffers(SSL *s); | ||
508 | int ssl3_new(SSL *s); | ||
509 | void ssl3_free(SSL *s); | ||
510 | int ssl3_accept(SSL *s); | ||
511 | int ssl3_connect(SSL *s); | ||
512 | int ssl3_read(SSL *s, void *buf, int len); | ||
513 | int ssl3_peek(SSL *s,char *buf, int len); | ||
514 | int ssl3_write(SSL *s, const void *buf, int len); | ||
515 | int ssl3_shutdown(SSL *s); | ||
516 | void ssl3_clear(SSL *s); | ||
517 | long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
518 | long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg); | ||
519 | long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
520 | long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)()); | ||
521 | int ssl3_pending(SSL *s); | ||
522 | |||
523 | int ssl23_accept(SSL *s); | ||
524 | int ssl23_connect(SSL *s); | ||
525 | int ssl23_read_bytes(SSL *s, int n); | ||
526 | int ssl23_write_bytes(SSL *s); | ||
527 | |||
528 | int tls1_new(SSL *s); | ||
529 | void tls1_free(SSL *s); | ||
530 | void tls1_clear(SSL *s); | ||
531 | long tls1_ctrl(SSL *s,int cmd, long larg, char *parg); | ||
532 | long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)()); | ||
533 | SSL_METHOD *tlsv1_base_method(void ); | ||
534 | |||
535 | int ssl_init_wbio_buffer(SSL *s, int push); | ||
536 | void ssl_free_wbio_buffer(SSL *s); | ||
537 | |||
538 | int tls1_change_cipher_state(SSL *s, int which); | ||
539 | int tls1_setup_key_block(SSL *s); | ||
540 | int tls1_enc(SSL *s, int snd); | ||
541 | int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | ||
542 | const char *str, int slen, unsigned char *p); | ||
543 | int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p); | ||
544 | int tls1_mac(SSL *ssl, unsigned char *md, int snd); | ||
545 | int tls1_generate_master_secret(SSL *s, unsigned char *out, | ||
546 | unsigned char *p, int len); | ||
547 | int tls1_alert_code(int code); | ||
548 | int ssl3_alert_code(int code); | ||
549 | int ssl_ok(SSL *s); | ||
550 | |||
551 | SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n); | ||
552 | STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void); | ||
553 | |||
554 | |||
555 | #endif | ||
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c deleted file mode 100644 index 6ec7a5cdb1..0000000000 --- a/src/lib/libssl/ssl_rsa.c +++ /dev/null | |||
@@ -1,815 +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 <openssl/bio.h> | ||
61 | #include <openssl/objects.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/x509.h> | ||
64 | #include <openssl/pem.h> | ||
65 | #include "ssl_locl.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 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 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 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_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 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 | if (c->pkeys[i].privatekey != NULL) | ||
245 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
246 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
247 | c->pkeys[i].privatekey=pkey; | ||
248 | c->key= &(c->pkeys[i]); | ||
249 | |||
250 | c->valid=0; | ||
251 | return(1); | ||
252 | } | ||
253 | |||
254 | #ifndef NO_RSA | ||
255 | #ifndef NO_STDIO | ||
256 | int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type) | ||
257 | { | ||
258 | int j,ret=0; | ||
259 | BIO *in; | ||
260 | RSA *rsa=NULL; | ||
261 | |||
262 | in=BIO_new(BIO_s_file_internal()); | ||
263 | if (in == NULL) | ||
264 | { | ||
265 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
266 | goto end; | ||
267 | } | ||
268 | |||
269 | if (BIO_read_filename(in,file) <= 0) | ||
270 | { | ||
271 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
272 | goto end; | ||
273 | } | ||
274 | if (type == SSL_FILETYPE_ASN1) | ||
275 | { | ||
276 | j=ERR_R_ASN1_LIB; | ||
277 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
278 | } | ||
279 | else if (type == SSL_FILETYPE_PEM) | ||
280 | { | ||
281 | j=ERR_R_PEM_LIB; | ||
282 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
283 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
288 | goto end; | ||
289 | } | ||
290 | if (rsa == NULL) | ||
291 | { | ||
292 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j); | ||
293 | goto end; | ||
294 | } | ||
295 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
296 | RSA_free(rsa); | ||
297 | end: | ||
298 | if (in != NULL) BIO_free(in); | ||
299 | return(ret); | ||
300 | } | ||
301 | #endif | ||
302 | |||
303 | int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len) | ||
304 | { | ||
305 | int ret; | ||
306 | unsigned char *p; | ||
307 | RSA *rsa; | ||
308 | |||
309 | p=d; | ||
310 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
311 | { | ||
312 | SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
313 | return(0); | ||
314 | } | ||
315 | |||
316 | ret=SSL_use_RSAPrivateKey(ssl,rsa); | ||
317 | RSA_free(rsa); | ||
318 | return(ret); | ||
319 | } | ||
320 | #endif /* !NO_RSA */ | ||
321 | |||
322 | int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey) | ||
323 | { | ||
324 | int ret; | ||
325 | |||
326 | if (pkey == NULL) | ||
327 | { | ||
328 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
329 | return(0); | ||
330 | } | ||
331 | if (!ssl_cert_inst(&ssl->cert)) | ||
332 | { | ||
333 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
334 | return(0); | ||
335 | } | ||
336 | ret=ssl_set_pkey(ssl->cert,pkey); | ||
337 | return(ret); | ||
338 | } | ||
339 | |||
340 | #ifndef NO_STDIO | ||
341 | int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type) | ||
342 | { | ||
343 | int j,ret=0; | ||
344 | BIO *in; | ||
345 | EVP_PKEY *pkey=NULL; | ||
346 | |||
347 | in=BIO_new(BIO_s_file_internal()); | ||
348 | if (in == NULL) | ||
349 | { | ||
350 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
351 | goto end; | ||
352 | } | ||
353 | |||
354 | if (BIO_read_filename(in,file) <= 0) | ||
355 | { | ||
356 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
357 | goto end; | ||
358 | } | ||
359 | if (type == SSL_FILETYPE_PEM) | ||
360 | { | ||
361 | j=ERR_R_PEM_LIB; | ||
362 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
363 | ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata); | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
368 | goto end; | ||
369 | } | ||
370 | if (pkey == NULL) | ||
371 | { | ||
372 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j); | ||
373 | goto end; | ||
374 | } | ||
375 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
376 | EVP_PKEY_free(pkey); | ||
377 | end: | ||
378 | if (in != NULL) BIO_free(in); | ||
379 | return(ret); | ||
380 | } | ||
381 | #endif | ||
382 | |||
383 | int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len) | ||
384 | { | ||
385 | int ret; | ||
386 | unsigned char *p; | ||
387 | EVP_PKEY *pkey; | ||
388 | |||
389 | p=d; | ||
390 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
391 | { | ||
392 | SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
393 | return(0); | ||
394 | } | ||
395 | |||
396 | ret=SSL_use_PrivateKey(ssl,pkey); | ||
397 | EVP_PKEY_free(pkey); | ||
398 | return(ret); | ||
399 | } | ||
400 | |||
401 | int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) | ||
402 | { | ||
403 | if (x == NULL) | ||
404 | { | ||
405 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER); | ||
406 | return(0); | ||
407 | } | ||
408 | if (!ssl_cert_inst(&ctx->cert)) | ||
409 | { | ||
410 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
411 | return(0); | ||
412 | } | ||
413 | return(ssl_set_cert(ctx->cert, x)); | ||
414 | } | ||
415 | |||
416 | static int ssl_set_cert(CERT *c, X509 *x) | ||
417 | { | ||
418 | EVP_PKEY *pkey; | ||
419 | int i,ok=0,bad=0; | ||
420 | |||
421 | pkey=X509_get_pubkey(x); | ||
422 | if (pkey == NULL) | ||
423 | { | ||
424 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB); | ||
425 | return(0); | ||
426 | } | ||
427 | |||
428 | i=ssl_cert_type(x,pkey); | ||
429 | if (i < 0) | ||
430 | { | ||
431 | SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE); | ||
432 | EVP_PKEY_free(pkey); | ||
433 | return(0); | ||
434 | } | ||
435 | |||
436 | if (c->pkeys[i].privatekey != NULL) | ||
437 | { | ||
438 | EVP_PKEY_copy_parameters(pkey,c->pkeys[i].privatekey); | ||
439 | ERR_clear_error(); | ||
440 | |||
441 | #ifndef NO_RSA | ||
442 | /* Don't check the public/private key, this is mostly | ||
443 | * for smart cards. */ | ||
444 | if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) && | ||
445 | (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) & | ||
446 | RSA_METHOD_FLAG_NO_CHECK)) | ||
447 | ok=1; | ||
448 | else | ||
449 | #endif | ||
450 | { | ||
451 | if (!X509_check_private_key(x,c->pkeys[i].privatekey)) | ||
452 | { | ||
453 | if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA)) | ||
454 | { | ||
455 | i=(i == SSL_PKEY_DH_RSA)? | ||
456 | SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA; | ||
457 | |||
458 | if (c->pkeys[i].privatekey == NULL) | ||
459 | ok=1; | ||
460 | else | ||
461 | { | ||
462 | if (!X509_check_private_key(x, | ||
463 | c->pkeys[i].privatekey)) | ||
464 | bad=1; | ||
465 | else | ||
466 | ok=1; | ||
467 | } | ||
468 | } | ||
469 | else | ||
470 | bad=1; | ||
471 | } | ||
472 | else | ||
473 | ok=1; | ||
474 | } /* NO_RSA */ | ||
475 | } | ||
476 | else | ||
477 | ok=1; | ||
478 | |||
479 | EVP_PKEY_free(pkey); | ||
480 | if (bad) | ||
481 | { | ||
482 | EVP_PKEY_free(c->pkeys[i].privatekey); | ||
483 | c->pkeys[i].privatekey=NULL; | ||
484 | } | ||
485 | |||
486 | if (c->pkeys[i].x509 != NULL) | ||
487 | X509_free(c->pkeys[i].x509); | ||
488 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | ||
489 | c->pkeys[i].x509=x; | ||
490 | c->key= &(c->pkeys[i]); | ||
491 | |||
492 | c->valid=0; | ||
493 | return(1); | ||
494 | } | ||
495 | |||
496 | #ifndef NO_STDIO | ||
497 | int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type) | ||
498 | { | ||
499 | int j; | ||
500 | BIO *in; | ||
501 | int ret=0; | ||
502 | X509 *x=NULL; | ||
503 | |||
504 | in=BIO_new(BIO_s_file_internal()); | ||
505 | if (in == NULL) | ||
506 | { | ||
507 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB); | ||
508 | goto end; | ||
509 | } | ||
510 | |||
511 | if (BIO_read_filename(in,file) <= 0) | ||
512 | { | ||
513 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB); | ||
514 | goto end; | ||
515 | } | ||
516 | if (type == SSL_FILETYPE_ASN1) | ||
517 | { | ||
518 | j=ERR_R_ASN1_LIB; | ||
519 | x=d2i_X509_bio(in,NULL); | ||
520 | } | ||
521 | else if (type == SSL_FILETYPE_PEM) | ||
522 | { | ||
523 | j=ERR_R_PEM_LIB; | ||
524 | x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
525 | } | ||
526 | else | ||
527 | { | ||
528 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
529 | goto end; | ||
530 | } | ||
531 | |||
532 | if (x == NULL) | ||
533 | { | ||
534 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j); | ||
535 | goto end; | ||
536 | } | ||
537 | |||
538 | ret=SSL_CTX_use_certificate(ctx,x); | ||
539 | end: | ||
540 | if (x != NULL) X509_free(x); | ||
541 | if (in != NULL) BIO_free(in); | ||
542 | return(ret); | ||
543 | } | ||
544 | #endif | ||
545 | |||
546 | int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d) | ||
547 | { | ||
548 | X509 *x; | ||
549 | int ret; | ||
550 | |||
551 | x=d2i_X509(NULL,&d,(long)len); | ||
552 | if (x == NULL) | ||
553 | { | ||
554 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB); | ||
555 | return(0); | ||
556 | } | ||
557 | |||
558 | ret=SSL_CTX_use_certificate(ctx,x); | ||
559 | X509_free(x); | ||
560 | return(ret); | ||
561 | } | ||
562 | |||
563 | #ifndef NO_RSA | ||
564 | int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa) | ||
565 | { | ||
566 | int ret; | ||
567 | EVP_PKEY *pkey; | ||
568 | |||
569 | if (rsa == NULL) | ||
570 | { | ||
571 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
572 | return(0); | ||
573 | } | ||
574 | if (!ssl_cert_inst(&ctx->cert)) | ||
575 | { | ||
576 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
577 | return(0); | ||
578 | } | ||
579 | if ((pkey=EVP_PKEY_new()) == NULL) | ||
580 | { | ||
581 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB); | ||
582 | return(0); | ||
583 | } | ||
584 | |||
585 | CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA); | ||
586 | EVP_PKEY_assign_RSA(pkey,rsa); | ||
587 | |||
588 | ret=ssl_set_pkey(ctx->cert, pkey); | ||
589 | EVP_PKEY_free(pkey); | ||
590 | return(ret); | ||
591 | } | ||
592 | |||
593 | #ifndef NO_STDIO | ||
594 | int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type) | ||
595 | { | ||
596 | int j,ret=0; | ||
597 | BIO *in; | ||
598 | RSA *rsa=NULL; | ||
599 | |||
600 | in=BIO_new(BIO_s_file_internal()); | ||
601 | if (in == NULL) | ||
602 | { | ||
603 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
604 | goto end; | ||
605 | } | ||
606 | |||
607 | if (BIO_read_filename(in,file) <= 0) | ||
608 | { | ||
609 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
610 | goto end; | ||
611 | } | ||
612 | if (type == SSL_FILETYPE_ASN1) | ||
613 | { | ||
614 | j=ERR_R_ASN1_LIB; | ||
615 | rsa=d2i_RSAPrivateKey_bio(in,NULL); | ||
616 | } | ||
617 | else if (type == SSL_FILETYPE_PEM) | ||
618 | { | ||
619 | j=ERR_R_PEM_LIB; | ||
620 | rsa=PEM_read_bio_RSAPrivateKey(in,NULL, | ||
621 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
622 | } | ||
623 | else | ||
624 | { | ||
625 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
626 | goto end; | ||
627 | } | ||
628 | if (rsa == NULL) | ||
629 | { | ||
630 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j); | ||
631 | goto end; | ||
632 | } | ||
633 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
634 | RSA_free(rsa); | ||
635 | end: | ||
636 | if (in != NULL) BIO_free(in); | ||
637 | return(ret); | ||
638 | } | ||
639 | #endif | ||
640 | |||
641 | int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len) | ||
642 | { | ||
643 | int ret; | ||
644 | unsigned char *p; | ||
645 | RSA *rsa; | ||
646 | |||
647 | p=d; | ||
648 | if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL) | ||
649 | { | ||
650 | SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
651 | return(0); | ||
652 | } | ||
653 | |||
654 | ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa); | ||
655 | RSA_free(rsa); | ||
656 | return(ret); | ||
657 | } | ||
658 | #endif /* !NO_RSA */ | ||
659 | |||
660 | int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey) | ||
661 | { | ||
662 | if (pkey == NULL) | ||
663 | { | ||
664 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER); | ||
665 | return(0); | ||
666 | } | ||
667 | if (!ssl_cert_inst(&ctx->cert)) | ||
668 | { | ||
669 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE); | ||
670 | return(0); | ||
671 | } | ||
672 | return(ssl_set_pkey(ctx->cert,pkey)); | ||
673 | } | ||
674 | |||
675 | #ifndef NO_STDIO | ||
676 | int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) | ||
677 | { | ||
678 | int j,ret=0; | ||
679 | BIO *in; | ||
680 | EVP_PKEY *pkey=NULL; | ||
681 | |||
682 | in=BIO_new(BIO_s_file_internal()); | ||
683 | if (in == NULL) | ||
684 | { | ||
685 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB); | ||
686 | goto end; | ||
687 | } | ||
688 | |||
689 | if (BIO_read_filename(in,file) <= 0) | ||
690 | { | ||
691 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB); | ||
692 | goto end; | ||
693 | } | ||
694 | if (type == SSL_FILETYPE_PEM) | ||
695 | { | ||
696 | j=ERR_R_PEM_LIB; | ||
697 | pkey=PEM_read_bio_PrivateKey(in,NULL, | ||
698 | ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
699 | } | ||
700 | else | ||
701 | { | ||
702 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE); | ||
703 | goto end; | ||
704 | } | ||
705 | if (pkey == NULL) | ||
706 | { | ||
707 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j); | ||
708 | goto end; | ||
709 | } | ||
710 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
711 | EVP_PKEY_free(pkey); | ||
712 | end: | ||
713 | if (in != NULL) BIO_free(in); | ||
714 | return(ret); | ||
715 | } | ||
716 | #endif | ||
717 | |||
718 | int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d, | ||
719 | long len) | ||
720 | { | ||
721 | int ret; | ||
722 | unsigned char *p; | ||
723 | EVP_PKEY *pkey; | ||
724 | |||
725 | p=d; | ||
726 | if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL) | ||
727 | { | ||
728 | SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB); | ||
729 | return(0); | ||
730 | } | ||
731 | |||
732 | ret=SSL_CTX_use_PrivateKey(ctx,pkey); | ||
733 | EVP_PKEY_free(pkey); | ||
734 | return(ret); | ||
735 | } | ||
736 | |||
737 | |||
738 | #ifndef NO_STDIO | ||
739 | /* Read a file that contains our certificate in "PEM" format, | ||
740 | * possibly followed by a sequence of CA certificates that should be | ||
741 | * sent to the peer in the Certificate message. | ||
742 | */ | ||
743 | int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | ||
744 | { | ||
745 | BIO *in; | ||
746 | int ret=0; | ||
747 | X509 *x=NULL; | ||
748 | |||
749 | in=BIO_new(BIO_s_file_internal()); | ||
750 | if (in == NULL) | ||
751 | { | ||
752 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_BUF_LIB); | ||
753 | goto end; | ||
754 | } | ||
755 | |||
756 | if (BIO_read_filename(in,file) <= 0) | ||
757 | { | ||
758 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_SYS_LIB); | ||
759 | goto end; | ||
760 | } | ||
761 | |||
762 | x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata); | ||
763 | if (x == NULL) | ||
764 | { | ||
765 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_PEM_LIB); | ||
766 | goto end; | ||
767 | } | ||
768 | |||
769 | ret=SSL_CTX_use_certificate(ctx,x); | ||
770 | if (ERR_peek_error() != 0) | ||
771 | ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */ | ||
772 | if (ret) | ||
773 | { | ||
774 | /* If we could set up our certificate, now proceed to | ||
775 | * the CA certificates. | ||
776 | */ | ||
777 | X509 *ca; | ||
778 | int r; | ||
779 | unsigned long err; | ||
780 | |||
781 | if (ctx->extra_certs != NULL) | ||
782 | { | ||
783 | sk_X509_pop_free(ctx->extra_certs, X509_free); | ||
784 | ctx->extra_certs = NULL; | ||
785 | } | ||
786 | |||
787 | while ((ca = PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata)) | ||
788 | != NULL) | ||
789 | { | ||
790 | r = SSL_CTX_add_extra_chain_cert(ctx, ca); | ||
791 | if (!r) | ||
792 | { | ||
793 | X509_free(ca); | ||
794 | ret = 0; | ||
795 | goto end; | ||
796 | } | ||
797 | /* Note that we must not free r if it was successfully | ||
798 | * added to the chain (while we must free the main | ||
799 | * certificate, since its reference count is increased | ||
800 | * by SSL_CTX_use_certificate). */ | ||
801 | } | ||
802 | /* When the while loop ends, it's usually just EOF. */ | ||
803 | err = ERR_peek_error(); | ||
804 | if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) | ||
805 | (void) ERR_get_error(); | ||
806 | else | ||
807 | ret = 0; /* some real error */ | ||
808 | } | ||
809 | |||
810 | end: | ||
811 | if (x != NULL) X509_free(x); | ||
812 | if (in != NULL) BIO_free(in); | ||
813 | return(ret); | ||
814 | } | ||
815 | #endif | ||
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c deleted file mode 100644 index 9e01f72753..0000000000 --- a/src/lib/libssl/ssl_sess.c +++ /dev/null | |||
@@ -1,680 +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 | static int ssl_session_num=0; | ||
68 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_session_meth=NULL; | ||
69 | |||
70 | SSL_SESSION *SSL_get_session(SSL *ssl) | ||
71 | /* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */ | ||
72 | { | ||
73 | return(ssl->session); | ||
74 | } | ||
75 | |||
76 | SSL_SESSION *SSL_get1_session(SSL *ssl) | ||
77 | /* variant of SSL_get_session: caller really gets something */ | ||
78 | { | ||
79 | SSL_SESSION *sess; | ||
80 | /* Need to lock this all up rather than just use CRYPTO_add so that | ||
81 | * somebody doesn't free ssl->session between when we check it's | ||
82 | * non-null and when we up the reference count. */ | ||
83 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_SESSION); | ||
84 | sess = ssl->session; | ||
85 | if(sess) | ||
86 | sess->references++; | ||
87 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_SESSION); | ||
88 | return(sess); | ||
89 | } | ||
90 | |||
91 | int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
92 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
93 | { | ||
94 | ssl_session_num++; | ||
95 | return(CRYPTO_get_ex_new_index(ssl_session_num-1, | ||
96 | &ssl_session_meth, | ||
97 | argl,argp,new_func,dup_func,free_func)); | ||
98 | } | ||
99 | |||
100 | int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg) | ||
101 | { | ||
102 | return(CRYPTO_set_ex_data(&s->ex_data,idx,arg)); | ||
103 | } | ||
104 | |||
105 | void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx) | ||
106 | { | ||
107 | return(CRYPTO_get_ex_data(&s->ex_data,idx)); | ||
108 | } | ||
109 | |||
110 | SSL_SESSION *SSL_SESSION_new(void) | ||
111 | { | ||
112 | SSL_SESSION *ss; | ||
113 | |||
114 | ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION)); | ||
115 | if (ss == NULL) | ||
116 | { | ||
117 | SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE); | ||
118 | return(0); | ||
119 | } | ||
120 | memset(ss,0,sizeof(SSL_SESSION)); | ||
121 | |||
122 | ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ | ||
123 | ss->references=1; | ||
124 | ss->timeout=60*5+4; /* 5 minute timeout by default */ | ||
125 | ss->time=time(NULL); | ||
126 | ss->prev=NULL; | ||
127 | ss->next=NULL; | ||
128 | ss->compress_meth=0; | ||
129 | CRYPTO_new_ex_data(ssl_session_meth,ss,&ss->ex_data); | ||
130 | return(ss); | ||
131 | } | ||
132 | |||
133 | int ssl_get_new_session(SSL *s, int session) | ||
134 | { | ||
135 | /* This gets used by clients and servers. */ | ||
136 | |||
137 | SSL_SESSION *ss=NULL; | ||
138 | |||
139 | if ((ss=SSL_SESSION_new()) == NULL) return(0); | ||
140 | |||
141 | /* If the context has a default timeout, use it */ | ||
142 | if (s->ctx->session_timeout == 0) | ||
143 | ss->timeout=SSL_get_default_timeout(s); | ||
144 | else | ||
145 | ss->timeout=s->ctx->session_timeout; | ||
146 | |||
147 | if (s->session != NULL) | ||
148 | { | ||
149 | SSL_SESSION_free(s->session); | ||
150 | s->session=NULL; | ||
151 | } | ||
152 | |||
153 | if (session) | ||
154 | { | ||
155 | if (s->version == SSL2_VERSION) | ||
156 | { | ||
157 | ss->ssl_version=SSL2_VERSION; | ||
158 | ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH; | ||
159 | } | ||
160 | else if (s->version == SSL3_VERSION) | ||
161 | { | ||
162 | ss->ssl_version=SSL3_VERSION; | ||
163 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
164 | } | ||
165 | else if (s->version == TLS1_VERSION) | ||
166 | { | ||
167 | ss->ssl_version=TLS1_VERSION; | ||
168 | ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH; | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION); | ||
173 | SSL_SESSION_free(ss); | ||
174 | return(0); | ||
175 | } | ||
176 | |||
177 | for (;;) | ||
178 | { | ||
179 | SSL_SESSION *r; | ||
180 | |||
181 | RAND_pseudo_bytes(ss->session_id,ss->session_id_length); | ||
182 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
183 | r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions, ss); | ||
184 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
185 | if (r == NULL) break; | ||
186 | /* else - woops a session_id match */ | ||
187 | /* XXX We should also check the external cache -- | ||
188 | * but the probability of a collision is negligible, and | ||
189 | * we could not prevent the concurrent creation of sessions | ||
190 | * with identical IDs since we currently don't have means | ||
191 | * to atomically check whether a session ID already exists | ||
192 | * and make a reservation for it if it does not | ||
193 | * (this problem applies to the internal cache as well). | ||
194 | */ | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | ss->session_id_length=0; | ||
200 | } | ||
201 | |||
202 | memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length); | ||
203 | ss->sid_ctx_length=s->sid_ctx_length; | ||
204 | s->session=ss; | ||
205 | ss->ssl_version=s->version; | ||
206 | ss->verify_result = X509_V_OK; | ||
207 | |||
208 | return(1); | ||
209 | } | ||
210 | |||
211 | int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len) | ||
212 | { | ||
213 | /* This is used only by servers. */ | ||
214 | |||
215 | SSL_SESSION *ret=NULL,data; | ||
216 | int fatal = 0; | ||
217 | |||
218 | data.ssl_version=s->version; | ||
219 | data.session_id_length=len; | ||
220 | if (len > SSL_MAX_SSL_SESSION_ID_LENGTH) | ||
221 | goto err; | ||
222 | memcpy(data.session_id,session_id,len); | ||
223 | |||
224 | if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) | ||
225 | { | ||
226 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | ||
227 | ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data); | ||
228 | if (ret != NULL) | ||
229 | /* don't allow other threads to steal it: */ | ||
230 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
231 | CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX); | ||
232 | } | ||
233 | |||
234 | if (ret == NULL) | ||
235 | { | ||
236 | int copy=1; | ||
237 | |||
238 | s->ctx->stats.sess_miss++; | ||
239 | ret=NULL; | ||
240 | if (s->ctx->get_session_cb != NULL | ||
241 | && (ret=s->ctx->get_session_cb(s,session_id,len,©)) | ||
242 | != NULL) | ||
243 | { | ||
244 | s->ctx->stats.sess_cb_hit++; | ||
245 | |||
246 | /* Increment reference count now if the session callback | ||
247 | * asks us to do so (note that if the session structures | ||
248 | * returned by the callback are shared between threads, | ||
249 | * it must handle the reference count itself [i.e. copy == 0], | ||
250 | * or things won't be thread-safe). */ | ||
251 | if (copy) | ||
252 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
253 | |||
254 | /* The following should not return 1, otherwise, | ||
255 | * things are very strange */ | ||
256 | SSL_CTX_add_session(s->ctx,ret); | ||
257 | } | ||
258 | if (ret == NULL) | ||
259 | goto err; | ||
260 | } | ||
261 | |||
262 | /* Now ret is non-NULL, and we own one of its reference counts. */ | ||
263 | |||
264 | if((s->verify_mode&SSL_VERIFY_PEER) | ||
265 | && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length | ||
266 | || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length))) | ||
267 | { | ||
268 | /* We've found the session named by the client, but we don't | ||
269 | * want to use it in this context. */ | ||
270 | |||
271 | if (s->sid_ctx_length == 0) | ||
272 | { | ||
273 | /* application should have used SSL[_CTX]_set_session_id_context | ||
274 | * -- we could tolerate this and just pretend we never heard | ||
275 | * of this session, but then applications could effectively | ||
276 | * disable the session cache by accident without anyone noticing */ | ||
277 | |||
278 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED); | ||
279 | fatal = 1; | ||
280 | goto err; | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | #if 0 /* The client cannot always know when a session is not appropriate, | ||
285 | * so we shouldn't generate an error message. */ | ||
286 | |||
287 | SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | ||
288 | #endif | ||
289 | goto err; /* treat like cache miss */ | ||
290 | } | ||
291 | } | ||
292 | |||
293 | if (ret->cipher == NULL) | ||
294 | { | ||
295 | unsigned char buf[5],*p; | ||
296 | unsigned long l; | ||
297 | |||
298 | p=buf; | ||
299 | l=ret->cipher_id; | ||
300 | l2n(l,p); | ||
301 | if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR) | ||
302 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[2])); | ||
303 | else | ||
304 | ret->cipher=ssl_get_cipher_by_char(s,&(buf[1])); | ||
305 | if (ret->cipher == NULL) | ||
306 | goto err; | ||
307 | } | ||
308 | |||
309 | |||
310 | #if 0 /* This is way too late. */ | ||
311 | |||
312 | /* If a thread got the session, then 'swaped', and another got | ||
313 | * it and then due to a time-out decided to 'Free' it we could | ||
314 | * be in trouble. So I'll increment it now, then double decrement | ||
315 | * later - am I speaking rubbish?. */ | ||
316 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
317 | #endif | ||
318 | |||
319 | if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */ | ||
320 | { | ||
321 | s->ctx->stats.sess_timeout++; | ||
322 | /* remove it from the cache */ | ||
323 | SSL_CTX_remove_session(s->ctx,ret); | ||
324 | goto err; | ||
325 | } | ||
326 | |||
327 | s->ctx->stats.sess_hit++; | ||
328 | |||
329 | /* ret->time=time(NULL); */ /* rezero timeout? */ | ||
330 | /* again, just leave the session | ||
331 | * if it is the same session, we have just incremented and | ||
332 | * then decremented the reference count :-) */ | ||
333 | if (s->session != NULL) | ||
334 | SSL_SESSION_free(s->session); | ||
335 | s->session=ret; | ||
336 | s->verify_result = s->session->verify_result; | ||
337 | return(1); | ||
338 | |||
339 | err: | ||
340 | if (ret != NULL) | ||
341 | SSL_SESSION_free(ret); | ||
342 | if (fatal) | ||
343 | return -1; | ||
344 | else | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c) | ||
349 | { | ||
350 | int ret=0; | ||
351 | SSL_SESSION *s; | ||
352 | |||
353 | /* add just 1 reference count for the SSL_CTX's session cache | ||
354 | * even though it has two ways of access: each session is in a | ||
355 | * doubly linked list and an lhash */ | ||
356 | CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
357 | /* if session c is in already in cache, we take back the increment later */ | ||
358 | |||
359 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
360 | s=(SSL_SESSION *)lh_insert(ctx->sessions,c); | ||
361 | |||
362 | /* s != NULL iff we already had a session with the given PID. | ||
363 | * In this case, s == c should hold (then we did not really modify | ||
364 | * ctx->sessions), or we're in trouble. */ | ||
365 | if (s != NULL && s != c) | ||
366 | { | ||
367 | /* We *are* in trouble ... */ | ||
368 | SSL_SESSION_list_remove(ctx,s); | ||
369 | SSL_SESSION_free(s); | ||
370 | /* ... so pretend the other session did not exist in cache | ||
371 | * (we cannot handle two SSL_SESSION structures with identical | ||
372 | * session ID in the same cache, which could happen e.g. when | ||
373 | * two threads concurrently obtain the same session from an external | ||
374 | * cache) */ | ||
375 | s = NULL; | ||
376 | } | ||
377 | |||
378 | /* Put at the head of the queue unless it is already in the cache */ | ||
379 | if (s == NULL) | ||
380 | SSL_SESSION_list_add(ctx,c); | ||
381 | |||
382 | if (s != NULL) | ||
383 | { | ||
384 | /* existing cache entry -- decrement previously incremented reference | ||
385 | * count because it already takes into account the cache */ | ||
386 | |||
387 | SSL_SESSION_free(s); /* s == c */ | ||
388 | ret=0; | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | /* new cache entry -- remove old ones if cache has become too large */ | ||
393 | |||
394 | ret=1; | ||
395 | |||
396 | if (SSL_CTX_sess_get_cache_size(ctx) > 0) | ||
397 | { | ||
398 | while (SSL_CTX_sess_number(ctx) > | ||
399 | SSL_CTX_sess_get_cache_size(ctx)) | ||
400 | { | ||
401 | if (!remove_session_lock(ctx, | ||
402 | ctx->session_cache_tail, 0)) | ||
403 | break; | ||
404 | else | ||
405 | ctx->stats.sess_cache_full++; | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
410 | return(ret); | ||
411 | } | ||
412 | |||
413 | int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c) | ||
414 | { | ||
415 | return remove_session_lock(ctx, c, 1); | ||
416 | } | ||
417 | |||
418 | static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck) | ||
419 | { | ||
420 | SSL_SESSION *r; | ||
421 | int ret=0; | ||
422 | |||
423 | if ((c != NULL) && (c->session_id_length != 0)) | ||
424 | { | ||
425 | if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
426 | r=(SSL_SESSION *)lh_delete(ctx->sessions,c); | ||
427 | if (r != NULL) | ||
428 | { | ||
429 | ret=1; | ||
430 | SSL_SESSION_list_remove(ctx,c); | ||
431 | } | ||
432 | |||
433 | if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
434 | |||
435 | if (ret) | ||
436 | { | ||
437 | r->not_resumable=1; | ||
438 | if (ctx->remove_session_cb != NULL) | ||
439 | ctx->remove_session_cb(ctx,r); | ||
440 | SSL_SESSION_free(r); | ||
441 | } | ||
442 | } | ||
443 | else | ||
444 | ret=0; | ||
445 | return(ret); | ||
446 | } | ||
447 | |||
448 | void SSL_SESSION_free(SSL_SESSION *ss) | ||
449 | { | ||
450 | int i; | ||
451 | |||
452 | if(ss == NULL) | ||
453 | return; | ||
454 | |||
455 | i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION); | ||
456 | #ifdef REF_PRINT | ||
457 | REF_PRINT("SSL_SESSION",ss); | ||
458 | #endif | ||
459 | if (i > 0) return; | ||
460 | #ifdef REF_CHECK | ||
461 | if (i < 0) | ||
462 | { | ||
463 | fprintf(stderr,"SSL_SESSION_free, bad reference count\n"); | ||
464 | abort(); /* ok */ | ||
465 | } | ||
466 | #endif | ||
467 | |||
468 | CRYPTO_free_ex_data(ssl_session_meth,ss,&ss->ex_data); | ||
469 | |||
470 | memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH); | ||
471 | memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH); | ||
472 | memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH); | ||
473 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); | ||
474 | if (ss->peer != NULL) X509_free(ss->peer); | ||
475 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); | ||
476 | memset(ss,0,sizeof(*ss)); | ||
477 | Free(ss); | ||
478 | } | ||
479 | |||
480 | int SSL_set_session(SSL *s, SSL_SESSION *session) | ||
481 | { | ||
482 | int ret=0; | ||
483 | SSL_METHOD *meth; | ||
484 | |||
485 | if (session != NULL) | ||
486 | { | ||
487 | meth=s->ctx->method->get_ssl_method(session->ssl_version); | ||
488 | if (meth == NULL) | ||
489 | meth=s->method->get_ssl_method(session->ssl_version); | ||
490 | if (meth == NULL) | ||
491 | { | ||
492 | SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD); | ||
493 | return(0); | ||
494 | } | ||
495 | |||
496 | if (meth != s->method) | ||
497 | { | ||
498 | if (!SSL_set_ssl_method(s,meth)) | ||
499 | return(0); | ||
500 | if (s->ctx->session_timeout == 0) | ||
501 | session->timeout=SSL_get_default_timeout(s); | ||
502 | else | ||
503 | session->timeout=s->ctx->session_timeout; | ||
504 | } | ||
505 | |||
506 | /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/ | ||
507 | CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION); | ||
508 | if (s->session != NULL) | ||
509 | SSL_SESSION_free(s->session); | ||
510 | s->session=session; | ||
511 | /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/ | ||
512 | ret=1; | ||
513 | } | ||
514 | else | ||
515 | { | ||
516 | if (s->session != NULL) | ||
517 | { | ||
518 | SSL_SESSION_free(s->session); | ||
519 | s->session=NULL; | ||
520 | } | ||
521 | |||
522 | meth=s->ctx->method; | ||
523 | if (meth != s->method) | ||
524 | { | ||
525 | if (!SSL_set_ssl_method(s,meth)) | ||
526 | return(0); | ||
527 | } | ||
528 | ret=1; | ||
529 | } | ||
530 | return(ret); | ||
531 | } | ||
532 | |||
533 | long SSL_SESSION_set_timeout(SSL_SESSION *s, long t) | ||
534 | { | ||
535 | if (s == NULL) return(0); | ||
536 | s->timeout=t; | ||
537 | return(1); | ||
538 | } | ||
539 | |||
540 | long SSL_SESSION_get_timeout(SSL_SESSION *s) | ||
541 | { | ||
542 | if (s == NULL) return(0); | ||
543 | return(s->timeout); | ||
544 | } | ||
545 | |||
546 | long SSL_SESSION_get_time(SSL_SESSION *s) | ||
547 | { | ||
548 | if (s == NULL) return(0); | ||
549 | return(s->time); | ||
550 | } | ||
551 | |||
552 | long SSL_SESSION_set_time(SSL_SESSION *s, long t) | ||
553 | { | ||
554 | if (s == NULL) return(0); | ||
555 | s->time=t; | ||
556 | return(t); | ||
557 | } | ||
558 | |||
559 | long SSL_CTX_set_timeout(SSL_CTX *s, long t) | ||
560 | { | ||
561 | long l; | ||
562 | if (s == NULL) return(0); | ||
563 | l=s->session_timeout; | ||
564 | s->session_timeout=t; | ||
565 | return(l); | ||
566 | } | ||
567 | |||
568 | long SSL_CTX_get_timeout(SSL_CTX *s) | ||
569 | { | ||
570 | if (s == NULL) return(0); | ||
571 | return(s->session_timeout); | ||
572 | } | ||
573 | |||
574 | typedef struct timeout_param_st | ||
575 | { | ||
576 | SSL_CTX *ctx; | ||
577 | long time; | ||
578 | LHASH *cache; | ||
579 | } TIMEOUT_PARAM; | ||
580 | |||
581 | static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p) | ||
582 | { | ||
583 | if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */ | ||
584 | { | ||
585 | /* The reason we don't call SSL_CTX_remove_session() is to | ||
586 | * save on locking overhead */ | ||
587 | lh_delete(p->cache,s); | ||
588 | SSL_SESSION_list_remove(p->ctx,s); | ||
589 | s->not_resumable=1; | ||
590 | if (p->ctx->remove_session_cb != NULL) | ||
591 | p->ctx->remove_session_cb(p->ctx,s); | ||
592 | SSL_SESSION_free(s); | ||
593 | } | ||
594 | } | ||
595 | |||
596 | void SSL_CTX_flush_sessions(SSL_CTX *s, long t) | ||
597 | { | ||
598 | unsigned long i; | ||
599 | TIMEOUT_PARAM tp; | ||
600 | |||
601 | tp.ctx=s; | ||
602 | tp.cache=s->sessions; | ||
603 | if (tp.cache == NULL) return; | ||
604 | tp.time=t; | ||
605 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
606 | i=tp.cache->down_load; | ||
607 | tp.cache->down_load=0; | ||
608 | lh_doall_arg(tp.cache,(void (*)())timeout,&tp); | ||
609 | tp.cache->down_load=i; | ||
610 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
611 | } | ||
612 | |||
613 | int ssl_clear_bad_session(SSL *s) | ||
614 | { | ||
615 | if ( (s->session != NULL) && | ||
616 | !(s->shutdown & SSL_SENT_SHUTDOWN) && | ||
617 | !(SSL_in_init(s) || SSL_in_before(s))) | ||
618 | { | ||
619 | SSL_CTX_remove_session(s->ctx,s->session); | ||
620 | return(1); | ||
621 | } | ||
622 | else | ||
623 | return(0); | ||
624 | } | ||
625 | |||
626 | /* locked by SSL_CTX in the calling function */ | ||
627 | static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s) | ||
628 | { | ||
629 | if ((s->next == NULL) || (s->prev == NULL)) return; | ||
630 | |||
631 | if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) | ||
632 | { /* last element in list */ | ||
633 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
634 | { /* only one element in list */ | ||
635 | ctx->session_cache_head=NULL; | ||
636 | ctx->session_cache_tail=NULL; | ||
637 | } | ||
638 | else | ||
639 | { | ||
640 | ctx->session_cache_tail=s->prev; | ||
641 | s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
642 | } | ||
643 | } | ||
644 | else | ||
645 | { | ||
646 | if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) | ||
647 | { /* first element in list */ | ||
648 | ctx->session_cache_head=s->next; | ||
649 | s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
650 | } | ||
651 | else | ||
652 | { /* middle of list */ | ||
653 | s->next->prev=s->prev; | ||
654 | s->prev->next=s->next; | ||
655 | } | ||
656 | } | ||
657 | s->prev=s->next=NULL; | ||
658 | } | ||
659 | |||
660 | static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s) | ||
661 | { | ||
662 | if ((s->next != NULL) && (s->prev != NULL)) | ||
663 | SSL_SESSION_list_remove(ctx,s); | ||
664 | |||
665 | if (ctx->session_cache_head == NULL) | ||
666 | { | ||
667 | ctx->session_cache_head=s; | ||
668 | ctx->session_cache_tail=s; | ||
669 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
670 | s->next=(SSL_SESSION *)&(ctx->session_cache_tail); | ||
671 | } | ||
672 | else | ||
673 | { | ||
674 | s->next=ctx->session_cache_head; | ||
675 | s->next->prev=s; | ||
676 | s->prev=(SSL_SESSION *)&(ctx->session_cache_head); | ||
677 | ctx->session_cache_head=s; | ||
678 | } | ||
679 | } | ||
680 | |||
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c deleted file mode 100644 index 8e12461f3b..0000000000 --- a/src/lib/libssl/ssl_stat.c +++ /dev/null | |||
@@ -1,454 +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 | char *SSL_state_string_long(SSL *s) | ||
63 | { | ||
64 | 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 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 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 A"; 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 A"; 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(NO_SSL2) && !defined(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 | char *SSL_rstate_string_long(SSL *s) | ||
203 | { | ||
204 | 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 | char *SSL_state_string(SSL *s) | ||
217 | { | ||
218 | 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 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 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(NO_SSL2) && !defined(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 | 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 | 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 | char *SSL_alert_desc_string(int value) | ||
373 | { | ||
374 | 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 | default: str="UK"; break; | ||
391 | } | ||
392 | return(str); | ||
393 | } | ||
394 | |||
395 | char *SSL_alert_desc_string_long(int value) | ||
396 | { | ||
397 | char *str; | ||
398 | |||
399 | switch (value & 0xff) | ||
400 | { | ||
401 | case SSL3_AD_CLOSE_NOTIFY: | ||
402 | str="close notify"; | ||
403 | break; | ||
404 | case SSL3_AD_UNEXPECTED_MESSAGE: | ||
405 | str="unexpected_message"; | ||
406 | break; | ||
407 | case SSL3_AD_BAD_RECORD_MAC: | ||
408 | str="bad record mac"; | ||
409 | break; | ||
410 | case SSL3_AD_DECOMPRESSION_FAILURE: | ||
411 | str="decompression failure"; | ||
412 | break; | ||
413 | case SSL3_AD_HANDSHAKE_FAILURE: | ||
414 | str="handshake failure"; | ||
415 | break; | ||
416 | case SSL3_AD_NO_CERTIFICATE: | ||
417 | str="no certificate"; | ||
418 | break; | ||
419 | case SSL3_AD_BAD_CERTIFICATE: | ||
420 | str="bad certificate"; | ||
421 | break; | ||
422 | case SSL3_AD_UNSUPPORTED_CERTIFICATE: | ||
423 | str="unsupported certificate"; | ||
424 | break; | ||
425 | case SSL3_AD_CERTIFICATE_REVOKED: | ||
426 | str="certificate revoked"; | ||
427 | break; | ||
428 | case SSL3_AD_CERTIFICATE_EXPIRED: | ||
429 | str="certificate expired"; | ||
430 | break; | ||
431 | case SSL3_AD_CERTIFICATE_UNKNOWN: | ||
432 | str="certificate unknown"; | ||
433 | break; | ||
434 | case SSL3_AD_ILLEGAL_PARAMETER: | ||
435 | str="illegal parameter"; | ||
436 | break; | ||
437 | default: str="unknown"; break; | ||
438 | } | ||
439 | return(str); | ||
440 | } | ||
441 | |||
442 | char *SSL_rstate_string(SSL *s) | ||
443 | { | ||
444 | char *str; | ||
445 | |||
446 | switch (s->rstate) | ||
447 | { | ||
448 | case SSL_ST_READ_HEADER:str="RH"; break; | ||
449 | case SSL_ST_READ_BODY: str="RB"; break; | ||
450 | case SSL_ST_READ_DONE: str="RD"; break; | ||
451 | default: str="unknown"; break; | ||
452 | } | ||
453 | return(str); | ||
454 | } | ||
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c deleted file mode 100644 index c07d957576..0000000000 --- a/src/lib/libssl/ssl_txt.c +++ /dev/null | |||
@@ -1,176 +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 NO_FP_API | ||
64 | int SSL_SESSION_print_fp(FILE *fp, 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, SSL_SESSION *x) | ||
82 | { | ||
83 | unsigned int i; | ||
84 | char str[128],*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 | sprintf(str," Protocol : %s\n",s); | ||
97 | if (BIO_puts(bp,str) <= 0) goto err; | ||
98 | |||
99 | if (x->cipher == NULL) | ||
100 | { | ||
101 | if (((x->cipher_id) & 0xff000000) == 0x02000000) | ||
102 | sprintf(str," Cipher : %06lX\n",x->cipher_id&0xffffff); | ||
103 | else | ||
104 | sprintf(str," Cipher : %04lX\n",x->cipher_id&0xffff); | ||
105 | } | ||
106 | else | ||
107 | sprintf(str," Cipher : %s\n",(x->cipher == NULL)?"unknown":x->cipher->name); | ||
108 | if (BIO_puts(bp,str) <= 0) goto err; | ||
109 | if (BIO_puts(bp," Session-ID: ") <= 0) goto err; | ||
110 | for (i=0; i<x->session_id_length; i++) | ||
111 | { | ||
112 | sprintf(str,"%02X",x->session_id[i]); | ||
113 | if (BIO_puts(bp,str) <= 0) goto err; | ||
114 | } | ||
115 | if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err; | ||
116 | for (i=0; i<x->sid_ctx_length; i++) | ||
117 | { | ||
118 | sprintf(str,"%02X",x->sid_ctx[i]); | ||
119 | if (BIO_puts(bp,str) <= 0) goto err; | ||
120 | } | ||
121 | if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err; | ||
122 | for (i=0; i<(unsigned int)x->master_key_length; i++) | ||
123 | { | ||
124 | sprintf(str,"%02X",x->master_key[i]); | ||
125 | if (BIO_puts(bp,str) <= 0) goto err; | ||
126 | } | ||
127 | if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err; | ||
128 | if (x->key_arg_length == 0) | ||
129 | { | ||
130 | if (BIO_puts(bp,"None") <= 0) goto err; | ||
131 | } | ||
132 | else | ||
133 | for (i=0; i<x->key_arg_length; i++) | ||
134 | { | ||
135 | sprintf(str,"%02X",x->key_arg[i]); | ||
136 | if (BIO_puts(bp,str) <= 0) goto err; | ||
137 | } | ||
138 | if (x->compress_meth != 0) | ||
139 | { | ||
140 | SSL_COMP *comp; | ||
141 | |||
142 | ssl_cipher_get_evp(x,NULL,NULL,&comp); | ||
143 | if (comp == NULL) | ||
144 | { | ||
145 | sprintf(str,"\n Compression: %d",x->compress_meth); | ||
146 | if (BIO_puts(bp,str) <= 0) goto err; | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | sprintf(str,"\n Compression: %d (%s)", | ||
151 | comp->id,comp->method->name); | ||
152 | if (BIO_puts(bp,str) <= 0) goto err; | ||
153 | } | ||
154 | } | ||
155 | if (x->time != 0L) | ||
156 | { | ||
157 | sprintf(str,"\n Start Time: %ld",x->time); | ||
158 | if (BIO_puts(bp,str) <= 0) goto err; | ||
159 | } | ||
160 | if (x->timeout != 0L) | ||
161 | { | ||
162 | sprintf(str,"\n Timeout : %ld (sec)",x->timeout); | ||
163 | if (BIO_puts(bp,str) <= 0) goto err; | ||
164 | } | ||
165 | if (BIO_puts(bp,"\n") <= 0) goto err; | ||
166 | |||
167 | if (BIO_puts(bp, " Verify return code: ") <= 0) goto err; | ||
168 | sprintf(str, "%ld (%s)\n", x->verify_result, | ||
169 | X509_verify_cert_error_string(x->verify_result)); | ||
170 | if (BIO_puts(bp,str) <= 0) goto err; | ||
171 | |||
172 | return(1); | ||
173 | err: | ||
174 | return(0); | ||
175 | } | ||
176 | |||
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c deleted file mode 100644 index 9745630a00..0000000000 --- a/src/lib/libssl/t1_clnt.c +++ /dev/null | |||
@@ -1,90 +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 <openssl/buffer.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include "ssl_locl.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 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), | ||
83 | sizeof(SSL_METHOD)); | ||
84 | TLSv1_client_data.ssl_connect=ssl3_connect; | ||
85 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | ||
86 | init=0; | ||
87 | } | ||
88 | return(&TLSv1_client_data); | ||
89 | } | ||
90 | |||
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c deleted file mode 100644 index 279e45db5d..0000000000 --- a/src/lib/libssl/t1_enc.c +++ /dev/null | |||
@@ -1,633 +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 | #include <stdio.h> | ||
60 | #include <openssl/comp.h> | ||
61 | #include <openssl/md5.h> | ||
62 | #include <openssl/sha.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/hmac.h> | ||
65 | #include "ssl_locl.h" | ||
66 | |||
67 | static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | ||
68 | int sec_len, unsigned char *seed, int seed_len, | ||
69 | unsigned char *out, int olen) | ||
70 | { | ||
71 | int chunk,n; | ||
72 | unsigned int j; | ||
73 | HMAC_CTX ctx; | ||
74 | HMAC_CTX ctx_tmp; | ||
75 | unsigned char A1[HMAC_MAX_MD_CBLOCK]; | ||
76 | unsigned int A1_len; | ||
77 | |||
78 | chunk=EVP_MD_size(md); | ||
79 | |||
80 | HMAC_Init(&ctx,sec,sec_len,md); | ||
81 | HMAC_Update(&ctx,seed,seed_len); | ||
82 | HMAC_Final(&ctx,A1,&A1_len); | ||
83 | |||
84 | n=0; | ||
85 | for (;;) | ||
86 | { | ||
87 | HMAC_Init(&ctx,NULL,0,NULL); /* re-init */ | ||
88 | HMAC_Update(&ctx,A1,A1_len); | ||
89 | memcpy(&ctx_tmp,&ctx,sizeof(ctx)); /* Copy for A2 */ /* not needed for last one */ | ||
90 | HMAC_Update(&ctx,seed,seed_len); | ||
91 | |||
92 | if (olen > chunk) | ||
93 | { | ||
94 | HMAC_Final(&ctx,out,&j); | ||
95 | out+=j; | ||
96 | olen-=j; | ||
97 | HMAC_Final(&ctx_tmp,A1,&A1_len); /* calc the next A1 value */ | ||
98 | } | ||
99 | else /* last one */ | ||
100 | { | ||
101 | HMAC_Final(&ctx,A1,&A1_len); | ||
102 | memcpy(out,A1,olen); | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | HMAC_cleanup(&ctx); | ||
107 | HMAC_cleanup(&ctx_tmp); | ||
108 | memset(A1,0,sizeof(A1)); | ||
109 | } | ||
110 | |||
111 | static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1, | ||
112 | unsigned char *label, int label_len, | ||
113 | const unsigned char *sec, int slen, unsigned char *out1, | ||
114 | unsigned char *out2, int olen) | ||
115 | { | ||
116 | int len,i; | ||
117 | const unsigned char *S1,*S2; | ||
118 | |||
119 | len=slen/2; | ||
120 | S1=sec; | ||
121 | S2= &(sec[len]); | ||
122 | len+=(slen&1); /* add for odd, make longer */ | ||
123 | |||
124 | |||
125 | tls1_P_hash(md5 ,S1,len,label,label_len,out1,olen); | ||
126 | tls1_P_hash(sha1,S2,len,label,label_len,out2,olen); | ||
127 | |||
128 | for (i=0; i<olen; i++) | ||
129 | out1[i]^=out2[i]; | ||
130 | } | ||
131 | |||
132 | static void tls1_generate_key_block(SSL *s, unsigned char *km, | ||
133 | unsigned char *tmp, int num) | ||
134 | { | ||
135 | unsigned char *p; | ||
136 | unsigned char buf[SSL3_RANDOM_SIZE*2+ | ||
137 | TLS_MD_MAX_CONST_SIZE]; | ||
138 | p=buf; | ||
139 | |||
140 | memcpy(p,TLS_MD_KEY_EXPANSION_CONST, | ||
141 | TLS_MD_KEY_EXPANSION_CONST_SIZE); | ||
142 | p+=TLS_MD_KEY_EXPANSION_CONST_SIZE; | ||
143 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
144 | p+=SSL3_RANDOM_SIZE; | ||
145 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
146 | p+=SSL3_RANDOM_SIZE; | ||
147 | |||
148 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf), | ||
149 | s->session->master_key,s->session->master_key_length, | ||
150 | km,tmp,num); | ||
151 | } | ||
152 | |||
153 | int tls1_change_cipher_state(SSL *s, int which) | ||
154 | { | ||
155 | static const unsigned char empty[]=""; | ||
156 | unsigned char *p,*key_block,*mac_secret; | ||
157 | unsigned char *exp_label,buf[TLS_MD_MAX_CONST_SIZE+ | ||
158 | SSL3_RANDOM_SIZE*2]; | ||
159 | unsigned char tmp1[EVP_MAX_KEY_LENGTH]; | ||
160 | unsigned char tmp2[EVP_MAX_KEY_LENGTH]; | ||
161 | unsigned char iv1[EVP_MAX_IV_LENGTH*2]; | ||
162 | unsigned char iv2[EVP_MAX_IV_LENGTH*2]; | ||
163 | unsigned char *ms,*key,*iv,*er1,*er2; | ||
164 | int client_write; | ||
165 | EVP_CIPHER_CTX *dd; | ||
166 | const EVP_CIPHER *c; | ||
167 | const SSL_COMP *comp; | ||
168 | const EVP_MD *m; | ||
169 | int _exp,n,i,j,k,exp_label_len,cl; | ||
170 | |||
171 | _exp=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher); | ||
172 | c=s->s3->tmp.new_sym_enc; | ||
173 | m=s->s3->tmp.new_hash; | ||
174 | comp=s->s3->tmp.new_compression; | ||
175 | key_block=s->s3->tmp.key_block; | ||
176 | |||
177 | if (which & SSL3_CC_READ) | ||
178 | { | ||
179 | if ((s->enc_read_ctx == NULL) && | ||
180 | ((s->enc_read_ctx=(EVP_CIPHER_CTX *) | ||
181 | Malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | ||
182 | goto err; | ||
183 | dd= s->enc_read_ctx; | ||
184 | s->read_hash=m; | ||
185 | if (s->expand != NULL) | ||
186 | { | ||
187 | COMP_CTX_free(s->expand); | ||
188 | s->expand=NULL; | ||
189 | } | ||
190 | if (comp != NULL) | ||
191 | { | ||
192 | s->expand=COMP_CTX_new(comp->method); | ||
193 | if (s->expand == NULL) | ||
194 | { | ||
195 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR); | ||
196 | goto err2; | ||
197 | } | ||
198 | if (s->s3->rrec.comp == NULL) | ||
199 | s->s3->rrec.comp=(unsigned char *) | ||
200 | Malloc(SSL3_RT_MAX_ENCRYPTED_LENGTH); | ||
201 | if (s->s3->rrec.comp == NULL) | ||
202 | goto err; | ||
203 | } | ||
204 | memset(&(s->s3->read_sequence[0]),0,8); | ||
205 | mac_secret= &(s->s3->read_mac_secret[0]); | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | if ((s->enc_write_ctx == NULL) && | ||
210 | ((s->enc_write_ctx=(EVP_CIPHER_CTX *) | ||
211 | Malloc(sizeof(EVP_CIPHER_CTX))) == NULL)) | ||
212 | goto err; | ||
213 | dd= s->enc_write_ctx; | ||
214 | s->write_hash=m; | ||
215 | if (s->compress != NULL) | ||
216 | { | ||
217 | COMP_CTX_free(s->compress); | ||
218 | s->compress=NULL; | ||
219 | } | ||
220 | if (comp != NULL) | ||
221 | { | ||
222 | s->compress=COMP_CTX_new(comp->method); | ||
223 | if (s->compress == NULL) | ||
224 | { | ||
225 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR); | ||
226 | goto err2; | ||
227 | } | ||
228 | } | ||
229 | memset(&(s->s3->write_sequence[0]),0,8); | ||
230 | mac_secret= &(s->s3->write_mac_secret[0]); | ||
231 | } | ||
232 | |||
233 | EVP_CIPHER_CTX_init(dd); | ||
234 | |||
235 | p=s->s3->tmp.key_block; | ||
236 | i=EVP_MD_size(m); | ||
237 | cl=EVP_CIPHER_key_length(c); | ||
238 | j=_exp ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ? | ||
239 | cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl; | ||
240 | /* Was j=(exp)?5:EVP_CIPHER_key_length(c); */ | ||
241 | k=EVP_CIPHER_iv_length(c); | ||
242 | er1= &(s->s3->client_random[0]); | ||
243 | er2= &(s->s3->server_random[0]); | ||
244 | if ( (which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || | ||
245 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) | ||
246 | { | ||
247 | ms= &(p[ 0]); n=i+i; | ||
248 | key= &(p[ n]); n+=j+j; | ||
249 | iv= &(p[ n]); n+=k+k; | ||
250 | exp_label=(unsigned char *)TLS_MD_CLIENT_WRITE_KEY_CONST; | ||
251 | exp_label_len=TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE; | ||
252 | client_write=1; | ||
253 | } | ||
254 | else | ||
255 | { | ||
256 | n=i; | ||
257 | ms= &(p[ n]); n+=i+j; | ||
258 | key= &(p[ n]); n+=j+k; | ||
259 | iv= &(p[ n]); n+=k; | ||
260 | exp_label=(unsigned char *)TLS_MD_SERVER_WRITE_KEY_CONST; | ||
261 | exp_label_len=TLS_MD_SERVER_WRITE_KEY_CONST_SIZE; | ||
262 | client_write=0; | ||
263 | } | ||
264 | |||
265 | if (n > s->s3->tmp.key_block_length) | ||
266 | { | ||
267 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR); | ||
268 | goto err2; | ||
269 | } | ||
270 | |||
271 | memcpy(mac_secret,ms,i); | ||
272 | #ifdef TLS_DEBUG | ||
273 | printf("which = %04X\nmac key=",which); | ||
274 | { int z; for (z=0; z<i; z++) printf("%02X%c",ms[z],((z+1)%16)?' ':'\n'); } | ||
275 | #endif | ||
276 | if (_exp) | ||
277 | { | ||
278 | /* In here I set both the read and write key/iv to the | ||
279 | * same value since only the correct one will be used :-). | ||
280 | */ | ||
281 | p=buf; | ||
282 | memcpy(p,exp_label,exp_label_len); | ||
283 | p+=exp_label_len; | ||
284 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
285 | p+=SSL3_RANDOM_SIZE; | ||
286 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
287 | p+=SSL3_RANDOM_SIZE; | ||
288 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(p-buf),key,j, | ||
289 | tmp1,tmp2,EVP_CIPHER_key_length(c)); | ||
290 | key=tmp1; | ||
291 | |||
292 | if (k > 0) | ||
293 | { | ||
294 | p=buf; | ||
295 | memcpy(p,TLS_MD_IV_BLOCK_CONST, | ||
296 | TLS_MD_IV_BLOCK_CONST_SIZE); | ||
297 | p+=TLS_MD_IV_BLOCK_CONST_SIZE; | ||
298 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | ||
299 | p+=SSL3_RANDOM_SIZE; | ||
300 | memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE); | ||
301 | p+=SSL3_RANDOM_SIZE; | ||
302 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,p-buf,empty,0, | ||
303 | iv1,iv2,k*2); | ||
304 | if (client_write) | ||
305 | iv=iv1; | ||
306 | else | ||
307 | iv= &(iv1[k]); | ||
308 | } | ||
309 | } | ||
310 | |||
311 | s->session->key_arg_length=0; | ||
312 | |||
313 | EVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE)); | ||
314 | #ifdef TLS_DEBUG | ||
315 | printf("which = %04X\nkey=",which); | ||
316 | { int z; for (z=0; z<EVP_CIPHER_key_length(c); z++) printf("%02X%c",key[z],((z+1)%16)?' ':'\n'); } | ||
317 | printf("\niv="); | ||
318 | { int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); } | ||
319 | printf("\n"); | ||
320 | #endif | ||
321 | |||
322 | memset(tmp1,0,sizeof(tmp1)); | ||
323 | memset(tmp2,0,sizeof(tmp1)); | ||
324 | memset(iv1,0,sizeof(iv1)); | ||
325 | memset(iv2,0,sizeof(iv2)); | ||
326 | return(1); | ||
327 | err: | ||
328 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE); | ||
329 | err2: | ||
330 | return(0); | ||
331 | } | ||
332 | |||
333 | int tls1_setup_key_block(SSL *s) | ||
334 | { | ||
335 | unsigned char *p1,*p2; | ||
336 | const EVP_CIPHER *c; | ||
337 | const EVP_MD *hash; | ||
338 | int num; | ||
339 | SSL_COMP *comp; | ||
340 | |||
341 | if (s->s3->tmp.key_block_length != 0) | ||
342 | return(1); | ||
343 | |||
344 | if (!ssl_cipher_get_evp(s->session,&c,&hash,&comp)) | ||
345 | { | ||
346 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | ||
347 | return(0); | ||
348 | } | ||
349 | |||
350 | s->s3->tmp.new_sym_enc=c; | ||
351 | s->s3->tmp.new_hash=hash; | ||
352 | |||
353 | num=EVP_CIPHER_key_length(c)+EVP_MD_size(hash)+EVP_CIPHER_iv_length(c); | ||
354 | num*=2; | ||
355 | |||
356 | ssl3_cleanup_key_block(s); | ||
357 | |||
358 | if ((p1=(unsigned char *)Malloc(num)) == NULL) | ||
359 | goto err; | ||
360 | if ((p2=(unsigned char *)Malloc(num)) == NULL) | ||
361 | goto err; | ||
362 | |||
363 | s->s3->tmp.key_block_length=num; | ||
364 | s->s3->tmp.key_block=p1; | ||
365 | |||
366 | |||
367 | #ifdef TLS_DEBUG | ||
368 | printf("client random\n"); | ||
369 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->client_random[z],((z+1)%16)?' ':'\n'); } | ||
370 | printf("server random\n"); | ||
371 | { int z; for (z=0; z<SSL3_RANDOM_SIZE; z++) printf("%02X%c",s->s3->server_random[z],((z+1)%16)?' ':'\n'); } | ||
372 | printf("pre-master\n"); | ||
373 | { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); } | ||
374 | #endif | ||
375 | tls1_generate_key_block(s,p1,p2,num); | ||
376 | memset(p2,0,num); | ||
377 | Free(p2); | ||
378 | #ifdef TLS_DEBUG | ||
379 | printf("\nkey block\n"); | ||
380 | { int z; for (z=0; z<num; z++) printf("%02X%c",p1[z],((z+1)%16)?' ':'\n'); } | ||
381 | #endif | ||
382 | |||
383 | return(1); | ||
384 | err: | ||
385 | SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE); | ||
386 | return(0); | ||
387 | } | ||
388 | |||
389 | int tls1_enc(SSL *s, int send) | ||
390 | { | ||
391 | SSL3_RECORD *rec; | ||
392 | EVP_CIPHER_CTX *ds; | ||
393 | unsigned long l; | ||
394 | int bs,i,ii,j,k,n=0; | ||
395 | const EVP_CIPHER *enc; | ||
396 | |||
397 | if (send) | ||
398 | { | ||
399 | if (s->write_hash != NULL) | ||
400 | n=EVP_MD_size(s->write_hash); | ||
401 | ds=s->enc_write_ctx; | ||
402 | rec= &(s->s3->wrec); | ||
403 | if (s->enc_write_ctx == NULL) | ||
404 | enc=NULL; | ||
405 | else | ||
406 | enc=EVP_CIPHER_CTX_cipher(s->enc_write_ctx); | ||
407 | } | ||
408 | else | ||
409 | { | ||
410 | if (s->read_hash != NULL) | ||
411 | n=EVP_MD_size(s->read_hash); | ||
412 | ds=s->enc_read_ctx; | ||
413 | rec= &(s->s3->rrec); | ||
414 | if (s->enc_read_ctx == NULL) | ||
415 | enc=NULL; | ||
416 | else | ||
417 | enc=EVP_CIPHER_CTX_cipher(s->enc_read_ctx); | ||
418 | } | ||
419 | |||
420 | if ((s->session == NULL) || (ds == NULL) || | ||
421 | (enc == NULL)) | ||
422 | { | ||
423 | memcpy(rec->data,rec->input,rec->length); | ||
424 | rec->input=rec->data; | ||
425 | } | ||
426 | else | ||
427 | { | ||
428 | l=rec->length; | ||
429 | bs=EVP_CIPHER_block_size(ds->cipher); | ||
430 | |||
431 | if ((bs != 1) && send) | ||
432 | { | ||
433 | i=bs-((int)l%bs); | ||
434 | |||
435 | /* Add weird padding of upto 256 bytes */ | ||
436 | |||
437 | /* we need to add 'i' padding bytes of value j */ | ||
438 | j=i-1; | ||
439 | if (s->options & SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
440 | { | ||
441 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
442 | j++; | ||
443 | } | ||
444 | for (k=(int)l; k<(int)(l+i); k++) | ||
445 | rec->input[k]=j; | ||
446 | l+=i; | ||
447 | rec->length+=i; | ||
448 | } | ||
449 | |||
450 | EVP_Cipher(ds,rec->data,rec->input,l); | ||
451 | |||
452 | if ((bs != 1) && !send) | ||
453 | { | ||
454 | ii=i=rec->data[l-1]; | ||
455 | i++; | ||
456 | if (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) | ||
457 | { | ||
458 | /* First packet is even in size, so check */ | ||
459 | if ((memcmp(s->s3->read_sequence, | ||
460 | "\0\0\0\0\0\0\0\0",8) == 0) && !(ii & 1)) | ||
461 | s->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG; | ||
462 | if (s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) | ||
463 | i--; | ||
464 | } | ||
465 | if (i > (int)rec->length) | ||
466 | { | ||
467 | SSLerr(SSL_F_TLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); | ||
468 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
469 | return(0); | ||
470 | } | ||
471 | for (j=(int)(l-i); j<(int)l; j++) | ||
472 | { | ||
473 | if (rec->data[j] != ii) | ||
474 | { | ||
475 | SSLerr(SSL_F_TLS1_ENC,SSL_R_DECRYPTION_FAILED); | ||
476 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED); | ||
477 | return(0); | ||
478 | } | ||
479 | } | ||
480 | rec->length-=i; | ||
481 | } | ||
482 | } | ||
483 | return(1); | ||
484 | } | ||
485 | |||
486 | int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in_ctx, unsigned char *out) | ||
487 | { | ||
488 | unsigned int ret; | ||
489 | EVP_MD_CTX ctx; | ||
490 | |||
491 | EVP_MD_CTX_copy(&ctx,in_ctx); | ||
492 | EVP_DigestFinal(&ctx,out,&ret); | ||
493 | return((int)ret); | ||
494 | } | ||
495 | |||
496 | int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | ||
497 | const char *str, int slen, unsigned char *out) | ||
498 | { | ||
499 | unsigned int i; | ||
500 | EVP_MD_CTX ctx; | ||
501 | unsigned char buf[TLS_MD_MAX_CONST_SIZE+MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | ||
502 | unsigned char *q,buf2[12]; | ||
503 | |||
504 | q=buf; | ||
505 | memcpy(q,str,slen); | ||
506 | q+=slen; | ||
507 | |||
508 | EVP_MD_CTX_copy(&ctx,in1_ctx); | ||
509 | EVP_DigestFinal(&ctx,q,&i); | ||
510 | q+=i; | ||
511 | EVP_MD_CTX_copy(&ctx,in2_ctx); | ||
512 | EVP_DigestFinal(&ctx,q,&i); | ||
513 | q+=i; | ||
514 | |||
515 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), | ||
516 | s->session->master_key,s->session->master_key_length, | ||
517 | out,buf2,12); | ||
518 | memset(&ctx,0,sizeof(EVP_MD_CTX)); | ||
519 | |||
520 | return((int)12); | ||
521 | } | ||
522 | |||
523 | int tls1_mac(SSL *ssl, unsigned char *md, int send) | ||
524 | { | ||
525 | SSL3_RECORD *rec; | ||
526 | unsigned char *mac_sec,*seq; | ||
527 | const EVP_MD *hash; | ||
528 | unsigned int md_size; | ||
529 | int i; | ||
530 | HMAC_CTX hmac; | ||
531 | unsigned char buf[5]; | ||
532 | |||
533 | if (send) | ||
534 | { | ||
535 | rec= &(ssl->s3->wrec); | ||
536 | mac_sec= &(ssl->s3->write_mac_secret[0]); | ||
537 | seq= &(ssl->s3->write_sequence[0]); | ||
538 | hash=ssl->write_hash; | ||
539 | } | ||
540 | else | ||
541 | { | ||
542 | rec= &(ssl->s3->rrec); | ||
543 | mac_sec= &(ssl->s3->read_mac_secret[0]); | ||
544 | seq= &(ssl->s3->read_sequence[0]); | ||
545 | hash=ssl->read_hash; | ||
546 | } | ||
547 | |||
548 | md_size=EVP_MD_size(hash); | ||
549 | |||
550 | buf[0]=rec->type; | ||
551 | buf[1]=TLS1_VERSION_MAJOR; | ||
552 | buf[2]=TLS1_VERSION_MINOR; | ||
553 | buf[3]=rec->length>>8; | ||
554 | buf[4]=rec->length&0xff; | ||
555 | |||
556 | /* I should fix this up TLS TLS TLS TLS TLS XXXXXXXX */ | ||
557 | HMAC_Init(&hmac,mac_sec,EVP_MD_size(hash),hash); | ||
558 | HMAC_Update(&hmac,seq,8); | ||
559 | HMAC_Update(&hmac,buf,5); | ||
560 | HMAC_Update(&hmac,rec->input,rec->length); | ||
561 | HMAC_Final(&hmac,md,&md_size); | ||
562 | |||
563 | #ifdef TLS_DEBUG | ||
564 | printf("sec="); | ||
565 | {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); } | ||
566 | printf("seq="); | ||
567 | {int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); } | ||
568 | printf("buf="); | ||
569 | {int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
570 | printf("rec="); | ||
571 | {unsigned int z; for (z=0; z<rec->length; z++) printf("%02X ",buf[z]); printf("\n"); } | ||
572 | #endif | ||
573 | |||
574 | for (i=7; i>=0; i--) | ||
575 | if (++seq[i]) break; | ||
576 | |||
577 | #ifdef TLS_DEBUG | ||
578 | {unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",md[z]); printf("\n"); } | ||
579 | #endif | ||
580 | return(md_size); | ||
581 | } | ||
582 | |||
583 | int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | ||
584 | int len) | ||
585 | { | ||
586 | unsigned char buf[SSL3_RANDOM_SIZE*2+TLS_MD_MASTER_SECRET_CONST_SIZE]; | ||
587 | unsigned char buff[SSL_MAX_MASTER_KEY_LENGTH]; | ||
588 | |||
589 | /* Setup the stuff to munge */ | ||
590 | memcpy(buf,TLS_MD_MASTER_SECRET_CONST, | ||
591 | TLS_MD_MASTER_SECRET_CONST_SIZE); | ||
592 | memcpy(&(buf[TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
593 | s->s3->client_random,SSL3_RANDOM_SIZE); | ||
594 | memcpy(&(buf[SSL3_RANDOM_SIZE+TLS_MD_MASTER_SECRET_CONST_SIZE]), | ||
595 | s->s3->server_random,SSL3_RANDOM_SIZE); | ||
596 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | ||
597 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, | ||
598 | s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE); | ||
599 | return(SSL3_MASTER_SECRET_SIZE); | ||
600 | } | ||
601 | |||
602 | int tls1_alert_code(int code) | ||
603 | { | ||
604 | switch (code) | ||
605 | { | ||
606 | case SSL_AD_CLOSE_NOTIFY: return(SSL3_AD_CLOSE_NOTIFY); | ||
607 | case SSL_AD_UNEXPECTED_MESSAGE: return(SSL3_AD_UNEXPECTED_MESSAGE); | ||
608 | case SSL_AD_BAD_RECORD_MAC: return(SSL3_AD_BAD_RECORD_MAC); | ||
609 | case SSL_AD_DECRYPTION_FAILED: return(TLS1_AD_DECRYPTION_FAILED); | ||
610 | case SSL_AD_RECORD_OVERFLOW: return(TLS1_AD_RECORD_OVERFLOW); | ||
611 | case SSL_AD_DECOMPRESSION_FAILURE:return(SSL3_AD_DECOMPRESSION_FAILURE); | ||
612 | case SSL_AD_HANDSHAKE_FAILURE: return(SSL3_AD_HANDSHAKE_FAILURE); | ||
613 | case SSL_AD_NO_CERTIFICATE: return(-1); | ||
614 | case SSL_AD_BAD_CERTIFICATE: return(SSL3_AD_BAD_CERTIFICATE); | ||
615 | case SSL_AD_UNSUPPORTED_CERTIFICATE:return(SSL3_AD_UNSUPPORTED_CERTIFICATE); | ||
616 | case SSL_AD_CERTIFICATE_REVOKED:return(SSL3_AD_CERTIFICATE_REVOKED); | ||
617 | case SSL_AD_CERTIFICATE_EXPIRED:return(SSL3_AD_CERTIFICATE_EXPIRED); | ||
618 | case SSL_AD_CERTIFICATE_UNKNOWN:return(SSL3_AD_CERTIFICATE_UNKNOWN); | ||
619 | case SSL_AD_ILLEGAL_PARAMETER: return(SSL3_AD_ILLEGAL_PARAMETER); | ||
620 | case SSL_AD_UNKNOWN_CA: return(TLS1_AD_UNKNOWN_CA); | ||
621 | case SSL_AD_ACCESS_DENIED: return(TLS1_AD_ACCESS_DENIED); | ||
622 | case SSL_AD_DECODE_ERROR: return(TLS1_AD_DECODE_ERROR); | ||
623 | case SSL_AD_DECRYPT_ERROR: return(TLS1_AD_DECRYPT_ERROR); | ||
624 | case SSL_AD_EXPORT_RESTRICTION: return(TLS1_AD_EXPORT_RESTRICTION); | ||
625 | case SSL_AD_PROTOCOL_VERSION: return(TLS1_AD_PROTOCOL_VERSION); | ||
626 | case SSL_AD_INSUFFICIENT_SECURITY:return(TLS1_AD_INSUFFICIENT_SECURITY); | ||
627 | case SSL_AD_INTERNAL_ERROR: return(TLS1_AD_INTERNAL_ERROR); | ||
628 | case SSL_AD_USER_CANCELLED: return(TLS1_AD_USER_CANCELLED); | ||
629 | case SSL_AD_NO_RENEGOTIATION: return(TLS1_AD_NO_RENEGOTIATION); | ||
630 | default: return(-1); | ||
631 | } | ||
632 | } | ||
633 | |||
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 9bb36a7d1c..0000000000 --- a/src/lib/libssl/t1_meth.c +++ /dev/null | |||
@@ -1,88 +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 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), | ||
80 | sizeof(SSL_METHOD)); | ||
81 | TLSv1_data.ssl_connect=ssl3_connect; | ||
82 | TLSv1_data.ssl_accept=ssl3_accept; | ||
83 | TLSv1_data.get_ssl_method=tls1_get_method; | ||
84 | init=0; | ||
85 | } | ||
86 | return(&TLSv1_data); | ||
87 | } | ||
88 | |||
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c deleted file mode 100644 index 996b7ca8e2..0000000000 --- a/src/lib/libssl/t1_srvr.c +++ /dev/null | |||
@@ -1,91 +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 <openssl/buffer.h> | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/x509.h> | ||
65 | #include "ssl_locl.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 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), | ||
84 | sizeof(SSL_METHOD)); | ||
85 | TLSv1_server_data.ssl_accept=ssl3_accept; | ||
86 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | ||
87 | init=0; | ||
88 | } | ||
89 | return(&TLSv1_server_data); | ||
90 | } | ||
91 | |||
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf deleted file mode 100644 index b941b7ae15..0000000000 --- a/src/lib/libssl/test/CAss.cnf +++ /dev/null | |||
@@ -1,25 +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 | ||
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/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 c89692d519..0000000000 --- a/src/lib/libssl/test/Uss.cnf +++ /dev/null | |||
@@ -1,28 +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 | ||
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/methtest.c b/src/lib/libssl/test/methtest.c deleted file mode 100644 index 06ccb3b310..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 acaf8f3c47..0000000000 --- a/src/lib/libssl/test/tcrl +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl crl' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testcrl.pem | ||
12 | fi | ||
13 | |||
14 | echo testing crl conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | #echo "p -> t" | ||
21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
22 | #if [ $? != 0 ]; then exit 1; fi | ||
23 | echo "p -> p" | ||
24 | $cmd -in fff.p -inform p -outform p >f.p | ||
25 | if [ $? != 0 ]; then exit 1; fi | ||
26 | |||
27 | echo "d -> d" | ||
28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | #echo "t -> d" | ||
31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
32 | #if [ $? != 0 ]; then exit 1; fi | ||
33 | echo "p -> d" | ||
34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
35 | if [ $? != 0 ]; then exit 1; fi | ||
36 | |||
37 | #echo "d -> t" | ||
38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
39 | #if [ $? != 0 ]; then exit 1; fi | ||
40 | #echo "t -> t" | ||
41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
42 | #if [ $? != 0 ]; then exit 1; fi | ||
43 | #echo "p -> t" | ||
44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
45 | #if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | echo "d -> p" | ||
48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | #echo "t -> p" | ||
51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
52 | #if [ $? != 0 ]; then exit 1; fi | ||
53 | echo "p -> p" | ||
54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
55 | if [ $? != 0 ]; then exit 1; fi | ||
56 | |||
57 | cmp fff.p f.p | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | cmp fff.p ff.p1 | ||
60 | if [ $? != 0 ]; then exit 1; fi | ||
61 | #cmp fff.p ff.p2 | ||
62 | #if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | #cmp f.t ff.t1 | ||
67 | #if [ $? != 0 ]; then exit 1; fi | ||
68 | #cmp f.t ff.t2 | ||
69 | #if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp f.t ff.t3 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | |||
73 | cmp f.p ff.p1 | ||
74 | if [ $? != 0 ]; then exit 1; fi | ||
75 | #cmp f.p ff.p2 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | cmp f.p ff.p3 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | |||
80 | /bin/rm -f f.* ff.* fff.* | ||
81 | 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 88c186b6ab..0000000000 --- a/src/lib/libssl/test/testca +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | SH="/bin/sh" | ||
4 | PATH=../apps:$PATH | ||
5 | export SH PATH | ||
6 | |||
7 | SSLEAY_CONFIG="-config CAss.cnf" | ||
8 | export SSLEAY_CONFIG | ||
9 | |||
10 | /bin/rm -fr demoCA | ||
11 | $SH ../apps/CA.sh -newca <<EOF | ||
12 | EOF | ||
13 | |||
14 | if [ $? != 0 ]; then | ||
15 | exit 1; | ||
16 | fi | ||
17 | |||
18 | SSLEAY_CONFIG="-config Uss.cnf" | ||
19 | export SSLEAY_CONFIG | ||
20 | $SH ../apps/CA.sh -newreq | ||
21 | if [ $? != 0 ]; then | ||
22 | exit 1; | ||
23 | fi | ||
24 | |||
25 | |||
26 | SSLEAY_CONFIG="-config ../apps/openssl.cnf" | ||
27 | export SSLEAY_CONFIG | ||
28 | $SH ../apps/CA.sh -sign <<EOF | ||
29 | y | ||
30 | y | ||
31 | EOF | ||
32 | if [ $? != 0 ]; then | ||
33 | exit 1; | ||
34 | fi | ||
35 | |||
36 | |||
37 | $SH ../apps/CA.sh -verify newcert.pem | ||
38 | if [ $? != 0 ]; then | ||
39 | exit 1; | ||
40 | fi | ||
41 | |||
42 | /bin/rm -fr demoCA newcert.pem newreq.pem | ||
43 | #usage: CA -newcert|-newreq|-newca|-sign|-verify | ||
44 | |||
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 0656c7f525..0000000000 --- a/src/lib/libssl/test/testenc +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | testsrc=Makefile.ssl | ||
4 | test=./p | ||
5 | cmd=../apps/openssl | ||
6 | |||
7 | cat $testsrc >$test; | ||
8 | |||
9 | echo cat | ||
10 | $cmd enc < $test > $test.cipher | ||
11 | $cmd enc < $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 -a -e < $test > $test.cipher | ||
21 | $cmd enc -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 -bufsize 113 -e -k test < $test > $test.$i.cipher | ||
34 | $cmd $i -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 -bufsize 113 -a -e -k test < $test > $test.$i.cipher | ||
45 | $cmd $i -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 c5f61b582b..0000000000 --- a/src/lib/libssl/test/testgen +++ /dev/null | |||
@@ -1,32 +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 | PATH=../apps:$PATH; | ||
10 | export PATH | ||
11 | |||
12 | echo "generating certificate request" | ||
13 | |||
14 | echo "There should be a 2 sequences of .'s and some +'s." | ||
15 | echo "There should not be more that at most 80 per line" | ||
16 | echo "This could take some time." | ||
17 | |||
18 | echo "string to make the random number generator think it has entropy" >> ./.rnd | ||
19 | |||
20 | ../apps/openssl req -config test.cnf -new -out testreq.pem | ||
21 | if [ $? != 0 ]; then | ||
22 | echo problems creating request | ||
23 | exit 1 | ||
24 | fi | ||
25 | |||
26 | ../apps/openssl req -config test.cnf -verify -in testreq.pem -noout | ||
27 | if [ $? != 0 ]; then | ||
28 | echo signature on req is wrong | ||
29 | exit 1 | ||
30 | fi | ||
31 | |||
32 | exit 0 | ||
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem deleted file mode 100644 index 6bba16f137..0000000000 --- a/src/lib/libssl/test/testp7.pem +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | -----BEGIN PKCS7----- | ||
2 | MIAGCSqGSIb3DQEHAqCAMIIIBwIBATEAMIAGCSqGSIb3DQEHAQAAoIIGPDCCBHIw | ||
3 | ggQcoAMCAQICEHkvjiX1iVGQMenF9HgIjI8wDQYJKoZIhvcNAQEEBQAwYjERMA8G | ||
4 | A1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQL | ||
5 | EytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMB4X | ||
6 | DTk2MDcxOTAwMDAwMFoXDTk3MDMzMDIzNTk1OVowgdUxETAPBgNVBAcTCEludGVy | ||
7 | bmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24g | ||
8 | Q2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjEoMCYGA1UECxMfRGln | ||
9 | aXRhbCBJRCBDbGFzcyAxIC0gU01JTUUgVGVzdDFHMEUGA1UECxM+d3d3LnZlcmlz | ||
10 | aWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLjAgSW5jLiBieSBSZWYuLExJQUIuTFRE | ||
11 | KGMpOTYwWzANBgkqhkiG9w0BAQEFAANKADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDO | ||
12 | Rl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMB | ||
13 | AAGjggI5MIICNTAJBgNVHRMEAjAAMIICJgYDVR0DBIICHTCCAhkwggIVMIICEQYL | ||
14 | YIZIAYb4RQEHAQEwggIAFoIBq1RoaXMgY2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVz | ||
15 | IGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0 | ||
16 | bywgdGhlIFZlcmlTaWduIENlcnRpZmljYXRpb24gUHJhY3RpY2UgU3RhdGVtZW50 | ||
17 | IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9D | ||
18 | UFMtMS4wOyBieSBFLW1haWwgYXQgQ1BTLXJlcXVlc3RzQHZlcmlzaWduLmNvbTsg | ||
19 | b3IgYnkgbWFpbCBhdCBWZXJpU2lnbiwgSW5jLiwgMjU5MyBDb2FzdCBBdmUuLCBN | ||
20 | b3VudGFpbiBWaWV3LCBDQSA5NDA0MyBVU0EgVGVsLiArMSAoNDE1KSA5NjEtODgz | ||
21 | MCBDb3B5cmlnaHQgKGMpIDE5OTYgVmVyaVNpZ24sIEluYy4gIEFsbCBSaWdodHMg | ||
22 | UmVzZXJ2ZWQuIENFUlRBSU4gV0FSUkFOVElFUyBESVNDTEFJTUVEIGFuZCBMSUFC | ||
23 | SUxJVFkgTElNSVRFRC6gDgYMYIZIAYb4RQEHAQEBoQ4GDGCGSAGG+EUBBwEBAjAv | ||
24 | MC0WK2h0dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUy0xLgMw | ||
25 | DQYJKoZIhvcNAQEEBQADQQDAmA7km/3iJWEsWN9Z2WU2gmZAknx45WnDKHxMa3Bf | ||
26 | gNsh6BLk/ngkJKjNKTDR13XVHqEPUY1flbjATZputw1GMIIBwjCCAWygAwIBAgIQ | ||
27 | fAmE6tW5ERSQWDneu3KfSTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX | ||
28 | MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0Ew | ||
29 | HhcNOTYwNzE3MDAwMDAwWhcNOTcwNzE3MjM1OTU5WjBiMREwDwYDVQQHEwhJbnRl | ||
30 | cm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWdu | ||
31 | IENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwXDANBgkqhkiG9w0B | ||
32 | AQEFAANLADBIAkEA7Fc6zYJw4WwCWa1ni3fYNbzGSQNluuw990024GusjLfhEk1h | ||
33 | MsIUukTT/n8yxoO7rYp4x+LS+tHF2tBtuxg7CwIDAQABoyIwIDALBgNVHQ8EBAMC | ||
34 | AQYwEQYJYIZIAYb4QgEBBAQDAgIEMA0GCSqGSIb3DQEBAgUAA0EAFKem0cJGg9nd | ||
35 | TAbP5o1HIEyNn11ZlvLU5v1Hejs1MKQt72IMm4jjgOH+pjguXW8lB6yzrK4oVOO2 | ||
36 | UNCaNQ1H26GCAa0wgcEwbTANBgkqhkiG9w0BAQIFADA+MQswCQYDVQQGEwJVUzEX | ||
37 | MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xFjAUBgNVBAsTDVRFU1QgUm9vdCBQQ0EX | ||
38 | DTk2MDcxNzE3NDQwOVoXDTk4MDcxNzAwMDAwMFowDQYJKoZIhvcNAQECBQADQQB4 | ||
39 | rQNP8QLpAox83odQDE/5dqAuvDfshW/miTxwQTMXOoBtjGiowTcG+YXF1JZTJRMT | ||
40 | jQN47tdH+6MCKt7N8MddMIHmMIGRMA0GCSqGSIb3DQEBAgUAMGIxETAPBgNVBAcT | ||
41 | CEludGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVy | ||
42 | aVNpZ24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlchcNOTYwNzE3 | ||
43 | MTc1OTI5WhcNOTcwNzE4MDAwMDAwWjANBgkqhkiG9w0BAQIFAANBALm1VmE7FrEJ | ||
44 | rLXvX/lIDMPAZIw5TNuX8EC6wn5ppy8Y3sHstdJEkTsqVGiS2/q+KEQC3NHxvV32 | ||
45 | bGooiIKLUB4xAAAAAAA= | ||
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 da62997a5f..0000000000 --- a/src/lib/libssl/test/testss +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | digest='-mdc2' | ||
4 | reqcmd="../apps/openssl req" | ||
5 | x509cmd="../apps/openssl x509 $digest" | ||
6 | verifycmd="../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 | echo | ||
21 | echo "make a certificate request using 'req'" | ||
22 | $reqcmd -config $CAconf -out $CAreq -keyout $CAkey -new #>err.ss | ||
23 | if [ $? != 0 ]; then | ||
24 | echo "error using 'req' to generate a certificate request" | ||
25 | exit 1 | ||
26 | fi | ||
27 | echo | ||
28 | echo "convert the certificate request into a self signed certificate using 'x509'" | ||
29 | $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss | ||
30 | if [ $? != 0 ]; then | ||
31 | echo "error using 'x509' to self sign a certificate request" | ||
32 | exit 1 | ||
33 | fi | ||
34 | |||
35 | echo | ||
36 | echo "convert a certificate into a certificate request using 'x509'" | ||
37 | $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss | ||
38 | if [ $? != 0 ]; then | ||
39 | echo "error using 'x509' convert a certificate to a certificate request" | ||
40 | exit 1 | ||
41 | fi | ||
42 | |||
43 | $reqcmd -config $dummycnf -verify -in $CAreq -noout | ||
44 | if [ $? != 0 ]; then | ||
45 | echo first generated request is invalid | ||
46 | exit 1 | ||
47 | fi | ||
48 | |||
49 | $reqcmd -config $dummycnf -verify -in $CAreq2 -noout | ||
50 | if [ $? != 0 ]; then | ||
51 | echo second generated request is invalid | ||
52 | exit 1 | ||
53 | fi | ||
54 | |||
55 | $verifycmd -CAfile $CAcert $CAcert | ||
56 | if [ $? != 0 ]; then | ||
57 | echo first generated cert is invalid | ||
58 | exit 1 | ||
59 | fi | ||
60 | |||
61 | echo | ||
62 | echo "make another certificate request using 'req'" | ||
63 | $reqcmd -config $Uconf -out $Ureq -keyout $Ukey -new >err.ss | ||
64 | if [ $? != 0 ]; then | ||
65 | echo "error using 'req' to generate a certificate request" | ||
66 | exit 1 | ||
67 | fi | ||
68 | |||
69 | echo | ||
70 | echo "sign certificate request with the just created CA via 'x509'" | ||
71 | $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss | ||
72 | if [ $? != 0 ]; then | ||
73 | echo "error using 'x509' to sign a certificate request" | ||
74 | exit 1 | ||
75 | fi | ||
76 | |||
77 | $verifycmd -CAfile $CAcert $Ucert | ||
78 | echo | ||
79 | echo "Certificate details" | ||
80 | $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert | ||
81 | |||
82 | echo | ||
83 | echo The generated CA certificate is $CAcert | ||
84 | echo The generated CA private key is $CAkey | ||
85 | |||
86 | echo The generated user certificate is $Ucert | ||
87 | echo The generated user private key is $Ukey | ||
88 | |||
89 | /bin/rm err.ss | ||
90 | exit 0 | ||
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl deleted file mode 100644 index a88e290c57..0000000000 --- a/src/lib/libssl/test/testssl +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | echo test sslv2 | ||
4 | ./ssltest -ssl2 || exit 1 | ||
5 | |||
6 | echo test sslv2 with server authentication | ||
7 | ./ssltest -ssl2 -server_auth -CApath ../certs || exit 1 | ||
8 | |||
9 | echo test sslv2 with client authentication | ||
10 | ./ssltest -ssl2 -client_auth -CApath ../certs || exit 1 | ||
11 | |||
12 | echo test sslv2 with both client and server authentication | ||
13 | ./ssltest -ssl2 -server_auth -client_auth -CApath ../certs || exit 1 | ||
14 | |||
15 | echo test sslv3 | ||
16 | ./ssltest -ssl3 || exit 1 | ||
17 | |||
18 | echo test sslv3 with server authentication | ||
19 | ./ssltest -ssl3 -server_auth -CApath ../certs || exit 1 | ||
20 | |||
21 | echo test sslv3 with client authentication | ||
22 | ./ssltest -ssl3 -client_auth -CApath ../certs || exit 1 | ||
23 | |||
24 | echo test sslv3 with both client and server authentication | ||
25 | ./ssltest -ssl3 -server_auth -client_auth -CApath ../certs || exit 1 | ||
26 | |||
27 | echo test sslv2/sslv3 | ||
28 | ./ssltest || exit 1 | ||
29 | |||
30 | echo test sslv2/sslv3 with server authentication | ||
31 | ./ssltest -server_auth -CApath ../certs || exit 1 | ||
32 | |||
33 | echo test sslv2/sslv3 with client authentication | ||
34 | ./ssltest -client_auth -CApath ../certs || exit 1 | ||
35 | |||
36 | echo test sslv2/sslv3 with both client and server authentication | ||
37 | ./ssltest -server_auth -client_auth -CApath ../certs || exit 1 | ||
38 | |||
39 | echo test sslv2 via BIO pair | ||
40 | ./ssltest -bio_pair -ssl2 || exit 1 | ||
41 | |||
42 | echo test sslv2 with server authentication via BIO pair | ||
43 | ./ssltest -bio_pair -ssl2 -server_auth -CApath ../certs || exit 1 | ||
44 | |||
45 | echo test sslv2 with client authentication via BIO pair | ||
46 | ./ssltest -bio_pair -ssl2 -client_auth -CApath ../certs || exit 1 | ||
47 | |||
48 | echo test sslv2 with both client and server authentication via BIO pair | ||
49 | ./ssltest -bio_pair -ssl2 -server_auth -client_auth -CApath ../certs || exit 1 | ||
50 | |||
51 | echo test sslv3 via BIO pair | ||
52 | ./ssltest -bio_pair -ssl3 || exit 1 | ||
53 | |||
54 | echo test sslv3 with server authentication via BIO pair | ||
55 | ./ssltest -bio_pair -ssl3 -server_auth -CApath ../certs || exit 1 | ||
56 | |||
57 | echo test sslv3 with client authentication via BIO pair | ||
58 | ./ssltest -bio_pair -ssl3 -client_auth -CApath ../certs || exit 1 | ||
59 | |||
60 | echo test sslv3 with both client and server authentication via BIO pair | ||
61 | ./ssltest -bio_pair -ssl3 -server_auth -client_auth -CApath ../certs || exit 1 | ||
62 | |||
63 | echo test sslv2/sslv3 via BIO pair | ||
64 | ./ssltest || exit 1 | ||
65 | |||
66 | echo test sslv2/sslv3 w/o DHE via BIO pair | ||
67 | ./ssltest -bio_pair -no_dhe || exit 1 | ||
68 | |||
69 | echo test sslv2/sslv3 with 1024bit DHE | ||
70 | ./ssltest -bio_pair -dhe1024 -v || exit 1 | ||
71 | |||
72 | echo test sslv2/sslv3 with server authentication | ||
73 | ./ssltest -bio_pair -server_auth -CApath ../certs || exit 1 | ||
74 | |||
75 | echo test sslv2/sslv3 with client authentication via BIO pair | ||
76 | ./ssltest -bio_pair -client_auth -CApath ../certs || exit 1 | ||
77 | |||
78 | echo test sslv2/sslv3 with both client and server authentication via BIO pair | ||
79 | ./ssltest -bio_pair -server_auth -client_auth -CApath ../certs || exit 1 | ||
80 | |||
81 | exit 0 | ||
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 49aeebf216..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/kernal 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 15bbba42c0..0000000000 --- a/src/lib/libssl/test/tpkcs7 +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl pkcs7' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testp7.pem | ||
12 | fi | ||
13 | |||
14 | echo testing pkcs7 conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | echo "p -> p" | ||
21 | $cmd -in fff.p -inform p -outform p >f.p | ||
22 | if [ $? != 0 ]; then exit 1; fi | ||
23 | |||
24 | echo "d -> d" | ||
25 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
26 | if [ $? != 0 ]; then exit 1; fi | ||
27 | echo "p -> d" | ||
28 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | |||
31 | echo "d -> p" | ||
32 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | echo "p -> p" | ||
35 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
36 | if [ $? != 0 ]; then exit 1; fi | ||
37 | |||
38 | cmp fff.p f.p | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | cmp fff.p ff.p1 | ||
41 | if [ $? != 0 ]; then exit 1; fi | ||
42 | cmp fff.p ff.p3 | ||
43 | if [ $? != 0 ]; then exit 1; fi | ||
44 | |||
45 | cmp f.p ff.p1 | ||
46 | if [ $? != 0 ]; then exit 1; fi | ||
47 | cmp f.p ff.p3 | ||
48 | if [ $? != 0 ]; then exit 1; fi | ||
49 | |||
50 | /bin/rm -f f.* ff.* fff.* | ||
51 | exit 0 | ||
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d deleted file mode 100644 index 46e5aa2bd6..0000000000 --- a/src/lib/libssl/test/tpkcs7d +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl pkcs7' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=pkcs7-1.pem | ||
12 | fi | ||
13 | |||
14 | echo "testing pkcs7 conversions (2)" | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | echo "p -> p" | ||
21 | $cmd -in fff.p -inform p -outform p >f.p | ||
22 | if [ $? != 0 ]; then exit 1; fi | ||
23 | |||
24 | echo "d -> d" | ||
25 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
26 | if [ $? != 0 ]; then exit 1; fi | ||
27 | echo "p -> d" | ||
28 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | |||
31 | echo "d -> p" | ||
32 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
33 | if [ $? != 0 ]; then exit 1; fi | ||
34 | echo "p -> p" | ||
35 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
36 | if [ $? != 0 ]; then exit 1; fi | ||
37 | |||
38 | cmp f.p ff.p1 | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | cmp f.p ff.p3 | ||
41 | if [ $? != 0 ]; then exit 1; fi | ||
42 | |||
43 | /bin/rm -f f.* ff.* fff.* | ||
44 | exit 0 | ||
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq deleted file mode 100644 index 0464c9d902..0000000000 --- a/src/lib/libssl/test/treq +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl req -config ../apps/openssl.cnf' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testreq.pem | ||
12 | fi | ||
13 | |||
14 | echo testing req conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | #echo "p -> t" | ||
21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
22 | #if [ $? != 0 ]; then exit 1; fi | ||
23 | echo "p -> p" | ||
24 | $cmd -in fff.p -inform p -outform p >f.p | ||
25 | if [ $? != 0 ]; then exit 1; fi | ||
26 | |||
27 | echo "d -> d" | ||
28 | $cmd -verify -in f.d -inform d -outform d >ff.d1 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | #echo "t -> d" | ||
31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
32 | #if [ $? != 0 ]; then exit 1; fi | ||
33 | echo "p -> d" | ||
34 | $cmd -verify -in f.p -inform p -outform d >ff.d3 | ||
35 | if [ $? != 0 ]; then exit 1; fi | ||
36 | |||
37 | #echo "d -> t" | ||
38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
39 | #if [ $? != 0 ]; then exit 1; fi | ||
40 | #echo "t -> t" | ||
41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
42 | #if [ $? != 0 ]; then exit 1; fi | ||
43 | #echo "p -> t" | ||
44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
45 | #if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | echo "d -> p" | ||
48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | #echo "t -> p" | ||
51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
52 | #if [ $? != 0 ]; then exit 1; fi | ||
53 | echo "p -> p" | ||
54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
55 | if [ $? != 0 ]; then exit 1; fi | ||
56 | |||
57 | cmp fff.p f.p | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | cmp fff.p ff.p1 | ||
60 | if [ $? != 0 ]; then exit 1; fi | ||
61 | #cmp fff.p ff.p2 | ||
62 | #if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | #cmp f.t ff.t1 | ||
67 | #if [ $? != 0 ]; then exit 1; fi | ||
68 | #cmp f.t ff.t2 | ||
69 | #if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp f.t ff.t3 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | |||
73 | cmp f.p ff.p1 | ||
74 | if [ $? != 0 ]; then exit 1; fi | ||
75 | #cmp f.p ff.p2 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | cmp f.p ff.p3 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | |||
80 | /bin/rm -f f.* ff.* fff.* | ||
81 | exit 0 | ||
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa deleted file mode 100644 index d6a4dd826d..0000000000 --- a/src/lib/libssl/test/trsa +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl rsa' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testrsa.pem | ||
12 | fi | ||
13 | |||
14 | echo testing rsa conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | #echo "p -> t" | ||
21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
22 | #if [ $? != 0 ]; then exit 1; fi | ||
23 | echo "p -> p" | ||
24 | $cmd -in fff.p -inform p -outform p >f.p | ||
25 | if [ $? != 0 ]; then exit 1; fi | ||
26 | |||
27 | echo "d -> d" | ||
28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | #echo "t -> d" | ||
31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
32 | #if [ $? != 0 ]; then exit 1; fi | ||
33 | echo "p -> d" | ||
34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
35 | if [ $? != 0 ]; then exit 1; fi | ||
36 | |||
37 | #echo "d -> t" | ||
38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
39 | #if [ $? != 0 ]; then exit 1; fi | ||
40 | #echo "t -> t" | ||
41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
42 | #if [ $? != 0 ]; then exit 1; fi | ||
43 | #echo "p -> t" | ||
44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
45 | #if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | echo "d -> p" | ||
48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | #echo "t -> p" | ||
51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
52 | #if [ $? != 0 ]; then exit 1; fi | ||
53 | echo "p -> p" | ||
54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
55 | if [ $? != 0 ]; then exit 1; fi | ||
56 | |||
57 | cmp fff.p f.p | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | cmp fff.p ff.p1 | ||
60 | if [ $? != 0 ]; then exit 1; fi | ||
61 | #cmp fff.p ff.p2 | ||
62 | #if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | #cmp f.t ff.t1 | ||
67 | #if [ $? != 0 ]; then exit 1; fi | ||
68 | #cmp f.t ff.t2 | ||
69 | #if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp f.t ff.t3 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | |||
73 | cmp f.p ff.p1 | ||
74 | if [ $? != 0 ]; then exit 1; fi | ||
75 | #cmp f.p ff.p2 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | cmp f.p ff.p3 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | |||
80 | /bin/rm -f f.* ff.* fff.* | ||
81 | exit 0 | ||
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid deleted file mode 100644 index 9e0854516c..0000000000 --- a/src/lib/libssl/test/tsid +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl sess_id' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testsid.pem | ||
12 | fi | ||
13 | |||
14 | echo testing session-id conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | #echo "p -> t" | ||
21 | #$cmd -in fff.p -inform p -outform t >f.t | ||
22 | #if [ $? != 0 ]; then exit 1; fi | ||
23 | echo "p -> p" | ||
24 | $cmd -in fff.p -inform p -outform p >f.p | ||
25 | if [ $? != 0 ]; then exit 1; fi | ||
26 | |||
27 | echo "d -> d" | ||
28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | #echo "t -> d" | ||
31 | #$cmd -in f.t -inform t -outform d >ff.d2 | ||
32 | #if [ $? != 0 ]; then exit 1; fi | ||
33 | echo "p -> d" | ||
34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
35 | if [ $? != 0 ]; then exit 1; fi | ||
36 | |||
37 | #echo "d -> t" | ||
38 | #$cmd -in f.d -inform d -outform t >ff.t1 | ||
39 | #if [ $? != 0 ]; then exit 1; fi | ||
40 | #echo "t -> t" | ||
41 | #$cmd -in f.t -inform t -outform t >ff.t2 | ||
42 | #if [ $? != 0 ]; then exit 1; fi | ||
43 | #echo "p -> t" | ||
44 | #$cmd -in f.p -inform p -outform t >ff.t3 | ||
45 | #if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | echo "d -> p" | ||
48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | #echo "t -> p" | ||
51 | #$cmd -in f.t -inform t -outform p >ff.p2 | ||
52 | #if [ $? != 0 ]; then exit 1; fi | ||
53 | echo "p -> p" | ||
54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
55 | if [ $? != 0 ]; then exit 1; fi | ||
56 | |||
57 | cmp fff.p f.p | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | cmp fff.p ff.p1 | ||
60 | if [ $? != 0 ]; then exit 1; fi | ||
61 | #cmp fff.p ff.p2 | ||
62 | #if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | #cmp f.t ff.t1 | ||
67 | #if [ $? != 0 ]; then exit 1; fi | ||
68 | #cmp f.t ff.t2 | ||
69 | #if [ $? != 0 ]; then exit 1; fi | ||
70 | #cmp f.t ff.t3 | ||
71 | #if [ $? != 0 ]; then exit 1; fi | ||
72 | |||
73 | cmp f.p ff.p1 | ||
74 | if [ $? != 0 ]; then exit 1; fi | ||
75 | #cmp f.p ff.p2 | ||
76 | #if [ $? != 0 ]; then exit 1; fi | ||
77 | cmp f.p ff.p3 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | |||
80 | /bin/rm -f f.* ff.* fff.* | ||
81 | exit 0 | ||
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509 deleted file mode 100644 index 35169f3a43..0000000000 --- a/src/lib/libssl/test/tx509 +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=../apps:$PATH | ||
4 | export PATH | ||
5 | |||
6 | cmd='../apps/openssl x509' | ||
7 | |||
8 | if [ "$1"x != "x" ]; then | ||
9 | t=$1 | ||
10 | else | ||
11 | t=testx509.pem | ||
12 | fi | ||
13 | |||
14 | echo testing X509 conversions | ||
15 | cp $t fff.p | ||
16 | |||
17 | echo "p -> d" | ||
18 | $cmd -in fff.p -inform p -outform d >f.d | ||
19 | if [ $? != 0 ]; then exit 1; fi | ||
20 | echo "p -> n" | ||
21 | $cmd -in fff.p -inform p -outform n >f.n | ||
22 | if [ $? != 0 ]; then exit 1; fi | ||
23 | echo "p -> p" | ||
24 | $cmd -in fff.p -inform p -outform p >f.p | ||
25 | if [ $? != 0 ]; then exit 1; fi | ||
26 | |||
27 | echo "d -> d" | ||
28 | $cmd -in f.d -inform d -outform d >ff.d1 | ||
29 | if [ $? != 0 ]; then exit 1; fi | ||
30 | echo "n -> d" | ||
31 | $cmd -in f.n -inform n -outform d >ff.d2 | ||
32 | if [ $? != 0 ]; then exit 1; fi | ||
33 | echo "p -> d" | ||
34 | $cmd -in f.p -inform p -outform d >ff.d3 | ||
35 | if [ $? != 0 ]; then exit 1; fi | ||
36 | |||
37 | echo "d -> n" | ||
38 | $cmd -in f.d -inform d -outform n >ff.n1 | ||
39 | if [ $? != 0 ]; then exit 1; fi | ||
40 | echo "n -> n" | ||
41 | $cmd -in f.n -inform n -outform n >ff.n2 | ||
42 | if [ $? != 0 ]; then exit 1; fi | ||
43 | echo "p -> n" | ||
44 | $cmd -in f.p -inform p -outform n >ff.n3 | ||
45 | if [ $? != 0 ]; then exit 1; fi | ||
46 | |||
47 | echo "d -> p" | ||
48 | $cmd -in f.d -inform d -outform p >ff.p1 | ||
49 | if [ $? != 0 ]; then exit 1; fi | ||
50 | echo "n -> p" | ||
51 | $cmd -in f.n -inform n -outform p >ff.p2 | ||
52 | if [ $? != 0 ]; then exit 1; fi | ||
53 | echo "p -> p" | ||
54 | $cmd -in f.p -inform p -outform p >ff.p3 | ||
55 | if [ $? != 0 ]; then exit 1; fi | ||
56 | |||
57 | cmp fff.p f.p | ||
58 | if [ $? != 0 ]; then exit 1; fi | ||
59 | cmp fff.p ff.p1 | ||
60 | if [ $? != 0 ]; then exit 1; fi | ||
61 | cmp fff.p ff.p2 | ||
62 | if [ $? != 0 ]; then exit 1; fi | ||
63 | cmp fff.p ff.p3 | ||
64 | if [ $? != 0 ]; then exit 1; fi | ||
65 | |||
66 | cmp f.n ff.n1 | ||
67 | if [ $? != 0 ]; then exit 1; fi | ||
68 | cmp f.n ff.n2 | ||
69 | if [ $? != 0 ]; then exit 1; fi | ||
70 | cmp f.n ff.n3 | ||
71 | if [ $? != 0 ]; then exit 1; fi | ||
72 | |||
73 | cmp f.p ff.p1 | ||
74 | if [ $? != 0 ]; then exit 1; fi | ||
75 | cmp f.p ff.p2 | ||
76 | if [ $? != 0 ]; then exit 1; fi | ||
77 | cmp f.p ff.p3 | ||
78 | if [ $? != 0 ]; then exit 1; fi | ||
79 | |||
80 | /bin/rm -f f.* ff.* fff.* | ||
81 | 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 6e2b06d34f..0000000000 --- a/src/lib/libssl/tls1.h +++ /dev/null | |||
@@ -1,153 +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 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060 | ||
88 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061 | ||
89 | #define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062 | ||
90 | #define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063 | ||
91 | #define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064 | ||
92 | #define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065 | ||
93 | #define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066 | ||
94 | |||
95 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5" | ||
96 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5" | ||
97 | #define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA" | ||
98 | #define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA" | ||
99 | #define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA" | ||
100 | #define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA" | ||
101 | #define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA" | ||
102 | |||
103 | |||
104 | #define TLS_CT_RSA_SIGN 1 | ||
105 | #define TLS_CT_DSS_SIGN 2 | ||
106 | #define TLS_CT_RSA_FIXED_DH 3 | ||
107 | #define TLS_CT_DSS_FIXED_DH 4 | ||
108 | #define TLS_CT_NUMBER 4 | ||
109 | |||
110 | #define TLS1_FINISH_MAC_LENGTH 12 | ||
111 | |||
112 | #define TLS_MD_MAX_CONST_SIZE 20 | ||
113 | #define TLS_MD_CLIENT_FINISH_CONST "client finished" | ||
114 | #define TLS_MD_CLIENT_FINISH_CONST_SIZE 15 | ||
115 | #define TLS_MD_SERVER_FINISH_CONST "server finished" | ||
116 | #define TLS_MD_SERVER_FINISH_CONST_SIZE 15 | ||
117 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
118 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
119 | #define TLS_MD_KEY_EXPANSION_CONST "key expansion" | ||
120 | #define TLS_MD_KEY_EXPANSION_CONST_SIZE 13 | ||
121 | #define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key" | ||
122 | #define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16 | ||
123 | #define TLS_MD_SERVER_WRITE_KEY_CONST "server write key" | ||
124 | #define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16 | ||
125 | #define TLS_MD_IV_BLOCK_CONST "IV block" | ||
126 | #define TLS_MD_IV_BLOCK_CONST_SIZE 8 | ||
127 | #define TLS_MD_MASTER_SECRET_CONST "master secret" | ||
128 | #define TLS_MD_MASTER_SECRET_CONST_SIZE 13 | ||
129 | |||
130 | #ifdef CHARSET_EBCDIC | ||
131 | #undef TLS_MD_CLIENT_FINISH_CONST | ||
132 | #define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/ | ||
133 | #undef TLS_MD_SERVER_FINISH_CONST | ||
134 | #define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/ | ||
135 | #undef TLS_MD_SERVER_WRITE_KEY_CONST | ||
136 | #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*/ | ||
137 | #undef TLS_MD_KEY_EXPANSION_CONST | ||
138 | #define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/ | ||
139 | #undef TLS_MD_CLIENT_WRITE_KEY_CONST | ||
140 | #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*/ | ||
141 | #undef TLS_MD_SERVER_WRITE_KEY_CONST | ||
142 | #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*/ | ||
143 | #undef TLS_MD_IV_BLOCK_CONST | ||
144 | #define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/ | ||
145 | #undef TLS_MD_MASTER_SECRET_CONST | ||
146 | #define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/ | ||
147 | #endif | ||
148 | |||
149 | #ifdef __cplusplus | ||
150 | } | ||
151 | #endif | ||
152 | #endif | ||
153 | |||