summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2002-09-26 11:41:23 +0000
committercvs2svn <admin@example.com>2002-09-26 11:41:23 +0000
commit3b5c5bfc7cdfc65c13061b8267f92cfc3c3d9f62 (patch)
tree65b4d250c712e6725dca113b306ae73f896475e1 /src/lib/libssl/ssl
parentaf61e3f7dbe1fd8b363339d8ec5d6aec5f400ce3 (diff)
downloadopenbsd-OPENBSD_3_2_BASE.tar.gz
openbsd-OPENBSD_3_2_BASE.tar.bz2
openbsd-OPENBSD_3_2_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_3_2_BASE'.OPENBSD_3_2_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/ssl.h1838
-rw-r--r--src/lib/libssl/ssl2.h268
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h504
-rw-r--r--src/lib/libssl/ssl_algs.c111
-rw-r--r--src/lib/libssl/ssl_asn1.c391
-rw-r--r--src/lib/libssl/ssl_cert.c832
-rw-r--r--src/lib/libssl/ssl_ciph.c1139
-rw-r--r--src/lib/libssl/ssl_err.c460
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c2302
-rw-r--r--src/lib/libssl/ssl_locl.h620
-rw-r--r--src/lib/libssl/ssl_rsa.c815
-rw-r--r--src/lib/libssl/ssl_sess.c751
-rw-r--r--src/lib/libssl/ssl_stat.c502
-rw-r--r--src/lib/libssl/ssl_txt.c186
16 files changed, 0 insertions, 10872 deletions
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index e9d1e896d7..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1838 +0,0 @@
1/* ssl/ssl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
113 *
114 * Redistribution and use in source and binary forms, with or without
115 * modification, are permitted provided that the following conditions
116 * are met:
117 *
118 * 1. Redistributions of source code must retain the above copyright
119 * notice, this list of conditions and the following disclaimer.
120 *
121 * 2. Redistributions in binary form must reproduce the above copyright
122 * notice, this list of conditions and the following disclaimer in
123 * the documentation and/or other materials provided with the
124 * distribution.
125 *
126 * 3. All advertising materials mentioning features or use of this
127 * software must display the following acknowledgment:
128 * "This product includes software developed by the OpenSSL Project
129 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
130 *
131 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
132 * endorse or promote products derived from this software without
133 * prior written permission. For written permission, please contact
134 * openssl-core@openssl.org.
135 *
136 * 5. Products derived from this software may not be called "OpenSSL"
137 * nor may "OpenSSL" appear in their names without prior written
138 * permission of the OpenSSL Project.
139 *
140 * 6. Redistributions of any form whatsoever must retain the following
141 * acknowledgment:
142 * "This product includes software developed by the OpenSSL Project
143 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
144 *
145 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
146 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
147 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
148 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
149 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
150 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
151 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
152 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
153 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
154 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
155 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
156 * OF THE POSSIBILITY OF SUCH DAMAGE.
157 * ====================================================================
158 *
159 * This product includes cryptographic software written by Eric Young
160 * (eay@cryptsoft.com). This product includes software written by Tim
161 * Hudson (tjh@cryptsoft.com).
162 *
163 */
164
165#ifndef HEADER_SSL_H
166#define HEADER_SSL_H
167
168#include <openssl/e_os2.h>
169
170#ifndef OPENSSL_NO_COMP
171#include <openssl/comp.h>
172#endif
173#ifndef OPENSSL_NO_BIO
174#include <openssl/bio.h>
175#endif
176#ifndef OPENSSL_NO_X509
177#include <openssl/x509.h>
178#endif
179#include <openssl/kssl.h>
180#include <openssl/safestack.h>
181#include <openssl/symhacks.h>
182
183#ifdef __cplusplus
184extern "C" {
185#endif
186
187/* SSLeay version number for ASN.1 encoding of the session information */
188/* Version 0 - initial version
189 * Version 1 - added the optional peer certificate
190 */
191#define SSL_SESSION_ASN1_VERSION 0x0001
192
193/* text strings for the ciphers */
194#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
195#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
196#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
197#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
198#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
199#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
200#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
201#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
202#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
203#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
204
205/* VRS Additional Kerberos5 entries
206 */
207#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA
208#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5
209#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA
210#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5
211#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA
212#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5
213#define SSL_MAX_KRB5_PRINCIPAL_LENGTH 256
214
215#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
216#define SSL_MAX_SID_CTX_LENGTH 32
217
218#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
219#define SSL_MAX_KEY_ARG_LENGTH 8
220#define SSL_MAX_MASTER_KEY_LENGTH 48
221
222/* These are used to specify which ciphers to use and not to use */
223#define SSL_TXT_LOW "LOW"
224#define SSL_TXT_MEDIUM "MEDIUM"
225#define SSL_TXT_HIGH "HIGH"
226#define SSL_TXT_kFZA "kFZA"
227#define SSL_TXT_aFZA "aFZA"
228#define SSL_TXT_eFZA "eFZA"
229#define SSL_TXT_FZA "FZA"
230
231#define SSL_TXT_aNULL "aNULL"
232#define SSL_TXT_eNULL "eNULL"
233#define SSL_TXT_NULL "NULL"
234
235#define SSL_TXT_kKRB5 "kKRB5"
236#define SSL_TXT_aKRB5 "aKRB5"
237#define SSL_TXT_KRB5 "KRB5"
238
239#define SSL_TXT_kRSA "kRSA"
240#define SSL_TXT_kDHr "kDHr"
241#define SSL_TXT_kDHd "kDHd"
242#define SSL_TXT_kEDH "kEDH"
243#define SSL_TXT_aRSA "aRSA"
244#define SSL_TXT_aDSS "aDSS"
245#define SSL_TXT_aDH "aDH"
246#define SSL_TXT_DSS "DSS"
247#define SSL_TXT_DH "DH"
248#define SSL_TXT_EDH "EDH"
249#define SSL_TXT_ADH "ADH"
250#define SSL_TXT_RSA "RSA"
251#define SSL_TXT_DES "DES"
252#define SSL_TXT_3DES "3DES"
253#define SSL_TXT_RC4 "RC4"
254#define SSL_TXT_RC2 "RC2"
255#define SSL_TXT_IDEA "IDEA"
256#define SSL_TXT_AES "AES"
257#define SSL_TXT_MD5 "MD5"
258#define SSL_TXT_SHA1 "SHA1"
259#define SSL_TXT_SHA "SHA"
260#define SSL_TXT_EXP "EXP"
261#define SSL_TXT_EXPORT "EXPORT"
262#define SSL_TXT_EXP40 "EXPORT40"
263#define SSL_TXT_EXP56 "EXPORT56"
264#define SSL_TXT_SSLV2 "SSLv2"
265#define SSL_TXT_SSLV3 "SSLv3"
266#define SSL_TXT_TLSV1 "TLSv1"
267#define SSL_TXT_ALL "ALL"
268
269/*
270 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
271 * ciphers normally not being used.
272 * Example: "RC4" will activate all ciphers using RC4 including ciphers
273 * without authentication, which would normally disabled by DEFAULT (due
274 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
275 * will make sure that it is also disabled in the specific selection.
276 * COMPLEMENTOF* identifiers are portable between version, as adjustments
277 * to the default cipher setup will also be included here.
278 *
279 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
280 * DEFAULT gets, as only selection is being done and no sorting as needed
281 * for DEFAULT.
282 */
283#define SSL_TXT_CMPALL "COMPLEMENTOFALL"
284#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT"
285
286/* The following cipher list is used by default.
287 * It also is substituted when an application-defined cipher list string
288 * starts with 'DEFAULT'. */
289#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:+RC4:@STRENGTH" /* low priority for RC4 */
290
291/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
292#define SSL_SENT_SHUTDOWN 1
293#define SSL_RECEIVED_SHUTDOWN 2
294
295#ifdef __cplusplus
296}
297#endif
298
299#include <openssl/crypto.h>
300#include <openssl/lhash.h>
301#include <openssl/buffer.h>
302#include <openssl/bio.h>
303#include <openssl/pem.h>
304#include <openssl/x509.h>
305
306#ifdef __cplusplus
307extern "C" {
308#endif
309
310#if (defined(OPENSSL_NO_RSA) || defined(OPENSSL_NO_MD5)) && !defined(OPENSSL_NO_SSL2)
311#define OPENSSL_NO_SSL2
312#endif
313
314#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
315#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
316
317/* This is needed to stop compilers complaining about the
318 * 'struct ssl_st *' function parameters used to prototype callbacks
319 * in SSL_CTX. */
320typedef struct ssl_st *ssl_crock_st;
321
322/* used to hold info on the particular ciphers used */
323typedef struct ssl_cipher_st
324 {
325 int valid;
326 const char *name; /* text name */
327 unsigned long id; /* id, 4 bytes, first is version */
328 unsigned long algorithms; /* what ciphers are used */
329 unsigned long algo_strength; /* strength and export flags */
330 unsigned long algorithm2; /* Extra flags */
331 int strength_bits; /* Number of bits really used */
332 int alg_bits; /* Number of bits for algorithm */
333 unsigned long mask; /* used for matching */
334 unsigned long mask_strength; /* also used for matching */
335 } SSL_CIPHER;
336
337DECLARE_STACK_OF(SSL_CIPHER)
338
339typedef struct ssl_st SSL;
340typedef struct ssl_ctx_st SSL_CTX;
341
342/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
343typedef struct ssl_method_st
344 {
345 int version;
346 int (*ssl_new)(SSL *s);
347 void (*ssl_clear)(SSL *s);
348 void (*ssl_free)(SSL *s);
349 int (*ssl_accept)(SSL *s);
350 int (*ssl_connect)(SSL *s);
351 int (*ssl_read)(SSL *s,void *buf,int len);
352 int (*ssl_peek)(SSL *s,void *buf,int len);
353 int (*ssl_write)(SSL *s,const void *buf,int len);
354 int (*ssl_shutdown)(SSL *s);
355 int (*ssl_renegotiate)(SSL *s);
356 int (*ssl_renegotiate_check)(SSL *s);
357 long (*ssl_ctrl)(SSL *s,int cmd,long larg,void *parg);
358 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,void *parg);
359 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
360 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
361 int (*ssl_pending)(SSL *s);
362 int (*num_ciphers)(void);
363 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
364 struct ssl_method_st *(*get_ssl_method)(int version);
365 long (*get_timeout)(void);
366 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
367 int (*ssl_version)();
368 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)());
369 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)());
370 } SSL_METHOD;
371
372/* Lets make this into an ASN.1 type structure as follows
373 * SSL_SESSION_ID ::= SEQUENCE {
374 * version INTEGER, -- structure version number
375 * SSLversion INTEGER, -- SSL version number
376 * Cipher OCTET_STRING, -- the 3 byte cipher ID
377 * Session_ID OCTET_STRING, -- the Session ID
378 * Master_key OCTET_STRING, -- the master key
379 * KRB5_principal OCTET_STRING -- optional Kerberos principal
380 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
381 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
382 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
383 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
384 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
385 * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer'
386 * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
387 * }
388 * Look in ssl/ssl_asn1.c for more details
389 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
390 */
391typedef struct ssl_session_st
392 {
393 int ssl_version; /* what ssl version session info is
394 * being kept in here? */
395
396 /* only really used in SSLv2 */
397 unsigned int key_arg_length;
398 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
399 int master_key_length;
400 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
401 /* session_id - valid? */
402 unsigned int session_id_length;
403 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
404 /* this is used to determine whether the session is being reused in
405 * the appropriate context. It is up to the application to set this,
406 * via SSL_new */
407 unsigned int sid_ctx_length;
408 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
409
410#ifndef OPENSSL_NO_KRB5
411 unsigned int krb5_client_princ_len;
412 unsigned char krb5_client_princ[SSL_MAX_KRB5_PRINCIPAL_LENGTH];
413#endif /* OPENSSL_NO_KRB5 */
414
415 int not_resumable;
416
417 /* The cert is the certificate used to establish this connection */
418 struct sess_cert_st /* SESS_CERT */ *sess_cert;
419
420 /* This is the cert for the other end.
421 * On clients, it will be the same as sess_cert->peer_key->x509
422 * (the latter is not enough as sess_cert is not retained
423 * in the external representation of sessions, see ssl_asn1.c). */
424 X509 *peer;
425 /* when app_verify_callback accepts a session where the peer's certificate
426 * is not ok, we must remember the error for session reuse: */
427 long verify_result; /* only for servers */
428
429 int references;
430 long timeout;
431 long time;
432
433 int compress_meth; /* Need to lookup the method */
434
435 SSL_CIPHER *cipher;
436 unsigned long cipher_id; /* when ASN.1 loaded, this
437 * needs to be used to load
438 * the 'cipher' structure */
439
440 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
441
442 CRYPTO_EX_DATA ex_data; /* application specific data */
443
444 /* These are used to make removal of session-ids more
445 * efficient and to implement a maximum cache size. */
446 struct ssl_session_st *prev,*next;
447 } SSL_SESSION;
448
449
450#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
451#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
452#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
453#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
454#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
455#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
456#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
457#define SSL_OP_TLS_D5_BUG 0x00000100L
458#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
459
460/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
461 * in OpenSSL 0.9.6d. Usually (depending on the application protocol)
462 * the workaround is not needed. Unfortunately some broken SSL/TLS
463 * implementations cannot handle it at all, which is why we include
464 * it in SSL_OP_ALL. */
465#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L /* added in 0.9.6e */
466
467/* SSL_OP_ALL: various bug workarounds that should be rather harmless.
468 * This used to be 0x000FFFFFL before 0.9.7. */
469#define SSL_OP_ALL 0x00000FFFL
470
471/* As server, disallow session resumption on renegotiation */
472#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L
473/* If set, always create a new key when using tmp_dh parameters */
474#define SSL_OP_SINGLE_DH_USE 0x00100000L
475/* Set to always use the tmp_rsa key when doing RSA operations,
476 * even when this violates protocol specs */
477#define SSL_OP_EPHEMERAL_RSA 0x00200000L
478/* Set on servers to choose the cipher according to the server's
479 * preferences */
480#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L
481/* If set, a server will allow a client to issue a SSLv3.0 version number
482 * as latest version supported in the premaster secret, even when TLSv1.0
483 * (version 3.1) was announced in the client hello. Normally this is
484 * forbidden to prevent version rollback attacks. */
485#define SSL_OP_TLS_ROLLBACK_BUG 0x00800000L
486
487#define SSL_OP_NO_SSLv2 0x01000000L
488#define SSL_OP_NO_SSLv3 0x02000000L
489#define SSL_OP_NO_TLSv1 0x04000000L
490
491/* The next flag deliberately changes the ciphertest, this is a check
492 * for the PKCS#1 attack */
493#define SSL_OP_PKCS1_CHECK_1 0x08000000L
494#define SSL_OP_PKCS1_CHECK_2 0x10000000L
495#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
496#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x40000000L
497
498
499/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
500 * when just a single record has been written): */
501#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
502/* Make it possible to retry SSL_write() with changed buffer location
503 * (buffer contents must stay the same!); this is not the default to avoid
504 * the misconception that non-blocking SSL_write() behaves like
505 * non-blocking write(): */
506#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
507/* Never bother the application with retries if the transport
508 * is blocking: */
509#define SSL_MODE_AUTO_RETRY 0x00000004L
510
511
512/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
513 * they cannot be used to clear bits. */
514
515#define SSL_CTX_set_options(ctx,op) \
516 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)
517#define SSL_CTX_get_options(ctx) \
518 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL)
519#define SSL_set_options(ssl,op) \
520 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL)
521#define SSL_get_options(ssl) \
522 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL)
523
524#define SSL_CTX_set_mode(ctx,op) \
525 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
526#define SSL_CTX_get_mode(ctx) \
527 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
528#define SSL_set_mode(ssl,op) \
529 SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
530#define SSL_get_mode(ssl) \
531 SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
532
533
534void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
535void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
536#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
537#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
538
539
540
541#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32)
542#define SSL_MAX_CERT_LIST_DEFAULT 1024*30 /* 30k max cert list :-) */
543#else
544#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
545#endif
546
547#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
548
549/* This callback type is used inside SSL_CTX, SSL, and in the functions that set
550 * them. It is used to override the generation of SSL/TLS session IDs in a
551 * server. Return value should be zero on an error, non-zero to proceed. Also,
552 * callbacks should themselves check if the id they generate is unique otherwise
553 * the SSL handshake will fail with an error - callbacks can do this using the
554 * 'ssl' value they're passed by;
555 * SSL_has_matching_session_id(ssl, id, *id_len)
556 * The length value passed in is set at the maximum size the session ID can be.
557 * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback
558 * can alter this length to be less if desired, but under SSLv2 session IDs are
559 * supposed to be fixed at 16 bytes so the id will be padded after the callback
560 * returns in this case. It is also an error for the callback to set the size to
561 * zero. */
562typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
563 unsigned int *id_len);
564
565typedef struct ssl_comp_st
566 {
567 int id;
568 char *name;
569#ifndef OPENSSL_NO_COMP
570 COMP_METHOD *method;
571#else
572 char *method;
573#endif
574 } SSL_COMP;
575
576DECLARE_STACK_OF(SSL_COMP)
577
578struct ssl_ctx_st
579 {
580 SSL_METHOD *method;
581
582 STACK_OF(SSL_CIPHER) *cipher_list;
583 /* same as above but sorted for lookup */
584 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
585
586 struct x509_store_st /* X509_STORE */ *cert_store;
587 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */
588 /* Most session-ids that will be cached, default is
589 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
590 unsigned long session_cache_size;
591 struct ssl_session_st *session_cache_head;
592 struct ssl_session_st *session_cache_tail;
593
594 /* This can have one of 2 values, ored together,
595 * SSL_SESS_CACHE_CLIENT,
596 * SSL_SESS_CACHE_SERVER,
597 * Default is SSL_SESSION_CACHE_SERVER, which means only
598 * SSL_accept which cache SSL_SESSIONS. */
599 int session_cache_mode;
600
601 /* If timeout is not 0, it is the default timeout value set
602 * when SSL_new() is called. This has been put in to make
603 * life easier to set things up */
604 long session_timeout;
605
606 /* If this callback is not null, it will be called each
607 * time a session id is added to the cache. If this function
608 * returns 1, it means that the callback will do a
609 * SSL_SESSION_free() when it has finished using it. Otherwise,
610 * on 0, it means the callback has finished with it.
611 * If remove_session_cb is not null, it will be called when
612 * a session-id is removed from the cache. After the call,
613 * OpenSSL will SSL_SESSION_free() it. */
614 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
615 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
616 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
617 unsigned char *data,int len,int *copy);
618
619 struct
620 {
621 int sess_connect; /* SSL new conn - started */
622 int sess_connect_renegotiate;/* SSL reneg - requested */
623 int sess_connect_good; /* SSL new conne/reneg - finished */
624 int sess_accept; /* SSL new accept - started */
625 int sess_accept_renegotiate;/* SSL reneg - requested */
626 int sess_accept_good; /* SSL accept/reneg - finished */
627 int sess_miss; /* session lookup misses */
628 int sess_timeout; /* reuse attempt on timeouted session */
629 int sess_cache_full; /* session removed due to full cache */
630 int sess_hit; /* session reuse actually done */
631 int sess_cb_hit; /* session-id that was not
632 * in the cache was
633 * passed back via the callback. This
634 * indicates that the application is
635 * supplying session-id's from other
636 * processes - spooky :-) */
637 } stats;
638
639 int references;
640
641 /* if defined, these override the X509_verify_cert() calls */
642 int (*app_verify_callback)(X509_STORE_CTX *, void *);
643 void *app_verify_arg;
644 /* before OpenSSL 0.9.7, 'app_verify_arg' was ignored
645 * ('app_verify_callback' was called with just one argument) */
646
647 /* Default password callback. */
648 pem_password_cb *default_passwd_callback;
649
650 /* Default password callback user data. */
651 void *default_passwd_callback_userdata;
652
653 /* get client cert callback */
654 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
655
656 CRYPTO_EX_DATA ex_data;
657
658 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
659 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
660 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
661
662 STACK_OF(X509) *extra_certs;
663 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
664
665
666 /* Default values used when no per-SSL value is defined follow */
667
668 void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */
669
670 /* what we put in client cert requests */
671 STACK_OF(X509_NAME) *client_CA;
672
673
674 /* Default values to use in SSL structures follow (these are copied by SSL_new) */
675
676 unsigned long options;
677 unsigned long mode;
678 long max_cert_list;
679
680 struct cert_st /* CERT */ *cert;
681 int read_ahead;
682
683 /* callback that allows applications to peek at protocol messages */
684 void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);
685 void *msg_callback_arg;
686
687 int verify_mode;
688 int verify_depth;
689 unsigned int sid_ctx_length;
690 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
691 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
692
693 /* Default generate session ID callback. */
694 GEN_SESSION_CB generate_session_id;
695
696 int purpose; /* Purpose setting */
697 int trust; /* Trust setting */
698
699 int quiet_shutdown;
700 };
701
702#define SSL_SESS_CACHE_OFF 0x0000
703#define SSL_SESS_CACHE_CLIENT 0x0001
704#define SSL_SESS_CACHE_SERVER 0x0002
705#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
706#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
707/* This one, when set, makes the server session-id lookup not look
708 * in the cache. If there is an application get_session callback
709 * defined, this will still get called. */
710#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
711
712 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
713#define SSL_CTX_sess_number(ctx) \
714 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
715#define SSL_CTX_sess_connect(ctx) \
716 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
717#define SSL_CTX_sess_connect_good(ctx) \
718 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
719#define SSL_CTX_sess_connect_renegotiate(ctx) \
720 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
721#define SSL_CTX_sess_accept(ctx) \
722 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
723#define SSL_CTX_sess_accept_renegotiate(ctx) \
724 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
725#define SSL_CTX_sess_accept_good(ctx) \
726 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
727#define SSL_CTX_sess_hits(ctx) \
728 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
729#define SSL_CTX_sess_cb_hits(ctx) \
730 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
731#define SSL_CTX_sess_misses(ctx) \
732 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
733#define SSL_CTX_sess_timeouts(ctx) \
734 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
735#define SSL_CTX_sess_cache_full(ctx) \
736 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
737
738#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
739#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
740#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
741#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
742#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
743#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
744#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
745#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
746#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
747#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
748
749#define SSL_NOTHING 1
750#define SSL_WRITING 2
751#define SSL_READING 3
752#define SSL_X509_LOOKUP 4
753
754/* These will only be used when doing non-blocking IO */
755#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
756#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
757#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
758#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
759
760struct ssl_st
761 {
762 /* protocol version
763 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
764 */
765 int version;
766 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
767
768 SSL_METHOD *method; /* SSLv3 */
769
770 /* There are 2 BIO's even though they are normally both the
771 * same. This is so data can be read and written to different
772 * handlers */
773
774#ifndef OPENSSL_NO_BIO
775 BIO *rbio; /* used by SSL_read */
776 BIO *wbio; /* used by SSL_write */
777 BIO *bbio; /* used during session-id reuse to concatenate
778 * messages */
779#else
780 char *rbio; /* used by SSL_read */
781 char *wbio; /* used by SSL_write */
782 char *bbio;
783#endif
784 /* This holds a variable that indicates what we were doing
785 * when a 0 or -1 is returned. This is needed for
786 * non-blocking IO so we know what request needs re-doing when
787 * in SSL_accept or SSL_connect */
788 int rwstate;
789
790 /* true when we are actually in SSL_accept() or SSL_connect() */
791 int in_handshake;
792 int (*handshake_func)();
793
794 /* Imagine that here's a boolean member "init" that is
795 * switched as soon as SSL_set_{accept/connect}_state
796 * is called for the first time, so that "state" and
797 * "handshake_func" are properly initialized. But as
798 * handshake_func is == 0 until then, we use this
799 * test instead of an "init" member.
800 */
801
802 int server; /* are we the server side? - mostly used by SSL_clear*/
803
804 int new_session;/* 1 if we are to use a new session.
805 * 2 if we are a server and are inside a handshake
806 * (i.e. not just sending a HelloRequest)
807 * NB: For servers, the 'new' session may actually be a previously
808 * cached session or even the previous session unless
809 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
810 int quiet_shutdown;/* don't send shutdown packets */
811 int shutdown; /* we have shut things down, 0x01 sent, 0x02
812 * for received */
813 int state; /* where we are */
814 int rstate; /* where we are when reading */
815
816 BUF_MEM *init_buf; /* buffer used during init */
817 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
818 int init_num; /* amount read/written */
819 int init_off; /* amount read/written */
820
821 /* used internally to point at a raw packet */
822 unsigned char *packet;
823 unsigned int packet_length;
824
825 struct ssl2_state_st *s2; /* SSLv2 variables */
826 struct ssl3_state_st *s3; /* SSLv3 variables */
827
828 int read_ahead; /* Read as many input bytes as possible
829 * (for non-blocking reads) */
830
831 /* callback that allows applications to peek at protocol messages */
832 void (*msg_callback)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg);
833 void *msg_callback_arg;
834
835 int hit; /* reusing a previous session */
836
837 int purpose; /* Purpose setting */
838 int trust; /* Trust setting */
839
840 /* crypto */
841 STACK_OF(SSL_CIPHER) *cipher_list;
842 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
843
844 /* These are the ones being used, the ones in SSL_SESSION are
845 * the ones to be 'copied' into these ones */
846
847 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
848 const EVP_MD *read_hash; /* used for mac generation */
849#ifndef OPENSSL_NO_COMP
850 COMP_CTX *expand; /* uncompress */
851#else
852 char *expand;
853#endif
854
855 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
856 const EVP_MD *write_hash; /* used for mac generation */
857#ifndef OPENSSL_NO_COMP
858 COMP_CTX *compress; /* compression */
859#else
860 char *compress;
861#endif
862
863 /* session info */
864
865 /* client cert? */
866 /* This is used to hold the server certificate used */
867 struct cert_st /* CERT */ *cert;
868
869 /* the session_id_context is used to ensure sessions are only reused
870 * in the appropriate context */
871 unsigned int sid_ctx_length;
872 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
873
874 /* This can also be in the session once a session is established */
875 SSL_SESSION *session;
876
877 /* Default generate session ID callback. */
878 GEN_SESSION_CB generate_session_id;
879
880 /* Used in SSL2 and SSL3 */
881 int verify_mode; /* 0 don't care about verify failure.
882 * 1 fail if verify fails */
883 int verify_depth;
884 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
885
886 void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */
887
888 int error; /* error bytes to be written */
889 int error_code; /* actual code */
890
891#ifndef OPENSSL_NO_KRB5
892 KSSL_CTX *kssl_ctx; /* Kerberos 5 context */
893#endif /* OPENSSL_NO_KRB5 */
894
895 SSL_CTX *ctx;
896 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
897 * and SSL_write() calls, good for nbio debuging :-) */
898 int debug;
899
900 /* extra application data */
901 long verify_result;
902 CRYPTO_EX_DATA ex_data;
903
904 /* for server side, keep the list of CA_dn we can use */
905 STACK_OF(X509_NAME) *client_CA;
906
907 int references;
908 unsigned long options; /* protocol behaviour */
909 unsigned long mode; /* API behaviour */
910 long max_cert_list;
911 int first_packet;
912 int client_version; /* what was passed, used for
913 * SSLv3/TLS rollback check */
914 };
915
916#ifdef __cplusplus
917}
918#endif
919
920#include <openssl/ssl2.h>
921#include <openssl/ssl3.h>
922#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
923#include <openssl/ssl23.h>
924
925#ifdef __cplusplus
926extern "C" {
927#endif
928
929/* compatibility */
930#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
931#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
932#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
933#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
934#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
935#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
936
937/* The following are the possible values for ssl->state are are
938 * used to indicate where we are up to in the SSL connection establishment.
939 * The macros that follow are about the only things you should need to use
940 * and even then, only when using non-blocking IO.
941 * It can also be useful to work out where you were when the connection
942 * failed */
943
944#define SSL_ST_CONNECT 0x1000
945#define SSL_ST_ACCEPT 0x2000
946#define SSL_ST_MASK 0x0FFF
947#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
948#define SSL_ST_BEFORE 0x4000
949#define SSL_ST_OK 0x03
950#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
951
952#define SSL_CB_LOOP 0x01
953#define SSL_CB_EXIT 0x02
954#define SSL_CB_READ 0x04
955#define SSL_CB_WRITE 0x08
956#define SSL_CB_ALERT 0x4000 /* used in callback */
957#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
958#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
959#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
960#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
961#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
962#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
963#define SSL_CB_HANDSHAKE_START 0x10
964#define SSL_CB_HANDSHAKE_DONE 0x20
965
966/* Is the SSL_connection established? */
967#define SSL_get_state(a) SSL_state(a)
968#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
969#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
970#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
971#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
972#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
973
974/* The following 2 states are kept in ssl->rstate when reads fail,
975 * you should not need these */
976#define SSL_ST_READ_HEADER 0xF0
977#define SSL_ST_READ_BODY 0xF1
978#define SSL_ST_READ_DONE 0xF2
979
980/* Obtain latest Finished message
981 * -- that we sent (SSL_get_finished)
982 * -- that we expected from peer (SSL_get_peer_finished).
983 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
984size_t SSL_get_finished(SSL *s, void *buf, size_t count);
985size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);
986
987/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
988 * are 'ored' with SSL_VERIFY_PEER if they are desired */
989#define SSL_VERIFY_NONE 0x00
990#define SSL_VERIFY_PEER 0x01
991#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
992#define SSL_VERIFY_CLIENT_ONCE 0x04
993
994#define OpenSSL_add_ssl_algorithms() SSL_library_init()
995#define SSLeay_add_ssl_algorithms() SSL_library_init()
996
997/* this is for backward compatibility */
998#if 0 /* NEW_SSLEAY */
999#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
1000#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
1001#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
1002#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
1003#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
1004#endif
1005/* More backward compatibility */
1006#define SSL_get_cipher(s) \
1007 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1008#define SSL_get_cipher_bits(s,np) \
1009 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
1010#define SSL_get_cipher_version(s) \
1011 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
1012#define SSL_get_cipher_name(s) \
1013 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1014#define SSL_get_time(a) SSL_SESSION_get_time(a)
1015#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
1016#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
1017#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
1018
1019#if 1 /*SSLEAY_MACROS*/
1020#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
1021 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
1022 (bp),(unsigned char **)(s_id))
1023#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
1024 bp,(unsigned char *)s_id)
1025#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
1026 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
1027#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
1028 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
1029#define PEM_write_SSL_SESSION(fp,x) \
1030 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
1031 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
1032#define PEM_write_bio_SSL_SESSION(bp,x) \
1033 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
1034 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
1035#endif
1036
1037#define SSL_AD_REASON_OFFSET 1000
1038/* These alert types are for SSLv3 and TLSv1 */
1039#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
1040#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
1041#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
1042#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
1043#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
1044#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
1045#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
1046#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
1047#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
1048#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
1049#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
1050#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
1051#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
1052#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
1053#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
1054#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
1055#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
1056#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
1057#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
1058#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
1059#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
1060#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
1061#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
1062#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
1063
1064#define SSL_ERROR_NONE 0
1065#define SSL_ERROR_SSL 1
1066#define SSL_ERROR_WANT_READ 2
1067#define SSL_ERROR_WANT_WRITE 3
1068#define SSL_ERROR_WANT_X509_LOOKUP 4
1069#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
1070#define SSL_ERROR_ZERO_RETURN 6
1071#define SSL_ERROR_WANT_CONNECT 7
1072#define SSL_ERROR_WANT_ACCEPT 8
1073
1074#define SSL_CTRL_NEED_TMP_RSA 1
1075#define SSL_CTRL_SET_TMP_RSA 2
1076#define SSL_CTRL_SET_TMP_DH 3
1077#define SSL_CTRL_SET_TMP_RSA_CB 4
1078#define SSL_CTRL_SET_TMP_DH_CB 5
1079
1080#define SSL_CTRL_GET_SESSION_REUSED 6
1081#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
1082#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
1083#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
1084#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
1085#define SSL_CTRL_GET_FLAGS 11
1086#define SSL_CTRL_EXTRA_CHAIN_CERT 12
1087
1088#define SSL_CTRL_SET_MSG_CALLBACK 13
1089#define SSL_CTRL_SET_MSG_CALLBACK_ARG 14
1090
1091/* Stats */
1092#define SSL_CTRL_SESS_NUMBER 20
1093#define SSL_CTRL_SESS_CONNECT 21
1094#define SSL_CTRL_SESS_CONNECT_GOOD 22
1095#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
1096#define SSL_CTRL_SESS_ACCEPT 24
1097#define SSL_CTRL_SESS_ACCEPT_GOOD 25
1098#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
1099#define SSL_CTRL_SESS_HIT 27
1100#define SSL_CTRL_SESS_CB_HIT 28
1101#define SSL_CTRL_SESS_MISSES 29
1102#define SSL_CTRL_SESS_TIMEOUTS 30
1103#define SSL_CTRL_SESS_CACHE_FULL 31
1104#define SSL_CTRL_OPTIONS 32
1105#define SSL_CTRL_MODE 33
1106
1107#define SSL_CTRL_GET_READ_AHEAD 40
1108#define SSL_CTRL_SET_READ_AHEAD 41
1109#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
1110#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
1111#define SSL_CTRL_SET_SESS_CACHE_MODE 44
1112#define SSL_CTRL_GET_SESS_CACHE_MODE 45
1113
1114#define SSL_CTRL_GET_MAX_CERT_LIST 50
1115#define SSL_CTRL_SET_MAX_CERT_LIST 51
1116
1117#define SSL_session_reused(ssl) \
1118 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
1119#define SSL_num_renegotiations(ssl) \
1120 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
1121#define SSL_clear_num_renegotiations(ssl) \
1122 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
1123#define SSL_total_renegotiations(ssl) \
1124 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
1125
1126#define SSL_CTX_need_tmp_RSA(ctx) \
1127 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1128#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
1129 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1130#define SSL_CTX_set_tmp_dh(ctx,dh) \
1131 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1132
1133#define SSL_need_tmp_RSA(ssl) \
1134 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1135#define SSL_set_tmp_rsa(ssl,rsa) \
1136 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1137#define SSL_set_tmp_dh(ssl,dh) \
1138 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1139
1140#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
1141 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
1142
1143#ifndef OPENSSL_NO_BIO
1144BIO_METHOD *BIO_f_ssl(void);
1145BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
1146BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
1147BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
1148int BIO_ssl_copy_session_id(BIO *to,BIO *from);
1149void BIO_ssl_shutdown(BIO *ssl_bio);
1150
1151#endif
1152
1153int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
1154SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
1155void SSL_CTX_free(SSL_CTX *);
1156long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
1157long SSL_CTX_get_timeout(SSL_CTX *ctx);
1158X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *);
1159void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
1160int SSL_want(SSL *s);
1161int SSL_clear(SSL *s);
1162
1163void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
1164
1165SSL_CIPHER *SSL_get_current_cipher(SSL *s);
1166int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
1167char * SSL_CIPHER_get_version(SSL_CIPHER *c);
1168const char * SSL_CIPHER_get_name(SSL_CIPHER *c);
1169
1170int SSL_get_fd(SSL *s);
1171int SSL_get_rfd(SSL *s);
1172int SSL_get_wfd(SSL *s);
1173const char * SSL_get_cipher_list(SSL *s,int n);
1174char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
1175int SSL_get_read_ahead(SSL * s);
1176int SSL_pending(SSL *s);
1177#ifndef OPENSSL_NO_SOCK
1178int SSL_set_fd(SSL *s, int fd);
1179int SSL_set_rfd(SSL *s, int fd);
1180int SSL_set_wfd(SSL *s, int fd);
1181#endif
1182#ifndef OPENSSL_NO_BIO
1183void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
1184BIO * SSL_get_rbio(SSL *s);
1185BIO * SSL_get_wbio(SSL *s);
1186#endif
1187int SSL_set_cipher_list(SSL *s, const char *str);
1188void SSL_set_read_ahead(SSL *s, int yes);
1189int SSL_get_verify_mode(SSL *s);
1190int SSL_get_verify_depth(SSL *s);
1191int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
1192void SSL_set_verify(SSL *s, int mode,
1193 int (*callback)(int ok,X509_STORE_CTX *ctx));
1194void SSL_set_verify_depth(SSL *s, int depth);
1195#ifndef OPENSSL_NO_RSA
1196int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
1197#endif
1198int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
1199int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
1200int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
1201int SSL_use_certificate(SSL *ssl, X509 *x);
1202int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
1203
1204#ifndef OPENSSL_NO_STDIO
1205int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
1206int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
1207int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
1208int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1209int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1210int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
1211int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
1212STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
1213int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1214 const char *file);
1215#ifndef OPENSSL_SYS_WIN32
1216#ifndef OPENSSL_SYS_VMS
1217#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */
1218int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1219 const char *dir);
1220#endif
1221#endif
1222#endif
1223
1224#endif
1225
1226void SSL_load_error_strings(void );
1227const char *SSL_state_string(const SSL *s);
1228const char *SSL_rstate_string(const SSL *s);
1229const char *SSL_state_string_long(const SSL *s);
1230const char *SSL_rstate_string_long(const SSL *s);
1231long SSL_SESSION_get_time(SSL_SESSION *s);
1232long SSL_SESSION_set_time(SSL_SESSION *s, long t);
1233long SSL_SESSION_get_timeout(SSL_SESSION *s);
1234long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
1235void SSL_copy_session_id(SSL *to,SSL *from);
1236
1237SSL_SESSION *SSL_SESSION_new(void);
1238unsigned long SSL_SESSION_hash(SSL_SESSION *a);
1239int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
1240#ifndef OPENSSL_NO_FP_API
1241int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
1242#endif
1243#ifndef OPENSSL_NO_BIO
1244int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
1245#endif
1246void SSL_SESSION_free(SSL_SESSION *ses);
1247int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
1248int SSL_set_session(SSL *to, SSL_SESSION *session);
1249int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
1250int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
1251int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
1252int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB);
1253int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
1254 unsigned int id_len);
1255SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
1256
1257#ifdef HEADER_X509_H
1258X509 * SSL_get_peer_certificate(SSL *s);
1259#endif
1260
1261STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
1262
1263int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
1264int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
1265int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
1266void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
1267 int (*callback)(int, X509_STORE_CTX *));
1268void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
1269void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg);
1270#ifndef OPENSSL_NO_RSA
1271int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1272#endif
1273int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
1274int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1275int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
1276 unsigned char *d, long len);
1277int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1278int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
1279
1280void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1281void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1282
1283int SSL_CTX_check_private_key(SSL_CTX *ctx);
1284int SSL_check_private_key(SSL *ctx);
1285
1286int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
1287 unsigned int sid_ctx_len);
1288
1289SSL * SSL_new(SSL_CTX *ctx);
1290int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1291 unsigned int sid_ctx_len);
1292
1293int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1294int SSL_set_purpose(SSL *s, int purpose);
1295int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1296int SSL_set_trust(SSL *s, int trust);
1297
1298void SSL_free(SSL *ssl);
1299int SSL_accept(SSL *ssl);
1300int SSL_connect(SSL *ssl);
1301int SSL_read(SSL *ssl,void *buf,int num);
1302int SSL_peek(SSL *ssl,void *buf,int num);
1303int SSL_write(SSL *ssl,const void *buf,int num);
1304long SSL_ctrl(SSL *ssl,int cmd, long larg, void *parg);
1305long SSL_callback_ctrl(SSL *, int, void (*)());
1306long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, void *parg);
1307long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)());
1308
1309int SSL_get_error(SSL *s,int ret_code);
1310const char *SSL_get_version(SSL *s);
1311
1312/* This sets the 'default' SSL version that SSL_new() will create */
1313int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1314
1315SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1316SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1317SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1318
1319SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1320SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1321SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1322
1323SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1324SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1325SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1326
1327SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1328SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1329SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1330
1331STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s);
1332
1333int SSL_do_handshake(SSL *s);
1334int SSL_renegotiate(SSL *s);
1335int SSL_renegotiate_pending(SSL *s);
1336int SSL_shutdown(SSL *s);
1337
1338SSL_METHOD *SSL_get_ssl_method(SSL *s);
1339int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1340const char *SSL_alert_type_string_long(int value);
1341const char *SSL_alert_type_string(int value);
1342const char *SSL_alert_desc_string_long(int value);
1343const char *SSL_alert_desc_string(int value);
1344
1345void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
1346void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
1347STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
1348STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s);
1349int SSL_add_client_CA(SSL *ssl,X509 *x);
1350int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1351
1352void SSL_set_connect_state(SSL *s);
1353void SSL_set_accept_state(SSL *s);
1354
1355long SSL_get_default_timeout(SSL *s);
1356
1357int SSL_library_init(void );
1358
1359char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1360STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1361
1362SSL *SSL_dup(SSL *ssl);
1363
1364X509 *SSL_get_certificate(SSL *ssl);
1365/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1366
1367void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1368int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
1369void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1370int SSL_get_quiet_shutdown(SSL *ssl);
1371void SSL_set_shutdown(SSL *ssl,int mode);
1372int SSL_get_shutdown(SSL *ssl);
1373int SSL_version(SSL *ssl);
1374int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1375int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1376 const char *CApath);
1377#define SSL_get0_session SSL_get_session /* just peek at pointer */
1378SSL_SESSION *SSL_get_session(SSL *ssl);
1379SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1380SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
1381void SSL_set_info_callback(SSL *ssl,
1382 void (*cb)(const SSL *ssl,int type,int val));
1383void (*SSL_get_info_callback(SSL *ssl))(const SSL *ssl,int type,int val);
1384int SSL_state(SSL *ssl);
1385
1386void SSL_set_verify_result(SSL *ssl,long v);
1387long SSL_get_verify_result(SSL *ssl);
1388
1389int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1390void *SSL_get_ex_data(SSL *ssl,int idx);
1391int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1392 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1393
1394int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1395void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
1396int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1397 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1398
1399int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1400void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
1401int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1402 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1403
1404int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1405
1406#define SSL_CTX_sess_set_cache_size(ctx,t) \
1407 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1408#define SSL_CTX_sess_get_cache_size(ctx) \
1409 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1410#define SSL_CTX_set_session_cache_mode(ctx,m) \
1411 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1412#define SSL_CTX_get_session_cache_mode(ctx) \
1413 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1414
1415#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1416#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1417#define SSL_CTX_get_read_ahead(ctx) \
1418 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1419#define SSL_CTX_set_read_ahead(ctx,m) \
1420 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
1421#define SSL_CTX_get_max_cert_list(ctx) \
1422 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1423#define SSL_CTX_set_max_cert_list(ctx,m) \
1424 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1425#define SSL_get_max_cert_list(ssl) \
1426 SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1427#define SSL_set_max_cert_list(ssl,m) \
1428 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1429
1430 /* NB: the keylength is only applicable when is_export is true */
1431#ifndef OPENSSL_NO_RSA
1432void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1433 RSA *(*cb)(SSL *ssl,int is_export,
1434 int keylength));
1435
1436void SSL_set_tmp_rsa_callback(SSL *ssl,
1437 RSA *(*cb)(SSL *ssl,int is_export,
1438 int keylength));
1439#endif
1440#ifndef OPENSSL_NO_DH
1441void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1442 DH *(*dh)(SSL *ssl,int is_export,
1443 int keylength));
1444void SSL_set_tmp_dh_callback(SSL *ssl,
1445 DH *(*dh)(SSL *ssl,int is_export,
1446 int keylength));
1447#endif
1448
1449#ifndef OPENSSL_NO_COMP
1450int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1451#else
1452int SSL_COMP_add_compression_method(int id,char *cm);
1453#endif
1454
1455/* BEGIN ERROR CODES */
1456/* The following lines are auto generated by the script mkerr.pl. Any changes
1457 * made after this point may be overwritten when the script is next run.
1458 */
1459void ERR_load_SSL_strings(void);
1460
1461/* Error codes for the SSL functions. */
1462
1463/* Function codes. */
1464#define SSL_F_CLIENT_CERTIFICATE 100
1465#define SSL_F_CLIENT_FINISHED 238
1466#define SSL_F_CLIENT_HELLO 101
1467#define SSL_F_CLIENT_MASTER_KEY 102
1468#define SSL_F_D2I_SSL_SESSION 103
1469#define SSL_F_DO_SSL3_WRITE 104
1470#define SSL_F_GET_CLIENT_FINISHED 105
1471#define SSL_F_GET_CLIENT_HELLO 106
1472#define SSL_F_GET_CLIENT_MASTER_KEY 107
1473#define SSL_F_GET_SERVER_FINISHED 108
1474#define SSL_F_GET_SERVER_HELLO 109
1475#define SSL_F_GET_SERVER_VERIFY 110
1476#define SSL_F_I2D_SSL_SESSION 111
1477#define SSL_F_READ_N 112
1478#define SSL_F_REQUEST_CERTIFICATE 113
1479#define SSL_F_SERVER_FINISH 239
1480#define SSL_F_SERVER_HELLO 114
1481#define SSL_F_SERVER_VERIFY 240
1482#define SSL_F_SSL23_ACCEPT 115
1483#define SSL_F_SSL23_CLIENT_HELLO 116
1484#define SSL_F_SSL23_CONNECT 117
1485#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1486#define SSL_F_SSL23_GET_SERVER_HELLO 119
1487#define SSL_F_SSL23_PEEK 237
1488#define SSL_F_SSL23_READ 120
1489#define SSL_F_SSL23_WRITE 121
1490#define SSL_F_SSL2_ACCEPT 122
1491#define SSL_F_SSL2_CONNECT 123
1492#define SSL_F_SSL2_ENC_INIT 124
1493#define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241
1494#define SSL_F_SSL2_PEEK 234
1495#define SSL_F_SSL2_READ 125
1496#define SSL_F_SSL2_READ_INTERNAL 236
1497#define SSL_F_SSL2_SET_CERTIFICATE 126
1498#define SSL_F_SSL2_WRITE 127
1499#define SSL_F_SSL3_ACCEPT 128
1500#define SSL_F_SSL3_CALLBACK_CTRL 233
1501#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1502#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1503#define SSL_F_SSL3_CLIENT_HELLO 131
1504#define SSL_F_SSL3_CONNECT 132
1505#define SSL_F_SSL3_CTRL 213
1506#define SSL_F_SSL3_CTX_CTRL 133
1507#define SSL_F_SSL3_ENC 134
1508#define SSL_F_SSL3_GENERATE_KEY_BLOCK 238
1509#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1510#define SSL_F_SSL3_GET_CERT_VERIFY 136
1511#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1512#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1513#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1514#define SSL_F_SSL3_GET_FINISHED 140
1515#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1516#define SSL_F_SSL3_GET_MESSAGE 142
1517#define SSL_F_SSL3_GET_RECORD 143
1518#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1519#define SSL_F_SSL3_GET_SERVER_DONE 145
1520#define SSL_F_SSL3_GET_SERVER_HELLO 146
1521#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1522#define SSL_F_SSL3_PEEK 235
1523#define SSL_F_SSL3_READ_BYTES 148
1524#define SSL_F_SSL3_READ_N 149
1525#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1526#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1527#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1528#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1529#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1530#define SSL_F_SSL3_SEND_SERVER_HELLO 242
1531#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1532#define SSL_F_SSL3_SETUP_BUFFERS 156
1533#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1534#define SSL_F_SSL3_WRITE_BYTES 158
1535#define SSL_F_SSL3_WRITE_PENDING 159
1536#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1537#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1538#define SSL_F_SSL_BAD_METHOD 160
1539#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1540#define SSL_F_SSL_CERT_DUP 221
1541#define SSL_F_SSL_CERT_INST 222
1542#define SSL_F_SSL_CERT_INSTANTIATE 214
1543#define SSL_F_SSL_CERT_NEW 162
1544#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1545#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1546#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1547#define SSL_F_SSL_CLEAR 164
1548#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1549#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1550#define SSL_F_SSL_CTRL 232
1551#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1552#define SSL_F_SSL_CTX_NEW 169
1553#define SSL_F_SSL_CTX_SET_PURPOSE 226
1554#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1555#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1556#define SSL_F_SSL_CTX_SET_TRUST 229
1557#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1558#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1559#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1560#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1561#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1562#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1563#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1564#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1565#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1566#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1567#define SSL_F_SSL_DO_HANDSHAKE 180
1568#define SSL_F_SSL_GET_NEW_SESSION 181
1569#define SSL_F_SSL_GET_PREV_SESSION 217
1570#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1571#define SSL_F_SSL_GET_SIGN_PKEY 183
1572#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1573#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1574#define SSL_F_SSL_NEW 186
1575#define SSL_F_SSL_READ 223
1576#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1577#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1578#define SSL_F_SSL_SESSION_NEW 189
1579#define SSL_F_SSL_SESSION_PRINT_FP 190
1580#define SSL_F_SSL_SESS_CERT_NEW 225
1581#define SSL_F_SSL_SET_CERT 191
1582#define SSL_F_SSL_SET_FD 192
1583#define SSL_F_SSL_SET_PKEY 193
1584#define SSL_F_SSL_SET_PURPOSE 227
1585#define SSL_F_SSL_SET_RFD 194
1586#define SSL_F_SSL_SET_SESSION 195
1587#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1588#define SSL_F_SSL_SET_TRUST 228
1589#define SSL_F_SSL_SET_WFD 196
1590#define SSL_F_SSL_SHUTDOWN 224
1591#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1592#define SSL_F_SSL_USE_CERTIFICATE 198
1593#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1594#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1595#define SSL_F_SSL_USE_PRIVATEKEY 201
1596#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1597#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1598#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1599#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1600#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1601#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1602#define SSL_F_SSL_WRITE 208
1603#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1604#define SSL_F_TLS1_ENC 210
1605#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1606#define SSL_F_WRITE_PENDING 212
1607
1608/* Reason codes. */
1609#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1610#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1611#define SSL_R_BAD_ALERT_RECORD 101
1612#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1613#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1614#define SSL_R_BAD_CHECKSUM 104
1615#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1616#define SSL_R_BAD_DECOMPRESSION 107
1617#define SSL_R_BAD_DH_G_LENGTH 108
1618#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1619#define SSL_R_BAD_DH_P_LENGTH 110
1620#define SSL_R_BAD_DIGEST_LENGTH 111
1621#define SSL_R_BAD_DSA_SIGNATURE 112
1622#define SSL_R_BAD_HELLO_REQUEST 105
1623#define SSL_R_BAD_LENGTH 271
1624#define SSL_R_BAD_MAC_DECODE 113
1625#define SSL_R_BAD_MESSAGE_TYPE 114
1626#define SSL_R_BAD_PACKET_LENGTH 115
1627#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1628#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1629#define SSL_R_BAD_RSA_DECRYPT 118
1630#define SSL_R_BAD_RSA_ENCRYPT 119
1631#define SSL_R_BAD_RSA_E_LENGTH 120
1632#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1633#define SSL_R_BAD_RSA_SIGNATURE 122
1634#define SSL_R_BAD_SIGNATURE 123
1635#define SSL_R_BAD_SSL_FILETYPE 124
1636#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1637#define SSL_R_BAD_STATE 126
1638#define SSL_R_BAD_WRITE_RETRY 127
1639#define SSL_R_BIO_NOT_SET 128
1640#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1641#define SSL_R_BN_LIB 130
1642#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1643#define SSL_R_CA_DN_TOO_LONG 132
1644#define SSL_R_CCS_RECEIVED_EARLY 133
1645#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1646#define SSL_R_CERT_LENGTH_MISMATCH 135
1647#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1648#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1649#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1650#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1651#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1652#define SSL_R_COMPRESSION_FAILURE 141
1653#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1654#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1655#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1656#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1657#define SSL_R_DATA_LENGTH_TOO_LONG 146
1658#define SSL_R_DECRYPTION_FAILED 147
1659#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 1109
1660#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1661#define SSL_R_DIGEST_CHECK_FAILED 149
1662#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1663#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 1092
1664#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1665#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1666#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1667#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1668#define SSL_R_HTTPS_PROXY_REQUEST 155
1669#define SSL_R_HTTP_REQUEST 156
1670#define SSL_R_ILLEGAL_PADDING 1110
1671#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1672#define SSL_R_INVALID_COMMAND 280
1673#define SSL_R_INVALID_PURPOSE 278
1674#define SSL_R_INVALID_TRUST 279
1675#define SSL_R_KEY_ARG_TOO_LONG 1112
1676#define SSL_R_KRB5 1104
1677#define SSL_R_KRB5_C_CC_PRINC 1094
1678#define SSL_R_KRB5_C_GET_CRED 1095
1679#define SSL_R_KRB5_C_INIT 1096
1680#define SSL_R_KRB5_C_MK_REQ 1097
1681#define SSL_R_KRB5_S_BAD_TICKET 1098
1682#define SSL_R_KRB5_S_INIT 1099
1683#define SSL_R_KRB5_S_RD_REQ 1108
1684#define SSL_R_KRB5_S_TKT_EXPIRED 1105
1685#define SSL_R_KRB5_S_TKT_NYV 1106
1686#define SSL_R_KRB5_S_TKT_SKEW 1107
1687#define SSL_R_LENGTH_MISMATCH 159
1688#define SSL_R_LENGTH_TOO_SHORT 160
1689#define SSL_R_LIBRARY_BUG 274
1690#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1691#define SSL_R_MESSAGE_TOO_LONG 1111
1692#define SSL_R_MISSING_DH_DSA_CERT 162
1693#define SSL_R_MISSING_DH_KEY 163
1694#define SSL_R_MISSING_DH_RSA_CERT 164
1695#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1696#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1697#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1698#define SSL_R_MISSING_RSA_CERTIFICATE 168
1699#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1700#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1701#define SSL_R_MISSING_TMP_DH_KEY 171
1702#define SSL_R_MISSING_TMP_RSA_KEY 172
1703#define SSL_R_MISSING_TMP_RSA_PKEY 173
1704#define SSL_R_MISSING_VERIFY_MESSAGE 174
1705#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1706#define SSL_R_NO_CERTIFICATES_RETURNED 176
1707#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1708#define SSL_R_NO_CERTIFICATE_RETURNED 178
1709#define SSL_R_NO_CERTIFICATE_SET 179
1710#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1711#define SSL_R_NO_CIPHERS_AVAILABLE 181
1712#define SSL_R_NO_CIPHERS_PASSED 182
1713#define SSL_R_NO_CIPHERS_SPECIFIED 183
1714#define SSL_R_NO_CIPHER_LIST 184
1715#define SSL_R_NO_CIPHER_MATCH 185
1716#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1717#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1718#define SSL_R_NO_METHOD_SPECIFIED 188
1719#define SSL_R_NO_PRIVATEKEY 189
1720#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1721#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1722#define SSL_R_NO_PUBLICKEY 192
1723#define SSL_R_NO_SHARED_CIPHER 193
1724#define SSL_R_NO_VERIFY_CALLBACK 194
1725#define SSL_R_NULL_SSL_CTX 195
1726#define SSL_R_NULL_SSL_METHOD_PASSED 196
1727#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1728#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1729#define SSL_R_PATH_TOO_LONG 270
1730#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1731#define SSL_R_PEER_ERROR 200
1732#define SSL_R_PEER_ERROR_CERTIFICATE 201
1733#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1734#define SSL_R_PEER_ERROR_NO_CIPHER 203
1735#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1736#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1737#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1738#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1739#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1740#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1741#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1742#define SSL_R_READ_BIO_NOT_SET 211
1743#define SSL_R_READ_WRONG_PACKET_TYPE 212
1744#define SSL_R_RECORD_LENGTH_MISMATCH 213
1745#define SSL_R_RECORD_TOO_LARGE 214
1746#define SSL_R_RECORD_TOO_SMALL 1093
1747#define SSL_R_REQUIRED_CIPHER_MISSING 215
1748#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1749#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1750#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1751#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1752#define SSL_R_SHORT_READ 219
1753#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1754#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1755#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 1114
1756#define SSL_R_SSL3_SESSION_ID_TOO_LONG 1113
1757#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1758#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1759#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1760#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1761#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1762#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1763#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1764#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1765#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1766#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1767#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223
1768#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224
1769#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225
1770#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226
1771#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1772#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227
1773#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1774#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1775#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1776#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1777#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 1102
1778#define SSL_R_SSL_SESSION_ID_CONFLICT 1103
1779#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1780#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 1101
1781#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1782#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1783#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1784#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1785#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1786#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
1787#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1788#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1789#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1790#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1791#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1792#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1793#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
1794#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1795#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1796#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1797#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1798#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1799#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1800#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1801#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1802#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1803#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1804#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1805#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1806#define SSL_R_UNEXPECTED_MESSAGE 244
1807#define SSL_R_UNEXPECTED_RECORD 245
1808#define SSL_R_UNINITIALIZED 276
1809#define SSL_R_UNKNOWN_ALERT_TYPE 246
1810#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1811#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1812#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1813#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1814#define SSL_R_UNKNOWN_PKEY_TYPE 251
1815#define SSL_R_UNKNOWN_PROTOCOL 252
1816#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1817#define SSL_R_UNKNOWN_SSL_VERSION 254
1818#define SSL_R_UNKNOWN_STATE 255
1819#define SSL_R_UNSUPPORTED_CIPHER 256
1820#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1821#define SSL_R_UNSUPPORTED_OPTION 1091
1822#define SSL_R_UNSUPPORTED_PROTOCOL 258
1823#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1824#define SSL_R_WRITE_BIO_NOT_SET 260
1825#define SSL_R_WRONG_CIPHER_RETURNED 261
1826#define SSL_R_WRONG_MESSAGE_TYPE 262
1827#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1828#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1829#define SSL_R_WRONG_SIGNATURE_SIZE 265
1830#define SSL_R_WRONG_SSL_VERSION 266
1831#define SSL_R_WRONG_VERSION_NUMBER 267
1832#define SSL_R_X509_LIB 268
1833#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1834
1835#ifdef __cplusplus
1836}
1837#endif
1838#endif
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index 99a52ea0dd..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,268 +0,0 @@
1/* ssl/ssl2.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_SSL2_H
60#define HEADER_SSL2_H
61
62#ifdef __cplusplus
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 OPENSSL_SYS_MPE
137#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 29998u
138#else
139#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */
140#endif
141#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */
142
143#define SSL2_CHALLENGE_LENGTH 16
144/*#define SSL2_CHALLENGE_LENGTH 32 */
145#define SSL2_MIN_CHALLENGE_LENGTH 16
146#define SSL2_MAX_CHALLENGE_LENGTH 32
147#define SSL2_CONNECTION_ID_LENGTH 16
148#define SSL2_MAX_CONNECTION_ID_LENGTH 16
149#define SSL2_SSL_SESSION_ID_LENGTH 16
150#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
151#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
152#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
153
154#ifndef HEADER_SSL_LOCL_H
155#define CERT char
156#endif
157
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
193 unsigned char *read_key;
194 unsigned char *write_key;
195
196 /* Stuff specifically to do with this SSL session */
197 unsigned int challenge_length;
198 unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
199 unsigned int conn_id_length;
200 unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
201 unsigned int key_material_length;
202 unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
203
204 unsigned long read_sequence;
205 unsigned long write_sequence;
206
207 struct {
208 unsigned int conn_id_length;
209 unsigned int cert_type;
210 unsigned int cert_length;
211 unsigned int csl;
212 unsigned int clear;
213 unsigned int enc;
214 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
215 unsigned int cipher_spec_length;
216 unsigned int session_id_length;
217 unsigned int clen;
218 unsigned int rlen;
219 } tmp;
220 } SSL2_STATE;
221
222/* SSLv2 */
223/* client */
224#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
225#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
226#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
227#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
228#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
229#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
230#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
231#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
232#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
233#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
234#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
235#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
236#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
237#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
238#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
239#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
240#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
241#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
242/* server */
243#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
244#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
245#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
246#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
247#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
248#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
249#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
250#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
251#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
252#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
253#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
254#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
255#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
256#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
257#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
258#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
259#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
260#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
261#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
262#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
263
264#ifdef __cplusplus
265}
266#endif
267#endif
268
diff --git a/src/lib/libssl/ssl23.h b/src/lib/libssl/ssl23.h
deleted file mode 100644
index d3228983c7..0000000000
--- a/src/lib/libssl/ssl23.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/* ssl/ssl23.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_SSL23_H
60#define HEADER_SSL23_H
61
62#ifdef __cplusplus
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 8fd6951d77..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,504 +0,0 @@
1/* ssl/ssl3.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_SSL3_H
113#define HEADER_SSL3_H
114
115#ifndef OPENSSL_NO_COMP
116#include <openssl/comp.h>
117#endif
118#include <openssl/buffer.h>
119#include <openssl/evp.h>
120#include <openssl/ssl.h>
121
122#ifdef __cplusplus
123extern "C" {
124#endif
125
126#define SSL3_CK_RSA_NULL_MD5 0x03000001
127#define SSL3_CK_RSA_NULL_SHA 0x03000002
128#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
129#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
130#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
131#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
132#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
133#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
134#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
135#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
136
137#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
138#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
139#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
140#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
141#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
142#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
143
144#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
145#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
146#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
147#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
148#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
149#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
150
151#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
152#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
153#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
154#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
155#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
156
157#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
158#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
159#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
160
161/* VRS Additional Kerberos5 entries
162 */
163#define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000021
164#define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000022
165#define SSL3_CK_KRB5_DES_64_CBC_SHA 0x03000023
166#define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000024
167#define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x03000025
168#define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000026
169
170#define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA"
171#define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5"
172#define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA"
173#define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5"
174#define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA"
175#define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5"
176
177#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
178#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
179#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
180#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
181#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
182#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
183#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
184#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
185#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
186#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
187
188#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
189#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
190#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
191#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
192#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
193#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
194
195#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
196#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
197#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
198#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
199#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
200#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
201
202#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
203#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
204#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
205#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
206#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
207
208#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
209#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
210#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
211
212#define SSL3_SSL_SESSION_ID_LENGTH 32
213#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
214
215#define SSL3_MASTER_SECRET_SIZE 48
216#define SSL3_RANDOM_SIZE 32
217#define SSL3_SESSION_ID_SIZE 32
218#define SSL3_RT_HEADER_LENGTH 5
219
220/* Due to MS stuffing up, this can change.... */
221#if defined(OPENSSL_SYS_WIN16) || \
222 (defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32))
223#define SSL3_RT_MAX_EXTRA (14000)
224#else
225#define SSL3_RT_MAX_EXTRA (16384)
226#endif
227
228#define SSL3_RT_MAX_PLAIN_LENGTH 16384
229#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
230#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
231#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
232#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
233
234#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
235#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
236
237#define SSL3_VERSION 0x0300
238#define SSL3_VERSION_MAJOR 0x03
239#define SSL3_VERSION_MINOR 0x00
240
241#define SSL3_RT_CHANGE_CIPHER_SPEC 20
242#define SSL3_RT_ALERT 21
243#define SSL3_RT_HANDSHAKE 22
244#define SSL3_RT_APPLICATION_DATA 23
245
246#define SSL3_AL_WARNING 1
247#define SSL3_AL_FATAL 2
248
249#define SSL3_AD_CLOSE_NOTIFY 0
250#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
251#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
252#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
253#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
254#define SSL3_AD_NO_CERTIFICATE 41
255#define SSL3_AD_BAD_CERTIFICATE 42
256#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
257#define SSL3_AD_CERTIFICATE_REVOKED 44
258#define SSL3_AD_CERTIFICATE_EXPIRED 45
259#define SSL3_AD_CERTIFICATE_UNKNOWN 46
260#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
261
262typedef struct ssl3_record_st
263 {
264/*r */ int type; /* type of record */
265/*rw*/ unsigned int length; /* How many bytes available */
266/*r */ unsigned int off; /* read/write offset into 'buf' */
267/*rw*/ unsigned char *data; /* pointer to the record data */
268/*rw*/ unsigned char *input; /* where the decode bytes are */
269/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
270 } SSL3_RECORD;
271
272typedef struct ssl3_buffer_st
273 {
274 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
275 * see ssl3_setup_buffers() */
276 size_t len; /* buffer size */
277 int offset; /* where to 'copy from' */
278 int left; /* how many bytes left */
279 } SSL3_BUFFER;
280
281#define SSL3_CT_RSA_SIGN 1
282#define SSL3_CT_DSS_SIGN 2
283#define SSL3_CT_RSA_FIXED_DH 3
284#define SSL3_CT_DSS_FIXED_DH 4
285#define SSL3_CT_RSA_EPHEMERAL_DH 5
286#define SSL3_CT_DSS_EPHEMERAL_DH 6
287#define SSL3_CT_FORTEZZA_DMS 20
288#define SSL3_CT_NUMBER 7
289
290#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
291#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
292#define SSL3_FLAGS_POP_BUFFER 0x0004
293#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
294
295typedef struct ssl3_state_st
296 {
297 long flags;
298 int delay_buf_pop_ret;
299
300 unsigned char read_sequence[8];
301 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
302 unsigned char write_sequence[8];
303 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
304
305 unsigned char server_random[SSL3_RANDOM_SIZE];
306 unsigned char client_random[SSL3_RANDOM_SIZE];
307
308 /* flags for countermeasure against known-IV weakness */
309 int need_empty_fragments;
310 int empty_fragment_done;
311
312 SSL3_BUFFER rbuf; /* read IO goes into here */
313 SSL3_BUFFER wbuf; /* write IO goes into here */
314
315 SSL3_RECORD rrec; /* each decoded record goes in here */
316 SSL3_RECORD wrec; /* goes out from here */
317
318 /* storage for Alert/Handshake protocol data received but not
319 * yet processed by ssl3_read_bytes: */
320 unsigned char alert_fragment[2];
321 unsigned int alert_fragment_len;
322 unsigned char handshake_fragment[4];
323 unsigned int handshake_fragment_len;
324
325 /* partial write - check the numbers match */
326 unsigned int wnum; /* number of bytes sent so far */
327 int wpend_tot; /* number bytes written */
328 int wpend_type;
329 int wpend_ret; /* number of bytes submitted */
330 const unsigned char *wpend_buf;
331
332 /* used during startup, digest all incoming/outgoing packets */
333 EVP_MD_CTX finish_dgst1;
334 EVP_MD_CTX finish_dgst2;
335
336 /* this is set whenerver we see a change_cipher_spec message
337 * come in when we are not looking for one */
338 int change_cipher_spec;
339
340 int warn_alert;
341 int fatal_alert;
342 /* we allow one fatal and one warning alert to be outstanding,
343 * send close alert via the warning alert */
344 int alert_dispatch;
345 unsigned char send_alert[2];
346
347 /* This flag is set when we should renegotiate ASAP, basically when
348 * there is no more data in the read or write buffers */
349 int renegotiate;
350 int total_renegotiations;
351 int num_renegotiations;
352
353 int in_read_app_data;
354
355 struct {
356 /* actually only needs to be 16+20 */
357 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
358
359 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
360 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
361 int finish_md_len;
362 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
363 int peer_finish_md_len;
364
365 unsigned long message_size;
366 int message_type;
367
368 /* used to hold the new cipher we are going to use */
369 SSL_CIPHER *new_cipher;
370#ifndef OPENSSL_NO_DH
371 DH *dh;
372#endif
373 /* used when SSL_ST_FLUSH_DATA is entered */
374 int next_state;
375
376 int reuse_message;
377
378 /* used for certificate requests */
379 int cert_req;
380 int ctype_num;
381 char ctype[SSL3_CT_NUMBER];
382 STACK_OF(X509_NAME) *ca_names;
383
384 int use_rsa_tmp;
385
386 int key_block_length;
387 unsigned char *key_block;
388
389 const EVP_CIPHER *new_sym_enc;
390 const EVP_MD *new_hash;
391#ifndef OPENSSL_NO_COMP
392 const SSL_COMP *new_compression;
393#else
394 char *new_compression;
395#endif
396 int cert_request;
397 } tmp;
398
399 } SSL3_STATE;
400
401/* SSLv3 */
402/*client */
403/* extra state */
404#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
405/* write to server */
406#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
407#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
408/* read from server */
409#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
410#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
411#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
412#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
413#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
414#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
415#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
416#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
417#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
418#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
419/* write to server */
420#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
421#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
422#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
423#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
424#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
425#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
426#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
427#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
428#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
429#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
430#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
431#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
432/* read from server */
433#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
434#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
435#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
436#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
437
438/* server */
439/* extra state */
440#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
441/* read from client */
442/* Do not change the number values, they do matter */
443#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
444#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
445#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
446/* write to client */
447#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
448#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
449#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
450#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
451#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
452#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
453#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
454#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
455#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
456#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
457#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
458#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
459#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
460/* read from client */
461#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
462#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
463#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
464#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
465#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
466#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
467#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
468#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
469#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
470#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
471/* write to client */
472#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
473#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
474#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
475#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
476
477#define SSL3_MT_HELLO_REQUEST 0
478#define SSL3_MT_CLIENT_HELLO 1
479#define SSL3_MT_SERVER_HELLO 2
480#define SSL3_MT_CERTIFICATE 11
481#define SSL3_MT_SERVER_KEY_EXCHANGE 12
482#define SSL3_MT_CERTIFICATE_REQUEST 13
483#define SSL3_MT_SERVER_DONE 14
484#define SSL3_MT_CERTIFICATE_VERIFY 15
485#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
486#define SSL3_MT_FINISHED 20
487
488#define SSL3_MT_CCS 1
489
490/* These are used when changing over to a new cipher */
491#define SSL3_CC_READ 0x01
492#define SSL3_CC_WRITE 0x02
493#define SSL3_CC_CLIENT 0x10
494#define SSL3_CC_SERVER 0x20
495#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
496#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
497#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
498#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
499
500#ifdef __cplusplus
501}
502#endif
503#endif
504
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c
deleted file mode 100644
index 3d1299ee7b..0000000000
--- a/src/lib/libssl/ssl_algs.c
+++ /dev/null
@@ -1,111 +0,0 @@
1/* ssl/ssl_algs.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/objects.h>
61#include <openssl/lhash.h>
62#include "ssl_locl.h"
63
64int SSL_library_init(void)
65 {
66
67#ifndef OPENSSL_NO_DES
68 EVP_add_cipher(EVP_des_cbc());
69 EVP_add_cipher(EVP_des_ede3_cbc());
70#endif
71#ifndef OPENSSL_NO_IDEA
72 EVP_add_cipher(EVP_idea_cbc());
73#endif
74#ifndef OPENSSL_NO_RC4
75 EVP_add_cipher(EVP_rc4());
76#endif
77#ifndef OPENSSL_NO_RC2
78 EVP_add_cipher(EVP_rc2_cbc());
79#endif
80#ifndef OPENSSL_NO_AES
81 EVP_add_cipher(EVP_aes_128_cbc());
82 EVP_add_cipher(EVP_aes_192_cbc());
83 EVP_add_cipher(EVP_aes_256_cbc());
84#endif
85#ifndef OPENSSL_NO_MD2
86 EVP_add_digest(EVP_md2());
87#endif
88#ifndef OPENSSL_NO_MD5
89 EVP_add_digest(EVP_md5());
90 EVP_add_digest_alias(SN_md5,"ssl2-md5");
91 EVP_add_digest_alias(SN_md5,"ssl3-md5");
92#endif
93#ifndef OPENSSL_NO_SHA
94 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
95 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
96 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
97#endif
98#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_DSA)
99 EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
100 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
101 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
102 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
103#endif
104 /* If you want support for phased out ciphers, add the following */
105#if 0
106 EVP_add_digest(EVP_sha());
107 EVP_add_digest(EVP_dss());
108#endif
109 return(1);
110 }
111
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index 23bfe44e21..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,391 +0,0 @@
1/* ssl/ssl_asn1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "ssl_locl.h"
62#include <openssl/asn1_mac.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65
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#ifndef OPENSSL_NO_KRB5
76 ASN1_OCTET_STRING krb5_princ;
77#endif /* OPENSSL_NO_KRB5 */
78 ASN1_INTEGER time;
79 ASN1_INTEGER timeout;
80 ASN1_INTEGER verify_result;
81 } SSL_SESSION_ASN1;
82
83int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
84 {
85#define LSIZE2 (sizeof(long)*2)
86 int v1=0,v2=0,v3=0,v4=0,v5=0;
87 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
88 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
89 long l;
90 SSL_SESSION_ASN1 a;
91 M_ASN1_I2D_vars(in);
92
93 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
94 return(0);
95
96 /* Note that I cheat in the following 2 assignments. I know
97 * that if the ASN1_INTEGER passed to ASN1_INTEGER_set
98 * is > sizeof(long)+1, the buffer will not be re-OPENSSL_malloc()ed.
99 * This is a bit evil but makes things simple, no dynamic allocation
100 * to clean up :-) */
101 a.version.length=LSIZE2;
102 a.version.type=V_ASN1_INTEGER;
103 a.version.data=ibuf1;
104 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
105
106 a.ssl_version.length=LSIZE2;
107 a.ssl_version.type=V_ASN1_INTEGER;
108 a.ssl_version.data=ibuf2;
109 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
110
111 a.cipher.type=V_ASN1_OCTET_STRING;
112 a.cipher.data=buf;
113
114 if (in->cipher == NULL)
115 l=in->cipher_id;
116 else
117 l=in->cipher->id;
118 if (in->ssl_version == SSL2_VERSION)
119 {
120 a.cipher.length=3;
121 buf[0]=((unsigned char)(l>>16L))&0xff;
122 buf[1]=((unsigned char)(l>> 8L))&0xff;
123 buf[2]=((unsigned char)(l ))&0xff;
124 }
125 else
126 {
127 a.cipher.length=2;
128 buf[0]=((unsigned char)(l>>8L))&0xff;
129 buf[1]=((unsigned char)(l ))&0xff;
130 }
131
132 a.master_key.length=in->master_key_length;
133 a.master_key.type=V_ASN1_OCTET_STRING;
134 a.master_key.data=in->master_key;
135
136 a.session_id.length=in->session_id_length;
137 a.session_id.type=V_ASN1_OCTET_STRING;
138 a.session_id.data=in->session_id;
139
140 a.session_id_context.length=in->sid_ctx_length;
141 a.session_id_context.type=V_ASN1_OCTET_STRING;
142 a.session_id_context.data=in->sid_ctx;
143
144 a.key_arg.length=in->key_arg_length;
145 a.key_arg.type=V_ASN1_OCTET_STRING;
146 a.key_arg.data=in->key_arg;
147
148#ifndef OPENSSL_NO_KRB5
149 if (in->krb5_client_princ_len)
150 {
151 a.krb5_princ.length=in->krb5_client_princ_len;
152 a.krb5_princ.type=V_ASN1_OCTET_STRING;
153 a.krb5_princ.data=in->krb5_client_princ;
154 }
155#endif /* OPENSSL_NO_KRB5 */
156
157 if (in->time != 0L)
158 {
159 a.time.length=LSIZE2;
160 a.time.type=V_ASN1_INTEGER;
161 a.time.data=ibuf3;
162 ASN1_INTEGER_set(&(a.time),in->time);
163 }
164
165 if (in->timeout != 0L)
166 {
167 a.timeout.length=LSIZE2;
168 a.timeout.type=V_ASN1_INTEGER;
169 a.timeout.data=ibuf4;
170 ASN1_INTEGER_set(&(a.timeout),in->timeout);
171 }
172
173 if (in->verify_result != X509_V_OK)
174 {
175 a.verify_result.length=LSIZE2;
176 a.verify_result.type=V_ASN1_INTEGER;
177 a.verify_result.data=ibuf5;
178 ASN1_INTEGER_set(&a.verify_result,in->verify_result);
179 }
180
181
182 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
183 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
184 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
185 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
186 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
187#ifndef OPENSSL_NO_KRB5
188 if (in->krb5_client_princ_len)
189 M_ASN1_I2D_len(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
190#endif /* OPENSSL_NO_KRB5 */
191 if (in->key_arg_length > 0)
192 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
193 if (in->time != 0L)
194 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
195 if (in->timeout != 0L)
196 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
197 if (in->peer != NULL)
198 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
199 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
200 if (in->verify_result != X509_V_OK)
201 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5);
202
203 M_ASN1_I2D_seq_total();
204
205 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
206 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
207 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
208 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
209 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
210#ifndef OPENSSL_NO_KRB5
211 if (in->krb5_client_princ_len)
212 M_ASN1_I2D_put(&(a.krb5_princ), i2d_ASN1_OCTET_STRING);
213#endif /* OPENSSL_NO_KRB5 */
214 if (in->key_arg_length > 0)
215 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
216 if (in->time != 0L)
217 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
218 if (in->timeout != 0L)
219 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
220 if (in->peer != NULL)
221 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
222 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
223 v4);
224 if (in->verify_result != X509_V_OK)
225 M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5);
226 M_ASN1_I2D_finish();
227 }
228
229SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp,
230 long length)
231 {
232 int version,ssl_version=0,i;
233 long id;
234 ASN1_INTEGER ai,*aip;
235 ASN1_OCTET_STRING os,*osp;
236 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
237
238 aip= &ai;
239 osp= &os;
240
241 M_ASN1_D2I_Init();
242 M_ASN1_D2I_start_sequence();
243
244 ai.data=NULL; ai.length=0;
245 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
246 version=(int)ASN1_INTEGER_get(aip);
247 if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
248
249 /* we don't care about the version right now :-) */
250 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
251 ssl_version=(int)ASN1_INTEGER_get(aip);
252 ret->ssl_version=ssl_version;
253 if (ai.data != NULL) { OPENSSL_free(ai.data); ai.data=NULL; ai.length=0; }
254
255 os.data=NULL; os.length=0;
256 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
257 if (ssl_version == SSL2_VERSION)
258 {
259 if (os.length != 3)
260 {
261 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
262 goto err;
263 }
264 id=0x02000000L|
265 ((unsigned long)os.data[0]<<16L)|
266 ((unsigned long)os.data[1]<< 8L)|
267 (unsigned long)os.data[2];
268 }
269 else if ((ssl_version>>8) == 3)
270 {
271 if (os.length != 2)
272 {
273 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
274 goto err;
275 }
276 id=0x03000000L|
277 ((unsigned long)os.data[0]<<8L)|
278 (unsigned long)os.data[1];
279 }
280 else
281 {
282 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
283 return(NULL);
284 }
285
286 ret->cipher=NULL;
287 ret->cipher_id=id;
288
289 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
290 if ((ssl_version>>8) == SSL3_VERSION)
291 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
292 else /* if (ssl_version == SSL2_VERSION) */
293 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
294
295 if (os.length > i)
296 os.length = i;
297 if (os.length > sizeof ret->session_id) /* can't happen */
298 os.length = sizeof ret->session_id;
299
300 ret->session_id_length=os.length;
301 memcpy(ret->session_id,os.data,os.length);
302
303 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
304 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
305 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
306 else
307 ret->master_key_length=os.length;
308 memcpy(ret->master_key,os.data,ret->master_key_length);
309
310 os.length=0;
311
312#ifndef OPENSSL_NO_KRB5
313 os.length=0;
314 M_ASN1_D2I_get_opt(osp,d2i_ASN1_OCTET_STRING,V_ASN1_OCTET_STRING);
315 if (os.data)
316 {
317 if (os.length > SSL_MAX_KRB5_PRINCIPAL_LENGTH)
318 ret->krb5_client_princ_len=0;
319 else
320 ret->krb5_client_princ_len=os.length;
321 memcpy(ret->krb5_client_princ,os.data,ret->krb5_client_princ_len);
322 OPENSSL_free(os.data);
323 os.data = NULL;
324 os.length = 0;
325 }
326 else
327 ret->krb5_client_princ_len=0;
328#endif /* OPENSSL_NO_KRB5 */
329
330 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
331 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
332 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
333 else
334 ret->key_arg_length=os.length;
335 memcpy(ret->key_arg,os.data,ret->key_arg_length);
336 if (os.data != NULL) OPENSSL_free(os.data);
337
338 ai.length=0;
339 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
340 if (ai.data != NULL)
341 {
342 ret->time=ASN1_INTEGER_get(aip);
343 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
344 }
345 else
346 ret->time=time(NULL);
347
348 ai.length=0;
349 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
350 if (ai.data != NULL)
351 {
352 ret->timeout=ASN1_INTEGER_get(aip);
353 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
354 }
355 else
356 ret->timeout=3;
357
358 if (ret->peer != NULL)
359 {
360 X509_free(ret->peer);
361 ret->peer=NULL;
362 }
363 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
364
365 os.length=0;
366 os.data=NULL;
367 M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
368
369 if(os.data != NULL)
370 {
371 if (os.length > SSL_MAX_SID_CTX_LENGTH)
372 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH);
373 ret->sid_ctx_length=os.length;
374 memcpy(ret->sid_ctx,os.data,os.length);
375 OPENSSL_free(os.data); os.data=NULL; os.length=0;
376 }
377 else
378 ret->sid_ctx_length=0;
379
380 ai.length=0;
381 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5);
382 if (ai.data != NULL)
383 {
384 ret->verify_result=ASN1_INTEGER_get(aip);
385 OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
386 }
387 else
388 ret->verify_result=X509_V_OK;
389
390 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
391 }
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index 3d31bbf05f..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,832 +0,0 @@
1/*! \file ssl/ssl_cert.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@OpenSSL.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 */
106
107#include <stdio.h>
108
109#include "e_os.h"
110#ifndef NO_SYS_TYPES_H
111# include <sys/types.h>
112#endif
113
114#if !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_VMS) && !defined(NeXT) && !defined(MAC_OS_pre_X)
115#include <dirent.h>
116#endif
117
118#if defined(WIN32)
119#include <windows.h>
120#endif
121
122#ifdef NeXT
123#include <sys/dir.h>
124#define dirent direct
125#endif
126
127#include <openssl/objects.h>
128#include <openssl/bio.h>
129#include <openssl/pem.h>
130#include <openssl/x509v3.h>
131#include "ssl_locl.h"
132
133int SSL_get_ex_data_X509_STORE_CTX_idx(void)
134 {
135 static volatile int ssl_x509_store_ctx_idx= -1;
136
137 if (ssl_x509_store_ctx_idx < 0)
138 {
139 /* any write lock will do; usually this branch
140 * will only be taken once anyway */
141 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
142
143 if (ssl_x509_store_ctx_idx < 0)
144 {
145 ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
146 0,"SSL for verify callback",NULL,NULL,NULL);
147 }
148
149 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
150 }
151 return ssl_x509_store_ctx_idx;
152 }
153
154CERT *ssl_cert_new(void)
155 {
156 CERT *ret;
157
158 ret=(CERT *)OPENSSL_malloc(sizeof(CERT));
159 if (ret == NULL)
160 {
161 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
162 return(NULL);
163 }
164 memset(ret,0,sizeof(CERT));
165
166 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
167 ret->references=1;
168
169 return(ret);
170 }
171
172CERT *ssl_cert_dup(CERT *cert)
173 {
174 CERT *ret;
175 int i;
176
177 ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
178 if (ret == NULL)
179 {
180 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
181 return(NULL);
182 }
183
184 memset(ret, 0, sizeof(CERT));
185
186 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
187 /* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
188 * if you find that more readable */
189
190 ret->valid = cert->valid;
191 ret->mask = cert->mask;
192 ret->export_mask = cert->export_mask;
193
194#ifndef OPENSSL_NO_RSA
195 if (cert->rsa_tmp != NULL)
196 {
197 RSA_up_ref(cert->rsa_tmp);
198 ret->rsa_tmp = cert->rsa_tmp;
199 }
200 ret->rsa_tmp_cb = cert->rsa_tmp_cb;
201#endif
202
203#ifndef OPENSSL_NO_DH
204 if (cert->dh_tmp != NULL)
205 {
206 /* DH parameters don't have a reference count */
207 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
208 if (ret->dh_tmp == NULL)
209 {
210 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB);
211 goto err;
212 }
213 if (cert->dh_tmp->priv_key)
214 {
215 BIGNUM *b = BN_dup(cert->dh_tmp->priv_key);
216 if (!b)
217 {
218 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
219 goto err;
220 }
221 ret->dh_tmp->priv_key = b;
222 }
223 if (cert->dh_tmp->pub_key)
224 {
225 BIGNUM *b = BN_dup(cert->dh_tmp->pub_key);
226 if (!b)
227 {
228 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
229 goto err;
230 }
231 ret->dh_tmp->pub_key = b;
232 }
233 }
234 ret->dh_tmp_cb = cert->dh_tmp_cb;
235#endif
236
237 for (i = 0; i < SSL_PKEY_NUM; i++)
238 {
239 if (cert->pkeys[i].x509 != NULL)
240 {
241 ret->pkeys[i].x509 = cert->pkeys[i].x509;
242 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
243 CRYPTO_LOCK_X509);
244 }
245
246 if (cert->pkeys[i].privatekey != NULL)
247 {
248 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
249 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
250 CRYPTO_LOCK_EVP_PKEY);
251
252 switch(i)
253 {
254 /* If there was anything special to do for
255 * certain types of keys, we'd do it here.
256 * (Nothing at the moment, I think.) */
257
258 case SSL_PKEY_RSA_ENC:
259 case SSL_PKEY_RSA_SIGN:
260 /* We have an RSA key. */
261 break;
262
263 case SSL_PKEY_DSA_SIGN:
264 /* We have a DSA key. */
265 break;
266
267 case SSL_PKEY_DH_RSA:
268 case SSL_PKEY_DH_DSA:
269 /* We have a DH key. */
270 break;
271
272 default:
273 /* Can't happen. */
274 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
275 }
276 }
277 }
278
279 /* ret->extra_certs *should* exist, but currently the own certificate
280 * chain is held inside SSL_CTX */
281
282 ret->references=1;
283
284 return(ret);
285
286#ifndef OPENSSL_NO_DH /* avoid 'unreferenced label' warning if OPENSSL_NO_DH is defined */
287err:
288#endif
289#ifndef OPENSSL_NO_RSA
290 if (ret->rsa_tmp != NULL)
291 RSA_free(ret->rsa_tmp);
292#endif
293#ifndef OPENSSL_NO_DH
294 if (ret->dh_tmp != NULL)
295 DH_free(ret->dh_tmp);
296#endif
297
298 for (i = 0; i < SSL_PKEY_NUM; i++)
299 {
300 if (ret->pkeys[i].x509 != NULL)
301 X509_free(ret->pkeys[i].x509);
302 if (ret->pkeys[i].privatekey != NULL)
303 EVP_PKEY_free(ret->pkeys[i].privatekey);
304 }
305
306 return NULL;
307 }
308
309
310void ssl_cert_free(CERT *c)
311 {
312 int i;
313
314 if(c == NULL)
315 return;
316
317 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
318#ifdef REF_PRINT
319 REF_PRINT("CERT",c);
320#endif
321 if (i > 0) return;
322#ifdef REF_CHECK
323 if (i < 0)
324 {
325 fprintf(stderr,"ssl_cert_free, bad reference count\n");
326 abort(); /* ok */
327 }
328#endif
329
330#ifndef OPENSSL_NO_RSA
331 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
332#endif
333#ifndef OPENSSL_NO_DH
334 if (c->dh_tmp) DH_free(c->dh_tmp);
335#endif
336
337 for (i=0; i<SSL_PKEY_NUM; i++)
338 {
339 if (c->pkeys[i].x509 != NULL)
340 X509_free(c->pkeys[i].x509);
341 if (c->pkeys[i].privatekey != NULL)
342 EVP_PKEY_free(c->pkeys[i].privatekey);
343#if 0
344 if (c->pkeys[i].publickey != NULL)
345 EVP_PKEY_free(c->pkeys[i].publickey);
346#endif
347 }
348 OPENSSL_free(c);
349 }
350
351int ssl_cert_inst(CERT **o)
352 {
353 /* Create a CERT if there isn't already one
354 * (which cannot really happen, as it is initially created in
355 * SSL_CTX_new; but the earlier code usually allows for that one
356 * being non-existant, so we follow that behaviour, as it might
357 * turn out that there actually is a reason for it -- but I'm
358 * not sure that *all* of the existing code could cope with
359 * s->cert being NULL, otherwise we could do without the
360 * initialization in SSL_CTX_new).
361 */
362
363 if (o == NULL)
364 {
365 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
366 return(0);
367 }
368 if (*o == NULL)
369 {
370 if ((*o = ssl_cert_new()) == NULL)
371 {
372 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
373 return(0);
374 }
375 }
376 return(1);
377 }
378
379
380SESS_CERT *ssl_sess_cert_new(void)
381 {
382 SESS_CERT *ret;
383
384 ret = OPENSSL_malloc(sizeof *ret);
385 if (ret == NULL)
386 {
387 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
388 return NULL;
389 }
390
391 memset(ret, 0 ,sizeof *ret);
392 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
393 ret->references = 1;
394
395 return ret;
396 }
397
398void ssl_sess_cert_free(SESS_CERT *sc)
399 {
400 int i;
401
402 if (sc == NULL)
403 return;
404
405 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
406#ifdef REF_PRINT
407 REF_PRINT("SESS_CERT", sc);
408#endif
409 if (i > 0)
410 return;
411#ifdef REF_CHECK
412 if (i < 0)
413 {
414 fprintf(stderr,"ssl_sess_cert_free, bad reference count\n");
415 abort(); /* ok */
416 }
417#endif
418
419 /* i == 0 */
420 if (sc->cert_chain != NULL)
421 sk_X509_pop_free(sc->cert_chain, X509_free);
422 for (i = 0; i < SSL_PKEY_NUM; i++)
423 {
424 if (sc->peer_pkeys[i].x509 != NULL)
425 X509_free(sc->peer_pkeys[i].x509);
426#if 0 /* We don't have the peer's private key. These lines are just
427 * here as a reminder that we're still using a not-quite-appropriate
428 * data structure. */
429 if (sc->peer_pkeys[i].privatekey != NULL)
430 EVP_PKEY_free(sc->peer_pkeys[i].privatekey);
431#endif
432 }
433
434#ifndef OPENSSL_NO_RSA
435 if (sc->peer_rsa_tmp != NULL)
436 RSA_free(sc->peer_rsa_tmp);
437#endif
438#ifndef OPENSSL_NO_DH
439 if (sc->peer_dh_tmp != NULL)
440 DH_free(sc->peer_dh_tmp);
441#endif
442
443 OPENSSL_free(sc);
444 }
445
446int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
447 {
448 sc->peer_cert_type = type;
449 return(1);
450 }
451
452int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
453 {
454 X509 *x;
455 int i;
456 X509_STORE_CTX ctx;
457
458 if ((sk == NULL) || (sk_X509_num(sk) == 0))
459 return(0);
460
461 x=sk_X509_value(sk,0);
462 if(!X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk))
463 {
464 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB);
465 return(0);
466 }
467 if (SSL_get_verify_depth(s) >= 0)
468 X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
469 X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
470
471 /* We need to set the verify purpose. The purpose can be determined by
472 * the context: if its a server it will verify SSL client certificates
473 * or vice versa.
474 */
475 if (s->server)
476 i = X509_PURPOSE_SSL_CLIENT;
477 else
478 i = X509_PURPOSE_SSL_SERVER;
479
480 X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
481
482 if (s->verify_callback)
483 X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback);
484
485 if (s->ctx->app_verify_callback != NULL)
486#if 1 /* new with OpenSSL 0.9.7 */
487 i=s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg);
488#else
489 i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
490#endif
491 else
492 {
493#ifndef OPENSSL_NO_X509_VERIFY
494 i=X509_verify_cert(&ctx);
495#else
496 i=0;
497 ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
498 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK);
499#endif
500 }
501
502 s->verify_result=ctx.error;
503 X509_STORE_CTX_cleanup(&ctx);
504
505 return(i);
506 }
507
508static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *list)
509 {
510 if (*ca_list != NULL)
511 sk_X509_NAME_pop_free(*ca_list,X509_NAME_free);
512
513 *ca_list=list;
514 }
515
516STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
517 {
518 int i;
519 STACK_OF(X509_NAME) *ret;
520 X509_NAME *name;
521
522 ret=sk_X509_NAME_new_null();
523 for (i=0; i<sk_X509_NAME_num(sk); i++)
524 {
525 name=X509_NAME_dup(sk_X509_NAME_value(sk,i));
526 if ((name == NULL) || !sk_X509_NAME_push(ret,name))
527 {
528 sk_X509_NAME_pop_free(ret,X509_NAME_free);
529 return(NULL);
530 }
531 }
532 return(ret);
533 }
534
535void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list)
536 {
537 set_client_CA_list(&(s->client_CA),list);
538 }
539
540void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *list)
541 {
542 set_client_CA_list(&(ctx->client_CA),list);
543 }
544
545STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx)
546 {
547 return(ctx->client_CA);
548 }
549
550STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s)
551 {
552 if (s->type == SSL_ST_CONNECT)
553 { /* we are in the client */
554 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
555 (s->s3 != NULL))
556 return(s->s3->tmp.ca_names);
557 else
558 return(NULL);
559 }
560 else
561 {
562 if (s->client_CA != NULL)
563 return(s->client_CA);
564 else
565 return(s->ctx->client_CA);
566 }
567 }
568
569static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x)
570 {
571 X509_NAME *name;
572
573 if (x == NULL) return(0);
574 if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL))
575 return(0);
576
577 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
578 return(0);
579
580 if (!sk_X509_NAME_push(*sk,name))
581 {
582 X509_NAME_free(name);
583 return(0);
584 }
585 return(1);
586 }
587
588int SSL_add_client_CA(SSL *ssl,X509 *x)
589 {
590 return(add_client_CA(&(ssl->client_CA),x));
591 }
592
593int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
594 {
595 return(add_client_CA(&(ctx->client_CA),x));
596 }
597
598static int xname_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
599 {
600 return(X509_NAME_cmp(*a,*b));
601 }
602
603#ifndef OPENSSL_NO_STDIO
604/*!
605 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
606 * it doesn't really have anything to do with clients (except that a common use
607 * for a stack of CAs is to send it to the client). Actually, it doesn't have
608 * much to do with CAs, either, since it will load any old cert.
609 * \param file the file containing one or more certs.
610 * \return a ::STACK containing the certs.
611 */
612STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
613 {
614 BIO *in;
615 X509 *x=NULL;
616 X509_NAME *xn=NULL;
617 STACK_OF(X509_NAME) *ret,*sk;
618
619 ret=sk_X509_NAME_new_null();
620 sk=sk_X509_NAME_new(xname_cmp);
621
622 in=BIO_new(BIO_s_file_internal());
623
624 if ((ret == NULL) || (sk == NULL) || (in == NULL))
625 {
626 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
627 goto err;
628 }
629
630 if (!BIO_read_filename(in,file))
631 goto err;
632
633 for (;;)
634 {
635 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
636 break;
637 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
638 /* check for duplicates */
639 xn=X509_NAME_dup(xn);
640 if (xn == NULL) goto err;
641 if (sk_X509_NAME_find(sk,xn) >= 0)
642 X509_NAME_free(xn);
643 else
644 {
645 sk_X509_NAME_push(sk,xn);
646 sk_X509_NAME_push(ret,xn);
647 }
648 }
649
650 if (0)
651 {
652err:
653 if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free);
654 ret=NULL;
655 }
656 if (sk != NULL) sk_X509_NAME_free(sk);
657 if (in != NULL) BIO_free(in);
658 if (x != NULL) X509_free(x);
659 return(ret);
660 }
661#endif
662
663/*!
664 * Add a file of certs to a stack.
665 * \param stack the stack to add to.
666 * \param file the file to add from. All certs in this file that are not
667 * already in the stack will be added.
668 * \return 1 for success, 0 for failure. Note that in the case of failure some
669 * certs may have been added to \c stack.
670 */
671
672int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
673 const char *file)
674 {
675 BIO *in;
676 X509 *x=NULL;
677 X509_NAME *xn=NULL;
678 int ret=1;
679 int (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b);
680
681 oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp);
682
683 in=BIO_new(BIO_s_file_internal());
684
685 if (in == NULL)
686 {
687 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);
688 goto err;
689 }
690
691 if (!BIO_read_filename(in,file))
692 goto err;
693
694 for (;;)
695 {
696 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
697 break;
698 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
699 xn=X509_NAME_dup(xn);
700 if (xn == NULL) goto err;
701 if (sk_X509_NAME_find(stack,xn) >= 0)
702 X509_NAME_free(xn);
703 else
704 sk_X509_NAME_push(stack,xn);
705 }
706
707 if (0)
708 {
709err:
710 ret=0;
711 }
712 if(in != NULL)
713 BIO_free(in);
714 if(x != NULL)
715 X509_free(x);
716
717 sk_X509_NAME_set_cmp_func(stack,oldcmp);
718
719 return ret;
720 }
721
722/*!
723 * Add a directory of certs to a stack.
724 * \param stack the stack to append to.
725 * \param dir the directory to append from. All files in this directory will be
726 * examined as potential certs. Any that are acceptable to
727 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be
728 * included.
729 * \return 1 for success, 0 for failure. Note that in the case of failure some
730 * certs may have been added to \c stack.
731 */
732
733#ifndef OPENSSL_SYS_WIN32
734#ifndef OPENSSL_SYS_VMS /* XXXX This may be fixed in the future */
735#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! */
736
737int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
738 const char *dir)
739 {
740 DIR *d;
741 struct dirent *dstruct;
742 int ret = 0;
743
744 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
745 d = opendir(dir);
746
747 /* Note that a side effect is that the CAs will be sorted by name */
748 if(!d)
749 {
750 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
751 ERR_add_error_data(3, "opendir('", dir, "')");
752 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
753 goto err;
754 }
755
756 while((dstruct=readdir(d)))
757 {
758 char buf[1024];
759 int r;
760
761 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
762 {
763 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
764 goto err;
765 }
766
767 r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
768 if (r <= 0 || r >= sizeof buf)
769 goto err;
770 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
771 goto err;
772 }
773 ret = 1;
774
775err:
776 if (d) closedir(d);
777 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
778 return ret;
779 }
780
781#endif
782#endif
783
784#else
785
786int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
787 const char *dir)
788 {
789 WIN32_FIND_DATA FindFileData;
790 HANDLE hFind;
791 int ret = 0;
792
793 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
794
795 hFind = FindFirstFile(dir, &FindFileData);
796 /* Note that a side effect is that the CAs will be sorted by name */
797 if(hFind == INVALID_HANDLE_VALUE)
798 {
799 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
800 ERR_add_error_data(3, "opendir('", dir, "')");
801 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
802 goto err_noclose;
803 }
804
805 do
806 {
807 char buf[1024];
808 int r;
809
810 if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf)
811 {
812 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
813 goto err;
814 }
815
816 r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,FindFileData.cFileName);
817 if (r <= 0 || r >= sizeof buf)
818 goto err;
819 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
820 goto err;
821 }
822 while (FindNextFile(hFind, &FindFileData) != FALSE);
823 ret = 1;
824
825err:
826 FindClose(hFind);
827err_noclose:
828 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
829 return ret;
830 }
831
832#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index df48245b2c..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1139 +0,0 @@
1/* ssl/ssl_ciph.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/objects.h>
61#include <openssl/comp.h>
62#include "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_AES128_IDX 7
72#define SSL_ENC_AES256_IDX 8
73#define SSL_ENC_NUM_IDX 9
74
75static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
76 NULL,NULL,NULL,NULL,NULL,NULL,
77 };
78
79static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
80
81#define SSL_MD_MD5_IDX 0
82#define SSL_MD_SHA1_IDX 1
83#define SSL_MD_NUM_IDX 2
84static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
85 NULL,NULL,
86 };
87
88#define CIPHER_ADD 1
89#define CIPHER_KILL 2
90#define CIPHER_DEL 3
91#define CIPHER_ORD 4
92#define CIPHER_SPECIAL 5
93
94typedef struct cipher_order_st
95 {
96 SSL_CIPHER *cipher;
97 int active;
98 int dead;
99 struct cipher_order_st *next,*prev;
100 } CIPHER_ORDER;
101
102static const SSL_CIPHER cipher_aliases[]={
103 /* Don't include eNULL unless specifically enabled. */
104 {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
105 {0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */
106 {0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0},
107 {0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */
108 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
109 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
110 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
111 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
112 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
113 {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
114 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
115
116 {0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */
117 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
118 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
119 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
120 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
121 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
122 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
123
124 {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
125 {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
126 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
127 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
128#ifndef OPENSSL_NO_IDEA
129 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
130#endif
131 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
132 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
133 {0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0},
134
135 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
136 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
137 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
138
139 {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
140 {0,SSL_TXT_KRB5,0,SSL_KRB5, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
141 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
142 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
143 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
144
145 {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
146 {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
147 {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
148
149 {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
150 {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
151 {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
152 {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
153 {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
154 {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
155 {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
156 };
157
158static int init_ciphers=1;
159
160static void load_ciphers(void)
161 {
162 init_ciphers=0;
163 ssl_cipher_methods[SSL_ENC_DES_IDX]=
164 EVP_get_cipherbyname(SN_des_cbc);
165 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
166 EVP_get_cipherbyname(SN_des_ede3_cbc);
167 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
168 EVP_get_cipherbyname(SN_rc4);
169 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
170 EVP_get_cipherbyname(SN_rc2_cbc);
171#ifndef OPENSSL_NO_IDEA
172 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
173 EVP_get_cipherbyname(SN_idea_cbc);
174#else
175 ssl_cipher_methods[SSL_ENC_IDEA_IDX]= NULL;
176#endif
177 ssl_cipher_methods[SSL_ENC_AES128_IDX]=
178 EVP_get_cipherbyname(SN_aes_128_cbc);
179 ssl_cipher_methods[SSL_ENC_AES256_IDX]=
180 EVP_get_cipherbyname(SN_aes_256_cbc);
181
182 ssl_digest_methods[SSL_MD_MD5_IDX]=
183 EVP_get_digestbyname(SN_md5);
184 ssl_digest_methods[SSL_MD_SHA1_IDX]=
185 EVP_get_digestbyname(SN_sha1);
186 }
187
188int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc,
189 const EVP_MD **md, SSL_COMP **comp)
190 {
191 int i;
192 SSL_CIPHER *c;
193
194 c=s->cipher;
195 if (c == NULL) return(0);
196 if (comp != NULL)
197 {
198 SSL_COMP ctmp;
199
200 if (s->compress_meth == 0)
201 *comp=NULL;
202 else if (ssl_comp_methods == NULL)
203 {
204 /* bad */
205 *comp=NULL;
206 }
207 else
208 {
209
210 ctmp.id=s->compress_meth;
211 i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
212 if (i >= 0)
213 *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
214 else
215 *comp=NULL;
216 }
217 }
218
219 if ((enc == NULL) || (md == NULL)) return(0);
220
221 switch (c->algorithms & SSL_ENC_MASK)
222 {
223 case SSL_DES:
224 i=SSL_ENC_DES_IDX;
225 break;
226 case SSL_3DES:
227 i=SSL_ENC_3DES_IDX;
228 break;
229 case SSL_RC4:
230 i=SSL_ENC_RC4_IDX;
231 break;
232 case SSL_RC2:
233 i=SSL_ENC_RC2_IDX;
234 break;
235 case SSL_IDEA:
236 i=SSL_ENC_IDEA_IDX;
237 break;
238 case SSL_eNULL:
239 i=SSL_ENC_NULL_IDX;
240 break;
241 case SSL_AES:
242 switch(c->alg_bits)
243 {
244 case 128: i=SSL_ENC_AES128_IDX; break;
245 case 256: i=SSL_ENC_AES256_IDX; break;
246 default: i=-1; break;
247 }
248 break;
249 default:
250 i= -1;
251 break;
252 }
253
254 if ((i < 0) || (i > SSL_ENC_NUM_IDX))
255 *enc=NULL;
256 else
257 {
258 if (i == SSL_ENC_NULL_IDX)
259 *enc=EVP_enc_null();
260 else
261 *enc=ssl_cipher_methods[i];
262 }
263
264 switch (c->algorithms & SSL_MAC_MASK)
265 {
266 case SSL_MD5:
267 i=SSL_MD_MD5_IDX;
268 break;
269 case SSL_SHA1:
270 i=SSL_MD_SHA1_IDX;
271 break;
272 default:
273 i= -1;
274 break;
275 }
276 if ((i < 0) || (i > SSL_MD_NUM_IDX))
277 *md=NULL;
278 else
279 *md=ssl_digest_methods[i];
280
281 if ((*enc != NULL) && (*md != NULL))
282 return(1);
283 else
284 return(0);
285 }
286
287#define ITEM_SEP(a) \
288 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
289
290static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
291 CIPHER_ORDER **tail)
292 {
293 if (curr == *tail) return;
294 if (curr == *head)
295 *head=curr->next;
296 if (curr->prev != NULL)
297 curr->prev->next=curr->next;
298 if (curr->next != NULL) /* should always be true */
299 curr->next->prev=curr->prev;
300 (*tail)->next=curr;
301 curr->prev= *tail;
302 curr->next=NULL;
303 *tail=curr;
304 }
305
306static unsigned long ssl_cipher_get_disabled(void)
307 {
308 unsigned long mask;
309
310 mask = SSL_kFZA;
311#ifdef OPENSSL_NO_RSA
312 mask |= SSL_aRSA|SSL_kRSA;
313#endif
314#ifdef OPENSSL_NO_DSA
315 mask |= SSL_aDSS;
316#endif
317#ifdef OPENSSL_NO_DH
318 mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
319#endif
320#ifdef OPENSSL_NO_KRB5
321 mask |= SSL_kKRB5|SSL_aKRB5;
322#endif
323
324#ifdef SSL_FORBID_ENULL
325 mask |= SSL_eNULL;
326#endif
327
328 mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
329 mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
330 mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
331 mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
332 mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
333 mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
334 mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0;
335
336 mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
337 mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
338
339 return(mask);
340 }
341
342static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
343 int num_of_ciphers, unsigned long mask, CIPHER_ORDER *list,
344 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
345 {
346 int i, list_num;
347 SSL_CIPHER *c;
348
349 /*
350 * We have num_of_ciphers descriptions compiled in, depending on the
351 * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
352 * These will later be sorted in a linked list with at most num
353 * entries.
354 */
355
356 /* Get the initial list of ciphers */
357 list_num = 0; /* actual count of ciphers */
358 for (i = 0; i < num_of_ciphers; i++)
359 {
360 c = ssl_method->get_cipher(i);
361 /* drop those that use any of that is not available */
362 if ((c != NULL) && c->valid && !(c->algorithms & mask))
363 {
364 list[list_num].cipher = c;
365 list[list_num].next = NULL;
366 list[list_num].prev = NULL;
367 list[list_num].active = 0;
368 list_num++;
369#ifdef KSSL_DEBUG
370 printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms);
371#endif /* KSSL_DEBUG */
372 /*
373 if (!sk_push(ca_list,(char *)c)) goto err;
374 */
375 }
376 }
377
378 /*
379 * Prepare linked list from list entries
380 */
381 for (i = 1; i < list_num - 1; i++)
382 {
383 list[i].prev = &(list[i-1]);
384 list[i].next = &(list[i+1]);
385 }
386 if (list_num > 0)
387 {
388 (*head_p) = &(list[0]);
389 (*head_p)->prev = NULL;
390 (*head_p)->next = &(list[1]);
391 (*tail_p) = &(list[list_num - 1]);
392 (*tail_p)->prev = &(list[list_num - 2]);
393 (*tail_p)->next = NULL;
394 }
395 }
396
397static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
398 int num_of_group_aliases, unsigned long mask,
399 CIPHER_ORDER *head)
400 {
401 CIPHER_ORDER *ciph_curr;
402 SSL_CIPHER **ca_curr;
403 int i;
404
405 /*
406 * First, add the real ciphers as already collected
407 */
408 ciph_curr = head;
409 ca_curr = ca_list;
410 while (ciph_curr != NULL)
411 {
412 *ca_curr = ciph_curr->cipher;
413 ca_curr++;
414 ciph_curr = ciph_curr->next;
415 }
416
417 /*
418 * Now we add the available ones from the cipher_aliases[] table.
419 * They represent either an algorithm, that must be fully
420 * supported (not match any bit in mask) or represent a cipher
421 * strength value (will be added in any case because algorithms=0).
422 */
423 for (i = 0; i < num_of_group_aliases; i++)
424 {
425 if ((i == 0) || /* always fetch "ALL" */
426 !(cipher_aliases[i].algorithms & mask))
427 {
428 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
429 ca_curr++;
430 }
431 }
432
433 *ca_curr = NULL; /* end of list */
434 }
435
436static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask,
437 unsigned long algo_strength, unsigned long mask_strength,
438 int rule, int strength_bits, CIPHER_ORDER *list,
439 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
440 {
441 CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
442 SSL_CIPHER *cp;
443 unsigned long ma, ma_s;
444
445#ifdef CIPHER_DEBUG
446 printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
447 rule, algorithms, mask, algo_strength, mask_strength,
448 strength_bits);
449#endif
450
451 curr = head = *head_p;
452 curr2 = head;
453 tail2 = tail = *tail_p;
454 for (;;)
455 {
456 if ((curr == NULL) || (curr == tail2)) break;
457 curr = curr2;
458 curr2 = curr->next;
459
460 cp = curr->cipher;
461
462 /*
463 * Selection criteria is either the number of strength_bits
464 * or the algorithm used.
465 */
466 if (strength_bits == -1)
467 {
468 ma = mask & cp->algorithms;
469 ma_s = mask_strength & cp->algo_strength;
470
471#ifdef CIPHER_DEBUG
472 printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
473 printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
474#endif
475 /*
476 * Select: if none of the mask bit was met from the
477 * cipher or not all of the bits were met, the
478 * selection does not apply.
479 */
480 if (((ma == 0) && (ma_s == 0)) ||
481 ((ma & algorithms) != ma) ||
482 ((ma_s & algo_strength) != ma_s))
483 continue; /* does not apply */
484 }
485 else if (strength_bits != cp->strength_bits)
486 continue; /* does not apply */
487
488#ifdef CIPHER_DEBUG
489 printf("Action = %d\n", rule);
490#endif
491
492 /* add the cipher if it has not been added yet. */
493 if (rule == CIPHER_ADD)
494 {
495 if (!curr->active)
496 {
497 ll_append_tail(&head, curr, &tail);
498 curr->active = 1;
499 }
500 }
501 /* Move the added cipher to this location */
502 else if (rule == CIPHER_ORD)
503 {
504 if (curr->active)
505 {
506 ll_append_tail(&head, curr, &tail);
507 }
508 }
509 else if (rule == CIPHER_DEL)
510 curr->active = 0;
511 else if (rule == CIPHER_KILL)
512 {
513 if (head == curr)
514 head = curr->next;
515 else
516 curr->prev->next = curr->next;
517 if (tail == curr)
518 tail = curr->prev;
519 curr->active = 0;
520 if (curr->next != NULL)
521 curr->next->prev = curr->prev;
522 if (curr->prev != NULL)
523 curr->prev->next = curr->next;
524 curr->next = NULL;
525 curr->prev = NULL;
526 }
527 }
528
529 *head_p = head;
530 *tail_p = tail;
531 }
532
533static int ssl_cipher_strength_sort(CIPHER_ORDER *list, CIPHER_ORDER **head_p,
534 CIPHER_ORDER **tail_p)
535 {
536 int max_strength_bits, i, *number_uses;
537 CIPHER_ORDER *curr;
538
539 /*
540 * This routine sorts the ciphers with descending strength. The sorting
541 * must keep the pre-sorted sequence, so we apply the normal sorting
542 * routine as '+' movement to the end of the list.
543 */
544 max_strength_bits = 0;
545 curr = *head_p;
546 while (curr != NULL)
547 {
548 if (curr->active &&
549 (curr->cipher->strength_bits > max_strength_bits))
550 max_strength_bits = curr->cipher->strength_bits;
551 curr = curr->next;
552 }
553
554 number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int));
555 if (!number_uses)
556 {
557 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
558 return(0);
559 }
560 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
561
562 /*
563 * Now find the strength_bits values actually used
564 */
565 curr = *head_p;
566 while (curr != NULL)
567 {
568 if (curr->active)
569 number_uses[curr->cipher->strength_bits]++;
570 curr = curr->next;
571 }
572 /*
573 * Go through the list of used strength_bits values in descending
574 * order.
575 */
576 for (i = max_strength_bits; i >= 0; i--)
577 if (number_uses[i] > 0)
578 ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i,
579 list, head_p, tail_p);
580
581 OPENSSL_free(number_uses);
582 return(1);
583 }
584
585static int ssl_cipher_process_rulestr(const char *rule_str,
586 CIPHER_ORDER *list, CIPHER_ORDER **head_p,
587 CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
588 {
589 unsigned long algorithms, mask, algo_strength, mask_strength;
590 const char *l, *start, *buf;
591 int j, multi, found, rule, retval, ok, buflen;
592 char ch;
593
594 retval = 1;
595 l = rule_str;
596 for (;;)
597 {
598 ch = *l;
599
600 if (ch == '\0')
601 break; /* done */
602 if (ch == '-')
603 { rule = CIPHER_DEL; l++; }
604 else if (ch == '+')
605 { rule = CIPHER_ORD; l++; }
606 else if (ch == '!')
607 { rule = CIPHER_KILL; l++; }
608 else if (ch == '@')
609 { rule = CIPHER_SPECIAL; l++; }
610 else
611 { rule = CIPHER_ADD; }
612
613 if (ITEM_SEP(ch))
614 {
615 l++;
616 continue;
617 }
618
619 algorithms = mask = algo_strength = mask_strength = 0;
620
621 start=l;
622 for (;;)
623 {
624 ch = *l;
625 buf = l;
626 buflen = 0;
627#ifndef CHARSET_EBCDIC
628 while ( ((ch >= 'A') && (ch <= 'Z')) ||
629 ((ch >= '0') && (ch <= '9')) ||
630 ((ch >= 'a') && (ch <= 'z')) ||
631 (ch == '-'))
632#else
633 while ( isalnum(ch) || (ch == '-'))
634#endif
635 {
636 ch = *(++l);
637 buflen++;
638 }
639
640 if (buflen == 0)
641 {
642 /*
643 * We hit something we cannot deal with,
644 * it is no command or separator nor
645 * alphanumeric, so we call this an error.
646 */
647 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
648 SSL_R_INVALID_COMMAND);
649 retval = found = 0;
650 l++;
651 break;
652 }
653
654 if (rule == CIPHER_SPECIAL)
655 {
656 found = 0; /* unused -- avoid compiler warning */
657 break; /* special treatment */
658 }
659
660 /* check for multi-part specification */
661 if (ch == '+')
662 {
663 multi=1;
664 l++;
665 }
666 else
667 multi=0;
668
669 /*
670 * Now search for the cipher alias in the ca_list. Be careful
671 * with the strncmp, because the "buflen" limitation
672 * will make the rule "ADH:SOME" and the cipher
673 * "ADH-MY-CIPHER" look like a match for buflen=3.
674 * So additionally check whether the cipher name found
675 * has the correct length. We can save a strlen() call:
676 * just checking for the '\0' at the right place is
677 * sufficient, we have to strncmp() anyway.
678 */
679 j = found = 0;
680 while (ca_list[j])
681 {
682 if ((ca_list[j]->name[buflen] == '\0') &&
683 !strncmp(buf, ca_list[j]->name, buflen))
684 {
685 found = 1;
686 break;
687 }
688 else
689 j++;
690 }
691 if (!found)
692 break; /* ignore this entry */
693
694 algorithms |= ca_list[j]->algorithms;
695 mask |= ca_list[j]->mask;
696 algo_strength |= ca_list[j]->algo_strength;
697 mask_strength |= ca_list[j]->mask_strength;
698
699 if (!multi) break;
700 }
701
702 /*
703 * Ok, we have the rule, now apply it
704 */
705 if (rule == CIPHER_SPECIAL)
706 { /* special command */
707 ok = 0;
708 if ((buflen == 8) &&
709 !strncmp(buf, "STRENGTH", 8))
710 ok = ssl_cipher_strength_sort(list,
711 head_p, tail_p);
712 else
713 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
714 SSL_R_INVALID_COMMAND);
715 if (ok == 0)
716 retval = 0;
717 /*
718 * We do not support any "multi" options
719 * together with "@", so throw away the
720 * rest of the command, if any left, until
721 * end or ':' is found.
722 */
723 while ((*l != '\0') && ITEM_SEP(*l))
724 l++;
725 }
726 else if (found)
727 {
728 ssl_cipher_apply_rule(algorithms, mask,
729 algo_strength, mask_strength, rule, -1,
730 list, head_p, tail_p);
731 }
732 else
733 {
734 while ((*l != '\0') && ITEM_SEP(*l))
735 l++;
736 }
737 if (*l == '\0') break; /* done */
738 }
739
740 return(retval);
741 }
742
743STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
744 STACK_OF(SSL_CIPHER) **cipher_list,
745 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
746 const char *rule_str)
747 {
748 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
749 unsigned long disabled_mask;
750 STACK_OF(SSL_CIPHER) *cipherstack;
751 const char *rule_p;
752 CIPHER_ORDER *list = NULL, *head = NULL, *tail = NULL, *curr;
753 SSL_CIPHER **ca_list = NULL;
754
755 /*
756 * Return with error if nothing to do.
757 */
758 if (rule_str == NULL) return(NULL);
759
760 if (init_ciphers) load_ciphers();
761
762 /*
763 * To reduce the work to do we only want to process the compiled
764 * in algorithms, so we first get the mask of disabled ciphers.
765 */
766 disabled_mask = ssl_cipher_get_disabled();
767
768 /*
769 * Now we have to collect the available ciphers from the compiled
770 * in ciphers. We cannot get more than the number compiled in, so
771 * it is used for allocation.
772 */
773 num_of_ciphers = ssl_method->num_ciphers();
774#ifdef KSSL_DEBUG
775 printf("ssl_create_cipher_list() for %d ciphers\n", num_of_ciphers);
776#endif /* KSSL_DEBUG */
777 list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
778 if (list == NULL)
779 {
780 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
781 return(NULL); /* Failure */
782 }
783
784 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
785 list, &head, &tail);
786
787 /*
788 * We also need cipher aliases for selecting based on the rule_str.
789 * There might be two types of entries in the rule_str: 1) names
790 * of ciphers themselves 2) aliases for groups of ciphers.
791 * For 1) we need the available ciphers and for 2) the cipher
792 * groups of cipher_aliases added together in one list (otherwise
793 * we would be happy with just the cipher_aliases table).
794 */
795 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
796 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
797 ca_list =
798 (SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
799 if (ca_list == NULL)
800 {
801 OPENSSL_free(list);
802 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
803 return(NULL); /* Failure */
804 }
805 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
806 head);
807
808 /*
809 * If the rule_string begins with DEFAULT, apply the default rule
810 * before using the (possibly available) additional rules.
811 */
812 ok = 1;
813 rule_p = rule_str;
814 if (strncmp(rule_str,"DEFAULT",7) == 0)
815 {
816 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
817 list, &head, &tail, ca_list);
818 rule_p += 7;
819 if (*rule_p == ':')
820 rule_p++;
821 }
822
823 if (ok && (strlen(rule_p) > 0))
824 ok = ssl_cipher_process_rulestr(rule_p, list, &head, &tail,
825 ca_list);
826
827 OPENSSL_free(ca_list); /* Not needed anymore */
828
829 if (!ok)
830 { /* Rule processing failure */
831 OPENSSL_free(list);
832 return(NULL);
833 }
834 /*
835 * Allocate new "cipherstack" for the result, return with error
836 * if we cannot get one.
837 */
838 if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL)
839 {
840 OPENSSL_free(list);
841 return(NULL);
842 }
843
844 /*
845 * The cipher selection for the list is done. The ciphers are added
846 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
847 */
848 for (curr = head; curr != NULL; curr = curr->next)
849 {
850 if (curr->active)
851 {
852 sk_SSL_CIPHER_push(cipherstack, curr->cipher);
853#ifdef CIPHER_DEBUG
854 printf("<%s>\n",curr->cipher->name);
855#endif
856 }
857 }
858 OPENSSL_free(list); /* Not needed any longer */
859
860 /*
861 * The following passage is a little bit odd. If pointer variables
862 * were supplied to hold STACK_OF(SSL_CIPHER) return information,
863 * the old memory pointed to is free()ed. Then, however, the
864 * cipher_list entry will be assigned just a copy of the returned
865 * cipher stack. For cipher_list_by_id a copy of the cipher stack
866 * will be created. See next comment...
867 */
868 if (cipher_list != NULL)
869 {
870 if (*cipher_list != NULL)
871 sk_SSL_CIPHER_free(*cipher_list);
872 *cipher_list = cipherstack;
873 }
874
875 if (cipher_list_by_id != NULL)
876 {
877 if (*cipher_list_by_id != NULL)
878 sk_SSL_CIPHER_free(*cipher_list_by_id);
879 *cipher_list_by_id = sk_SSL_CIPHER_dup(cipherstack);
880 }
881
882 /*
883 * Now it is getting really strange. If something failed during
884 * the previous pointer assignment or if one of the pointers was
885 * not requested, the error condition is met. That might be
886 * discussable. The strange thing is however that in this case
887 * the memory "ret" pointed to is "free()ed" and hence the pointer
888 * cipher_list becomes wild. The memory reserved for
889 * cipher_list_by_id however is not "free()ed" and stays intact.
890 */
891 if ( (cipher_list_by_id == NULL) ||
892 (*cipher_list_by_id == NULL) ||
893 (cipher_list == NULL) ||
894 (*cipher_list == NULL))
895 {
896 sk_SSL_CIPHER_free(cipherstack);
897 return(NULL);
898 }
899
900 sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
901
902 return(cipherstack);
903 }
904
905char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
906 {
907 int is_export,pkl,kl;
908 char *ver,*exp;
909 char *kx,*au,*enc,*mac;
910 unsigned long alg,alg2,alg_s;
911#ifdef KSSL_DEBUG
912 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
913#else
914 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
915#endif /* KSSL_DEBUG */
916
917 alg=cipher->algorithms;
918 alg_s=cipher->algo_strength;
919 alg2=cipher->algorithm2;
920
921 is_export=SSL_C_IS_EXPORT(cipher);
922 pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
923 kl=SSL_C_EXPORT_KEYLENGTH(cipher);
924 exp=is_export?" export":"";
925
926 if (alg & SSL_SSLV2)
927 ver="SSLv2";
928 else if (alg & SSL_SSLV3)
929 ver="SSLv3";
930 else
931 ver="unknown";
932
933 switch (alg&SSL_MKEY_MASK)
934 {
935 case SSL_kRSA:
936 kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
937 break;
938 case SSL_kDHr:
939 kx="DH/RSA";
940 break;
941 case SSL_kDHd:
942 kx="DH/DSS";
943 break;
944 case SSL_kKRB5: /* VRS */
945 case SSL_KRB5: /* VRS */
946 kx="KRB5";
947 break;
948 case SSL_kFZA:
949 kx="Fortezza";
950 break;
951 case SSL_kEDH:
952 kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
953 break;
954 default:
955 kx="unknown";
956 }
957
958 switch (alg&SSL_AUTH_MASK)
959 {
960 case SSL_aRSA:
961 au="RSA";
962 break;
963 case SSL_aDSS:
964 au="DSS";
965 break;
966 case SSL_aDH:
967 au="DH";
968 break;
969 case SSL_aKRB5: /* VRS */
970 case SSL_KRB5: /* VRS */
971 au="KRB5";
972 break;
973 case SSL_aFZA:
974 case SSL_aNULL:
975 au="None";
976 break;
977 default:
978 au="unknown";
979 break;
980 }
981
982 switch (alg&SSL_ENC_MASK)
983 {
984 case SSL_DES:
985 enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
986 break;
987 case SSL_3DES:
988 enc="3DES(168)";
989 break;
990 case SSL_RC4:
991 enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
992 :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
993 break;
994 case SSL_RC2:
995 enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
996 break;
997 case SSL_IDEA:
998 enc="IDEA(128)";
999 break;
1000 case SSL_eFZA:
1001 enc="Fortezza";
1002 break;
1003 case SSL_eNULL:
1004 enc="None";
1005 break;
1006 case SSL_AES:
1007 switch(cipher->strength_bits)
1008 {
1009 case 128: enc="AES(128)"; break;
1010 case 192: enc="AES(192)"; break;
1011 case 256: enc="AES(256)"; break;
1012 default: enc="AES(?""?""?)"; break;
1013 }
1014 break;
1015 default:
1016 enc="unknown";
1017 break;
1018 }
1019
1020 switch (alg&SSL_MAC_MASK)
1021 {
1022 case SSL_MD5:
1023 mac="MD5";
1024 break;
1025 case SSL_SHA1:
1026 mac="SHA1";
1027 break;
1028 default:
1029 mac="unknown";
1030 break;
1031 }
1032
1033 if (buf == NULL)
1034 {
1035 len=128;
1036 buf=OPENSSL_malloc(len);
1037 if (buf == NULL) return("OPENSSL_malloc Error");
1038 }
1039 else if (len < 128)
1040 return("Buffer too small");
1041
1042#ifdef KSSL_DEBUG
1043 BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp,alg);
1044#else
1045 BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp);
1046#endif /* KSSL_DEBUG */
1047 return(buf);
1048 }
1049
1050char *SSL_CIPHER_get_version(SSL_CIPHER *c)
1051 {
1052 int i;
1053
1054 if (c == NULL) return("(NONE)");
1055 i=(int)(c->id>>24L);
1056 if (i == 3)
1057 return("TLSv1/SSLv3");
1058 else if (i == 2)
1059 return("SSLv2");
1060 else
1061 return("unknown");
1062 }
1063
1064/* return the actual cipher being used */
1065const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
1066 {
1067 if (c != NULL)
1068 return(c->name);
1069 return("(NONE)");
1070 }
1071
1072/* number of bits for symmetric cipher */
1073int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
1074 {
1075 int ret=0;
1076
1077 if (c != NULL)
1078 {
1079 if (alg_bits != NULL) *alg_bits = c->alg_bits;
1080 ret = c->strength_bits;
1081 }
1082 return(ret);
1083 }
1084
1085SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
1086 {
1087 SSL_COMP *ctmp;
1088 int i,nn;
1089
1090 if ((n == 0) || (sk == NULL)) return(NULL);
1091 nn=sk_SSL_COMP_num(sk);
1092 for (i=0; i<nn; i++)
1093 {
1094 ctmp=sk_SSL_COMP_value(sk,i);
1095 if (ctmp->id == n)
1096 return(ctmp);
1097 }
1098 return(NULL);
1099 }
1100
1101static int sk_comp_cmp(const SSL_COMP * const *a,
1102 const SSL_COMP * const *b)
1103 {
1104 return((*a)->id-(*b)->id);
1105 }
1106
1107STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
1108 {
1109 return(ssl_comp_methods);
1110 }
1111
1112int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
1113 {
1114 SSL_COMP *comp;
1115 STACK_OF(SSL_COMP) *sk;
1116
1117 if (cm == NULL || cm->type == NID_undef)
1118 return 1;
1119
1120 MemCheck_off();
1121 comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
1122 comp->id=id;
1123 comp->method=cm;
1124 if (ssl_comp_methods == NULL)
1125 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
1126 else
1127 sk=ssl_comp_methods;
1128 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
1129 {
1130 MemCheck_on();
1131 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
1132 return(0);
1133 }
1134 else
1135 {
1136 MemCheck_on();
1137 return(1);
1138 }
1139 }
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 7067a745f3..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,460 +0,0 @@
1/* ssl/ssl_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ssl.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
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_FINISHED,0), "CLIENT_FINISHED"},
71{ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"},
72{ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"},
73{ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"},
74{ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"},
75{ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"},
76{ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"},
77{ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"},
78{ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"},
79{ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"},
80{ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"},
81{ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"},
82{ERR_PACK(0,SSL_F_READ_N,0), "READ_N"},
83{ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"},
84{ERR_PACK(0,SSL_F_SERVER_FINISH,0), "SERVER_FINISH"},
85{ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"},
86{ERR_PACK(0,SSL_F_SERVER_VERIFY,0), "SERVER_VERIFY"},
87{ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"},
88{ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"},
89{ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"},
90{ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"},
91{ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"},
92{ERR_PACK(0,SSL_F_SSL23_PEEK,0), "SSL23_PEEK"},
93{ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"},
94{ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"},
95{ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"},
96{ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"},
97{ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"},
98{ERR_PACK(0,SSL_F_SSL2_GENERATE_KEY_MATERIAL,0), "SSL2_GENERATE_KEY_MATERIAL"},
99{ERR_PACK(0,SSL_F_SSL2_PEEK,0), "SSL2_PEEK"},
100{ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"},
101{ERR_PACK(0,SSL_F_SSL2_READ_INTERNAL,0), "SSL2_READ_INTERNAL"},
102{ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"},
103{ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"},
104{ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"},
105{ERR_PACK(0,SSL_F_SSL3_CALLBACK_CTRL,0), "SSL3_CALLBACK_CTRL"},
106{ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"},
107{ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"},
108{ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"},
109{ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"},
110{ERR_PACK(0,SSL_F_SSL3_CTRL,0), "SSL3_CTRL"},
111{ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"},
112{ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"},
113{ERR_PACK(0,SSL_F_SSL3_GENERATE_KEY_BLOCK,0), "SSL3_GENERATE_KEY_BLOCK"},
114{ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"},
115{ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"},
116{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"},
117{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"},
118{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
119{ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"},
120{ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"},
121{ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"},
122{ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"},
123{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"},
124{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"},
125{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"},
126{ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"},
127{ERR_PACK(0,SSL_F_SSL3_PEEK,0), "SSL3_PEEK"},
128{ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"},
129{ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"},
130{ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"},
131{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"},
132{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
133{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"},
134{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"},
135{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_HELLO,0), "SSL3_SEND_SERVER_HELLO"},
136{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
137{ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"},
138{ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"},
139{ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"},
140{ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"},
141{ERR_PACK(0,SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,0), "SSL_add_dir_cert_subjects_to_stack"},
142{ERR_PACK(0,SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,0), "SSL_add_file_cert_subjects_to_stack"},
143{ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"},
144{ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"},
145{ERR_PACK(0,SSL_F_SSL_CERT_DUP,0), "SSL_CERT_DUP"},
146{ERR_PACK(0,SSL_F_SSL_CERT_INST,0), "SSL_CERT_INST"},
147{ERR_PACK(0,SSL_F_SSL_CERT_INSTANTIATE,0), "SSL_CERT_INSTANTIATE"},
148{ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"},
149{ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"},
150{ERR_PACK(0,SSL_F_SSL_CIPHER_PROCESS_RULESTR,0), "SSL_CIPHER_PROCESS_RULESTR"},
151{ERR_PACK(0,SSL_F_SSL_CIPHER_STRENGTH_SORT,0), "SSL_CIPHER_STRENGTH_SORT"},
152{ERR_PACK(0,SSL_F_SSL_CLEAR,0), "SSL_clear"},
153{ERR_PACK(0,SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,0), "SSL_COMP_add_compression_method"},
154{ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"},
155{ERR_PACK(0,SSL_F_SSL_CTRL,0), "SSL_ctrl"},
156{ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"},
157{ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"},
158{ERR_PACK(0,SSL_F_SSL_CTX_SET_PURPOSE,0), "SSL_CTX_set_purpose"},
159{ERR_PACK(0,SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,0), "SSL_CTX_set_session_id_context"},
160{ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"},
161{ERR_PACK(0,SSL_F_SSL_CTX_SET_TRUST,0), "SSL_CTX_set_trust"},
162{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"},
163{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"},
164{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,0), "SSL_CTX_use_certificate_chain_file"},
165{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"},
166{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"},
167{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"},
168{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"},
169{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"},
170{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"},
171{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"},
172{ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"},
173{ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"},
174{ERR_PACK(0,SSL_F_SSL_GET_PREV_SESSION,0), "SSL_GET_PREV_SESSION"},
175{ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"},
176{ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"},
177{ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"},
178{ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"},
179{ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"},
180{ERR_PACK(0,SSL_F_SSL_READ,0), "SSL_read"},
181{ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"},
182{ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"},
183{ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"},
184{ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"},
185{ERR_PACK(0,SSL_F_SSL_SESS_CERT_NEW,0), "SSL_SESS_CERT_NEW"},
186{ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"},
187{ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"},
188{ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"},
189{ERR_PACK(0,SSL_F_SSL_SET_PURPOSE,0), "SSL_set_purpose"},
190{ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"},
191{ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"},
192{ERR_PACK(0,SSL_F_SSL_SET_SESSION_ID_CONTEXT,0), "SSL_set_session_id_context"},
193{ERR_PACK(0,SSL_F_SSL_SET_TRUST,0), "SSL_set_trust"},
194{ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"},
195{ERR_PACK(0,SSL_F_SSL_SHUTDOWN,0), "SSL_shutdown"},
196{ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"},
197{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"},
198{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"},
199{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"},
200{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"},
201{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"},
202{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"},
203{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"},
204{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"},
205{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"},
206{ERR_PACK(0,SSL_F_SSL_VERIFY_CERT_CHAIN,0), "SSL_VERIFY_CERT_CHAIN"},
207{ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"},
208{ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"},
209{ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
210{ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"},
211{ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"},
212{0,NULL}
213 };
214
215static ERR_STRING_DATA SSL_str_reasons[]=
216 {
217{SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"},
218{SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT,"attempt to reuse session in different context"},
219{SSL_R_BAD_ALERT_RECORD ,"bad alert record"},
220{SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"},
221{SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"},
222{SSL_R_BAD_CHECKSUM ,"bad checksum"},
223{SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"},
224{SSL_R_BAD_DECOMPRESSION ,"bad decompression"},
225{SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"},
226{SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"},
227{SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"},
228{SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"},
229{SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"},
230{SSL_R_BAD_HELLO_REQUEST ,"bad hello request"},
231{SSL_R_BAD_LENGTH ,"bad length"},
232{SSL_R_BAD_MAC_DECODE ,"bad mac decode"},
233{SSL_R_BAD_MESSAGE_TYPE ,"bad message type"},
234{SSL_R_BAD_PACKET_LENGTH ,"bad packet length"},
235{SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"},
236{SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"},
237{SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"},
238{SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"},
239{SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"},
240{SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"},
241{SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"},
242{SSL_R_BAD_SIGNATURE ,"bad signature"},
243{SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"},
244{SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"},
245{SSL_R_BAD_STATE ,"bad state"},
246{SSL_R_BAD_WRITE_RETRY ,"bad write retry"},
247{SSL_R_BIO_NOT_SET ,"bio not set"},
248{SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"},
249{SSL_R_BN_LIB ,"bn lib"},
250{SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"},
251{SSL_R_CA_DN_TOO_LONG ,"ca dn too long"},
252{SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"},
253{SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"},
254{SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"},
255{SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"},
256{SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"},
257{SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"},
258{SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"},
259{SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"},
260{SSL_R_COMPRESSION_FAILURE ,"compression failure"},
261{SSL_R_COMPRESSION_LIBRARY_ERROR ,"compression library error"},
262{SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"},
263{SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"},
264{SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"},
265{SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"},
266{SSL_R_DECRYPTION_FAILED ,"decryption failed"},
267{SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC,"decryption failed or bad record mac"},
268{SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"},
269{SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"},
270{SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"},
271{SSL_R_ERROR_GENERATING_TMP_RSA_KEY ,"error generating tmp rsa key"},
272{SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"},
273{SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"},
274{SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"},
275{SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"},
276{SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"},
277{SSL_R_HTTP_REQUEST ,"http request"},
278{SSL_R_ILLEGAL_PADDING ,"illegal padding"},
279{SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"},
280{SSL_R_INVALID_COMMAND ,"invalid command"},
281{SSL_R_INVALID_PURPOSE ,"invalid purpose"},
282{SSL_R_INVALID_TRUST ,"invalid trust"},
283{SSL_R_KEY_ARG_TOO_LONG ,"key arg too long"},
284{SSL_R_KRB5 ,"krb5"},
285{SSL_R_KRB5_C_CC_PRINC ,"krb5 client cc principal (no tkt?)"},
286{SSL_R_KRB5_C_GET_CRED ,"krb5 client get cred"},
287{SSL_R_KRB5_C_INIT ,"krb5 client init"},
288{SSL_R_KRB5_C_MK_REQ ,"krb5 client mk_req (expired tkt?)"},
289{SSL_R_KRB5_S_BAD_TICKET ,"krb5 server bad ticket"},
290{SSL_R_KRB5_S_INIT ,"krb5 server init"},
291{SSL_R_KRB5_S_RD_REQ ,"krb5 server rd_req (keytab perms?)"},
292{SSL_R_KRB5_S_TKT_EXPIRED ,"krb5 server tkt expired"},
293{SSL_R_KRB5_S_TKT_NYV ,"krb5 server tkt not yet valid"},
294{SSL_R_KRB5_S_TKT_SKEW ,"krb5 server tkt skew"},
295{SSL_R_LENGTH_MISMATCH ,"length mismatch"},
296{SSL_R_LENGTH_TOO_SHORT ,"length too short"},
297{SSL_R_LIBRARY_BUG ,"library bug"},
298{SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"},
299{SSL_R_MESSAGE_TOO_LONG ,"message too long"},
300{SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"},
301{SSL_R_MISSING_DH_KEY ,"missing dh key"},
302{SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"},
303{SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"},
304{SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"},
305{SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"},
306{SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"},
307{SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"},
308{SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"},
309{SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"},
310{SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"},
311{SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"},
312{SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"},
313{SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"},
314{SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"},
315{SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"},
316{SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"},
317{SSL_R_NO_CERTIFICATE_SET ,"no certificate set"},
318{SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"},
319{SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"},
320{SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"},
321{SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"},
322{SSL_R_NO_CIPHER_LIST ,"no cipher list"},
323{SSL_R_NO_CIPHER_MATCH ,"no cipher match"},
324{SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"},
325{SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"},
326{SSL_R_NO_METHOD_SPECIFIED ,"no method specified"},
327{SSL_R_NO_PRIVATEKEY ,"no privatekey"},
328{SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"},
329{SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"},
330{SSL_R_NO_PUBLICKEY ,"no publickey"},
331{SSL_R_NO_SHARED_CIPHER ,"no shared cipher"},
332{SSL_R_NO_VERIFY_CALLBACK ,"no verify callback"},
333{SSL_R_NULL_SSL_CTX ,"null ssl ctx"},
334{SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"},
335{SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"},
336{SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"},
337{SSL_R_PATH_TOO_LONG ,"path too long"},
338{SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"},
339{SSL_R_PEER_ERROR ,"peer error"},
340{SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"},
341{SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"},
342{SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"},
343{SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"},
344{SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"},
345{SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"},
346{SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"},
347{SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"},
348{SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"},
349{SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
350{SSL_R_READ_BIO_NOT_SET ,"read bio not set"},
351{SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"},
352{SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"},
353{SSL_R_RECORD_TOO_LARGE ,"record too large"},
354{SSL_R_RECORD_TOO_SMALL ,"record too small"},
355{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
356{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
357{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
358{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
359{SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"},
360{SSL_R_SHORT_READ ,"short read"},
361{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
362{SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"},
363{SSL_R_SSL2_CONNECTION_ID_TOO_LONG ,"ssl2 connection id too long"},
364{SSL_R_SSL3_SESSION_ID_TOO_LONG ,"ssl3 session id too long"},
365{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
366{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
367{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
368{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
369{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
370{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
371{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
372{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
373{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
374{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
375{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
376{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
377{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
378{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
379{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
380{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
381{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
382{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
383{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
384{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
385{SSL_R_SSL_SESSION_ID_CALLBACK_FAILED ,"ssl session id callback failed"},
386{SSL_R_SSL_SESSION_ID_CONFLICT ,"ssl session id conflict"},
387{SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"},
388{SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH ,"ssl session id has bad length"},
389{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
390{SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"},
391{SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"},
392{SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"},
393{SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"},
394{SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION ,"tlsv1 alert export restriction"},
395{SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"},
396{SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"},
397{SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"},
398{SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"},
399{SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"},
400{SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"},
401{SSL_R_TLSV1_ALERT_USER_CANCELLED ,"tlsv1 alert user cancelled"},
402{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
403{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
404{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
405{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
406{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
407{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
408{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
409{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
410{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
411{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
412{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
413{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
414{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
415{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
416{SSL_R_UNINITIALIZED ,"uninitialized"},
417{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
418{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
419{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
420{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
421{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
422{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
423{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
424{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
425{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
426{SSL_R_UNKNOWN_STATE ,"unknown state"},
427{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
428{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
429{SSL_R_UNSUPPORTED_OPTION ,"unsupported option"},
430{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
431{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
432{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
433{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
434{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
435{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
436{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
437{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
438{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
439{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
440{SSL_R_X509_LIB ,"x509 lib"},
441{SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"},
442{0,NULL}
443 };
444
445#endif
446
447void ERR_load_SSL_strings(void)
448 {
449 static int init=1;
450
451 if (init)
452 {
453 init=0;
454#ifndef OPENSSL_NO_ERR
455 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
456 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
457#endif
458
459 }
460 }
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c
deleted file mode 100644
index ea95a5f983..0000000000
--- a/src/lib/libssl/ssl_err2.c
+++ /dev/null
@@ -1,70 +0,0 @@
1/* ssl/ssl_err2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/err.h>
61#include <openssl/ssl.h>
62
63void SSL_load_error_strings(void)
64 {
65#ifndef OPENSSL_NO_ERR
66 ERR_load_crypto_strings();
67 ERR_load_SSL_strings();
68#endif
69 }
70
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
deleted file mode 100644
index 4bc4ce5b3a..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,2302 +0,0 @@
1/*! \file ssl/ssl_lib.c
2 * \brief Version independent SSL functions.
3 */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42 *
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60/* ====================================================================
61 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
62 *
63 * Redistribution and use in source and binary forms, with or without
64 * modification, are permitted provided that the following conditions
65 * are met:
66 *
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 *
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in
72 * the documentation and/or other materials provided with the
73 * distribution.
74 *
75 * 3. All advertising materials mentioning features or use of this
76 * software must display the following acknowledgment:
77 * "This product includes software developed by the OpenSSL Project
78 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
79 *
80 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
81 * endorse or promote products derived from this software without
82 * prior written permission. For written permission, please contact
83 * openssl-core@openssl.org.
84 *
85 * 5. Products derived from this software may not be called "OpenSSL"
86 * nor may "OpenSSL" appear in their names without prior written
87 * permission of the OpenSSL Project.
88 *
89 * 6. Redistributions of any form whatsoever must retain the following
90 * acknowledgment:
91 * "This product includes software developed by the OpenSSL Project
92 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
95 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
97 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
98 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
99 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
101 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
103 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
104 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
105 * OF THE POSSIBILITY OF SUCH DAMAGE.
106 * ====================================================================
107 *
108 * This product includes cryptographic software written by Eric Young
109 * (eay@cryptsoft.com). This product includes software written by Tim
110 * Hudson (tjh@cryptsoft.com).
111 *
112 */
113
114
115#ifdef REF_CHECK
116# include <assert.h>
117#endif
118#include <stdio.h>
119#include "ssl_locl.h"
120#include "kssl_lcl.h"
121#include <openssl/objects.h>
122#include <openssl/lhash.h>
123#include <openssl/x509v3.h>
124
125const char *SSL_version_str=OPENSSL_VERSION_TEXT;
126
127OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
128 /* evil casts, but these functions are only called if there's a library bug */
129 (int (*)(SSL *,int))ssl_undefined_function,
130 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
131 ssl_undefined_function,
132 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
133 (int (*)(SSL*, int))ssl_undefined_function,
134 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
135 };
136
137int SSL_clear(SSL *s)
138 {
139
140 if (s->method == NULL)
141 {
142 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
143 return(0);
144 }
145
146 if (ssl_clear_bad_session(s))
147 {
148 SSL_SESSION_free(s->session);
149 s->session=NULL;
150 }
151
152 s->error=0;
153 s->hit=0;
154 s->shutdown=0;
155
156#if 0 /* Disabled since version 1.10 of this file (early return not
157 * needed because SSL_clear is not called when doing renegotiation) */
158 /* This is set if we are doing dynamic renegotiation so keep
159 * the old cipher. It is sort of a SSL_clear_lite :-) */
160 if (s->new_session) return(1);
161#else
162 if (s->new_session)
163 {
164 SSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);
165 return 0;
166 }
167#endif
168
169 s->type=0;
170
171 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
172
173 s->version=s->method->version;
174 s->client_version=s->version;
175 s->rwstate=SSL_NOTHING;
176 s->rstate=SSL_ST_READ_HEADER;
177#if 0
178 s->read_ahead=s->ctx->read_ahead;
179#endif
180
181 if (s->init_buf != NULL)
182 {
183 BUF_MEM_free(s->init_buf);
184 s->init_buf=NULL;
185 }
186
187 ssl_clear_cipher_ctx(s);
188
189 s->first_packet=0;
190
191#if 1
192 /* Check to see if we were changed into a different method, if
193 * so, revert back if we are not doing session-id reuse. */
194 if (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method))
195 {
196 s->method->ssl_free(s);
197 s->method=s->ctx->method;
198 if (!s->method->ssl_new(s))
199 return(0);
200 }
201 else
202#endif
203 s->method->ssl_clear(s);
204 return(1);
205 }
206
207/** Used to change an SSL_CTXs default SSL method type */
208int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
209 {
210 STACK_OF(SSL_CIPHER) *sk;
211
212 ctx->method=meth;
213
214 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
215 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
216 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
217 {
218 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
219 return(0);
220 }
221 return(1);
222 }
223
224SSL *SSL_new(SSL_CTX *ctx)
225 {
226 SSL *s;
227
228 if (ctx == NULL)
229 {
230 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
231 return(NULL);
232 }
233 if (ctx->method == NULL)
234 {
235 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
236 return(NULL);
237 }
238
239 s=(SSL *)OPENSSL_malloc(sizeof(SSL));
240 if (s == NULL) goto err;
241 memset(s,0,sizeof(SSL));
242
243#ifndef OPENSSL_NO_KRB5
244 s->kssl_ctx = kssl_ctx_new();
245#endif /* OPENSSL_NO_KRB5 */
246
247 s->options=ctx->options;
248 s->mode=ctx->mode;
249 s->max_cert_list=ctx->max_cert_list;
250
251 if (ctx->cert != NULL)
252 {
253 /* Earlier library versions used to copy the pointer to
254 * the CERT, not its contents; only when setting new
255 * parameters for the per-SSL copy, ssl_cert_new would be
256 * called (and the direct reference to the per-SSL_CTX
257 * settings would be lost, but those still were indirectly
258 * accessed for various purposes, and for that reason they
259 * used to be known as s->ctx->default_cert).
260 * Now we don't look at the SSL_CTX's CERT after having
261 * duplicated it once. */
262
263 s->cert = ssl_cert_dup(ctx->cert);
264 if (s->cert == NULL)
265 goto err;
266 }
267 else
268 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
269
270 s->read_ahead=ctx->read_ahead;
271 s->msg_callback=ctx->msg_callback;
272 s->msg_callback_arg=ctx->msg_callback_arg;
273 s->verify_mode=ctx->verify_mode;
274 s->verify_depth=ctx->verify_depth;
275 s->sid_ctx_length=ctx->sid_ctx_length;
276 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
277 s->verify_callback=ctx->default_verify_callback;
278 s->generate_session_id=ctx->generate_session_id;
279 s->purpose = ctx->purpose;
280 s->trust = ctx->trust;
281 s->quiet_shutdown=ctx->quiet_shutdown;
282
283 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
284 s->ctx=ctx;
285
286 s->verify_result=X509_V_OK;
287
288 s->method=ctx->method;
289
290 if (!s->method->ssl_new(s))
291 goto err;
292
293 s->references=1;
294 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
295
296 SSL_clear(s);
297
298 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
299
300 return(s);
301err:
302 if (s != NULL)
303 {
304 if (s->cert != NULL)
305 ssl_cert_free(s->cert);
306 if (s->ctx != NULL)
307 SSL_CTX_free(s->ctx); /* decrement reference count */
308 OPENSSL_free(s);
309 }
310 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
311 return(NULL);
312 }
313
314int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
315 unsigned int sid_ctx_len)
316 {
317 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
318 {
319 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
320 return 0;
321 }
322 ctx->sid_ctx_length=sid_ctx_len;
323 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
324
325 return 1;
326 }
327
328int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
329 unsigned int sid_ctx_len)
330 {
331 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
332 {
333 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
334 return 0;
335 }
336 ssl->sid_ctx_length=sid_ctx_len;
337 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
338
339 return 1;
340 }
341
342int SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb)
343 {
344 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
345 ctx->generate_session_id = cb;
346 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
347 return 1;
348 }
349
350int SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb)
351 {
352 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
353 ssl->generate_session_id = cb;
354 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
355 return 1;
356 }
357
358int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
359 unsigned int id_len)
360 {
361 /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how
362 * we can "construct" a session to give us the desired check - ie. to
363 * find if there's a session in the hash table that would conflict with
364 * any new session built out of this id/id_len and the ssl_version in
365 * use by this SSL. */
366 SSL_SESSION r, *p;
367 r.ssl_version = ssl->version;
368 r.session_id_length = id_len;
369 memcpy(r.session_id, id, id_len);
370 /* NB: SSLv2 always uses a fixed 16-byte session ID, so even if a
371 * callback is calling us to check the uniqueness of a shorter ID, it
372 * must be compared as a padded-out ID because that is what it will be
373 * converted to when the callback has finished choosing it. */
374 if((r.ssl_version == SSL2_VERSION) &&
375 (id_len < SSL2_SSL_SESSION_ID_LENGTH))
376 {
377 memset(r.session_id + id_len, 0,
378 SSL2_SSL_SESSION_ID_LENGTH - id_len);
379 r.session_id_length = SSL2_SSL_SESSION_ID_LENGTH;
380 }
381
382 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
383 p = (SSL_SESSION *)lh_retrieve(ssl->ctx->sessions, &r);
384 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
385 return (p != NULL);
386 }
387
388int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
389 {
390 return X509_PURPOSE_set(&s->purpose, purpose);
391 }
392
393int SSL_set_purpose(SSL *s, int purpose)
394 {
395 return X509_PURPOSE_set(&s->purpose, purpose);
396 }
397
398int SSL_CTX_set_trust(SSL_CTX *s, int trust)
399 {
400 return X509_TRUST_set(&s->trust, trust);
401 }
402
403int SSL_set_trust(SSL *s, int trust)
404 {
405 return X509_TRUST_set(&s->trust, trust);
406 }
407
408void SSL_free(SSL *s)
409 {
410 int i;
411
412 if(s == NULL)
413 return;
414
415 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
416#ifdef REF_PRINT
417 REF_PRINT("SSL",s);
418#endif
419 if (i > 0) return;
420#ifdef REF_CHECK
421 if (i < 0)
422 {
423 fprintf(stderr,"SSL_free, bad reference count\n");
424 abort(); /* ok */
425 }
426#endif
427
428 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
429
430 if (s->bbio != NULL)
431 {
432 /* If the buffering BIO is in place, pop it off */
433 if (s->bbio == s->wbio)
434 {
435 s->wbio=BIO_pop(s->wbio);
436 }
437 BIO_free(s->bbio);
438 s->bbio=NULL;
439 }
440 if (s->rbio != NULL)
441 BIO_free_all(s->rbio);
442 if ((s->wbio != NULL) && (s->wbio != s->rbio))
443 BIO_free_all(s->wbio);
444
445 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
446
447 /* add extra stuff */
448 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
449 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
450
451 /* Make the next call work :-) */
452 if (s->session != NULL)
453 {
454 ssl_clear_bad_session(s);
455 SSL_SESSION_free(s->session);
456 }
457
458 ssl_clear_cipher_ctx(s);
459
460 if (s->cert != NULL) ssl_cert_free(s->cert);
461 /* Free up if allocated */
462
463 if (s->ctx) SSL_CTX_free(s->ctx);
464
465 if (s->client_CA != NULL)
466 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
467
468 if (s->method != NULL) s->method->ssl_free(s);
469
470 OPENSSL_free(s);
471 }
472
473void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
474 {
475 /* If the output buffering BIO is still in place, remove it
476 */
477 if (s->bbio != NULL)
478 {
479 if (s->wbio == s->bbio)
480 {
481 s->wbio=s->wbio->next_bio;
482 s->bbio->next_bio=NULL;
483 }
484 }
485 if ((s->rbio != NULL) && (s->rbio != rbio))
486 BIO_free_all(s->rbio);
487 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
488 BIO_free_all(s->wbio);
489 s->rbio=rbio;
490 s->wbio=wbio;
491 }
492
493BIO *SSL_get_rbio(SSL *s)
494 { return(s->rbio); }
495
496BIO *SSL_get_wbio(SSL *s)
497 { return(s->wbio); }
498
499int SSL_get_fd(SSL *s)
500 {
501 return(SSL_get_rfd(s));
502 }
503
504int SSL_get_rfd(SSL *s)
505 {
506 int ret= -1;
507 BIO *b,*r;
508
509 b=SSL_get_rbio(s);
510 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
511 if (r != NULL)
512 BIO_get_fd(r,&ret);
513 return(ret);
514 }
515
516int SSL_get_wfd(SSL *s)
517 {
518 int ret= -1;
519 BIO *b,*r;
520
521 b=SSL_get_wbio(s);
522 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
523 if (r != NULL)
524 BIO_get_fd(r,&ret);
525 return(ret);
526 }
527
528#ifndef OPENSSL_NO_SOCK
529int SSL_set_fd(SSL *s,int fd)
530 {
531 int ret=0;
532 BIO *bio=NULL;
533
534 bio=BIO_new(BIO_s_socket());
535
536 if (bio == NULL)
537 {
538 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
539 goto err;
540 }
541 BIO_set_fd(bio,fd,BIO_NOCLOSE);
542 SSL_set_bio(s,bio,bio);
543 ret=1;
544err:
545 return(ret);
546 }
547
548int SSL_set_wfd(SSL *s,int fd)
549 {
550 int ret=0;
551 BIO *bio=NULL;
552
553 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
554 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
555 {
556 bio=BIO_new(BIO_s_socket());
557
558 if (bio == NULL)
559 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
560 BIO_set_fd(bio,fd,BIO_NOCLOSE);
561 SSL_set_bio(s,SSL_get_rbio(s),bio);
562 }
563 else
564 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
565 ret=1;
566err:
567 return(ret);
568 }
569
570int SSL_set_rfd(SSL *s,int fd)
571 {
572 int ret=0;
573 BIO *bio=NULL;
574
575 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
576 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
577 {
578 bio=BIO_new(BIO_s_socket());
579
580 if (bio == NULL)
581 {
582 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
583 goto err;
584 }
585 BIO_set_fd(bio,fd,BIO_NOCLOSE);
586 SSL_set_bio(s,bio,SSL_get_wbio(s));
587 }
588 else
589 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
590 ret=1;
591err:
592 return(ret);
593 }
594#endif
595
596
597/* return length of latest Finished message we sent, copy to 'buf' */
598size_t SSL_get_finished(SSL *s, void *buf, size_t count)
599 {
600 size_t ret = 0;
601
602 if (s->s3 != NULL)
603 {
604 ret = s->s3->tmp.finish_md_len;
605 if (count > ret)
606 count = ret;
607 memcpy(buf, s->s3->tmp.finish_md, count);
608 }
609 return ret;
610 }
611
612/* return length of latest Finished message we expected, copy to 'buf' */
613size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
614 {
615 size_t ret = 0;
616
617 if (s->s3 != NULL)
618 {
619 ret = s->s3->tmp.peer_finish_md_len;
620 if (count > ret)
621 count = ret;
622 memcpy(buf, s->s3->tmp.peer_finish_md, count);
623 }
624 return ret;
625 }
626
627
628int SSL_get_verify_mode(SSL *s)
629 {
630 return(s->verify_mode);
631 }
632
633int SSL_get_verify_depth(SSL *s)
634 {
635 return(s->verify_depth);
636 }
637
638int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *)
639 {
640 return(s->verify_callback);
641 }
642
643int SSL_CTX_get_verify_mode(SSL_CTX *ctx)
644 {
645 return(ctx->verify_mode);
646 }
647
648int SSL_CTX_get_verify_depth(SSL_CTX *ctx)
649 {
650 return(ctx->verify_depth);
651 }
652
653int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *)
654 {
655 return(ctx->default_verify_callback);
656 }
657
658void SSL_set_verify(SSL *s,int mode,
659 int (*callback)(int ok,X509_STORE_CTX *ctx))
660 {
661 s->verify_mode=mode;
662 if (callback != NULL)
663 s->verify_callback=callback;
664 }
665
666void SSL_set_verify_depth(SSL *s,int depth)
667 {
668 s->verify_depth=depth;
669 }
670
671void SSL_set_read_ahead(SSL *s,int yes)
672 {
673 s->read_ahead=yes;
674 }
675
676int SSL_get_read_ahead(SSL *s)
677 {
678 return(s->read_ahead);
679 }
680
681int SSL_pending(SSL *s)
682 {
683 /* SSL_pending cannot work properly if read-ahead is enabled
684 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)),
685 * and it is impossible to fix since SSL_pending cannot report
686 * errors that may be observed while scanning the new data.
687 * (Note that SSL_pending() is often used as a boolean value,
688 * so we'd better not return -1.)
689 */
690 return(s->method->ssl_pending(s));
691 }
692
693X509 *SSL_get_peer_certificate(SSL *s)
694 {
695 X509 *r;
696
697 if ((s == NULL) || (s->session == NULL))
698 r=NULL;
699 else
700 r=s->session->peer;
701
702 if (r == NULL) return(r);
703
704 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
705
706 return(r);
707 }
708
709STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
710 {
711 STACK_OF(X509) *r;
712
713 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
714 r=NULL;
715 else
716 r=s->session->sess_cert->cert_chain;
717
718 /* If we are a client, cert_chain includes the peer's own
719 * certificate; if we are a server, it does not. */
720
721 return(r);
722 }
723
724/* Now in theory, since the calling process own 't' it should be safe to
725 * modify. We need to be able to read f without being hassled */
726void SSL_copy_session_id(SSL *t,SSL *f)
727 {
728 CERT *tmp;
729
730 /* Do we need to to SSL locking? */
731 SSL_set_session(t,SSL_get_session(f));
732
733 /* what if we are setup as SSLv2 but want to talk SSLv3 or
734 * vice-versa */
735 if (t->method != f->method)
736 {
737 t->method->ssl_free(t); /* cleanup current */
738 t->method=f->method; /* change method */
739 t->method->ssl_new(t); /* setup new */
740 }
741
742 tmp=t->cert;
743 if (f->cert != NULL)
744 {
745 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
746 t->cert=f->cert;
747 }
748 else
749 t->cert=NULL;
750 if (tmp != NULL) ssl_cert_free(tmp);
751 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
752 }
753
754/* Fix this so it checks all the valid key/cert options */
755int SSL_CTX_check_private_key(SSL_CTX *ctx)
756 {
757 if ( (ctx == NULL) ||
758 (ctx->cert == NULL) ||
759 (ctx->cert->key->x509 == NULL))
760 {
761 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
762 return(0);
763 }
764 if (ctx->cert->key->privatekey == NULL)
765 {
766 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
767 return(0);
768 }
769 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
770 }
771
772/* Fix this function so that it takes an optional type parameter */
773int SSL_check_private_key(SSL *ssl)
774 {
775 if (ssl == NULL)
776 {
777 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
778 return(0);
779 }
780 if (ssl->cert == NULL)
781 {
782 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
783 return 0;
784 }
785 if (ssl->cert->key->x509 == NULL)
786 {
787 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
788 return(0);
789 }
790 if (ssl->cert->key->privatekey == NULL)
791 {
792 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
793 return(0);
794 }
795 return(X509_check_private_key(ssl->cert->key->x509,
796 ssl->cert->key->privatekey));
797 }
798
799int SSL_accept(SSL *s)
800 {
801 if (s->handshake_func == 0)
802 /* Not properly initialized yet */
803 SSL_set_accept_state(s);
804
805 return(s->method->ssl_accept(s));
806 }
807
808int SSL_connect(SSL *s)
809 {
810 if (s->handshake_func == 0)
811 /* Not properly initialized yet */
812 SSL_set_connect_state(s);
813
814 return(s->method->ssl_connect(s));
815 }
816
817long SSL_get_default_timeout(SSL *s)
818 {
819 return(s->method->get_timeout());
820 }
821
822int SSL_read(SSL *s,void *buf,int num)
823 {
824 if (s->handshake_func == 0)
825 {
826 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
827 return -1;
828 }
829
830 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
831 {
832 s->rwstate=SSL_NOTHING;
833 return(0);
834 }
835 return(s->method->ssl_read(s,buf,num));
836 }
837
838int SSL_peek(SSL *s,void *buf,int num)
839 {
840 if (s->handshake_func == 0)
841 {
842 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
843 return -1;
844 }
845
846 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
847 {
848 return(0);
849 }
850 return(s->method->ssl_peek(s,buf,num));
851 }
852
853int SSL_write(SSL *s,const void *buf,int num)
854 {
855 if (s->handshake_func == 0)
856 {
857 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
858 return -1;
859 }
860
861 if (s->shutdown & SSL_SENT_SHUTDOWN)
862 {
863 s->rwstate=SSL_NOTHING;
864 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
865 return(-1);
866 }
867 return(s->method->ssl_write(s,buf,num));
868 }
869
870int SSL_shutdown(SSL *s)
871 {
872 /* Note that this function behaves differently from what one might
873 * expect. Return values are 0 for no success (yet),
874 * 1 for success; but calling it once is usually not enough,
875 * even if blocking I/O is used (see ssl3_shutdown).
876 */
877
878 if (s->handshake_func == 0)
879 {
880 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
881 return -1;
882 }
883
884 if ((s != NULL) && !SSL_in_init(s))
885 return(s->method->ssl_shutdown(s));
886 else
887 return(1);
888 }
889
890int SSL_renegotiate(SSL *s)
891 {
892 if (s->new_session == 0)
893 {
894 s->new_session=1;
895 }
896 return(s->method->ssl_renegotiate(s));
897 }
898
899int SSL_renegotiate_pending(SSL *s)
900 {
901 /* becomes true when negotiation is requested;
902 * false again once a handshake has finished */
903 return (s->new_session != 0);
904 }
905
906long SSL_ctrl(SSL *s,int cmd,long larg,void *parg)
907 {
908 long l;
909
910 switch (cmd)
911 {
912 case SSL_CTRL_GET_READ_AHEAD:
913 return(s->read_ahead);
914 case SSL_CTRL_SET_READ_AHEAD:
915 l=s->read_ahead;
916 s->read_ahead=larg;
917 return(l);
918
919 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
920 s->msg_callback_arg = parg;
921 return 1;
922
923 case SSL_CTRL_OPTIONS:
924 return(s->options|=larg);
925 case SSL_CTRL_MODE:
926 return(s->mode|=larg);
927 case SSL_CTRL_GET_MAX_CERT_LIST:
928 return(s->max_cert_list);
929 case SSL_CTRL_SET_MAX_CERT_LIST:
930 l=s->max_cert_list;
931 s->max_cert_list=larg;
932 return(l);
933 default:
934 return(s->method->ssl_ctrl(s,cmd,larg,parg));
935 }
936 }
937
938long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
939 {
940 switch(cmd)
941 {
942 case SSL_CTRL_SET_MSG_CALLBACK:
943 s->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp);
944 return 1;
945
946 default:
947 return(s->method->ssl_callback_ctrl(s,cmd,fp));
948 }
949 }
950
951struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
952 {
953 return ctx->sessions;
954 }
955
956long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,void *parg)
957 {
958 long l;
959
960 switch (cmd)
961 {
962 case SSL_CTRL_GET_READ_AHEAD:
963 return(ctx->read_ahead);
964 case SSL_CTRL_SET_READ_AHEAD:
965 l=ctx->read_ahead;
966 ctx->read_ahead=larg;
967 return(l);
968
969 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
970 ctx->msg_callback_arg = parg;
971 return 1;
972
973 case SSL_CTRL_GET_MAX_CERT_LIST:
974 return(ctx->max_cert_list);
975 case SSL_CTRL_SET_MAX_CERT_LIST:
976 l=ctx->max_cert_list;
977 ctx->max_cert_list=larg;
978 return(l);
979
980 case SSL_CTRL_SET_SESS_CACHE_SIZE:
981 l=ctx->session_cache_size;
982 ctx->session_cache_size=larg;
983 return(l);
984 case SSL_CTRL_GET_SESS_CACHE_SIZE:
985 return(ctx->session_cache_size);
986 case SSL_CTRL_SET_SESS_CACHE_MODE:
987 l=ctx->session_cache_mode;
988 ctx->session_cache_mode=larg;
989 return(l);
990 case SSL_CTRL_GET_SESS_CACHE_MODE:
991 return(ctx->session_cache_mode);
992
993 case SSL_CTRL_SESS_NUMBER:
994 return(ctx->sessions->num_items);
995 case SSL_CTRL_SESS_CONNECT:
996 return(ctx->stats.sess_connect);
997 case SSL_CTRL_SESS_CONNECT_GOOD:
998 return(ctx->stats.sess_connect_good);
999 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
1000 return(ctx->stats.sess_connect_renegotiate);
1001 case SSL_CTRL_SESS_ACCEPT:
1002 return(ctx->stats.sess_accept);
1003 case SSL_CTRL_SESS_ACCEPT_GOOD:
1004 return(ctx->stats.sess_accept_good);
1005 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
1006 return(ctx->stats.sess_accept_renegotiate);
1007 case SSL_CTRL_SESS_HIT:
1008 return(ctx->stats.sess_hit);
1009 case SSL_CTRL_SESS_CB_HIT:
1010 return(ctx->stats.sess_cb_hit);
1011 case SSL_CTRL_SESS_MISSES:
1012 return(ctx->stats.sess_miss);
1013 case SSL_CTRL_SESS_TIMEOUTS:
1014 return(ctx->stats.sess_timeout);
1015 case SSL_CTRL_SESS_CACHE_FULL:
1016 return(ctx->stats.sess_cache_full);
1017 case SSL_CTRL_OPTIONS:
1018 return(ctx->options|=larg);
1019 case SSL_CTRL_MODE:
1020 return(ctx->mode|=larg);
1021 default:
1022 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
1023 }
1024 }
1025
1026long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
1027 {
1028 switch(cmd)
1029 {
1030 case SSL_CTRL_SET_MSG_CALLBACK:
1031 ctx->msg_callback = (void (*)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))(fp);
1032 return 1;
1033
1034 default:
1035 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
1036 }
1037 }
1038
1039int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
1040 {
1041 long l;
1042
1043 l=a->id-b->id;
1044 if (l == 0L)
1045 return(0);
1046 else
1047 return((l > 0)?1:-1);
1048 }
1049
1050int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1051 const SSL_CIPHER * const *bp)
1052 {
1053 long l;
1054
1055 l=(*ap)->id-(*bp)->id;
1056 if (l == 0L)
1057 return(0);
1058 else
1059 return((l > 0)?1:-1);
1060 }
1061
1062/** return a STACK of the ciphers available for the SSL and in order of
1063 * preference */
1064STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s)
1065 {
1066 if ((s != NULL) && (s->cipher_list != NULL))
1067 {
1068 return(s->cipher_list);
1069 }
1070 else if ((s->ctx != NULL) &&
1071 (s->ctx->cipher_list != NULL))
1072 {
1073 return(s->ctx->cipher_list);
1074 }
1075 return(NULL);
1076 }
1077
1078/** return a STACK of the ciphers available for the SSL and in order of
1079 * algorithm id */
1080STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
1081 {
1082 if ((s != NULL) && (s->cipher_list_by_id != NULL))
1083 {
1084 return(s->cipher_list_by_id);
1085 }
1086 else if ((s != NULL) && (s->ctx != NULL) &&
1087 (s->ctx->cipher_list_by_id != NULL))
1088 {
1089 return(s->ctx->cipher_list_by_id);
1090 }
1091 return(NULL);
1092 }
1093
1094/** The old interface to get the same thing as SSL_get_ciphers() */
1095const char *SSL_get_cipher_list(SSL *s,int n)
1096 {
1097 SSL_CIPHER *c;
1098 STACK_OF(SSL_CIPHER) *sk;
1099
1100 if (s == NULL) return(NULL);
1101 sk=SSL_get_ciphers(s);
1102 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
1103 return(NULL);
1104 c=sk_SSL_CIPHER_value(sk,n);
1105 if (c == NULL) return(NULL);
1106 return(c->name);
1107 }
1108
1109/** specify the ciphers to be used by default by the SSL_CTX */
1110int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
1111 {
1112 STACK_OF(SSL_CIPHER) *sk;
1113
1114 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
1115 &ctx->cipher_list_by_id,str);
1116/* XXXX */
1117 return((sk == NULL)?0:1);
1118 }
1119
1120/** specify the ciphers to be used by the SSL */
1121int SSL_set_cipher_list(SSL *s,const char *str)
1122 {
1123 STACK_OF(SSL_CIPHER) *sk;
1124
1125 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
1126 &s->cipher_list_by_id,str);
1127/* XXXX */
1128 return((sk == NULL)?0:1);
1129 }
1130
1131/* works well for SSLv2, not so good for SSLv3 */
1132char *SSL_get_shared_ciphers(SSL *s,char *buf,int len)
1133 {
1134 char *p;
1135 const char *cp;
1136 STACK_OF(SSL_CIPHER) *sk;
1137 SSL_CIPHER *c;
1138 int i;
1139
1140 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
1141 (len < 2))
1142 return(NULL);
1143
1144 p=buf;
1145 sk=s->session->ciphers;
1146 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1147 {
1148 /* Decrement for either the ':' or a '\0' */
1149 len--;
1150 c=sk_SSL_CIPHER_value(sk,i);
1151 for (cp=c->name; *cp; )
1152 {
1153 if (len-- == 0)
1154 {
1155 *p='\0';
1156 return(buf);
1157 }
1158 else
1159 *(p++)= *(cp++);
1160 }
1161 *(p++)=':';
1162 }
1163 p[-1]='\0';
1164 return(buf);
1165 }
1166
1167int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p)
1168 {
1169 int i,j=0;
1170 SSL_CIPHER *c;
1171 unsigned char *q;
1172#ifndef OPENSSL_NO_KRB5
1173 int nokrb5 = !kssl_tgt_is_available(s->kssl_ctx);
1174#endif /* OPENSSL_NO_KRB5 */
1175
1176 if (sk == NULL) return(0);
1177 q=p;
1178
1179 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1180 {
1181 c=sk_SSL_CIPHER_value(sk,i);
1182#ifndef OPENSSL_NO_KRB5
1183 if ((c->algorithms & SSL_KRB5) && nokrb5)
1184 continue;
1185#endif /* OPENSSL_NO_KRB5 */
1186 j=ssl_put_cipher_by_char(s,c,p);
1187 p+=j;
1188 }
1189 return(p-q);
1190 }
1191
1192STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
1193 STACK_OF(SSL_CIPHER) **skp)
1194 {
1195 SSL_CIPHER *c;
1196 STACK_OF(SSL_CIPHER) *sk;
1197 int i,n;
1198
1199 n=ssl_put_cipher_by_char(s,NULL,NULL);
1200 if ((num%n) != 0)
1201 {
1202 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1203 return(NULL);
1204 }
1205 if ((skp == NULL) || (*skp == NULL))
1206 sk=sk_SSL_CIPHER_new_null(); /* change perhaps later */
1207 else
1208 {
1209 sk= *skp;
1210 sk_SSL_CIPHER_zero(sk);
1211 }
1212
1213 for (i=0; i<num; i+=n)
1214 {
1215 c=ssl_get_cipher_by_char(s,p);
1216 p+=n;
1217 if (c != NULL)
1218 {
1219 if (!sk_SSL_CIPHER_push(sk,c))
1220 {
1221 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
1222 goto err;
1223 }
1224 }
1225 }
1226
1227 if (skp != NULL)
1228 *skp=sk;
1229 return(sk);
1230err:
1231 if ((skp == NULL) || (*skp == NULL))
1232 sk_SSL_CIPHER_free(sk);
1233 return(NULL);
1234 }
1235
1236unsigned long SSL_SESSION_hash(SSL_SESSION *a)
1237 {
1238 unsigned long l;
1239
1240 l=(unsigned long)
1241 ((unsigned int) a->session_id[0] )|
1242 ((unsigned int) a->session_id[1]<< 8L)|
1243 ((unsigned long)a->session_id[2]<<16L)|
1244 ((unsigned long)a->session_id[3]<<24L);
1245 return(l);
1246 }
1247
1248/* NB: If this function (or indeed the hash function which uses a sort of
1249 * coarser function than this one) is changed, ensure
1250 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
1251 * able to construct an SSL_SESSION that will collide with any existing session
1252 * with a matching session ID. */
1253int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b)
1254 {
1255 if (a->ssl_version != b->ssl_version)
1256 return(1);
1257 if (a->session_id_length != b->session_id_length)
1258 return(1);
1259 return(memcmp(a->session_id,b->session_id,a->session_id_length));
1260 }
1261
1262/* These wrapper functions should remain rather than redeclaring
1263 * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
1264 * variable. The reason is that the functions aren't static, they're exposed via
1265 * ssl.h. */
1266static IMPLEMENT_LHASH_HASH_FN(SSL_SESSION_hash, SSL_SESSION *)
1267static IMPLEMENT_LHASH_COMP_FN(SSL_SESSION_cmp, SSL_SESSION *)
1268
1269SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1270 {
1271 SSL_CTX *ret=NULL;
1272
1273 if (meth == NULL)
1274 {
1275 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
1276 return(NULL);
1277 }
1278
1279 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1280 {
1281 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1282 goto err;
1283 }
1284 ret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
1285 if (ret == NULL)
1286 goto err;
1287
1288 memset(ret,0,sizeof(SSL_CTX));
1289
1290 ret->method=meth;
1291
1292 ret->cert_store=NULL;
1293 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1294 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1295 ret->session_cache_head=NULL;
1296 ret->session_cache_tail=NULL;
1297
1298 /* We take the system default */
1299 ret->session_timeout=meth->get_timeout();
1300
1301 ret->new_session_cb=0;
1302 ret->remove_session_cb=0;
1303 ret->get_session_cb=0;
1304 ret->generate_session_id=0;
1305
1306 memset((char *)&ret->stats,0,sizeof(ret->stats));
1307
1308 ret->references=1;
1309 ret->quiet_shutdown=0;
1310
1311/* ret->cipher=NULL;*/
1312/* ret->s2->challenge=NULL;
1313 ret->master_key=NULL;
1314 ret->key_arg=NULL;
1315 ret->s2->conn_id=NULL; */
1316
1317 ret->info_callback=NULL;
1318
1319 ret->app_verify_callback=0;
1320 ret->app_verify_arg=NULL;
1321
1322 ret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT;
1323 ret->read_ahead=0;
1324 ret->msg_callback=0;
1325 ret->msg_callback_arg=NULL;
1326 ret->verify_mode=SSL_VERIFY_NONE;
1327 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1328 ret->sid_ctx_length=0;
1329 ret->default_verify_callback=NULL;
1330 if ((ret->cert=ssl_cert_new()) == NULL)
1331 goto err;
1332
1333 ret->default_passwd_callback=0;
1334 ret->default_passwd_callback_userdata=NULL;
1335 ret->client_cert_cb=0;
1336
1337 ret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash),
1338 LHASH_COMP_FN(SSL_SESSION_cmp));
1339 if (ret->sessions == NULL) goto err;
1340 ret->cert_store=X509_STORE_new();
1341 if (ret->cert_store == NULL) goto err;
1342
1343 ssl_create_cipher_list(ret->method,
1344 &ret->cipher_list,&ret->cipher_list_by_id,
1345 SSL_DEFAULT_CIPHER_LIST);
1346 if (ret->cipher_list == NULL
1347 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1348 {
1349 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1350 goto err2;
1351 }
1352
1353 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1354 {
1355 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1356 goto err2;
1357 }
1358 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1359 {
1360 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1361 goto err2;
1362 }
1363 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1364 {
1365 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1366 goto err2;
1367 }
1368
1369 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1370 goto err;
1371
1372 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);
1373
1374 ret->extra_certs=NULL;
1375 ret->comp_methods=SSL_COMP_get_compression_methods();
1376
1377 return(ret);
1378err:
1379 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1380err2:
1381 if (ret != NULL) SSL_CTX_free(ret);
1382 return(NULL);
1383 }
1384
1385#if 0
1386static void SSL_COMP_free(SSL_COMP *comp)
1387 { OPENSSL_free(comp); }
1388#endif
1389
1390void SSL_CTX_free(SSL_CTX *a)
1391 {
1392 int i;
1393
1394 if (a == NULL) return;
1395
1396 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1397#ifdef REF_PRINT
1398 REF_PRINT("SSL_CTX",a);
1399#endif
1400 if (i > 0) return;
1401#ifdef REF_CHECK
1402 if (i < 0)
1403 {
1404 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1405 abort(); /* ok */
1406 }
1407#endif
1408
1409 /*
1410 * Free internal session cache. However: the remove_cb() may reference
1411 * the ex_data of SSL_CTX, thus the ex_data store can only be removed
1412 * after the sessions were flushed.
1413 * As the ex_data handling routines might also touch the session cache,
1414 * the most secure solution seems to be: empty (flush) the cache, then
1415 * free ex_data, then finally free the cache.
1416 * (See ticket [openssl.org #212].)
1417 */
1418 if (a->sessions != NULL)
1419 SSL_CTX_flush_sessions(a,0);
1420
1421 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);
1422
1423 if (a->sessions != NULL)
1424 lh_free(a->sessions);
1425
1426 if (a->cert_store != NULL)
1427 X509_STORE_free(a->cert_store);
1428 if (a->cipher_list != NULL)
1429 sk_SSL_CIPHER_free(a->cipher_list);
1430 if (a->cipher_list_by_id != NULL)
1431 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1432 if (a->cert != NULL)
1433 ssl_cert_free(a->cert);
1434 if (a->client_CA != NULL)
1435 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1436 if (a->extra_certs != NULL)
1437 sk_X509_pop_free(a->extra_certs,X509_free);
1438#if 0 /* This should never be done, since it removes a global database */
1439 if (a->comp_methods != NULL)
1440 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1441#else
1442 a->comp_methods = NULL;
1443#endif
1444 OPENSSL_free(a);
1445 }
1446
1447void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1448 {
1449 ctx->default_passwd_callback=cb;
1450 }
1451
1452void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1453 {
1454 ctx->default_passwd_callback_userdata=u;
1455 }
1456
1457void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,void *), void *arg)
1458 {
1459 ctx->app_verify_callback=cb;
1460 ctx->app_verify_arg=arg;
1461 }
1462
1463void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1464 {
1465 ctx->verify_mode=mode;
1466 ctx->default_verify_callback=cb;
1467 }
1468
1469void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1470 {
1471 ctx->verify_depth=depth;
1472 }
1473
1474void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1475 {
1476 CERT_PKEY *cpk;
1477 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1478 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1479 int rsa_tmp_export,dh_tmp_export,kl;
1480 unsigned long mask,emask;
1481
1482 if (c == NULL) return;
1483
1484 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1485
1486#ifndef OPENSSL_NO_RSA
1487 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1488 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1489 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1490#else
1491 rsa_tmp=rsa_tmp_export=0;
1492#endif
1493#ifndef OPENSSL_NO_DH
1494 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1495 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1496 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1497#else
1498 dh_tmp=dh_tmp_export=0;
1499#endif
1500
1501 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1502 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1503 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1504 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1505 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1506 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1507 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1508 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1509 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1510 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1511 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1512/* FIX THIS EAY EAY EAY */
1513 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1514 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1515
1516 mask=0;
1517 emask=0;
1518
1519#ifdef CIPHER_DEBUG
1520 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1521 rsa_tmp,rsa_tmp_export,dh_tmp,
1522 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1523#endif
1524
1525 if (rsa_enc || (rsa_tmp && rsa_sign))
1526 mask|=SSL_kRSA;
1527 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1528 emask|=SSL_kRSA;
1529
1530#if 0
1531 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1532 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1533 (rsa_enc || rsa_sign || dsa_sign))
1534 mask|=SSL_kEDH;
1535 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1536 (rsa_enc || rsa_sign || dsa_sign))
1537 emask|=SSL_kEDH;
1538#endif
1539
1540 if (dh_tmp_export)
1541 emask|=SSL_kEDH;
1542
1543 if (dh_tmp)
1544 mask|=SSL_kEDH;
1545
1546 if (dh_rsa) mask|=SSL_kDHr;
1547 if (dh_rsa_export) emask|=SSL_kDHr;
1548
1549 if (dh_dsa) mask|=SSL_kDHd;
1550 if (dh_dsa_export) emask|=SSL_kDHd;
1551
1552 if (rsa_enc || rsa_sign)
1553 {
1554 mask|=SSL_aRSA;
1555 emask|=SSL_aRSA;
1556 }
1557
1558 if (dsa_sign)
1559 {
1560 mask|=SSL_aDSS;
1561 emask|=SSL_aDSS;
1562 }
1563
1564 mask|=SSL_aNULL;
1565 emask|=SSL_aNULL;
1566
1567#ifndef OPENSSL_NO_KRB5
1568 mask|=SSL_kKRB5|SSL_aKRB5;
1569 emask|=SSL_kKRB5|SSL_aKRB5;
1570#endif
1571
1572 c->mask=mask;
1573 c->export_mask=emask;
1574 c->valid=1;
1575 }
1576
1577/* THIS NEEDS CLEANING UP */
1578X509 *ssl_get_server_send_cert(SSL *s)
1579 {
1580 unsigned long alg,mask,kalg;
1581 CERT *c;
1582 int i,is_export;
1583
1584 c=s->cert;
1585 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1586 alg=s->s3->tmp.new_cipher->algorithms;
1587 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1588 mask=is_export?c->export_mask:c->mask;
1589 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1590
1591 if (kalg & SSL_kDHr)
1592 i=SSL_PKEY_DH_RSA;
1593 else if (kalg & SSL_kDHd)
1594 i=SSL_PKEY_DH_DSA;
1595 else if (kalg & SSL_aDSS)
1596 i=SSL_PKEY_DSA_SIGN;
1597 else if (kalg & SSL_aRSA)
1598 {
1599 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1600 i=SSL_PKEY_RSA_SIGN;
1601 else
1602 i=SSL_PKEY_RSA_ENC;
1603 }
1604 else if (kalg & SSL_aKRB5)
1605 {
1606 /* VRS something else here? */
1607 return(NULL);
1608 }
1609 else /* if (kalg & SSL_aNULL) */
1610 {
1611 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR);
1612 return(NULL);
1613 }
1614 if (c->pkeys[i].x509 == NULL) return(NULL);
1615 return(c->pkeys[i].x509);
1616 }
1617
1618EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1619 {
1620 unsigned long alg;
1621 CERT *c;
1622
1623 alg=cipher->algorithms;
1624 c=s->cert;
1625
1626 if ((alg & SSL_aDSS) &&
1627 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1628 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1629 else if (alg & SSL_aRSA)
1630 {
1631 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1632 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1633 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1634 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1635 else
1636 return(NULL);
1637 }
1638 else /* if (alg & SSL_aNULL) */
1639 {
1640 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,ERR_R_INTERNAL_ERROR);
1641 return(NULL);
1642 }
1643 }
1644
1645void ssl_update_cache(SSL *s,int mode)
1646 {
1647 int i;
1648
1649 /* If the session_id_length is 0, we are not supposed to cache it,
1650 * and it would be rather hard to do anyway :-) */
1651 if (s->session->session_id_length == 0) return;
1652
1653 i=s->ctx->session_cache_mode;
1654 if ((i & mode) && (!s->hit)
1655 && ((i & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)
1656 || SSL_CTX_add_session(s->ctx,s->session))
1657 && (s->ctx->new_session_cb != NULL))
1658 {
1659 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1660 if (!s->ctx->new_session_cb(s,s->session))
1661 SSL_SESSION_free(s->session);
1662 }
1663
1664 /* auto flush every 255 connections */
1665 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1666 ((i & mode) == mode))
1667 {
1668 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1669 ?s->ctx->stats.sess_connect_good
1670 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1671 {
1672 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1673 }
1674 }
1675 }
1676
1677SSL_METHOD *SSL_get_ssl_method(SSL *s)
1678 {
1679 return(s->method);
1680 }
1681
1682int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1683 {
1684 int conn= -1;
1685 int ret=1;
1686
1687 if (s->method != meth)
1688 {
1689 if (s->handshake_func != NULL)
1690 conn=(s->handshake_func == s->method->ssl_connect);
1691
1692 if (s->method->version == meth->version)
1693 s->method=meth;
1694 else
1695 {
1696 s->method->ssl_free(s);
1697 s->method=meth;
1698 ret=s->method->ssl_new(s);
1699 }
1700
1701 if (conn == 1)
1702 s->handshake_func=meth->ssl_connect;
1703 else if (conn == 0)
1704 s->handshake_func=meth->ssl_accept;
1705 }
1706 return(ret);
1707 }
1708
1709int SSL_get_error(SSL *s,int i)
1710 {
1711 int reason;
1712 unsigned long l;
1713 BIO *bio;
1714
1715 if (i > 0) return(SSL_ERROR_NONE);
1716
1717 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1718 * etc, where we do encode the error */
1719 if ((l=ERR_peek_error()) != 0)
1720 {
1721 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1722 return(SSL_ERROR_SYSCALL);
1723 else
1724 return(SSL_ERROR_SSL);
1725 }
1726
1727 if ((i < 0) && SSL_want_read(s))
1728 {
1729 bio=SSL_get_rbio(s);
1730 if (BIO_should_read(bio))
1731 return(SSL_ERROR_WANT_READ);
1732 else if (BIO_should_write(bio))
1733 /* This one doesn't make too much sense ... We never try
1734 * to write to the rbio, and an application program where
1735 * rbio and wbio are separate couldn't even know what it
1736 * should wait for.
1737 * However if we ever set s->rwstate incorrectly
1738 * (so that we have SSL_want_read(s) instead of
1739 * SSL_want_write(s)) and rbio and wbio *are* the same,
1740 * this test works around that bug; so it might be safer
1741 * to keep it. */
1742 return(SSL_ERROR_WANT_WRITE);
1743 else if (BIO_should_io_special(bio))
1744 {
1745 reason=BIO_get_retry_reason(bio);
1746 if (reason == BIO_RR_CONNECT)
1747 return(SSL_ERROR_WANT_CONNECT);
1748 else if (reason == BIO_RR_ACCEPT)
1749 return(SSL_ERROR_WANT_ACCEPT);
1750 else
1751 return(SSL_ERROR_SYSCALL); /* unknown */
1752 }
1753 }
1754
1755 if ((i < 0) && SSL_want_write(s))
1756 {
1757 bio=SSL_get_wbio(s);
1758 if (BIO_should_write(bio))
1759 return(SSL_ERROR_WANT_WRITE);
1760 else if (BIO_should_read(bio))
1761 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1762 return(SSL_ERROR_WANT_READ);
1763 else if (BIO_should_io_special(bio))
1764 {
1765 reason=BIO_get_retry_reason(bio);
1766 if (reason == BIO_RR_CONNECT)
1767 return(SSL_ERROR_WANT_CONNECT);
1768 else if (reason == BIO_RR_ACCEPT)
1769 return(SSL_ERROR_WANT_ACCEPT);
1770 else
1771 return(SSL_ERROR_SYSCALL);
1772 }
1773 }
1774 if ((i < 0) && SSL_want_x509_lookup(s))
1775 {
1776 return(SSL_ERROR_WANT_X509_LOOKUP);
1777 }
1778
1779 if (i == 0)
1780 {
1781 if (s->version == SSL2_VERSION)
1782 {
1783 /* assume it is the socket being closed */
1784 return(SSL_ERROR_ZERO_RETURN);
1785 }
1786 else
1787 {
1788 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1789 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1790 return(SSL_ERROR_ZERO_RETURN);
1791 }
1792 }
1793 return(SSL_ERROR_SYSCALL);
1794 }
1795
1796int SSL_do_handshake(SSL *s)
1797 {
1798 int ret=1;
1799
1800 if (s->handshake_func == NULL)
1801 {
1802 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1803 return(-1);
1804 }
1805
1806 s->method->ssl_renegotiate_check(s);
1807
1808 if (SSL_in_init(s) || SSL_in_before(s))
1809 {
1810 ret=s->handshake_func(s);
1811 }
1812 return(ret);
1813 }
1814
1815/* For the next 2 functions, SSL_clear() sets shutdown and so
1816 * one of these calls will reset it */
1817void SSL_set_accept_state(SSL *s)
1818 {
1819 s->server=1;
1820 s->shutdown=0;
1821 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1822 s->handshake_func=s->method->ssl_accept;
1823 /* clear the current cipher */
1824 ssl_clear_cipher_ctx(s);
1825 }
1826
1827void SSL_set_connect_state(SSL *s)
1828 {
1829 s->server=0;
1830 s->shutdown=0;
1831 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1832 s->handshake_func=s->method->ssl_connect;
1833 /* clear the current cipher */
1834 ssl_clear_cipher_ctx(s);
1835 }
1836
1837int ssl_undefined_function(SSL *s)
1838 {
1839 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1840 return(0);
1841 }
1842
1843SSL_METHOD *ssl_bad_method(int ver)
1844 {
1845 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1846 return(NULL);
1847 }
1848
1849const char *SSL_get_version(SSL *s)
1850 {
1851 if (s->version == TLS1_VERSION)
1852 return("TLSv1");
1853 else if (s->version == SSL3_VERSION)
1854 return("SSLv3");
1855 else if (s->version == SSL2_VERSION)
1856 return("SSLv2");
1857 else
1858 return("unknown");
1859 }
1860
1861SSL *SSL_dup(SSL *s)
1862 {
1863 STACK_OF(X509_NAME) *sk;
1864 X509_NAME *xn;
1865 SSL *ret;
1866 int i;
1867
1868 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1869 return(NULL);
1870
1871 ret->version = s->version;
1872 ret->type = s->type;
1873 ret->method = s->method;
1874
1875 if (s->session != NULL)
1876 {
1877 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1878 SSL_copy_session_id(ret,s);
1879 }
1880 else
1881 {
1882 /* No session has been established yet, so we have to expect
1883 * that s->cert or ret->cert will be changed later --
1884 * they should not both point to the same object,
1885 * and thus we can't use SSL_copy_session_id. */
1886
1887 ret->method = s->method;
1888 ret->method->ssl_new(ret);
1889
1890 if (s->cert != NULL)
1891 {
1892 if (ret->cert != NULL)
1893 {
1894 ssl_cert_free(ret->cert);
1895 }
1896 ret->cert = ssl_cert_dup(s->cert);
1897 if (ret->cert == NULL)
1898 goto err;
1899 }
1900
1901 SSL_set_session_id_context(ret,
1902 s->sid_ctx, s->sid_ctx_length);
1903 }
1904
1905 ret->options=s->options;
1906 ret->mode=s->mode;
1907 SSL_set_max_cert_list(ret,SSL_get_max_cert_list(s));
1908 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1909 ret->msg_callback = s->msg_callback;
1910 ret->msg_callback_arg = s->msg_callback_arg;
1911 SSL_set_verify(ret,SSL_get_verify_mode(s),
1912 SSL_get_verify_callback(s));
1913 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1914 ret->generate_session_id = s->generate_session_id;
1915
1916 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1917
1918 ret->debug=s->debug;
1919
1920 /* copy app data, a little dangerous perhaps */
1921 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data))
1922 goto err;
1923
1924 /* setup rbio, and wbio */
1925 if (s->rbio != NULL)
1926 {
1927 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1928 goto err;
1929 }
1930 if (s->wbio != NULL)
1931 {
1932 if (s->wbio != s->rbio)
1933 {
1934 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1935 goto err;
1936 }
1937 else
1938 ret->wbio=ret->rbio;
1939 }
1940 ret->rwstate = s->rwstate;
1941 ret->in_handshake = s->in_handshake;
1942 ret->handshake_func = s->handshake_func;
1943 ret->server = s->server;
1944 ret->new_session = s->new_session;
1945 ret->quiet_shutdown = s->quiet_shutdown;
1946 ret->shutdown=s->shutdown;
1947 ret->state=s->state; /* SSL_dup does not really work at any state, though */
1948 ret->rstate=s->rstate;
1949 ret->init_num = 0; /* would have to copy ret->init_buf, ret->init_msg, ret->init_num, ret->init_off */
1950 ret->hit=s->hit;
1951 ret->purpose=s->purpose;
1952 ret->trust=s->trust;
1953
1954 /* dup the cipher_list and cipher_list_by_id stacks */
1955 if (s->cipher_list != NULL)
1956 {
1957 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
1958 goto err;
1959 }
1960 if (s->cipher_list_by_id != NULL)
1961 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
1962 == NULL)
1963 goto err;
1964
1965 /* Dup the client_CA list */
1966 if (s->client_CA != NULL)
1967 {
1968 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
1969 ret->client_CA=sk;
1970 for (i=0; i<sk_X509_NAME_num(sk); i++)
1971 {
1972 xn=sk_X509_NAME_value(sk,i);
1973 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
1974 {
1975 X509_NAME_free(xn);
1976 goto err;
1977 }
1978 }
1979 }
1980
1981 if (0)
1982 {
1983err:
1984 if (ret != NULL) SSL_free(ret);
1985 ret=NULL;
1986 }
1987 return(ret);
1988 }
1989
1990void ssl_clear_cipher_ctx(SSL *s)
1991 {
1992 if (s->enc_read_ctx != NULL)
1993 {
1994 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1995 OPENSSL_free(s->enc_read_ctx);
1996 s->enc_read_ctx=NULL;
1997 }
1998 if (s->enc_write_ctx != NULL)
1999 {
2000 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
2001 OPENSSL_free(s->enc_write_ctx);
2002 s->enc_write_ctx=NULL;
2003 }
2004 if (s->expand != NULL)
2005 {
2006 COMP_CTX_free(s->expand);
2007 s->expand=NULL;
2008 }
2009 if (s->compress != NULL)
2010 {
2011 COMP_CTX_free(s->compress);
2012 s->compress=NULL;
2013 }
2014 }
2015
2016/* Fix this function so that it takes an optional type parameter */
2017X509 *SSL_get_certificate(SSL *s)
2018 {
2019 if (s->cert != NULL)
2020 return(s->cert->key->x509);
2021 else
2022 return(NULL);
2023 }
2024
2025/* Fix this function so that it takes an optional type parameter */
2026EVP_PKEY *SSL_get_privatekey(SSL *s)
2027 {
2028 if (s->cert != NULL)
2029 return(s->cert->key->privatekey);
2030 else
2031 return(NULL);
2032 }
2033
2034SSL_CIPHER *SSL_get_current_cipher(SSL *s)
2035 {
2036 if ((s->session != NULL) && (s->session->cipher != NULL))
2037 return(s->session->cipher);
2038 return(NULL);
2039 }
2040
2041int ssl_init_wbio_buffer(SSL *s,int push)
2042 {
2043 BIO *bbio;
2044
2045 if (s->bbio == NULL)
2046 {
2047 bbio=BIO_new(BIO_f_buffer());
2048 if (bbio == NULL) return(0);
2049 s->bbio=bbio;
2050 }
2051 else
2052 {
2053 bbio=s->bbio;
2054 if (s->bbio == s->wbio)
2055 s->wbio=BIO_pop(s->wbio);
2056 }
2057 (void)BIO_reset(bbio);
2058/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
2059 if (!BIO_set_read_buffer_size(bbio,1))
2060 {
2061 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
2062 return(0);
2063 }
2064 if (push)
2065 {
2066 if (s->wbio != bbio)
2067 s->wbio=BIO_push(bbio,s->wbio);
2068 }
2069 else
2070 {
2071 if (s->wbio == bbio)
2072 s->wbio=BIO_pop(bbio);
2073 }
2074 return(1);
2075 }
2076
2077void ssl_free_wbio_buffer(SSL *s)
2078 {
2079 if (s->bbio == NULL) return;
2080
2081 if (s->bbio == s->wbio)
2082 {
2083 /* remove buffering */
2084 s->wbio=BIO_pop(s->wbio);
2085#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids adding one more preprocessor symbol */
2086 assert(s->wbio != NULL);
2087#endif
2088 }
2089 BIO_free(s->bbio);
2090 s->bbio=NULL;
2091 }
2092
2093void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
2094 {
2095 ctx->quiet_shutdown=mode;
2096 }
2097
2098int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx)
2099 {
2100 return(ctx->quiet_shutdown);
2101 }
2102
2103void SSL_set_quiet_shutdown(SSL *s,int mode)
2104 {
2105 s->quiet_shutdown=mode;
2106 }
2107
2108int SSL_get_quiet_shutdown(SSL *s)
2109 {
2110 return(s->quiet_shutdown);
2111 }
2112
2113void SSL_set_shutdown(SSL *s,int mode)
2114 {
2115 s->shutdown=mode;
2116 }
2117
2118int SSL_get_shutdown(SSL *s)
2119 {
2120 return(s->shutdown);
2121 }
2122
2123int SSL_version(SSL *s)
2124 {
2125 return(s->version);
2126 }
2127
2128SSL_CTX *SSL_get_SSL_CTX(SSL *ssl)
2129 {
2130 return(ssl->ctx);
2131 }
2132
2133#ifndef OPENSSL_NO_STDIO
2134int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
2135 {
2136 return(X509_STORE_set_default_paths(ctx->cert_store));
2137 }
2138
2139int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
2140 const char *CApath)
2141 {
2142 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath));
2143 }
2144#endif
2145
2146void SSL_set_info_callback(SSL *ssl,
2147 void (*cb)(const SSL *ssl,int type,int val))
2148 {
2149 ssl->info_callback=cb;
2150 }
2151
2152void (*SSL_get_info_callback(SSL *ssl))(const SSL *ssl,int type,int val)
2153 {
2154 return ssl->info_callback;
2155 }
2156
2157int SSL_state(SSL *ssl)
2158 {
2159 return(ssl->state);
2160 }
2161
2162void SSL_set_verify_result(SSL *ssl,long arg)
2163 {
2164 ssl->verify_result=arg;
2165 }
2166
2167long SSL_get_verify_result(SSL *ssl)
2168 {
2169 return(ssl->verify_result);
2170 }
2171
2172int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
2173 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
2174 {
2175 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp,
2176 new_func, dup_func, free_func);
2177 }
2178
2179int SSL_set_ex_data(SSL *s,int idx,void *arg)
2180 {
2181 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2182 }
2183
2184void *SSL_get_ex_data(SSL *s,int idx)
2185 {
2186 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2187 }
2188
2189int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
2190 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
2191 {
2192 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp,
2193 new_func, dup_func, free_func);
2194 }
2195
2196int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
2197 {
2198 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
2199 }
2200
2201void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx)
2202 {
2203 return(CRYPTO_get_ex_data(&s->ex_data,idx));
2204 }
2205
2206int ssl_ok(SSL *s)
2207 {
2208 return(1);
2209 }
2210
2211X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx)
2212 {
2213 return(ctx->cert_store);
2214 }
2215
2216void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
2217 {
2218 if (ctx->cert_store != NULL)
2219 X509_STORE_free(ctx->cert_store);
2220 ctx->cert_store=store;
2221 }
2222
2223int SSL_want(SSL *s)
2224 {
2225 return(s->rwstate);
2226 }
2227
2228/*!
2229 * \brief Set the callback for generating temporary RSA keys.
2230 * \param ctx the SSL context.
2231 * \param cb the callback
2232 */
2233
2234#ifndef OPENSSL_NO_RSA
2235void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
2236 int is_export,
2237 int keylength))
2238 {
2239 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2240 }
2241
2242void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,
2243 int is_export,
2244 int keylength))
2245 {
2246 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2247 }
2248#endif
2249
2250#ifdef DOXYGEN
2251/*!
2252 * \brief The RSA temporary key callback function.
2253 * \param ssl the SSL session.
2254 * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite.
2255 * \param keylength if \c is_export is \c TRUE, then \c keylength is the size
2256 * of the required key in bits.
2257 * \return the temporary RSA key.
2258 * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback
2259 */
2260
2261RSA *cb(SSL *ssl,int is_export,int keylength)
2262 {}
2263#endif
2264
2265/*!
2266 * \brief Set the callback for generating temporary DH keys.
2267 * \param ctx the SSL context.
2268 * \param dh the callback
2269 */
2270
2271#ifndef OPENSSL_NO_DH
2272void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
2273 int keylength))
2274 {
2275 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2276 }
2277
2278void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
2279 int keylength))
2280 {
2281 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2282 }
2283#endif
2284
2285
2286void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
2287 {
2288 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb);
2289 }
2290void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
2291 {
2292 SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)())cb);
2293 }
2294
2295
2296
2297#if defined(_WINDLL) && defined(OPENSSL_SYS_WIN16)
2298#include "../crypto/bio/bss_file.c"
2299#endif
2300
2301IMPLEMENT_STACK_OF(SSL_CIPHER)
2302IMPLEMENT_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 dd6c7a7323..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,620 +0,0 @@
1/* ssl/ssl_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_SSL_LOCL_H
113#define HEADER_SSL_LOCL_H
114#include <stdlib.h>
115#include <time.h>
116#include <string.h>
117#include <errno.h>
118
119#include "e_os.h"
120
121#include <openssl/buffer.h>
122#include <openssl/comp.h>
123#include <openssl/bio.h>
124#include <openssl/crypto.h>
125#include <openssl/evp.h>
126#include <openssl/stack.h>
127#include <openssl/x509.h>
128#include <openssl/err.h>
129#include <openssl/ssl.h>
130#include <openssl/symhacks.h>
131
132#ifdef OPENSSL_BUILD_SHLIBSSL
133# undef OPENSSL_EXTERN
134# define OPENSSL_EXTERN OPENSSL_EXPORT
135#endif
136
137#define PKCS1_CHECK
138
139#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
140 l|=(((unsigned long)(*((c)++)))<< 8), \
141 l|=(((unsigned long)(*((c)++)))<<16), \
142 l|=(((unsigned long)(*((c)++)))<<24))
143
144/* NOTE - c is not incremented as per c2l */
145#define c2ln(c,l1,l2,n) { \
146 c+=n; \
147 l1=l2=0; \
148 switch (n) { \
149 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
150 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
151 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
152 case 5: l2|=((unsigned long)(*(--(c)))); \
153 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
154 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
155 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
156 case 1: l1|=((unsigned long)(*(--(c)))); \
157 } \
158 }
159
160#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
161 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
162 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
163 *((c)++)=(unsigned char)(((l)>>24)&0xff))
164
165#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
166 l|=((unsigned long)(*((c)++)))<<16, \
167 l|=((unsigned long)(*((c)++)))<< 8, \
168 l|=((unsigned long)(*((c)++))))
169
170#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
171 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
172 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
173 *((c)++)=(unsigned char)(((l) )&0xff))
174
175/* NOTE - c is not incremented as per l2c */
176#define l2cn(l1,l2,c,n) { \
177 c+=n; \
178 switch (n) { \
179 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
180 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
181 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
182 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
183 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
184 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
185 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
186 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
187 } \
188 }
189
190#define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
191 (((unsigned int)(c[1])) )),c+=2)
192#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
193 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
194
195#define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \
196 (((unsigned long)(c[1]))<< 8)| \
197 (((unsigned long)(c[2])) )),c+=3)
198
199#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
200 c[1]=(unsigned char)(((l)>> 8)&0xff), \
201 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
202
203/* LOCAL STUFF */
204
205#define SSL_DECRYPT 0
206#define SSL_ENCRYPT 1
207
208#define TWO_BYTE_BIT 0x80
209#define SEC_ESC_BIT 0x40
210#define TWO_BYTE_MASK 0x7fff
211#define THREE_BYTE_MASK 0x3fff
212
213#define INC32(a) ((a)=((a)+1)&0xffffffffL)
214#define DEC32(a) ((a)=((a)-1)&0xffffffffL)
215#define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */
216
217/*
218 * Define the Bitmasks for SSL_CIPHER.algorithms.
219 * This bits are used packed as dense as possible. If new methods/ciphers
220 * etc will be added, the bits a likely to change, so this information
221 * is for internal library use only, even though SSL_CIPHER.algorithms
222 * can be publicly accessed.
223 * Use the according functions for cipher management instead.
224 *
225 * The bit mask handling in the selection and sorting scheme in
226 * ssl_create_cipher_list() has only limited capabilities, reflecting
227 * that the different entities within are mutually exclusive:
228 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
229 */
230#define SSL_MKEY_MASK 0x0000003FL
231#define SSL_kRSA 0x00000001L /* RSA key exchange */
232#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
233#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
234#define SSL_kFZA 0x00000008L
235#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
236#define SSL_kKRB5 0x00000020L /* Kerberos5 key exchange */
237#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
238
239#define SSL_AUTH_MASK 0x00000FC0L
240#define SSL_aRSA 0x00000040L /* Authenticate with RSA */
241#define SSL_aDSS 0x00000080L /* Authenticate with DSS */
242#define SSL_DSS SSL_aDSS
243#define SSL_aFZA 0x00000100L
244#define SSL_aNULL 0x00000200L /* no Authenticate, ADH */
245#define SSL_aDH 0x00000400L /* no Authenticate, ADH */
246#define SSL_aKRB5 0x00000800L /* Authenticate with KRB5 */
247
248#define SSL_NULL (SSL_eNULL)
249#define SSL_ADH (SSL_kEDH|SSL_aNULL)
250#define SSL_RSA (SSL_kRSA|SSL_aRSA)
251#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
252#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
253#define SSL_KRB5 (SSL_kKRB5|SSL_aKRB5)
254
255#define SSL_ENC_MASK 0x0087F000L
256#define SSL_DES 0x00001000L
257#define SSL_3DES 0x00002000L
258#define SSL_RC4 0x00004000L
259#define SSL_RC2 0x00008000L
260#define SSL_IDEA 0x00010000L
261#define SSL_eFZA 0x00020000L
262#define SSL_eNULL 0x00040000L
263#define SSL_AES 0x00800000L
264
265#define SSL_MAC_MASK 0x00180000L
266#define SSL_MD5 0x00080000L
267#define SSL_SHA1 0x00100000L
268#define SSL_SHA (SSL_SHA1)
269
270#define SSL_SSL_MASK 0x00600000L
271#define SSL_SSLV2 0x00200000L
272#define SSL_SSLV3 0x00400000L
273#define SSL_TLSV1 SSL_SSLV3 /* for now */
274
275/* we have used 007fffff - 9 bits left to go */
276
277/*
278 * Export and cipher strength information. For each cipher we have to decide
279 * whether it is exportable or not. This information is likely to change
280 * over time, since the export control rules are no static technical issue.
281 *
282 * Independent of the export flag the cipher strength is sorted into classes.
283 * SSL_EXP40 was denoting the 40bit US export limit of past times, which now
284 * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change
285 * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more,
286 * since SSL_EXP64 could be similar to SSL_LOW.
287 * For this reason SSL_MICRO and SSL_MINI macros are included to widen the
288 * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed
289 * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would
290 * be possible.
291 */
292#define SSL_EXP_MASK 0x00000003L
293#define SSL_NOT_EXP 0x00000001L
294#define SSL_EXPORT 0x00000002L
295
296#define SSL_STRONG_MASK 0x000000fcL
297#define SSL_STRONG_NONE 0x00000004L
298#define SSL_EXP40 0x00000008L
299#define SSL_MICRO (SSL_EXP40)
300#define SSL_EXP56 0x00000010L
301#define SSL_MINI (SSL_EXP56)
302#define SSL_LOW 0x00000020L
303#define SSL_MEDIUM 0x00000040L
304#define SSL_HIGH 0x00000080L
305
306/* we have used 000000ff - 24 bits left to go */
307
308/*
309 * Macros to check the export status and cipher strength for export ciphers.
310 * Even though the macros for EXPORT and EXPORT40/56 have similar names,
311 * their meaning is different:
312 * *_EXPORT macros check the 'exportable' status.
313 * *_EXPORT40/56 macros are used to check whether a certain cipher strength
314 * is given.
315 * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct
316 * algorithm structure element to be passed (algorithms, algo_strength) and no
317 * typechecking can be done as they are all of type unsigned long, their
318 * direct usage is discouraged.
319 * Use the SSL_C_* macros instead.
320 */
321#define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT)
322#define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56)
323#define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40)
324#define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength)
325#define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength)
326#define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength)
327
328#define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \
329 ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
330#define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
331#define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \
332 (c)->algo_strength)
333#define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength)
334
335
336#define SSL_ALL 0xffffffffL
337#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
338 SSL_MAC_MASK)
339#define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK)
340
341/* Mostly for SSLv3 */
342#define SSL_PKEY_RSA_ENC 0
343#define SSL_PKEY_RSA_SIGN 1
344#define SSL_PKEY_DSA_SIGN 2
345#define SSL_PKEY_DH_RSA 3
346#define SSL_PKEY_DH_DSA 4
347#define SSL_PKEY_NUM 5
348
349/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
350 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
351 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
352 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
353 * SSL_aRSA <- RSA_ENC | RSA_SIGN
354 * SSL_aDSS <- DSA_SIGN
355 */
356
357/*
358#define CERT_INVALID 0
359#define CERT_PUBLIC_KEY 1
360#define CERT_PRIVATE_KEY 2
361*/
362
363typedef struct cert_pkey_st
364 {
365 X509 *x509;
366 EVP_PKEY *privatekey;
367 } CERT_PKEY;
368
369typedef struct cert_st
370 {
371 /* Current active set */
372 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
373 * Probably it would make more sense to store
374 * an index, not a pointer. */
375
376 /* The following masks are for the key and auth
377 * algorithms that are supported by the certs below */
378 int valid;
379 unsigned long mask;
380 unsigned long export_mask;
381#ifndef OPENSSL_NO_RSA
382 RSA *rsa_tmp;
383 RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
384#endif
385#ifndef OPENSSL_NO_DH
386 DH *dh_tmp;
387 DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize);
388#endif
389
390 CERT_PKEY pkeys[SSL_PKEY_NUM];
391
392 int references; /* >1 only if SSL_copy_session_id is used */
393 } CERT;
394
395
396typedef struct sess_cert_st
397 {
398 STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */
399
400 /* The 'peer_...' members are used only by clients. */
401 int peer_cert_type;
402
403 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
404 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
405 /* Obviously we don't have the private keys of these,
406 * so maybe we shouldn't even use the CERT_PKEY type here. */
407
408#ifndef OPENSSL_NO_RSA
409 RSA *peer_rsa_tmp; /* not used for SSL 2 */
410#endif
411#ifndef OPENSSL_NO_DH
412 DH *peer_dh_tmp; /* not used for SSL 2 */
413#endif
414
415 int references; /* actually always 1 at the moment */
416 } SESS_CERT;
417
418
419/*#define MAC_DEBUG */
420
421/*#define ERR_DEBUG */
422/*#define ABORT_DEBUG */
423/*#define PKT_DEBUG 1 */
424/*#define DES_DEBUG */
425/*#define DES_OFB_DEBUG */
426/*#define SSL_DEBUG */
427/*#define RSA_DEBUG */
428/*#define IDEA_DEBUG */
429
430#define FP_ICC (int (*)(const void *,const void *))
431#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
432 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
433#define ssl_get_cipher_by_char(ssl,ptr) \
434 ((ssl)->method->get_cipher_by_char(ptr))
435
436/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
437 * It is a bit of a mess of functions, but hell, think of it as
438 * an opaque structure :-) */
439typedef struct ssl3_enc_method
440 {
441 int (*enc)(SSL *, int);
442 int (*mac)(SSL *, unsigned char *, int);
443 int (*setup_key_block)(SSL *);
444 int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int);
445 int (*change_cipher_state)(SSL *, int);
446 int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *);
447 int finish_mac_length;
448 int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *);
449 const char *client_finished_label;
450 int client_finished_label_len;
451 const char *server_finished_label;
452 int server_finished_label_len;
453 int (*alert_value)(int);
454 } SSL3_ENC_METHOD;
455
456/* Used for holding the relevant compression methods loaded into SSL_CTX */
457typedef struct ssl3_comp_st
458 {
459 int comp_id; /* The identifier byte for this compression type */
460 char *name; /* Text name used for the compression type */
461 COMP_METHOD *method; /* The method :-) */
462 } SSL3_COMP;
463
464OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method;
465OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
466OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
467
468#ifdef OPENSSL_SYS_VMS
469#undef SSL_COMP_get_compression_methods
470#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods
471#endif
472
473
474SSL_METHOD *ssl_bad_method(int ver);
475SSL_METHOD *sslv2_base_method(void);
476SSL_METHOD *sslv23_base_method(void);
477SSL_METHOD *sslv3_base_method(void);
478
479void ssl_clear_cipher_ctx(SSL *s);
480int ssl_clear_bad_session(SSL *s);
481CERT *ssl_cert_new(void);
482CERT *ssl_cert_dup(CERT *cert);
483int ssl_cert_inst(CERT **o);
484void ssl_cert_free(CERT *c);
485SESS_CERT *ssl_sess_cert_new(void);
486void ssl_sess_cert_free(SESS_CERT *sc);
487int ssl_set_peer_cert_type(SESS_CERT *c, int type);
488int ssl_get_new_session(SSL *s, int session);
489int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
490int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);
491int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
492 const SSL_CIPHER * const *bp);
493STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
494 STACK_OF(SSL_CIPHER) **skp);
495int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
496STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
497 STACK_OF(SSL_CIPHER) **pref,
498 STACK_OF(SSL_CIPHER) **sorted,
499 const char *rule_str);
500void ssl_update_cache(SSL *s, int mode);
501int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md,
502 SSL_COMP **comp);
503int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
504int ssl_undefined_function(SSL *s);
505X509 *ssl_get_server_send_cert(SSL *);
506EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
507int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
508void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
509STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
510int ssl_verify_alarm_type(long type);
511
512int ssl2_enc_init(SSL *s, int client);
513int ssl2_generate_key_material(SSL *s);
514void ssl2_enc(SSL *s,int send_data);
515void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
516SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
517int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
518int ssl2_part_read(SSL *s, unsigned long f, int i);
519int ssl2_do_write(SSL *s);
520int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
521void ssl2_return_error(SSL *s,int reason);
522void ssl2_write_error(SSL *s);
523int ssl2_num_ciphers(void);
524SSL_CIPHER *ssl2_get_cipher(unsigned int u);
525int ssl2_new(SSL *s);
526void ssl2_free(SSL *s);
527int ssl2_accept(SSL *s);
528int ssl2_connect(SSL *s);
529int ssl2_read(SSL *s, void *buf, int len);
530int ssl2_peek(SSL *s, void *buf, int len);
531int ssl2_write(SSL *s, const void *buf, int len);
532int ssl2_shutdown(SSL *s);
533void ssl2_clear(SSL *s);
534long ssl2_ctrl(SSL *s,int cmd, long larg, void *parg);
535long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
536long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)());
537long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
538int ssl2_pending(SSL *s);
539
540SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
541int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
542void ssl3_init_finished_mac(SSL *s);
543int ssl3_send_server_certificate(SSL *s);
544int ssl3_get_finished(SSL *s,int state_a,int state_b);
545int ssl3_setup_key_block(SSL *s);
546int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
547int ssl3_change_cipher_state(SSL *s,int which);
548void ssl3_cleanup_key_block(SSL *s);
549int ssl3_do_write(SSL *s,int type);
550void ssl3_send_alert(SSL *s,int level, int desc);
551int ssl3_generate_master_secret(SSL *s, unsigned char *out,
552 unsigned char *p, int len);
553int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
554long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
555int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
556int ssl3_num_ciphers(void);
557SSL_CIPHER *ssl3_get_cipher(unsigned int u);
558int ssl3_renegotiate(SSL *ssl);
559int ssl3_renegotiate_check(SSL *ssl);
560int ssl3_dispatch_alert(SSL *s);
561int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
562int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
563int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
564 const char *sender, int slen,unsigned char *p);
565int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
566void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
567int ssl3_enc(SSL *s, int send_data);
568int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
569unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
570SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *clnt,
571 STACK_OF(SSL_CIPHER) *srvr);
572int ssl3_setup_buffers(SSL *s);
573int ssl3_new(SSL *s);
574void ssl3_free(SSL *s);
575int ssl3_accept(SSL *s);
576int ssl3_connect(SSL *s);
577int ssl3_read(SSL *s, void *buf, int len);
578int ssl3_peek(SSL *s, void *buf, int len);
579int ssl3_write(SSL *s, const void *buf, int len);
580int ssl3_shutdown(SSL *s);
581void ssl3_clear(SSL *s);
582long ssl3_ctrl(SSL *s,int cmd, long larg, void *parg);
583long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
584long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)());
585long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
586int ssl3_pending(SSL *s);
587
588int ssl23_accept(SSL *s);
589int ssl23_connect(SSL *s);
590int ssl23_read_bytes(SSL *s, int n);
591int ssl23_write_bytes(SSL *s);
592
593int tls1_new(SSL *s);
594void tls1_free(SSL *s);
595void tls1_clear(SSL *s);
596long tls1_ctrl(SSL *s,int cmd, long larg, void *parg);
597long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)());
598SSL_METHOD *tlsv1_base_method(void );
599
600int ssl_init_wbio_buffer(SSL *s, int push);
601void ssl_free_wbio_buffer(SSL *s);
602
603int tls1_change_cipher_state(SSL *s, int which);
604int tls1_setup_key_block(SSL *s);
605int tls1_enc(SSL *s, int snd);
606int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
607 const char *str, int slen, unsigned char *p);
608int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
609int tls1_mac(SSL *ssl, unsigned char *md, int snd);
610int tls1_generate_master_secret(SSL *s, unsigned char *out,
611 unsigned char *p, int len);
612int tls1_alert_code(int code);
613int ssl3_alert_code(int code);
614int ssl_ok(SSL *s);
615
616SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
617STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
618
619
620#endif
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index 03828b6632..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 "ssl_locl.h"
61#include <openssl/bio.h>
62#include <openssl/objects.h>
63#include <openssl/evp.h>
64#include <openssl/x509.h>
65#include <openssl/pem.h>
66
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 OPENSSL_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 OPENSSL_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 RSA_up_ref(rsa);
174 EVP_PKEY_assign_RSA(pkey,rsa);
175
176 ret=ssl_set_pkey(ssl->cert,pkey);
177 EVP_PKEY_free(pkey);
178 return(ret);
179 }
180#endif
181
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 OPENSSL_NO_RSA
202 /* Don't check the public/private key, this is mostly
203 * for smart cards. */
204 if ((pkey->type == EVP_PKEY_RSA) &&
205 (RSA_flags(pkey->pkey.rsa) &
206 RSA_METHOD_FLAG_NO_CHECK))
207 ok=1;
208 else
209#endif
210 if (!X509_check_private_key(c->pkeys[i].x509,pkey))
211 {
212 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
213 {
214 i=(i == SSL_PKEY_DH_RSA)?
215 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
216
217 if (c->pkeys[i].x509 == NULL)
218 ok=1;
219 else
220 {
221 if (!X509_check_private_key(
222 c->pkeys[i].x509,pkey))
223 bad=1;
224 else
225 ok=1;
226 }
227 }
228 else
229 bad=1;
230 }
231 else
232 ok=1;
233 }
234 else
235 ok=1;
236
237 if (bad)
238 {
239 X509_free(c->pkeys[i].x509);
240 c->pkeys[i].x509=NULL;
241 return(0);
242 }
243
244 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 OPENSSL_NO_RSA
255#ifndef OPENSSL_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 const 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 /* !OPENSSL_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 OPENSSL_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 OPENSSL_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 } /* OPENSSL_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 OPENSSL_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 OPENSSL_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 RSA_up_ref(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 OPENSSL_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 const 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 /* !OPENSSL_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 OPENSSL_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 OPENSSL_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_last_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 664f8c2230..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,751 +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);
67
68SSL_SESSION *SSL_get_session(SSL *ssl)
69/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
70 {
71 return(ssl->session);
72 }
73
74SSL_SESSION *SSL_get1_session(SSL *ssl)
75/* variant of SSL_get_session: caller really gets something */
76 {
77 SSL_SESSION *sess;
78 /* Need to lock this all up rather than just use CRYPTO_add so that
79 * somebody doesn't free ssl->session between when we check it's
80 * non-null and when we up the reference count. */
81 CRYPTO_r_lock(CRYPTO_LOCK_SSL_SESSION);
82 sess = ssl->session;
83 if(sess)
84 sess->references++;
85 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_SESSION);
86 return(sess);
87 }
88
89int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
90 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
91 {
92 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION, argl, argp,
93 new_func, dup_func, free_func);
94 }
95
96int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
97 {
98 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
99 }
100
101void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx)
102 {
103 return(CRYPTO_get_ex_data(&s->ex_data,idx));
104 }
105
106SSL_SESSION *SSL_SESSION_new(void)
107 {
108 SSL_SESSION *ss;
109
110 ss=(SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));
111 if (ss == NULL)
112 {
113 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
114 return(0);
115 }
116 memset(ss,0,sizeof(SSL_SESSION));
117
118 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
119 ss->references=1;
120 ss->timeout=60*5+4; /* 5 minute timeout by default */
121 ss->time=time(NULL);
122 ss->prev=NULL;
123 ss->next=NULL;
124 ss->compress_meth=0;
125 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
126 return(ss);
127 }
128
129/* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1
130 * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly
131 * until we have no conflict is going to complete in one iteration pretty much
132 * "most" of the time (btw: understatement). So, if it takes us 10 iterations
133 * and we still can't avoid a conflict - well that's a reasonable point to call
134 * it quits. Either the RAND code is broken or someone is trying to open roughly
135 * very close to 2^128 (or 2^256) SSL sessions to our server. How you might
136 * store that many sessions is perhaps a more interesting question ... */
137
138#define MAX_SESS_ID_ATTEMPTS 10
139static int def_generate_session_id(const SSL *ssl, unsigned char *id,
140 unsigned int *id_len)
141{
142 unsigned int retry = 0;
143 do
144 RAND_pseudo_bytes(id, *id_len);
145 while(SSL_has_matching_session_id(ssl, id, *id_len) &&
146 (++retry < MAX_SESS_ID_ATTEMPTS));
147 if(retry < MAX_SESS_ID_ATTEMPTS)
148 return 1;
149 /* else - woops a session_id match */
150 /* XXX We should also check the external cache --
151 * but the probability of a collision is negligible, and
152 * we could not prevent the concurrent creation of sessions
153 * with identical IDs since we currently don't have means
154 * to atomically check whether a session ID already exists
155 * and make a reservation for it if it does not
156 * (this problem applies to the internal cache as well).
157 */
158 return 0;
159}
160
161int ssl_get_new_session(SSL *s, int session)
162 {
163 /* This gets used by clients and servers. */
164
165 unsigned int tmp;
166 SSL_SESSION *ss=NULL;
167 GEN_SESSION_CB cb = def_generate_session_id;
168
169 if ((ss=SSL_SESSION_new()) == NULL) return(0);
170
171 /* If the context has a default timeout, use it */
172 if (s->ctx->session_timeout == 0)
173 ss->timeout=SSL_get_default_timeout(s);
174 else
175 ss->timeout=s->ctx->session_timeout;
176
177 if (s->session != NULL)
178 {
179 SSL_SESSION_free(s->session);
180 s->session=NULL;
181 }
182
183 if (session)
184 {
185 if (s->version == SSL2_VERSION)
186 {
187 ss->ssl_version=SSL2_VERSION;
188 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
189 }
190 else if (s->version == SSL3_VERSION)
191 {
192 ss->ssl_version=SSL3_VERSION;
193 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
194 }
195 else if (s->version == TLS1_VERSION)
196 {
197 ss->ssl_version=TLS1_VERSION;
198 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
199 }
200 else
201 {
202 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
203 SSL_SESSION_free(ss);
204 return(0);
205 }
206 /* Choose which callback will set the session ID */
207 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
208 if(s->generate_session_id)
209 cb = s->generate_session_id;
210 else if(s->ctx->generate_session_id)
211 cb = s->ctx->generate_session_id;
212 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
213 /* Choose a session ID */
214 tmp = ss->session_id_length;
215 if(!cb(s, ss->session_id, &tmp))
216 {
217 /* The callback failed */
218 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
219 SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
220 SSL_SESSION_free(ss);
221 return(0);
222 }
223 /* Don't allow the callback to set the session length to zero.
224 * nor set it higher than it was. */
225 if(!tmp || (tmp > ss->session_id_length))
226 {
227 /* The callback set an illegal length */
228 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
229 SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
230 SSL_SESSION_free(ss);
231 return(0);
232 }
233 /* If the session length was shrunk and we're SSLv2, pad it */
234 if((tmp < ss->session_id_length) && (s->version == SSL2_VERSION))
235 memset(ss->session_id + tmp, 0, ss->session_id_length - tmp);
236 else
237 ss->session_id_length = tmp;
238 /* Finally, check for a conflict */
239 if(SSL_has_matching_session_id(s, ss->session_id,
240 ss->session_id_length))
241 {
242 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
243 SSL_R_SSL_SESSION_ID_CONFLICT);
244 SSL_SESSION_free(ss);
245 return(0);
246 }
247 }
248 else
249 {
250 ss->session_id_length=0;
251 }
252
253 if (s->sid_ctx_length > sizeof ss->sid_ctx)
254 {
255 SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
256 SSL_SESSION_free(ss);
257 return 0;
258 }
259 memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
260 ss->sid_ctx_length=s->sid_ctx_length;
261 s->session=ss;
262 ss->ssl_version=s->version;
263 ss->verify_result = X509_V_OK;
264
265 return(1);
266 }
267
268int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
269 {
270 /* This is used only by servers. */
271
272 SSL_SESSION *ret=NULL,data;
273 int fatal = 0;
274
275 data.ssl_version=s->version;
276 data.session_id_length=len;
277 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
278 goto err;
279 memcpy(data.session_id,session_id,len);
280
281 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
282 {
283 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
284 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);
285 if (ret != NULL)
286 /* don't allow other threads to steal it: */
287 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
288 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
289 }
290
291 if (ret == NULL)
292 {
293 int copy=1;
294
295 s->ctx->stats.sess_miss++;
296 ret=NULL;
297 if (s->ctx->get_session_cb != NULL
298 && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
299 != NULL)
300 {
301 s->ctx->stats.sess_cb_hit++;
302
303 /* Increment reference count now if the session callback
304 * asks us to do so (note that if the session structures
305 * returned by the callback are shared between threads,
306 * it must handle the reference count itself [i.e. copy == 0],
307 * or things won't be thread-safe). */
308 if (copy)
309 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
310
311 /* The following should not return 1, otherwise,
312 * things are very strange */
313 SSL_CTX_add_session(s->ctx,ret);
314 }
315 if (ret == NULL)
316 goto err;
317 }
318
319 /* Now ret is non-NULL, and we own one of its reference counts. */
320
321 if((s->verify_mode&SSL_VERIFY_PEER)
322 && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length
323 || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))
324 {
325 /* We've found the session named by the client, but we don't
326 * want to use it in this context. */
327
328 if (s->sid_ctx_length == 0)
329 {
330 /* application should have used SSL[_CTX]_set_session_id_context
331 * -- we could tolerate this and just pretend we never heard
332 * of this session, but then applications could effectively
333 * disable the session cache by accident without anyone noticing */
334
335 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
336 fatal = 1;
337 goto err;
338 }
339 else
340 {
341#if 0 /* The client cannot always know when a session is not appropriate,
342 * so we shouldn't generate an error message. */
343
344 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
345#endif
346 goto err; /* treat like cache miss */
347 }
348 }
349
350 if (ret->cipher == NULL)
351 {
352 unsigned char buf[5],*p;
353 unsigned long l;
354
355 p=buf;
356 l=ret->cipher_id;
357 l2n(l,p);
358 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
359 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
360 else
361 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
362 if (ret->cipher == NULL)
363 goto err;
364 }
365
366
367#if 0 /* This is way too late. */
368
369 /* If a thread got the session, then 'swaped', and another got
370 * it and then due to a time-out decided to 'OPENSSL_free' it we could
371 * be in trouble. So I'll increment it now, then double decrement
372 * later - am I speaking rubbish?. */
373 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
374#endif
375
376 if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */
377 {
378 s->ctx->stats.sess_timeout++;
379 /* remove it from the cache */
380 SSL_CTX_remove_session(s->ctx,ret);
381 goto err;
382 }
383
384 s->ctx->stats.sess_hit++;
385
386 /* ret->time=time(NULL); */ /* rezero timeout? */
387 /* again, just leave the session
388 * if it is the same session, we have just incremented and
389 * then decremented the reference count :-) */
390 if (s->session != NULL)
391 SSL_SESSION_free(s->session);
392 s->session=ret;
393 s->verify_result = s->session->verify_result;
394 return(1);
395
396 err:
397 if (ret != NULL)
398 SSL_SESSION_free(ret);
399 if (fatal)
400 return -1;
401 else
402 return 0;
403 }
404
405int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
406 {
407 int ret=0;
408 SSL_SESSION *s;
409
410 /* add just 1 reference count for the SSL_CTX's session cache
411 * even though it has two ways of access: each session is in a
412 * doubly linked list and an lhash */
413 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
414 /* if session c is in already in cache, we take back the increment later */
415
416 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
417 s=(SSL_SESSION *)lh_insert(ctx->sessions,c);
418
419 /* s != NULL iff we already had a session with the given PID.
420 * In this case, s == c should hold (then we did not really modify
421 * ctx->sessions), or we're in trouble. */
422 if (s != NULL && s != c)
423 {
424 /* We *are* in trouble ... */
425 SSL_SESSION_list_remove(ctx,s);
426 SSL_SESSION_free(s);
427 /* ... so pretend the other session did not exist in cache
428 * (we cannot handle two SSL_SESSION structures with identical
429 * session ID in the same cache, which could happen e.g. when
430 * two threads concurrently obtain the same session from an external
431 * cache) */
432 s = NULL;
433 }
434
435 /* Put at the head of the queue unless it is already in the cache */
436 if (s == NULL)
437 SSL_SESSION_list_add(ctx,c);
438
439 if (s != NULL)
440 {
441 /* existing cache entry -- decrement previously incremented reference
442 * count because it already takes into account the cache */
443
444 SSL_SESSION_free(s); /* s == c */
445 ret=0;
446 }
447 else
448 {
449 /* new cache entry -- remove old ones if cache has become too large */
450
451 ret=1;
452
453 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
454 {
455 while (SSL_CTX_sess_number(ctx) >
456 SSL_CTX_sess_get_cache_size(ctx))
457 {
458 if (!remove_session_lock(ctx,
459 ctx->session_cache_tail, 0))
460 break;
461 else
462 ctx->stats.sess_cache_full++;
463 }
464 }
465 }
466 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
467 return(ret);
468 }
469
470int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
471{
472 return remove_session_lock(ctx, c, 1);
473}
474
475static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
476 {
477 SSL_SESSION *r;
478 int ret=0;
479
480 if ((c != NULL) && (c->session_id_length != 0))
481 {
482 if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
483 if ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)
484 {
485 ret=1;
486 r=(SSL_SESSION *)lh_delete(ctx->sessions,c);
487 SSL_SESSION_list_remove(ctx,c);
488 }
489
490 if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
491
492 if (ret)
493 {
494 r->not_resumable=1;
495 if (ctx->remove_session_cb != NULL)
496 ctx->remove_session_cb(ctx,r);
497 SSL_SESSION_free(r);
498 }
499 }
500 else
501 ret=0;
502 return(ret);
503 }
504
505void SSL_SESSION_free(SSL_SESSION *ss)
506 {
507 int i;
508
509 if(ss == NULL)
510 return;
511
512 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
513#ifdef REF_PRINT
514 REF_PRINT("SSL_SESSION",ss);
515#endif
516 if (i > 0) return;
517#ifdef REF_CHECK
518 if (i < 0)
519 {
520 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
521 abort(); /* ok */
522 }
523#endif
524
525 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
526
527 memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
528 memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
529 memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
530 if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
531 if (ss->peer != NULL) X509_free(ss->peer);
532 if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
533 memset(ss,0,sizeof(*ss));
534 OPENSSL_free(ss);
535 }
536
537int SSL_set_session(SSL *s, SSL_SESSION *session)
538 {
539 int ret=0;
540 SSL_METHOD *meth;
541
542 if (session != NULL)
543 {
544 meth=s->ctx->method->get_ssl_method(session->ssl_version);
545 if (meth == NULL)
546 meth=s->method->get_ssl_method(session->ssl_version);
547 if (meth == NULL)
548 {
549 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
550 return(0);
551 }
552
553 if (meth != s->method)
554 {
555 if (!SSL_set_ssl_method(s,meth))
556 return(0);
557 if (s->ctx->session_timeout == 0)
558 session->timeout=SSL_get_default_timeout(s);
559 else
560 session->timeout=s->ctx->session_timeout;
561 }
562
563#ifndef OPENSSL_NO_KRB5
564 if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
565 session->krb5_client_princ_len > 0)
566 {
567 s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1);
568 memcpy(s->kssl_ctx->client_princ,session->krb5_client_princ,
569 session->krb5_client_princ_len);
570 s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
571 }
572#endif /* OPENSSL_NO_KRB5 */
573
574 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
575 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
576 if (s->session != NULL)
577 SSL_SESSION_free(s->session);
578 s->session=session;
579 s->verify_result = s->session->verify_result;
580 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
581 ret=1;
582 }
583 else
584 {
585 if (s->session != NULL)
586 {
587 SSL_SESSION_free(s->session);
588 s->session=NULL;
589 }
590
591 meth=s->ctx->method;
592 if (meth != s->method)
593 {
594 if (!SSL_set_ssl_method(s,meth))
595 return(0);
596 }
597 ret=1;
598 }
599 return(ret);
600 }
601
602long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
603 {
604 if (s == NULL) return(0);
605 s->timeout=t;
606 return(1);
607 }
608
609long SSL_SESSION_get_timeout(SSL_SESSION *s)
610 {
611 if (s == NULL) return(0);
612 return(s->timeout);
613 }
614
615long SSL_SESSION_get_time(SSL_SESSION *s)
616 {
617 if (s == NULL) return(0);
618 return(s->time);
619 }
620
621long SSL_SESSION_set_time(SSL_SESSION *s, long t)
622 {
623 if (s == NULL) return(0);
624 s->time=t;
625 return(t);
626 }
627
628long SSL_CTX_set_timeout(SSL_CTX *s, long t)
629 {
630 long l;
631 if (s == NULL) return(0);
632 l=s->session_timeout;
633 s->session_timeout=t;
634 return(l);
635 }
636
637long SSL_CTX_get_timeout(SSL_CTX *s)
638 {
639 if (s == NULL) return(0);
640 return(s->session_timeout);
641 }
642
643typedef struct timeout_param_st
644 {
645 SSL_CTX *ctx;
646 long time;
647 LHASH *cache;
648 } TIMEOUT_PARAM;
649
650static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
651 {
652 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
653 {
654 /* The reason we don't call SSL_CTX_remove_session() is to
655 * save on locking overhead */
656 lh_delete(p->cache,s);
657 SSL_SESSION_list_remove(p->ctx,s);
658 s->not_resumable=1;
659 if (p->ctx->remove_session_cb != NULL)
660 p->ctx->remove_session_cb(p->ctx,s);
661 SSL_SESSION_free(s);
662 }
663 }
664
665static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *)
666
667void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
668 {
669 unsigned long i;
670 TIMEOUT_PARAM tp;
671
672 tp.ctx=s;
673 tp.cache=s->sessions;
674 if (tp.cache == NULL) return;
675 tp.time=t;
676 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
677 i=tp.cache->down_load;
678 tp.cache->down_load=0;
679 lh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp);
680 tp.cache->down_load=i;
681 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
682 }
683
684int ssl_clear_bad_session(SSL *s)
685 {
686 if ( (s->session != NULL) &&
687 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
688 !(SSL_in_init(s) || SSL_in_before(s)))
689 {
690 SSL_CTX_remove_session(s->ctx,s->session);
691 return(1);
692 }
693 else
694 return(0);
695 }
696
697/* locked by SSL_CTX in the calling function */
698static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
699 {
700 if ((s->next == NULL) || (s->prev == NULL)) return;
701
702 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
703 { /* last element in list */
704 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
705 { /* only one element in list */
706 ctx->session_cache_head=NULL;
707 ctx->session_cache_tail=NULL;
708 }
709 else
710 {
711 ctx->session_cache_tail=s->prev;
712 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
713 }
714 }
715 else
716 {
717 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
718 { /* first element in list */
719 ctx->session_cache_head=s->next;
720 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
721 }
722 else
723 { /* middle of list */
724 s->next->prev=s->prev;
725 s->prev->next=s->next;
726 }
727 }
728 s->prev=s->next=NULL;
729 }
730
731static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
732 {
733 if ((s->next != NULL) && (s->prev != NULL))
734 SSL_SESSION_list_remove(ctx,s);
735
736 if (ctx->session_cache_head == NULL)
737 {
738 ctx->session_cache_head=s;
739 ctx->session_cache_tail=s;
740 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
741 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
742 }
743 else
744 {
745 s->next=ctx->session_cache_head;
746 s->next->prev=s;
747 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
748 ctx->session_cache_head=s;
749 }
750 }
751
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index b16d253081..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,502 +0,0 @@
1/* ssl/ssl_stat.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "ssl_locl.h"
61
62const char *SSL_state_string_long(const SSL *s)
63 {
64 const 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 OPENSSL_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 OPENSSL_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 B"; 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 B"; 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(OPENSSL_NO_SSL2) && !defined(OPENSSL_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
202const char *SSL_rstate_string_long(const SSL *s)
203 {
204 const char *str;
205
206 switch (s->rstate)
207 {
208 case SSL_ST_READ_HEADER: str="read header"; break;
209 case SSL_ST_READ_BODY: str="read body"; break;
210 case SSL_ST_READ_DONE: str="read done"; break;
211 default: str="unknown"; break;
212 }
213 return(str);
214 }
215
216const char *SSL_state_string(const SSL *s)
217 {
218 const 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 OPENSSL_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 OPENSSL_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(OPENSSL_NO_SSL2) && !defined(OPENSSL_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
350const char *SSL_alert_type_string_long(int value)
351 {
352 value>>=8;
353 if (value == SSL3_AL_WARNING)
354 return("warning");
355 else if (value == SSL3_AL_FATAL)
356 return("fatal");
357 else
358 return("unknown");
359 }
360
361const char *SSL_alert_type_string(int value)
362 {
363 value>>=8;
364 if (value == SSL3_AL_WARNING)
365 return("W");
366 else if (value == SSL3_AL_FATAL)
367 return("F");
368 else
369 return("U");
370 }
371
372const char *SSL_alert_desc_string(int value)
373 {
374 const char *str;
375
376 switch (value & 0xff)
377 {
378 case SSL3_AD_CLOSE_NOTIFY: str="CN"; break;
379 case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break;
380 case SSL3_AD_BAD_RECORD_MAC: str="BM"; break;
381 case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break;
382 case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break;
383 case SSL3_AD_NO_CERTIFICATE: str="NC"; break;
384 case SSL3_AD_BAD_CERTIFICATE: str="BC"; break;
385 case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break;
386 case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break;
387 case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break;
388 case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break;
389 case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break;
390 case TLS1_AD_DECRYPTION_FAILED: str="DC"; break;
391 case TLS1_AD_RECORD_OVERFLOW: str="RO"; break;
392 case TLS1_AD_UNKNOWN_CA: str="CA"; break;
393 case TLS1_AD_ACCESS_DENIED: str="AD"; break;
394 case TLS1_AD_DECODE_ERROR: str="DE"; break;
395 case TLS1_AD_DECRYPT_ERROR: str="CY"; break;
396 case TLS1_AD_EXPORT_RESTRICTION: str="ER"; break;
397 case TLS1_AD_PROTOCOL_VERSION: str="PV"; break;
398 case TLS1_AD_INSUFFICIENT_SECURITY: str="IS"; break;
399 case TLS1_AD_INTERNAL_ERROR: str="IE"; break;
400 case TLS1_AD_USER_CANCELLED: str="US"; break;
401 case TLS1_AD_NO_RENEGOTIATION: str="NR"; break;
402 default: str="UK"; break;
403 }
404 return(str);
405 }
406
407const char *SSL_alert_desc_string_long(int value)
408 {
409 const char *str;
410
411 switch (value & 0xff)
412 {
413 case SSL3_AD_CLOSE_NOTIFY:
414 str="close notify";
415 break;
416 case SSL3_AD_UNEXPECTED_MESSAGE:
417 str="unexpected_message";
418 break;
419 case SSL3_AD_BAD_RECORD_MAC:
420 str="bad record mac";
421 break;
422 case SSL3_AD_DECOMPRESSION_FAILURE:
423 str="decompression failure";
424 break;
425 case SSL3_AD_HANDSHAKE_FAILURE:
426 str="handshake failure";
427 break;
428 case SSL3_AD_NO_CERTIFICATE:
429 str="no certificate";
430 break;
431 case SSL3_AD_BAD_CERTIFICATE:
432 str="bad certificate";
433 break;
434 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
435 str="unsupported certificate";
436 break;
437 case SSL3_AD_CERTIFICATE_REVOKED:
438 str="certificate revoked";
439 break;
440 case SSL3_AD_CERTIFICATE_EXPIRED:
441 str="certificate expired";
442 break;
443 case SSL3_AD_CERTIFICATE_UNKNOWN:
444 str="certificate unknown";
445 break;
446 case SSL3_AD_ILLEGAL_PARAMETER:
447 str="illegal parameter";
448 break;
449 case TLS1_AD_DECRYPTION_FAILED:
450 str="decryption failed";
451 break;
452 case TLS1_AD_RECORD_OVERFLOW:
453 str="record overflow";
454 break;
455 case TLS1_AD_UNKNOWN_CA:
456 str="unknown CA";
457 break;
458 case TLS1_AD_ACCESS_DENIED:
459 str="access denied";
460 break;
461 case TLS1_AD_DECODE_ERROR:
462 str="decode error";
463 break;
464 case TLS1_AD_DECRYPT_ERROR:
465 str="decrypt error";
466 break;
467 case TLS1_AD_EXPORT_RESTRICTION:
468 str="export restriction";
469 break;
470 case TLS1_AD_PROTOCOL_VERSION:
471 str="protocol version";
472 break;
473 case TLS1_AD_INSUFFICIENT_SECURITY:
474 str="insufficient security";
475 break;
476 case TLS1_AD_INTERNAL_ERROR:
477 str="internal error";
478 break;
479 case TLS1_AD_USER_CANCELLED:
480 str="user canceled";
481 break;
482 case TLS1_AD_NO_RENEGOTIATION:
483 str="no renegotiation";
484 break;
485 default: str="unknown"; break;
486 }
487 return(str);
488 }
489
490const char *SSL_rstate_string(const SSL *s)
491 {
492 const char *str;
493
494 switch (s->rstate)
495 {
496 case SSL_ST_READ_HEADER:str="RH"; break;
497 case SSL_ST_READ_BODY: str="RB"; break;
498 case SSL_ST_READ_DONE: str="RD"; break;
499 default: str="unknown"; break;
500 }
501 return(str);
502 }
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index 40b76b1b26..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/* ssl/ssl_txt.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/buffer.h>
61#include "ssl_locl.h"
62
63#ifndef OPENSSL_NO_FP_API
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#ifndef OPENSSL_NO_KRB5
143 if (BIO_puts(bp,"\n Krb5 Principal: ") <= 0) goto err;
144 if (x->krb5_client_princ_len == 0)
145 {
146 if (BIO_puts(bp,"None") <= 0) goto err;
147 }
148 else
149 for (i=0; i<x->krb5_client_princ_len; i++)
150 {
151 if (BIO_printf(bp,"%02X",x->krb5_client_princ[i]) <= 0) goto err;
152 }
153#endif /* OPENSSL_NO_KRB5 */
154 if (x->compress_meth != 0)
155 {
156 SSL_COMP *comp;
157
158 ssl_cipher_get_evp(x,NULL,NULL,&comp);
159 if (comp == NULL)
160 {
161 if (BIO_printf(bp,"\n Compression: %d",x->compress_meth) <= 0) goto err;
162 }
163 else
164 {
165 if (BIO_printf(bp,"\n Compression: %d (%s)", comp->id,comp->method->name) <= 0) goto err;
166 }
167 }
168 if (x->time != 0L)
169 {
170 if (BIO_printf(bp, "\n Start Time: %ld",x->time) <= 0) goto err;
171 }
172 if (x->timeout != 0L)
173 {
174 if (BIO_printf(bp, "\n Timeout : %ld (sec)",x->timeout) <= 0) goto err;
175 }
176 if (BIO_puts(bp,"\n") <= 0) goto err;
177
178 if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
179 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
180 X509_verify_cert_error_string(x->verify_result)) <= 0) goto err;
181
182 return(1);
183err:
184 return(0);
185 }
186