summaryrefslogtreecommitdiff
path: root/src/lib/libssl
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2001-04-23 15:30:26 +0000
committercvs2svn <admin@example.com>2001-04-23 15:30:26 +0000
commit5c517720d5b21a720e400586177c050d4bc95721 (patch)
tree34ec35b1061b27f8770c5ac5ee02aad558cbfc90 /src/lib/libssl
parentd2092adc32c6de492232ba39518f9091db6bc67f (diff)
downloadopenbsd-OPENBSD_2_9_BASE.tar.gz
openbsd-OPENBSD_2_9_BASE.tar.bz2
openbsd-OPENBSD_2_9_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_9_BASE'.OPENBSD_2_9_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/LICENSE127
-rw-r--r--src/lib/libssl/bio_ssl.c586
-rw-r--r--src/lib/libssl/doc/openssl.cnf244
-rw-r--r--src/lib/libssl/doc/openssl.txt1235
-rw-r--r--src/lib/libssl/doc/standards.txt121
-rw-r--r--src/lib/libssl/s23_clnt.c475
-rw-r--r--src/lib/libssl/s23_lib.c226
-rw-r--r--src/lib/libssl/s23_pkt.c117
-rw-r--r--src/lib/libssl/s23_srvr.c576
-rw-r--r--src/lib/libssl/s3_both.c588
-rw-r--r--src/lib/libssl/s3_clnt.c1740
-rw-r--r--src/lib/libssl/s3_lib.c1339
-rw-r--r--src/lib/libssl/s3_pkt.c1198
-rw-r--r--src/lib/libssl/s3_srvr.c1755
-rw-r--r--src/lib/libssl/shlib_version2
-rw-r--r--src/lib/libssl/ssl.h1562
-rw-r--r--src/lib/libssl/ssl2.h269
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h429
-rw-r--r--src/lib/libssl/ssl_algs.c103
-rw-r--r--src/lib/libssl/ssl_asn1.c349
-rw-r--r--src/lib/libssl/ssl_cert.c755
-rw-r--r--src/lib/libssl/ssl_ciph.c1071
-rw-r--r--src/lib/libssl/ssl_err.c431
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c2061
-rw-r--r--src/lib/libssl/ssl_locl.h556
-rw-r--r--src/lib/libssl/ssl_rsa.c815
-rw-r--r--src/lib/libssl/ssl_sess.c680
-rw-r--r--src/lib/libssl/ssl_stat.c454
-rw-r--r--src/lib/libssl/ssl_txt.c174
-rw-r--r--src/lib/libssl/t1_clnt.c90
-rw-r--r--src/lib/libssl/t1_enc.c633
-rw-r--r--src/lib/libssl/t1_lib.c149
-rw-r--r--src/lib/libssl/t1_meth.c88
-rw-r--r--src/lib/libssl/t1_srvr.c91
-rw-r--r--src/lib/libssl/test/CAss.cnf25
-rw-r--r--src/lib/libssl/test/CAssdh.cnf24
-rw-r--r--src/lib/libssl/test/CAssdsa.cnf23
-rw-r--r--src/lib/libssl/test/CAssrsa.cnf24
-rw-r--r--src/lib/libssl/test/Sssdsa.cnf27
-rw-r--r--src/lib/libssl/test/Sssrsa.cnf26
-rw-r--r--src/lib/libssl/test/Uss.cnf28
-rw-r--r--src/lib/libssl/test/VMSca-response.11
-rw-r--r--src/lib/libssl/test/VMSca-response.22
-rw-r--r--src/lib/libssl/test/methtest.c105
-rw-r--r--src/lib/libssl/test/pkcs7-1.pem15
-rw-r--r--src/lib/libssl/test/pkcs7.pem54
-rw-r--r--src/lib/libssl/test/r160test.c57
-rw-r--r--src/lib/libssl/test/tcrl81
-rw-r--r--src/lib/libssl/test/test.cnf88
-rw-r--r--src/lib/libssl/test/testca44
-rw-r--r--src/lib/libssl/test/testcrl.pem16
-rw-r--r--src/lib/libssl/test/testenc54
-rw-r--r--src/lib/libssl/test/testgen32
-rw-r--r--src/lib/libssl/test/testp7.pem46
-rw-r--r--src/lib/libssl/test/testreq2.pem7
-rw-r--r--src/lib/libssl/test/testrsa.pem9
-rw-r--r--src/lib/libssl/test/testsid.pem12
-rw-r--r--src/lib/libssl/test/testss90
-rw-r--r--src/lib/libssl/test/testssl81
-rw-r--r--src/lib/libssl/test/testx509.pem10
-rw-r--r--src/lib/libssl/test/times113
-rw-r--r--src/lib/libssl/test/tpkcs751
-rw-r--r--src/lib/libssl/test/tpkcs7d44
-rw-r--r--src/lib/libssl/test/treq81
-rw-r--r--src/lib/libssl/test/trsa81
-rw-r--r--src/lib/libssl/test/tsid81
-rw-r--r--src/lib/libssl/test/tx50981
-rw-r--r--src/lib/libssl/test/v3-cert1.pem16
-rw-r--r--src/lib/libssl/test/v3-cert2.pem16
-rw-r--r--src/lib/libssl/tls1.h164
72 files changed, 0 insertions, 22951 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 d85555a7e6..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
68static int ssl_write(BIO *h, const char *buf, int num);
69static int ssl_read(BIO *h, char *buf, int size);
70static int ssl_puts(BIO *h, const char *str);
71static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2);
72static int ssl_new(BIO *h);
73static int ssl_free(BIO *data);
74static long ssl_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
75typedef 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
86static 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
99BIO_METHOD *BIO_f_ssl(void)
100 {
101 return(&methods_sslp);
102 }
103
104static int ssl_new(BIO *bi)
105 {
106 BIO_SSL *bs;
107
108 bs=(BIO_SSL *)OPENSSL_malloc(sizeof(BIO_SSL));
109 if (bs == NULL)
110 {
111 BIOerr(BIO_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
112 return(0);
113 }
114 memset(bs,0,sizeof(BIO_SSL));
115 bi->init=0;
116 bi->ptr=(char *)bs;
117 bi->flags=0;
118 return(1);
119 }
120
121static int ssl_free(BIO *a)
122 {
123 BIO_SSL *bs;
124
125 if (a == NULL) return(0);
126 bs=(BIO_SSL *)a->ptr;
127 if (bs->ssl != NULL) SSL_shutdown(bs->ssl);
128 if (a->shutdown)
129 {
130 if (a->init && (bs->ssl != NULL))
131 SSL_free(bs->ssl);
132 a->init=0;
133 a->flags=0;
134 }
135 if (a->ptr != NULL)
136 OPENSSL_free(a->ptr);
137 return(1);
138 }
139
140static 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
224static int ssl_write(BIO *b, const 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
292static long ssl_ctrl(BIO *b, int cmd, long num, void *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
473static long ssl_callback_ctrl(BIO *b, int cmd, bio_info_cb *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
495static int ssl_puts(BIO *bp, const char *str)
496 {
497 int n,ret;
498
499 n=strlen(str);
500 ret=BIO_write(bp,str,n);
501 return(ret);
502 }
503
504BIO *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);
515err:
516 if (buf != NULL) BIO_free(buf);
517 if (ssl != NULL) BIO_free(ssl);
518 return(NULL);
519 }
520
521BIO *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);
532err:
533 if (con != NULL) BIO_free(con);
534 if (ret != NULL) BIO_free(ret);
535 return(NULL);
536 }
537
538BIO *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
559int 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
572void 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.
8HOME = .
9RANDFILE = $ENV::HOME/.rnd
10
11# Extra OBJECT IDENTIFIER info:
12#oid_file = $ENV::HOME/.oid
13oid_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 ]
32default_ca = CA_default # The default ca section
33
34####################################################################
35[ CA_default ]
36
37dir = ./demoCA # Where everything is kept
38certs = $dir/certs # Where the issued certs are kept
39crl_dir = $dir/crl # Where the issued crl are kept
40database = $dir/index.txt # database index file.
41new_certs_dir = $dir/newcerts # default place for new certs.
42
43certificate = $dir/cacert.pem # The CA certificate
44serial = $dir/serial # The current serial number
45crl = $dir/crl.pem # The current CRL
46private_key = $dir/private/cakey.pem# The private key
47RANDFILE = $dir/private/.rand # private random number file
48
49x509_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
55default_days = 365 # how long to certify for
56default_crl_days= 30 # how long before next CRL
57default_md = md5 # which md to use.
58preserve = 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 :-)
63policy = policy_match
64
65# For the CA policy
66[ policy_match ]
67countryName = match
68stateOrProvinceName = match
69organizationName = match
70organizationalUnitName = optional
71commonName = supplied
72emailAddress = optional
73
74# For the 'anything' policy
75# At this point in time, you must list all acceptable 'object'
76# types.
77[ policy_anything ]
78countryName = optional
79stateOrProvinceName = optional
80localityName = optional
81organizationName = optional
82organizationalUnitName = optional
83commonName = supplied
84emailAddress = optional
85
86####################################################################
87[ req ]
88default_bits = 1024
89default_keyfile = privkey.pem
90distinguished_name = req_distinguished_name
91attributes = req_attributes
92x509_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!
106string_mask = nombstr
107
108# req_extensions = v3_req # The extensions to add to a certificate request
109
110[ req_distinguished_name ]
111countryName = Country Name (2 letter code)
112countryName_default = AU
113countryName_min = 2
114countryName_max = 2
115
116stateOrProvinceName = State or Province Name (full name)
117stateOrProvinceName_default = Some-State
118
119localityName = Locality Name (eg, city)
120
1210.organizationName = Organization Name (eg, company)
1220.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
128organizationalUnitName = Organizational Unit Name (eg, section)
129#organizationalUnitName_default =
130
131commonName = Common Name (eg, YOUR name)
132commonName_max = 64
133
134emailAddress = Email Address
135emailAddress_max = 40
136
137# SET-ex3 = SET extension number 3
138
139[ req_attributes ]
140challengePassword = A challenge password
141challengePassword_min = 4
142challengePassword_max = 20
143
144unstructuredName = 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
153basicConstraints=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.
174nsComment = "OpenSSL Generated Certificate"
175
176# PKIX recommendations harmless if included in all certificates.
177subjectKeyIdentifier=hash
178authorityKeyIdentifier=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
198basicConstraints = CA:FALSE
199keyUsage = nonRepudiation, digitalSignature, keyEncipherment
200
201[ v3_ca ]
202
203
204# Extensions for a typical CA
205
206
207# PKIX recommendation.
208
209subjectKeyIdentifier=hash
210
211authorityKeyIdentifier=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.
217basicConstraints = 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
244authorityKeyIdentifier=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 5da519e7e4..0000000000
--- a/src/lib/libssl/doc/openssl.txt
+++ /dev/null
@@ -1,1235 +0,0 @@
1
2This is some preliminary documentation for OpenSSL.
3
4Contents:
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
15OpenSSL X509V3 extension configuration: preliminary documentation.
16
17INTRODUCTION.
18
19For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
20possible to add and print out common X509 V3 certificate and CRL extensions.
21
22BEGINNERS NOTE
23
24For most simple applications you don't need to know too much about extensions:
25the default openssl.cnf values will usually do sensible things.
26
27If you want to know more you can initially quickly look through the sections
28describing how the standard OpenSSL utilities display and add extensions and
29then the list of supported extensions.
30
31For more technical information about the meaning of extensions see:
32
33http://www.imc.org/ietf-pkix/
34http://home.netscape.com/eng/security/certs.html
35
36PRINTING EXTENSIONS.
37
38Extension values are automatically printed out for supported extensions.
39
40openssl x509 -in cert.pem -text
41openssl crl -in crl.pem -text
42
43will 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
57CONFIGURATION FILES.
58
59The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
60which certificate extensions to include. In each case a line:
61
62x509_extensions = extension_section
63
64indicates which section contains the extensions. In the case of 'req' the
65extension section is used when the -x509 option is present to create a
66self signed root certificate.
67
68The 'x509' utility also supports extensions when it signs a certificate.
69The -extfile option is used to set the configuration file containing the
70extensions. In this case a line with:
71
72extensions = extension_section
73
74in the nameless (default) section is used. If no such line is included then
75it uses the default section.
76
77You can also add extensions to CRLs: a line
78
79crl_extensions = crl_extension_section
80
81will include extensions when the -gencrl option is used with the 'ca' utility.
82You can add any extension to a CRL but of the supported extensions only
83issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
84CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
85CRL entry extensions can be displayed.
86
87NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
88you should not include a crl_extensions line in the configuration file.
89
90As with all configuration files you can use the inbuilt environment expansion
91to allow the values to be passed in the environment. Therefore if you have
92several extension sections used for different purposes you can have a line:
93
94x509_extensions = $ENV::ENV_EXT
95
96and set the ENV_EXT environment variable before calling the relevant utility.
97
98EXTENSION SYNTAX.
99
100Extensions have the basic form:
101
102extension_name=[critical,] extension_options
103
104the use of the critical option makes the extension critical. Extreme caution
105should be made when using the critical flag. If an extension is marked
106as critical then any client that does not understand the extension should
107reject it as invalid. Some broken software will reject certificates which
108have *any* critical extensions (these violates PKIX but we have to live
109with it).
110
111There are three main types of extension: string extensions, multi-valued
112extensions, and raw extensions.
113
114String extensions simply have a string which contains either the value itself
115or how it is obtained.
116
117For example:
118
119nsComment="This is a Comment"
120
121Multi-valued extensions have a short form and a long form. The short form
122is a list of names and values:
123
124basicConstraints=critical,CA:true,pathlen:1
125
126The long form allows the values to be placed in a separate section:
127
128basicConstraints=critical,@bs_section
129
130[bs_section]
131
132CA=true
133pathlen=1
134
135Both forms are equivalent. However it should be noted that in some cases the
136same name can appear multiple times, for example,
137
138subjectAltName=email:steve@here,email:steve@there
139
140in this case an equivalent long form is:
141
142subjectAltName=@alt_section
143
144[alt_section]
145
146email.1=steve@here
147email.2=steve@there
148
149This is because the configuration file code cannot handle the same name
150occurring twice in the same section.
151
152The syntax of raw extensions is governed by the extension code: it can
153for example contain data in multiple sections. The correct syntax to
154use is defined by the extension code itself: check out the certificate
155policies extension for an example.
156
157In addition it is also possible to use the word DER to include arbitrary
158data in any extension.
159
1601.2.3.4=critical,DER:01:02:03:04
1611.2.3.4=DER:01020304
162
163The value following DER is a hex dump of the DER encoding of the extension
164Any extension can be placed in this form to override the default behaviour.
165For example:
166
167basicConstraints=critical,DER:00:01:02:03
168
169WARNING: DER should be used with caution. It is possible to create totally
170invalid extensions unless care is taken.
171
172CURRENTLY SUPPORTED EXTENSIONS.
173
174If you aren't sure about extensions then they can be largely ignored: its only
175when you want to do things like restrict certificate usage when you need to
176worry about them.
177
178The only extension that a beginner might want to look at is Basic Constraints.
179If in addition you want to try Netscape object signing the you should also
180look at Netscape Certificate Type.
181
182Literal String extensions.
183
184In each case the 'value' of the extension is placed directly in the
185extension. Currently supported extensions in this category are: nsBaseUrl,
186nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
187nsSslServerName and nsComment.
188
189For example:
190
191nsComment="This is a test comment"
192
193Bit Strings.
194
195Bit string extensions just consist of a list of supported bits, currently
196two extensions are in this category: PKIX keyUsage and the Netscape specific
197nsCertType.
198
199nsCertType (netscape certificate type) takes the flags: client, server, email,
200objsign, reserved, sslCA, emailCA, objCA.
201
202keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
203keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
204encipherOnly, decipherOnly.
205
206For example:
207
208nsCertType=server
209
210keyUsage=digitalSignature, nonRepudiation
211
212Hints on Netscape Certificate Type.
213
214Other than Basic Constraints this is the only extension a beginner might
215want to use, if you want to try Netscape object signing, otherwise it can
216be ignored.
217
218If you want a certificate that can be used just for object signing then:
219
220nsCertType=objsign
221
222will do the job. If you want to use it as a normal end user and server
223certificate as well then
224
225nsCertType=objsign,email,server
226
227is more appropriate. You cannot use a self signed certificate for object
228signing (well Netscape signtool can but it cheats!) so you need to create
229a CA certificate and sign an end user certificate with it.
230
231Side note: If you want to conform to the Netscape specifications then you
232should really also set:
233
234nsCertType=objCA
235
236in the *CA* certificate for just an object signing CA and
237
238nsCertType=objCA,emailCA,sslCA
239
240for everything. Current Netscape software doesn't enforce this so it can
241be omitted.
242
243Basic Constraints.
244
245This is generally the only extension you need to worry about for simple
246applications. 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
249basicConstraints=CA:TRUE
250
251if you want to be certain the certificate cannot be used as a CA then do:
252
253basicConstraints=CA:FALSE
254
255The rest of this section describes more advanced usage.
256
257Basic constraints is a multi-valued extension that supports a CA and an
258optional pathlen option. The CA option takes the values true and false and
259pathlen takes an integer. Note if the CA option is false the pathlen option
260should be omitted.
261
262The pathlen parameter indicates the maximum number of CAs that can appear
263below this one in a chain. So if you have a CA with a pathlen of zero it can
264only be used to sign end user certificates and not further CAs. This all
265assumes that the software correctly interprets this extension of course.
266
267Examples:
268
269basicConstraints=CA:TRUE
270basicConstraints=critical,CA:TRUE, pathlen:0
271
272NOTE: for a CA to be considered valid it must have the CA option set to
273TRUE. An end user certificate MUST NOT have the CA value set to true.
274According to PKIX recommendations it should exclude the extension entirely,
275however some software may require CA set to FALSE for end entity certificates.
276
277Extended Key Usage.
278
279This extensions consists of a list of usages.
280
281These can either be object short names of the dotted numerical form of OIDs.
282While any OID can be used only certain values make sense. In particular the
283following PKIX, NS and MS values are meaningful:
284
285Value Meaning
286----- -------
287serverAuth SSL/TLS Web Server Authentication.
288clientAuth SSL/TLS Web Client Authentication.
289codeSigning Code signing.
290emailProtection E-mail Protection (S/MIME).
291timeStamping Trusted Timestamping
292msCodeInd Microsoft Individual Code Signing (authenticode)
293msCodeCom Microsoft Commercial Code Signing (authenticode)
294msCTLSign Microsoft Trust List Signing
295msSGC Microsoft Server Gated Crypto
296msEFS Microsoft Encrypted File System
297nsSGC Netscape Server Gated Crypto
298
299For example, under IE5 a CA can be used for any purpose: by including a list
300of the above usages the CA can be restricted to only authorised uses.
301
302Note: software packages may place additional interpretations on certificate
303use, in particular some usages may only work for selected CAs. Don't for example
304expect just including msSGC or nsSGC will automatically mean that a certificate
305can be used for SGC ("step up" encryption) otherwise anyone could use it.
306
307Examples:
308
309extendedKeyUsage=critical,codeSigning,1.2.3.4
310extendedKeyUsage=nsSGC,msSGC
311
312Subject Key Identifier.
313
314This is really a string extension and can take two possible values. Either
315a hex string giving details of the extension value to include or the word
316'hash' which then automatically follow PKIX guidelines in selecting and
317appropriate key identifier. The use of the hex string is strongly discouraged.
318
319Example: subjectKeyIdentifier=hash
320
321Authority Key Identifier.
322
323The authority key identifier extension permits two options. keyid and issuer:
324both can take the optional value "always".
325
326If the keyid option is present an attempt is made to copy the subject key
327identifier from the parent certificate. If the value "always" is present
328then an error is returned if the option fails.
329
330The issuer option copies the issuer and serial number from the issuer
331certificate. Normally this will only be done if the keyid option fails or
332is not included: the "always" flag will always include the value.
333
334Subject Alternative Name.
335
336The subject alternative name extension allows various literal values to be
337included in the configuration file. These include "email" (an email address)
338"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
339registered ID: OBJECT IDENTIFIER) and IP (and IP address).
340
341Also the email option include a special 'copy' value. This will automatically
342include and email addresses contained in the certificate subject name in
343the extension.
344
345Examples:
346
347subjectAltName=email:copy,email:my@other.address,URL:http://my.url.here/
348subjectAltName=email:my@other.address,RID:1.2.3.4
349
350Issuer Alternative Name.
351
352The issuer alternative name option supports all the literal options of
353subject alternative name. It does *not* support the email:copy option because
354that would not make sense. It does support an additional issuer:copy option
355that will copy all the subject alternative name values from the issuer
356certificate (if possible).
357
358Example:
359
360issuserAltName = issuer:copy
361
362Authority Info Access.
363
364The authority information access extension gives details about how to access
365certain information relating to the CA. Its syntax is accessOID;location
366where 'location' has the same syntax as subject alternative name (except
367that email:copy is not supported). accessOID can be any valid OID but only
368certain values are meaningful for example OCSP and caIssuers. OCSP gives the
369location of an OCSP responder: this is used by Netscape PSM and other software.
370
371Example:
372
373authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
374authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
375
376CRL distribution points.
377
378This is a multi-valued extension that supports all the literal options of
379subject alternative name. Of the few software packages that currently interpret
380this extension most only interpret the URI option.
381
382Currently each option will set a new DistributionPoint with the fullName
383field set to the given value.
384
385Other fields like cRLissuer and reasons cannot currently be set or displayed:
386at this time no examples were available that used these fields.
387
388If you see this extension with <UNSUPPORTED> when you attempt to print it out
389or it doesn't appear to display correctly then let me know, including the
390certificate (mail me at steve@openssl.org) .
391
392Examples:
393
394crlDistributionPoints=URI:http://www.myhost.com/myca.crl
395crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
396
397Certificate Policies.
398
399This is a RAW extension. It attempts to display the contents of this extension:
400unfortunately this extension is often improperly encoded.
401
402The certificate policies extension will rarely be used in practice: few
403software packages interpret it correctly or at all. IE5 does partially
404support this extension: but it needs the 'ia5org' option because it will
405only correctly support a broken encoding. Of the options below only the
406policy OID, explicitText and CPS options are displayed with IE5.
407
408All the fields of this extension can be set by using the appropriate syntax.
409
410If you follow the PKIX recommendations of not including any qualifiers and just
411using only one OID then you just include the value of that OID. Multiple OIDs
412can be set separated by commas, for example:
413
414certificatePolicies= 1.2.4.5, 1.1.3.4
415
416If you wish to include qualifiers then the policy OID and qualifiers need to
417be specified in a separate section: this is done by using the @section syntax
418instead of a literal OID value.
419
420The section referred to must include the policy OID using the name
421policyIdentifier, cPSuri qualifiers can be included using the syntax:
422
423CPS.nnn=value
424
425userNotice qualifiers can be set using the syntax:
426
427userNotice.nnn=@notice
428
429The value of the userNotice qualifier is specified in the relevant section.
430This section can include explicitText, organization and noticeNumbers
431options. explicitText and organization are text strings, noticeNumbers is a
432comma separated list of numbers. The organization and noticeNumbers options
433(if included) must BOTH be present. If you use the userNotice option with IE5
434then you need the 'ia5org' option at the top level to modify the encoding:
435otherwise it will not be interpreted properly.
436
437Example:
438
439certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
440
441[polsect]
442
443policyIdentifier = 1.3.5.8
444CPS.1="http://my.host.name/"
445CPS.2="http://my.your.name/"
446userNotice.1=@notice
447
448[notice]
449
450explicitText="Explicit Text Here"
451organization="Organisation Name"
452noticeNumbers=1,2,3,4
453
454TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
455according to PKIX it should be of type DisplayText but Verisign uses an
456IA5STRING and IE5 needs this too.
457
458Display only extensions.
459
460Some extensions are only partially supported and currently are only displayed
461but cannot be set. These include private key usage period, CRL number, and
462CRL reason.
463
464==============================================================================
465 X509V3 Extension code: programmers guide
466==============================================================================
467
468The purpose of the extension code is twofold. It allows an extension to be
469created from a string or structure describing its contents and it prints out an
470extension in a human or machine readable form.
471
4721. Initialisation and cleanup.
473
474No special initialisation is needed before calling the extension functions.
475You used to have to call X509V3_add_standard_extensions(); but this is no longer
476required and this function no longer does anything.
477
478void X509V3_EXT_cleanup(void);
479
480This function should be called to cleanup the extension code if any custom
481extensions have been added. If no custom extensions have been added then this
482call does nothing. After this call all custom extension code is freed up but
483you can still use the standard extensions.
484
4852. Printing and parsing extensions.
486
487The simplest way to print out extensions is via the standard X509 printing
488routines: if you use the standard X509_print() function, the supported
489extensions will be printed out automatically.
490
491The following functions allow finer control over extension display:
492
493int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
494int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
495
496These two functions print out an individual extension to a BIO or FILE pointer.
497Currently the flag argument is unused and should be set to 0. The 'indent'
498argument is the number of spaces to indent each line.
499
500void *X509V3_EXT_d2i(X509_EXTENSION *ext);
501
502This function parses an extension and returns its internal structure. The
503precise structure you get back depends on the extension being parsed. If the
504extension if basicConstraints you will get back a pointer to a
505BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
506details about the structures returned. The returned structure should be freed
507after use using the relevant free function, BASIC_CONSTRAINTS_free() for
508example.
509
510void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
511void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
512void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
513void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
514
515These functions combine the operations of searching for extensions and
516parsing them. They search a certificate, a CRL a CRL entry or a stack
517of extensions respectively for extension whose NID is 'nid' and return
518the parsed result of NULL if an error occurred. For example:
519
520BASIC_CONSTRAINTS *bs;
521bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
522
523This will search for the basicConstraints extension and either return
524it value or NULL. NULL can mean either the extension was not found, it
525occurred more than once or it could not be parsed.
526
527If 'idx' is NULL then an extension is only parsed if it occurs precisely
528once. This is standard behaviour because extensions normally cannot occur
529more than once. If however more than one extension of the same type can
530occur it can be used to parse successive extensions for example:
531
532int i;
533void *ext;
534
535i = -1;
536for(;;) {
537 ext = X509_get_ext_d2i(x, nid, crit, &idx);
538 if(ext == NULL) break;
539 /* Do something with ext */
540}
541
542If 'crit' is not NULL and the extension was found then the int it points to
543is set to 1 for critical extensions and 0 for non critical. Therefore if the
544function returns NULL but 'crit' is set to 0 or 1 then the extension was
545found but it could not be parsed.
546
547The int pointed to by crit will be set to -1 if the extension was not found
548and -2 if the extension occurred more than once (this will only happen if
549idx is NULL). In both cases the function will return NULL.
550
5513. Generating extensions.
552
553An extension will typically be generated from a configuration file, or some
554other kind of configuration database.
555
556int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
557 X509 *cert);
558int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
559 X509_CRL *crl);
560
561These functions add all the extensions in the given section to the given
562certificate or CRL. They will normally be called just before the certificate
563or CRL is due to be signed. Both return 0 on error on non zero for success.
564
565In each case 'conf' is the LHASH pointer of the configuration file to use
566and 'section' is the section containing the extension details.
567
568See the 'context functions' section for a description of the ctx parameter.
569
570
571X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
572 char *value);
573
574This function returns an extension based on a name and value pair, if the
575pair will not need to access other sections in a config file (or there is no
576config file) then the 'conf' parameter can be set to NULL.
577
578X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
579 char *value);
580
581This function creates an extension in the same way as X509V3_EXT_conf() but
582takes the NID of the extension rather than its name.
583
584For example to produce basicConstraints with the CA flag and a path length of
58510:
586
587x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
588
589
590X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
591
592This function sets up an extension from its internal structure. The ext_nid
593parameter is the NID of the extension and 'crit' is the critical flag.
594
5954. Context functions.
596
597The following functions set and manipulate an extension context structure.
598The purpose of the extension context is to allow the extension code to
599access various structures relating to the "environment" of the certificate:
600for example the issuers certificate or the certificate request.
601
602void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
603 X509_REQ *req, X509_CRL *crl, int flags);
604
605This function sets up an X509V3_CTX structure with details of the certificate
606environment: specifically the issuers certificate, the subject certificate,
607the certificate request and the CRL: if these are not relevant or not
608available then they can be set to NULL. The 'flags' parameter should be set
609to zero.
610
611X509V3_set_ctx_test(ctx)
612
613This macro is used to set the 'ctx' structure to a 'test' value: this is to
614allow the syntax of an extension (or configuration file) to be tested.
615
616X509V3_set_ctx_nodb(ctx)
617
618This macro is used when no configuration database is present.
619
620void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
621
622This function is used to set the configuration database when it is an LHASH
623structure: typically a configuration file.
624
625The following functions are used to access a configuration database: they
626should only be used in RAW extensions.
627
628char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
629
630This function returns the value of the parameter "name" in "section", or NULL
631if there has been an error.
632
633void X509V3_string_free(X509V3_CTX *ctx, char *str);
634
635This function frees up the string returned by the above function.
636
637STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
638
639This function returns a whole section as a STACK_OF(CONF_VALUE) .
640
641void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
642
643This function frees up the STACK returned by the above function.
644
645Note: it is possible to use the extension code with a custom configuration
646database. To do this the "db_meth" element of the X509V3_CTX structure should
647be set to an X509V3_CTX_METHOD structure. This structure contains the following
648function pointers:
649
650char * (*get_string)(void *db, char *section, char *value);
651STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
652void (*free_string)(void *db, char * string);
653void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
654
655these will be called and passed the 'db' element in the X509V3_CTX structure
656to access the database. If a given function is not implemented or not required
657it can be set to NULL.
658
6595. String helper functions.
660
661There are several "i2s" and "s2i" functions that convert structures to and
662from ASCII strings. In all the "i2s" cases the returned string should be
663freed using Free() after use. Since some of these are part of other extension
664code they may take a 'method' parameter. Unless otherwise stated it can be
665safely set to NULL.
666
667char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
668
669This returns a hex string from an ASN1_OCTET_STRING.
670
671char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
672char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
673
674These return a string decimal representations of an ASN1_INTEGER and an
675ASN1_ENUMERATED type, respectively.
676
677ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
678 X509V3_CTX *ctx, char *str);
679
680This converts an ASCII hex string to an ASN1_OCTET_STRING.
681
682ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
683
684This converts a decimal ASCII string into an ASN1_INTEGER.
685
6866. Multi valued extension helper functions.
687
688The following functions can be used to manipulate STACKs of CONF_VALUE
689structures, as used by multi valued extensions.
690
691int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
692
693This function expects a boolean value in 'value' and sets 'asn1_bool' to
694it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
695strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
696"false", "N", "n", "NO" or "no".
697
698int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
699
700This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
701
702int X509V3_add_value(const char *name, const char *value,
703 STACK_OF(CONF_VALUE) **extlist);
704
705This simply adds a string name and value pair.
706
707int X509V3_add_value_uchar(const char *name, const unsigned char *value,
708 STACK_OF(CONF_VALUE) **extlist);
709
710The same as above but for an unsigned character value.
711
712int X509V3_add_value_bool(const char *name, int asn1_bool,
713 STACK_OF(CONF_VALUE) **extlist);
714
715This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
716
717int X509V3_add_value_bool_nf(char *name, int asn1_bool,
718 STACK_OF(CONF_VALUE) **extlist);
719
720This is the same as above except it adds nothing if asn1_bool is FALSE.
721
722int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
723 STACK_OF(CONF_VALUE) **extlist);
724
725This function adds the value of the ASN1_INTEGER in decimal form.
726
7277. Other helper functions.
728
729<to be added>
730
731ADDING CUSTOM EXTENSIONS.
732
733Currently there are three types of supported extensions.
734
735String extensions are simple strings where the value is placed directly in the
736extensions, and the string returned is printed out.
737
738Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
739or return a STACK_OF(CONF_VALUE).
740
741Raw extensions are just passed a BIO or a value and it is the extensions
742responsibility to handle all the necessary printing.
743
744There are two ways to add an extension. One is simply as an alias to an already
745existing extension. An alias is an extension that is identical in ASN1 structure
746to an existing extension but has a different OBJECT IDENTIFIER. This can be
747done by calling:
748
749int X509V3_EXT_add_alias(int nid_to, int nid_from);
750
751'nid_to' is the new extension NID and 'nid_from' is the already existing
752extension NID.
753
754Alternatively an extension can be written from scratch. This involves writing
755the ASN1 code to encode and decode the extension and functions to print out and
756generate the extension from strings. The relevant functions are then placed in
757a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
758called.
759
760The X509V3_EXT_METHOD structure is described below.
761
762strut {
763int ext_nid;
764int ext_flags;
765X509V3_EXT_NEW ext_new;
766X509V3_EXT_FREE ext_free;
767X509V3_EXT_D2I d2i;
768X509V3_EXT_I2D i2d;
769X509V3_EXT_I2S i2s;
770X509V3_EXT_S2I s2i;
771X509V3_EXT_I2V i2v;
772X509V3_EXT_V2I v2i;
773X509V3_EXT_R2I r2i;
774X509V3_EXT_I2R i2r;
775
776void *usr_data;
777};
778
779The elements have the following meanings.
780
781ext_nid is the NID of the object identifier of the extension.
782
783ext_flags is set of flags. Currently the only external flag is
784 X509V3_EXT_MULTILINE which means a multi valued extensions
785 should be printed on separate lines.
786
787usr_data is an extension specific pointer to any relevant data. This
788 allows extensions to share identical code but have different
789 uses. An example of this is the bit string extension which uses
790 usr_data to contain a list of the bit names.
791
792All the remaining elements are function pointers.
793
794ext_new is a pointer to a function that allocates memory for the
795 extension ASN1 structure: for example ASN1_OBJECT_new().
796
797ext_free is a pointer to a function that free up memory of the extension
798 ASN1 structure: for example ASN1_OBJECT_free().
799
800d2i is the standard ASN1 function that converts a DER buffer into
801 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
802
803i2d is the standard ASN1 function that converts the internal
804 structure into the DER representation: for example
805 i2d_ASN1_IA5STRING().
806
807The remaining functions are depend on the type of extension. One i2X and
808one X2i should be set and the rest set to NULL. The types set do not need
809to match up, for example the extension could be set using the multi valued
810v2i function and printed out using the raw i2r.
811
812All functions have the X509V3_EXT_METHOD passed to them in the 'method'
813parameter and an X509V3_CTX structure. Extension code can then access the
814parent structure via the 'method' parameter to for example make use of the value
815of usr_data. If the code needs to use detail relating to the request it can
816use the 'ctx' parameter.
817
818A note should be given here about the 'flags' member of the 'ctx' parameter.
819If it has the value CTX_TEST then the configuration syntax is being checked
820and no actual certificate or CRL exists. Therefore any attempt in the config
821file to access such information should silently succeed. If the syntax is OK
822then it should simply return a (possibly bogus) extension, otherwise it
823should return NULL.
824
825char *i2s(struct v3_ext_method *method, void *ext);
826
827This function takes the internal structure in the ext parameter and returns
828a Malloc'ed string representing its value.
829
830void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
831
832This function takes the string representation in the ext parameter and returns
833an allocated internal structure: ext_free() will be used on this internal
834structure after use.
835
836i2v and v2i handle a STACK_OF(CONF_VALUE):
837
838typedef struct
839{
840 char *section;
841 char *name;
842 char *value;
843} CONF_VALUE;
844
845Only the name and value members are currently used.
846
847STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
848
849This function is passed the internal structure in the ext parameter and
850returns a STACK of CONF_VALUE structures. The values of name, value,
851section and the structure itself will be freed up with Free after use.
852Several helper functions are available to add values to this STACK.
853
854void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
855 STACK_OF(CONF_VALUE) *values);
856
857This function takes a STACK_OF(CONF_VALUE) structures and should set the
858values of the external structure. This typically uses the name element to
859determine which structure element to set and the value element to determine
860what to set it to. Several helper functions are available for this
861purpose (see above).
862
863int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
864
865This function is passed the internal extension structure in the ext parameter
866and sends out a human readable version of the extension to out. The 'indent'
867parameter should be noted to determine the necessary amount of indentation
868needed on the output.
869
870void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
871
872This is just passed the string representation of the extension. It is intended
873to be used for more elaborate extensions where the standard single and multi
874valued options are insufficient. They can use the 'ctx' parameter to parse the
875configuration database themselves. See the context functions section for details
876of how to do this.
877
878Note: although this type takes the same parameters as the "r2s" function there
879is a subtle difference. Whereas an "r2i" function can access a configuration
880database an "s2i" function MUST NOT. This is so the internal code can safely
881assume that an "s2i" function will work without a configuration database.
882
883==============================================================================
884 PKCS#12 Library
885==============================================================================
886
887This section describes the internal PKCS#12 support. There are very few
888differences between the old external library and the new internal code at
889present. This may well change because the external library will not be updated
890much in future.
891
892This version now includes a couple of high level PKCS#12 functions which
893generally "do the right thing" and should make it much easier to handle PKCS#12
894structures.
895
896HIGH LEVEL FUNCTIONS.
897
898For most applications you only need concern yourself with the high level
899functions. They can parse and generate simple PKCS#12 files as produced by
900Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
901private key and certificate pair.
902
9031. Initialisation and cleanup.
904
905No special initialisation is needed for the internal PKCS#12 library: the
906standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
907add all algorithms (you should at least add SHA1 though) then you can manually
908initialise the PKCS#12 library with:
909
910PKCS12_PBE_add();
911
912The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
913called or it can be directly freed with:
914
915EVP_PBE_cleanup();
916
917after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
918be called.
919
9202. I/O functions.
921
922i2d_PKCS12_bio(bp, p12)
923
924This writes out a PKCS12 structure to a BIO.
925
926i2d_PKCS12_fp(fp, p12)
927
928This is the same but for a FILE pointer.
929
930d2i_PKCS12_bio(bp, p12)
931
932This reads in a PKCS12 structure from a BIO.
933
934d2i_PKCS12_fp(fp, p12)
935
936This is the same but for a FILE pointer.
937
9383. High level functions.
939
9403.1 Parsing with PKCS12_parse().
941
942int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
943 STACK **ca);
944
945This function takes a PKCS12 structure and a password (ASCII, null terminated)
946and returns the private key, the corresponding certificate and any CA
947certificates. If any of these is not required it can be passed as a NULL.
948The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
949structure. Typically to read in a PKCS#12 file you might do:
950
951p12 = d2i_PKCS12_fp(fp, NULL);
952PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
953PKCS12_free(p12);
954
9553.2 PKCS#12 creation with PKCS12_create().
956
957PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
958 STACK *ca, int nid_key, int nid_cert, int iter,
959 int mac_iter, int keytype);
960
961This function will create a PKCS12 structure from a given password, name,
962private key, certificate and optional STACK of CA certificates. The remaining
9635 parameters can be set to 0 and sensible defaults will be used.
964
965The parameters nid_key and nid_cert are the key and certificate encryption
966algorithms, iter is the encryption iteration count, mac_iter is the MAC
967iteration count and keytype is the type of private key. If you really want
968to know what these last 5 parameters do then read the low level section.
969
970Typically to create a PKCS#12 file the following could be used:
971
972p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
973i2d_PKCS12_fp(fp, p12);
974PKCS12_free(p12);
975
9763.3 Changing a PKCS#12 structure password.
977
978int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
979
980This changes the password of an already existing PKCS#12 structure. oldpass
981is the old password and newpass is the new one. An error occurs if the old
982password is incorrect.
983
984LOW LEVEL FUNCTIONS.
985
986In some cases the high level functions do not provide the necessary
987functionality. For example if you want to generate or parse more complex
988PKCS#12 files. The sample pkcs12 application uses the low level functions
989to display details about the internal structure of a PKCS#12 file.
990
991Introduction.
992
993This is a brief description of how a PKCS#12 file is represented internally:
994some knowledge of PKCS#12 is assumed.
995
996A PKCS#12 object contains several levels.
997
998At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
999CRL, a private key, encrypted or unencrypted, a set of safebags (so the
1000structure can be nested) or other secrets (not documented at present).
1001A safebag can optionally have attributes, currently these are: a unicode
1002friendlyName (a Unicode string) or a localKeyID (a string of bytes).
1003
1004At the next level is an authSafe which is a set of safebags collected into
1005a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
1006
1007At the top level is the PKCS12 structure itself which contains a set of
1008authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
1009contains a MAC which is a kind of password protected digest to preserve
1010integrity (so any unencrypted stuff below can't be tampered with).
1011
1012The reason for these levels is so various objects can be encrypted in various
1013ways. For example you might want to encrypt a set of private keys with
1014triple-DES and then include the related certificates either unencrypted or
1015with lower encryption. Yes it's the dreaded crypto laws at work again which
1016allow strong encryption on private keys and only weak encryption on other
1017stuff.
1018
1019To build one of these things you turn all certificates and keys into safebags
1020(with optional attributes). You collect the safebags into (one or more) STACKS
1021and convert these into authsafes (encrypted or unencrypted). The authsafes
1022are collected into a STACK and added to a PKCS12 structure. Finally a MAC
1023inserted.
1024
1025Pulling one apart is basically the reverse process. The MAC is verified against
1026the given password. The authsafes are extracted and each authsafe split into
1027a set of safebags (possibly involving decryption). Finally the safebags are
1028decomposed into the original keys and certificates and the attributes used to
1029match up private key and certificate pairs.
1030
1031Anyway here are the functions that do the dirty work.
1032
10331. Construction functions.
1034
10351.1 Safebag functions.
1036
1037M_PKCS12_x5092certbag(x509)
1038
1039This macro takes an X509 structure and returns a certificate bag. The
1040X509 structure can be freed up after calling this function.
1041
1042M_PKCS12_x509crl2certbag(crl)
1043
1044As above but for a CRL.
1045
1046PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
1047
1048Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
1049Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
1050structure contains a private key data in plain text form it should be free'd
1051up as soon as it has been encrypted for security reasons (freeing up the
1052structure zeros out the sensitive data). This can be done with
1053PKCS8_PRIV_KEY_INFO_free().
1054
1055PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
1056
1057This sets the key type when a key is imported into MSIE or Outlook 98. Two
1058values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
1059key that can also be used for signing but its size is limited in the export
1060versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1061signing only key but the keysize is unlimited (well 16K is supposed to work).
1062If you are using the domestic version of MSIE then you can ignore this because
1063KEY_EX is not limited and can be used for both.
1064
1065PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1066
1067Convert a PKCS8 private key structure into a keybag. This routine embeds the
1068p8 structure in the keybag so p8 should not be freed up or used after it is
1069called. The p8 structure will be freed up when the safebag is freed.
1070
1071PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1072
1073Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1074embedded and can be freed up after use.
1075
1076int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1077int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1078
1079Add a local key id or a friendlyname to a safebag.
1080
10811.2 Authsafe functions.
1082
1083PKCS7 *PKCS12_pack_p7data(STACK *sk)
1084Take a stack of safebags and convert them into an unencrypted authsafe. The
1085stack of safebags can be freed up after calling this function.
1086
1087PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1088
1089As above but encrypted.
1090
10911.3 PKCS12 functions.
1092
1093PKCS12 *PKCS12_init(int mode)
1094
1095Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1096
1097M_PKCS12_pack_authsafes(p12, safes)
1098
1099This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1100
1101int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1102
1103Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1104that SHA-1 should be used.
1105
11062. Extraction Functions.
1107
11082.1 Safebags.
1109
1110M_PKCS12_bag_type(bag)
1111
1112Return the type of "bag". Returns one of the following
1113
1114NID_keyBag
1115NID_pkcs8ShroudedKeyBag 7
1116NID_certBag 8
1117NID_crlBag 9
1118NID_secretBag 10
1119NID_safeContentsBag 11
1120
1121M_PKCS12_cert_bag_type(bag)
1122
1123Returns type of certificate bag, following are understood.
1124
1125NID_x509Certificate 14
1126NID_sdsiCertificate 15
1127
1128M_PKCS12_crl_bag_type(bag)
1129
1130Returns crl bag type, currently only NID_crlBag is recognised.
1131
1132M_PKCS12_certbag2x509(bag)
1133
1134This macro extracts an X509 certificate from a certificate bag.
1135
1136M_PKCS12_certbag2x509crl(bag)
1137
1138As above but for a CRL.
1139
1140EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1141
1142Extract a private key from a PKCS8 private key info structure.
1143
1144M_PKCS12_decrypt_skey(bag, pass, passlen)
1145
1146Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1147Works with both RSA and DSA keys
1148
1149char *PKCS12_get_friendlyname(bag)
1150
1151Returns the friendlyName of a bag if present or NULL if none. The returned
1152string is a null terminated ASCII string allocated with Malloc(). It should
1153thus be freed up with Free() after use.
1154
11552.2 AuthSafe functions.
1156
1157M_PKCS12_unpack_p7data(p7)
1158
1159Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1160
1161#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1162
1163As above but for an encrypted content info.
1164
11652.3 PKCS12 functions.
1166
1167M_PKCS12_unpack_authsafes(p12)
1168
1169Extract a STACK of authsafes from a PKCS12 structure.
1170
1171M_PKCS12_mac_present(p12)
1172
1173Check to see if a MAC is present.
1174
1175int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1176
1177Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1178
1179
1180Notes.
1181
11821. All the function return 0 or NULL on error.
11832. Encryption based functions take a common set of parameters. These are
1184described below.
1185
1186pass, passlen
1187ASCII password and length. The password on the MAC is called the "integrity
1188password" the encryption password is called the "privacy password" in the
1189PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1190passed for the length it is worked out by the function itself (currently
1191this is sometimes done whatever is passed as the length but that may change).
1192
1193salt, saltlen
1194A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1195default length is used.
1196
1197iter
1198Iteration count. This is a measure of how many times an internal function is
1199called to encrypt the data. The larger this value is the longer it takes, it
1200makes dictionary attacks on passwords harder. NOTE: Some implementations do
1201not support an iteration count on the MAC. If the password for the MAC and
1202encryption is the same then there is no point in having a high iteration
1203count for encryption if the MAC has no count. The MAC could be attacked
1204and the password used for the main decryption.
1205
1206pbe_nid
1207This is the NID of the password based encryption method used. The following are
1208supported.
1209NID_pbe_WithSHA1And128BitRC4
1210NID_pbe_WithSHA1And40BitRC4
1211NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1212NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1213NID_pbe_WithSHA1And128BitRC2_CBC
1214NID_pbe_WithSHA1And40BitRC2_CBC
1215
1216Which you use depends on the implementation you are exporting to. "Export
1217grade" (i.e. cryptographically challenged) products cannot support all
1218algorithms. Typically you may be able to use any encryption on shrouded key
1219bags but they must then be placed in an unencrypted authsafe. Other authsafes
1220may only support 40bit encryption. Of course if you are using SSLeay
1221throughout you can strongly encrypt everything and have high iteration counts
1222on everything.
1223
12243. For decryption routines only the password and length are needed.
1225
12264. Unlike the external version the nid's of objects are the values of the
1227constants: that is NID_certBag is the real nid, therefore there is no
1228PKCS12_obj_offset() function. Note the object constants are not the same as
1229those of the external version. If you use these constants then you will need
1230to recompile your code.
1231
12325. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1233macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1234reused or freed up safely.
1235
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt
deleted file mode 100644
index 61ccc5d7e0..0000000000
--- a/src/lib/libssl/doc/standards.txt
+++ /dev/null
@@ -1,121 +0,0 @@
1Standards related to OpenSSL
2============================
3
4[Please, this is currently a draft. I made a first try at finding
5 documents that describe parts of what OpenSSL implements. There are
6 big gaps, and I've most certainly done something wrong. Please
7 correct whatever is... Also, this note should be removed when this
8 file is reaching a somewhat correct state. -- Richard Levitte]
9
10
11All pointers in here will be either URL's or blobs of text borrowed
12from miscellaneous indexes, like rfc-index.txt (index of RFCs),
131id-index.txt (index of Internet drafts) and the like.
14
15To find the latest possible RFCs, it's recommended to either browse
16ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and
17use the search mechanism found there.
18To find the latest possible Internet drafts, it's recommended to
19browse ftp://ftp.isi.edu/internet-drafts/.
20To find the latest possible PKCS, it's recommended to browse
21http://www.rsasecurity.com/rsalabs/pkcs/.
22
23
24Implemented:
25------------
26
27These are documents that describe things that are implemented in OpenSSL.
28
291319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992.
30 (Format: TXT=25661 bytes) (Status: INFORMATIONAL)
31
321320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
33 TXT=32407 bytes) (Status: INFORMATIONAL)
34
351321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
36 TXT=35222 bytes) (Status: INFORMATIONAL)
37
382246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999.
39 (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD)
40
412268 A Description of the RC2(r) Encryption Algorithm. R. Rivest.
42 January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL)
43
442314 PKCS 10: Certification Request Syntax Version 1.5. B. Kaliski.
45 March 1998. (Format: TXT=15814 bytes) (Status: INFORMATIONAL)
46
472315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski.
48 March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL)
49
502437 PKCS #1: RSA Cryptography Specifications Version 2.0. B. Kaliski,
51 J. Staddon. October 1998. (Format: TXT=73529 bytes) (Obsoletes
52 RFC2313) (Status: INFORMATIONAL)
53
542459 Internet X.509 Public Key Infrastructure Certificate and CRL
55 Profile. R. Housley, W. Ford, W. Polk, D. Solo. January 1999.
56 (Format: TXT=278438 bytes) (Status: PROPOSED STANDARD)
57
58PKCS#8: Private-Key Information Syntax Standard
59
60PKCS#12: Personal Information Exchange Syntax Standard, version 1.0.
61
62
63Related:
64--------
65
66These are documents that are close to OpenSSL, for example the
67STARTTLS documents.
68
691421 Privacy Enhancement for Internet Electronic Mail: Part I: Message
70 Encryption and Authentication Procedures. J. Linn. February 1993.
71 (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED
72 STANDARD)
73
741422 Privacy Enhancement for Internet Electronic Mail: Part II:
75 Certificate-Based Key Management. S. Kent. February 1993. (Format:
76 TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD)
77
781423 Privacy Enhancement for Internet Electronic Mail: Part III:
79 Algorithms, Modes, and Identifiers. D. Balenson. February 1993.
80 (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED
81 STANDARD)
82
831424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key
84 Certification and Related Services. B. Kaliski. February 1993.
85 (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD)
86
872487 SMTP Service Extension for Secure SMTP over TLS. P. Hoffman.
88 January 1999. (Format: TXT=15120 bytes) (Status: PROPOSED STANDARD)
89
902585 Internet X.509 Public Key Infrastructure Operational Protocols:
91 FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813
92 bytes) (Status: PROPOSED STANDARD)
93
942595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999.
95 (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD)
96
972712 Addition of Kerberos Cipher Suites to Transport Layer Security
98 (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes)
99 (Status: PROPOSED STANDARD)
100
1012817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May
102 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED
103 STANDARD)
104
1052818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes)
106 (Status: INFORMATIONAL)
107
108 "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt>
109
110
111To be implemented:
112------------------
113
114These are documents that describe things that are planed to be
115implemented in the hopefully short future.
116
1172560 X.509 Internet Public Key Infrastructure Online Certificate
118 Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin,
119 C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED
120 STANDARD)
121
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c
deleted file mode 100644
index 5050a13ef2..0000000000
--- a/src/lib/libssl/s23_clnt.c
+++ /dev/null
@@ -1,475 +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
66static SSL_METHOD *ssl23_get_client_method(int ver);
67static int ssl23_client_hello(SSL *s);
68static int ssl23_get_server_hello(SSL *s);
69static 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
83SSL_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
99int 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 }
201end:
202 s->in_handshake--;
203 if (cb != NULL)
204 cb(s,SSL_CB_CONNECT_EXIT,ret);
205 return(ret);
206 }
207
208
209static 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
308static 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 if (!(s->client_version == SSL2_VERSION))
370 /* use special padding (SSL 3.0 draft/RFC 2246, App. E.2) */
371 s->s2->ssl2_rollback=1;
372
373 /* setup the 5 bytes we have read so we get them from
374 * the sslv2 buffer */
375 s->rstate=SSL_ST_READ_HEADER;
376 s->packet_length=n;
377 s->packet= &(s->s2->rbuf[0]);
378 memcpy(s->packet,buf,n);
379 s->s2->rbuf_left=n;
380 s->s2->rbuf_offs=0;
381
382 /* we have already written one */
383 s->s2->write_sequence=1;
384
385 s->method=SSLv2_client_method();
386 s->handshake_func=s->method->ssl_connect;
387#endif
388 }
389 else if ((p[0] == SSL3_RT_HANDSHAKE) &&
390 (p[1] == SSL3_VERSION_MAJOR) &&
391 ((p[2] == SSL3_VERSION_MINOR) ||
392 (p[2] == TLS1_VERSION_MINOR)) &&
393 (p[5] == SSL3_MT_SERVER_HELLO))
394 {
395 /* we have sslv3 or tls1 */
396
397 if (!ssl_init_wbio_buffer(s,1)) goto err;
398
399 /* we are in this state */
400 s->state=SSL3_ST_CR_SRVR_HELLO_A;
401
402 /* put the 5 bytes we have read into the input buffer
403 * for SSLv3 */
404 s->rstate=SSL_ST_READ_HEADER;
405 s->packet_length=n;
406 s->packet= &(s->s3->rbuf.buf[0]);
407 memcpy(s->packet,buf,n);
408 s->s3->rbuf.left=n;
409 s->s3->rbuf.offset=0;
410
411 if ((p[2] == SSL3_VERSION_MINOR) &&
412 !(s->options & SSL_OP_NO_SSLv3))
413 {
414 s->version=SSL3_VERSION;
415 s->method=SSLv3_client_method();
416 }
417 else if ((p[2] == TLS1_VERSION_MINOR) &&
418 !(s->options & SSL_OP_NO_TLSv1))
419 {
420 s->version=TLS1_VERSION;
421 s->method=TLSv1_client_method();
422 }
423 else
424 {
425 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
426 goto err;
427 }
428
429 s->handshake_func=s->method->ssl_connect;
430 }
431 else if ((p[0] == SSL3_RT_ALERT) &&
432 (p[1] == SSL3_VERSION_MAJOR) &&
433 ((p[2] == SSL3_VERSION_MINOR) ||
434 (p[2] == TLS1_VERSION_MINOR)) &&
435 (p[3] == 0) &&
436 (p[4] == 2))
437 {
438 void (*cb)()=NULL;
439 int j;
440
441 /* An alert */
442 if (s->info_callback != NULL)
443 cb=s->info_callback;
444 else if (s->ctx->info_callback != NULL)
445 cb=s->ctx->info_callback;
446
447 i=p[5];
448 if (cb != NULL)
449 {
450 j=(i<<8)|p[6];
451 cb(s,SSL_CB_READ_ALERT,j);
452 }
453
454 s->rwstate=SSL_NOTHING;
455 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_AD_REASON_OFFSET+p[6]);
456 goto err;
457 }
458 else
459 {
460 SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,SSL_R_UNKNOWN_PROTOCOL);
461 goto err;
462 }
463 s->init_num=0;
464
465 /* Since, if we are sending a ssl23 client hello, we are not
466 * reusing a session-id */
467 if (!ssl_get_new_session(s,0))
468 goto err;
469
470 s->first_packet=1;
471 return(SSL_connect(s));
472err:
473 return(-1);
474 }
475
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
63static int ssl23_num_ciphers(void );
64static SSL_CIPHER *ssl23_get_cipher(unsigned int u);
65static int ssl23_read(SSL *s, void *buf, int len);
66static int ssl23_write(SSL *s, const void *buf, int len);
67static long ssl23_default_timeout(void );
68static int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
69static SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
70const char *SSL23_version_str="SSLv2/3 compatibility" OPENSSL_VERSION_PTEXT;
71
72static 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
100static long ssl23_default_timeout(void)
101 {
102 return(300);
103 }
104
105SSL_METHOD *sslv23_base_method(void)
106 {
107 return(&SSLv23_data);
108 }
109
110static int ssl23_num_ciphers(void)
111 {
112 return(ssl3_num_ciphers()
113#ifndef NO_SSL2
114 + ssl2_num_ciphers()
115#endif
116 );
117 }
118
119static 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 */
135static 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
153static 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
168static 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
198static 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
66int 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 */
93int 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 050618235f..0000000000
--- a/src/lib/libssl/s23_srvr.c
+++ /dev/null
@@ -1,576 +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
66static SSL_METHOD *ssl23_get_server_method(int ver);
67int ssl23_get_client_hello(SSL *s);
68static 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
82SSL_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
98int 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 }
181end:
182 if (cb != NULL)
183 cb(s,SSL_CB_ACCEPT_EXIT,ret);
184 s->in_handshake--;
185 return(ret);
186 }
187
188
189int 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=OPENSSL_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 (= SSL3_VERSION_MAJOR) */
352 /* We must look at client_version inside the Client Hello message
353 * to get the correct minor version.
354 * However if we have only a pathologically small fragment of the
355 * Client Hello message, this would be difficult, we'd have
356 * to read at least one additional record to find out.
357 * This doesn't usually happen in real life, so we just complain
358 * for now.
359 */
360 if (p[3] == 0 && p[4] < 6)
361 {
362 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL);
363 goto err;
364 }
365 v[1]=p[10]; /* minor version according to client_version */
366 if (v[1] >= TLS1_VERSION_MINOR)
367 {
368 if (!(s->options & SSL_OP_NO_TLSv1))
369 {
370 s->version=TLS1_VERSION;
371 type=3;
372 }
373 else if (!(s->options & SSL_OP_NO_SSLv3))
374 {
375 s->version=SSL3_VERSION;
376 type=3;
377 }
378 }
379 else if (!(s->options & SSL_OP_NO_SSLv3))
380 {
381 s->version=SSL3_VERSION;
382 type=3;
383 }
384 }
385 else if ((strncmp("GET ", (char *)p,4) == 0) ||
386 (strncmp("POST ",(char *)p,5) == 0) ||
387 (strncmp("HEAD ",(char *)p,5) == 0) ||
388 (strncmp("PUT ", (char *)p,4) == 0))
389 {
390 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
391 goto err;
392 }
393 else if (strncmp("CONNECT",(char *)p,7) == 0)
394 {
395 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
396 goto err;
397 }
398 }
399
400 if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
401 {
402 /* we have SSLv3/TLSv1 in an SSLv2 header
403 * (other cases skip this state) */
404
405 type=2;
406 p=s->packet;
407 v[0] = p[3]; /* == SSL3_VERSION_MAJOR */
408 v[1] = p[4];
409
410 n=((p[0]&0x7f)<<8)|p[1];
411 if (n > (1024*4))
412 {
413 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
414 goto err;
415 }
416
417 j=ssl23_read_bytes(s,n+2);
418 if (j <= 0) return(j);
419
420 ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
421
422 p=s->packet;
423 p+=5;
424 n2s(p,csl);
425 n2s(p,sil);
426 n2s(p,cl);
427 d=(unsigned char *)s->init_buf->data;
428 if ((csl+sil+cl+11) != s->packet_length)
429 {
430 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
431 goto err;
432 }
433
434 *(d++) = SSL3_VERSION_MAJOR; /* == v[0] */
435 *(d++) = v[1];
436
437 /* lets populate the random area */
438 /* get the challenge_length */
439 i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
440 memset(d,0,SSL3_RANDOM_SIZE);
441 memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
442 d+=SSL3_RANDOM_SIZE;
443
444 /* no session-id reuse */
445 *(d++)=0;
446
447 /* ciphers */
448 j=0;
449 dd=d;
450 d+=2;
451 for (i=0; i<csl; i+=3)
452 {
453 if (p[i] != 0) continue;
454 *(d++)=p[i+1];
455 *(d++)=p[i+2];
456 j+=2;
457 }
458 s2n(j,dd);
459
460 /* COMPRESSION */
461 *(d++)=1;
462 *(d++)=0;
463
464 i=(d-(unsigned char *)s->init_buf->data);
465
466 /* get the data reused from the init_buf */
467 s->s3->tmp.reuse_message=1;
468 s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
469 s->s3->tmp.message_size=i;
470 }
471
472 /* imaginary new state (for program structure): */
473 /* s->state = SSL23_SR_CLNT_HELLO_C */
474
475 if (type == 1)
476 {
477#ifdef NO_SSL2
478 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
479 goto err;
480#else
481 /* we are talking sslv2 */
482 /* we need to clean up the SSLv3/TLSv1 setup and put in the
483 * sslv2 stuff. */
484
485 if (s->s2 == NULL)
486 {
487 if (!ssl2_new(s))
488 goto err;
489 }
490 else
491 ssl2_clear(s);
492
493 if (s->s3 != NULL) ssl3_free(s);
494
495 if (!BUF_MEM_grow(s->init_buf,
496 SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
497 {
498 goto err;
499 }
500
501 s->state=SSL2_ST_GET_CLIENT_HELLO_A;
502 if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||
503 use_sslv2_strong ||
504 (s->options & SSL_OP_NO_TLSv1 && s->options & SSL_OP_NO_SSLv3))
505 s->s2->ssl2_rollback=0;
506 else
507 /* reject SSL 2.0 session if client supports SSL 3.0 or TLS 1.0
508 * (SSL 3.0 draft/RFC 2246, App. E.2) */
509 s->s2->ssl2_rollback=1;
510
511 /* setup the n bytes we have read so we get them from
512 * the sslv2 buffer */
513 s->rstate=SSL_ST_READ_HEADER;
514 s->packet_length=n;
515 s->packet= &(s->s2->rbuf[0]);
516 memcpy(s->packet,buf,n);
517 s->s2->rbuf_left=n;
518 s->s2->rbuf_offs=0;
519
520 s->method=SSLv2_server_method();
521 s->handshake_func=s->method->ssl_accept;
522#endif
523 }
524
525 if ((type == 2) || (type == 3))
526 {
527 /* we have SSLv3/TLSv1 (type 2: SSL2 style, type 3: SSL3/TLS style) */
528
529 if (!ssl_init_wbio_buffer(s,1)) goto err;
530
531 /* we are in this state */
532 s->state=SSL3_ST_SR_CLNT_HELLO_A;
533
534 if (type == 3)
535 {
536 /* put the 'n' bytes we have read into the input buffer
537 * for SSLv3 */
538 s->rstate=SSL_ST_READ_HEADER;
539 s->packet_length=n;
540 s->packet= &(s->s3->rbuf.buf[0]);
541 memcpy(s->packet,buf,n);
542 s->s3->rbuf.left=n;
543 s->s3->rbuf.offset=0;
544 }
545 else
546 {
547 s->packet_length=0;
548 s->s3->rbuf.left=0;
549 s->s3->rbuf.offset=0;
550 }
551
552 if (s->version == TLS1_VERSION)
553 s->method = TLSv1_server_method();
554 else
555 s->method = SSLv3_server_method();
556#if 0 /* ssl3_get_client_hello does this */
557 s->client_version=(v[0]<<8)|v[1];
558#endif
559 s->handshake_func=s->method->ssl_accept;
560 }
561
562 if ((type < 1) || (type > 3))
563 {
564 /* bad, very bad */
565 SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
566 goto err;
567 }
568 s->init_num=0;
569
570 if (buf != buf_space) OPENSSL_free(buf);
571 s->first_packet=1;
572 return(SSL_accept(s));
573err:
574 if (buf != buf_space) OPENSSL_free(buf);
575 return(-1);
576 }
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c
deleted file mode 100644
index d92c164b0f..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' */
122int 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
141int 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
180int 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);
226f_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 */
239int 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
257unsigned 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 */
337long 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;
450f_err:
451 ssl3_send_alert(s,SSL3_AL_FATAL,al);
452err:
453 *ok=0;
454 return(-1);
455 }
456
457int 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
502err:
503 if(!pkey) EVP_PKEY_free(pk);
504 return(ret);
505 }
506
507int 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
559int 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=OPENSSL_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=OPENSSL_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);
585err:
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 62040f9f1d..0000000000
--- a/src/lib/libssl/s3_clnt.c
+++ /dev/null
@@ -1,1740 +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
68static SSL_METHOD *ssl3_get_client_method(int ver);
69static int ssl3_client_hello(SSL *s);
70static int ssl3_get_server_hello(SSL *s);
71static int ssl3_get_certificate_request(SSL *s);
72static int ca_dn_cmp(const X509_NAME * const *a,const X509_NAME * const *b);
73static int ssl3_get_server_done(SSL *s);
74static int ssl3_send_client_verify(SSL *s);
75static int ssl3_send_client_certificate(SSL *s);
76static int ssl3_send_client_key_exchange(SSL *s);
77static int ssl3_get_key_exchange(SSL *s);
78static int ssl3_get_server_certificate(SSL *s);
79static int ssl3_check_cert_and_algorithm(SSL *s);
80static 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
88SSL_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
104int 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 {
146 SSLerr(SSL_F_SSL3_CONNECT, SSL_R_INTERNAL_ERROR);
147 ret = -1;
148 goto end;
149 }
150
151 /* s->version=SSL3_VERSION; */
152 s->type=SSL_ST_CONNECT;
153
154 if (s->init_buf == NULL)
155 {
156 if ((buf=BUF_MEM_new()) == NULL)
157 {
158 ret= -1;
159 goto end;
160 }
161 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
162 {
163 ret= -1;
164 goto end;
165 }
166 s->init_buf=buf;
167 }
168
169 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
170
171 /* setup buffing BIO */
172 if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
173
174 /* don't push the buffering BIO quite yet */
175
176 ssl3_init_finished_mac(s);
177
178 s->state=SSL3_ST_CW_CLNT_HELLO_A;
179 s->ctx->stats.sess_connect++;
180 s->init_num=0;
181 break;
182
183 case SSL3_ST_CW_CLNT_HELLO_A:
184 case SSL3_ST_CW_CLNT_HELLO_B:
185
186 s->shutdown=0;
187 ret=ssl3_client_hello(s);
188 if (ret <= 0) goto end;
189 s->state=SSL3_ST_CR_SRVR_HELLO_A;
190 s->init_num=0;
191
192 /* turn on buffering for the next lot of output */
193 if (s->bbio != s->wbio)
194 s->wbio=BIO_push(s->bbio,s->wbio);
195
196 break;
197
198 case SSL3_ST_CR_SRVR_HELLO_A:
199 case SSL3_ST_CR_SRVR_HELLO_B:
200 ret=ssl3_get_server_hello(s);
201 if (ret <= 0) goto end;
202 if (s->hit)
203 s->state=SSL3_ST_CR_FINISHED_A;
204 else
205 s->state=SSL3_ST_CR_CERT_A;
206 s->init_num=0;
207 break;
208
209 case SSL3_ST_CR_CERT_A:
210 case SSL3_ST_CR_CERT_B:
211 /* Check if it is anon DH */
212 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
213 {
214 ret=ssl3_get_server_certificate(s);
215 if (ret <= 0) goto end;
216 }
217 else
218 skip=1;
219 s->state=SSL3_ST_CR_KEY_EXCH_A;
220 s->init_num=0;
221 break;
222
223 case SSL3_ST_CR_KEY_EXCH_A:
224 case SSL3_ST_CR_KEY_EXCH_B:
225 ret=ssl3_get_key_exchange(s);
226 if (ret <= 0) goto end;
227 s->state=SSL3_ST_CR_CERT_REQ_A;
228 s->init_num=0;
229
230 /* at this point we check that we have the
231 * required stuff from the server */
232 if (!ssl3_check_cert_and_algorithm(s))
233 {
234 ret= -1;
235 goto end;
236 }
237 break;
238
239 case SSL3_ST_CR_CERT_REQ_A:
240 case SSL3_ST_CR_CERT_REQ_B:
241 ret=ssl3_get_certificate_request(s);
242 if (ret <= 0) goto end;
243 s->state=SSL3_ST_CR_SRVR_DONE_A;
244 s->init_num=0;
245 break;
246
247 case SSL3_ST_CR_SRVR_DONE_A:
248 case SSL3_ST_CR_SRVR_DONE_B:
249 ret=ssl3_get_server_done(s);
250 if (ret <= 0) goto end;
251 if (s->s3->tmp.cert_req)
252 s->state=SSL3_ST_CW_CERT_A;
253 else
254 s->state=SSL3_ST_CW_KEY_EXCH_A;
255 s->init_num=0;
256
257 break;
258
259 case SSL3_ST_CW_CERT_A:
260 case SSL3_ST_CW_CERT_B:
261 case SSL3_ST_CW_CERT_C:
262 case SSL3_ST_CW_CERT_D:
263 ret=ssl3_send_client_certificate(s);
264 if (ret <= 0) goto end;
265 s->state=SSL3_ST_CW_KEY_EXCH_A;
266 s->init_num=0;
267 break;
268
269 case SSL3_ST_CW_KEY_EXCH_A:
270 case SSL3_ST_CW_KEY_EXCH_B:
271 ret=ssl3_send_client_key_exchange(s);
272 if (ret <= 0) goto end;
273 l=s->s3->tmp.new_cipher->algorithms;
274 /* EAY EAY EAY need to check for DH fix cert
275 * sent back */
276 /* For TLS, cert_req is set to 2, so a cert chain
277 * of nothing is sent, but no verify packet is sent */
278 if (s->s3->tmp.cert_req == 1)
279 {
280 s->state=SSL3_ST_CW_CERT_VRFY_A;
281 }
282 else
283 {
284 s->state=SSL3_ST_CW_CHANGE_A;
285 s->s3->change_cipher_spec=0;
286 }
287
288 s->init_num=0;
289 break;
290
291 case SSL3_ST_CW_CERT_VRFY_A:
292 case SSL3_ST_CW_CERT_VRFY_B:
293 ret=ssl3_send_client_verify(s);
294 if (ret <= 0) goto end;
295 s->state=SSL3_ST_CW_CHANGE_A;
296 s->init_num=0;
297 s->s3->change_cipher_spec=0;
298 break;
299
300 case SSL3_ST_CW_CHANGE_A:
301 case SSL3_ST_CW_CHANGE_B:
302 ret=ssl3_send_change_cipher_spec(s,
303 SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
304 if (ret <= 0) goto end;
305 s->state=SSL3_ST_CW_FINISHED_A;
306 s->init_num=0;
307
308 s->session->cipher=s->s3->tmp.new_cipher;
309 if (s->s3->tmp.new_compression == NULL)
310 s->session->compress_meth=0;
311 else
312 s->session->compress_meth=
313 s->s3->tmp.new_compression->id;
314 if (!s->method->ssl3_enc->setup_key_block(s))
315 {
316 ret= -1;
317 goto end;
318 }
319
320 if (!s->method->ssl3_enc->change_cipher_state(s,
321 SSL3_CHANGE_CIPHER_CLIENT_WRITE))
322 {
323 ret= -1;
324 goto end;
325 }
326
327 break;
328
329 case SSL3_ST_CW_FINISHED_A:
330 case SSL3_ST_CW_FINISHED_B:
331 ret=ssl3_send_finished(s,
332 SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
333 s->method->ssl3_enc->client_finished_label,
334 s->method->ssl3_enc->client_finished_label_len);
335 if (ret <= 0) goto end;
336 s->state=SSL3_ST_CW_FLUSH;
337
338 /* clear flags */
339 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
340 if (s->hit)
341 {
342 s->s3->tmp.next_state=SSL_ST_OK;
343 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
344 {
345 s->state=SSL_ST_OK;
346 s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
347 s->s3->delay_buf_pop_ret=0;
348 }
349 }
350 else
351 {
352 s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
353 }
354 s->init_num=0;
355 break;
356
357 case SSL3_ST_CR_FINISHED_A:
358 case SSL3_ST_CR_FINISHED_B:
359
360 ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
361 SSL3_ST_CR_FINISHED_B);
362 if (ret <= 0) goto end;
363
364 if (s->hit)
365 s->state=SSL3_ST_CW_CHANGE_A;
366 else
367 s->state=SSL_ST_OK;
368 s->init_num=0;
369 break;
370
371 case SSL3_ST_CW_FLUSH:
372 /* number of bytes to be flushed */
373 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
374 if (num1 > 0)
375 {
376 s->rwstate=SSL_WRITING;
377 num1=BIO_flush(s->wbio);
378 if (num1 <= 0) { ret= -1; goto end; }
379 s->rwstate=SSL_NOTHING;
380 }
381
382 s->state=s->s3->tmp.next_state;
383 break;
384
385 case SSL_ST_OK:
386 /* clean a few things up */
387 ssl3_cleanup_key_block(s);
388
389 if (s->init_buf != NULL)
390 {
391 BUF_MEM_free(s->init_buf);
392 s->init_buf=NULL;
393 }
394
395 /* If we are not 'joining' the last two packets,
396 * remove the buffering now */
397 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
398 ssl_free_wbio_buffer(s);
399 /* else do it later in ssl3_write */
400
401 s->init_num=0;
402 s->new_session=0;
403
404 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
405 if (s->hit) s->ctx->stats.sess_hit++;
406
407 ret=1;
408 /* s->server=0; */
409 s->handshake_func=ssl3_connect;
410 s->ctx->stats.sess_connect_good++;
411
412 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
413
414 goto end;
415 /* break; */
416
417 default:
418 SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);
419 ret= -1;
420 goto end;
421 /* break; */
422 }
423
424 /* did we do anything */
425 if (!s->s3->tmp.reuse_message && !skip)
426 {
427 if (s->debug)
428 {
429 if ((ret=BIO_flush(s->wbio)) <= 0)
430 goto end;
431 }
432
433 if ((cb != NULL) && (s->state != state))
434 {
435 new_state=s->state;
436 s->state=state;
437 cb(s,SSL_CB_CONNECT_LOOP,1);
438 s->state=new_state;
439 }
440 }
441 skip=0;
442 }
443end:
444 if (cb != NULL)
445 cb(s,SSL_CB_CONNECT_EXIT,ret);
446 s->in_handshake--;
447 return(ret);
448 }
449
450
451static int ssl3_client_hello(SSL *s)
452 {
453 unsigned char *buf;
454 unsigned char *p,*d;
455 int i,j;
456 unsigned long Time,l;
457 SSL_COMP *comp;
458
459 buf=(unsigned char *)s->init_buf->data;
460 if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
461 {
462 if ((s->session == NULL) ||
463 (s->session->ssl_version != s->version) ||
464 (s->session->not_resumable))
465 {
466 if (!ssl_get_new_session(s,0))
467 goto err;
468 }
469 /* else use the pre-loaded session */
470
471 p=s->s3->client_random;
472 Time=time(NULL); /* Time */
473 l2n(Time,p);
474 RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
475
476 /* Do the message type and length last */
477 d=p= &(buf[4]);
478
479 *(p++)=s->version>>8;
480 *(p++)=s->version&0xff;
481 s->client_version=s->version;
482
483 /* Random stuff */
484 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
485 p+=SSL3_RANDOM_SIZE;
486
487 /* Session ID */
488 if (s->new_session)
489 i=0;
490 else
491 i=s->session->session_id_length;
492 *(p++)=i;
493 if (i != 0)
494 {
495 memcpy(p,s->session->session_id,i);
496 p+=i;
497 }
498
499 /* Ciphers supported */
500 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]));
501 if (i == 0)
502 {
503 SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
504 goto err;
505 }
506 s2n(i,p);
507 p+=i;
508
509 /* COMPRESSION */
510 if (s->ctx->comp_methods == NULL)
511 j=0;
512 else
513 j=sk_SSL_COMP_num(s->ctx->comp_methods);
514 *(p++)=1+j;
515 for (i=0; i<j; i++)
516 {
517 comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
518 *(p++)=comp->id;
519 }
520 *(p++)=0; /* Add the NULL method */
521
522 l=(p-d);
523 d=buf;
524 *(d++)=SSL3_MT_CLIENT_HELLO;
525 l2n3(l,d);
526
527 s->state=SSL3_ST_CW_CLNT_HELLO_B;
528 /* number of bytes to write */
529 s->init_num=p-buf;
530 s->init_off=0;
531 }
532
533 /* SSL3_ST_CW_CLNT_HELLO_B */
534 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
535err:
536 return(-1);
537 }
538
539static int ssl3_get_server_hello(SSL *s)
540 {
541 STACK_OF(SSL_CIPHER) *sk;
542 SSL_CIPHER *c;
543 unsigned char *p,*d;
544 int i,al,ok;
545 unsigned int j;
546 long n;
547 SSL_COMP *comp;
548
549 n=ssl3_get_message(s,
550 SSL3_ST_CR_SRVR_HELLO_A,
551 SSL3_ST_CR_SRVR_HELLO_B,
552 SSL3_MT_SERVER_HELLO,
553 300, /* ?? */
554 &ok);
555
556 if (!ok) return((int)n);
557 d=p=(unsigned char *)s->init_buf->data;
558
559 if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))
560 {
561 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);
562 s->version=(s->version&0xff00)|p[1];
563 al=SSL_AD_PROTOCOL_VERSION;
564 goto f_err;
565 }
566 p+=2;
567
568 /* load the server hello data */
569 /* load the server random */
570 memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);
571 p+=SSL3_RANDOM_SIZE;
572
573 /* get the session-id */
574 j= *(p++);
575
576 if ((j != 0) && (j != SSL3_SESSION_ID_SIZE))
577 {
578 /* SSLref returns 16 :-( */
579 if (j < SSL2_SSL_SESSION_ID_LENGTH)
580 {
581 al=SSL_AD_ILLEGAL_PARAMETER;
582 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
583 goto f_err;
584 }
585 }
586 if (j != 0 && j == s->session->session_id_length
587 && memcmp(p,s->session->session_id,j) == 0)
588 {
589 if(s->sid_ctx_length != s->session->sid_ctx_length
590 || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length))
591 {
592 al=SSL_AD_ILLEGAL_PARAMETER;
593 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
594 goto f_err;
595 }
596 s->hit=1;
597 }
598 else /* a miss or crap from the other end */
599 {
600 /* If we were trying for session-id reuse, make a new
601 * SSL_SESSION so we don't stuff up other people */
602 s->hit=0;
603 if (s->session->session_id_length > 0)
604 {
605 if (!ssl_get_new_session(s,0))
606 {
607 al=SSL_AD_INTERNAL_ERROR;
608 goto f_err;
609 }
610 }
611 s->session->session_id_length=j;
612 memcpy(s->session->session_id,p,j); /* j could be 0 */
613 }
614 p+=j;
615 c=ssl_get_cipher_by_char(s,p);
616 if (c == NULL)
617 {
618 /* unknown cipher */
619 al=SSL_AD_ILLEGAL_PARAMETER;
620 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);
621 goto f_err;
622 }
623 p+=ssl_put_cipher_by_char(s,NULL,NULL);
624
625 sk=ssl_get_ciphers_by_id(s);
626 i=sk_SSL_CIPHER_find(sk,c);
627 if (i < 0)
628 {
629 /* we did not say we would use this cipher */
630 al=SSL_AD_ILLEGAL_PARAMETER;
631 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);
632 goto f_err;
633 }
634
635 if (s->hit && (s->session->cipher != c))
636 {
637 if (!(s->options &
638 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))
639 {
640 al=SSL_AD_ILLEGAL_PARAMETER;
641 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
642 goto f_err;
643 }
644 }
645 s->s3->tmp.new_cipher=c;
646
647 /* lets get the compression algorithm */
648 /* COMPRESSION */
649 j= *(p++);
650 if (j == 0)
651 comp=NULL;
652 else
653 comp=ssl3_comp_find(s->ctx->comp_methods,j);
654
655 if ((j != 0) && (comp == NULL))
656 {
657 al=SSL_AD_ILLEGAL_PARAMETER;
658 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
659 goto f_err;
660 }
661 else
662 {
663 s->s3->tmp.new_compression=comp;
664 }
665
666 if (p != (d+n))
667 {
668 /* wrong packet length */
669 al=SSL_AD_DECODE_ERROR;
670 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
671 goto err;
672 }
673
674 return(1);
675f_err:
676 ssl3_send_alert(s,SSL3_AL_FATAL,al);
677err:
678 return(-1);
679 }
680
681static int ssl3_get_server_certificate(SSL *s)
682 {
683 int al,i,ok,ret= -1;
684 unsigned long n,nc,llen,l;
685 X509 *x=NULL;
686 unsigned char *p,*d,*q;
687 STACK_OF(X509) *sk=NULL;
688 SESS_CERT *sc;
689 EVP_PKEY *pkey=NULL;
690
691 n=ssl3_get_message(s,
692 SSL3_ST_CR_CERT_A,
693 SSL3_ST_CR_CERT_B,
694 -1,
695#if defined(MSDOS) && !defined(WIN32)
696 1024*30, /* 30k max cert list :-) */
697#else
698 1024*100, /* 100k max cert list :-) */
699#endif
700 &ok);
701
702 if (!ok) return((int)n);
703
704 if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE)
705 {
706 s->s3->tmp.reuse_message=1;
707 return(1);
708 }
709
710 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
711 {
712 al=SSL_AD_UNEXPECTED_MESSAGE;
713 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);
714 goto f_err;
715 }
716 d=p=(unsigned char *)s->init_buf->data;
717
718 if ((sk=sk_X509_new_null()) == NULL)
719 {
720 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
721 goto err;
722 }
723
724 n2l3(p,llen);
725 if (llen+3 != n)
726 {
727 al=SSL_AD_DECODE_ERROR;
728 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
729 goto f_err;
730 }
731 for (nc=0; nc<llen; )
732 {
733 n2l3(p,l);
734 if ((l+nc+3) > llen)
735 {
736 al=SSL_AD_DECODE_ERROR;
737 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
738 goto f_err;
739 }
740
741 q=p;
742 x=d2i_X509(NULL,&q,l);
743 if (x == NULL)
744 {
745 al=SSL_AD_BAD_CERTIFICATE;
746 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);
747 goto f_err;
748 }
749 if (q != (p+l))
750 {
751 al=SSL_AD_DECODE_ERROR;
752 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
753 goto f_err;
754 }
755 if (!sk_X509_push(sk,x))
756 {
757 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
758 goto err;
759 }
760 x=NULL;
761 nc+=l+3;
762 p=q;
763 }
764
765 i=ssl_verify_cert_chain(s,sk);
766 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
767 {
768 al=ssl_verify_alarm_type(s->verify_result);
769 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
770 goto f_err;
771 }
772 ERR_clear_error(); /* but we keep s->verify_result */
773
774 sc=ssl_sess_cert_new();
775 if (sc == NULL) goto err;
776
777 if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert);
778 s->session->sess_cert=sc;
779
780 sc->cert_chain=sk;
781 /* Inconsistency alert: cert_chain does include the peer's
782 * certificate, which we don't include in s3_srvr.c */
783 x=sk_X509_value(sk,0);
784 sk=NULL;
785
786 pkey=X509_get_pubkey(x);
787
788 if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))
789 {
790 x=NULL;
791 al=SSL3_AL_FATAL;
792 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
793 goto f_err;
794 }
795
796 i=ssl_cert_type(x,pkey);
797 if (i < 0)
798 {
799 x=NULL;
800 al=SSL3_AL_FATAL;
801 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
802 goto f_err;
803 }
804
805 sc->peer_cert_type=i;
806 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
807 if (sc->peer_pkeys[i].x509 != NULL) /* Why would this ever happen?
808 * We just created sc a couple of
809 * lines ago. */
810 X509_free(sc->peer_pkeys[i].x509);
811 sc->peer_pkeys[i].x509=x;
812 sc->peer_key= &(sc->peer_pkeys[i]);
813
814 if (s->session->peer != NULL)
815 X509_free(s->session->peer);
816 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
817 s->session->peer=x;
818
819 x=NULL;
820 ret=1;
821
822 if (0)
823 {
824f_err:
825 ssl3_send_alert(s,SSL3_AL_FATAL,al);
826 }
827err:
828 EVP_PKEY_free(pkey);
829 X509_free(x);
830 sk_X509_pop_free(sk,X509_free);
831 return(ret);
832 }
833
834static int ssl3_get_key_exchange(SSL *s)
835 {
836#ifndef NO_RSA
837 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
838#endif
839 EVP_MD_CTX md_ctx;
840 unsigned char *param,*p;
841 int al,i,j,param_len,ok;
842 long n,alg;
843 EVP_PKEY *pkey=NULL;
844#ifndef NO_RSA
845 RSA *rsa=NULL;
846#endif
847#ifndef NO_DH
848 DH *dh=NULL;
849#endif
850
851 n=ssl3_get_message(s,
852 SSL3_ST_CR_KEY_EXCH_A,
853 SSL3_ST_CR_KEY_EXCH_B,
854 -1,
855 1024*8, /* ?? */
856 &ok);
857
858 if (!ok) return((int)n);
859
860 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
861 {
862 s->s3->tmp.reuse_message=1;
863 return(1);
864 }
865
866 param=p=(unsigned char *)s->init_buf->data;
867
868 if (s->session->sess_cert != NULL)
869 {
870#ifndef NO_RSA
871 if (s->session->sess_cert->peer_rsa_tmp != NULL)
872 {
873 RSA_free(s->session->sess_cert->peer_rsa_tmp);
874 s->session->sess_cert->peer_rsa_tmp=NULL;
875 }
876#endif
877#ifndef NO_DH
878 if (s->session->sess_cert->peer_dh_tmp)
879 {
880 DH_free(s->session->sess_cert->peer_dh_tmp);
881 s->session->sess_cert->peer_dh_tmp=NULL;
882 }
883#endif
884 }
885 else
886 {
887 s->session->sess_cert=ssl_sess_cert_new();
888 }
889
890 param_len=0;
891 alg=s->s3->tmp.new_cipher->algorithms;
892
893#ifndef NO_RSA
894 if (alg & SSL_kRSA)
895 {
896 if ((rsa=RSA_new()) == NULL)
897 {
898 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
899 goto err;
900 }
901 n2s(p,i);
902 param_len=i+2;
903 if (param_len > n)
904 {
905 al=SSL_AD_DECODE_ERROR;
906 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
907 goto f_err;
908 }
909 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
910 {
911 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
912 goto err;
913 }
914 p+=i;
915
916 n2s(p,i);
917 param_len+=i+2;
918 if (param_len > n)
919 {
920 al=SSL_AD_DECODE_ERROR;
921 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
922 goto f_err;
923 }
924 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
925 {
926 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
927 goto err;
928 }
929 p+=i;
930 n-=param_len;
931
932 /* this should be because we are using an export cipher */
933 if (alg & SSL_aRSA)
934 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
935 else
936 {
937 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
938 goto err;
939 }
940 s->session->sess_cert->peer_rsa_tmp=rsa;
941 rsa=NULL;
942 }
943#else /* NO_RSA */
944 if (0)
945 ;
946#endif
947#ifndef NO_DH
948 else if (alg & SSL_kEDH)
949 {
950 if ((dh=DH_new()) == NULL)
951 {
952 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
953 goto err;
954 }
955 n2s(p,i);
956 param_len=i+2;
957 if (param_len > n)
958 {
959 al=SSL_AD_DECODE_ERROR;
960 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
961 goto f_err;
962 }
963 if (!(dh->p=BN_bin2bn(p,i,NULL)))
964 {
965 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
966 goto err;
967 }
968 p+=i;
969
970 n2s(p,i);
971 param_len+=i+2;
972 if (param_len > n)
973 {
974 al=SSL_AD_DECODE_ERROR;
975 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
976 goto f_err;
977 }
978 if (!(dh->g=BN_bin2bn(p,i,NULL)))
979 {
980 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
981 goto err;
982 }
983 p+=i;
984
985 n2s(p,i);
986 param_len+=i+2;
987 if (param_len > n)
988 {
989 al=SSL_AD_DECODE_ERROR;
990 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
991 goto f_err;
992 }
993 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
994 {
995 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
996 goto err;
997 }
998 p+=i;
999 n-=param_len;
1000
1001#ifndef NO_RSA
1002 if (alg & SSL_aRSA)
1003 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1004#else
1005 if (0)
1006 ;
1007#endif
1008#ifndef NO_DSA
1009 else if (alg & SSL_aDSS)
1010 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);
1011#endif
1012 /* else anonymous DH, so no certificate or pkey. */
1013
1014 s->session->sess_cert->peer_dh_tmp=dh;
1015 dh=NULL;
1016 }
1017 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
1018 {
1019 al=SSL_AD_ILLEGAL_PARAMETER;
1020 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1021 goto f_err;
1022 }
1023#endif /* !NO_DH */
1024 if (alg & SSL_aFZA)
1025 {
1026 al=SSL_AD_HANDSHAKE_FAILURE;
1027 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1028 goto f_err;
1029 }
1030
1031
1032 /* p points to the next byte, there are 'n' bytes left */
1033
1034
1035 /* if it was signed, check the signature */
1036 if (pkey != NULL)
1037 {
1038 n2s(p,i);
1039 n-=2;
1040 j=EVP_PKEY_size(pkey);
1041
1042 if ((i != n) || (n > j) || (n <= 0))
1043 {
1044 /* wrong packet length */
1045 al=SSL_AD_DECODE_ERROR;
1046 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1047 goto f_err;
1048 }
1049
1050#ifndef NO_RSA
1051 if (pkey->type == EVP_PKEY_RSA)
1052 {
1053 int num;
1054
1055 j=0;
1056 q=md_buf;
1057 for (num=2; num > 0; num--)
1058 {
1059 EVP_DigestInit(&md_ctx,(num == 2)
1060 ?s->ctx->md5:s->ctx->sha1);
1061 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1062 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1063 EVP_DigestUpdate(&md_ctx,param,param_len);
1064 EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);
1065 q+=i;
1066 j+=i;
1067 }
1068 i=RSA_verify(NID_md5_sha1, md_buf, j, p, n,
1069 pkey->pkey.rsa);
1070 if (i < 0)
1071 {
1072 al=SSL_AD_DECRYPT_ERROR;
1073 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1074 goto f_err;
1075 }
1076 if (i == 0)
1077 {
1078 /* bad signature */
1079 al=SSL_AD_DECRYPT_ERROR;
1080 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1081 goto f_err;
1082 }
1083 }
1084 else
1085#endif
1086#ifndef NO_DSA
1087 if (pkey->type == EVP_PKEY_DSA)
1088 {
1089 /* lets do DSS */
1090 EVP_VerifyInit(&md_ctx,EVP_dss1());
1091 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1092 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1093 EVP_VerifyUpdate(&md_ctx,param,param_len);
1094 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1095 {
1096 /* bad signature */
1097 al=SSL_AD_DECRYPT_ERROR;
1098 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1099 goto f_err;
1100 }
1101 }
1102 else
1103#endif
1104 {
1105 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1106 goto err;
1107 }
1108 }
1109 else
1110 {
1111 /* still data left over */
1112 if (!(alg & SSL_aNULL))
1113 {
1114 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1115 goto err;
1116 }
1117 if (n != 0)
1118 {
1119 al=SSL_AD_DECODE_ERROR;
1120 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1121 goto f_err;
1122 }
1123 }
1124 EVP_PKEY_free(pkey);
1125 return(1);
1126f_err:
1127 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1128err:
1129 EVP_PKEY_free(pkey);
1130#ifndef NO_RSA
1131 if (rsa != NULL)
1132 RSA_free(rsa);
1133#endif
1134#ifndef NO_DH
1135 if (dh != NULL)
1136 DH_free(dh);
1137#endif
1138 return(-1);
1139 }
1140
1141static int ssl3_get_certificate_request(SSL *s)
1142 {
1143 int ok,ret=0;
1144 unsigned long n,nc,l;
1145 unsigned int llen,ctype_num,i;
1146 X509_NAME *xn=NULL;
1147 unsigned char *p,*d,*q;
1148 STACK_OF(X509_NAME) *ca_sk=NULL;
1149
1150 n=ssl3_get_message(s,
1151 SSL3_ST_CR_CERT_REQ_A,
1152 SSL3_ST_CR_CERT_REQ_B,
1153 -1,
1154#if defined(MSDOS) && !defined(WIN32)
1155 1024*30, /* 30k max cert list :-) */
1156#else
1157 1024*100, /* 100k max cert list :-) */
1158#endif
1159 &ok);
1160
1161 if (!ok) return((int)n);
1162
1163 s->s3->tmp.cert_req=0;
1164
1165 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1166 {
1167 s->s3->tmp.reuse_message=1;
1168 return(1);
1169 }
1170
1171 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1172 {
1173 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1174 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1175 goto err;
1176 }
1177
1178 /* TLS does not like anon-DH with client cert */
1179 if (s->version > SSL3_VERSION)
1180 {
1181 l=s->s3->tmp.new_cipher->algorithms;
1182 if (l & SSL_aNULL)
1183 {
1184 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1185 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1186 goto err;
1187 }
1188 }
1189
1190 d=p=(unsigned char *)s->init_buf->data;
1191
1192 if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)
1193 {
1194 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1195 goto err;
1196 }
1197
1198 /* get the certificate types */
1199 ctype_num= *(p++);
1200 if (ctype_num > SSL3_CT_NUMBER)
1201 ctype_num=SSL3_CT_NUMBER;
1202 for (i=0; i<ctype_num; i++)
1203 s->s3->tmp.ctype[i]= p[i];
1204 p+=ctype_num;
1205
1206 /* get the CA RDNs */
1207 n2s(p,llen);
1208#if 0
1209{
1210FILE *out;
1211out=fopen("/tmp/vsign.der","w");
1212fwrite(p,1,llen,out);
1213fclose(out);
1214}
1215#endif
1216
1217 if ((llen+ctype_num+2+1) != n)
1218 {
1219 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1220 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1221 goto err;
1222 }
1223
1224 for (nc=0; nc<llen; )
1225 {
1226 n2s(p,l);
1227 if ((l+nc+2) > llen)
1228 {
1229 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1230 goto cont; /* netscape bugs */
1231 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1232 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1233 goto err;
1234 }
1235
1236 q=p;
1237
1238 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1239 {
1240 /* If netscape tolerance is on, ignore errors */
1241 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1242 goto cont;
1243 else
1244 {
1245 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1246 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1247 goto err;
1248 }
1249 }
1250
1251 if (q != (p+l))
1252 {
1253 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1254 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1255 goto err;
1256 }
1257 if (!sk_X509_NAME_push(ca_sk,xn))
1258 {
1259 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1260 goto err;
1261 }
1262
1263 p+=l;
1264 nc+=l+2;
1265 }
1266
1267 if (0)
1268 {
1269cont:
1270 ERR_clear_error();
1271 }
1272
1273 /* we should setup a certificate to return.... */
1274 s->s3->tmp.cert_req=1;
1275 s->s3->tmp.ctype_num=ctype_num;
1276 if (s->s3->tmp.ca_names != NULL)
1277 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1278 s->s3->tmp.ca_names=ca_sk;
1279 ca_sk=NULL;
1280
1281 ret=1;
1282err:
1283 if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);
1284 return(ret);
1285 }
1286
1287static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
1288 {
1289 return(X509_NAME_cmp(*a,*b));
1290 }
1291
1292static int ssl3_get_server_done(SSL *s)
1293 {
1294 int ok,ret=0;
1295 long n;
1296
1297 n=ssl3_get_message(s,
1298 SSL3_ST_CR_SRVR_DONE_A,
1299 SSL3_ST_CR_SRVR_DONE_B,
1300 SSL3_MT_SERVER_DONE,
1301 30, /* should be very small, like 0 :-) */
1302 &ok);
1303
1304 if (!ok) return((int)n);
1305 if (n > 0)
1306 {
1307 /* should contain no data */
1308 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1309 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1310 }
1311 ret=1;
1312 return(ret);
1313 }
1314
1315static int ssl3_send_client_key_exchange(SSL *s)
1316 {
1317 unsigned char *p,*d;
1318 int n;
1319 unsigned long l;
1320#ifndef NO_RSA
1321 unsigned char *q;
1322 EVP_PKEY *pkey=NULL;
1323#endif
1324
1325 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1326 {
1327 d=(unsigned char *)s->init_buf->data;
1328 p= &(d[4]);
1329
1330 l=s->s3->tmp.new_cipher->algorithms;
1331
1332#ifndef NO_RSA
1333 if (l & SSL_kRSA)
1334 {
1335 RSA *rsa;
1336 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1337
1338 if (s->session->sess_cert->peer_rsa_tmp != NULL)
1339 rsa=s->session->sess_cert->peer_rsa_tmp;
1340 else
1341 {
1342 pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);
1343 if ((pkey == NULL) ||
1344 (pkey->type != EVP_PKEY_RSA) ||
1345 (pkey->pkey.rsa == NULL))
1346 {
1347 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1348 goto err;
1349 }
1350 rsa=pkey->pkey.rsa;
1351 EVP_PKEY_free(pkey);
1352 }
1353
1354 tmp_buf[0]=s->client_version>>8;
1355 tmp_buf[1]=s->client_version&0xff;
1356 if (RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2) <= 0)
1357 goto err;
1358
1359 s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
1360
1361 q=p;
1362 /* Fix buf for TLS and beyond */
1363 if (s->version > SSL3_VERSION)
1364 p+=2;
1365 n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH,
1366 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1367#ifdef PKCS1_CHECK
1368 if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
1369 if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
1370#endif
1371 if (n <= 0)
1372 {
1373 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1374 goto err;
1375 }
1376
1377 /* Fix buf for TLS and beyond */
1378 if (s->version > SSL3_VERSION)
1379 {
1380 s2n(n,q);
1381 n+=2;
1382 }
1383
1384 s->session->master_key_length=
1385 s->method->ssl3_enc->generate_master_secret(s,
1386 s->session->master_key,
1387 tmp_buf,SSL_MAX_MASTER_KEY_LENGTH);
1388 memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH);
1389 }
1390 else
1391#endif
1392#ifndef NO_DH
1393 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1394 {
1395 DH *dh_srvr,*dh_clnt;
1396
1397 if (s->session->sess_cert->peer_dh_tmp != NULL)
1398 dh_srvr=s->session->sess_cert->peer_dh_tmp;
1399 else
1400 {
1401 /* we get them from the cert */
1402 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1403 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1404 goto err;
1405 }
1406
1407 /* generate a new random key */
1408 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1409 {
1410 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1411 goto err;
1412 }
1413 if (!DH_generate_key(dh_clnt))
1414 {
1415 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1416 goto err;
1417 }
1418
1419 /* use the 'p' output buffer for the DH key, but
1420 * make sure to clear it out afterwards */
1421
1422 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1423
1424 if (n <= 0)
1425 {
1426 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1427 goto err;
1428 }
1429
1430 /* generate master key from the result */
1431 s->session->master_key_length=
1432 s->method->ssl3_enc->generate_master_secret(s,
1433 s->session->master_key,p,n);
1434 /* clean up */
1435 memset(p,0,n);
1436
1437 /* send off the data */
1438 n=BN_num_bytes(dh_clnt->pub_key);
1439 s2n(n,p);
1440 BN_bn2bin(dh_clnt->pub_key,p);
1441 n+=2;
1442
1443 DH_free(dh_clnt);
1444
1445 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1446 }
1447 else
1448#endif
1449 {
1450 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1451 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1452 goto err;
1453 }
1454
1455 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1456 l2n3(n,d);
1457
1458 s->state=SSL3_ST_CW_KEY_EXCH_B;
1459 /* number of bytes to write */
1460 s->init_num=n+4;
1461 s->init_off=0;
1462 }
1463
1464 /* SSL3_ST_CW_KEY_EXCH_B */
1465 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1466err:
1467 return(-1);
1468 }
1469
1470static int ssl3_send_client_verify(SSL *s)
1471 {
1472 unsigned char *p,*d;
1473 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1474 EVP_PKEY *pkey;
1475#ifndef NO_RSA
1476 unsigned u=0;
1477#endif
1478 unsigned long n;
1479#ifndef NO_DSA
1480 int j;
1481#endif
1482
1483 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1484 {
1485 d=(unsigned char *)s->init_buf->data;
1486 p= &(d[4]);
1487 pkey=s->cert->key->privatekey;
1488
1489 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1490 &(data[MD5_DIGEST_LENGTH]));
1491
1492#ifndef NO_RSA
1493 if (pkey->type == EVP_PKEY_RSA)
1494 {
1495 s->method->ssl3_enc->cert_verify_mac(s,
1496 &(s->s3->finish_dgst1),&(data[0]));
1497 if (RSA_sign(NID_md5_sha1, data,
1498 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1499 &(p[2]), &u, pkey->pkey.rsa) <= 0 )
1500 {
1501 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1502 goto err;
1503 }
1504 s2n(u,p);
1505 n=u+2;
1506 }
1507 else
1508#endif
1509#ifndef NO_DSA
1510 if (pkey->type == EVP_PKEY_DSA)
1511 {
1512 if (!DSA_sign(pkey->save_type,
1513 &(data[MD5_DIGEST_LENGTH]),
1514 SHA_DIGEST_LENGTH,&(p[2]),
1515 (unsigned int *)&j,pkey->pkey.dsa))
1516 {
1517 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1518 goto err;
1519 }
1520 s2n(j,p);
1521 n=j+2;
1522 }
1523 else
1524#endif
1525 {
1526 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR);
1527 goto err;
1528 }
1529 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1530 l2n3(n,d);
1531
1532 s->init_num=(int)n+4;
1533 s->init_off=0;
1534 }
1535 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1536err:
1537 return(-1);
1538 }
1539
1540static int ssl3_send_client_certificate(SSL *s)
1541 {
1542 X509 *x509=NULL;
1543 EVP_PKEY *pkey=NULL;
1544 int i;
1545 unsigned long l;
1546
1547 if (s->state == SSL3_ST_CW_CERT_A)
1548 {
1549 if ((s->cert == NULL) ||
1550 (s->cert->key->x509 == NULL) ||
1551 (s->cert->key->privatekey == NULL))
1552 s->state=SSL3_ST_CW_CERT_B;
1553 else
1554 s->state=SSL3_ST_CW_CERT_C;
1555 }
1556
1557 /* We need to get a client cert */
1558 if (s->state == SSL3_ST_CW_CERT_B)
1559 {
1560 /* If we get an error, we need to
1561 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1562 * We then get retied later */
1563 i=0;
1564 if (s->ctx->client_cert_cb != NULL)
1565 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1566 if (i < 0)
1567 {
1568 s->rwstate=SSL_X509_LOOKUP;
1569 return(-1);
1570 }
1571 s->rwstate=SSL_NOTHING;
1572 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1573 {
1574 s->state=SSL3_ST_CW_CERT_B;
1575 if ( !SSL_use_certificate(s,x509) ||
1576 !SSL_use_PrivateKey(s,pkey))
1577 i=0;
1578 }
1579 else if (i == 1)
1580 {
1581 i=0;
1582 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1583 }
1584
1585 if (x509 != NULL) X509_free(x509);
1586 if (pkey != NULL) EVP_PKEY_free(pkey);
1587 if (i == 0)
1588 {
1589 if (s->version == SSL3_VERSION)
1590 {
1591 s->s3->tmp.cert_req=0;
1592 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1593 return(1);
1594 }
1595 else
1596 {
1597 s->s3->tmp.cert_req=2;
1598 }
1599 }
1600
1601 /* Ok, we have a cert */
1602 s->state=SSL3_ST_CW_CERT_C;
1603 }
1604
1605 if (s->state == SSL3_ST_CW_CERT_C)
1606 {
1607 s->state=SSL3_ST_CW_CERT_D;
1608 l=ssl3_output_cert_chain(s,
1609 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1610 s->init_num=(int)l;
1611 s->init_off=0;
1612 }
1613 /* SSL3_ST_CW_CERT_D */
1614 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1615 }
1616
1617#define has_bits(i,m) (((i)&(m)) == (m))
1618
1619static int ssl3_check_cert_and_algorithm(SSL *s)
1620 {
1621 int i,idx;
1622 long algs;
1623 EVP_PKEY *pkey=NULL;
1624 SESS_CERT *sc;
1625#ifndef NO_RSA
1626 RSA *rsa;
1627#endif
1628#ifndef NO_DH
1629 DH *dh;
1630#endif
1631
1632 sc=s->session->sess_cert;
1633
1634 if (sc == NULL)
1635 {
1636 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
1637 goto err;
1638 }
1639
1640 algs=s->s3->tmp.new_cipher->algorithms;
1641
1642 /* we don't have a certificate */
1643 if (algs & (SSL_aDH|SSL_aNULL))
1644 return(1);
1645
1646#ifndef NO_RSA
1647 rsa=s->session->sess_cert->peer_rsa_tmp;
1648#endif
1649#ifndef NO_DH
1650 dh=s->session->sess_cert->peer_dh_tmp;
1651#endif
1652
1653 /* This is the passed certificate */
1654
1655 idx=sc->peer_cert_type;
1656 pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);
1657 i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);
1658 EVP_PKEY_free(pkey);
1659
1660
1661 /* Check that we have a certificate if we require one */
1662 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1663 {
1664 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1665 goto f_err;
1666 }
1667#ifndef NO_DSA
1668 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1669 {
1670 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1671 goto f_err;
1672 }
1673#endif
1674#ifndef NO_RSA
1675 if ((algs & SSL_kRSA) &&
1676 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1677 {
1678 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1679 goto f_err;
1680 }
1681#endif
1682#ifndef NO_DH
1683 if ((algs & SSL_kEDH) &&
1684 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1685 {
1686 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1687 goto f_err;
1688 }
1689 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1690 {
1691 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1692 goto f_err;
1693 }
1694#ifndef NO_DSA
1695 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1696 {
1697 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1698 goto f_err;
1699 }
1700#endif
1701#endif
1702
1703 if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))
1704 {
1705#ifndef NO_RSA
1706 if (algs & SSL_kRSA)
1707 {
1708 if (rsa == NULL
1709 || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1710 {
1711 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1712 goto f_err;
1713 }
1714 }
1715 else
1716#endif
1717#ifndef NO_DH
1718 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1719 {
1720 if (dh == NULL
1721 || DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
1722 {
1723 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1724 goto f_err;
1725 }
1726 }
1727 else
1728#endif
1729 {
1730 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1731 goto f_err;
1732 }
1733 }
1734 return(1);
1735f_err:
1736 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1737err:
1738 return(0);
1739 }
1740
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
deleted file mode 100644
index cee2021b6b..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
65const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
66
67#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
68
69static long ssl3_default_timeout(void );
70
71OPENSSL_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
574static 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
588static 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
616static 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
623SSL_METHOD *sslv3_base_method(void)
624 {
625 return(&SSLv3_data);
626 }
627
628int ssl3_num_ciphers(void)
629 {
630 return(SSL3_NUM_CIPHERS);
631 }
632
633SSL_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 */
642int ssl3_pending(SSL *s)
643 {
644 return(s->s3->rrec.length);
645 }
646
647int ssl3_new(SSL *s)
648 {
649 SSL3_STATE *s3;
650
651 if ((s3=OPENSSL_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);
658err:
659 return(0);
660 }
661
662void 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 OPENSSL_free(s->s3->rbuf.buf);
670 if (s->s3->wbuf.buf != NULL)
671 OPENSSL_free(s->s3->wbuf.buf);
672 if (s->s3->rrec.comp != NULL)
673 OPENSSL_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 OPENSSL_free(s->s3);
682 s->s3=NULL;
683 }
684
685void 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 OPENSSL_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
720long 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
839long 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
883long 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
985long 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 */
1015SSL_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 FP_ICC ssl_cipher_ptr_id_cmp);
1045 if ((cpp == NULL) || !(*cpp)->valid)
1046 return(NULL);
1047 else
1048 return(*cpp);
1049 }
1050
1051int 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
1065SSL_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
1125int 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
1162int 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
1202int 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
1255int 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
1281int 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
1303int 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
1315int 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/*
1326if we are the server, and we have sent a 'RENEGOTIATE' message, we
1327need 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 1414079853..0000000000
--- a/src/lib/libssl/s3_pkt.c
+++ /dev/null
@@ -1,1198 +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
119static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
120 unsigned int len);
121static int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
122 unsigned int len);
123static int ssl3_get_record(SSL *s);
124static int do_compress(SSL *ssl);
125static int do_uncompress(SSL *ssl);
126static int do_change_cipher_spec(SSL *ssl);
127
128/* used only by ssl3_get_record */
129static 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 */
231static 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
251again:
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
351printf("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'); }
353printf("\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);
430f_err:
431 ssl3_send_alert(s,SSL3_AL_FATAL,al);
432err:
433 return(ret);
434 }
435
436static 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
453static 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 */
474int 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
522static 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));
632err:
633 return(-1);
634 }
635
636/* if s->s3->wbuf.left != 0, we need to call this */
637static 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 */
707int 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 }
757start:
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->mode & SSL_MODE_AUTO_RETRY))
903 {
904 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
905 {
906 BIO *bio;
907 /* In the case where we try to read application data,
908 * but we trigger an SSL handshake, we return -1 with
909 * the retry option set. Otherwise renegotiation may
910 * cause nasty problems in the blocking world */
911 s->rwstate=SSL_READING;
912 bio=SSL_get_rbio(s);
913 BIO_clear_retry_flags(bio);
914 BIO_set_retry_read(bio);
915 return(-1);
916 }
917 }
918 }
919 }
920 /* we either finished a handshake or ignored the request,
921 * now try again to obtain the (application) data we were asked for */
922 goto start;
923 }
924
925 if (s->s3->alert_fragment_len >= 2)
926 {
927 int alert_level = s->s3->alert_fragment[0];
928 int alert_descr = s->s3->alert_fragment[1];
929
930 s->s3->alert_fragment_len = 0;
931
932 if (s->info_callback != NULL)
933 cb=s->info_callback;
934 else if (s->ctx->info_callback != NULL)
935 cb=s->ctx->info_callback;
936
937 if (cb != NULL)
938 {
939 j = (alert_level << 8) | alert_descr;
940 cb(s, SSL_CB_READ_ALERT, j);
941 }
942
943 if (alert_level == 1) /* warning */
944 {
945 s->s3->warn_alert = alert_descr;
946 if (alert_descr == SSL_AD_CLOSE_NOTIFY)
947 {
948 s->shutdown |= SSL_RECEIVED_SHUTDOWN;
949 return(0);
950 }
951 }
952 else if (alert_level == 2) /* fatal */
953 {
954 char tmp[16];
955
956 s->rwstate=SSL_NOTHING;
957 s->s3->fatal_alert = alert_descr;
958 SSLerr(SSL_F_SSL3_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr);
959 BIO_snprintf(tmp,sizeof tmp,"%d",alert_descr);
960 ERR_add_error_data(2,"SSL alert number ",tmp);
961 s->shutdown|=SSL_RECEIVED_SHUTDOWN;
962 SSL_CTX_remove_session(s->ctx,s->session);
963 return(0);
964 }
965 else
966 {
967 al=SSL_AD_ILLEGAL_PARAMETER;
968 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);
969 goto f_err;
970 }
971
972 goto start;
973 }
974
975 if (s->shutdown & SSL_SENT_SHUTDOWN) /* but we have not received a shutdown */
976 {
977 s->rwstate=SSL_NOTHING;
978 rr->length=0;
979 return(0);
980 }
981
982 if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)
983 {
984 /* 'Change Cipher Spec' is just a single byte, so we know
985 * exactly what the record payload has to look like */
986 if ( (rr->length != 1) || (rr->off != 0) ||
987 (rr->data[0] != SSL3_MT_CCS))
988 {
989 i=SSL_AD_ILLEGAL_PARAMETER;
990 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);
991 goto err;
992 }
993
994 rr->length=0;
995 s->s3->change_cipher_spec=1;
996 if (!do_change_cipher_spec(s))
997 goto err;
998 else
999 goto start;
1000 }
1001
1002 /* Unexpected handshake message (Client Hello, or protocol violation) */
1003 if ((s->s3->handshake_fragment_len >= 4) && !s->in_handshake)
1004 {
1005 if (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&
1006 !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))
1007 {
1008#if 0 /* worked only because C operator preferences are not as expected (and
1009 * because this is not really needed for clients except for detecting
1010 * protocol violations): */
1011 s->state=SSL_ST_BEFORE|(s->server)
1012 ?SSL_ST_ACCEPT
1013 :SSL_ST_CONNECT;
1014#else
1015 s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT;
1016#endif
1017 s->new_session=1;
1018 }
1019 i=s->handshake_func(s);
1020 if (i < 0) return(i);
1021 if (i == 0)
1022 {
1023 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);
1024 return(-1);
1025 }
1026
1027 if (!(s->mode & SSL_MODE_AUTO_RETRY))
1028 {
1029 if (s->s3->rbuf.left == 0) /* no read-ahead left? */
1030 {
1031 BIO *bio;
1032 /* In the case where we try to read application data,
1033 * but we trigger an SSL handshake, we return -1 with
1034 * the retry option set. Otherwise renegotiation may
1035 * cause nasty problems in the blocking world */
1036 s->rwstate=SSL_READING;
1037 bio=SSL_get_rbio(s);
1038 BIO_clear_retry_flags(bio);
1039 BIO_set_retry_read(bio);
1040 return(-1);
1041 }
1042 }
1043 goto start;
1044 }
1045
1046 switch (rr->type)
1047 {
1048 default:
1049#ifndef NO_TLS
1050 /* TLS just ignores unknown message types */
1051 if (s->version == TLS1_VERSION)
1052 {
1053 goto start;
1054 }
1055#endif
1056 al=SSL_AD_UNEXPECTED_MESSAGE;
1057 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1058 goto f_err;
1059 case SSL3_RT_CHANGE_CIPHER_SPEC:
1060 case SSL3_RT_ALERT:
1061 case SSL3_RT_HANDSHAKE:
1062 /* we already handled all of these, with the possible exception
1063 * of SSL3_RT_HANDSHAKE when s->in_handshake is set, but that
1064 * should not happen when type != rr->type */
1065 al=SSL_AD_UNEXPECTED_MESSAGE;
1066 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_INTERNAL_ERROR);
1067 goto f_err;
1068 case SSL3_RT_APPLICATION_DATA:
1069 /* At this point, we were expecting handshake data,
1070 * but have application data. If the library was
1071 * running inside ssl3_read() (i.e. in_read_app_data
1072 * is set) and it makes sense to read application data
1073 * at this point (session renegotiation not yet started),
1074 * we will indulge it.
1075 */
1076 if (s->s3->in_read_app_data &&
1077 (s->s3->total_renegotiations != 0) &&
1078 ((
1079 (s->state & SSL_ST_CONNECT) &&
1080 (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&
1081 (s->state <= SSL3_ST_CR_SRVR_HELLO_A)
1082 ) || (
1083 (s->state & SSL_ST_ACCEPT) &&
1084 (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&
1085 (s->state >= SSL3_ST_SR_CLNT_HELLO_A)
1086 )
1087 ))
1088 {
1089 s->s3->in_read_app_data=0;
1090 return(-1);
1091 }
1092 else
1093 {
1094 al=SSL_AD_UNEXPECTED_MESSAGE;
1095 SSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);
1096 goto f_err;
1097 }
1098 }
1099 /* not reached */
1100
1101f_err:
1102 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1103err:
1104 return(-1);
1105 }
1106
1107static int do_change_cipher_spec(SSL *s)
1108 {
1109 int i;
1110 const char *sender;
1111 int slen;
1112
1113 if (s->state & SSL_ST_ACCEPT)
1114 i=SSL3_CHANGE_CIPHER_SERVER_READ;
1115 else
1116 i=SSL3_CHANGE_CIPHER_CLIENT_READ;
1117
1118 if (s->s3->tmp.key_block == NULL)
1119 {
1120 s->session->cipher=s->s3->tmp.new_cipher;
1121 if (!s->method->ssl3_enc->setup_key_block(s)) return(0);
1122 }
1123
1124 if (!s->method->ssl3_enc->change_cipher_state(s,i))
1125 return(0);
1126
1127 /* we have to record the message digest at
1128 * this point so we can get it before we read
1129 * the finished message */
1130 if (s->state & SSL_ST_CONNECT)
1131 {
1132 sender=s->method->ssl3_enc->server_finished_label;
1133 slen=s->method->ssl3_enc->server_finished_label_len;
1134 }
1135 else
1136 {
1137 sender=s->method->ssl3_enc->client_finished_label;
1138 slen=s->method->ssl3_enc->client_finished_label_len;
1139 }
1140
1141 s->s3->tmp.peer_finish_md_len = s->method->ssl3_enc->final_finish_mac(s,
1142 &(s->s3->finish_dgst1),
1143 &(s->s3->finish_dgst2),
1144 sender,slen,s->s3->tmp.peer_finish_md);
1145
1146 return(1);
1147 }
1148
1149void ssl3_send_alert(SSL *s, int level, int desc)
1150 {
1151 /* Map tls/ssl alert value to correct one */
1152 desc=s->method->ssl3_enc->alert_value(desc);
1153 if (desc < 0) return;
1154 /* If a fatal one, remove from cache */
1155 if ((level == 2) && (s->session != NULL))
1156 SSL_CTX_remove_session(s->ctx,s->session);
1157
1158 s->s3->alert_dispatch=1;
1159 s->s3->send_alert[0]=level;
1160 s->s3->send_alert[1]=desc;
1161 if (s->s3->wbuf.left == 0) /* data still being written out */
1162 ssl3_dispatch_alert(s);
1163 /* else data is still being written out, we will get written
1164 * some time in the future */
1165 }
1166
1167int ssl3_dispatch_alert(SSL *s)
1168 {
1169 int i,j;
1170 void (*cb)()=NULL;
1171
1172 s->s3->alert_dispatch=0;
1173 i=do_ssl3_write(s,SSL3_RT_ALERT,&s->s3->send_alert[0],2);
1174 if (i <= 0)
1175 {
1176 s->s3->alert_dispatch=1;
1177 }
1178 else
1179 {
1180 /* If it is important, send it now. If the message
1181 * does not get sent due to non-blocking IO, we will
1182 * not worry too much. */
1183 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1184 (void)BIO_flush(s->wbio);
1185
1186 if (s->info_callback != NULL)
1187 cb=s->info_callback;
1188 else if (s->ctx->info_callback != NULL)
1189 cb=s->ctx->info_callback;
1190
1191 if (cb != NULL)
1192 {
1193 j=(s->s3->send_alert[0]<<8)|s->s3->send_alert[1];
1194 cb(s,SSL_CB_WRITE_ALERT,j);
1195 }
1196 }
1197 return(i);
1198 }
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
deleted file mode 100644
index d04232960e..0000000000
--- a/src/lib/libssl/s3_srvr.c
+++ /dev/null
@@ -1,1755 +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
73static SSL_METHOD *ssl3_get_server_method(int ver);
74static int ssl3_get_client_hello(SSL *s);
75static int ssl3_check_client_hello(SSL *s);
76static int ssl3_send_server_hello(SSL *s);
77static int ssl3_send_server_key_exchange(SSL *s);
78static int ssl3_send_certificate_request(SSL *s);
79static int ssl3_send_server_done(SSL *s);
80static int ssl3_get_client_key_exchange(SSL *s);
81static int ssl3_get_client_certificate(SSL *s);
82static int ssl3_get_cert_verify(SSL *s);
83static int ssl3_send_hello_request(SSL *s);
84
85static 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
93SSL_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
109int 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 {
157 SSLerr(SSL_F_SSL3_ACCEPT, SSL_R_INTERNAL_ERROR);
158 return -1;
159 }
160 s->type=SSL_ST_ACCEPT;
161
162 if (s->init_buf == NULL)
163 {
164 if ((buf=BUF_MEM_new()) == NULL)
165 {
166 ret= -1;
167 goto end;
168 }
169 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
170 {
171 ret= -1;
172 goto end;
173 }
174 s->init_buf=buf;
175 }
176
177 if (!ssl3_setup_buffers(s))
178 {
179 ret= -1;
180 goto end;
181 }
182
183 /* Ok, we now need to push on a buffering BIO so that
184 * the output is sent in a way that TCP likes :-)
185 */
186 if (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }
187
188 s->init_num=0;
189
190 if (s->state != SSL_ST_RENEGOTIATE)
191 {
192 ssl3_init_finished_mac(s);
193 s->state=SSL3_ST_SR_CLNT_HELLO_A;
194 s->ctx->stats.sess_accept++;
195 }
196 else
197 {
198 s->ctx->stats.sess_accept_renegotiate++;
199 s->state=SSL3_ST_SW_HELLO_REQ_A;
200 }
201 break;
202
203 case SSL3_ST_SW_HELLO_REQ_A:
204 case SSL3_ST_SW_HELLO_REQ_B:
205
206 s->shutdown=0;
207 ret=ssl3_send_hello_request(s);
208 if (ret <= 0) goto end;
209 s->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;
210 s->state=SSL3_ST_SW_FLUSH;
211 s->init_num=0;
212
213 ssl3_init_finished_mac(s);
214 break;
215
216 case SSL3_ST_SW_HELLO_REQ_C:
217 s->state=SSL_ST_OK;
218 ret=1;
219 goto end;
220 /* break; */
221
222 case SSL3_ST_SR_CLNT_HELLO_A:
223 case SSL3_ST_SR_CLNT_HELLO_B:
224 case SSL3_ST_SR_CLNT_HELLO_C:
225
226 s->shutdown=0;
227 ret=ssl3_get_client_hello(s);
228 if (ret <= 0) goto end;
229 s->state=SSL3_ST_SW_SRVR_HELLO_A;
230 s->init_num=0;
231 break;
232
233 case SSL3_ST_SW_SRVR_HELLO_A:
234 case SSL3_ST_SW_SRVR_HELLO_B:
235 ret=ssl3_send_server_hello(s);
236 if (ret <= 0) goto end;
237
238 if (s->hit)
239 s->state=SSL3_ST_SW_CHANGE_A;
240 else
241 s->state=SSL3_ST_SW_CERT_A;
242 s->init_num=0;
243 break;
244
245 case SSL3_ST_SW_CERT_A:
246 case SSL3_ST_SW_CERT_B:
247 /* Check if it is anon DH */
248 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
249 {
250 ret=ssl3_send_server_certificate(s);
251 if (ret <= 0) goto end;
252 }
253 else
254 skip=1;
255 s->state=SSL3_ST_SW_KEY_EXCH_A;
256 s->init_num=0;
257 break;
258
259 case SSL3_ST_SW_KEY_EXCH_A:
260 case SSL3_ST_SW_KEY_EXCH_B:
261 l=s->s3->tmp.new_cipher->algorithms;
262
263 /* clear this, it may get reset by
264 * send_server_key_exchange */
265 if (s->options & SSL_OP_EPHEMERAL_RSA)
266 s->s3->tmp.use_rsa_tmp=1;
267 else
268 s->s3->tmp.use_rsa_tmp=0;
269
270 /* only send if a DH key exchange, fortezza or
271 * RSA but we have a sign only certificate */
272 if (s->s3->tmp.use_rsa_tmp
273 || (l & (SSL_DH|SSL_kFZA))
274 || ((l & SSL_kRSA)
275 && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL
276 || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)
277 && EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)
278 )
279 )
280 )
281 )
282 {
283 ret=ssl3_send_server_key_exchange(s);
284 if (ret <= 0) goto end;
285 }
286 else
287 skip=1;
288
289 s->state=SSL3_ST_SW_CERT_REQ_A;
290 s->init_num=0;
291 break;
292
293 case SSL3_ST_SW_CERT_REQ_A:
294 case SSL3_ST_SW_CERT_REQ_B:
295 if (/* don't request cert unless asked for it: */
296 !(s->verify_mode & SSL_VERIFY_PEER) ||
297 /* if SSL_VERIFY_CLIENT_ONCE is set,
298 * don't request cert during re-negotiation: */
299 ((s->session->peer != NULL) &&
300 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
301 /* never request cert in anonymous ciphersuites
302 * (see section "Certificate request" in SSL 3 drafts
303 * and in RFC 2246): */
304 ((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&
305 /* ... except when the application insists on verification
306 * (against the specs, but s3_clnt.c accepts this for SSL 3) */
307 !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)))
308 {
309 /* no cert request */
310 skip=1;
311 s->s3->tmp.cert_request=0;
312 s->state=SSL3_ST_SW_SRVR_DONE_A;
313 }
314 else
315 {
316 s->s3->tmp.cert_request=1;
317 ret=ssl3_send_certificate_request(s);
318 if (ret <= 0) goto end;
319#ifndef NETSCAPE_HANG_BUG
320 s->state=SSL3_ST_SW_SRVR_DONE_A;
321#else
322 s->state=SSL3_ST_SW_FLUSH;
323 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
324#endif
325 s->init_num=0;
326 }
327 break;
328
329 case SSL3_ST_SW_SRVR_DONE_A:
330 case SSL3_ST_SW_SRVR_DONE_B:
331 ret=ssl3_send_server_done(s);
332 if (ret <= 0) goto end;
333 s->s3->tmp.next_state=SSL3_ST_SR_CERT_A;
334 s->state=SSL3_ST_SW_FLUSH;
335 s->init_num=0;
336 break;
337
338 case SSL3_ST_SW_FLUSH:
339 /* number of bytes to be flushed */
340 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
341 if (num1 > 0)
342 {
343 s->rwstate=SSL_WRITING;
344 num1=BIO_flush(s->wbio);
345 if (num1 <= 0) { ret= -1; goto end; }
346 s->rwstate=SSL_NOTHING;
347 }
348
349 s->state=s->s3->tmp.next_state;
350 break;
351
352 case SSL3_ST_SR_CERT_A:
353 case SSL3_ST_SR_CERT_B:
354 /* Check for second client hello (MS SGC) */
355 ret = ssl3_check_client_hello(s);
356 if (ret <= 0)
357 goto end;
358 if (ret == 2)
359 s->state = SSL3_ST_SR_CLNT_HELLO_C;
360 else {
361 /* could be sent for a DH cert, even if we
362 * have not asked for it :-) */
363 ret=ssl3_get_client_certificate(s);
364 if (ret <= 0) goto end;
365 s->init_num=0;
366 s->state=SSL3_ST_SR_KEY_EXCH_A;
367 }
368 break;
369
370 case SSL3_ST_SR_KEY_EXCH_A:
371 case SSL3_ST_SR_KEY_EXCH_B:
372 ret=ssl3_get_client_key_exchange(s);
373 if (ret <= 0) goto end;
374 s->state=SSL3_ST_SR_CERT_VRFY_A;
375 s->init_num=0;
376
377 /* We need to get hashes here so if there is
378 * a client cert, it can be verified */
379 s->method->ssl3_enc->cert_verify_mac(s,
380 &(s->s3->finish_dgst1),
381 &(s->s3->tmp.cert_verify_md[0]));
382 s->method->ssl3_enc->cert_verify_mac(s,
383 &(s->s3->finish_dgst2),
384 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));
385
386 break;
387
388 case SSL3_ST_SR_CERT_VRFY_A:
389 case SSL3_ST_SR_CERT_VRFY_B:
390
391 /* we should decide if we expected this one */
392 ret=ssl3_get_cert_verify(s);
393 if (ret <= 0) goto end;
394
395 s->state=SSL3_ST_SR_FINISHED_A;
396 s->init_num=0;
397 break;
398
399 case SSL3_ST_SR_FINISHED_A:
400 case SSL3_ST_SR_FINISHED_B:
401 ret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,
402 SSL3_ST_SR_FINISHED_B);
403 if (ret <= 0) goto end;
404 if (s->hit)
405 s->state=SSL_ST_OK;
406 else
407 s->state=SSL3_ST_SW_CHANGE_A;
408 s->init_num=0;
409 break;
410
411 case SSL3_ST_SW_CHANGE_A:
412 case SSL3_ST_SW_CHANGE_B:
413
414 s->session->cipher=s->s3->tmp.new_cipher;
415 if (!s->method->ssl3_enc->setup_key_block(s))
416 { ret= -1; goto end; }
417
418 ret=ssl3_send_change_cipher_spec(s,
419 SSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);
420
421 if (ret <= 0) goto end;
422 s->state=SSL3_ST_SW_FINISHED_A;
423 s->init_num=0;
424
425 if (!s->method->ssl3_enc->change_cipher_state(s,
426 SSL3_CHANGE_CIPHER_SERVER_WRITE))
427 {
428 ret= -1;
429 goto end;
430 }
431
432 break;
433
434 case SSL3_ST_SW_FINISHED_A:
435 case SSL3_ST_SW_FINISHED_B:
436 ret=ssl3_send_finished(s,
437 SSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,
438 s->method->ssl3_enc->server_finished_label,
439 s->method->ssl3_enc->server_finished_label_len);
440 if (ret <= 0) goto end;
441 s->state=SSL3_ST_SW_FLUSH;
442 if (s->hit)
443 s->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;
444 else
445 s->s3->tmp.next_state=SSL_ST_OK;
446 s->init_num=0;
447 break;
448
449 case SSL_ST_OK:
450 /* clean a few things up */
451 ssl3_cleanup_key_block(s);
452
453 BUF_MEM_free(s->init_buf);
454 s->init_buf=NULL;
455
456 /* remove buffering on output */
457 ssl_free_wbio_buffer(s);
458
459 s->new_session=0;
460 s->init_num=0;
461
462 ssl_update_cache(s,SSL_SESS_CACHE_SERVER);
463
464 s->ctx->stats.sess_accept_good++;
465 /* s->server=1; */
466 s->handshake_func=ssl3_accept;
467 ret=1;
468
469 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
470
471 goto end;
472 /* break; */
473
474 default:
475 SSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);
476 ret= -1;
477 goto end;
478 /* break; */
479 }
480
481 if (!s->s3->tmp.reuse_message && !skip)
482 {
483 if (s->debug)
484 {
485 if ((ret=BIO_flush(s->wbio)) <= 0)
486 goto end;
487 }
488
489
490 if ((cb != NULL) && (s->state != state))
491 {
492 new_state=s->state;
493 s->state=state;
494 cb(s,SSL_CB_ACCEPT_LOOP,1);
495 s->state=new_state;
496 }
497 }
498 skip=0;
499 }
500end:
501 /* BIO_flush(s->wbio); */
502
503 if (cb != NULL)
504 cb(s,SSL_CB_ACCEPT_EXIT,ret);
505 s->in_handshake--;
506 return(ret);
507 }
508
509static int ssl3_send_hello_request(SSL *s)
510 {
511 unsigned char *p;
512
513 if (s->state == SSL3_ST_SW_HELLO_REQ_A)
514 {
515 p=(unsigned char *)s->init_buf->data;
516 *(p++)=SSL3_MT_HELLO_REQUEST;
517 *(p++)=0;
518 *(p++)=0;
519 *(p++)=0;
520
521 s->state=SSL3_ST_SW_HELLO_REQ_B;
522 /* number of bytes to write */
523 s->init_num=4;
524 s->init_off=0;
525 }
526
527 /* SSL3_ST_SW_HELLO_REQ_B */
528 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
529 }
530
531static int ssl3_check_client_hello(SSL *s)
532 {
533 int ok;
534 long n;
535
536 n=ssl3_get_message(s,
537 SSL3_ST_SR_CERT_A,
538 SSL3_ST_SR_CERT_B,
539 -1,
540 SSL3_RT_MAX_PLAIN_LENGTH,
541 &ok);
542 if (!ok) return((int)n);
543 s->s3->tmp.reuse_message = 1;
544 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_HELLO)
545 {
546 /* Throw away what we have done so far in the current handshake,
547 * which will now be aborted. (A full SSL_clear would be too much.)
548 * I hope that tmp.dh is the only thing that may need to be cleared
549 * when a handshake is not completed ... */
550#ifndef NO_DH
551 if (s->s3->tmp.dh != NULL)
552 {
553 DH_free(s->s3->tmp.dh);
554 s->s3->tmp.dh = NULL;
555 }
556#endif
557 return 2;
558 }
559 return 1;
560}
561
562static int ssl3_get_client_hello(SSL *s)
563 {
564 int i,j,ok,al,ret= -1;
565 long n;
566 unsigned long id;
567 unsigned char *p,*d,*q;
568 SSL_CIPHER *c;
569 SSL_COMP *comp=NULL;
570 STACK_OF(SSL_CIPHER) *ciphers=NULL;
571
572 /* We do this so that we will respond with our native type.
573 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
574 * This down switching should be handled by a different method.
575 * If we are SSLv3, we will respond with SSLv3, even if prompted with
576 * TLSv1.
577 */
578 if (s->state == SSL3_ST_SR_CLNT_HELLO_A)
579 {
580 s->first_packet=1;
581 s->state=SSL3_ST_SR_CLNT_HELLO_B;
582 }
583 n=ssl3_get_message(s,
584 SSL3_ST_SR_CLNT_HELLO_B,
585 SSL3_ST_SR_CLNT_HELLO_C,
586 SSL3_MT_CLIENT_HELLO,
587 SSL3_RT_MAX_PLAIN_LENGTH,
588 &ok);
589
590 if (!ok) return((int)n);
591 d=p=(unsigned char *)s->init_buf->data;
592
593 /* use version from inside client hello, not from record header
594 * (may differ: see RFC 2246, Appendix E, second paragraph) */
595 s->client_version=(((int)p[0])<<8)|(int)p[1];
596 p+=2;
597
598 /* load the client random */
599 memcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);
600 p+=SSL3_RANDOM_SIZE;
601
602 /* get the session-id */
603 j= *(p++);
604
605 s->hit=0;
606 if (j == 0)
607 {
608 if (!ssl_get_new_session(s,1))
609 goto err;
610 }
611 else
612 {
613 i=ssl_get_prev_session(s,p,j);
614 if (i == 1)
615 { /* previous session */
616 s->hit=1;
617 }
618 else if (i == -1)
619 goto err;
620 else /* i == 0 */
621 {
622 if (!ssl_get_new_session(s,1))
623 goto err;
624 }
625 }
626
627 p+=j;
628 n2s(p,i);
629 if ((i == 0) && (j != 0))
630 {
631 /* we need a cipher if we are not resuming a session */
632 al=SSL_AD_ILLEGAL_PARAMETER;
633 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);
634 goto f_err;
635 }
636 if ((i+p) > (d+n))
637 {
638 /* not enough data */
639 al=SSL_AD_DECODE_ERROR;
640 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
641 goto f_err;
642 }
643 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
644 == NULL))
645 {
646 goto err;
647 }
648 p+=i;
649
650 /* If it is a hit, check that the cipher is in the list */
651 if ((s->hit) && (i > 0))
652 {
653 j=0;
654 id=s->session->cipher->id;
655
656#ifdef CIPHER_DEBUG
657 printf("client sent %d ciphers\n",sk_num(ciphers));
658#endif
659 for (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)
660 {
661 c=sk_SSL_CIPHER_value(ciphers,i);
662#ifdef CIPHER_DEBUG
663 printf("client [%2d of %2d]:%s\n",
664 i,sk_num(ciphers),SSL_CIPHER_get_name(c));
665#endif
666 if (c->id == id)
667 {
668 j=1;
669 break;
670 }
671 }
672 if (j == 0)
673 {
674 if ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))
675 {
676 /* Very bad for multi-threading.... */
677 s->session->cipher=sk_SSL_CIPHER_value(ciphers,
678 0);
679 }
680 else
681 {
682 /* we need to have the cipher in the cipher
683 * list if we are asked to reuse it */
684 al=SSL_AD_ILLEGAL_PARAMETER;
685 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);
686 goto f_err;
687 }
688 }
689 }
690
691 /* compression */
692 i= *(p++);
693 q=p;
694 for (j=0; j<i; j++)
695 {
696 if (p[j] == 0) break;
697 }
698
699 p+=i;
700 if (j >= i)
701 {
702 /* no compress */
703 al=SSL_AD_DECODE_ERROR;
704 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);
705 goto f_err;
706 }
707
708 /* Worst case, we will use the NULL compression, but if we have other
709 * options, we will now look for them. We have i-1 compression
710 * algorithms from the client, starting at q. */
711 s->s3->tmp.new_compression=NULL;
712 if (s->ctx->comp_methods != NULL)
713 { /* See if we have a match */
714 int m,nn,o,v,done=0;
715
716 nn=sk_SSL_COMP_num(s->ctx->comp_methods);
717 for (m=0; m<nn; m++)
718 {
719 comp=sk_SSL_COMP_value(s->ctx->comp_methods,m);
720 v=comp->id;
721 for (o=0; o<i; o++)
722 {
723 if (v == q[o])
724 {
725 done=1;
726 break;
727 }
728 }
729 if (done) break;
730 }
731 if (done)
732 s->s3->tmp.new_compression=comp;
733 else
734 comp=NULL;
735 }
736
737 /* TLS does not mind if there is extra stuff */
738 if (s->version == SSL3_VERSION)
739 {
740 if (p > (d+n))
741 {
742 /* wrong number of bytes,
743 * there could be more to follow */
744 al=SSL_AD_DECODE_ERROR;
745 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);
746 goto f_err;
747 }
748 }
749
750 /* Given s->session->ciphers and ssl_get_ciphers_by_id(s), we must
751 * pick a cipher */
752
753 if (!s->hit)
754 {
755 s->session->compress_meth=(comp == NULL)?0:comp->id;
756 if (s->session->ciphers != NULL)
757 sk_SSL_CIPHER_free(s->session->ciphers);
758 s->session->ciphers=ciphers;
759 if (ciphers == NULL)
760 {
761 al=SSL_AD_ILLEGAL_PARAMETER;
762 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);
763 goto f_err;
764 }
765 ciphers=NULL;
766 c=ssl3_choose_cipher(s,s->session->ciphers,
767 ssl_get_ciphers_by_id(s));
768
769 if (c == NULL)
770 {
771 al=SSL_AD_HANDSHAKE_FAILURE;
772 SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);
773 goto f_err;
774 }
775 s->s3->tmp.new_cipher=c;
776 }
777 else
778 {
779 /* Session-id reuse */
780#ifdef REUSE_CIPHER_BUG
781 STACK_OF(SSL_CIPHER) *sk;
782 SSL_CIPHER *nc=NULL;
783 SSL_CIPHER *ec=NULL;
784
785 if (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)
786 {
787 sk=s->session->ciphers;
788 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
789 {
790 c=sk_SSL_CIPHER_value(sk,i);
791 if (c->algorithms & SSL_eNULL)
792 nc=c;
793 if (SSL_C_IS_EXPORT(c))
794 ec=c;
795 }
796 if (nc != NULL)
797 s->s3->tmp.new_cipher=nc;
798 else if (ec != NULL)
799 s->s3->tmp.new_cipher=ec;
800 else
801 s->s3->tmp.new_cipher=s->session->cipher;
802 }
803 else
804#endif
805 s->s3->tmp.new_cipher=s->session->cipher;
806 }
807
808 /* we now have the following setup.
809 * client_random
810 * cipher_list - our prefered list of ciphers
811 * ciphers - the clients prefered list of ciphers
812 * compression - basically ignored right now
813 * ssl version is set - sslv3
814 * s->session - The ssl session has been setup.
815 * s->hit - session reuse flag
816 * s->tmp.new_cipher - the new cipher to use.
817 */
818
819 ret=1;
820 if (0)
821 {
822f_err:
823 ssl3_send_alert(s,SSL3_AL_FATAL,al);
824 }
825err:
826 if (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);
827 return(ret);
828 }
829
830static int ssl3_send_server_hello(SSL *s)
831 {
832 unsigned char *buf;
833 unsigned char *p,*d;
834 int i,sl;
835 unsigned long l,Time;
836
837 if (s->state == SSL3_ST_SW_SRVR_HELLO_A)
838 {
839 buf=(unsigned char *)s->init_buf->data;
840 p=s->s3->server_random;
841 Time=time(NULL); /* Time */
842 l2n(Time,p);
843 RAND_pseudo_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
844 /* Do the message type and length last */
845 d=p= &(buf[4]);
846
847 *(p++)=s->version>>8;
848 *(p++)=s->version&0xff;
849
850 /* Random stuff */
851 memcpy(p,s->s3->server_random,SSL3_RANDOM_SIZE);
852 p+=SSL3_RANDOM_SIZE;
853
854 /* now in theory we have 3 options to sending back the
855 * session id. If it is a re-use, we send back the
856 * old session-id, if it is a new session, we send
857 * back the new session-id or we send back a 0 length
858 * session-id if we want it to be single use.
859 * Currently I will not implement the '0' length session-id
860 * 12-Jan-98 - I'll now support the '0' length stuff.
861 */
862 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER))
863 s->session->session_id_length=0;
864
865 sl=s->session->session_id_length;
866 *(p++)=sl;
867 memcpy(p,s->session->session_id,sl);
868 p+=sl;
869
870 /* put the cipher */
871 i=ssl3_put_cipher_by_char(s->s3->tmp.new_cipher,p);
872 p+=i;
873
874 /* put the compression method */
875 if (s->s3->tmp.new_compression == NULL)
876 *(p++)=0;
877 else
878 *(p++)=s->s3->tmp.new_compression->id;
879
880 /* do the header */
881 l=(p-d);
882 d=buf;
883 *(d++)=SSL3_MT_SERVER_HELLO;
884 l2n3(l,d);
885
886 s->state=SSL3_ST_CW_CLNT_HELLO_B;
887 /* number of bytes to write */
888 s->init_num=p-buf;
889 s->init_off=0;
890 }
891
892 /* SSL3_ST_CW_CLNT_HELLO_B */
893 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
894 }
895
896static int ssl3_send_server_done(SSL *s)
897 {
898 unsigned char *p;
899
900 if (s->state == SSL3_ST_SW_SRVR_DONE_A)
901 {
902 p=(unsigned char *)s->init_buf->data;
903
904 /* do the header */
905 *(p++)=SSL3_MT_SERVER_DONE;
906 *(p++)=0;
907 *(p++)=0;
908 *(p++)=0;
909
910 s->state=SSL3_ST_SW_SRVR_DONE_B;
911 /* number of bytes to write */
912 s->init_num=4;
913 s->init_off=0;
914 }
915
916 /* SSL3_ST_CW_CLNT_HELLO_B */
917 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
918 }
919
920static int ssl3_send_server_key_exchange(SSL *s)
921 {
922#ifndef NO_RSA
923 unsigned char *q;
924 int j,num;
925 RSA *rsa;
926 unsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
927 unsigned int u;
928#endif
929#ifndef NO_DH
930 DH *dh=NULL,*dhp;
931#endif
932 EVP_PKEY *pkey;
933 unsigned char *p,*d;
934 int al,i;
935 unsigned long type;
936 int n;
937 CERT *cert;
938 BIGNUM *r[4];
939 int nr[4],kn;
940 BUF_MEM *buf;
941 EVP_MD_CTX md_ctx;
942
943 if (s->state == SSL3_ST_SW_KEY_EXCH_A)
944 {
945 type=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;
946 cert=s->cert;
947
948 buf=s->init_buf;
949
950 r[0]=r[1]=r[2]=r[3]=NULL;
951 n=0;
952#ifndef NO_RSA
953 if (type & SSL_kRSA)
954 {
955 rsa=cert->rsa_tmp;
956 if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL))
957 {
958 rsa=s->cert->rsa_tmp_cb(s,
959 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
960 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
961 if(rsa == NULL)
962 {
963 al=SSL_AD_HANDSHAKE_FAILURE;
964 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY);
965 goto f_err;
966 }
967 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
968 cert->rsa_tmp=rsa;
969 }
970 if (rsa == NULL)
971 {
972 al=SSL_AD_HANDSHAKE_FAILURE;
973 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);
974 goto f_err;
975 }
976 r[0]=rsa->n;
977 r[1]=rsa->e;
978 s->s3->tmp.use_rsa_tmp=1;
979 }
980 else
981#endif
982#ifndef NO_DH
983 if (type & SSL_kEDH)
984 {
985 dhp=cert->dh_tmp;
986 if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))
987 dhp=s->cert->dh_tmp_cb(s,
988 SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),
989 SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));
990 if (dhp == NULL)
991 {
992 al=SSL_AD_HANDSHAKE_FAILURE;
993 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
994 goto f_err;
995 }
996
997 if (s->s3->tmp.dh != NULL)
998 {
999 DH_free(dh);
1000 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, SSL_R_INTERNAL_ERROR);
1001 goto err;
1002 }
1003
1004 if ((dh=DHparams_dup(dhp)) == NULL)
1005 {
1006 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1007 goto err;
1008 }
1009
1010 s->s3->tmp.dh=dh;
1011 if ((dhp->pub_key == NULL ||
1012 dhp->priv_key == NULL ||
1013 (s->options & SSL_OP_SINGLE_DH_USE)))
1014 {
1015 if(!DH_generate_key(dh))
1016 {
1017 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
1018 ERR_R_DH_LIB);
1019 goto err;
1020 }
1021 }
1022 else
1023 {
1024 dh->pub_key=BN_dup(dhp->pub_key);
1025 dh->priv_key=BN_dup(dhp->priv_key);
1026 if ((dh->pub_key == NULL) ||
1027 (dh->priv_key == NULL))
1028 {
1029 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);
1030 goto err;
1031 }
1032 }
1033 r[0]=dh->p;
1034 r[1]=dh->g;
1035 r[2]=dh->pub_key;
1036 }
1037 else
1038#endif
1039 {
1040 al=SSL_AD_HANDSHAKE_FAILURE;
1041 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1042 goto f_err;
1043 }
1044 for (i=0; r[i] != NULL; i++)
1045 {
1046 nr[i]=BN_num_bytes(r[i]);
1047 n+=2+nr[i];
1048 }
1049
1050 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
1051 {
1052 if ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))
1053 == NULL)
1054 {
1055 al=SSL_AD_DECODE_ERROR;
1056 goto f_err;
1057 }
1058 kn=EVP_PKEY_size(pkey);
1059 }
1060 else
1061 {
1062 pkey=NULL;
1063 kn=0;
1064 }
1065
1066 if (!BUF_MEM_grow(buf,n+4+kn))
1067 {
1068 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);
1069 goto err;
1070 }
1071 d=(unsigned char *)s->init_buf->data;
1072 p= &(d[4]);
1073
1074 for (i=0; r[i] != NULL; i++)
1075 {
1076 s2n(nr[i],p);
1077 BN_bn2bin(r[i],p);
1078 p+=nr[i];
1079 }
1080
1081 /* not anonymous */
1082 if (pkey != NULL)
1083 {
1084 /* n is the length of the params, they start at &(d[4])
1085 * and p points to the space at the end. */
1086#ifndef NO_RSA
1087 if (pkey->type == EVP_PKEY_RSA)
1088 {
1089 q=md_buf;
1090 j=0;
1091 for (num=2; num > 0; num--)
1092 {
1093 EVP_DigestInit(&md_ctx,(num == 2)
1094 ?s->ctx->md5:s->ctx->sha1);
1095 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1096 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1097 EVP_DigestUpdate(&md_ctx,&(d[4]),n);
1098 EVP_DigestFinal(&md_ctx,q,
1099 (unsigned int *)&i);
1100 q+=i;
1101 j+=i;
1102 }
1103 if (RSA_sign(NID_md5_sha1, md_buf, j,
1104 &(p[2]), &u, pkey->pkey.rsa) <= 0)
1105 {
1106 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);
1107 goto err;
1108 }
1109 s2n(u,p);
1110 n+=u+2;
1111 }
1112 else
1113#endif
1114#if !defined(NO_DSA)
1115 if (pkey->type == EVP_PKEY_DSA)
1116 {
1117 /* lets do DSS */
1118 EVP_SignInit(&md_ctx,EVP_dss1());
1119 EVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1120 EVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1121 EVP_SignUpdate(&md_ctx,&(d[4]),n);
1122 if (!EVP_SignFinal(&md_ctx,&(p[2]),
1123 (unsigned int *)&i,pkey))
1124 {
1125 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);
1126 goto err;
1127 }
1128 s2n(i,p);
1129 n+=i+2;
1130 }
1131 else
1132#endif
1133 {
1134 /* Is this error check actually needed? */
1135 al=SSL_AD_HANDSHAKE_FAILURE;
1136 SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);
1137 goto f_err;
1138 }
1139 }
1140
1141 *(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;
1142 l2n3(n,d);
1143
1144 /* we should now have things packed up, so lets send
1145 * it off */
1146 s->init_num=n+4;
1147 s->init_off=0;
1148 }
1149
1150 s->state = SSL3_ST_SW_KEY_EXCH_B;
1151 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1152f_err:
1153 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1154err:
1155 return(-1);
1156 }
1157
1158static int ssl3_send_certificate_request(SSL *s)
1159 {
1160 unsigned char *p,*d;
1161 int i,j,nl,off,n;
1162 STACK_OF(X509_NAME) *sk=NULL;
1163 X509_NAME *name;
1164 BUF_MEM *buf;
1165
1166 if (s->state == SSL3_ST_SW_CERT_REQ_A)
1167 {
1168 buf=s->init_buf;
1169
1170 d=p=(unsigned char *)&(buf->data[4]);
1171
1172 /* get the list of acceptable cert types */
1173 p++;
1174 n=ssl3_get_req_cert_type(s,p);
1175 d[0]=n;
1176 p+=n;
1177 n++;
1178
1179 off=n;
1180 p+=2;
1181 n+=2;
1182
1183 sk=SSL_get_client_CA_list(s);
1184 nl=0;
1185 if (sk != NULL)
1186 {
1187 for (i=0; i<sk_X509_NAME_num(sk); i++)
1188 {
1189 name=sk_X509_NAME_value(sk,i);
1190 j=i2d_X509_NAME(name,NULL);
1191 if (!BUF_MEM_grow(buf,4+n+j+2))
1192 {
1193 SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB);
1194 goto err;
1195 }
1196 p=(unsigned char *)&(buf->data[4+n]);
1197 if (!(s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1198 {
1199 s2n(j,p);
1200 i2d_X509_NAME(name,&p);
1201 n+=2+j;
1202 nl+=2+j;
1203 }
1204 else
1205 {
1206 d=p;
1207 i2d_X509_NAME(name,&p);
1208 j-=2; s2n(j,d); j+=2;
1209 n+=j;
1210 nl+=j;
1211 }
1212 }
1213 }
1214 /* else no CA names */
1215 p=(unsigned char *)&(buf->data[4+off]);
1216 s2n(nl,p);
1217
1218 d=(unsigned char *)buf->data;
1219 *(d++)=SSL3_MT_CERTIFICATE_REQUEST;
1220 l2n3(n,d);
1221
1222 /* we should now have things packed up, so lets send
1223 * it off */
1224
1225 s->init_num=n+4;
1226 s->init_off=0;
1227#ifdef NETSCAPE_HANG_BUG
1228 p=(unsigned char *)s->init_buf->data + s->init_num;
1229
1230 /* do the header */
1231 *(p++)=SSL3_MT_SERVER_DONE;
1232 *(p++)=0;
1233 *(p++)=0;
1234 *(p++)=0;
1235 s->init_num += 4;
1236#endif
1237
1238 }
1239
1240 /* SSL3_ST_SW_CERT_REQ_B */
1241 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1242err:
1243 return(-1);
1244 }
1245
1246static int ssl3_get_client_key_exchange(SSL *s)
1247 {
1248 int i,al,ok;
1249 long n;
1250 unsigned long l;
1251 unsigned char *p;
1252#ifndef NO_RSA
1253 RSA *rsa=NULL;
1254 EVP_PKEY *pkey=NULL;
1255#endif
1256#ifndef NO_DH
1257 BIGNUM *pub=NULL;
1258 DH *dh_srvr;
1259#endif
1260
1261 n=ssl3_get_message(s,
1262 SSL3_ST_SR_KEY_EXCH_A,
1263 SSL3_ST_SR_KEY_EXCH_B,
1264 SSL3_MT_CLIENT_KEY_EXCHANGE,
1265 400, /* ???? */
1266 &ok);
1267
1268 if (!ok) return((int)n);
1269 p=(unsigned char *)s->init_buf->data;
1270
1271 l=s->s3->tmp.new_cipher->algorithms;
1272
1273#ifndef NO_RSA
1274 if (l & SSL_kRSA)
1275 {
1276 /* FIX THIS UP EAY EAY EAY EAY */
1277 if (s->s3->tmp.use_rsa_tmp)
1278 {
1279 if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))
1280 rsa=s->cert->rsa_tmp;
1281 /* Don't do a callback because rsa_tmp should
1282 * be sent already */
1283 if (rsa == NULL)
1284 {
1285 al=SSL_AD_HANDSHAKE_FAILURE;
1286 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
1287 goto f_err;
1288
1289 }
1290 }
1291 else
1292 {
1293 pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
1294 if ( (pkey == NULL) ||
1295 (pkey->type != EVP_PKEY_RSA) ||
1296 (pkey->pkey.rsa == NULL))
1297 {
1298 al=SSL_AD_HANDSHAKE_FAILURE;
1299 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
1300 goto f_err;
1301 }
1302 rsa=pkey->pkey.rsa;
1303 }
1304
1305 /* TLS */
1306 if (s->version > SSL3_VERSION)
1307 {
1308 n2s(p,i);
1309 if (n != i+2)
1310 {
1311 if (!(s->options & SSL_OP_TLS_D5_BUG))
1312 {
1313 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1314 goto err;
1315 }
1316 else
1317 p-=2;
1318 }
1319 else
1320 n=i;
1321 }
1322
1323 i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
1324
1325 if (i != SSL_MAX_MASTER_KEY_LENGTH)
1326 {
1327 al=SSL_AD_DECODE_ERROR;
1328 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1329 goto f_err;
1330 }
1331
1332 if (!((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))
1333 {
1334 /* The premaster secret must contain the same version number as the
1335 * ClientHello to detect version rollback attacks (strangely, the
1336 * protocol does not offer such protection for DH ciphersuites).
1337 * However, buggy clients exist that send the negotiated protocol
1338 * version instead if the server does not support the requested
1339 * protocol version.
1340 * If SSL_OP_TLS_ROLLBACK_BUG is set, tolerate such clients. */
1341 if (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&
1342 (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))
1343 {
1344 al=SSL_AD_DECODE_ERROR;
1345 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);
1346 goto f_err;
1347 }
1348 }
1349
1350 s->session->master_key_length=
1351 s->method->ssl3_enc->generate_master_secret(s,
1352 s->session->master_key,
1353 p,i);
1354 memset(p,0,i);
1355 }
1356 else
1357#endif
1358#ifndef NO_DH
1359 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1360 {
1361 n2s(p,i);
1362 if (n != i+2)
1363 {
1364 if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
1365 {
1366 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1367 goto err;
1368 }
1369 else
1370 {
1371 p-=2;
1372 i=(int)n;
1373 }
1374 }
1375
1376 if (n == 0L) /* the parameters are in the cert */
1377 {
1378 al=SSL_AD_HANDSHAKE_FAILURE;
1379 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
1380 goto f_err;
1381 }
1382 else
1383 {
1384 if (s->s3->tmp.dh == NULL)
1385 {
1386 al=SSL_AD_HANDSHAKE_FAILURE;
1387 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
1388 goto f_err;
1389 }
1390 else
1391 dh_srvr=s->s3->tmp.dh;
1392 }
1393
1394 pub=BN_bin2bn(p,i,NULL);
1395 if (pub == NULL)
1396 {
1397 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
1398 goto err;
1399 }
1400
1401 i=DH_compute_key(p,pub,dh_srvr);
1402
1403 if (i <= 0)
1404 {
1405 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1406 goto err;
1407 }
1408
1409 DH_free(s->s3->tmp.dh);
1410 s->s3->tmp.dh=NULL;
1411
1412 BN_clear_free(pub);
1413 pub=NULL;
1414 s->session->master_key_length=
1415 s->method->ssl3_enc->generate_master_secret(s,
1416 s->session->master_key,p,i);
1417 memset(p,0,i);
1418 }
1419 else
1420#endif
1421 {
1422 al=SSL_AD_HANDSHAKE_FAILURE;
1423 SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);
1424 goto f_err;
1425 }
1426
1427 return(1);
1428f_err:
1429 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1430#if !defined(NO_DH) || !defined(NO_RSA)
1431err:
1432#endif
1433 return(-1);
1434 }
1435
1436static int ssl3_get_cert_verify(SSL *s)
1437 {
1438 EVP_PKEY *pkey=NULL;
1439 unsigned char *p;
1440 int al,ok,ret=0;
1441 long n;
1442 int type=0,i,j;
1443 X509 *peer;
1444
1445 n=ssl3_get_message(s,
1446 SSL3_ST_SR_CERT_VRFY_A,
1447 SSL3_ST_SR_CERT_VRFY_B,
1448 -1,
1449 512, /* 512? */
1450 &ok);
1451
1452 if (!ok) return((int)n);
1453
1454 if (s->session->peer != NULL)
1455 {
1456 peer=s->session->peer;
1457 pkey=X509_get_pubkey(peer);
1458 type=X509_certificate_type(peer,pkey);
1459 }
1460 else
1461 {
1462 peer=NULL;
1463 pkey=NULL;
1464 }
1465
1466 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY)
1467 {
1468 s->s3->tmp.reuse_message=1;
1469 if ((peer != NULL) && (type | EVP_PKT_SIGN))
1470 {
1471 al=SSL_AD_UNEXPECTED_MESSAGE;
1472 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_MISSING_VERIFY_MESSAGE);
1473 goto f_err;
1474 }
1475 ret=1;
1476 goto end;
1477 }
1478
1479 if (peer == NULL)
1480 {
1481 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_NO_CLIENT_CERT_RECEIVED);
1482 al=SSL_AD_UNEXPECTED_MESSAGE;
1483 goto f_err;
1484 }
1485
1486 if (!(type & EVP_PKT_SIGN))
1487 {
1488 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1489 al=SSL_AD_ILLEGAL_PARAMETER;
1490 goto f_err;
1491 }
1492
1493 if (s->s3->change_cipher_spec)
1494 {
1495 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_CCS_RECEIVED_EARLY);
1496 al=SSL_AD_UNEXPECTED_MESSAGE;
1497 goto f_err;
1498 }
1499
1500 /* we now have a signature that we need to verify */
1501 p=(unsigned char *)s->init_buf->data;
1502 n2s(p,i);
1503 n-=2;
1504 if (i > n)
1505 {
1506 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_LENGTH_MISMATCH);
1507 al=SSL_AD_DECODE_ERROR;
1508 goto f_err;
1509 }
1510
1511 j=EVP_PKEY_size(pkey);
1512 if ((i > j) || (n > j) || (n <= 0))
1513 {
1514 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_WRONG_SIGNATURE_SIZE);
1515 al=SSL_AD_DECODE_ERROR;
1516 goto f_err;
1517 }
1518
1519#ifndef NO_RSA
1520 if (pkey->type == EVP_PKEY_RSA)
1521 {
1522 i=RSA_verify(NID_md5_sha1, s->s3->tmp.cert_verify_md,
1523 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH, p, i,
1524 pkey->pkey.rsa);
1525 if (i < 0)
1526 {
1527 al=SSL_AD_DECRYPT_ERROR;
1528 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_DECRYPT);
1529 goto f_err;
1530 }
1531 if (i == 0)
1532 {
1533 al=SSL_AD_DECRYPT_ERROR;
1534 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_RSA_SIGNATURE);
1535 goto f_err;
1536 }
1537 }
1538 else
1539#endif
1540#ifndef NO_DSA
1541 if (pkey->type == EVP_PKEY_DSA)
1542 {
1543 j=DSA_verify(pkey->save_type,
1544 &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]),
1545 SHA_DIGEST_LENGTH,p,i,pkey->pkey.dsa);
1546 if (j <= 0)
1547 {
1548 /* bad signature */
1549 al=SSL_AD_DECRYPT_ERROR;
1550 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_BAD_DSA_SIGNATURE);
1551 goto f_err;
1552 }
1553 }
1554 else
1555#endif
1556 {
1557 SSLerr(SSL_F_SSL3_GET_CERT_VERIFY,SSL_R_INTERNAL_ERROR);
1558 al=SSL_AD_UNSUPPORTED_CERTIFICATE;
1559 goto f_err;
1560 }
1561
1562
1563 ret=1;
1564 if (0)
1565 {
1566f_err:
1567 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1568 }
1569end:
1570 EVP_PKEY_free(pkey);
1571 return(ret);
1572 }
1573
1574static int ssl3_get_client_certificate(SSL *s)
1575 {
1576 int i,ok,al,ret= -1;
1577 X509 *x=NULL;
1578 unsigned long l,nc,llen,n;
1579 unsigned char *p,*d,*q;
1580 STACK_OF(X509) *sk=NULL;
1581
1582 n=ssl3_get_message(s,
1583 SSL3_ST_SR_CERT_A,
1584 SSL3_ST_SR_CERT_B,
1585 -1,
1586#if defined(MSDOS) && !defined(WIN32)
1587 1024*30, /* 30k max cert list :-) */
1588#else
1589 1024*100, /* 100k max cert list :-) */
1590#endif
1591 &ok);
1592
1593 if (!ok) return((int)n);
1594
1595 if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)
1596 {
1597 if ( (s->verify_mode & SSL_VERIFY_PEER) &&
1598 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1599 {
1600 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1601 al=SSL_AD_HANDSHAKE_FAILURE;
1602 goto f_err;
1603 }
1604 /* If tls asked for a client cert, the client must return a 0 list */
1605 if ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)
1606 {
1607 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
1608 al=SSL_AD_UNEXPECTED_MESSAGE;
1609 goto f_err;
1610 }
1611 s->s3->tmp.reuse_message=1;
1612 return(1);
1613 }
1614
1615 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
1616 {
1617 al=SSL_AD_UNEXPECTED_MESSAGE;
1618 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);
1619 goto f_err;
1620 }
1621 d=p=(unsigned char *)s->init_buf->data;
1622
1623 if ((sk=sk_X509_new_null()) == NULL)
1624 {
1625 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1626 goto err;
1627 }
1628
1629 n2l3(p,llen);
1630 if (llen+3 != n)
1631 {
1632 al=SSL_AD_DECODE_ERROR;
1633 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
1634 goto f_err;
1635 }
1636 for (nc=0; nc<llen; )
1637 {
1638 n2l3(p,l);
1639 if ((l+nc+3) > llen)
1640 {
1641 al=SSL_AD_DECODE_ERROR;
1642 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1643 goto f_err;
1644 }
1645
1646 q=p;
1647 x=d2i_X509(NULL,&p,l);
1648 if (x == NULL)
1649 {
1650 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);
1651 goto err;
1652 }
1653 if (p != (q+l))
1654 {
1655 al=SSL_AD_DECODE_ERROR;
1656 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
1657 goto f_err;
1658 }
1659 if (!sk_X509_push(sk,x))
1660 {
1661 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);
1662 goto err;
1663 }
1664 x=NULL;
1665 nc+=l+3;
1666 }
1667
1668 if (sk_X509_num(sk) <= 0)
1669 {
1670 /* TLS does not mind 0 certs returned */
1671 if (s->version == SSL3_VERSION)
1672 {
1673 al=SSL_AD_HANDSHAKE_FAILURE;
1674 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);
1675 goto f_err;
1676 }
1677 /* Fail for TLS only if we required a certificate */
1678 else if ((s->verify_mode & SSL_VERIFY_PEER) &&
1679 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
1680 {
1681 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1682 al=SSL_AD_HANDSHAKE_FAILURE;
1683 goto f_err;
1684 }
1685 }
1686 else
1687 {
1688 i=ssl_verify_cert_chain(s,sk);
1689 if (!i)
1690 {
1691 al=ssl_verify_alarm_type(s->verify_result);
1692 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);
1693 goto f_err;
1694 }
1695 }
1696
1697 if (s->session->peer != NULL) /* This should not be needed */
1698 X509_free(s->session->peer);
1699 s->session->peer=sk_X509_shift(sk);
1700 s->session->verify_result = s->verify_result;
1701
1702 /* With the current implementation, sess_cert will always be NULL
1703 * when we arrive here. */
1704 if (s->session->sess_cert == NULL)
1705 {
1706 s->session->sess_cert = ssl_sess_cert_new();
1707 if (s->session->sess_cert == NULL)
1708 {
1709 SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE);
1710 goto err;
1711 }
1712 }
1713 if (s->session->sess_cert->cert_chain != NULL)
1714 sk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free);
1715 s->session->sess_cert->cert_chain=sk;
1716 /* Inconsistency alert: cert_chain does *not* include the
1717 * peer's own certificate, while we do include it in s3_clnt.c */
1718
1719 sk=NULL;
1720
1721 ret=1;
1722 if (0)
1723 {
1724f_err:
1725 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1726 }
1727err:
1728 if (x != NULL) X509_free(x);
1729 if (sk != NULL) sk_X509_pop_free(sk,X509_free);
1730 return(ret);
1731 }
1732
1733int ssl3_send_server_certificate(SSL *s)
1734 {
1735 unsigned long l;
1736 X509 *x;
1737
1738 if (s->state == SSL3_ST_SW_CERT_A)
1739 {
1740 x=ssl_get_server_send_cert(s);
1741 if (x == NULL)
1742 {
1743 SSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,SSL_R_INTERNAL_ERROR);
1744 return(0);
1745 }
1746
1747 l=ssl3_output_cert_chain(s,x);
1748 s->state=SSL3_ST_SW_CERT_B;
1749 s->init_num=(int)l;
1750 s->init_off=0;
1751 }
1752
1753 /* SSL3_ST_SW_CERT_B */
1754 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1755 }
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version
deleted file mode 100644
index 890c57389b..0000000000
--- a/src/lib/libssl/shlib_version
+++ /dev/null
@@ -1,2 +0,0 @@
1major=4
2minor=1
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index fdbdc70ba7..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1562 +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#ifndef NO_COMP
63#include <openssl/comp.h>
64#endif
65#ifndef NO_BIO
66#include <openssl/bio.h>
67#endif
68#ifndef NO_X509
69#include <openssl/x509.h>
70#endif
71#include <openssl/safestack.h>
72
73#ifdef __cplusplus
74extern "C" {
75#endif
76
77/* SSLeay version number for ASN.1 encoding of the session information */
78/* Version 0 - initial version
79 * Version 1 - added the optional peer certificate
80 */
81#define SSL_SESSION_ASN1_VERSION 0x0001
82
83/* text strings for the ciphers */
84#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
85#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
86#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
87#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
88#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
89#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
90#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
91#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
92#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
93#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
94
95#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
96#define SSL_MAX_SID_CTX_LENGTH 32
97
98#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
99#define SSL_MAX_KEY_ARG_LENGTH 8
100#define SSL_MAX_MASTER_KEY_LENGTH 48
101
102/* These are used to specify which ciphers to use and not to use */
103#define SSL_TXT_LOW "LOW"
104#define SSL_TXT_MEDIUM "MEDIUM"
105#define SSL_TXT_HIGH "HIGH"
106#define SSL_TXT_kFZA "kFZA"
107#define SSL_TXT_aFZA "aFZA"
108#define SSL_TXT_eFZA "eFZA"
109#define SSL_TXT_FZA "FZA"
110
111#define SSL_TXT_aNULL "aNULL"
112#define SSL_TXT_eNULL "eNULL"
113#define SSL_TXT_NULL "NULL"
114
115#define SSL_TXT_kRSA "kRSA"
116#define SSL_TXT_kDHr "kDHr"
117#define SSL_TXT_kDHd "kDHd"
118#define SSL_TXT_kEDH "kEDH"
119#define SSL_TXT_aRSA "aRSA"
120#define SSL_TXT_aDSS "aDSS"
121#define SSL_TXT_aDH "aDH"
122#define SSL_TXT_DSS "DSS"
123#define SSL_TXT_DH "DH"
124#define SSL_TXT_EDH "EDH"
125#define SSL_TXT_ADH "ADH"
126#define SSL_TXT_RSA "RSA"
127#define SSL_TXT_DES "DES"
128#define SSL_TXT_3DES "3DES"
129#define SSL_TXT_RC4 "RC4"
130#define SSL_TXT_RC2 "RC2"
131#define SSL_TXT_IDEA "IDEA"
132#define SSL_TXT_MD5 "MD5"
133#define SSL_TXT_SHA1 "SHA1"
134#define SSL_TXT_SHA "SHA"
135#define SSL_TXT_EXP "EXP"
136#define SSL_TXT_EXPORT "EXPORT"
137#define SSL_TXT_EXP40 "EXPORT40"
138#define SSL_TXT_EXP56 "EXPORT56"
139#define SSL_TXT_SSLV2 "SSLv2"
140#define SSL_TXT_SSLV3 "SSLv3"
141#define SSL_TXT_TLSV1 "TLSv1"
142#define SSL_TXT_ALL "ALL"
143
144/* 'DEFAULT' at the start of the cipher list insert the following string
145 * in addition to this being the default cipher string */
146#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH"
147
148/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
149#define SSL_SENT_SHUTDOWN 1
150#define SSL_RECEIVED_SHUTDOWN 2
151
152#ifdef __cplusplus
153}
154#endif
155
156#include <openssl/crypto.h>
157#include <openssl/lhash.h>
158#include <openssl/buffer.h>
159#include <openssl/bio.h>
160#include <openssl/pem.h>
161#include <openssl/x509.h>
162
163#ifdef __cplusplus
164extern "C" {
165#endif
166
167#if (defined(NO_RSA) || defined(NO_MD5)) && !defined(NO_SSL2)
168#define NO_SSL2
169#endif
170
171#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
172#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
173
174/* This is needed to stop compilers complaining about the
175 * 'struct ssl_st *' function parameters used to prototype callbacks
176 * in SSL_CTX. */
177typedef struct ssl_st *ssl_crock_st;
178
179/* used to hold info on the particular ciphers used */
180typedef struct ssl_cipher_st
181 {
182 int valid;
183 const char *name; /* text name */
184 unsigned long id; /* id, 4 bytes, first is version */
185 unsigned long algorithms; /* what ciphers are used */
186 unsigned long algo_strength; /* strength and export flags */
187 unsigned long algorithm2; /* Extra flags */
188 int strength_bits; /* Number of bits really used */
189 int alg_bits; /* Number of bits for algorithm */
190 unsigned long mask; /* used for matching */
191 unsigned long mask_strength; /* also used for matching */
192 } SSL_CIPHER;
193
194DECLARE_STACK_OF(SSL_CIPHER)
195
196typedef struct ssl_st SSL;
197typedef struct ssl_ctx_st SSL_CTX;
198
199/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
200typedef struct ssl_method_st
201 {
202 int version;
203 int (*ssl_new)(SSL *s);
204 void (*ssl_clear)(SSL *s);
205 void (*ssl_free)(SSL *s);
206 int (*ssl_accept)(SSL *s);
207 int (*ssl_connect)(SSL *s);
208 int (*ssl_read)(SSL *s,void *buf,int len);
209 int (*ssl_peek)(SSL *s,char *buf,int len);
210 int (*ssl_write)(SSL *s,const void *buf,int len);
211 int (*ssl_shutdown)(SSL *s);
212 int (*ssl_renegotiate)(SSL *s);
213 int (*ssl_renegotiate_check)(SSL *s);
214 long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg);
215 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg);
216 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
217 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
218 int (*ssl_pending)(SSL *s);
219 int (*num_ciphers)(void);
220 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
221 struct ssl_method_st *(*get_ssl_method)(int version);
222 long (*get_timeout)(void);
223 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
224 int (*ssl_version)();
225 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)());
226 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)());
227 } SSL_METHOD;
228
229/* Lets make this into an ASN.1 type structure as follows
230 * SSL_SESSION_ID ::= SEQUENCE {
231 * version INTEGER, -- structure version number
232 * SSLversion INTEGER, -- SSL version number
233 * Cipher OCTET_STRING, -- the 3 byte cipher ID
234 * Session_ID OCTET_STRING, -- the Session ID
235 * Master_key OCTET_STRING, -- the master key
236 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
237 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
238 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
239 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
240 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
241 * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer'
242 * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
243 * }
244 * Look in ssl/ssl_asn1.c for more details
245 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
246 */
247typedef struct ssl_session_st
248 {
249 int ssl_version; /* what ssl version session info is
250 * being kept in here? */
251
252 /* only really used in SSLv2 */
253 unsigned int key_arg_length;
254 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
255 int master_key_length;
256 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
257 /* session_id - valid? */
258 unsigned int session_id_length;
259 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
260 /* this is used to determine whether the session is being reused in
261 * the appropriate context. It is up to the application to set this,
262 * via SSL_new */
263 unsigned int sid_ctx_length;
264 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
265
266 int not_resumable;
267
268 /* The cert is the certificate used to establish this connection */
269 struct sess_cert_st /* SESS_CERT */ *sess_cert;
270
271 /* This is the cert for the other end.
272 * On clients, it will be the same as sess_cert->peer_key->x509
273 * (the latter is not enough as sess_cert is not retained
274 * in the external representation of sessions, see ssl_asn1.c). */
275 X509 *peer;
276 /* when app_verify_callback accepts a session where the peer's certificate
277 * is not ok, we must remember the error for session reuse: */
278 long verify_result; /* only for servers */
279
280 int references;
281 long timeout;
282 long time;
283
284 int compress_meth; /* Need to lookup the method */
285
286 SSL_CIPHER *cipher;
287 unsigned long cipher_id; /* when ASN.1 loaded, this
288 * needs to be used to load
289 * the 'cipher' structure */
290
291 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
292
293 CRYPTO_EX_DATA ex_data; /* application specific data */
294
295 /* These are used to make removal of session-ids more
296 * efficient and to implement a maximum cache size. */
297 struct ssl_session_st *prev,*next;
298 } SSL_SESSION;
299
300#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
301#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
302#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
303#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
304#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
305#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
306#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
307#define SSL_OP_TLS_D5_BUG 0x00000100L
308#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
309#define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L
310
311/* If set, always create a new key when using tmp_dh parameters */
312#define SSL_OP_SINGLE_DH_USE 0x00100000L
313/* Set to also use the tmp_rsa key when doing RSA operations. */
314#define SSL_OP_EPHEMERAL_RSA 0x00200000L
315
316/* The next flag deliberately changes the ciphertest, this is a check
317 * for the PKCS#1 attack */
318#define SSL_OP_PKCS1_CHECK_1 0x08000000L
319#define SSL_OP_PKCS1_CHECK_2 0x10000000L
320#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
321/* SSL_OP_NON_EXPORT_FIRST looks utterly broken .. */
322#define SSL_OP_NON_EXPORT_FIRST 0x40000000L
323#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L
324#define SSL_OP_ALL 0x000FFFFFL
325
326#define SSL_OP_NO_SSLv2 0x01000000L
327#define SSL_OP_NO_SSLv3 0x02000000L
328#define SSL_OP_NO_TLSv1 0x04000000L
329
330/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
331 * when just a single record has been written): */
332#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
333/* Make it possible to retry SSL_write() with changed buffer location
334 * (buffer contents must stay the same!); this is not the default to avoid
335 * the misconception that non-blocking SSL_write() behaves like
336 * non-blocking write(): */
337#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
338/* Never bother the application with retries if the transport
339 * is blocking: */
340#define SSL_MODE_AUTO_RETRY 0x00000004L
341
342/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
343 * they cannot be used to clear bits. */
344
345#define SSL_CTX_set_options(ctx,op) \
346 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL)
347#define SSL_CTX_get_options(ctx) \
348 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL)
349#define SSL_set_options(ssl,op) \
350 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL)
351#define SSL_get_options(ssl) \
352 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL)
353
354#define SSL_CTX_set_mode(ctx,op) \
355 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL)
356#define SSL_CTX_get_mode(ctx) \
357 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL)
358#define SSL_set_mode(ssl,op) \
359 SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL)
360#define SSL_get_mode(ssl) \
361 SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL)
362
363#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
364
365typedef struct ssl_comp_st
366 {
367 int id;
368 char *name;
369#ifndef NO_COMP
370 COMP_METHOD *method;
371#else
372 char *method;
373#endif
374 } SSL_COMP;
375
376DECLARE_STACK_OF(SSL_COMP)
377
378struct ssl_ctx_st
379 {
380 SSL_METHOD *method;
381 unsigned long options;
382 unsigned long mode;
383
384 STACK_OF(SSL_CIPHER) *cipher_list;
385 /* same as above but sorted for lookup */
386 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
387
388 struct x509_store_st /* X509_STORE */ *cert_store;
389 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */
390 /* Most session-ids that will be cached, default is
391 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
392 unsigned long session_cache_size;
393 struct ssl_session_st *session_cache_head;
394 struct ssl_session_st *session_cache_tail;
395
396 /* This can have one of 2 values, ored together,
397 * SSL_SESS_CACHE_CLIENT,
398 * SSL_SESS_CACHE_SERVER,
399 * Default is SSL_SESSION_CACHE_SERVER, which means only
400 * SSL_accept which cache SSL_SESSIONS. */
401 int session_cache_mode;
402
403 /* If timeout is not 0, it is the default timeout value set
404 * when SSL_new() is called. This has been put in to make
405 * life easier to set things up */
406 long session_timeout;
407
408 /* If this callback is not null, it will be called each
409 * time a session id is added to the cache. If this function
410 * returns 1, it means that the callback will do a
411 * SSL_SESSION_free() when it has finished using it. Otherwise,
412 * on 0, it means the callback has finished with it.
413 * If remove_session_cb is not null, it will be called when
414 * a session-id is removed from the cache. After the call,
415 * OpenSSL will SSL_SESSION_free() it. */
416 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
417 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
418 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
419 unsigned char *data,int len,int *copy);
420 struct
421 {
422 int sess_connect; /* SSL new conn - started */
423 int sess_connect_renegotiate;/* SSL reneg - requested */
424 int sess_connect_good; /* SSL new conne/reneg - finished */
425 int sess_accept; /* SSL new accept - started */
426 int sess_accept_renegotiate;/* SSL reneg - requested */
427 int sess_accept_good; /* SSL accept/reneg - finished */
428 int sess_miss; /* session lookup misses */
429 int sess_timeout; /* reuse attempt on timeouted session */
430 int sess_cache_full; /* session removed due to full cache */
431 int sess_hit; /* session reuse actually done */
432 int sess_cb_hit; /* session-id that was not
433 * in the cache was
434 * passed back via the callback. This
435 * indicates that the application is
436 * supplying session-id's from other
437 * processes - spooky :-) */
438 } stats;
439
440 int references;
441
442/**/ void (*info_callback)();
443
444 /* if defined, these override the X509_verify_cert() calls */
445/**/ int (*app_verify_callback)();
446/**/ char *app_verify_arg; /* never used; should be void * */
447
448 /* default values to use in SSL structures */
449/**/ struct cert_st /* CERT */ *cert;
450/**/ int read_ahead;
451/**/ int verify_mode;
452/**/ int verify_depth;
453/**/ unsigned int sid_ctx_length;
454/**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
455/**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx);
456
457 int purpose; /* Purpose setting */
458 int trust; /* Trust setting */
459
460 /* Default password callback. */
461/**/ pem_password_cb *default_passwd_callback;
462
463 /* Default password callback user data. */
464/**/ void *default_passwd_callback_userdata;
465
466 /* get client cert callback */
467/**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
468
469 /* what we put in client cert requests */
470 STACK_OF(X509_NAME) *client_CA;
471
472/**/ int quiet_shutdown;
473
474 CRYPTO_EX_DATA ex_data;
475
476 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
477 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
478 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
479
480 STACK_OF(X509) *extra_certs;
481 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
482 };
483
484#define SSL_SESS_CACHE_OFF 0x0000
485#define SSL_SESS_CACHE_CLIENT 0x0001
486#define SSL_SESS_CACHE_SERVER 0x0002
487#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
488#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
489/* This one, when set, makes the server session-id lookup not look
490 * in the cache. If there is an application get_session callback
491 * defined, this will still get called. */
492#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
493
494 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
495#define SSL_CTX_sess_number(ctx) \
496 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
497#define SSL_CTX_sess_connect(ctx) \
498 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
499#define SSL_CTX_sess_connect_good(ctx) \
500 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
501#define SSL_CTX_sess_connect_renegotiate(ctx) \
502 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
503#define SSL_CTX_sess_accept(ctx) \
504 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
505#define SSL_CTX_sess_accept_renegotiate(ctx) \
506 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
507#define SSL_CTX_sess_accept_good(ctx) \
508 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
509#define SSL_CTX_sess_hits(ctx) \
510 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
511#define SSL_CTX_sess_cb_hits(ctx) \
512 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
513#define SSL_CTX_sess_misses(ctx) \
514 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
515#define SSL_CTX_sess_timeouts(ctx) \
516 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
517#define SSL_CTX_sess_cache_full(ctx) \
518 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
519
520#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
521#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
522#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
523#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
524#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
525#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
526#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
527#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
528#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
529#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
530
531#define SSL_NOTHING 1
532#define SSL_WRITING 2
533#define SSL_READING 3
534#define SSL_X509_LOOKUP 4
535
536/* These will only be used when doing non-blocking IO */
537#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
538#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
539#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
540#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
541
542struct ssl_st
543 {
544 /* protocol version
545 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
546 */
547 int version;
548 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
549
550 SSL_METHOD *method; /* SSLv3 */
551
552 /* There are 2 BIO's even though they are normally both the
553 * same. This is so data can be read and written to different
554 * handlers */
555
556#ifndef NO_BIO
557 BIO *rbio; /* used by SSL_read */
558 BIO *wbio; /* used by SSL_write */
559 BIO *bbio; /* used during session-id reuse to concatenate
560 * messages */
561#else
562 char *rbio; /* used by SSL_read */
563 char *wbio; /* used by SSL_write */
564 char *bbio;
565#endif
566 /* This holds a variable that indicates what we were doing
567 * when a 0 or -1 is returned. This is needed for
568 * non-blocking IO so we know what request needs re-doing when
569 * in SSL_accept or SSL_connect */
570 int rwstate;
571
572 /* true when we are actually in SSL_accept() or SSL_connect() */
573 int in_handshake;
574 int (*handshake_func)();
575
576 /* Imagine that here's a boolean member "init" that is
577 * switched as soon as SSL_set_{accept/connect}_state
578 * is called for the first time, so that "state" and
579 * "handshake_func" are properly initialized. But as
580 * handshake_func is == 0 until then, we use this
581 * test instead of an "init" member.
582 */
583
584 int server; /* are we the server side? - mostly used by SSL_clear*/
585
586 int new_session;/* 1 if we are to use a new session */
587 int quiet_shutdown;/* don't send shutdown packets */
588 int shutdown; /* we have shut things down, 0x01 sent, 0x02
589 * for received */
590 int state; /* where we are */
591 int rstate; /* where we are when reading */
592
593 BUF_MEM *init_buf; /* buffer used during init */
594 int init_num; /* amount read/written */
595 int init_off; /* amount read/written */
596
597 /* used internally to point at a raw packet */
598 unsigned char *packet;
599 unsigned int packet_length;
600
601 struct ssl2_state_st *s2; /* SSLv2 variables */
602 struct ssl3_state_st *s3; /* SSLv3 variables */
603
604 int read_ahead; /* Read as many input bytes as possible
605 * (for non-blocking reads) */
606 int hit; /* reusing a previous session */
607
608 int purpose; /* Purpose setting */
609 int trust; /* Trust setting */
610
611 /* crypto */
612 STACK_OF(SSL_CIPHER) *cipher_list;
613 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
614
615 /* These are the ones being used, the ones in SSL_SESSION are
616 * the ones to be 'copied' into these ones */
617
618 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
619 const EVP_MD *read_hash; /* used for mac generation */
620#ifndef NO_COMP
621 COMP_CTX *expand; /* uncompress */
622#else
623 char *expand;
624#endif
625
626 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
627 const EVP_MD *write_hash; /* used for mac generation */
628#ifndef NO_COMP
629 COMP_CTX *compress; /* compression */
630#else
631 char *compress;
632#endif
633
634 /* session info */
635
636 /* client cert? */
637 /* This is used to hold the server certificate used */
638 struct cert_st /* CERT */ *cert;
639
640 /* the session_id_context is used to ensure sessions are only reused
641 * in the appropriate context */
642 unsigned int sid_ctx_length;
643 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
644
645 /* This can also be in the session once a session is established */
646 SSL_SESSION *session;
647
648 /* Used in SSL2 and SSL3 */
649 int verify_mode; /* 0 don't care about verify failure.
650 * 1 fail if verify fails */
651 int verify_depth;
652 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
653 void (*info_callback)(); /* optional informational callback */
654
655 int error; /* error bytes to be written */
656 int error_code; /* actual code */
657
658 SSL_CTX *ctx;
659 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
660 * and SSL_write() calls, good for nbio debuging :-) */
661 int debug;
662
663 /* extra application data */
664 long verify_result;
665 CRYPTO_EX_DATA ex_data;
666
667 /* for server side, keep the list of CA_dn we can use */
668 STACK_OF(X509_NAME) *client_CA;
669
670 int references;
671 unsigned long options; /* protocol behaviour */
672 unsigned long mode; /* API behaviour */
673 int first_packet;
674 int client_version; /* what was passed, used for
675 * SSLv3/TLS rollback check */
676 };
677
678#ifdef __cplusplus
679}
680#endif
681
682#include <openssl/ssl2.h>
683#include <openssl/ssl3.h>
684#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
685#include <openssl/ssl23.h>
686
687#ifdef __cplusplus
688extern "C" {
689#endif
690
691/* compatibility */
692#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
693#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
694#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
695#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
696#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
697#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
698
699/* The following are the possible values for ssl->state are are
700 * used to indicate where we are up to in the SSL connection establishment.
701 * The macros that follow are about the only things you should need to use
702 * and even then, only when using non-blocking IO.
703 * It can also be useful to work out where you were when the connection
704 * failed */
705
706#define SSL_ST_CONNECT 0x1000
707#define SSL_ST_ACCEPT 0x2000
708#define SSL_ST_MASK 0x0FFF
709#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
710#define SSL_ST_BEFORE 0x4000
711#define SSL_ST_OK 0x03
712#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
713
714#define SSL_CB_LOOP 0x01
715#define SSL_CB_EXIT 0x02
716#define SSL_CB_READ 0x04
717#define SSL_CB_WRITE 0x08
718#define SSL_CB_ALERT 0x4000 /* used in callback */
719#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
720#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
721#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
722#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
723#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
724#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
725#define SSL_CB_HANDSHAKE_START 0x10
726#define SSL_CB_HANDSHAKE_DONE 0x20
727
728/* Is the SSL_connection established? */
729#define SSL_get_state(a) SSL_state(a)
730#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
731#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
732#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
733#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
734#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
735
736/* The following 2 states are kept in ssl->rstate when reads fail,
737 * you should not need these */
738#define SSL_ST_READ_HEADER 0xF0
739#define SSL_ST_READ_BODY 0xF1
740#define SSL_ST_READ_DONE 0xF2
741
742/* Obtain latest Finished message
743 * -- that we sent (SSL_get_finished)
744 * -- that we expected from peer (SSL_get_peer_finished).
745 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
746size_t SSL_get_finished(SSL *s, void *buf, size_t count);
747size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);
748
749/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
750 * are 'ored' with SSL_VERIFY_PEER if they are desired */
751#define SSL_VERIFY_NONE 0x00
752#define SSL_VERIFY_PEER 0x01
753#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
754#define SSL_VERIFY_CLIENT_ONCE 0x04
755
756#define OpenSSL_add_ssl_algorithms() SSL_library_init()
757#define SSLeay_add_ssl_algorithms() SSL_library_init()
758
759/* this is for backward compatibility */
760#if 0 /* NEW_SSLEAY */
761#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
762#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
763#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
764#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
765#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
766#endif
767/* More backward compatibility */
768#define SSL_get_cipher(s) \
769 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
770#define SSL_get_cipher_bits(s,np) \
771 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
772#define SSL_get_cipher_version(s) \
773 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
774#define SSL_get_cipher_name(s) \
775 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
776#define SSL_get_time(a) SSL_SESSION_get_time(a)
777#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
778#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
779#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
780
781#if 1 /*SSLEAY_MACROS*/
782#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
783 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
784 (bp),(unsigned char **)(s_id))
785#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
786 bp,(unsigned char *)s_id)
787#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
788 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
789#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
790 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
791#define PEM_write_SSL_SESSION(fp,x) \
792 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
793 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
794#define PEM_write_bio_SSL_SESSION(bp,x) \
795 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
796 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
797#endif
798
799#define SSL_AD_REASON_OFFSET 1000
800/* These alert types are for SSLv3 and TLSv1 */
801#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
802#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
803#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
804#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
805#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
806#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
807#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
808#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
809#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
810#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
811#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
812#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
813#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
814#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
815#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
816#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
817#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
818#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
819#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
820#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
821#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
822#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
823#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
824#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
825
826#define SSL_ERROR_NONE 0
827#define SSL_ERROR_SSL 1
828#define SSL_ERROR_WANT_READ 2
829#define SSL_ERROR_WANT_WRITE 3
830#define SSL_ERROR_WANT_X509_LOOKUP 4
831#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
832#define SSL_ERROR_ZERO_RETURN 6
833#define SSL_ERROR_WANT_CONNECT 7
834
835#define SSL_CTRL_NEED_TMP_RSA 1
836#define SSL_CTRL_SET_TMP_RSA 2
837#define SSL_CTRL_SET_TMP_DH 3
838#define SSL_CTRL_SET_TMP_RSA_CB 4
839#define SSL_CTRL_SET_TMP_DH_CB 5
840/* Add these ones */
841#define SSL_CTRL_GET_SESSION_REUSED 6
842#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
843#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
844#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
845#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
846#define SSL_CTRL_GET_FLAGS 11
847#define SSL_CTRL_EXTRA_CHAIN_CERT 12
848
849/* Stats */
850#define SSL_CTRL_SESS_NUMBER 20
851#define SSL_CTRL_SESS_CONNECT 21
852#define SSL_CTRL_SESS_CONNECT_GOOD 22
853#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
854#define SSL_CTRL_SESS_ACCEPT 24
855#define SSL_CTRL_SESS_ACCEPT_GOOD 25
856#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
857#define SSL_CTRL_SESS_HIT 27
858#define SSL_CTRL_SESS_CB_HIT 28
859#define SSL_CTRL_SESS_MISSES 29
860#define SSL_CTRL_SESS_TIMEOUTS 30
861#define SSL_CTRL_SESS_CACHE_FULL 31
862#define SSL_CTRL_OPTIONS 32
863#define SSL_CTRL_MODE 33
864
865#define SSL_CTRL_GET_READ_AHEAD 40
866#define SSL_CTRL_SET_READ_AHEAD 41
867#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
868#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
869#define SSL_CTRL_SET_SESS_CACHE_MODE 44
870#define SSL_CTRL_GET_SESS_CACHE_MODE 45
871
872#define SSL_session_reused(ssl) \
873 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
874#define SSL_num_renegotiations(ssl) \
875 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
876#define SSL_clear_num_renegotiations(ssl) \
877 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
878#define SSL_total_renegotiations(ssl) \
879 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
880
881#define SSL_CTX_need_tmp_RSA(ctx) \
882 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
883#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
884 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
885#define SSL_CTX_set_tmp_dh(ctx,dh) \
886 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
887
888#define SSL_need_tmp_RSA(ssl) \
889 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
890#define SSL_set_tmp_rsa(ssl,rsa) \
891 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
892#define SSL_set_tmp_dh(ssl,dh) \
893 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
894
895#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
896 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
897
898/* VMS uses only 31 characters for symbols. */
899#ifdef VMS
900#undef SSL_CTX_set_cert_verify_callback
901#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
902#undef SSL_CTX_use_certificate_chain_file
903#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
904#undef SSL_CTX_set_default_verify_paths
905#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
906#undef SSL_get_ex_data_X509_STORE_CTX_idx
907#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i
908#undef SSL_add_file_cert_subjects_to_stack
909#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack
910#undef SSL_add_dir_cert_subjects_to_stack
911#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
912#endif
913
914#ifndef NO_BIO
915BIO_METHOD *BIO_f_ssl(void);
916BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
917BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
918BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
919int BIO_ssl_copy_session_id(BIO *to,BIO *from);
920void BIO_ssl_shutdown(BIO *ssl_bio);
921
922#endif
923
924int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
925SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
926void SSL_CTX_free(SSL_CTX *);
927long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
928long SSL_CTX_get_timeout(SSL_CTX *ctx);
929X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *);
930void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
931int SSL_want(SSL *s);
932int SSL_clear(SSL *s);
933
934void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
935
936SSL_CIPHER *SSL_get_current_cipher(SSL *s);
937int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
938char * SSL_CIPHER_get_version(SSL_CIPHER *c);
939const char * SSL_CIPHER_get_name(SSL_CIPHER *c);
940
941int SSL_get_fd(SSL *s);
942const char * SSL_get_cipher_list(SSL *s,int n);
943char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
944int SSL_get_read_ahead(SSL * s);
945int SSL_pending(SSL *s);
946#ifndef NO_SOCK
947int SSL_set_fd(SSL *s, int fd);
948int SSL_set_rfd(SSL *s, int fd);
949int SSL_set_wfd(SSL *s, int fd);
950#endif
951#ifndef NO_BIO
952void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
953BIO * SSL_get_rbio(SSL *s);
954BIO * SSL_get_wbio(SSL *s);
955#endif
956int SSL_set_cipher_list(SSL *s, const char *str);
957void SSL_set_read_ahead(SSL *s, int yes);
958int SSL_get_verify_mode(SSL *s);
959int SSL_get_verify_depth(SSL *s);
960int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
961void SSL_set_verify(SSL *s, int mode,
962 int (*callback)(int ok,X509_STORE_CTX *ctx));
963void SSL_set_verify_depth(SSL *s, int depth);
964#ifndef NO_RSA
965int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
966#endif
967int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
968int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
969int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
970int SSL_use_certificate(SSL *ssl, X509 *x);
971int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
972
973#ifndef NO_STDIO
974int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
975int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
976int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
977int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
978int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
979int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
980int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
981STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
982int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
983 const char *file);
984int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
985 const char *dir);
986#endif
987
988void ERR_load_SSL_strings(void );
989void SSL_load_error_strings(void );
990char * SSL_state_string(SSL *s);
991char * SSL_rstate_string(SSL *s);
992char * SSL_state_string_long(SSL *s);
993char * SSL_rstate_string_long(SSL *s);
994long SSL_SESSION_get_time(SSL_SESSION *s);
995long SSL_SESSION_set_time(SSL_SESSION *s, long t);
996long SSL_SESSION_get_timeout(SSL_SESSION *s);
997long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
998void SSL_copy_session_id(SSL *to,SSL *from);
999
1000SSL_SESSION *SSL_SESSION_new(void);
1001unsigned long SSL_SESSION_hash(SSL_SESSION *a);
1002int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
1003#ifndef NO_FP_API
1004int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
1005#endif
1006#ifndef NO_BIO
1007int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
1008#endif
1009void SSL_SESSION_free(SSL_SESSION *ses);
1010int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
1011int SSL_set_session(SSL *to, SSL_SESSION *session);
1012int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
1013int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
1014SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
1015
1016#ifdef HEADER_X509_H
1017X509 * SSL_get_peer_certificate(SSL *s);
1018#endif
1019
1020STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
1021
1022#ifdef VMS
1023#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
1024#endif
1025
1026int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
1027int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
1028int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
1029void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
1030 int (*callback)(int, X509_STORE_CTX *));
1031void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
1032void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg);
1033#ifndef NO_RSA
1034int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1035#endif
1036int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
1037int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1038int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
1039 unsigned char *d, long len);
1040int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1041int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
1042
1043void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1044void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1045
1046int SSL_CTX_check_private_key(SSL_CTX *ctx);
1047int SSL_check_private_key(SSL *ctx);
1048
1049int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
1050 unsigned int sid_ctx_len);
1051
1052SSL * SSL_new(SSL_CTX *ctx);
1053int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1054 unsigned int sid_ctx_len);
1055
1056int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1057int SSL_set_purpose(SSL *s, int purpose);
1058int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1059int SSL_set_trust(SSL *s, int trust);
1060
1061void SSL_free(SSL *ssl);
1062int SSL_accept(SSL *ssl);
1063int SSL_connect(SSL *ssl);
1064int SSL_read(SSL *ssl,char *buf,int num);
1065int SSL_peek(SSL *ssl,char *buf,int num);
1066int SSL_write(SSL *ssl,const char *buf,int num);
1067long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
1068long SSL_callback_ctrl(SSL *, int, void (*)());
1069long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
1070long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)());
1071
1072int SSL_get_error(SSL *s,int ret_code);
1073const char *SSL_get_version(SSL *s);
1074
1075/* This sets the 'default' SSL version that SSL_new() will create */
1076int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1077
1078SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1079SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1080SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1081
1082SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1083SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1084SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1085
1086SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1087SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1088SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1089
1090SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1091SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1092SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1093
1094STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s);
1095
1096int SSL_do_handshake(SSL *s);
1097int SSL_renegotiate(SSL *s);
1098int SSL_shutdown(SSL *s);
1099
1100SSL_METHOD *SSL_get_ssl_method(SSL *s);
1101int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1102char *SSL_alert_type_string_long(int value);
1103char *SSL_alert_type_string(int value);
1104char *SSL_alert_desc_string_long(int value);
1105char *SSL_alert_desc_string(int value);
1106
1107void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
1108void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
1109STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
1110STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s);
1111int SSL_add_client_CA(SSL *ssl,X509 *x);
1112int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1113
1114void SSL_set_connect_state(SSL *s);
1115void SSL_set_accept_state(SSL *s);
1116
1117long SSL_get_default_timeout(SSL *s);
1118
1119int SSL_library_init(void );
1120
1121char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1122STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1123
1124SSL *SSL_dup(SSL *ssl);
1125
1126X509 *SSL_get_certificate(SSL *ssl);
1127/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1128
1129void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1130int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
1131void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1132int SSL_get_quiet_shutdown(SSL *ssl);
1133void SSL_set_shutdown(SSL *ssl,int mode);
1134int SSL_get_shutdown(SSL *ssl);
1135int SSL_version(SSL *ssl);
1136int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1137int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1138 const char *CApath);
1139#define SSL_get0_session SSL_get_session /* just peek at pointer */
1140SSL_SESSION *SSL_get_session(SSL *ssl);
1141SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1142SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
1143void SSL_set_info_callback(SSL *ssl,void (*cb)());
1144void (*SSL_get_info_callback(SSL *ssl))();
1145int SSL_state(SSL *ssl);
1146
1147void SSL_set_verify_result(SSL *ssl,long v);
1148long SSL_get_verify_result(SSL *ssl);
1149
1150int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1151void *SSL_get_ex_data(SSL *ssl,int idx);
1152int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1153 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1154
1155int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1156void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
1157int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1158 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1159
1160int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1161void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
1162int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1163 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1164
1165int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1166
1167#define SSL_CTX_sess_set_cache_size(ctx,t) \
1168 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1169#define SSL_CTX_sess_get_cache_size(ctx) \
1170 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1171#define SSL_CTX_set_session_cache_mode(ctx,m) \
1172 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1173#define SSL_CTX_get_session_cache_mode(ctx) \
1174 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1175
1176#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1177#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1178#define SSL_CTX_get_read_ahead(ctx) \
1179 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1180#define SSL_CTX_set_read_ahead(ctx,m) \
1181 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,0,NULL)
1182
1183 /* NB: the keylength is only applicable when is_export is true */
1184#ifndef NO_RSA
1185void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1186 RSA *(*cb)(SSL *ssl,int is_export,
1187 int keylength));
1188
1189void SSL_set_tmp_rsa_callback(SSL *ssl,
1190 RSA *(*cb)(SSL *ssl,int is_export,
1191 int keylength));
1192#endif
1193#ifndef NO_DH
1194void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1195 DH *(*dh)(SSL *ssl,int is_export,
1196 int keylength));
1197void SSL_set_tmp_dh_callback(SSL *ssl,
1198 DH *(*dh)(SSL *ssl,int is_export,
1199 int keylength));
1200#endif
1201
1202#ifndef NO_COMP
1203int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1204#else
1205int SSL_COMP_add_compression_method(int id,char *cm);
1206#endif
1207
1208/* BEGIN ERROR CODES */
1209/* The following lines are auto generated by the script mkerr.pl. Any changes
1210 * made after this point may be overwritten when the script is next run.
1211 */
1212
1213/* Error codes for the SSL functions. */
1214
1215/* Function codes. */
1216#define SSL_F_CLIENT_CERTIFICATE 100
1217#define SSL_F_CLIENT_HELLO 101
1218#define SSL_F_CLIENT_MASTER_KEY 102
1219#define SSL_F_D2I_SSL_SESSION 103
1220#define SSL_F_DO_SSL3_WRITE 104
1221#define SSL_F_GET_CLIENT_FINISHED 105
1222#define SSL_F_GET_CLIENT_HELLO 106
1223#define SSL_F_GET_CLIENT_MASTER_KEY 107
1224#define SSL_F_GET_SERVER_FINISHED 108
1225#define SSL_F_GET_SERVER_HELLO 109
1226#define SSL_F_GET_SERVER_VERIFY 110
1227#define SSL_F_I2D_SSL_SESSION 111
1228#define SSL_F_READ_N 112
1229#define SSL_F_REQUEST_CERTIFICATE 113
1230#define SSL_F_SERVER_HELLO 114
1231#define SSL_F_SSL23_ACCEPT 115
1232#define SSL_F_SSL23_CLIENT_HELLO 116
1233#define SSL_F_SSL23_CONNECT 117
1234#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1235#define SSL_F_SSL23_GET_SERVER_HELLO 119
1236#define SSL_F_SSL23_READ 120
1237#define SSL_F_SSL23_WRITE 121
1238#define SSL_F_SSL2_ACCEPT 122
1239#define SSL_F_SSL2_CONNECT 123
1240#define SSL_F_SSL2_ENC_INIT 124
1241#define SSL_F_SSL2_READ 125
1242#define SSL_F_SSL2_SET_CERTIFICATE 126
1243#define SSL_F_SSL2_WRITE 127
1244#define SSL_F_SSL3_ACCEPT 128
1245#define SSL_F_SSL3_CALLBACK_CTRL 233
1246#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1247#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1248#define SSL_F_SSL3_CLIENT_HELLO 131
1249#define SSL_F_SSL3_CONNECT 132
1250#define SSL_F_SSL3_CTRL 213
1251#define SSL_F_SSL3_CTX_CTRL 133
1252#define SSL_F_SSL3_ENC 134
1253#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1254#define SSL_F_SSL3_GET_CERT_VERIFY 136
1255#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1256#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1257#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1258#define SSL_F_SSL3_GET_FINISHED 140
1259#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1260#define SSL_F_SSL3_GET_MESSAGE 142
1261#define SSL_F_SSL3_GET_RECORD 143
1262#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1263#define SSL_F_SSL3_GET_SERVER_DONE 145
1264#define SSL_F_SSL3_GET_SERVER_HELLO 146
1265#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1266#define SSL_F_SSL3_READ_BYTES 148
1267#define SSL_F_SSL3_READ_N 149
1268#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1269#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1270#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1271#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1272#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1273#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1274#define SSL_F_SSL3_SETUP_BUFFERS 156
1275#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1276#define SSL_F_SSL3_WRITE_BYTES 158
1277#define SSL_F_SSL3_WRITE_PENDING 159
1278#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1279#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1280#define SSL_F_SSL_BAD_METHOD 160
1281#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1282#define SSL_F_SSL_CERT_DUP 221
1283#define SSL_F_SSL_CERT_INST 222
1284#define SSL_F_SSL_CERT_INSTANTIATE 214
1285#define SSL_F_SSL_CERT_NEW 162
1286#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1287#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1288#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1289#define SSL_F_SSL_CLEAR 164
1290#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1291#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1292#define SSL_F_SSL_CTRL 232
1293#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1294#define SSL_F_SSL_CTX_NEW 169
1295#define SSL_F_SSL_CTX_SET_PURPOSE 226
1296#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1297#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1298#define SSL_F_SSL_CTX_SET_TRUST 229
1299#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1300#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1301#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1302#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1303#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1304#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1305#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1306#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1307#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1308#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1309#define SSL_F_SSL_DO_HANDSHAKE 180
1310#define SSL_F_SSL_GET_NEW_SESSION 181
1311#define SSL_F_SSL_GET_PREV_SESSION 217
1312#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1313#define SSL_F_SSL_GET_SIGN_PKEY 183
1314#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1315#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1316#define SSL_F_SSL_NEW 186
1317#define SSL_F_SSL_READ 223
1318#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1319#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1320#define SSL_F_SSL_SESSION_NEW 189
1321#define SSL_F_SSL_SESSION_PRINT_FP 190
1322#define SSL_F_SSL_SESS_CERT_NEW 225
1323#define SSL_F_SSL_SET_CERT 191
1324#define SSL_F_SSL_SET_FD 192
1325#define SSL_F_SSL_SET_PKEY 193
1326#define SSL_F_SSL_SET_PURPOSE 227
1327#define SSL_F_SSL_SET_RFD 194
1328#define SSL_F_SSL_SET_SESSION 195
1329#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1330#define SSL_F_SSL_SET_TRUST 228
1331#define SSL_F_SSL_SET_WFD 196
1332#define SSL_F_SSL_SHUTDOWN 224
1333#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1334#define SSL_F_SSL_USE_CERTIFICATE 198
1335#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1336#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1337#define SSL_F_SSL_USE_PRIVATEKEY 201
1338#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1339#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1340#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1341#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1342#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1343#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1344#define SSL_F_SSL_WRITE 208
1345#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1346#define SSL_F_TLS1_ENC 210
1347#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1348#define SSL_F_WRITE_PENDING 212
1349
1350/* Reason codes. */
1351#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1352#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1353#define SSL_R_BAD_ALERT_RECORD 101
1354#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1355#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1356#define SSL_R_BAD_CHECKSUM 104
1357#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1358#define SSL_R_BAD_DECOMPRESSION 107
1359#define SSL_R_BAD_DH_G_LENGTH 108
1360#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1361#define SSL_R_BAD_DH_P_LENGTH 110
1362#define SSL_R_BAD_DIGEST_LENGTH 111
1363#define SSL_R_BAD_DSA_SIGNATURE 112
1364#define SSL_R_BAD_HELLO_REQUEST 105
1365#define SSL_R_BAD_LENGTH 271
1366#define SSL_R_BAD_MAC_DECODE 113
1367#define SSL_R_BAD_MESSAGE_TYPE 114
1368#define SSL_R_BAD_PACKET_LENGTH 115
1369#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1370#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1371#define SSL_R_BAD_RSA_DECRYPT 118
1372#define SSL_R_BAD_RSA_ENCRYPT 119
1373#define SSL_R_BAD_RSA_E_LENGTH 120
1374#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1375#define SSL_R_BAD_RSA_SIGNATURE 122
1376#define SSL_R_BAD_SIGNATURE 123
1377#define SSL_R_BAD_SSL_FILETYPE 124
1378#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1379#define SSL_R_BAD_STATE 126
1380#define SSL_R_BAD_WRITE_RETRY 127
1381#define SSL_R_BIO_NOT_SET 128
1382#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1383#define SSL_R_BN_LIB 130
1384#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1385#define SSL_R_CA_DN_TOO_LONG 132
1386#define SSL_R_CCS_RECEIVED_EARLY 133
1387#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1388#define SSL_R_CERT_LENGTH_MISMATCH 135
1389#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1390#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1391#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1392#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1393#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1394#define SSL_R_COMPRESSION_FAILURE 141
1395#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1396#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1397#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1398#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1399#define SSL_R_DATA_LENGTH_TOO_LONG 146
1400#define SSL_R_DECRYPTION_FAILED 147
1401#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1402#define SSL_R_DIGEST_CHECK_FAILED 149
1403#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1404#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 1092
1405#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1406#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1407#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1408#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1409#define SSL_R_HTTPS_PROXY_REQUEST 155
1410#define SSL_R_HTTP_REQUEST 156
1411#define SSL_R_INTERNAL_ERROR 157
1412#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1413#define SSL_R_INVALID_COMMAND 280
1414#define SSL_R_INVALID_PURPOSE 278
1415#define SSL_R_INVALID_TRUST 279
1416#define SSL_R_LENGTH_MISMATCH 159
1417#define SSL_R_LENGTH_TOO_SHORT 160
1418#define SSL_R_LIBRARY_BUG 274
1419#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1420#define SSL_R_MISSING_DH_DSA_CERT 162
1421#define SSL_R_MISSING_DH_KEY 163
1422#define SSL_R_MISSING_DH_RSA_CERT 164
1423#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1424#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1425#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1426#define SSL_R_MISSING_RSA_CERTIFICATE 168
1427#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1428#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1429#define SSL_R_MISSING_TMP_DH_KEY 171
1430#define SSL_R_MISSING_TMP_RSA_KEY 172
1431#define SSL_R_MISSING_TMP_RSA_PKEY 173
1432#define SSL_R_MISSING_VERIFY_MESSAGE 174
1433#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1434#define SSL_R_NO_CERTIFICATES_RETURNED 176
1435#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1436#define SSL_R_NO_CERTIFICATE_RETURNED 178
1437#define SSL_R_NO_CERTIFICATE_SET 179
1438#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1439#define SSL_R_NO_CIPHERS_AVAILABLE 181
1440#define SSL_R_NO_CIPHERS_PASSED 182
1441#define SSL_R_NO_CIPHERS_SPECIFIED 183
1442#define SSL_R_NO_CIPHER_LIST 184
1443#define SSL_R_NO_CIPHER_MATCH 185
1444#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1445#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1446#define SSL_R_NO_METHOD_SPECIFIED 188
1447#define SSL_R_NO_PRIVATEKEY 189
1448#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1449#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1450#define SSL_R_NO_PUBLICKEY 192
1451#define SSL_R_NO_SHARED_CIPHER 193
1452#define SSL_R_NO_VERIFY_CALLBACK 194
1453#define SSL_R_NULL_SSL_CTX 195
1454#define SSL_R_NULL_SSL_METHOD_PASSED 196
1455#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1456#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1457#define SSL_R_PATH_TOO_LONG 270
1458#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1459#define SSL_R_PEER_ERROR 200
1460#define SSL_R_PEER_ERROR_CERTIFICATE 201
1461#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1462#define SSL_R_PEER_ERROR_NO_CIPHER 203
1463#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1464#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1465#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1466#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1467#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1468#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1469#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1470#define SSL_R_READ_BIO_NOT_SET 211
1471#define SSL_R_READ_WRONG_PACKET_TYPE 212
1472#define SSL_R_RECORD_LENGTH_MISMATCH 213
1473#define SSL_R_RECORD_TOO_LARGE 214
1474#define SSL_R_RECORD_TOO_SMALL 1093
1475#define SSL_R_REQUIRED_CIPHER_MISSING 215
1476#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1477#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1478#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1479#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1480#define SSL_R_SHORT_READ 219
1481#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1482#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1483#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1484#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1485#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1486#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1487#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1488#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1489#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1490#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1491#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1492#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1493#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223
1494#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224
1495#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225
1496#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226
1497#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1498#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227
1499#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1500#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1501#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1502#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1503#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1504#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1505#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1506#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1507#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1508#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1509#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
1510#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1511#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1512#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1513#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1514#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1515#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1516#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
1517#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1518#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1519#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1520#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1521#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1522#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1523#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1524#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1525#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1526#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1527#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1528#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1529#define SSL_R_UNEXPECTED_MESSAGE 244
1530#define SSL_R_UNEXPECTED_RECORD 245
1531#define SSL_R_UNINITIALIZED 276
1532#define SSL_R_UNKNOWN_ALERT_TYPE 246
1533#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1534#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1535#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1536#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1537#define SSL_R_UNKNOWN_PKEY_TYPE 251
1538#define SSL_R_UNKNOWN_PROTOCOL 252
1539#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1540#define SSL_R_UNKNOWN_SSL_VERSION 254
1541#define SSL_R_UNKNOWN_STATE 255
1542#define SSL_R_UNSUPPORTED_CIPHER 256
1543#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1544#define SSL_R_UNSUPPORTED_OPTION 1091
1545#define SSL_R_UNSUPPORTED_PROTOCOL 258
1546#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1547#define SSL_R_WRITE_BIO_NOT_SET 260
1548#define SSL_R_WRONG_CIPHER_RETURNED 261
1549#define SSL_R_WRONG_MESSAGE_TYPE 262
1550#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1551#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1552#define SSL_R_WRONG_SIGNATURE_SIZE 265
1553#define SSL_R_WRONG_SSL_VERSION 266
1554#define SSL_R_WRONG_VERSION_NUMBER 267
1555#define SSL_R_X509_LIB 268
1556#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1557
1558#ifdef __cplusplus
1559}
1560#endif
1561#endif
1562
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index df7d03c18f..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,269 +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
63extern "C" {
64#endif
65
66/* Protocol Version Codes */
67#define SSL2_VERSION 0x0002
68#define SSL2_VERSION_MAJOR 0x00
69#define SSL2_VERSION_MINOR 0x02
70/* #define SSL2_CLIENT_VERSION 0x0002 */
71/* #define SSL2_SERVER_VERSION 0x0002 */
72
73/* Protocol Message Codes */
74#define SSL2_MT_ERROR 0
75#define SSL2_MT_CLIENT_HELLO 1
76#define SSL2_MT_CLIENT_MASTER_KEY 2
77#define SSL2_MT_CLIENT_FINISHED 3
78#define SSL2_MT_SERVER_HELLO 4
79#define SSL2_MT_SERVER_VERIFY 5
80#define SSL2_MT_SERVER_FINISHED 6
81#define SSL2_MT_REQUEST_CERTIFICATE 7
82#define SSL2_MT_CLIENT_CERTIFICATE 8
83
84/* Error Message Codes */
85#define SSL2_PE_UNDEFINED_ERROR 0x0000
86#define SSL2_PE_NO_CIPHER 0x0001
87#define SSL2_PE_NO_CERTIFICATE 0x0002
88#define SSL2_PE_BAD_CERTIFICATE 0x0004
89#define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
90
91/* Cipher Kind Values */
92#define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */
93#define SSL2_CK_RC4_128_WITH_MD5 0x02010080
94#define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080
95#define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080
96#define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080
97#define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080
98#define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040
99#define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */
100#define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0
101#define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */
102#define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */
103
104#define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */
105#define SSL2_CK_NULL 0x02ff0810 /* SSLeay */
106
107#define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1"
108#define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5"
109#define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5"
110#define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5"
111#define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5"
112#define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5"
113#define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5"
114#define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5"
115#define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA"
116#define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5"
117#define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA"
118#define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5"
119
120#define SSL2_TXT_NULL "NULL"
121
122/* Flags for the SSL_CIPHER.algorithm2 field */
123#define SSL2_CF_5_BYTE_ENC 0x01
124#define SSL2_CF_8_BYTE_ENC 0x02
125
126/* Certificate Type Codes */
127#define SSL2_CT_X509_CERTIFICATE 0x01
128
129/* Authentication Type Code */
130#define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01
131
132#define SSL2_MAX_SSL_SESSION_ID_LENGTH 32
133
134/* Upper/Lower Bounds */
135#define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256
136#ifdef MPE
137#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)29998
138#else
139#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)32767
140#endif
141#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /**/
142
143#define SSL2_CHALLENGE_LENGTH 16
144/*#define SSL2_CHALLENGE_LENGTH 32 */
145#define SSL2_MIN_CHALLENGE_LENGTH 16
146#define SSL2_MAX_CHALLENGE_LENGTH 32
147#define SSL2_CONNECTION_ID_LENGTH 16
148#define SSL2_MAX_CONNECTION_ID_LENGTH 16
149#define SSL2_SSL_SESSION_ID_LENGTH 16
150#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
151#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
152#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
153
154#ifndef HEADER_SSL_LOCL_H
155#define CERT char
156#endif
157
158typedef struct ssl2_state_st
159 {
160 int three_byte_header;
161 int clear_text; /* clear text */
162 int escape; /* not used in SSLv2 */
163 int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */
164
165 /* non-blocking io info, used to make sure the same
166 * args were passwd */
167 unsigned int wnum; /* number of bytes sent so far */
168 int wpend_tot;
169 const unsigned char *wpend_buf;
170
171 int wpend_off; /* offset to data to write */
172 int wpend_len; /* number of bytes passwd to write */
173 int wpend_ret; /* number of bytes to return to caller */
174
175 /* buffer raw data */
176 int rbuf_left;
177 int rbuf_offs;
178 unsigned char *rbuf;
179 unsigned char *wbuf;
180
181 unsigned char *write_ptr;/* used to point to the start due to
182 * 2/3 byte header. */
183
184 unsigned int padding;
185 unsigned int rlength; /* passed to ssl2_enc */
186 int ract_data_length; /* Set when things are encrypted. */
187 unsigned int wlength; /* passed to ssl2_enc */
188 int wact_data_length; /* Set when things are decrypted. */
189 unsigned char *ract_data;
190 unsigned char *wact_data;
191 unsigned char *mac_data;
192 unsigned char *pad_data;
193
194 unsigned char *read_key;
195 unsigned char *write_key;
196
197 /* Stuff specifically to do with this SSL session */
198 unsigned int challenge_length;
199 unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
200 unsigned int conn_id_length;
201 unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
202 unsigned int key_material_length;
203 unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
204
205 unsigned long read_sequence;
206 unsigned long write_sequence;
207
208 struct {
209 unsigned int conn_id_length;
210 unsigned int cert_type;
211 unsigned int cert_length;
212 int csl;
213 int clear;
214 unsigned int enc;
215 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
216 int cipher_spec_length;
217 unsigned int session_id_length;
218 unsigned int clen;
219 unsigned int rlen;
220 } tmp;
221 } SSL2_STATE;
222
223/* SSLv2 */
224/* client */
225#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
226#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
227#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
228#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
229#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
230#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
231#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
232#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
233#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
234#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
235#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
236#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
237#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
238#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
239#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
240#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
241#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
242#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
243/* server */
244#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
245#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
246#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
247#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
248#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
249#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
250#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
251#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
252#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
253#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
254#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
255#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
256#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
257#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
258#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
259#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
260#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
261#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
262#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
263#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
264
265#ifdef __cplusplus
266}
267#endif
268#endif
269
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
63extern "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 7ee1feaa67..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,429 +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#ifndef NO_COMP
63#include <openssl/comp.h>
64#endif
65#include <openssl/buffer.h>
66#include <openssl/evp.h>
67#include <openssl/ssl.h>
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#define SSL3_CK_RSA_NULL_MD5 0x03000001
74#define SSL3_CK_RSA_NULL_SHA 0x03000002
75#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
76#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
77#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
78#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
79#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
80#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
81#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
82#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
83
84#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
85#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
86#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
87#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
88#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
89#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
90
91#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
92#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
93#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
94#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
95#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
96#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
97
98#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
99#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
100#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
101#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
102#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
103
104#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
105#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
106#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
107
108#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
109#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
110#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
111#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
112#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
113#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
114#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
115#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
116#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
117#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
118
119#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
120#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
121#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
122#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
123#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
124#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
125
126#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
127#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
128#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
129#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
130#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
131#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
132
133#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
134#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
135#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
136#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
137#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
138
139#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
140#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
141#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
142
143#define SSL3_SSL_SESSION_ID_LENGTH 32
144#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
145
146#define SSL3_MASTER_SECRET_SIZE 48
147#define SSL3_RANDOM_SIZE 32
148#define SSL3_SESSION_ID_SIZE 32
149#define SSL3_RT_HEADER_LENGTH 5
150
151/* Due to MS stuffing up, this can change.... */
152#if defined(WIN16) || (defined(MSDOS) && !defined(WIN32))
153#define SSL3_RT_MAX_EXTRA (14000)
154#else
155#define SSL3_RT_MAX_EXTRA (16384)
156#endif
157
158#define SSL3_RT_MAX_PLAIN_LENGTH 16384
159#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
160#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
161#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
162#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
163
164#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
165#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
166
167#define SSL3_VERSION 0x0300
168#define SSL3_VERSION_MAJOR 0x03
169#define SSL3_VERSION_MINOR 0x00
170
171#define SSL3_RT_CHANGE_CIPHER_SPEC 20
172#define SSL3_RT_ALERT 21
173#define SSL3_RT_HANDSHAKE 22
174#define SSL3_RT_APPLICATION_DATA 23
175
176#define SSL3_AL_WARNING 1
177#define SSL3_AL_FATAL 2
178
179#define SSL3_AD_CLOSE_NOTIFY 0
180#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
181#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
182#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
183#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
184#define SSL3_AD_NO_CERTIFICATE 41
185#define SSL3_AD_BAD_CERTIFICATE 42
186#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
187#define SSL3_AD_CERTIFICATE_REVOKED 44
188#define SSL3_AD_CERTIFICATE_EXPIRED 45
189#define SSL3_AD_CERTIFICATE_UNKNOWN 46
190#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
191
192typedef struct ssl3_record_st
193 {
194/*r */ int type; /* type of record */
195/*rw*/ unsigned int length; /* How many bytes available */
196/*r */ unsigned int off; /* read/write offset into 'buf' */
197/*rw*/ unsigned char *data; /* pointer to the record data */
198/*rw*/ unsigned char *input; /* where the decode bytes are */
199/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
200 } SSL3_RECORD;
201
202typedef struct ssl3_buffer_st
203 {
204 unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes (more if
205 * SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER is set) */
206 int offset; /* where to 'copy from' */
207 int left; /* how many bytes left */
208 } SSL3_BUFFER;
209
210#define SSL3_CT_RSA_SIGN 1
211#define SSL3_CT_DSS_SIGN 2
212#define SSL3_CT_RSA_FIXED_DH 3
213#define SSL3_CT_DSS_FIXED_DH 4
214#define SSL3_CT_RSA_EPHEMERAL_DH 5
215#define SSL3_CT_DSS_EPHEMERAL_DH 6
216#define SSL3_CT_FORTEZZA_DMS 20
217#define SSL3_CT_NUMBER 7
218
219#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
220#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
221#define SSL3_FLAGS_POP_BUFFER 0x0004
222#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
223
224typedef struct ssl3_state_st
225 {
226 long flags;
227 int delay_buf_pop_ret;
228
229 unsigned char read_sequence[8];
230 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
231 unsigned char write_sequence[8];
232 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
233
234 unsigned char server_random[SSL3_RANDOM_SIZE];
235 unsigned char client_random[SSL3_RANDOM_SIZE];
236
237 SSL3_BUFFER rbuf; /* read IO goes into here */
238 SSL3_BUFFER wbuf; /* write IO goes into here */
239
240 SSL3_RECORD rrec; /* each decoded record goes in here */
241 SSL3_RECORD wrec; /* goes out from here */
242
243 /* storage for Alert/Handshake protocol data received but not
244 * yet processed by ssl3_read_bytes: */
245 unsigned char alert_fragment[2];
246 unsigned int alert_fragment_len;
247 unsigned char handshake_fragment[4];
248 unsigned int handshake_fragment_len;
249
250 /* partial write - check the numbers match */
251 unsigned int wnum; /* number of bytes sent so far */
252 int wpend_tot; /* number bytes written */
253 int wpend_type;
254 int wpend_ret; /* number of bytes submitted */
255 const unsigned char *wpend_buf;
256
257 /* used during startup, digest all incoming/outgoing packets */
258 EVP_MD_CTX finish_dgst1;
259 EVP_MD_CTX finish_dgst2;
260
261 /* this is set whenerver we see a change_cipher_spec message
262 * come in when we are not looking for one */
263 int change_cipher_spec;
264
265 int warn_alert;
266 int fatal_alert;
267 /* we allow one fatal and one warning alert to be outstanding,
268 * send close alert via the warning alert */
269 int alert_dispatch;
270 unsigned char send_alert[2];
271
272 /* This flag is set when we should renegotiate ASAP, basically when
273 * there is no more data in the read or write buffers */
274 int renegotiate;
275 int total_renegotiations;
276 int num_renegotiations;
277
278 int in_read_app_data;
279
280 struct {
281 /* actually only needs to be 16+20 */
282 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
283
284 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
285 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
286 int finish_md_len;
287 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
288 int peer_finish_md_len;
289
290 unsigned long message_size;
291 int message_type;
292
293 /* used to hold the new cipher we are going to use */
294 SSL_CIPHER *new_cipher;
295#ifndef NO_DH
296 DH *dh;
297#endif
298 /* used when SSL_ST_FLUSH_DATA is entered */
299 int next_state;
300
301 int reuse_message;
302
303 /* used for certificate requests */
304 int cert_req;
305 int ctype_num;
306 char ctype[SSL3_CT_NUMBER];
307 STACK_OF(X509_NAME) *ca_names;
308
309 int use_rsa_tmp;
310
311 int key_block_length;
312 unsigned char *key_block;
313
314 const EVP_CIPHER *new_sym_enc;
315 const EVP_MD *new_hash;
316#ifndef NO_COMP
317 const SSL_COMP *new_compression;
318#else
319 char *new_compression;
320#endif
321 int cert_request;
322 } tmp;
323
324 } SSL3_STATE;
325
326/* SSLv3 */
327/*client */
328/* extra state */
329#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
330/* write to server */
331#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
332#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
333/* read from server */
334#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
335#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
336#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
337#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
338#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
339#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
340#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
341#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
342#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
343#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
344/* write to server */
345#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
346#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
347#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
348#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
349#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
350#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
351#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
352#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
353#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
354#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
355#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
356#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
357/* read from server */
358#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
359#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
360#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
361#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
362
363/* server */
364/* extra state */
365#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
366/* read from client */
367/* Do not change the number values, they do matter */
368#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
369#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
370#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
371/* write to client */
372#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
373#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
374#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
375#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
376#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
377#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
378#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
379#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
380#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
381#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
382#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
383#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
384#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
385/* read from client */
386#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
387#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
388#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
389#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
390#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
391#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
392#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
393#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
394#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
395#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
396/* write to client */
397#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
398#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
399#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
400#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
401
402#define SSL3_MT_HELLO_REQUEST 0
403#define SSL3_MT_CLIENT_HELLO 1
404#define SSL3_MT_SERVER_HELLO 2
405#define SSL3_MT_CERTIFICATE 11
406#define SSL3_MT_SERVER_KEY_EXCHANGE 12
407#define SSL3_MT_CERTIFICATE_REQUEST 13
408#define SSL3_MT_SERVER_DONE 14
409#define SSL3_MT_CERTIFICATE_VERIFY 15
410#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
411#define SSL3_MT_FINISHED 20
412
413#define SSL3_MT_CCS 1
414
415/* These are used when changing over to a new cipher */
416#define SSL3_CC_READ 0x01
417#define SSL3_CC_WRITE 0x02
418#define SSL3_CC_CLIENT 0x10
419#define SSL3_CC_SERVER 0x20
420#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
421#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
422#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
423#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
424
425#ifdef __cplusplus
426}
427#endif
428#endif
429
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
64int 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 fa6456e4f5..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
66typedef 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
80int 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-OPENSSL_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
208SSL_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) { OPENSSL_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) { OPENSSL_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) OPENSSL_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 OPENSSL_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 OPENSSL_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 OPENSSL_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 OPENSSL_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 c26df62c20..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,755 +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
130int 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
142CERT *ssl_cert_new(void)
143 {
144 CERT *ret;
145
146 ret=(CERT *)OPENSSL_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
160CERT *ssl_cert_dup(CERT *cert)
161 {
162 CERT *ret;
163 int i;
164
165 ret = (CERT *)OPENSSL_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
274err:
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
296void 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 OPENSSL_free(c);
335 }
336
337int 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
366SESS_CERT *ssl_sess_cert_new(void)
367 {
368 SESS_CERT *ret;
369
370 ret = OPENSSL_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
384void 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 OPENSSL_free(sc);
430 }
431
432int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
433 {
434 sc->peer_cert_type = type;
435 return(1);
436 }
437
438int 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
481static 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
489STACK_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
508void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list)
509 {
510 set_client_CA_list(&(s->client_CA),list);
511 }
512
513void 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
518STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx)
519 {
520 return(ctx->client_CA);
521 }
522
523STACK_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
542static 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
561int SSL_add_client_CA(SSL *ssl,X509 *x)
562 {
563 return(add_client_CA(&(ssl->client_CA),x));
564 }
565
566int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
567 {
568 return(add_client_CA(&(ctx->client_CA),x));
569 }
570
571static int xname_cmp(const X509_NAME * const *a, const X509_NAME * const *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 */
585STACK_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 {
625err:
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
645int 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)(const X509_NAME * const *a, const X509_NAME * const *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 {
682err:
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
710int 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 int r;
733
734 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
735 {
736 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
737 goto err;
738 }
739
740 r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
741 if (r <= 0 || r >= sizeof buf)
742 goto err;
743 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
744 goto err;
745 }
746 ret = 1;
747
748err:
749 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
750 return ret;
751 }
752
753#endif
754#endif
755#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index f63163f26c..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1071 +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
73static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
74 NULL,NULL,NULL,NULL,NULL,NULL,
75 };
76
77static 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
82static 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
92typedef 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
100static 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
148static int init_ciphers=1;
149
150static 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
170int 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
264static 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
280static 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
312static 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
364static 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
403static 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
500static 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 = OPENSSL_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 OPENSSL_free(number_uses);
549 return(1);
550 }
551
552static 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
710STACK_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 *)OPENSSL_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 **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
763 if (ca_list == NULL)
764 {
765 OPENSSL_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 OPENSSL_free(ca_list); /* Not needed anymore */
792
793 if (!ok)
794 { /* Rule processing failure */
795 OPENSSL_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 OPENSSL_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 OPENSSL_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
869char *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 len=128;
979 buf=OPENSSL_malloc(len);
980 if (buf == NULL) return("OPENSSL_malloc Error");
981 }
982 else if (len < 128)
983 return("Buffer too small");
984
985 BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp);
986 return(buf);
987 }
988
989char *SSL_CIPHER_get_version(SSL_CIPHER *c)
990 {
991 int i;
992
993 if (c == NULL) return("(NONE)");
994 i=(int)(c->id>>24L);
995 if (i == 3)
996 return("TLSv1/SSLv3");
997 else if (i == 2)
998 return("SSLv2");
999 else
1000 return("unknown");
1001 }
1002
1003/* return the actual cipher being used */
1004const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
1005 {
1006 if (c != NULL)
1007 return(c->name);
1008 return("(NONE)");
1009 }
1010
1011/* number of bits for symmetric cipher */
1012int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
1013 {
1014 int ret=0;
1015
1016 if (c != NULL)
1017 {
1018 if (alg_bits != NULL) *alg_bits = c->alg_bits;
1019 ret = c->strength_bits;
1020 }
1021 return(ret);
1022 }
1023
1024SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
1025 {
1026 SSL_COMP *ctmp;
1027 int i,nn;
1028
1029 if ((n == 0) || (sk == NULL)) return(NULL);
1030 nn=sk_SSL_COMP_num(sk);
1031 for (i=0; i<nn; i++)
1032 {
1033 ctmp=sk_SSL_COMP_value(sk,i);
1034 if (ctmp->id == n)
1035 return(ctmp);
1036 }
1037 return(NULL);
1038 }
1039
1040static int sk_comp_cmp(const SSL_COMP * const *a,
1041 const SSL_COMP * const *b)
1042 {
1043 return((*a)->id-(*b)->id);
1044 }
1045
1046STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
1047 {
1048 return(ssl_comp_methods);
1049 }
1050
1051int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
1052 {
1053 SSL_COMP *comp;
1054 STACK_OF(SSL_COMP) *sk;
1055
1056 comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
1057 comp->id=id;
1058 comp->method=cm;
1059 if (ssl_comp_methods == NULL)
1060 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
1061 else
1062 sk=ssl_comp_methods;
1063 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
1064 {
1065 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
1066 return(0);
1067 }
1068 else
1069 return(1);
1070 }
1071
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 17b4caf528..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,431 +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
67static 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
205static 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_RECORD_TOO_SMALL ,"record too small"},
331{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
332{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
333{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
334{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
335{SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"},
336{SSL_R_SHORT_READ ,"short read"},
337{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
338{SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"},
339{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
340{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
341{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
342{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
343{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
344{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
345{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
346{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
347{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
348{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
349{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
350{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
351{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
352{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
353{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
354{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
355{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
356{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
357{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
358{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
359{SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"},
360{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
361{SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"},
362{SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"},
363{SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"},
364{SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"},
365{SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION ,"tlsv1 alert export restriction"},
366{SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"},
367{SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"},
368{SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"},
369{SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"},
370{SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"},
371{SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"},
372{SSL_R_TLSV1_ALERT_USER_CANCELLED ,"tlsv1 alert user cancelled"},
373{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
374{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
375{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
376{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
377{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
378{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
379{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
380{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
381{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
382{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
383{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
384{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
385{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
386{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
387{SSL_R_UNINITIALIZED ,"uninitialized"},
388{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
389{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
390{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
391{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
392{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
393{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
394{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
395{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
396{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
397{SSL_R_UNKNOWN_STATE ,"unknown state"},
398{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
399{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
400{SSL_R_UNSUPPORTED_OPTION ,"unsupported option"},
401{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
402{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
403{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
404{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
405{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
406{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
407{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
408{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
409{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
410{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
411{SSL_R_X509_LIB ,"x509 lib"},
412{SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"},
413{0,NULL}
414 };
415
416#endif
417
418void ERR_load_SSL_strings(void)
419 {
420 static int init=1;
421
422 if (init)
423 {
424 init=0;
425#ifndef NO_ERR
426 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
427 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
428#endif
429
430 }
431 }
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
63void 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 635b25062e..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
62#include <assert.h>
63#include <stdio.h>
64#include <openssl/objects.h>
65#include <openssl/lhash.h>
66#include <openssl/x509v3.h>
67#include "ssl_locl.h"
68
69const char *SSL_version_str=OPENSSL_VERSION_TEXT;
70
71static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_meth=NULL;
72static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_ctx_meth=NULL;
73static int ssl_meth_num=0;
74static int ssl_ctx_meth_num=0;
75
76OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
77 /* evil casts, but these functions are only called if there's a library bug */
78 (int (*)(SSL *,int))ssl_undefined_function,
79 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
80 ssl_undefined_function,
81 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
82 (int (*)(SSL*, int))ssl_undefined_function,
83 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
84 };
85
86int SSL_clear(SSL *s)
87 {
88 int state;
89
90 if (s->method == NULL)
91 {
92 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
93 return(0);
94 }
95
96 s->error=0;
97 s->hit=0;
98 s->shutdown=0;
99
100#if 0 /* Disabled since version 1.10 of this file (early return not
101 * needed because SSL_clear is not called when doing renegotiation) */
102 /* This is set if we are doing dynamic renegotiation so keep
103 * the old cipher. It is sort of a SSL_clear_lite :-) */
104 if (s->new_session) return(1);
105#else
106 if (s->new_session)
107 {
108 SSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);
109 return 0;
110 }
111#endif
112
113 state=s->state; /* Keep to check if we throw away the session-id */
114 s->type=0;
115
116 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
117
118 s->version=s->method->version;
119 s->client_version=s->version;
120 s->rwstate=SSL_NOTHING;
121 s->rstate=SSL_ST_READ_HEADER;
122 s->read_ahead=s->ctx->read_ahead;
123
124 if (s->init_buf != NULL)
125 {
126 BUF_MEM_free(s->init_buf);
127 s->init_buf=NULL;
128 }
129
130 ssl_clear_cipher_ctx(s);
131
132 if (ssl_clear_bad_session(s))
133 {
134 SSL_SESSION_free(s->session);
135 s->session=NULL;
136 }
137
138 s->first_packet=0;
139
140#if 1
141 /* Check to see if we were changed into a different method, if
142 * so, revert back if we are not doing session-id reuse. */
143 if ((s->session == NULL) && (s->method != s->ctx->method))
144 {
145 s->method->ssl_free(s);
146 s->method=s->ctx->method;
147 if (!s->method->ssl_new(s))
148 return(0);
149 }
150 else
151#endif
152 s->method->ssl_clear(s);
153 return(1);
154 }
155
156/** Used to change an SSL_CTXs default SSL method type */
157int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
158 {
159 STACK_OF(SSL_CIPHER) *sk;
160
161 ctx->method=meth;
162
163 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
164 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
165 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
166 {
167 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
168 return(0);
169 }
170 return(1);
171 }
172
173SSL *SSL_new(SSL_CTX *ctx)
174 {
175 SSL *s;
176
177 if (ctx == NULL)
178 {
179 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
180 return(NULL);
181 }
182 if (ctx->method == NULL)
183 {
184 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
185 return(NULL);
186 }
187
188 s=(SSL *)OPENSSL_malloc(sizeof(SSL));
189 if (s == NULL) goto err;
190 memset(s,0,sizeof(SSL));
191
192 if (ctx->cert != NULL)
193 {
194 /* Earlier library versions used to copy the pointer to
195 * the CERT, not its contents; only when setting new
196 * parameters for the per-SSL copy, ssl_cert_new would be
197 * called (and the direct reference to the per-SSL_CTX
198 * settings would be lost, but those still were indirectly
199 * accessed for various purposes, and for that reason they
200 * used to be known as s->ctx->default_cert).
201 * Now we don't look at the SSL_CTX's CERT after having
202 * duplicated it once. */
203
204 s->cert = ssl_cert_dup(ctx->cert);
205 if (s->cert == NULL)
206 goto err;
207 }
208 else
209 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
210 s->sid_ctx_length=ctx->sid_ctx_length;
211 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
212 s->verify_mode=ctx->verify_mode;
213 s->verify_depth=ctx->verify_depth;
214 s->verify_callback=ctx->default_verify_callback;
215 s->purpose = ctx->purpose;
216 s->trust = ctx->trust;
217 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
218 s->ctx=ctx;
219
220 s->verify_result=X509_V_OK;
221
222 s->method=ctx->method;
223
224 if (!s->method->ssl_new(s))
225 goto err;
226
227 s->quiet_shutdown=ctx->quiet_shutdown;
228 s->references=1;
229 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
230 s->options=ctx->options;
231 s->mode=ctx->mode;
232 SSL_clear(s);
233
234 CRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);
235
236 return(s);
237err:
238 if (s != NULL)
239 {
240 if (s->cert != NULL)
241 ssl_cert_free(s->cert);
242 if (s->ctx != NULL)
243 SSL_CTX_free(s->ctx); /* decrement reference count */
244 OPENSSL_free(s);
245 }
246 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
247 return(NULL);
248 }
249
250int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
251 unsigned int sid_ctx_len)
252 {
253 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
254 {
255 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
256 return 0;
257 }
258 ctx->sid_ctx_length=sid_ctx_len;
259 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
260
261 return 1;
262 }
263
264int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
265 unsigned int sid_ctx_len)
266 {
267 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
268 {
269 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
270 return 0;
271 }
272 ssl->sid_ctx_length=sid_ctx_len;
273 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
274
275 return 1;
276 }
277
278int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
279{
280 if(X509_PURPOSE_get_by_id(purpose) == -1) {
281 SSLerr(SSL_F_SSL_CTX_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
282 return 0;
283 }
284 s->purpose = purpose;
285 return 1;
286}
287
288int SSL_set_purpose(SSL *s, int purpose)
289{
290 if(X509_PURPOSE_get_by_id(purpose) == -1) {
291 SSLerr(SSL_F_SSL_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
292 return 0;
293 }
294 s->purpose = purpose;
295 return 1;
296}
297
298int SSL_CTX_set_trust(SSL_CTX *s, int trust)
299{
300 if(X509_TRUST_get_by_id(trust) == -1) {
301 SSLerr(SSL_F_SSL_CTX_SET_TRUST, SSL_R_INVALID_TRUST);
302 return 0;
303 }
304 s->trust = trust;
305 return 1;
306}
307
308int SSL_set_trust(SSL *s, int trust)
309{
310 if(X509_TRUST_get_by_id(trust) == -1) {
311 SSLerr(SSL_F_SSL_SET_TRUST, SSL_R_INVALID_TRUST);
312 return 0;
313 }
314 s->trust = trust;
315 return 1;
316}
317
318void SSL_free(SSL *s)
319 {
320 int i;
321
322 if(s == NULL)
323 return;
324
325 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
326#ifdef REF_PRINT
327 REF_PRINT("SSL",s);
328#endif
329 if (i > 0) return;
330#ifdef REF_CHECK
331 if (i < 0)
332 {
333 fprintf(stderr,"SSL_free, bad reference count\n");
334 abort(); /* ok */
335 }
336#endif
337
338 CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);
339
340 if (s->bbio != NULL)
341 {
342 /* If the buffering BIO is in place, pop it off */
343 if (s->bbio == s->wbio)
344 {
345 s->wbio=BIO_pop(s->wbio);
346 }
347 BIO_free(s->bbio);
348 s->bbio=NULL;
349 }
350 if (s->rbio != NULL)
351 BIO_free_all(s->rbio);
352 if ((s->wbio != NULL) && (s->wbio != s->rbio))
353 BIO_free_all(s->wbio);
354
355 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
356
357 /* add extra stuff */
358 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
359 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
360
361 /* Make the next call work :-) */
362 if (s->session != NULL)
363 {
364 ssl_clear_bad_session(s);
365 SSL_SESSION_free(s->session);
366 }
367
368 ssl_clear_cipher_ctx(s);
369
370 if (s->cert != NULL) ssl_cert_free(s->cert);
371 /* Free up if allocated */
372
373 if (s->ctx) SSL_CTX_free(s->ctx);
374
375 if (s->client_CA != NULL)
376 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
377
378 if (s->method != NULL) s->method->ssl_free(s);
379
380 OPENSSL_free(s);
381 }
382
383void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
384 {
385 /* If the output buffering BIO is still in place, remove it
386 */
387 if (s->bbio != NULL)
388 {
389 if (s->wbio == s->bbio)
390 {
391 s->wbio=s->wbio->next_bio;
392 s->bbio->next_bio=NULL;
393 }
394 }
395 if ((s->rbio != NULL) && (s->rbio != rbio))
396 BIO_free_all(s->rbio);
397 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
398 BIO_free_all(s->wbio);
399 s->rbio=rbio;
400 s->wbio=wbio;
401 }
402
403BIO *SSL_get_rbio(SSL *s)
404 { return(s->rbio); }
405
406BIO *SSL_get_wbio(SSL *s)
407 { return(s->wbio); }
408
409int SSL_get_fd(SSL *s)
410 {
411 int ret= -1;
412 BIO *b,*r;
413
414 b=SSL_get_rbio(s);
415 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
416 if (r != NULL)
417 BIO_get_fd(r,&ret);
418 return(ret);
419 }
420
421#ifndef NO_SOCK
422int SSL_set_fd(SSL *s,int fd)
423 {
424 int ret=0;
425 BIO *bio=NULL;
426
427 bio=BIO_new(BIO_s_socket());
428
429 if (bio == NULL)
430 {
431 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
432 goto err;
433 }
434 BIO_set_fd(bio,fd,BIO_NOCLOSE);
435 SSL_set_bio(s,bio,bio);
436 ret=1;
437err:
438 return(ret);
439 }
440
441int SSL_set_wfd(SSL *s,int fd)
442 {
443 int ret=0;
444 BIO *bio=NULL;
445
446 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
447 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
448 {
449 bio=BIO_new(BIO_s_socket());
450
451 if (bio == NULL)
452 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
453 BIO_set_fd(bio,fd,BIO_NOCLOSE);
454 SSL_set_bio(s,SSL_get_rbio(s),bio);
455 }
456 else
457 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
458 ret=1;
459err:
460 return(ret);
461 }
462
463int SSL_set_rfd(SSL *s,int fd)
464 {
465 int ret=0;
466 BIO *bio=NULL;
467
468 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
469 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
470 {
471 bio=BIO_new(BIO_s_socket());
472
473 if (bio == NULL)
474 {
475 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
476 goto err;
477 }
478 BIO_set_fd(bio,fd,BIO_NOCLOSE);
479 SSL_set_bio(s,bio,SSL_get_wbio(s));
480 }
481 else
482 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
483 ret=1;
484err:
485 return(ret);
486 }
487#endif
488
489
490/* return length of latest Finished message we sent, copy to 'buf' */
491size_t SSL_get_finished(SSL *s, void *buf, size_t count)
492 {
493 size_t ret = 0;
494
495 if (s->s3 != NULL)
496 {
497 ret = s->s3->tmp.finish_md_len;
498 if (count > ret)
499 count = ret;
500 memcpy(buf, s->s3->tmp.finish_md, count);
501 }
502 return ret;
503 }
504
505/* return length of latest Finished message we expected, copy to 'buf' */
506size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
507 {
508 size_t ret = 0;
509
510 if (s->s3 != NULL)
511 {
512 ret = s->s3->tmp.peer_finish_md_len;
513 if (count > ret)
514 count = ret;
515 memcpy(buf, s->s3->tmp.peer_finish_md, count);
516 }
517 return ret;
518 }
519
520
521int SSL_get_verify_mode(SSL *s)
522 {
523 return(s->verify_mode);
524 }
525
526int SSL_get_verify_depth(SSL *s)
527 {
528 return(s->verify_depth);
529 }
530
531int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *)
532 {
533 return(s->verify_callback);
534 }
535
536int SSL_CTX_get_verify_mode(SSL_CTX *ctx)
537 {
538 return(ctx->verify_mode);
539 }
540
541int SSL_CTX_get_verify_depth(SSL_CTX *ctx)
542 {
543 return(ctx->verify_depth);
544 }
545
546int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *)
547 {
548 return(ctx->default_verify_callback);
549 }
550
551void SSL_set_verify(SSL *s,int mode,
552 int (*callback)(int ok,X509_STORE_CTX *ctx))
553 {
554 s->verify_mode=mode;
555 if (callback != NULL)
556 s->verify_callback=callback;
557 }
558
559void SSL_set_verify_depth(SSL *s,int depth)
560 {
561 s->verify_depth=depth;
562 }
563
564void SSL_set_read_ahead(SSL *s,int yes)
565 {
566 s->read_ahead=yes;
567 }
568
569int SSL_get_read_ahead(SSL *s)
570 {
571 return(s->read_ahead);
572 }
573
574int SSL_pending(SSL *s)
575 {
576 return(s->method->ssl_pending(s));
577 }
578
579X509 *SSL_get_peer_certificate(SSL *s)
580 {
581 X509 *r;
582
583 if ((s == NULL) || (s->session == NULL))
584 r=NULL;
585 else
586 r=s->session->peer;
587
588 if (r == NULL) return(r);
589
590 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
591
592 return(r);
593 }
594
595STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
596 {
597 STACK_OF(X509) *r;
598
599 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
600 r=NULL;
601 else
602 r=s->session->sess_cert->cert_chain;
603
604 /* If we are a client, cert_chain includes the peer's own
605 * certificate; if we are a server, it does not. */
606
607 return(r);
608 }
609
610/* Now in theory, since the calling process own 't' it should be safe to
611 * modify. We need to be able to read f without being hassled */
612void SSL_copy_session_id(SSL *t,SSL *f)
613 {
614 CERT *tmp;
615
616 /* Do we need to to SSL locking? */
617 SSL_set_session(t,SSL_get_session(f));
618
619 /* what if we are setup as SSLv2 but want to talk SSLv3 or
620 * vice-versa */
621 if (t->method != f->method)
622 {
623 t->method->ssl_free(t); /* cleanup current */
624 t->method=f->method; /* change method */
625 t->method->ssl_new(t); /* setup new */
626 }
627
628 tmp=t->cert;
629 if (f->cert != NULL)
630 {
631 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
632 t->cert=f->cert;
633 }
634 else
635 t->cert=NULL;
636 if (tmp != NULL) ssl_cert_free(tmp);
637 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
638 }
639
640/* Fix this so it checks all the valid key/cert options */
641int SSL_CTX_check_private_key(SSL_CTX *ctx)
642 {
643 if ( (ctx == NULL) ||
644 (ctx->cert == NULL) ||
645 (ctx->cert->key->x509 == NULL))
646 {
647 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
648 return(0);
649 }
650 if (ctx->cert->key->privatekey == NULL)
651 {
652 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
653 return(0);
654 }
655 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
656 }
657
658/* Fix this function so that it takes an optional type parameter */
659int SSL_check_private_key(SSL *ssl)
660 {
661 if (ssl == NULL)
662 {
663 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
664 return(0);
665 }
666 if (ssl->cert == NULL)
667 {
668 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
669 return 0;
670 }
671 if (ssl->cert->key->x509 == NULL)
672 {
673 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
674 return(0);
675 }
676 if (ssl->cert->key->privatekey == NULL)
677 {
678 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
679 return(0);
680 }
681 return(X509_check_private_key(ssl->cert->key->x509,
682 ssl->cert->key->privatekey));
683 }
684
685int SSL_accept(SSL *s)
686 {
687 if (s->handshake_func == 0)
688 /* Not properly initialized yet */
689 SSL_set_accept_state(s);
690
691 return(s->method->ssl_accept(s));
692 }
693
694int SSL_connect(SSL *s)
695 {
696 if (s->handshake_func == 0)
697 /* Not properly initialized yet */
698 SSL_set_connect_state(s);
699
700 return(s->method->ssl_connect(s));
701 }
702
703long SSL_get_default_timeout(SSL *s)
704 {
705 return(s->method->get_timeout());
706 }
707
708int SSL_read(SSL *s,char *buf,int num)
709 {
710 if (s->handshake_func == 0)
711 {
712 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
713 return -1;
714 }
715
716 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
717 {
718 s->rwstate=SSL_NOTHING;
719 return(0);
720 }
721 return(s->method->ssl_read(s,buf,num));
722 }
723
724int SSL_peek(SSL *s,char *buf,int num)
725 {
726 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
727 {
728 return(0);
729 }
730 return(s->method->ssl_peek(s,buf,num));
731 }
732
733int SSL_write(SSL *s,const char *buf,int num)
734 {
735 if (s->handshake_func == 0)
736 {
737 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
738 return -1;
739 }
740
741 if (s->shutdown & SSL_SENT_SHUTDOWN)
742 {
743 s->rwstate=SSL_NOTHING;
744 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
745 return(-1);
746 }
747 return(s->method->ssl_write(s,buf,num));
748 }
749
750int SSL_shutdown(SSL *s)
751 {
752 /* Note that this function behaves differently from what one might
753 * expect. Return values are 0 for no success (yet),
754 * 1 for success; but calling it once is usually not enough,
755 * even if blocking I/O is used (see ssl3_shutdown).
756 */
757
758 if (s->handshake_func == 0)
759 {
760 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
761 return -1;
762 }
763
764 if ((s != NULL) && !SSL_in_init(s))
765 return(s->method->ssl_shutdown(s));
766 else
767 return(1);
768 }
769
770int SSL_renegotiate(SSL *s)
771 {
772 s->new_session=1;
773 return(s->method->ssl_renegotiate(s));
774 }
775
776long SSL_ctrl(SSL *s,int cmd,long larg,char *parg)
777 {
778 long l;
779
780 switch (cmd)
781 {
782 case SSL_CTRL_GET_READ_AHEAD:
783 return(s->read_ahead);
784 case SSL_CTRL_SET_READ_AHEAD:
785 l=s->read_ahead;
786 s->read_ahead=larg;
787 return(l);
788 case SSL_CTRL_OPTIONS:
789 return(s->options|=larg);
790 case SSL_CTRL_MODE:
791 return(s->mode|=larg);
792 default:
793 return(s->method->ssl_ctrl(s,cmd,larg,parg));
794 }
795 }
796
797long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
798 {
799 switch(cmd)
800 {
801 default:
802 return(s->method->ssl_callback_ctrl(s,cmd,fp));
803 }
804 }
805
806struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
807 {
808 return ctx->sessions;
809 }
810
811long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
812 {
813 long l;
814
815 switch (cmd)
816 {
817 case SSL_CTRL_GET_READ_AHEAD:
818 return(ctx->read_ahead);
819 case SSL_CTRL_SET_READ_AHEAD:
820 l=ctx->read_ahead;
821 ctx->read_ahead=larg;
822 return(l);
823
824 case SSL_CTRL_SET_SESS_CACHE_SIZE:
825 l=ctx->session_cache_size;
826 ctx->session_cache_size=larg;
827 return(l);
828 case SSL_CTRL_GET_SESS_CACHE_SIZE:
829 return(ctx->session_cache_size);
830 case SSL_CTRL_SET_SESS_CACHE_MODE:
831 l=ctx->session_cache_mode;
832 ctx->session_cache_mode=larg;
833 return(l);
834 case SSL_CTRL_GET_SESS_CACHE_MODE:
835 return(ctx->session_cache_mode);
836
837 case SSL_CTRL_SESS_NUMBER:
838 return(ctx->sessions->num_items);
839 case SSL_CTRL_SESS_CONNECT:
840 return(ctx->stats.sess_connect);
841 case SSL_CTRL_SESS_CONNECT_GOOD:
842 return(ctx->stats.sess_connect_good);
843 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
844 return(ctx->stats.sess_connect_renegotiate);
845 case SSL_CTRL_SESS_ACCEPT:
846 return(ctx->stats.sess_accept);
847 case SSL_CTRL_SESS_ACCEPT_GOOD:
848 return(ctx->stats.sess_accept_good);
849 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
850 return(ctx->stats.sess_accept_renegotiate);
851 case SSL_CTRL_SESS_HIT:
852 return(ctx->stats.sess_hit);
853 case SSL_CTRL_SESS_CB_HIT:
854 return(ctx->stats.sess_cb_hit);
855 case SSL_CTRL_SESS_MISSES:
856 return(ctx->stats.sess_miss);
857 case SSL_CTRL_SESS_TIMEOUTS:
858 return(ctx->stats.sess_timeout);
859 case SSL_CTRL_SESS_CACHE_FULL:
860 return(ctx->stats.sess_cache_full);
861 case SSL_CTRL_OPTIONS:
862 return(ctx->options|=larg);
863 case SSL_CTRL_MODE:
864 return(ctx->mode|=larg);
865 default:
866 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
867 }
868 }
869
870long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
871 {
872 switch(cmd)
873 {
874 default:
875 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
876 }
877 }
878
879int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
880 {
881 long l;
882
883 l=a->id-b->id;
884 if (l == 0L)
885 return(0);
886 else
887 return((l > 0)?1:-1);
888 }
889
890int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
891 const SSL_CIPHER * const *bp)
892 {
893 long l;
894
895 l=(*ap)->id-(*bp)->id;
896 if (l == 0L)
897 return(0);
898 else
899 return((l > 0)?1:-1);
900 }
901
902/** return a STACK of the ciphers available for the SSL and in order of
903 * preference */
904STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s)
905 {
906 if ((s != NULL) && (s->cipher_list != NULL))
907 {
908 return(s->cipher_list);
909 }
910 else if ((s->ctx != NULL) &&
911 (s->ctx->cipher_list != NULL))
912 {
913 return(s->ctx->cipher_list);
914 }
915 return(NULL);
916 }
917
918/** return a STACK of the ciphers available for the SSL and in order of
919 * algorithm id */
920STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
921 {
922 if ((s != NULL) && (s->cipher_list_by_id != NULL))
923 {
924 return(s->cipher_list_by_id);
925 }
926 else if ((s != NULL) && (s->ctx != NULL) &&
927 (s->ctx->cipher_list_by_id != NULL))
928 {
929 return(s->ctx->cipher_list_by_id);
930 }
931 return(NULL);
932 }
933
934/** The old interface to get the same thing as SSL_get_ciphers() */
935const char *SSL_get_cipher_list(SSL *s,int n)
936 {
937 SSL_CIPHER *c;
938 STACK_OF(SSL_CIPHER) *sk;
939
940 if (s == NULL) return(NULL);
941 sk=SSL_get_ciphers(s);
942 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
943 return(NULL);
944 c=sk_SSL_CIPHER_value(sk,n);
945 if (c == NULL) return(NULL);
946 return(c->name);
947 }
948
949/** specify the ciphers to be used by default by the SSL_CTX */
950int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
951 {
952 STACK_OF(SSL_CIPHER) *sk;
953
954 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
955 &ctx->cipher_list_by_id,str);
956/* XXXX */
957 return((sk == NULL)?0:1);
958 }
959
960/** specify the ciphers to be used by the SSL */
961int SSL_set_cipher_list(SSL *s,const char *str)
962 {
963 STACK_OF(SSL_CIPHER) *sk;
964
965 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
966 &s->cipher_list_by_id,str);
967/* XXXX */
968 return((sk == NULL)?0:1);
969 }
970
971/* works well for SSLv2, not so good for SSLv3 */
972char *SSL_get_shared_ciphers(SSL *s,char *buf,int len)
973 {
974 char *p;
975 const char *cp;
976 STACK_OF(SSL_CIPHER) *sk;
977 SSL_CIPHER *c;
978 int i;
979
980 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
981 (len < 2))
982 return(NULL);
983
984 p=buf;
985 sk=s->session->ciphers;
986 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
987 {
988 /* Decrement for either the ':' or a '\0' */
989 len--;
990 c=sk_SSL_CIPHER_value(sk,i);
991 for (cp=c->name; *cp; )
992 {
993 if (len-- == 0)
994 {
995 *p='\0';
996 return(buf);
997 }
998 else
999 *(p++)= *(cp++);
1000 }
1001 *(p++)=':';
1002 }
1003 p[-1]='\0';
1004 return(buf);
1005 }
1006
1007int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p)
1008 {
1009 int i,j=0;
1010 SSL_CIPHER *c;
1011 unsigned char *q;
1012
1013 if (sk == NULL) return(0);
1014 q=p;
1015
1016 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1017 {
1018 c=sk_SSL_CIPHER_value(sk,i);
1019 j=ssl_put_cipher_by_char(s,c,p);
1020 p+=j;
1021 }
1022 return(p-q);
1023 }
1024
1025STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
1026 STACK_OF(SSL_CIPHER) **skp)
1027 {
1028 SSL_CIPHER *c;
1029 STACK_OF(SSL_CIPHER) *sk;
1030 int i,n;
1031
1032 n=ssl_put_cipher_by_char(s,NULL,NULL);
1033 if ((num%n) != 0)
1034 {
1035 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1036 return(NULL);
1037 }
1038 if ((skp == NULL) || (*skp == NULL))
1039 sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */
1040 else
1041 {
1042 sk= *skp;
1043 sk_SSL_CIPHER_zero(sk);
1044 }
1045
1046 for (i=0; i<num; i+=n)
1047 {
1048 c=ssl_get_cipher_by_char(s,p);
1049 p+=n;
1050 if (c != NULL)
1051 {
1052 if (!sk_SSL_CIPHER_push(sk,c))
1053 {
1054 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
1055 goto err;
1056 }
1057 }
1058 }
1059
1060 if (skp != NULL)
1061 *skp=sk;
1062 return(sk);
1063err:
1064 if ((skp == NULL) || (*skp == NULL))
1065 sk_SSL_CIPHER_free(sk);
1066 return(NULL);
1067 }
1068
1069unsigned long SSL_SESSION_hash(SSL_SESSION *a)
1070 {
1071 unsigned long l;
1072
1073 l=(unsigned long)
1074 ((unsigned int) a->session_id[0] )|
1075 ((unsigned int) a->session_id[1]<< 8L)|
1076 ((unsigned long)a->session_id[2]<<16L)|
1077 ((unsigned long)a->session_id[3]<<24L);
1078 return(l);
1079 }
1080
1081int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b)
1082 {
1083 if (a->ssl_version != b->ssl_version)
1084 return(1);
1085 if (a->session_id_length != b->session_id_length)
1086 return(1);
1087 return(memcmp(a->session_id,b->session_id,a->session_id_length));
1088 }
1089
1090SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1091 {
1092 SSL_CTX *ret=NULL;
1093
1094 if (meth == NULL)
1095 {
1096 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
1097 return(NULL);
1098 }
1099
1100 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1101 {
1102 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1103 goto err;
1104 }
1105 ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
1106 if (ret == NULL)
1107 goto err;
1108
1109 memset(ret,0,sizeof(SSL_CTX));
1110
1111 ret->method=meth;
1112
1113 ret->cert_store=NULL;
1114 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1115 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1116 ret->session_cache_head=NULL;
1117 ret->session_cache_tail=NULL;
1118
1119 /* We take the system default */
1120 ret->session_timeout=meth->get_timeout();
1121
1122 ret->new_session_cb=NULL;
1123 ret->remove_session_cb=NULL;
1124 ret->get_session_cb=NULL;
1125
1126 memset((char *)&ret->stats,0,sizeof(ret->stats));
1127
1128 ret->references=1;
1129 ret->quiet_shutdown=0;
1130
1131/* ret->cipher=NULL;*/
1132/* ret->s2->challenge=NULL;
1133 ret->master_key=NULL;
1134 ret->key_arg=NULL;
1135 ret->s2->conn_id=NULL; */
1136
1137 ret->info_callback=NULL;
1138
1139 ret->app_verify_callback=NULL;
1140 ret->app_verify_arg=NULL;
1141
1142 ret->read_ahead=0;
1143 ret->verify_mode=SSL_VERIFY_NONE;
1144 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1145 ret->default_verify_callback=NULL;
1146 if ((ret->cert=ssl_cert_new()) == NULL)
1147 goto err;
1148
1149 ret->default_passwd_callback=NULL;
1150 ret->default_passwd_callback_userdata=NULL;
1151 ret->client_cert_cb=NULL;
1152
1153 ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);
1154 if (ret->sessions == NULL) goto err;
1155 ret->cert_store=X509_STORE_new();
1156 if (ret->cert_store == NULL) goto err;
1157
1158 ssl_create_cipher_list(ret->method,
1159 &ret->cipher_list,&ret->cipher_list_by_id,
1160 SSL_DEFAULT_CIPHER_LIST);
1161 if (ret->cipher_list == NULL
1162 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1163 {
1164 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1165 goto err2;
1166 }
1167
1168 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1169 {
1170 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1171 goto err2;
1172 }
1173 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1174 {
1175 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1176 goto err2;
1177 }
1178 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1179 {
1180 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1181 goto err2;
1182 }
1183
1184 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1185 goto err;
1186
1187 CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);
1188
1189 ret->extra_certs=NULL;
1190 ret->comp_methods=SSL_COMP_get_compression_methods();
1191
1192 return(ret);
1193err:
1194 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1195err2:
1196 if (ret != NULL) SSL_CTX_free(ret);
1197 return(NULL);
1198 }
1199
1200static void SSL_COMP_free(SSL_COMP *comp)
1201 { OPENSSL_free(comp); }
1202
1203void SSL_CTX_free(SSL_CTX *a)
1204 {
1205 int i;
1206
1207 if (a == NULL) return;
1208
1209 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1210#ifdef REF_PRINT
1211 REF_PRINT("SSL_CTX",a);
1212#endif
1213 if (i > 0) return;
1214#ifdef REF_CHECK
1215 if (i < 0)
1216 {
1217 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1218 abort(); /* ok */
1219 }
1220#endif
1221 CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data);
1222
1223 if (a->sessions != NULL)
1224 {
1225 SSL_CTX_flush_sessions(a,0);
1226 lh_free(a->sessions);
1227 }
1228 if (a->cert_store != NULL)
1229 X509_STORE_free(a->cert_store);
1230 if (a->cipher_list != NULL)
1231 sk_SSL_CIPHER_free(a->cipher_list);
1232 if (a->cipher_list_by_id != NULL)
1233 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1234 if (a->cert != NULL)
1235 ssl_cert_free(a->cert);
1236 if (a->client_CA != NULL)
1237 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1238 if (a->extra_certs != NULL)
1239 sk_X509_pop_free(a->extra_certs,X509_free);
1240 if (a->comp_methods != NULL)
1241 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1242 OPENSSL_free(a);
1243 }
1244
1245void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1246 {
1247 ctx->default_passwd_callback=cb;
1248 }
1249
1250void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1251 {
1252 ctx->default_passwd_callback_userdata=u;
1253 }
1254
1255void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,int (*cb)(),char *arg)
1256 {
1257 /* now
1258 * int (*cb)(X509_STORE_CTX *),
1259 * but should be
1260 * int (*cb)(X509_STORE_CTX *, void *arg)
1261 */
1262 ctx->app_verify_callback=cb;
1263 ctx->app_verify_arg=arg; /* never used */
1264 }
1265
1266void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1267 {
1268 ctx->verify_mode=mode;
1269 ctx->default_verify_callback=cb;
1270 /* This needs cleaning up EAY EAY EAY */
1271 X509_STORE_set_verify_cb_func(ctx->cert_store,cb);
1272 }
1273
1274void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1275 {
1276 ctx->verify_depth=depth;
1277 }
1278
1279void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1280 {
1281 CERT_PKEY *cpk;
1282 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1283 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1284 int rsa_tmp_export,dh_tmp_export,kl;
1285 unsigned long mask,emask;
1286
1287 if (c == NULL) return;
1288
1289 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1290
1291#ifndef NO_RSA
1292 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1293 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1294 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1295#else
1296 rsa_tmp=rsa_tmp_export=0;
1297#endif
1298#ifndef NO_DH
1299 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1300 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1301 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1302#else
1303 dh_tmp=dh_tmp_export=0;
1304#endif
1305
1306 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1307 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1308 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1309 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1310 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1311 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1312 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1313 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1314 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1315 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1316 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1317/* FIX THIS EAY EAY EAY */
1318 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1319 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1320
1321 mask=0;
1322 emask=0;
1323
1324#ifdef CIPHER_DEBUG
1325 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1326 rsa_tmp,rsa_tmp_export,dh_tmp,
1327 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1328#endif
1329
1330 if (rsa_enc || (rsa_tmp && rsa_sign))
1331 mask|=SSL_kRSA;
1332 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1333 emask|=SSL_kRSA;
1334
1335#if 0
1336 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1337 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1338 (rsa_enc || rsa_sign || dsa_sign))
1339 mask|=SSL_kEDH;
1340 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1341 (rsa_enc || rsa_sign || dsa_sign))
1342 emask|=SSL_kEDH;
1343#endif
1344
1345 if (dh_tmp_export)
1346 emask|=SSL_kEDH;
1347
1348 if (dh_tmp)
1349 mask|=SSL_kEDH;
1350
1351 if (dh_rsa) mask|=SSL_kDHr;
1352 if (dh_rsa_export) emask|=SSL_kDHr;
1353
1354 if (dh_dsa) mask|=SSL_kDHd;
1355 if (dh_dsa_export) emask|=SSL_kDHd;
1356
1357 if (rsa_enc || rsa_sign)
1358 {
1359 mask|=SSL_aRSA;
1360 emask|=SSL_aRSA;
1361 }
1362
1363 if (dsa_sign)
1364 {
1365 mask|=SSL_aDSS;
1366 emask|=SSL_aDSS;
1367 }
1368
1369 mask|=SSL_aNULL;
1370 emask|=SSL_aNULL;
1371
1372 c->mask=mask;
1373 c->export_mask=emask;
1374 c->valid=1;
1375 }
1376
1377/* THIS NEEDS CLEANING UP */
1378X509 *ssl_get_server_send_cert(SSL *s)
1379 {
1380 unsigned long alg,mask,kalg;
1381 CERT *c;
1382 int i,is_export;
1383
1384 c=s->cert;
1385 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1386 alg=s->s3->tmp.new_cipher->algorithms;
1387 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1388 mask=is_export?c->export_mask:c->mask;
1389 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1390
1391 if (kalg & SSL_kDHr)
1392 i=SSL_PKEY_DH_RSA;
1393 else if (kalg & SSL_kDHd)
1394 i=SSL_PKEY_DH_DSA;
1395 else if (kalg & SSL_aDSS)
1396 i=SSL_PKEY_DSA_SIGN;
1397 else if (kalg & SSL_aRSA)
1398 {
1399 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1400 i=SSL_PKEY_RSA_SIGN;
1401 else
1402 i=SSL_PKEY_RSA_ENC;
1403 }
1404 else /* if (kalg & SSL_aNULL) */
1405 {
1406 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR);
1407 return(NULL);
1408 }
1409 if (c->pkeys[i].x509 == NULL) return(NULL);
1410 return(c->pkeys[i].x509);
1411 }
1412
1413EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1414 {
1415 unsigned long alg;
1416 CERT *c;
1417
1418 alg=cipher->algorithms;
1419 c=s->cert;
1420
1421 if ((alg & SSL_aDSS) &&
1422 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1423 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1424 else if (alg & SSL_aRSA)
1425 {
1426 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1427 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1428 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1429 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1430 else
1431 return(NULL);
1432 }
1433 else /* if (alg & SSL_aNULL) */
1434 {
1435 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR);
1436 return(NULL);
1437 }
1438 }
1439
1440void ssl_update_cache(SSL *s,int mode)
1441 {
1442 int i;
1443
1444 /* If the session_id_length is 0, we are not supposed to cache it,
1445 * and it would be rather hard to do anyway :-) */
1446 if (s->session->session_id_length == 0) return;
1447
1448 if ((s->ctx->session_cache_mode & mode)
1449 && (!s->hit)
1450 && SSL_CTX_add_session(s->ctx,s->session)
1451 && (s->ctx->new_session_cb != NULL))
1452 {
1453 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1454 if (!s->ctx->new_session_cb(s,s->session))
1455 SSL_SESSION_free(s->session);
1456 }
1457
1458 /* auto flush every 255 connections */
1459 i=s->ctx->session_cache_mode;
1460 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1461 ((i & mode) == mode))
1462 {
1463 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1464 ?s->ctx->stats.sess_connect_good
1465 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1466 {
1467 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1468 }
1469 }
1470 }
1471
1472SSL_METHOD *SSL_get_ssl_method(SSL *s)
1473 {
1474 return(s->method);
1475 }
1476
1477int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1478 {
1479 int conn= -1;
1480 int ret=1;
1481
1482 if (s->method != meth)
1483 {
1484 if (s->handshake_func != NULL)
1485 conn=(s->handshake_func == s->method->ssl_connect);
1486
1487 if (s->method->version == meth->version)
1488 s->method=meth;
1489 else
1490 {
1491 s->method->ssl_free(s);
1492 s->method=meth;
1493 ret=s->method->ssl_new(s);
1494 }
1495
1496 if (conn == 1)
1497 s->handshake_func=meth->ssl_connect;
1498 else if (conn == 0)
1499 s->handshake_func=meth->ssl_accept;
1500 }
1501 return(ret);
1502 }
1503
1504int SSL_get_error(SSL *s,int i)
1505 {
1506 int reason;
1507 unsigned long l;
1508 BIO *bio;
1509
1510 if (i > 0) return(SSL_ERROR_NONE);
1511
1512 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1513 * etc, where we do encode the error */
1514 if ((l=ERR_peek_error()) != 0)
1515 {
1516 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1517 return(SSL_ERROR_SYSCALL);
1518 else
1519 return(SSL_ERROR_SSL);
1520 }
1521
1522 if ((i < 0) && SSL_want_read(s))
1523 {
1524 bio=SSL_get_rbio(s);
1525 if (BIO_should_read(bio))
1526 return(SSL_ERROR_WANT_READ);
1527 else if (BIO_should_write(bio))
1528 /* This one doesn't make too much sense ... We never try
1529 * to write to the rbio, and an application program where
1530 * rbio and wbio are separate couldn't even know what it
1531 * should wait for.
1532 * However if we ever set s->rwstate incorrectly
1533 * (so that we have SSL_want_read(s) instead of
1534 * SSL_want_write(s)) and rbio and wbio *are* the same,
1535 * this test works around that bug; so it might be safer
1536 * to keep it. */
1537 return(SSL_ERROR_WANT_WRITE);
1538 else if (BIO_should_io_special(bio))
1539 {
1540 reason=BIO_get_retry_reason(bio);
1541 if (reason == BIO_RR_CONNECT)
1542 return(SSL_ERROR_WANT_CONNECT);
1543 else
1544 return(SSL_ERROR_SYSCALL); /* unknown */
1545 }
1546 }
1547
1548 if ((i < 0) && SSL_want_write(s))
1549 {
1550 bio=SSL_get_wbio(s);
1551 if (BIO_should_write(bio))
1552 return(SSL_ERROR_WANT_WRITE);
1553 else if (BIO_should_read(bio))
1554 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1555 return(SSL_ERROR_WANT_READ);
1556 else if (BIO_should_io_special(bio))
1557 {
1558 reason=BIO_get_retry_reason(bio);
1559 if (reason == BIO_RR_CONNECT)
1560 return(SSL_ERROR_WANT_CONNECT);
1561 else
1562 return(SSL_ERROR_SYSCALL);
1563 }
1564 }
1565 if ((i < 0) && SSL_want_x509_lookup(s))
1566 {
1567 return(SSL_ERROR_WANT_X509_LOOKUP);
1568 }
1569
1570 if (i == 0)
1571 {
1572 if (s->version == SSL2_VERSION)
1573 {
1574 /* assume it is the socket being closed */
1575 return(SSL_ERROR_ZERO_RETURN);
1576 }
1577 else
1578 {
1579 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1580 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1581 return(SSL_ERROR_ZERO_RETURN);
1582 }
1583 }
1584 return(SSL_ERROR_SYSCALL);
1585 }
1586
1587int SSL_do_handshake(SSL *s)
1588 {
1589 int ret=1;
1590
1591 if (s->handshake_func == NULL)
1592 {
1593 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1594 return(-1);
1595 }
1596
1597 s->method->ssl_renegotiate_check(s);
1598
1599 if (SSL_in_init(s) || SSL_in_before(s))
1600 {
1601 ret=s->handshake_func(s);
1602 }
1603 return(ret);
1604 }
1605
1606/* For the next 2 functions, SSL_clear() sets shutdown and so
1607 * one of these calls will reset it */
1608void SSL_set_accept_state(SSL *s)
1609 {
1610 s->server=1;
1611 s->shutdown=0;
1612 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1613 s->handshake_func=s->method->ssl_accept;
1614 /* clear the current cipher */
1615 ssl_clear_cipher_ctx(s);
1616 }
1617
1618void SSL_set_connect_state(SSL *s)
1619 {
1620 s->server=0;
1621 s->shutdown=0;
1622 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1623 s->handshake_func=s->method->ssl_connect;
1624 /* clear the current cipher */
1625 ssl_clear_cipher_ctx(s);
1626 }
1627
1628int ssl_undefined_function(SSL *s)
1629 {
1630 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1631 return(0);
1632 }
1633
1634SSL_METHOD *ssl_bad_method(int ver)
1635 {
1636 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1637 return(NULL);
1638 }
1639
1640const char *SSL_get_version(SSL *s)
1641 {
1642 if (s->version == TLS1_VERSION)
1643 return("TLSv1");
1644 else if (s->version == SSL3_VERSION)
1645 return("SSLv3");
1646 else if (s->version == SSL2_VERSION)
1647 return("SSLv2");
1648 else
1649 return("unknown");
1650 }
1651
1652SSL *SSL_dup(SSL *s)
1653 {
1654 STACK_OF(X509_NAME) *sk;
1655 X509_NAME *xn;
1656 SSL *ret;
1657 int i;
1658
1659 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1660 return(NULL);
1661
1662 if (s->session != NULL)
1663 {
1664 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1665 SSL_copy_session_id(ret,s);
1666 }
1667 else
1668 {
1669 /* No session has been established yet, so we have to expect
1670 * that s->cert or ret->cert will be changed later --
1671 * they should not both point to the same object,
1672 * and thus we can't use SSL_copy_session_id. */
1673
1674 ret->method = s->method;
1675 ret->method->ssl_new(ret);
1676
1677 if (s->cert != NULL)
1678 {
1679 ret->cert = ssl_cert_dup(s->cert);
1680 if (ret->cert == NULL)
1681 goto err;
1682 }
1683
1684 SSL_set_session_id_context(ret,
1685 s->sid_ctx, s->sid_ctx_length);
1686 }
1687
1688 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1689 SSL_set_verify(ret,SSL_get_verify_mode(s),
1690 SSL_get_verify_callback(s));
1691 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1692
1693 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1694
1695 ret->debug=s->debug;
1696 ret->options=s->options;
1697
1698 /* copy app data, a little dangerous perhaps */
1699 if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data))
1700 goto err;
1701
1702 /* setup rbio, and wbio */
1703 if (s->rbio != NULL)
1704 {
1705 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1706 goto err;
1707 }
1708 if (s->wbio != NULL)
1709 {
1710 if (s->wbio != s->rbio)
1711 {
1712 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1713 goto err;
1714 }
1715 else
1716 ret->wbio=ret->rbio;
1717 }
1718
1719 /* dup the cipher_list and cipher_list_by_id stacks */
1720 if (s->cipher_list != NULL)
1721 {
1722 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
1723 goto err;
1724 }
1725 if (s->cipher_list_by_id != NULL)
1726 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
1727 == NULL)
1728 goto err;
1729
1730 /* Dup the client_CA list */
1731 if (s->client_CA != NULL)
1732 {
1733 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
1734 ret->client_CA=sk;
1735 for (i=0; i<sk_X509_NAME_num(sk); i++)
1736 {
1737 xn=sk_X509_NAME_value(sk,i);
1738 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
1739 {
1740 X509_NAME_free(xn);
1741 goto err;
1742 }
1743 }
1744 }
1745
1746 ret->shutdown=s->shutdown;
1747 ret->state=s->state;
1748 ret->handshake_func=s->handshake_func;
1749 ret->server=s->server;
1750
1751 if (0)
1752 {
1753err:
1754 if (ret != NULL) SSL_free(ret);
1755 ret=NULL;
1756 }
1757 return(ret);
1758 }
1759
1760void ssl_clear_cipher_ctx(SSL *s)
1761 {
1762 if (s->enc_read_ctx != NULL)
1763 {
1764 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1765 OPENSSL_free(s->enc_read_ctx);
1766 s->enc_read_ctx=NULL;
1767 }
1768 if (s->enc_write_ctx != NULL)
1769 {
1770 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1771 OPENSSL_free(s->enc_write_ctx);
1772 s->enc_write_ctx=NULL;
1773 }
1774 if (s->expand != NULL)
1775 {
1776 COMP_CTX_free(s->expand);
1777 s->expand=NULL;
1778 }
1779 if (s->compress != NULL)
1780 {
1781 COMP_CTX_free(s->compress);
1782 s->compress=NULL;
1783 }
1784 }
1785
1786/* Fix this function so that it takes an optional type parameter */
1787X509 *SSL_get_certificate(SSL *s)
1788 {
1789 if (s->cert != NULL)
1790 return(s->cert->key->x509);
1791 else
1792 return(NULL);
1793 }
1794
1795/* Fix this function so that it takes an optional type parameter */
1796EVP_PKEY *SSL_get_privatekey(SSL *s)
1797 {
1798 if (s->cert != NULL)
1799 return(s->cert->key->privatekey);
1800 else
1801 return(NULL);
1802 }
1803
1804SSL_CIPHER *SSL_get_current_cipher(SSL *s)
1805 {
1806 if ((s->session != NULL) && (s->session->cipher != NULL))
1807 return(s->session->cipher);
1808 return(NULL);
1809 }
1810
1811int ssl_init_wbio_buffer(SSL *s,int push)
1812 {
1813 BIO *bbio;
1814
1815 if (s->bbio == NULL)
1816 {
1817 bbio=BIO_new(BIO_f_buffer());
1818 if (bbio == NULL) return(0);
1819 s->bbio=bbio;
1820 }
1821 else
1822 {
1823 bbio=s->bbio;
1824 if (s->bbio == s->wbio)
1825 s->wbio=BIO_pop(s->wbio);
1826 }
1827 (void)BIO_reset(bbio);
1828/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
1829 if (!BIO_set_read_buffer_size(bbio,1))
1830 {
1831 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
1832 return(0);
1833 }
1834 if (push)
1835 {
1836 if (s->wbio != bbio)
1837 s->wbio=BIO_push(bbio,s->wbio);
1838 }
1839 else
1840 {
1841 if (s->wbio == bbio)
1842 s->wbio=BIO_pop(bbio);
1843 }
1844 return(1);
1845 }
1846
1847void ssl_free_wbio_buffer(SSL *s)
1848 {
1849 if (s->bbio == NULL) return;
1850
1851 if (s->bbio == s->wbio)
1852 {
1853 /* remove buffering */
1854 s->wbio=BIO_pop(s->wbio);
1855#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */
1856 assert(s->wbio != NULL);
1857#endif
1858 }
1859 BIO_free(s->bbio);
1860 s->bbio=NULL;
1861 }
1862
1863void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1864 {
1865 ctx->quiet_shutdown=mode;
1866 }
1867
1868int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx)
1869 {
1870 return(ctx->quiet_shutdown);
1871 }
1872
1873void SSL_set_quiet_shutdown(SSL *s,int mode)
1874 {
1875 s->quiet_shutdown=mode;
1876 }
1877
1878int SSL_get_quiet_shutdown(SSL *s)
1879 {
1880 return(s->quiet_shutdown);
1881 }
1882
1883void SSL_set_shutdown(SSL *s,int mode)
1884 {
1885 s->shutdown=mode;
1886 }
1887
1888int SSL_get_shutdown(SSL *s)
1889 {
1890 return(s->shutdown);
1891 }
1892
1893int SSL_version(SSL *s)
1894 {
1895 return(s->version);
1896 }
1897
1898SSL_CTX *SSL_get_SSL_CTX(SSL *ssl)
1899 {
1900 return(ssl->ctx);
1901 }
1902
1903#ifndef NO_STDIO
1904int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
1905 {
1906 return(X509_STORE_set_default_paths(ctx->cert_store));
1907 }
1908
1909int 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
1916void SSL_set_info_callback(SSL *ssl,void (*cb)())
1917 {
1918 ssl->info_callback=cb;
1919 }
1920
1921void (*SSL_get_info_callback(SSL *ssl))(void)
1922 {
1923 return((void (*)())ssl->info_callback);
1924 }
1925
1926int SSL_state(SSL *ssl)
1927 {
1928 return(ssl->state);
1929 }
1930
1931void SSL_set_verify_result(SSL *ssl,long arg)
1932 {
1933 ssl->verify_result=arg;
1934 }
1935
1936long SSL_get_verify_result(SSL *ssl)
1937 {
1938 return(ssl->verify_result);
1939 }
1940
1941int 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
1949int SSL_set_ex_data(SSL *s,int idx,void *arg)
1950 {
1951 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1952 }
1953
1954void *SSL_get_ex_data(SSL *s,int idx)
1955 {
1956 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1957 }
1958
1959int 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
1967int 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
1972void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx)
1973 {
1974 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1975 }
1976
1977int ssl_ok(SSL *s)
1978 {
1979 return(1);
1980 }
1981
1982X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx)
1983 {
1984 return(ctx->cert_store);
1985 }
1986
1987void 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
1994int 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
2006void 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
2013void 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
2032RSA *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
2043void 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
2049void 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
2060IMPLEMENT_STACK_OF(SSL_CIPHER)
2061IMPLEMENT_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 d70fff4627..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,556 +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
299typedef struct cert_pkey_st
300 {
301 X509 *x509;
302 EVP_PKEY *privatekey;
303 } CERT_PKEY;
304
305typedef 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
332typedef 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 :-) */
375typedef 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 */
393typedef 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
400OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method;
401OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
402OPENSSL_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
410SSL_METHOD *ssl_bad_method(int ver);
411SSL_METHOD *sslv2_base_method(void);
412SSL_METHOD *sslv23_base_method(void);
413SSL_METHOD *sslv3_base_method(void);
414
415void ssl_clear_cipher_ctx(SSL *s);
416int ssl_clear_bad_session(SSL *s);
417CERT *ssl_cert_new(void);
418CERT *ssl_cert_dup(CERT *cert);
419int ssl_cert_inst(CERT **o);
420void ssl_cert_free(CERT *c);
421SESS_CERT *ssl_sess_cert_new(void);
422void ssl_sess_cert_free(SESS_CERT *sc);
423int ssl_set_peer_cert_type(SESS_CERT *c, int type);
424int ssl_get_new_session(SSL *s, int session);
425int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
426int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);
427int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
428 const SSL_CIPHER * const *bp);
429STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
430 STACK_OF(SSL_CIPHER) **skp);
431int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
432STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
433 STACK_OF(SSL_CIPHER) **pref,
434 STACK_OF(SSL_CIPHER) **sorted,
435 const char *rule_str);
436void ssl_update_cache(SSL *s, int mode);
437int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md,
438 SSL_COMP **comp);
439int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
440int ssl_undefined_function(SSL *s);
441X509 *ssl_get_server_send_cert(SSL *);
442EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
443int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
444void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
445STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
446int ssl_verify_alarm_type(long type);
447
448int ssl2_enc_init(SSL *s, int client);
449void ssl2_generate_key_material(SSL *s);
450void ssl2_enc(SSL *s,int send_data);
451void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
452SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
453int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
454int ssl2_part_read(SSL *s, unsigned long f, int i);
455int ssl2_do_write(SSL *s);
456int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
457void ssl2_return_error(SSL *s,int reason);
458void ssl2_write_error(SSL *s);
459int ssl2_num_ciphers(void);
460SSL_CIPHER *ssl2_get_cipher(unsigned int u);
461int ssl2_new(SSL *s);
462void ssl2_free(SSL *s);
463int ssl2_accept(SSL *s);
464int ssl2_connect(SSL *s);
465int ssl2_read(SSL *s, void *buf, int len);
466int ssl2_peek(SSL *s, char *buf, int len);
467int ssl2_write(SSL *s, const void *buf, int len);
468int ssl2_shutdown(SSL *s);
469void ssl2_clear(SSL *s);
470long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg);
471long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
472long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)());
473long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
474int ssl2_pending(SSL *s);
475
476SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
477int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
478void ssl3_init_finished_mac(SSL *s);
479int ssl3_send_server_certificate(SSL *s);
480int ssl3_get_finished(SSL *s,int state_a,int state_b);
481int ssl3_setup_key_block(SSL *s);
482int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
483int ssl3_change_cipher_state(SSL *s,int which);
484void ssl3_cleanup_key_block(SSL *s);
485int ssl3_do_write(SSL *s,int type);
486void ssl3_send_alert(SSL *s,int level, int desc);
487int ssl3_generate_master_secret(SSL *s, unsigned char *out,
488 unsigned char *p, int len);
489int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
490long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
491int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
492int ssl3_num_ciphers(void);
493SSL_CIPHER *ssl3_get_cipher(unsigned int u);
494int ssl3_renegotiate(SSL *ssl);
495int ssl3_renegotiate_check(SSL *ssl);
496int ssl3_dispatch_alert(SSL *s);
497int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len);
498int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
499int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
500 const char *sender, int slen,unsigned char *p);
501int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
502void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
503int ssl3_enc(SSL *s, int send_data);
504int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
505unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
506SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *have,
507 STACK_OF(SSL_CIPHER) *pref);
508int ssl3_setup_buffers(SSL *s);
509int ssl3_new(SSL *s);
510void ssl3_free(SSL *s);
511int ssl3_accept(SSL *s);
512int ssl3_connect(SSL *s);
513int ssl3_read(SSL *s, void *buf, int len);
514int ssl3_peek(SSL *s,char *buf, int len);
515int ssl3_write(SSL *s, const void *buf, int len);
516int ssl3_shutdown(SSL *s);
517void ssl3_clear(SSL *s);
518long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg);
519long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
520long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)());
521long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
522int ssl3_pending(SSL *s);
523
524int ssl23_accept(SSL *s);
525int ssl23_connect(SSL *s);
526int ssl23_read_bytes(SSL *s, int n);
527int ssl23_write_bytes(SSL *s);
528
529int tls1_new(SSL *s);
530void tls1_free(SSL *s);
531void tls1_clear(SSL *s);
532long tls1_ctrl(SSL *s,int cmd, long larg, char *parg);
533long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)());
534SSL_METHOD *tlsv1_base_method(void );
535
536int ssl_init_wbio_buffer(SSL *s, int push);
537void ssl_free_wbio_buffer(SSL *s);
538
539int tls1_change_cipher_state(SSL *s, int which);
540int tls1_setup_key_block(SSL *s);
541int tls1_enc(SSL *s, int snd);
542int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
543 const char *str, int slen, unsigned char *p);
544int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
545int tls1_mac(SSL *ssl, unsigned char *md, int snd);
546int tls1_generate_master_secret(SSL *s, unsigned char *out,
547 unsigned char *p, int len);
548int tls1_alert_code(int code);
549int ssl3_alert_code(int code);
550int ssl_ok(SSL *s);
551
552SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
553STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
554
555
556#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
67static int ssl_set_cert(CERT *c, X509 *x509);
68static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
69int 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
85int 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);
127end:
128 if (x != NULL) X509_free(x);
129 if (in != NULL) BIO_free(in);
130 return(ret);
131 }
132#endif
133
134int 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
152int 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
182static 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
256int 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);
297end:
298 if (in != NULL) BIO_free(in);
299 return(ret);
300 }
301#endif
302
303int 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
322int 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
341int 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);
377end:
378 if (in != NULL) BIO_free(in);
379 return(ret);
380 }
381#endif
382
383int 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
401int 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
416static 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
497int 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);
539end:
540 if (x != NULL) X509_free(x);
541 if (in != NULL) BIO_free(in);
542 return(ret);
543 }
544#endif
545
546int 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
564int 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
594int 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);
635end:
636 if (in != NULL) BIO_free(in);
637 return(ret);
638 }
639#endif
640
641int 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
660int 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
676int 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);
712end:
713 if (in != NULL) BIO_free(in);
714 return(ret);
715 }
716#endif
717
718int 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 */
743int 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
810end:
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 416def8908..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
64static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
65static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
66static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
67static int ssl_session_num=0;
68static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_session_meth=NULL;
69
70SSL_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
76SSL_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
91int 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
100int 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
105void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx)
106 {
107 return(CRYPTO_get_ex_data(&s->ex_data,idx));
108 }
109
110SSL_SESSION *SSL_SESSION_new(void)
111 {
112 SSL_SESSION *ss;
113
114 ss=(SSL_SESSION *)OPENSSL_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
133int 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
211int 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,&copy))
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 'OPENSSL_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
348int 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
413int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
414{
415 return remove_session_lock(ctx, c, 1);
416}
417
418static 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
448void 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 OPENSSL_free(ss);
478 }
479
480int 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
533long 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
540long SSL_SESSION_get_timeout(SSL_SESSION *s)
541 {
542 if (s == NULL) return(0);
543 return(s->timeout);
544 }
545
546long SSL_SESSION_get_time(SSL_SESSION *s)
547 {
548 if (s == NULL) return(0);
549 return(s->time);
550 }
551
552long 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
559long 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
568long SSL_CTX_get_timeout(SSL_CTX *s)
569 {
570 if (s == NULL) return(0);
571 return(s->session_timeout);
572 }
573
574typedef struct timeout_param_st
575 {
576 SSL_CTX *ctx;
577 long time;
578 LHASH *cache;
579 } TIMEOUT_PARAM;
580
581static 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
596void 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
613int 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 */
627static 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
660static 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
62char *SSL_state_string_long(SSL *s)
63 {
64 char *str;
65
66 switch (s->state)
67 {
68case SSL_ST_BEFORE: str="before SSL initialization"; break;
69case SSL_ST_ACCEPT: str="before accept initialization"; break;
70case SSL_ST_CONNECT: str="before connect initialization"; break;
71case SSL_ST_OK: str="SSL negotiation finished successfully"; break;
72case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break;
73case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initialization"; break;
74case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initialization"; break;
75case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initialization"; break;
76case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initialization"; break;
77#ifndef NO_SSL2
78case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break;
79case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break;
80case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break;
81case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break;
82case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break;
83case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break;
84case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break;
85case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break;
86case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break;
87case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break;
88case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break;
89case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break;
90case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break;
91case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break;
92case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break;
93case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break;
94case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break;
95case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break;
96case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break;
97case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break;
98case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break;
99case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break;
100case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break;
101case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break;
102case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break;
103case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break;
104case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break;
105case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break;
106case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break;
107case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break;
108case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break;
109case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break;
110case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break;
111case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break;
112case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break;
113case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break;
114case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break;
115case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break;
116#endif
117
118#ifndef NO_SSL3
119/* SSLv3 additions */
120case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break;
121case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break;
122case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break;
123case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break;
124case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break;
125case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break;
126case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break;
127case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break;
128case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break;
129case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break;
130case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break;
131case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break;
132case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break;
133case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break;
134case SSL3_ST_CW_CERT_C: str="SSLv3 write client certificate C"; break;
135case SSL3_ST_CW_CERT_D: str="SSLv3 write client certificate D"; break;
136case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break;
137case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break;
138case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break;
139case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify A"; break;
140
141case SSL3_ST_CW_CHANGE_A:
142case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break;
143case SSL3_ST_CW_CHANGE_B:
144case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break;
145case SSL3_ST_CW_FINISHED_A:
146case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break;
147case SSL3_ST_CW_FINISHED_B:
148case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished A"; break;
149case SSL3_ST_CR_CHANGE_A:
150case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break;
151case SSL3_ST_CR_CHANGE_B:
152case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break;
153case SSL3_ST_CR_FINISHED_A:
154case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break;
155case SSL3_ST_CR_FINISHED_B:
156case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break;
157
158case SSL3_ST_CW_FLUSH:
159case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break;
160
161case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break;
162case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break;
163case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break;
164case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break;
165case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break;
166case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break;
167case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break;
168case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break;
169case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break;
170case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break;
171case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break;
172case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break;
173case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break;
174case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break;
175case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break;
176case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break;
177case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break;
178case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break;
179case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break;
180case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break;
181case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break;
182case 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 */
188case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break;
189case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break;
190case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break;
191case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break;
192/* server */
193case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break;
194case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break;
195#endif
196
197default: str="unknown state"; break;
198 }
199 return(str);
200 }
201
202char *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
216char *SSL_state_string(SSL *s)
217 {
218 char *str;
219
220 switch (s->state)
221 {
222case SSL_ST_BEFORE: str="PINIT "; break;
223case SSL_ST_ACCEPT: str="AINIT "; break;
224case SSL_ST_CONNECT: str="CINIT "; break;
225case SSL_ST_OK: str="SSLOK "; break;
226#ifndef NO_SSL2
227case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break;
228case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break;
229case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break;
230case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break;
231case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break;
232case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break;
233case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break;
234case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break;
235case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break;
236case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break;
237case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break;
238case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break;
239case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break;
240case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break;
241case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break;
242case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break;
243case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break;
244case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break;
245case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break;
246case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break;
247case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break;
248case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break;
249case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break;
250case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break;
251case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break;
252case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break;
253case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break;
254case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break;
255case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break;
256case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break;
257case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break;
258case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break;
259case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break;
260case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break;
261case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break;
262case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break;
263case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break;
264case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break;
265#endif
266
267#ifndef NO_SSL3
268/* SSLv3 additions */
269case SSL3_ST_SW_FLUSH:
270case SSL3_ST_CW_FLUSH: str="3FLUSH"; break;
271case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break;
272case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break;
273case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break;
274case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break;
275case SSL3_ST_CR_CERT_A: str="3RSC_A"; break;
276case SSL3_ST_CR_CERT_B: str="3RSC_B"; break;
277case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break;
278case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break;
279case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break;
280case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break;
281case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break;
282case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break;
283case SSL3_ST_CW_CERT_A: str="3WCC_A"; break;
284case SSL3_ST_CW_CERT_B: str="3WCC_B"; break;
285case SSL3_ST_CW_CERT_C: str="3WCC_C"; break;
286case SSL3_ST_CW_CERT_D: str="3WCC_D"; break;
287case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break;
288case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break;
289case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break;
290case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break;
291
292case SSL3_ST_SW_CHANGE_A:
293case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break;
294case SSL3_ST_SW_CHANGE_B:
295case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break;
296case SSL3_ST_SW_FINISHED_A:
297case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break;
298case SSL3_ST_SW_FINISHED_B:
299case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break;
300case SSL3_ST_SR_CHANGE_A:
301case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break;
302case SSL3_ST_SR_CHANGE_B:
303case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break;
304case SSL3_ST_SR_FINISHED_A:
305case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break;
306case SSL3_ST_SR_FINISHED_B:
307case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break;
308
309case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break;
310case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break;
311case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break;
312case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break;
313case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break;
314case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break;
315case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break;
316case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break;
317case SSL3_ST_SW_CERT_A: str="3WSC_A"; break;
318case SSL3_ST_SW_CERT_B: str="3WSC_B"; break;
319case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break;
320case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break;
321case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break;
322case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break;
323case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break;
324case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break;
325case SSL3_ST_SR_CERT_A: str="3RCC_A"; break;
326case SSL3_ST_SR_CERT_B: str="3RCC_B"; break;
327case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break;
328case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break;
329case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break;
330case 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 */
336case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break;
337case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break;
338case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break;
339case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break;
340/* server */
341case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break;
342case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break;
343#endif
344
345default: str="UNKWN "; break;
346 }
347 return(str);
348 }
349
350char *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
361char *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
372char *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
395char *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
442char *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 6e33eec3e4..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,174 +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
64int 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
81int SSL_SESSION_print(BIO *bp, SSL_SESSION *x)
82 {
83 unsigned int i;
84 char *s;
85
86 if (x == NULL) goto err;
87 if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
88 if (x->ssl_version == SSL2_VERSION)
89 s="SSLv2";
90 else if (x->ssl_version == SSL3_VERSION)
91 s="SSLv3";
92 else if (x->ssl_version == TLS1_VERSION)
93 s="TLSv1";
94 else
95 s="unknown";
96 if (BIO_printf(bp," Protocol : %s\n",s) <= 0) goto err;
97
98 if (x->cipher == NULL)
99 {
100 if (((x->cipher_id) & 0xff000000) == 0x02000000)
101 {
102 if (BIO_printf(bp," Cipher : %06lX\n",x->cipher_id&0xffffff) <= 0)
103 goto err;
104 }
105 else
106 {
107 if (BIO_printf(bp," Cipher : %04lX\n",x->cipher_id&0xffff) <= 0)
108 goto err;
109 }
110 }
111 else
112 {
113 if (BIO_printf(bp," Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0)
114 goto err;
115 }
116 if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
117 for (i=0; i<x->session_id_length; i++)
118 {
119 if (BIO_printf(bp,"%02X",x->session_id[i]) <= 0) goto err;
120 }
121 if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err;
122 for (i=0; i<x->sid_ctx_length; i++)
123 {
124 if (BIO_printf(bp,"%02X",x->sid_ctx[i]) <= 0)
125 goto err;
126 }
127 if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
128 for (i=0; i<(unsigned int)x->master_key_length; i++)
129 {
130 if (BIO_printf(bp,"%02X",x->master_key[i]) <= 0) goto err;
131 }
132 if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
133 if (x->key_arg_length == 0)
134 {
135 if (BIO_puts(bp,"None") <= 0) goto err;
136 }
137 else
138 for (i=0; i<x->key_arg_length; i++)
139 {
140 if (BIO_printf(bp,"%02X",x->key_arg[i]) <= 0) goto err;
141 }
142 if (x->compress_meth != 0)
143 {
144 SSL_COMP *comp;
145
146 ssl_cipher_get_evp(x,NULL,NULL,&comp);
147 if (comp == NULL)
148 {
149 if (BIO_printf(bp,"\n Compression: %d",x->compress_meth) <= 0) goto err;
150 }
151 else
152 {
153 if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err;
154 }
155 }
156 if (x->time != 0L)
157 {
158 if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err;
159 }
160 if (x->timeout != 0L)
161 {
162 if (BIO_printf(bp, "\n Timeout : %ld (sec)",x->timeout) <= 0) goto err;
163 }
164 if (BIO_puts(bp,"\n") <= 0) goto err;
165
166 if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
167 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
168 X509_verify_cert_error_string(x->verify_result)) <= 0) goto err;
169
170 return(1);
171err:
172 return(0);
173 }
174
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
66static SSL_METHOD *tls1_get_client_method(int ver);
67static 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
75SSL_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 0d34357eb4..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
67static 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
111static 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
132static 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
153int 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 OPENSSL_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 OPENSSL_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 OPENSSL_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
273printf("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
315printf("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'); }
317printf("\niv=");
318{ int z; for (z=0; z<k; z++) printf("%02X%c",iv[z],((z+1)%16)?' ':'\n'); }
319printf("\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);
327err:
328 SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);
329err2:
330 return(0);
331 }
332
333int 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 *)OPENSSL_malloc(num)) == NULL)
359 goto err;
360 if ((p2=(unsigned char *)OPENSSL_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
368printf("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'); }
370printf("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'); }
372printf("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 OPENSSL_free(p2);
378#ifdef TLS_DEBUG
379printf("\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);
384err:
385 SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK,ERR_R_MALLOC_FAILURE);
386 return(0);
387 }
388
389int 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
486int 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
496int 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
523int 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
564printf("sec=");
565{unsigned int z; for (z=0; z<md_size; z++) printf("%02X ",mac_sec[z]); printf("\n"); }
566printf("seq=");
567{int z; for (z=0; z<8; z++) printf("%02X ",seq[z]); printf("\n"); }
568printf("buf=");
569{int z; for (z=0; z<5; z++) printf("%02X ",buf[z]); printf("\n"); }
570printf("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
583int 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
602int 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
63const char *tls1_version_str="TLSv1" OPENSSL_VERSION_PTEXT;
64
65static long tls1_default_timeout(void);
66
67static 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
81static 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
109static 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
116SSL_METHOD *tlsv1_base_method(void)
117 {
118 return(&TLSv1_data);
119 }
120
121int tls1_new(SSL *s)
122 {
123 if (!ssl3_new(s)) return(0);
124 s->method->ssl_clear(s);
125 return(1);
126 }
127
128void tls1_free(SSL *s)
129 {
130 ssl3_free(s);
131 }
132
133void tls1_clear(SSL *s)
134 {
135 ssl3_clear(s);
136 s->version=TLS1_VERSION;
137 }
138
139#if 0
140long tls1_ctrl(SSL *s, int cmd, long larg, char *parg)
141 {
142 return(0);
143 }
144
145long 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
63static SSL_METHOD *tls1_get_method(int ver);
64static SSL_METHOD *tls1_get_method(int ver)
65 {
66 if (ver == TLS1_VERSION)
67 return(TLSv1_method());
68 else
69 return(NULL);
70 }
71
72SSL_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
67static SSL_METHOD *tls1_get_server_method(int ver);
68static 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
76SSL_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
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = sha1
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
24commonName = Common Name (eg, YOUR name)
25commonName_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
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = CU
17countryName_value = CU
18
19organizationName = Organization Name (eg, company)
20organizationName_value = La Junta de la Revolucion
21
22commonName = Common Name (eg, YOUR name)
23commonName_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
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_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
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_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
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.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
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.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
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.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 @@
1y
2y
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
66int main(argc,argv)
67int argc;
68char *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);
100err:
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-----
2MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG
3SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE
4AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF
5eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4
6MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv
7bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK
8ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB
9FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N
109XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8
11BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w
12bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB
13BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C
14j7Kie1x339mxW/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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl crl'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testcrl.pem
12fi
13
14echo testing crl conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 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
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 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
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 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
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 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
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 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
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 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
6RANDFILE = ./.rnd
7
8####################################################################
9[ ca ]
10default_ca = CA_default # The default ca section
11
12####################################################################
13[ CA_default ]
14
15dir = ./demoCA # Where everything is kept
16certs = $dir/certs # Where the issued certs are kept
17crl_dir = $dir/crl # Where the issued crl are kept
18database = $dir/index.txt # database index file.
19new_certs_dir = $dir/new_certs # default place for new certs.
20
21certificate = $dir/CAcert.pem # The CA certificate
22serial = $dir/serial # The current serial number
23crl = $dir/crl.pem # The current CRL
24private_key = $dir/private/CAkey.pem# The private key
25RANDFILE = $dir/private/.rand # private random number file
26
27default_days = 365 # how long to certify for
28default_crl_days= 30 # how long before next CRL
29default_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 :-)
34policy = policy_match
35
36# For the CA policy
37[ policy_match ]
38countryName = match
39stateOrProvinceName = match
40organizationName = match
41organizationalUnitName = optional
42commonName = supplied
43emailAddress = optional
44
45# For the 'anything' policy
46# At this point in time, you must list all acceptable 'object'
47# types.
48[ policy_anything ]
49countryName = optional
50stateOrProvinceName = optional
51localityName = optional
52organizationName = optional
53organizationalUnitName = optional
54commonName = supplied
55emailAddress = optional
56
57####################################################################
58[ req ]
59default_bits = 512
60default_keyfile = testkey.pem
61distinguished_name = req_distinguished_name
62encrypt_rsa_key = no
63
64[ req_distinguished_name ]
65countryName = Country Name (2 letter code)
66countryName_default = AU
67countryName_value = AU
68
69stateOrProvinceName = State or Province Name (full name)
70stateOrProvinceName_default = Queensland
71stateOrProvinceName_value =
72
73localityName = Locality Name (eg, city)
74localityName_value = Brisbane
75
76organizationName = Organization Name (eg, company)
77organizationName_default =
78organizationName_value = CryptSoft Pty Ltd
79
80organizationalUnitName = Organizational Unit Name (eg, section)
81organizationalUnitName_default =
82organizationalUnitName_value = .
83
84commonName = Common Name (eg, YOUR name)
85commonName_value = Eric Young
86
87emailAddress = Email Address
88emailAddress_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
3SH="/bin/sh"
4PATH=../apps:$PATH
5export SH PATH
6
7SSLEAY_CONFIG="-config CAss.cnf"
8export SSLEAY_CONFIG
9
10/bin/rm -fr demoCA
11$SH ../apps/CA.sh -newca <<EOF
12EOF
13
14if [ $? != 0 ]; then
15 exit 1;
16fi
17
18SSLEAY_CONFIG="-config Uss.cnf"
19export SSLEAY_CONFIG
20$SH ../apps/CA.sh -newreq
21if [ $? != 0 ]; then
22 exit 1;
23fi
24
25
26SSLEAY_CONFIG="-config ../apps/openssl.cnf"
27export SSLEAY_CONFIG
28$SH ../apps/CA.sh -sign <<EOF
29y
30y
31EOF
32if [ $? != 0 ]; then
33 exit 1;
34fi
35
36
37$SH ../apps/CA.sh -verify newcert.pem
38if [ $? != 0 ]; then
39 exit 1;
40fi
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-----
2MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT
3F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy
4IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw
5MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw
6MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw
7MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw
8MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw
9MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw
10MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw
11NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw
12NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF
13AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ
14wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt
15JaAL3iTJHJD55kK2D/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
3testsrc=Makefile.ssl
4test=./p
5cmd=../apps/openssl
6
7cat $testsrc >$test;
8
9echo cat
10$cmd enc < $test > $test.cipher
11$cmd enc < $test.cipher >$test.clear
12cmp $test $test.clear
13if [ $? != 0 ]
14then
15 exit 1
16else
17 /bin/rm $test.cipher $test.clear
18fi
19echo base64
20$cmd enc -a -e < $test > $test.cipher
21$cmd enc -a -d < $test.cipher >$test.clear
22cmp $test $test.clear
23if [ $? != 0 ]
24then
25 exit 1
26else
27 /bin/rm $test.cipher $test.clear
28fi
29
30for i in `$cmd list-cipher-commands`
31do
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
53done
54rm -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
3T=testcert
4KEY=512
5CA=../certs/testca.pem
6
7/bin/rm -f $T.1 $T.2 $T.key
8
9PATH=../apps:$PATH;
10export PATH
11
12echo "generating certificate request"
13
14echo "There should be a 2 sequences of .'s and some +'s."
15echo "There should not be more that at most 80 per line"
16echo "This could take some time."
17
18echo "string to make the random number generator think it has entropy" >> ./.rnd
19
20../apps/openssl req -config test.cnf -new -out testreq.pem
21if [ $? != 0 ]; then
22echo problems creating request
23exit 1
24fi
25
26../apps/openssl req -config test.cnf -verify -in testreq.pem -noout
27if [ $? != 0 ]; then
28echo signature on req is wrong
29exit 1
30fi
31
32exit 0
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem
deleted file mode 100644
index e5b7866c31..0000000000
--- a/src/lib/libssl/test/testp7.pem
+++ /dev/null
@@ -1,46 +0,0 @@
1-----BEGIN PKCS7-----
2MIIIGAYJKoZIhvcNAQcCoIIICTCCCAUCAQExADALBgkqhkiG9w0BBwGgggY8MIIE
3cjCCBBygAwIBAgIQeS+OJfWJUZAx6cX0eAiMjzANBgkqhkiG9w0BAQQFADBiMREw
4DwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNV
5BAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIw
6HhcNOTYwNzE5MDAwMDAwWhcNOTcwMzMwMjM1OTU5WjCB1TERMA8GA1UEBxMISW50
7ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln
8biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMSgwJgYDVQQLEx9E
9aWdpdGFsIElEIENsYXNzIDEgLSBTTUlNRSBUZXN0MUcwRQYDVQQLEz53d3cudmVy
10aXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMCBJbmMuIGJ5IFJlZi4sTElBQi5M
11VEQoYyk5NjBbMA0GCSqGSIb3DQEBAQUAA0oAMEcCQA7LvHEIAiQ5+4gDYvJGnGAq
12UM5GXyG11diEXmIEZTHUZhorooX5sr8IIjSXiPY59YYUFSvAaharFM1xaBN8zNEC
13AwEAAaOCAjkwggI1MAkGA1UdEwQCMAAwggImBgNVHQMEggIdMIICGTCCAhUwggIR
14BgtghkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0
15ZXMgYnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0
16IHRvLCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1l
17bnQgKENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
18L0NQUy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29t
19OyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4s
20IE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04
21ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0
22cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJ
23QUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQEC
24MC8wLRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEu
25AzANBgkqhkiG9w0BAQQFAANBAMCYDuSb/eIlYSxY31nZZTaCZkCSfHjlacMofExr
26cF+A2yHoEuT+eCQkqM0pMNHXddUeoQ9RjV+VuMBNmm63DUYwggHCMIIBbKADAgEC
27AhB8CYTq1bkRFJBYOd67cp9JMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
28MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
29QTAeFw05NjA3MTcwMDAwMDBaFw05NzA3MTcyMzU5NTlaMGIxETAPBgNVBAcTCElu
30dGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNp
31Z24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjBcMA0GCSqGSIb3
32DQEBAQUAA0sAMEgCQQDsVzrNgnDhbAJZrWeLd9g1vMZJA2W67D33TTbga6yMt+ES
33TWEywhS6RNP+fzLGg7utinjH4tL60cXa0G27GDsLAgMBAAGjIjAgMAsGA1UdDwQE
34AwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADQQAUp6bRwkaD
352d1MBs/mjUcgTI2fXVmW8tTm/Ud6OzUwpC3vYgybiOOA4f6mOC5dbyUHrLOsrihU
3647ZQ0Jo1DUfboYIBrTCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
37MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
38QRcNOTYwNzE3MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANB
39AHitA0/xAukCjHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMl
40ExONA3ju10f7owIq3s3wx10wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UE
41BxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytW
42ZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3
43MTcxNzU5MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsW
44sQmste9f+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9
45XfZsaiiIgotQHjEA
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-----
2MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC
3QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG
4DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq
5hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi
6gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/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-----
2MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I
3Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R
4rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy
5oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S
6mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz
7rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA
8mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM=
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-----
2MIIB1gIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV
3bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw
4ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz
5YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG
6A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk
7LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G
8CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD
9TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI
10hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L
11CrWF5i8LWt/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
3digest='-mdc2'
4reqcmd="../apps/openssl req"
5x509cmd="../apps/openssl x509 $digest"
6verifycmd="../apps/openssl verify"
7dummycnf="../apps/openssl.cnf"
8
9CAkey="keyCA.ss"
10CAcert="certCA.ss"
11CAreq="reqCA.ss"
12CAconf="CAss.cnf"
13CAreq2="req2CA.ss" # temp
14
15Uconf="Uss.cnf"
16Ukey="keyU.ss"
17Ureq="reqU.ss"
18Ucert="certU.ss"
19
20echo
21echo "make a certificate request using 'req'"
22$reqcmd -config $CAconf -out $CAreq -keyout $CAkey -new #>err.ss
23if [ $? != 0 ]; then
24 echo "error using 'req' to generate a certificate request"
25 exit 1
26fi
27echo
28echo "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
30if [ $? != 0 ]; then
31 echo "error using 'x509' to self sign a certificate request"
32 exit 1
33fi
34
35echo
36echo "convert a certificate into a certificate request using 'x509'"
37$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
38if [ $? != 0 ]; then
39 echo "error using 'x509' convert a certificate to a certificate request"
40 exit 1
41fi
42
43$reqcmd -config $dummycnf -verify -in $CAreq -noout
44if [ $? != 0 ]; then
45 echo first generated request is invalid
46 exit 1
47fi
48
49$reqcmd -config $dummycnf -verify -in $CAreq2 -noout
50if [ $? != 0 ]; then
51 echo second generated request is invalid
52 exit 1
53fi
54
55$verifycmd -CAfile $CAcert $CAcert
56if [ $? != 0 ]; then
57 echo first generated cert is invalid
58 exit 1
59fi
60
61echo
62echo "make another certificate request using 'req'"
63$reqcmd -config $Uconf -out $Ureq -keyout $Ukey -new >err.ss
64if [ $? != 0 ]; then
65 echo "error using 'req' to generate a certificate request"
66 exit 1
67fi
68
69echo
70echo "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
72if [ $? != 0 ]; then
73 echo "error using 'x509' to sign a certificate request"
74 exit 1
75fi
76
77$verifycmd -CAfile $CAcert $Ucert
78echo
79echo "Certificate details"
80$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
81
82echo
83echo The generated CA certificate is $CAcert
84echo The generated CA private key is $CAkey
85
86echo The generated user certificate is $Ucert
87echo The generated user private key is $Ukey
88
89/bin/rm err.ss
90exit 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
3echo test sslv2
4./ssltest -ssl2 || exit 1
5
6echo test sslv2 with server authentication
7./ssltest -ssl2 -server_auth -CApath ../certs || exit 1
8
9echo test sslv2 with client authentication
10./ssltest -ssl2 -client_auth -CApath ../certs || exit 1
11
12echo test sslv2 with both client and server authentication
13./ssltest -ssl2 -server_auth -client_auth -CApath ../certs || exit 1
14
15echo test sslv3
16./ssltest -ssl3 || exit 1
17
18echo test sslv3 with server authentication
19./ssltest -ssl3 -server_auth -CApath ../certs || exit 1
20
21echo test sslv3 with client authentication
22./ssltest -ssl3 -client_auth -CApath ../certs || exit 1
23
24echo test sslv3 with both client and server authentication
25./ssltest -ssl3 -server_auth -client_auth -CApath ../certs || exit 1
26
27echo test sslv2/sslv3
28./ssltest || exit 1
29
30echo test sslv2/sslv3 with server authentication
31./ssltest -server_auth -CApath ../certs || exit 1
32
33echo test sslv2/sslv3 with client authentication
34./ssltest -client_auth -CApath ../certs || exit 1
35
36echo test sslv2/sslv3 with both client and server authentication
37./ssltest -server_auth -client_auth -CApath ../certs || exit 1
38
39echo test sslv2 via BIO pair
40./ssltest -bio_pair -ssl2 || exit 1
41
42echo test sslv2 with server authentication via BIO pair
43./ssltest -bio_pair -ssl2 -server_auth -CApath ../certs || exit 1
44
45echo test sslv2 with client authentication via BIO pair
46./ssltest -bio_pair -ssl2 -client_auth -CApath ../certs || exit 1
47
48echo 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
51echo test sslv3 via BIO pair
52./ssltest -bio_pair -ssl3 || exit 1
53
54echo test sslv3 with server authentication via BIO pair
55./ssltest -bio_pair -ssl3 -server_auth -CApath ../certs || exit 1
56
57echo test sslv3 with client authentication via BIO pair
58./ssltest -bio_pair -ssl3 -client_auth -CApath ../certs || exit 1
59
60echo 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
63echo test sslv2/sslv3 via BIO pair
64./ssltest || exit 1
65
66echo test sslv2/sslv3 w/o DHE via BIO pair
67./ssltest -bio_pair -no_dhe || exit 1
68
69echo test sslv2/sslv3 with 1024bit DHE
70./ssltest -bio_pair -dhe1024 -v || exit 1
71
72echo test sslv2/sslv3 with server authentication
73./ssltest -bio_pair -server_auth -CApath ../certs || exit 1
74
75echo test sslv2/sslv3 with client authentication via BIO pair
76./ssltest -bio_pair -client_auth -CApath ../certs || exit 1
77
78echo 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
81exit 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-----
2MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
3BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz
4MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
5RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF
6AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO
7/Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE
8Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ
9zl9HYIMxATFyqSiD9jsx
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
2More number for the questions about SSL overheads....
3
4The following numbers were generated on a pentium pro 200, running linux.
5They give an indication of the SSL protocol and encryption overheads.
6
7The program that generated them is an unreleased version of ssl/ssltest.c
8which is the SSLeay ssl protocol testing program. It is a single process that
9talks both sides of the SSL protocol via a non-blocking memory buffer
10interface.
11
12How do I read this? The protocol and cipher are reasonable obvious.
13The next number is the number of connections being made. The next is the
14number of bytes exchanged bewteen the client and server side of the protocol.
15This is the number of bytes that the client sends to the server, and then
16the server sends back. Because this is all happening in one process,
17the data is being encrypted, decrypted, encrypted and then decrypted again.
18It is a round trip of that many bytes. Because the one process performs
19both the client and server sides of the protocol and it sends this many bytes
20each direction, multiply this number by 4 to generate the number
21of bytes encrypted/decrypted/MACed. The first time value is how many seconds
22elapsed doing a full SSL handshake, the second is the cost of one
23full handshake and the rest being session-id reuse.
24
25SSLv2 RC4-MD5 1000 x 1 12.83s 0.70s
26SSLv3 NULL-MD5 1000 x 1 14.35s 1.47s
27SSLv3 RC4-MD5 1000 x 1 14.46s 1.56s
28SSLv3 RC4-MD5 1000 x 1 51.93s 1.62s 1024bit RSA
29SSLv3 RC4-SHA 1000 x 1 14.61s 1.83s
30SSLv3 DES-CBC-SHA 1000 x 1 14.70s 1.89s
31SSLv3 DES-CBC3-SHA 1000 x 1 15.16s 2.16s
32
33SSLv2 RC4-MD5 1000 x 1024 13.72s 1.27s
34SSLv3 NULL-MD5 1000 x 1024 14.79s 1.92s
35SSLv3 RC4-MD5 1000 x 1024 52.58s 2.29s 1024bit RSA
36SSLv3 RC4-SHA 1000 x 1024 15.39s 2.67s
37SSLv3 DES-CBC-SHA 1000 x 1024 16.45s 3.55s
38SSLv3 DES-CBC3-SHA 1000 x 1024 18.21s 5.38s
39
40SSLv2 RC4-MD5 1000 x 10240 18.97s 6.52s
41SSLv3 NULL-MD5 1000 x 10240 17.79s 5.11s
42SSLv3 RC4-MD5 1000 x 10240 20.25s 7.90s
43SSLv3 RC4-MD5 1000 x 10240 58.26s 8.08s 1024bit RSA
44SSLv3 RC4-SHA 1000 x 10240 22.96s 11.44s
45SSLv3 DES-CBC-SHA 1000 x 10240 30.65s 18.41s
46SSLv3 DES-CBC3-SHA 1000 x 10240 47.04s 34.53s
47
48SSLv2 RC4-MD5 1000 x 102400 70.22s 57.74s
49SSLv3 NULL-MD5 1000 x 102400 43.73s 31.03s
50SSLv3 RC4-MD5 1000 x 102400 71.32s 58.83s
51SSLv3 RC4-MD5 1000 x 102400 109.66s 59.20s 1024bit RSA
52SSLv3 RC4-SHA 1000 x 102400 95.88s 82.21s
53SSLv3 DES-CBC-SHA 1000 x 102400 173.22s 160.55s
54SSLv3 DES-CBC3-SHA 1000 x 102400 336.61s 323.82s
55
56What does this all mean? Well for a server, with no session-id reuse, with
57a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key,
58a pentium pro 200 running linux can handle the SSLv3 protocol overheads of
59about 49 connections a second. Reality will be quite different :-).
60
61Remeber the first number is 1000 full ssl handshakes, the second is
621 full and 999 with session-id reuse. The RSA overheads for each exchange
63would be one public and one private operation, but the protocol/MAC/cipher
64cost would be quite similar in both the client and server.
65
66eric (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
89The general cipher performace number for this platform are
90
91SSLeay 0.8.2a 04-Sep-1997
92built on Fri Sep 5 17:37:05 EST 1997
93options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
94C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
95The 'numbers' are in 1000s of bytes per second processed.
96type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
97md2 131.02k 368.41k 500.57k 549.21k 566.09k
98mdc2 535.60k 589.10k 595.88k 595.97k 594.54k
99md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k
100sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k
101sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k
102rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k
103des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k
104des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k
105idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k
106rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k
107blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k
108 sign verify
109rsa 512 bits 0.0100s 0.0011s
110rsa 1024 bits 0.0451s 0.0012s
111rsa 2048 bits 0.2605s 0.0086s
112rsa 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl pkcs7'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testp7.pem
12fi
13
14echo testing pkcs7 conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27echo "p -> d"
28$cmd -in f.p -inform p -outform d >ff.d3
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> p"
32$cmd -in f.d -inform d -outform p >ff.p1
33if [ $? != 0 ]; then exit 1; fi
34echo "p -> p"
35$cmd -in f.p -inform p -outform p >ff.p3
36if [ $? != 0 ]; then exit 1; fi
37
38cmp fff.p f.p
39if [ $? != 0 ]; then exit 1; fi
40cmp fff.p ff.p1
41if [ $? != 0 ]; then exit 1; fi
42cmp fff.p ff.p3
43if [ $? != 0 ]; then exit 1; fi
44
45cmp f.p ff.p1
46if [ $? != 0 ]; then exit 1; fi
47cmp f.p ff.p3
48if [ $? != 0 ]; then exit 1; fi
49
50/bin/rm -f f.* ff.* fff.*
51exit 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl pkcs7'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=pkcs7-1.pem
12fi
13
14echo "testing pkcs7 conversions (2)"
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27echo "p -> d"
28$cmd -in f.p -inform p -outform d >ff.d3
29if [ $? != 0 ]; then exit 1; fi
30
31echo "d -> p"
32$cmd -in f.d -inform d -outform p >ff.p1
33if [ $? != 0 ]; then exit 1; fi
34echo "p -> p"
35$cmd -in f.p -inform p -outform p >ff.p3
36if [ $? != 0 ]; then exit 1; fi
37
38cmp f.p ff.p1
39if [ $? != 0 ]; then exit 1; fi
40cmp f.p ff.p3
41if [ $? != 0 ]; then exit 1; fi
42
43/bin/rm -f f.* ff.* fff.*
44exit 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl req -config ../apps/openssl.cnf'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testreq.pem
12fi
13
14echo testing req conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 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
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -verify -in f.d -inform d -outform d >ff.d1
29if [ $? != 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
33echo "p -> d"
34$cmd -verify -in f.p -inform p -outform d >ff.d3
35if [ $? != 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
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 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
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 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
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl rsa'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testrsa.pem
12fi
13
14echo testing rsa conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 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
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 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
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 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
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 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
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 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
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl sess_id'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testsid.pem
12fi
13
14echo testing session-id conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 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
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 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
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 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
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 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
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61#cmp fff.p ff.p2
62#if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 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
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75#cmp f.p ff.p2
76#if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 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
3PATH=../apps:$PATH
4export PATH
5
6cmd='../apps/openssl x509'
7
8if [ "$1"x != "x" ]; then
9 t=$1
10else
11 t=testx509.pem
12fi
13
14echo testing X509 conversions
15cp $t fff.p
16
17echo "p -> d"
18$cmd -in fff.p -inform p -outform d >f.d
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> n"
21$cmd -in fff.p -inform p -outform n >f.n
22if [ $? != 0 ]; then exit 1; fi
23echo "p -> p"
24$cmd -in fff.p -inform p -outform p >f.p
25if [ $? != 0 ]; then exit 1; fi
26
27echo "d -> d"
28$cmd -in f.d -inform d -outform d >ff.d1
29if [ $? != 0 ]; then exit 1; fi
30echo "n -> d"
31$cmd -in f.n -inform n -outform d >ff.d2
32if [ $? != 0 ]; then exit 1; fi
33echo "p -> d"
34$cmd -in f.p -inform p -outform d >ff.d3
35if [ $? != 0 ]; then exit 1; fi
36
37echo "d -> n"
38$cmd -in f.d -inform d -outform n >ff.n1
39if [ $? != 0 ]; then exit 1; fi
40echo "n -> n"
41$cmd -in f.n -inform n -outform n >ff.n2
42if [ $? != 0 ]; then exit 1; fi
43echo "p -> n"
44$cmd -in f.p -inform p -outform n >ff.n3
45if [ $? != 0 ]; then exit 1; fi
46
47echo "d -> p"
48$cmd -in f.d -inform d -outform p >ff.p1
49if [ $? != 0 ]; then exit 1; fi
50echo "n -> p"
51$cmd -in f.n -inform n -outform p >ff.p2
52if [ $? != 0 ]; then exit 1; fi
53echo "p -> p"
54$cmd -in f.p -inform p -outform p >ff.p3
55if [ $? != 0 ]; then exit 1; fi
56
57cmp fff.p f.p
58if [ $? != 0 ]; then exit 1; fi
59cmp fff.p ff.p1
60if [ $? != 0 ]; then exit 1; fi
61cmp fff.p ff.p2
62if [ $? != 0 ]; then exit 1; fi
63cmp fff.p ff.p3
64if [ $? != 0 ]; then exit 1; fi
65
66cmp f.n ff.n1
67if [ $? != 0 ]; then exit 1; fi
68cmp f.n ff.n2
69if [ $? != 0 ]; then exit 1; fi
70cmp f.n ff.n3
71if [ $? != 0 ]; then exit 1; fi
72
73cmp f.p ff.p1
74if [ $? != 0 ]; then exit 1; fi
75cmp f.p ff.p2
76if [ $? != 0 ]; then exit 1; fi
77cmp f.p ff.p3
78if [ $? != 0 ]; then exit 1; fi
79
80/bin/rm -f f.* ff.* fff.*
81exit 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-----
2MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
3NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
4dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
5ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
6ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
7ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
8miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
9AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
10Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
11DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
12MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
13AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
14X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
15WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+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-----
2MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD
3YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0
4ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu
5dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1
6WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV
7BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx
8FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA
96ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT
10G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ
11YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm
12b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc
13F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz
14lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap
15jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU=
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/tls1.h b/src/lib/libssl/tls1.h
deleted file mode 100644
index cf92ae034f..0000000000
--- a/src/lib/libssl/tls1.h
+++ /dev/null
@@ -1,164 +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
65extern "C" {
66#endif
67
68#define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 1
69
70#define TLS1_VERSION 0x0301
71#define TLS1_VERSION_MAJOR 0x03
72#define TLS1_VERSION_MINOR 0x01
73
74#define TLS1_AD_DECRYPTION_FAILED 21
75#define TLS1_AD_RECORD_OVERFLOW 22
76#define TLS1_AD_UNKNOWN_CA 48 /* fatal */
77#define TLS1_AD_ACCESS_DENIED 49 /* fatal */
78#define TLS1_AD_DECODE_ERROR 50 /* fatal */
79#define TLS1_AD_DECRYPT_ERROR 51
80#define TLS1_AD_EXPORT_RESTRICTION 60 /* fatal */
81#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */
82#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */
83#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */
84#define TLS1_AD_USER_CANCELLED 90
85#define TLS1_AD_NO_RENEGOTIATION 100
86
87/* Additional TLS ciphersuites from draft-ietf-tls-56-bit-ciphersuites-00.txt
88 * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see
89 * s3_lib.c). We actually treat them like SSL 3.0 ciphers, which we probably
90 * shouldn't. */
91#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060
92#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061
93#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062
94#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063
95#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064
96#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065
97#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066
98
99/* XXX
100 * Inconsistency alert:
101 * The OpenSSL names of ciphers with ephemeral DH here include the string
102 * "DHE", while elsewhere it has always been "EDH".
103 * (The alias for the list of all such ciphers also is "EDH".)
104 * The specifications speak of "EDH"; maybe we should allow both forms
105 * for everything. */
106#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5"
107#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5"
108#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA"
109#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA"
110#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA"
111#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA"
112#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA"
113
114
115#define TLS_CT_RSA_SIGN 1
116#define TLS_CT_DSS_SIGN 2
117#define TLS_CT_RSA_FIXED_DH 3
118#define TLS_CT_DSS_FIXED_DH 4
119#define TLS_CT_NUMBER 4
120
121#define TLS1_FINISH_MAC_LENGTH 12
122
123#define TLS_MD_MAX_CONST_SIZE 20
124#define TLS_MD_CLIENT_FINISH_CONST "client finished"
125#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
126#define TLS_MD_SERVER_FINISH_CONST "server finished"
127#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
128#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
129#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
130#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
131#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
132#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
133#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
134#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
135#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
136#define TLS_MD_IV_BLOCK_CONST "IV block"
137#define TLS_MD_IV_BLOCK_CONST_SIZE 8
138#define TLS_MD_MASTER_SECRET_CONST "master secret"
139#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
140
141#ifdef CHARSET_EBCDIC
142#undef TLS_MD_CLIENT_FINISH_CONST
143#define TLS_MD_CLIENT_FINISH_CONST "\x63\x6c\x69\x65\x6e\x74\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*client finished*/
144#undef TLS_MD_SERVER_FINISH_CONST
145#define TLS_MD_SERVER_FINISH_CONST "\x73\x65\x72\x76\x65\x72\x20\x66\x69\x6e\x69\x73\x68\x65\x64" /*server finished*/
146#undef TLS_MD_SERVER_WRITE_KEY_CONST
147#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*/
148#undef TLS_MD_KEY_EXPANSION_CONST
149#define TLS_MD_KEY_EXPANSION_CONST "\x6b\x65\x79\x20\x65\x78\x70\x61\x6e\x73\x69\x6f\x6e" /*key expansion*/
150#undef TLS_MD_CLIENT_WRITE_KEY_CONST
151#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*/
152#undef TLS_MD_SERVER_WRITE_KEY_CONST
153#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*/
154#undef TLS_MD_IV_BLOCK_CONST
155#define TLS_MD_IV_BLOCK_CONST "\x49\x56\x20\x62\x6c\x6f\x63\x6b" /*IV block*/
156#undef TLS_MD_MASTER_SECRET_CONST
157#define TLS_MD_MASTER_SECRET_CONST "\x6d\x61\x73\x74\x65\x72\x20\x73\x65\x63\x72\x65\x74" /*master secret*/
158#endif
159
160#ifdef __cplusplus
161}
162#endif
163#endif
164