summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/ssl.h2382
-rw-r--r--src/lib/libssl/ssl2.h153
-rw-r--r--src/lib/libssl/ssl23.h82
-rw-r--r--src/lib/libssl/ssl3.h617
-rw-r--r--src/lib/libssl/ssl_algs.c131
-rw-r--r--src/lib/libssl/ssl_asn1.c691
-rw-r--r--src/lib/libssl/ssl_cert.c722
-rw-r--r--src/lib/libssl/ssl_ciph.c1798
-rw-r--r--src/lib/libssl/ssl_err.c615
-rw-r--r--src/lib/libssl/ssl_err2.c72
-rw-r--r--src/lib/libssl/ssl_lib.c3062
-rw-r--r--src/lib/libssl/ssl_locl.h847
-rw-r--r--src/lib/libssl/ssl_rsa.c751
-rw-r--r--src/lib/libssl/ssl_sess.c1099
-rw-r--r--src/lib/libssl/ssl_stat.c801
-rw-r--r--src/lib/libssl/ssl_txt.c187
16 files changed, 0 insertions, 14010 deletions
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index 58493fa988..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,2382 +0,0 @@
1/* $OpenBSD: ssl.h,v 1.96 2015/10/25 16:07:04 doug Exp $ */
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-2007 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 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#ifndef HEADER_SSL_H
144#define HEADER_SSL_H
145
146#include <stdint.h>
147
148#include <openssl/opensslconf.h>
149#include <openssl/hmac.h>
150#include <openssl/pem.h>
151#include <openssl/safestack.h>
152
153#ifndef OPENSSL_NO_BIO
154#include <openssl/bio.h>
155#endif
156
157#ifndef OPENSSL_NO_DEPRECATED
158#include <openssl/buffer.h>
159#include <openssl/crypto.h>
160#include <openssl/lhash.h>
161
162#ifndef OPENSSL_NO_X509
163#include <openssl/x509.h>
164#endif
165#endif
166
167#ifdef __cplusplus
168extern "C" {
169#endif
170
171/* SSLeay version number for ASN.1 encoding of the session information */
172/* Version 0 - initial version
173 * Version 1 - added the optional peer certificate
174 */
175#define SSL_SESSION_ASN1_VERSION 0x0001
176
177/* text strings for the ciphers */
178#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
179#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
180#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
181#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
182#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
183#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
184#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
185#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
186#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
187#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
188
189/* VRS Additional Kerberos5 entries
190 */
191#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA
192#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA
193#define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA
194#define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA
195#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5
196#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5
197#define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5
198#define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5
199
200#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA
201#define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA
202#define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA
203#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5
204#define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5
205#define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5
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
223/* These are used to specify which ciphers to use and not to use */
224
225#define SSL_TXT_LOW "LOW"
226#define SSL_TXT_MEDIUM "MEDIUM"
227#define SSL_TXT_HIGH "HIGH"
228
229#define SSL_TXT_kFZA "kFZA" /* unused! */
230#define SSL_TXT_aFZA "aFZA" /* unused! */
231#define SSL_TXT_eFZA "eFZA" /* unused! */
232#define SSL_TXT_FZA "FZA" /* unused! */
233
234#define SSL_TXT_aNULL "aNULL"
235#define SSL_TXT_eNULL "eNULL"
236#define SSL_TXT_NULL "NULL"
237
238#define SSL_TXT_kRSA "kRSA"
239#define SSL_TXT_kDHr "kDHr" /* no such ciphersuites supported! */
240#define SSL_TXT_kDHd "kDHd" /* no such ciphersuites supported! */
241#define SSL_TXT_kDH "kDH" /* no such ciphersuites supported! */
242#define SSL_TXT_kEDH "kEDH"
243#define SSL_TXT_kKRB5 "kKRB5"
244#define SSL_TXT_kECDHr "kECDHr"
245#define SSL_TXT_kECDHe "kECDHe"
246#define SSL_TXT_kECDH "kECDH"
247#define SSL_TXT_kEECDH "kEECDH"
248#define SSL_TXT_kPSK "kPSK"
249#define SSL_TXT_kGOST "kGOST"
250#define SSL_TXT_kSRP "kSRP"
251
252#define SSL_TXT_aRSA "aRSA"
253#define SSL_TXT_aDSS "aDSS"
254#define SSL_TXT_aDH "aDH" /* no such ciphersuites supported! */
255#define SSL_TXT_aECDH "aECDH"
256#define SSL_TXT_aKRB5 "aKRB5"
257#define SSL_TXT_aECDSA "aECDSA"
258#define SSL_TXT_aPSK "aPSK"
259#define SSL_TXT_aGOST94 "aGOST94"
260#define SSL_TXT_aGOST01 "aGOST01"
261#define SSL_TXT_aGOST "aGOST"
262
263#define SSL_TXT_DSS "DSS"
264#define SSL_TXT_DH "DH"
265#define SSL_TXT_DHE "DHE" /* same as "kDHE:-ADH" */
266#define SSL_TXT_EDH "EDH" /* previous name for DHE */
267#define SSL_TXT_ADH "ADH"
268#define SSL_TXT_RSA "RSA"
269#define SSL_TXT_ECDH "ECDH"
270#define SSL_TXT_ECDHE "ECDHE" /* same as "kECDHE:-AECDH" */
271#define SSL_TXT_EECDH "EECDH" /* previous name for ECDHE */
272#define SSL_TXT_AECDH "AECDH"
273#define SSL_TXT_ECDSA "ECDSA"
274#define SSL_TXT_KRB5 "KRB5"
275#define SSL_TXT_PSK "PSK"
276#define SSL_TXT_SRP "SRP"
277
278#define SSL_TXT_DES "DES"
279#define SSL_TXT_3DES "3DES"
280#define SSL_TXT_RC4 "RC4"
281#define SSL_TXT_RC2 "RC2"
282#define SSL_TXT_IDEA "IDEA"
283#define SSL_TXT_SEED "SEED"
284#define SSL_TXT_AES128 "AES128"
285#define SSL_TXT_AES256 "AES256"
286#define SSL_TXT_AES "AES"
287#define SSL_TXT_AES_GCM "AESGCM"
288#define SSL_TXT_CAMELLIA128 "CAMELLIA128"
289#define SSL_TXT_CAMELLIA256 "CAMELLIA256"
290#define SSL_TXT_CAMELLIA "CAMELLIA"
291#define SSL_TXT_CHACHA20 "CHACHA20"
292
293#define SSL_TXT_AEAD "AEAD"
294#define SSL_TXT_MD5 "MD5"
295#define SSL_TXT_SHA1 "SHA1"
296#define SSL_TXT_SHA "SHA" /* same as "SHA1" */
297#define SSL_TXT_GOST94 "GOST94"
298#define SSL_TXT_GOST89MAC "GOST89MAC"
299#define SSL_TXT_SHA256 "SHA256"
300#define SSL_TXT_SHA384 "SHA384"
301#define SSL_TXT_STREEBOG256 "STREEBOG256"
302#define SSL_TXT_STREEBOG512 "STREEBOG512"
303
304#define SSL_TXT_DTLS1 "DTLSv1"
305#define SSL_TXT_SSLV2 "SSLv2"
306#define SSL_TXT_SSLV3 "SSLv3"
307#define SSL_TXT_TLSV1 "TLSv1"
308#define SSL_TXT_TLSV1_1 "TLSv1.1"
309#define SSL_TXT_TLSV1_2 "TLSv1.2"
310
311#define SSL_TXT_EXP "EXP"
312#define SSL_TXT_EXPORT "EXPORT"
313
314#define SSL_TXT_ALL "ALL"
315
316/*
317 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
318 * ciphers normally not being used.
319 * Example: "RC4" will activate all ciphers using RC4 including ciphers
320 * without authentication, which would normally disabled by DEFAULT (due
321 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
322 * will make sure that it is also disabled in the specific selection.
323 * COMPLEMENTOF* identifiers are portable between version, as adjustments
324 * to the default cipher setup will also be included here.
325 *
326 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
327 * DEFAULT gets, as only selection is being done and no sorting as needed
328 * for DEFAULT.
329 */
330#define SSL_TXT_CMPALL "COMPLEMENTOFALL"
331#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT"
332
333/* The following cipher list is used by default.
334 * It also is substituted when an application-defined cipher list string
335 * starts with 'DEFAULT'. */
336#define SSL_DEFAULT_CIPHER_LIST "ALL:!aNULL:!eNULL:!SSLv2"
337/* As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
338 * starts with a reasonable order, and all we have to do for DEFAULT is
339 * throwing out anonymous and unencrypted ciphersuites!
340 * (The latter are not actually enabled by ALL, but "ALL:RSA" would enable
341 * some of them.)
342 */
343
344/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
345#define SSL_SENT_SHUTDOWN 1
346#define SSL_RECEIVED_SHUTDOWN 2
347
348
349#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
350#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
351
352/* This is needed to stop compilers complaining about the
353 * 'struct ssl_st *' function parameters used to prototype callbacks
354 * in SSL_CTX. */
355typedef struct ssl_st *ssl_crock_st;
356typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
357typedef struct ssl_method_st SSL_METHOD;
358typedef struct ssl_cipher_st SSL_CIPHER;
359typedef struct ssl_session_st SSL_SESSION;
360
361DECLARE_STACK_OF(SSL_CIPHER)
362
363/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
364typedef struct srtp_protection_profile_st {
365 const char *name;
366 unsigned long id;
367} SRTP_PROTECTION_PROFILE;
368
369DECLARE_STACK_OF(SRTP_PROTECTION_PROFILE)
370
371typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
372 int len, void *arg);
373typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
374 STACK_OF(SSL_CIPHER) *peer_ciphers, SSL_CIPHER **cipher, void *arg);
375
376#ifndef OPENSSL_NO_SSL_INTERN
377
378/* used to hold info on the particular ciphers used */
379struct ssl_cipher_st {
380 int valid;
381 const char *name; /* text name */
382 unsigned long id; /* id, 4 bytes, first is version */
383
384 unsigned long algorithm_mkey; /* key exchange algorithm */
385 unsigned long algorithm_auth; /* server authentication */
386 unsigned long algorithm_enc; /* symmetric encryption */
387 unsigned long algorithm_mac; /* symmetric authentication */
388 unsigned long algorithm_ssl; /* (major) protocol version */
389
390 unsigned long algo_strength; /* strength and export flags */
391 unsigned long algorithm2; /* Extra flags */
392 int strength_bits; /* Number of bits really used */
393 int alg_bits; /* Number of bits for algorithm */
394};
395
396
397/* Used to hold functions for SSLv3/TLSv1 functions */
398struct ssl_method_st {
399 int version;
400 int (*ssl_new)(SSL *s);
401 void (*ssl_clear)(SSL *s);
402 void (*ssl_free)(SSL *s);
403 int (*ssl_accept)(SSL *s);
404 int (*ssl_connect)(SSL *s);
405 int (*ssl_read)(SSL *s, void *buf, int len);
406 int (*ssl_peek)(SSL *s, void *buf, int len);
407 int (*ssl_write)(SSL *s, const void *buf, int len);
408 int (*ssl_shutdown)(SSL *s);
409 int (*ssl_renegotiate)(SSL *s);
410 int (*ssl_renegotiate_check)(SSL *s);
411 long (*ssl_get_message)(SSL *s, int st1, int stn, int mt,
412 long max, int *ok);
413 int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf,
414 int len, int peek);
415 int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len);
416 int (*ssl_dispatch_alert)(SSL *s);
417 long (*ssl_ctrl)(SSL *s, int cmd, long larg, void *parg);
418 long (*ssl_ctx_ctrl)(SSL_CTX *ctx, int cmd, long larg, void *parg);
419 const SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
420 int (*put_cipher_by_char)(const SSL_CIPHER *cipher, unsigned char *ptr);
421 int (*ssl_pending)(const SSL *s);
422 int (*num_ciphers)(void);
423 const SSL_CIPHER *(*get_cipher)(unsigned ncipher);
424 const struct ssl_method_st *(*get_ssl_method)(int version);
425 long (*get_timeout)(void);
426 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
427 int (*ssl_version)(void);
428 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)(void));
429 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)(void));
430};
431
432/* Lets make this into an ASN.1 type structure as follows
433 * SSL_SESSION_ID ::= SEQUENCE {
434 * version INTEGER, -- structure version number
435 * SSLversion INTEGER, -- SSL version number
436 * Cipher OCTET STRING, -- the 3 byte cipher ID
437 * Session_ID OCTET STRING, -- the Session ID
438 * Master_key OCTET STRING, -- the master key
439 * KRB5_principal OCTET STRING -- optional Kerberos principal
440 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
441 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
442 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
443 * Session_ID_context [ 4 ] EXPLICIT OCTET STRING, -- the Session ID context
444 * Verify_result [ 5 ] EXPLICIT INTEGER, -- X509_V_... code for `Peer'
445 * HostName [ 6 ] EXPLICIT OCTET STRING, -- optional HostName from servername TLS extension
446 * PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
447 * PSK_identity [ 8 ] EXPLICIT OCTET STRING, -- optional PSK identity
448 * Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
449 * Ticket [10] EXPLICIT OCTET STRING, -- session ticket (clients only)
450 * Compression_meth [11] EXPLICIT OCTET STRING, -- optional compression method
451 * SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
452 * }
453 * Look in ssl/ssl_asn1.c for more details
454 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
455 */
456struct ssl_session_st {
457 int ssl_version; /* what ssl version session info is
458 * being kept in here? */
459
460 int master_key_length;
461 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
462 /* session_id - valid? */
463 unsigned int session_id_length;
464 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
465 /* this is used to determine whether the session is being reused in
466 * the appropriate context. It is up to the application to set this,
467 * via SSL_new */
468 unsigned int sid_ctx_length;
469 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
470
471 /* Used to indicate that session resumption is not allowed.
472 * Applications can also set this bit for a new session via
473 * not_resumable_session_cb to disable session caching and tickets. */
474 int not_resumable;
475
476 /* The cert is the certificate used to establish this connection */
477 struct sess_cert_st /* SESS_CERT */ *sess_cert;
478
479 /* This is the cert for the other end.
480 * On clients, it will be the same as sess_cert->peer_key->x509
481 * (the latter is not enough as sess_cert is not retained
482 * in the external representation of sessions, see ssl_asn1.c). */
483 X509 *peer;
484 /* when app_verify_callback accepts a session where the peer's certificate
485 * is not ok, we must remember the error for session reuse: */
486 long verify_result; /* only for servers */
487
488 long timeout;
489 time_t time;
490 int references;
491
492 const SSL_CIPHER *cipher;
493 unsigned long cipher_id; /* when ASN.1 loaded, this
494 * needs to be used to load
495 * the 'cipher' structure */
496
497 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
498
499 CRYPTO_EX_DATA ex_data; /* application specific data */
500
501 /* These are used to make removal of session-ids more
502 * efficient and to implement a maximum cache size. */
503 struct ssl_session_st *prev, *next;
504 char *tlsext_hostname;
505 size_t tlsext_ecpointformatlist_length;
506 uint8_t *tlsext_ecpointformatlist; /* peer's list */
507 size_t tlsext_ellipticcurvelist_length;
508 uint16_t *tlsext_ellipticcurvelist; /* peer's list */
509
510 /* RFC4507 info */
511 unsigned char *tlsext_tick; /* Session ticket */
512 size_t tlsext_ticklen; /* Session ticket length */
513 long tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
514};
515
516#endif
517
518/* Allow initial connection to servers that don't support RI */
519#define SSL_OP_LEGACY_SERVER_CONNECT 0x00000004L
520#define SSL_OP_TLSEXT_PADDING 0x00000010L
521
522/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
523 * in OpenSSL 0.9.6d. Usually (depending on the application protocol)
524 * the workaround is not needed.
525 * Unfortunately some broken SSL/TLS implementations cannot handle it
526 * at all, which is why it was previously included in SSL_OP_ALL.
527 * Now it's not.
528 */
529#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L
530
531/* DTLS options */
532#define SSL_OP_NO_QUERY_MTU 0x00001000L
533/* Turn on Cookie Exchange (on relevant for servers) */
534#define SSL_OP_COOKIE_EXCHANGE 0x00002000L
535/* Don't use RFC4507 ticket extension */
536#define SSL_OP_NO_TICKET 0x00004000L
537
538/* As server, disallow session resumption on renegotiation */
539#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L
540/* If set, always create a new key when using tmp_ecdh parameters */
541#define SSL_OP_SINGLE_ECDH_USE 0x00080000L
542/* If set, always create a new key when using tmp_dh parameters */
543#define SSL_OP_SINGLE_DH_USE 0x00100000L
544/* Set on servers to choose the cipher according to the server's
545 * preferences */
546#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L
547/* If set, a server will allow a client to issue a SSLv3.0 version number
548 * as latest version supported in the premaster secret, even when TLSv1.0
549 * (version 3.1) was announced in the client hello. Normally this is
550 * forbidden to prevent version rollback attacks. */
551#define SSL_OP_TLS_ROLLBACK_BUG 0x00800000L
552
553#define SSL_OP_NO_TLSv1 0x04000000L
554#define SSL_OP_NO_TLSv1_2 0x08000000L
555#define SSL_OP_NO_TLSv1_1 0x10000000L
556
557/* Make server add server-hello extension from early version of
558 * cryptopro draft, when GOST ciphersuite is negotiated.
559 * Required for interoperability with CryptoPro CSP 3.x
560 */
561#define SSL_OP_CRYPTOPRO_TLSEXT_BUG 0x80000000L
562
563/* SSL_OP_ALL: various bug workarounds that should be rather harmless. */
564#define SSL_OP_ALL \
565 (SSL_OP_LEGACY_SERVER_CONNECT | \
566 SSL_OP_TLSEXT_PADDING | \
567 SSL_OP_CRYPTOPRO_TLSEXT_BUG)
568
569/* Obsolete flags kept for compatibility. No sane code should use them. */
570#define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0x0
571#define SSL_OP_CISCO_ANYCONNECT 0x0
572#define SSL_OP_EPHEMERAL_RSA 0x0
573#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0
574#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0
575#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0
576#define SSL_OP_NETSCAPE_CA_DN_BUG 0x0
577#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0
578#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0
579#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0
580#define SSL_OP_NO_COMPRESSION 0x0
581#define SSL_OP_NO_SSLv2 0x0
582#define SSL_OP_NO_SSLv3 0x0
583#define SSL_OP_PKCS1_CHECK_1 0x0
584#define SSL_OP_PKCS1_CHECK_2 0x0
585#define SSL_OP_SAFARI_ECDHE_ECDSA_BUG 0x0
586#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0
587#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0
588#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0
589#define SSL_OP_TLS_D5_BUG 0x0
590
591/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
592 * when just a single record has been written): */
593#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
594/* Make it possible to retry SSL_write() with changed buffer location
595 * (buffer contents must stay the same!); this is not the default to avoid
596 * the misconception that non-blocking SSL_write() behaves like
597 * non-blocking write(): */
598#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
599/* Never bother the application with retries if the transport
600 * is blocking: */
601#define SSL_MODE_AUTO_RETRY 0x00000004L
602/* Don't attempt to automatically build certificate chain */
603#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
604/* Save RAM by releasing read and write buffers when they're empty. (SSL3 and
605 * TLS only.) "Released" buffers are put onto a free-list in the context
606 * or just freed (depending on the context's setting for freelist_max_len). */
607#define SSL_MODE_RELEASE_BUFFERS 0x00000010L
608
609/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
610 * they cannot be used to clear bits. */
611
612#define SSL_CTX_set_options(ctx,op) \
613 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)
614#define SSL_CTX_clear_options(ctx,op) \
615 SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_OPTIONS,(op),NULL)
616#define SSL_CTX_get_options(ctx) \
617 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL)
618#define SSL_set_options(ssl,op) \
619 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL)
620#define SSL_clear_options(ssl,op) \
621 SSL_ctrl((ssl),SSL_CTRL_CLEAR_OPTIONS,(op),NULL)
622#define SSL_get_options(ssl) \
623 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL)
624
625#define SSL_CTX_set_mode(ctx,op) \
626 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
627#define SSL_CTX_clear_mode(ctx,op) \
628 SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
629#define SSL_CTX_get_mode(ctx) \
630 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
631#define SSL_clear_mode(ssl,op) \
632 SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
633#define SSL_set_mode(ssl,op) \
634 SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
635#define SSL_get_mode(ssl) \
636 SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
637#define SSL_set_mtu(ssl, mtu) \
638 SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
639
640#define SSL_get_secure_renegotiation_support(ssl) \
641 SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)
642
643void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p,
644 int version, int content_type, const void *buf, size_t len, SSL *ssl,
645 void *arg));
646void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
647 int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
648#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
649#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
650
651struct ssl_aead_ctx_st;
652typedef struct ssl_aead_ctx_st SSL_AEAD_CTX;
653
654#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
655
656#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
657
658/* This callback type is used inside SSL_CTX, SSL, and in the functions that set
659 * them. It is used to override the generation of SSL/TLS session IDs in a
660 * server. Return value should be zero on an error, non-zero to proceed. Also,
661 * callbacks should themselves check if the id they generate is unique otherwise
662 * the SSL handshake will fail with an error - callbacks can do this using the
663 * 'ssl' value they're passed by;
664 * SSL_has_matching_session_id(ssl, id, *id_len)
665 * The length value passed in is set at the maximum size the session ID can be.
666 * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback
667 * can alter this length to be less if desired, but under SSLv2 session IDs are
668 * supposed to be fixed at 16 bytes so the id will be padded after the callback
669 * returns in this case. It is also an error for the callback to set the size to
670 * zero. */
671typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
672 unsigned int *id_len);
673
674typedef struct ssl_comp_st SSL_COMP;
675
676#ifndef OPENSSL_NO_SSL_INTERN
677
678struct ssl_comp_st {
679 int id;
680 const char *name;
681};
682
683DECLARE_STACK_OF(SSL_COMP)
684DECLARE_LHASH_OF(SSL_SESSION);
685
686struct ssl_ctx_st {
687 const SSL_METHOD *method;
688
689 STACK_OF(SSL_CIPHER) *cipher_list;
690 /* same as above but sorted for lookup */
691 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
692
693 struct x509_store_st /* X509_STORE */ *cert_store;
694 LHASH_OF(SSL_SESSION) *sessions;
695 /* Most session-ids that will be cached, default is
696 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
697 unsigned long session_cache_size;
698 struct ssl_session_st *session_cache_head;
699 struct ssl_session_st *session_cache_tail;
700
701 /* This can have one of 2 values, ored together,
702 * SSL_SESS_CACHE_CLIENT,
703 * SSL_SESS_CACHE_SERVER,
704 * Default is SSL_SESSION_CACHE_SERVER, which means only
705 * SSL_accept which cache SSL_SESSIONS. */
706 int session_cache_mode;
707
708 /* If timeout is not 0, it is the default timeout value set
709 * when SSL_new() is called. This has been put in to make
710 * life easier to set things up */
711 long session_timeout;
712
713 /* If this callback is not null, it will be called each
714 * time a session id is added to the cache. If this function
715 * returns 1, it means that the callback will do a
716 * SSL_SESSION_free() when it has finished using it. Otherwise,
717 * on 0, it means the callback has finished with it.
718 * If remove_session_cb is not null, it will be called when
719 * a session-id is removed from the cache. After the call,
720 * OpenSSL will SSL_SESSION_free() it. */
721 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
722 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
723 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
724 unsigned char *data, int len, int *copy);
725
726 struct {
727 int sess_connect; /* SSL new conn - started */
728 int sess_connect_renegotiate;/* SSL reneg - requested */
729 int sess_connect_good; /* SSL new conne/reneg - finished */
730 int sess_accept; /* SSL new accept - started */
731 int sess_accept_renegotiate;/* SSL reneg - requested */
732 int sess_accept_good; /* SSL accept/reneg - finished */
733 int sess_miss; /* session lookup misses */
734 int sess_timeout; /* reuse attempt on timeouted session */
735 int sess_cache_full; /* session removed due to full cache */
736 int sess_hit; /* session reuse actually done */
737 int sess_cb_hit; /* session-id that was not
738 * in the cache was
739 * passed back via the callback. This
740 * indicates that the application is
741 * supplying session-id's from other
742 * processes - spooky :-) */
743 } stats;
744
745 int references;
746
747 /* if defined, these override the X509_verify_cert() calls */
748 int (*app_verify_callback)(X509_STORE_CTX *, void *);
749 void *app_verify_arg;
750
751 /* Default password callback. */
752 pem_password_cb *default_passwd_callback;
753
754 /* Default password callback user data. */
755 void *default_passwd_callback_userdata;
756
757 /* get client cert callback */
758 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
759
760 /* cookie generate callback */
761 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
762 unsigned int *cookie_len);
763
764 /* verify cookie callback */
765 int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie,
766 unsigned int cookie_len);
767
768 CRYPTO_EX_DATA ex_data;
769
770 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
771 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3-sha1' */
772
773 STACK_OF(X509) *extra_certs;
774
775 /* Default values used when no per-SSL value is defined follow */
776
777 void (*info_callback)(const SSL *ssl,int type,int val); /* used if SSL's info_callback is NULL */
778
779 /* what we put in client cert requests */
780 STACK_OF(X509_NAME) *client_CA;
781
782
783 /* Default values to use in SSL structures follow (these are copied by SSL_new) */
784
785 unsigned long options;
786 unsigned long mode;
787 long max_cert_list;
788
789 struct cert_st /* CERT */ *cert;
790 int read_ahead;
791
792 /* callback that allows applications to peek at protocol messages */
793 void (*msg_callback)(int write_p, int version, int content_type,
794 const void *buf, size_t len, SSL *ssl, void *arg);
795 void *msg_callback_arg;
796
797 int verify_mode;
798 unsigned int sid_ctx_length;
799 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
800 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
801
802 /* Default generate session ID callback. */
803 GEN_SESSION_CB generate_session_id;
804
805 X509_VERIFY_PARAM *param;
806
807 int quiet_shutdown;
808
809 /* Maximum amount of data to send in one fragment.
810 * actual record size can be more than this due to
811 * padding and MAC overheads.
812 */
813 unsigned int max_send_fragment;
814
815#ifndef OPENSSL_NO_ENGINE
816 /* Engine to pass requests for client certs to
817 */
818 ENGINE *client_cert_engine;
819#endif
820
821 /* TLS extensions servername callback */
822 int (*tlsext_servername_callback)(SSL*, int *, void *);
823 void *tlsext_servername_arg;
824 /* RFC 4507 session ticket keys */
825 unsigned char tlsext_tick_key_name[16];
826 unsigned char tlsext_tick_hmac_key[16];
827 unsigned char tlsext_tick_aes_key[16];
828 /* Callback to support customisation of ticket key setting */
829 int (*tlsext_ticket_key_cb)(SSL *ssl, unsigned char *name,
830 unsigned char *iv, EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
831
832 /* certificate status request info */
833 /* Callback for status request */
834 int (*tlsext_status_cb)(SSL *ssl, void *arg);
835 void *tlsext_status_arg;
836
837
838
839
840 /* Next protocol negotiation information */
841 /* (for experimental NPN extension). */
842
843 /* For a server, this contains a callback function by which the set of
844 * advertised protocols can be provided. */
845 int (*next_protos_advertised_cb)(SSL *s, const unsigned char **buf,
846 unsigned int *len, void *arg);
847 void *next_protos_advertised_cb_arg;
848 /* For a client, this contains a callback function that selects the
849 * next protocol from the list provided by the server. */
850 int (*next_proto_select_cb)(SSL *s, unsigned char **out,
851 unsigned char *outlen, const unsigned char *in,
852 unsigned int inlen, void *arg);
853 void *next_proto_select_cb_arg;
854
855 /*
856 * ALPN information
857 * (we are in the process of transitioning from NPN to ALPN).
858 */
859
860 /*
861 * Server callback function that allows the server to select the
862 * protocol for the connection.
863 * out: on successful return, this must point to the raw protocol
864 * name (without the length prefix).
865 * outlen: on successful return, this contains the length of out.
866 * in: points to the client's list of supported protocols in
867 * wire-format.
868 * inlen: the length of in.
869 */
870 int (*alpn_select_cb)(SSL *s, const unsigned char **out,
871 unsigned char *outlen, const unsigned char *in, unsigned int inlen,
872 void *arg);
873 void *alpn_select_cb_arg;
874
875 /* Client list of supported protocols in wire format. */
876 unsigned char *alpn_client_proto_list;
877 unsigned int alpn_client_proto_list_len;
878
879 /* SRTP profiles we are willing to do from RFC 5764 */
880 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
881};
882
883#endif
884
885#define SSL_SESS_CACHE_OFF 0x0000
886#define SSL_SESS_CACHE_CLIENT 0x0001
887#define SSL_SESS_CACHE_SERVER 0x0002
888#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
889#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
890/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
891#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
892#define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200
893#define SSL_SESS_CACHE_NO_INTERNAL \
894 (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
895
896LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx);
897#define SSL_CTX_sess_number(ctx) \
898 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
899#define SSL_CTX_sess_connect(ctx) \
900 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
901#define SSL_CTX_sess_connect_good(ctx) \
902 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
903#define SSL_CTX_sess_connect_renegotiate(ctx) \
904 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
905#define SSL_CTX_sess_accept(ctx) \
906 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
907#define SSL_CTX_sess_accept_renegotiate(ctx) \
908 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
909#define SSL_CTX_sess_accept_good(ctx) \
910 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
911#define SSL_CTX_sess_hits(ctx) \
912 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
913#define SSL_CTX_sess_cb_hits(ctx) \
914 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
915#define SSL_CTX_sess_misses(ctx) \
916 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
917#define SSL_CTX_sess_timeouts(ctx) \
918 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
919#define SSL_CTX_sess_cache_full(ctx) \
920 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
921
922void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
923 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess));
924int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
925 SSL_SESSION *sess);
926void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
927 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess));
928void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx,
929 SSL_SESSION *sess);
930void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
931 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl, unsigned char *data,
932 int len, int *copy));
933SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
934 unsigned char *Data, int len, int *copy);
935void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*cb)(const SSL *ssl,
936 int type, int val));
937void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl, int type,
938 int val);
939void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
940 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
941int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509,
942 EVP_PKEY **pkey);
943#ifndef OPENSSL_NO_ENGINE
944int SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e);
945#endif
946void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
947 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
948 unsigned int *cookie_len));
949void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
950 int (*app_verify_cookie_cb)(SSL *ssl, unsigned char *cookie,
951 unsigned int cookie_len));
952void
953SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, int (*cb)(SSL *ssl,
954 const unsigned char **out, unsigned int *outlen, void *arg), void *arg);
955void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, int (*cb)(SSL *ssl,
956 unsigned char **out, unsigned char *outlen, const unsigned char *in,
957 unsigned int inlen, void *arg), void *arg);
958
959int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
960 const unsigned char *in, unsigned int inlen, const unsigned char *client,
961 unsigned int client_len);
962void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
963 unsigned *len);
964
965#define OPENSSL_NPN_UNSUPPORTED 0
966#define OPENSSL_NPN_NEGOTIATED 1
967#define OPENSSL_NPN_NO_OVERLAP 2
968
969int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
970 unsigned int protos_len);
971int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
972 unsigned int protos_len);
973void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
974 int (*cb)(SSL *ssl, const unsigned char **out, unsigned char *outlen,
975 const unsigned char *in, unsigned int inlen, void *arg), void *arg);
976void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
977 unsigned int *len);
978
979#define SSL_NOTHING 1
980#define SSL_WRITING 2
981#define SSL_READING 3
982#define SSL_X509_LOOKUP 4
983
984/* These will only be used when doing non-blocking IO */
985#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
986#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
987#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
988#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
989
990#define SSL_MAC_FLAG_READ_MAC_STREAM 1
991#define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
992
993#ifndef OPENSSL_NO_SSL_INTERN
994
995struct ssl_st {
996 /* protocol version
997 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION)
998 */
999 int version;
1000 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
1001
1002 const SSL_METHOD *method; /* SSLv3 */
1003
1004 /* There are 2 BIO's even though they are normally both the
1005 * same. This is so data can be read and written to different
1006 * handlers */
1007
1008#ifndef OPENSSL_NO_BIO
1009 BIO *rbio; /* used by SSL_read */
1010 BIO *wbio; /* used by SSL_write */
1011 BIO *bbio; /* used during session-id reuse to concatenate
1012 * messages */
1013#else
1014 char *rbio; /* used by SSL_read */
1015 char *wbio; /* used by SSL_write */
1016 char *bbio;
1017#endif
1018 /* This holds a variable that indicates what we were doing
1019 * when a 0 or -1 is returned. This is needed for
1020 * non-blocking IO so we know what request needs re-doing when
1021 * in SSL_accept or SSL_connect */
1022 int rwstate;
1023
1024 /* true when we are actually in SSL_accept() or SSL_connect() */
1025 int in_handshake;
1026 int (*handshake_func)(SSL *);
1027
1028 /* Imagine that here's a boolean member "init" that is
1029 * switched as soon as SSL_set_{accept/connect}_state
1030 * is called for the first time, so that "state" and
1031 * "handshake_func" are properly initialized. But as
1032 * handshake_func is == 0 until then, we use this
1033 * test instead of an "init" member.
1034 */
1035
1036 int server; /* are we the server side? - mostly used by SSL_clear*/
1037
1038 int new_session;/* Generate a new session or reuse an old one.
1039 * NB: For servers, the 'new' session may actually be a previously
1040 * cached session or even the previous session unless
1041 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
1042 int quiet_shutdown;/* don't send shutdown packets */
1043 int shutdown; /* we have shut things down, 0x01 sent, 0x02
1044 * for received */
1045 int state; /* where we are */
1046 int rstate; /* where we are when reading */
1047
1048 BUF_MEM *init_buf; /* buffer used during init */
1049 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
1050 int init_num; /* amount read/written */
1051 int init_off; /* amount read/written */
1052
1053 /* used internally to point at a raw packet */
1054 unsigned char *packet;
1055 unsigned int packet_length;
1056
1057 struct ssl3_state_st *s3; /* SSLv3 variables */
1058 struct dtls1_state_st *d1; /* DTLSv1 variables */
1059
1060 int read_ahead; /* Read as many input bytes as possible
1061 * (for non-blocking reads) */
1062
1063 /* callback that allows applications to peek at protocol messages */
1064 void (*msg_callback)(int write_p, int version, int content_type,
1065 const void *buf, size_t len, SSL *ssl, void *arg);
1066 void *msg_callback_arg;
1067
1068 int hit; /* reusing a previous session */
1069
1070 X509_VERIFY_PARAM *param;
1071
1072 /* crypto */
1073 STACK_OF(SSL_CIPHER) *cipher_list;
1074 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
1075
1076 /* These are the ones being used, the ones in SSL_SESSION are
1077 * the ones to be 'copied' into these ones */
1078 int mac_flags;
1079
1080 SSL_AEAD_CTX *aead_read_ctx; /* AEAD context. If non-NULL, then
1081 enc_read_ctx and read_hash are
1082 ignored. */
1083
1084 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
1085 EVP_MD_CTX *read_hash; /* used for mac generation */
1086
1087 SSL_AEAD_CTX *aead_write_ctx; /* AEAD context. If non-NULL, then
1088 enc_write_ctx and write_hash are
1089 ignored. */
1090
1091 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
1092 EVP_MD_CTX *write_hash; /* used for mac generation */
1093
1094 /* session info */
1095
1096 /* client cert? */
1097 /* This is used to hold the server certificate used */
1098 struct cert_st /* CERT */ *cert;
1099
1100 /* the session_id_context is used to ensure sessions are only reused
1101 * in the appropriate context */
1102 unsigned int sid_ctx_length;
1103 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1104
1105 /* This can also be in the session once a session is established */
1106 SSL_SESSION *session;
1107
1108 /* Default generate session ID callback. */
1109 GEN_SESSION_CB generate_session_id;
1110
1111 /* Used in SSL2 and SSL3 */
1112 int verify_mode; /* 0 don't care about verify failure.
1113 * 1 fail if verify fails */
1114 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
1115
1116 void (*info_callback)(const SSL *ssl,int type,int val); /* optional informational callback */
1117
1118 int error; /* error bytes to be written */
1119 int error_code; /* actual code */
1120
1121
1122
1123 SSL_CTX *ctx;
1124 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
1125 * and SSL_write() calls, good for nbio debuging :-) */
1126 int debug;
1127
1128
1129 /* extra application data */
1130 long verify_result;
1131 CRYPTO_EX_DATA ex_data;
1132
1133 /* for server side, keep the list of CA_dn we can use */
1134 STACK_OF(X509_NAME) *client_CA;
1135
1136 int references;
1137 unsigned long options; /* protocol behaviour */
1138 unsigned long mode; /* API behaviour */
1139 long max_cert_list;
1140 int first_packet;
1141 int client_version; /* what was passed, used for
1142 * SSLv3/TLS rollback check */
1143 unsigned int max_send_fragment;
1144 /* TLS extension debug callback */
1145 void (*tlsext_debug_cb)(SSL *s, int client_server, int type,
1146 unsigned char *data, int len, void *arg);
1147 void *tlsext_debug_arg;
1148 char *tlsext_hostname;
1149 int servername_done; /* no further mod of servername
1150 0 : call the servername extension callback.
1151 1 : prepare 2, allow last ack just after in server callback.
1152 2 : don't call servername callback, no ack in server hello
1153 */
1154 /* certificate status request info */
1155 /* Status type or -1 if no status type */
1156 int tlsext_status_type;
1157 /* Expect OCSP CertificateStatus message */
1158 int tlsext_status_expected;
1159 /* OCSP status request only */
1160 STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids;
1161 X509_EXTENSIONS *tlsext_ocsp_exts;
1162 /* OCSP response received or to be sent */
1163 unsigned char *tlsext_ocsp_resp;
1164 int tlsext_ocsp_resplen;
1165
1166 /* RFC4507 session ticket expected to be received or sent */
1167 int tlsext_ticket_expected;
1168 size_t tlsext_ecpointformatlist_length;
1169 uint8_t *tlsext_ecpointformatlist; /* our list */
1170 size_t tlsext_ellipticcurvelist_length;
1171 uint16_t *tlsext_ellipticcurvelist; /* our list */
1172
1173 /* TLS Session Ticket extension override */
1174 TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
1175
1176 /* TLS Session Ticket extension callback */
1177 tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
1178 void *tls_session_ticket_ext_cb_arg;
1179
1180 /* TLS pre-shared secret session resumption */
1181 tls_session_secret_cb_fn tls_session_secret_cb;
1182 void *tls_session_secret_cb_arg;
1183
1184 SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
1185
1186 /* Next protocol negotiation. For the client, this is the protocol that
1187 * we sent in NextProtocol and is set when handling ServerHello
1188 * extensions.
1189 *
1190 * For a server, this is the client's selected_protocol from
1191 * NextProtocol and is set when handling the NextProtocol message,
1192 * before the Finished message. */
1193 unsigned char *next_proto_negotiated;
1194 unsigned char next_proto_negotiated_len;
1195
1196#define session_ctx initial_ctx
1197
1198 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles; /* What we'll do */
1199 SRTP_PROTECTION_PROFILE *srtp_profile; /* What's been chosen */
1200
1201 unsigned int tlsext_heartbeat; /* Is use of the Heartbeat extension negotiated?
1202 0: disabled
1203 1: enabled
1204 2: enabled, but not allowed to send Requests
1205 */
1206 unsigned int tlsext_hb_pending; /* Indicates if a HeartbeatRequest is in flight */
1207 unsigned int tlsext_hb_seq; /* HeartbeatRequest sequence number */
1208
1209 /* Client list of supported protocols in wire format. */
1210 unsigned char *alpn_client_proto_list;
1211 unsigned int alpn_client_proto_list_len;
1212
1213 int renegotiate;/* 1 if we are renegotiating.
1214 * 2 if we are a server and are inside a handshake
1215 * (i.e. not just sending a HelloRequest) */
1216
1217};
1218
1219#endif
1220
1221#ifdef __cplusplus
1222}
1223#endif
1224
1225#include <openssl/ssl2.h>
1226#include <openssl/ssl3.h>
1227#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
1228#include <openssl/dtls1.h> /* Datagram TLS */
1229#include <openssl/ssl23.h>
1230#include <openssl/srtp.h> /* Support for the use_srtp extension */
1231
1232#ifdef __cplusplus
1233extern "C" {
1234#endif
1235
1236/* compatibility */
1237#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
1238#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
1239#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
1240#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
1241#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
1242#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
1243
1244/* The following are the possible values for ssl->state are are
1245 * used to indicate where we are up to in the SSL connection establishment.
1246 * The macros that follow are about the only things you should need to use
1247 * and even then, only when using non-blocking IO.
1248 * It can also be useful to work out where you were when the connection
1249 * failed */
1250
1251#define SSL_ST_CONNECT 0x1000
1252#define SSL_ST_ACCEPT 0x2000
1253#define SSL_ST_MASK 0x0FFF
1254#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
1255#define SSL_ST_BEFORE 0x4000
1256#define SSL_ST_OK 0x03
1257#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
1258
1259#define SSL_CB_LOOP 0x01
1260#define SSL_CB_EXIT 0x02
1261#define SSL_CB_READ 0x04
1262#define SSL_CB_WRITE 0x08
1263#define SSL_CB_ALERT 0x4000 /* used in callback */
1264#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
1265#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
1266#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
1267#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
1268#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
1269#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
1270#define SSL_CB_HANDSHAKE_START 0x10
1271#define SSL_CB_HANDSHAKE_DONE 0x20
1272
1273/* Is the SSL_connection established? */
1274#define SSL_get_state(a) SSL_state(a)
1275#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
1276#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
1277#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
1278#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
1279#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
1280
1281/* The following 2 states are kept in ssl->rstate when reads fail,
1282 * you should not need these */
1283#define SSL_ST_READ_HEADER 0xF0
1284#define SSL_ST_READ_BODY 0xF1
1285#define SSL_ST_READ_DONE 0xF2
1286
1287/* Obtain latest Finished message
1288 * -- that we sent (SSL_get_finished)
1289 * -- that we expected from peer (SSL_get_peer_finished).
1290 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
1291size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
1292size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
1293
1294/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
1295 * are 'ored' with SSL_VERIFY_PEER if they are desired */
1296#define SSL_VERIFY_NONE 0x00
1297#define SSL_VERIFY_PEER 0x01
1298#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
1299#define SSL_VERIFY_CLIENT_ONCE 0x04
1300
1301#define OpenSSL_add_ssl_algorithms() SSL_library_init()
1302#define SSLeay_add_ssl_algorithms() SSL_library_init()
1303
1304/* More backward compatibility */
1305#define SSL_get_cipher(s) \
1306 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1307#define SSL_get_cipher_bits(s,np) \
1308 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
1309#define SSL_get_cipher_version(s) \
1310 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
1311#define SSL_get_cipher_name(s) \
1312 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
1313#define SSL_get_time(a) SSL_SESSION_get_time(a)
1314#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
1315#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
1316#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
1317
1318#define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
1319#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)
1320
1321DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
1322
1323#define SSL_AD_REASON_OFFSET 1000 /* offset to get SSL_R_... value from SSL_AD_... */
1324
1325/* These alert types are for SSLv3 and TLSv1 */
1326#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
1327#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
1328#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
1329#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
1330#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
1331#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
1332#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
1333#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
1334#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
1335#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
1336#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
1337#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
1338#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
1339#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
1340#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
1341#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
1342#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
1343#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
1344#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
1345#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
1346#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
1347#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
1348#define SSL_AD_INAPPROPRIATE_FALLBACK TLS1_AD_INAPPROPRIATE_FALLBACK /* fatal */
1349#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
1350#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
1351#define SSL_AD_UNSUPPORTED_EXTENSION TLS1_AD_UNSUPPORTED_EXTENSION
1352#define SSL_AD_CERTIFICATE_UNOBTAINABLE TLS1_AD_CERTIFICATE_UNOBTAINABLE
1353#define SSL_AD_UNRECOGNIZED_NAME TLS1_AD_UNRECOGNIZED_NAME
1354#define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE
1355#define SSL_AD_BAD_CERTIFICATE_HASH_VALUE TLS1_AD_BAD_CERTIFICATE_HASH_VALUE
1356#define SSL_AD_UNKNOWN_PSK_IDENTITY TLS1_AD_UNKNOWN_PSK_IDENTITY /* fatal */
1357
1358#define SSL_ERROR_NONE 0
1359#define SSL_ERROR_SSL 1
1360#define SSL_ERROR_WANT_READ 2
1361#define SSL_ERROR_WANT_WRITE 3
1362#define SSL_ERROR_WANT_X509_LOOKUP 4
1363#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
1364#define SSL_ERROR_ZERO_RETURN 6
1365#define SSL_ERROR_WANT_CONNECT 7
1366#define SSL_ERROR_WANT_ACCEPT 8
1367
1368#define SSL_CTRL_NEED_TMP_RSA 1
1369#define SSL_CTRL_SET_TMP_RSA 2
1370#define SSL_CTRL_SET_TMP_DH 3
1371#define SSL_CTRL_SET_TMP_ECDH 4
1372#define SSL_CTRL_SET_TMP_RSA_CB 5
1373#define SSL_CTRL_SET_TMP_DH_CB 6
1374#define SSL_CTRL_SET_TMP_ECDH_CB 7
1375
1376#define SSL_CTRL_GET_SESSION_REUSED 8
1377#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9
1378#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10
1379#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11
1380#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12
1381#define SSL_CTRL_GET_FLAGS 13
1382#define SSL_CTRL_EXTRA_CHAIN_CERT 14
1383
1384#define SSL_CTRL_SET_MSG_CALLBACK 15
1385#define SSL_CTRL_SET_MSG_CALLBACK_ARG 16
1386
1387/* only applies to datagram connections */
1388#define SSL_CTRL_SET_MTU 17
1389/* Stats */
1390#define SSL_CTRL_SESS_NUMBER 20
1391#define SSL_CTRL_SESS_CONNECT 21
1392#define SSL_CTRL_SESS_CONNECT_GOOD 22
1393#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
1394#define SSL_CTRL_SESS_ACCEPT 24
1395#define SSL_CTRL_SESS_ACCEPT_GOOD 25
1396#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
1397#define SSL_CTRL_SESS_HIT 27
1398#define SSL_CTRL_SESS_CB_HIT 28
1399#define SSL_CTRL_SESS_MISSES 29
1400#define SSL_CTRL_SESS_TIMEOUTS 30
1401#define SSL_CTRL_SESS_CACHE_FULL 31
1402#define SSL_CTRL_OPTIONS 32
1403#define SSL_CTRL_MODE 33
1404
1405#define SSL_CTRL_GET_READ_AHEAD 40
1406#define SSL_CTRL_SET_READ_AHEAD 41
1407#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
1408#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
1409#define SSL_CTRL_SET_SESS_CACHE_MODE 44
1410#define SSL_CTRL_GET_SESS_CACHE_MODE 45
1411
1412#define SSL_CTRL_GET_MAX_CERT_LIST 50
1413#define SSL_CTRL_SET_MAX_CERT_LIST 51
1414
1415#define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52
1416
1417/* see tls1.h for macros based on these */
1418#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53
1419#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54
1420#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
1421#define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56
1422#define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57
1423#define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58
1424#define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59
1425#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63
1426#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64
1427#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65
1428#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66
1429#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67
1430#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68
1431#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69
1432#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70
1433#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71
1434
1435#define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72
1436
1437#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75
1438#define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76
1439#define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77
1440
1441#define SSL_CTRL_SET_SRP_ARG 78
1442#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79
1443#define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80
1444#define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81
1445
1446#define DTLS_CTRL_GET_TIMEOUT 73
1447#define DTLS_CTRL_HANDLE_TIMEOUT 74
1448#define DTLS_CTRL_LISTEN 75
1449
1450#define SSL_CTRL_GET_RI_SUPPORT 76
1451#define SSL_CTRL_CLEAR_OPTIONS 77
1452#define SSL_CTRL_CLEAR_MODE 78
1453
1454#define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82
1455#define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83
1456
1457#define SSL_CTRL_SET_ECDH_AUTO 94
1458
1459#define SSL_CTRL_SET_DH_AUTO 118
1460
1461#define DTLSv1_get_timeout(ssl, arg) \
1462 SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg)
1463#define DTLSv1_handle_timeout(ssl) \
1464 SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
1465#define DTLSv1_listen(ssl, peer) \
1466 SSL_ctrl(ssl,DTLS_CTRL_LISTEN,0, (void *)peer)
1467
1468#define SSL_session_reused(ssl) \
1469 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
1470#define SSL_num_renegotiations(ssl) \
1471 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
1472#define SSL_clear_num_renegotiations(ssl) \
1473 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
1474#define SSL_total_renegotiations(ssl) \
1475 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
1476
1477#define SSL_CTX_need_tmp_RSA(ctx) \
1478 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1479#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
1480 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1481#define SSL_CTX_set_tmp_dh(ctx,dh) \
1482 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1483#define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
1484 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)
1485#define SSL_CTX_set_dh_auto(ctx, onoff) \
1486 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
1487#define SSL_CTX_set_ecdh_auto(ctx, onoff) \
1488 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_ECDH_AUTO,onoff,NULL)
1489
1490#define SSL_need_tmp_RSA(ssl) \
1491 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
1492#define SSL_set_tmp_rsa(ssl,rsa) \
1493 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
1494#define SSL_set_tmp_dh(ssl,dh) \
1495 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
1496#define SSL_set_tmp_ecdh(ssl,ecdh) \
1497 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)
1498#define SSL_set_dh_auto(s, onoff) \
1499 SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
1500#define SSL_set_ecdh_auto(s, onoff) \
1501 SSL_ctrl(s,SSL_CTRL_SET_ECDH_AUTO,onoff,NULL)
1502
1503#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
1504 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
1505#define SSL_CTX_get_extra_chain_certs(ctx,px509) \
1506 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_EXTRA_CHAIN_CERTS,0,px509)
1507#define SSL_CTX_clear_extra_chain_certs(ctx) \
1508 SSL_CTX_ctrl(ctx,SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS,0,NULL)
1509
1510#ifndef OPENSSL_NO_BIO
1511BIO_METHOD *BIO_f_ssl(void);
1512BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
1513BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
1514BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
1515int BIO_ssl_copy_session_id(BIO *to, BIO *from);
1516void BIO_ssl_shutdown(BIO *ssl_bio);
1517#endif
1518
1519int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
1520SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
1521void SSL_CTX_free(SSL_CTX *);
1522long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
1523long SSL_CTX_get_timeout(const SSL_CTX *ctx);
1524X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
1525void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
1526int SSL_want(const SSL *s);
1527int SSL_clear(SSL *s);
1528
1529void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);
1530
1531const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
1532const SSL_CIPHER *SSL_CIPHER_get_by_id(unsigned int id);
1533const SSL_CIPHER *SSL_CIPHER_get_by_value(uint16_t value);
1534int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
1535char * SSL_CIPHER_get_version(const SSL_CIPHER *c);
1536const char * SSL_CIPHER_get_name(const SSL_CIPHER *c);
1537unsigned long SSL_CIPHER_get_id(const SSL_CIPHER *c);
1538uint16_t SSL_CIPHER_get_value(const SSL_CIPHER *c);
1539
1540int SSL_get_fd(const SSL *s);
1541int SSL_get_rfd(const SSL *s);
1542int SSL_get_wfd(const SSL *s);
1543const char * SSL_get_cipher_list(const SSL *s, int n);
1544char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len);
1545int SSL_get_read_ahead(const SSL * s);
1546int SSL_pending(const SSL *s);
1547int SSL_set_fd(SSL *s, int fd);
1548int SSL_set_rfd(SSL *s, int fd);
1549int SSL_set_wfd(SSL *s, int fd);
1550#ifndef OPENSSL_NO_BIO
1551void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
1552BIO * SSL_get_rbio(const SSL *s);
1553BIO * SSL_get_wbio(const SSL *s);
1554#endif
1555int SSL_set_cipher_list(SSL *s, const char *str);
1556void SSL_set_read_ahead(SSL *s, int yes);
1557int SSL_get_verify_mode(const SSL *s);
1558int SSL_get_verify_depth(const SSL *s);
1559int (*SSL_get_verify_callback(const SSL *s))(int, X509_STORE_CTX *);
1560void SSL_set_verify(SSL *s, int mode,
1561 int (*callback)(int ok, X509_STORE_CTX *ctx));
1562void SSL_set_verify_depth(SSL *s, int depth);
1563int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
1564int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
1565int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
1566int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, long len);
1567int SSL_use_certificate(SSL *ssl, X509 *x);
1568int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
1569
1570int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
1571int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
1572int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
1573int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1574int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1575int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
1576int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
1577int SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len);
1578STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
1579int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1580 const char *file);
1581int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1582 const char *dir);
1583
1584void SSL_load_error_strings(void );
1585const char *SSL_state_string(const SSL *s);
1586const char *SSL_rstate_string(const SSL *s);
1587const char *SSL_state_string_long(const SSL *s);
1588const char *SSL_rstate_string_long(const SSL *s);
1589long SSL_SESSION_get_time(const SSL_SESSION *s);
1590long SSL_SESSION_set_time(SSL_SESSION *s, long t);
1591long SSL_SESSION_get_timeout(const SSL_SESSION *s);
1592long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
1593void SSL_copy_session_id(SSL *to, const SSL *from);
1594X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
1595int
1596SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
1597unsigned int sid_ctx_len);
1598
1599SSL_SESSION *SSL_SESSION_new(void);
1600const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s,
1601 unsigned int *len);
1602unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *s);
1603int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
1604#ifndef OPENSSL_NO_BIO
1605int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
1606#endif
1607void SSL_SESSION_free(SSL_SESSION *ses);
1608int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
1609int SSL_set_session(SSL *to, SSL_SESSION *session);
1610int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
1611int SSL_CTX_remove_session(SSL_CTX *, SSL_SESSION *c);
1612int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
1613int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB);
1614int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
1615 unsigned int id_len);
1616SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
1617 long length);
1618
1619#ifdef HEADER_X509_H
1620X509 * SSL_get_peer_certificate(const SSL *s);
1621#endif
1622
1623STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);
1624
1625int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
1626int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
1627int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *);
1628void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
1629 int (*callback)(int, X509_STORE_CTX *));
1630void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
1631void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *, void *), void *arg);
1632int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1633int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);
1634int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1635int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, const unsigned char *d, long len);
1636int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1637int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);
1638
1639void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1640void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1641
1642int SSL_CTX_check_private_key(const SSL_CTX *ctx);
1643int SSL_check_private_key(const SSL *ctx);
1644
1645int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx, unsigned int sid_ctx_len);
1646
1647SSL *SSL_new(SSL_CTX *ctx);
1648int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx, unsigned int sid_ctx_len);
1649
1650int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1651int SSL_set_purpose(SSL *s, int purpose);
1652int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1653int SSL_set_trust(SSL *s, int trust);
1654
1655int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
1656int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);
1657
1658
1659void SSL_free(SSL *ssl);
1660int SSL_accept(SSL *ssl);
1661int SSL_connect(SSL *ssl);
1662int SSL_read(SSL *ssl, void *buf, int num);
1663int SSL_peek(SSL *ssl, void *buf, int num);
1664int SSL_write(SSL *ssl, const void *buf, int num);
1665long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
1666long SSL_callback_ctrl(SSL *, int, void (*)(void));
1667long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
1668long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));
1669
1670int SSL_get_error(const SSL *s, int ret_code);
1671const char *SSL_get_version(const SSL *s);
1672
1673/* This sets the 'default' SSL version that SSL_new() will create */
1674int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
1675
1676const SSL_METHOD *SSLv23_method(void); /* SSLv3 or TLSv1.* */
1677const SSL_METHOD *SSLv23_server_method(void); /* SSLv3 or TLSv1.* */
1678const SSL_METHOD *SSLv23_client_method(void); /* SSLv3 or TLSv1.* */
1679
1680const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1681const SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1682const SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1683
1684const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
1685const SSL_METHOD *TLSv1_1_server_method(void); /* TLSv1.1 */
1686const SSL_METHOD *TLSv1_1_client_method(void); /* TLSv1.1 */
1687
1688const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
1689const SSL_METHOD *TLSv1_2_server_method(void); /* TLSv1.2 */
1690const SSL_METHOD *TLSv1_2_client_method(void); /* TLSv1.2 */
1691
1692const SSL_METHOD *TLS_method(void); /* TLS v1.0 or later */
1693const SSL_METHOD *TLS_server_method(void); /* TLS v1.0 or later */
1694const SSL_METHOD *TLS_client_method(void); /* TLS v1.0 or later */
1695
1696const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
1697const SSL_METHOD *DTLSv1_server_method(void); /* DTLSv1.0 */
1698const SSL_METHOD *DTLSv1_client_method(void); /* DTLSv1.0 */
1699
1700STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
1701
1702int SSL_do_handshake(SSL *s);
1703int SSL_renegotiate(SSL *s);
1704int SSL_renegotiate_abbreviated(SSL *s);
1705int SSL_renegotiate_pending(SSL *s);
1706int SSL_shutdown(SSL *s);
1707
1708const SSL_METHOD *SSL_get_ssl_method(SSL *s);
1709int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
1710const char *SSL_alert_type_string_long(int value);
1711const char *SSL_alert_type_string(int value);
1712const char *SSL_alert_desc_string_long(int value);
1713const char *SSL_alert_desc_string(int value);
1714
1715void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
1716void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
1717STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
1718STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
1719int SSL_add_client_CA(SSL *ssl, X509 *x);
1720int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
1721
1722void SSL_set_connect_state(SSL *s);
1723void SSL_set_accept_state(SSL *s);
1724
1725long SSL_get_default_timeout(const SSL *s);
1726
1727int SSL_library_init(void );
1728
1729char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
1730STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1731
1732SSL *SSL_dup(SSL *ssl);
1733
1734X509 *SSL_get_certificate(const SSL *ssl);
1735/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1736
1737void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1738int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
1739void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1740int SSL_get_quiet_shutdown(const SSL *ssl);
1741void SSL_set_shutdown(SSL *ssl,int mode);
1742int SSL_get_shutdown(const SSL *ssl);
1743int SSL_version(const SSL *ssl);
1744int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1745int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1746 const char *CApath);
1747int SSL_CTX_load_verify_mem(SSL_CTX *ctx, void *buf, int len);
1748#define SSL_get0_session SSL_get_session /* just peek at pointer */
1749SSL_SESSION *SSL_get_session(const SSL *ssl);
1750SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1751SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
1752SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx);
1753void SSL_set_info_callback(SSL *ssl,
1754 void (*cb)(const SSL *ssl, int type, int val));
1755void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type, int val);
1756int SSL_state(const SSL *ssl);
1757void SSL_set_state(SSL *ssl, int state);
1758
1759void SSL_set_verify_result(SSL *ssl, long v);
1760long SSL_get_verify_result(const SSL *ssl);
1761
1762int SSL_set_ex_data(SSL *ssl, int idx, void *data);
1763void *SSL_get_ex_data(const SSL *ssl, int idx);
1764int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1765 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1766
1767int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
1768void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
1769int SSL_SESSION_get_ex_new_index(long argl, void *argp,
1770 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
1771 CRYPTO_EX_free *free_func);
1772
1773int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
1774void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);
1775int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1776 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1777
1778int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1779
1780#define SSL_CTX_sess_set_cache_size(ctx,t) \
1781 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1782#define SSL_CTX_sess_get_cache_size(ctx) \
1783 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1784#define SSL_CTX_set_session_cache_mode(ctx,m) \
1785 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1786#define SSL_CTX_get_session_cache_mode(ctx) \
1787 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1788
1789#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1790#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1791#define SSL_CTX_get_read_ahead(ctx) \
1792 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1793#define SSL_CTX_set_read_ahead(ctx,m) \
1794 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
1795#define SSL_CTX_get_max_cert_list(ctx) \
1796 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1797#define SSL_CTX_set_max_cert_list(ctx,m) \
1798 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1799#define SSL_get_max_cert_list(ssl) \
1800 SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1801#define SSL_set_max_cert_list(ssl,m) \
1802 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1803
1804#define SSL_CTX_set_max_send_fragment(ctx,m) \
1805 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
1806#define SSL_set_max_send_fragment(ssl,m) \
1807 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
1808
1809/* NB: the keylength is only applicable when is_export is true */
1810void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1811 RSA *(*cb)(SSL *ssl, int is_export, int keylength));
1812
1813void SSL_set_tmp_rsa_callback(SSL *ssl,
1814 RSA *(*cb)(SSL *ssl, int is_export, int keylength));
1815void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1816 DH *(*dh)(SSL *ssl, int is_export, int keylength));
1817void SSL_set_tmp_dh_callback(SSL *ssl,
1818 DH *(*dh)(SSL *ssl, int is_export, int keylength));
1819void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,
1820 EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength));
1821void SSL_set_tmp_ecdh_callback(SSL *ssl,
1822 EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength));
1823
1824const void *SSL_get_current_compression(SSL *s);
1825const void *SSL_get_current_expansion(SSL *s);
1826
1827const char *SSL_COMP_get_name(const void *comp);
1828void *SSL_COMP_get_compression_methods(void);
1829int SSL_COMP_add_compression_method(int id, void *cm);
1830
1831/* TLS extensions functions */
1832int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
1833
1834int SSL_set_session_ticket_ext_cb(SSL *s,
1835 tls_session_ticket_ext_cb_fn cb, void *arg);
1836
1837/* Pre-shared secret session resumption functions */
1838int SSL_set_session_secret_cb(SSL *s,
1839 tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
1840
1841void SSL_set_debug(SSL *s, int debug);
1842int SSL_cache_hit(SSL *s);
1843
1844/* BEGIN ERROR CODES */
1845/* The following lines are auto generated by the script mkerr.pl. Any changes
1846 * made after this point may be overwritten when the script is next run.
1847 */
1848void ERR_load_SSL_strings(void);
1849
1850/* Error codes for the SSL functions. */
1851
1852/* Function codes. */
1853#define SSL_F_CLIENT_CERTIFICATE 100
1854#define SSL_F_CLIENT_FINISHED 167
1855#define SSL_F_CLIENT_HELLO 101
1856#define SSL_F_CLIENT_MASTER_KEY 102
1857#define SSL_F_D2I_SSL_SESSION 103
1858#define SSL_F_DO_DTLS1_WRITE 245
1859#define SSL_F_DO_SSL3_WRITE 104
1860#define SSL_F_DTLS1_ACCEPT 246
1861#define SSL_F_DTLS1_ADD_CERT_TO_BUF 295
1862#define SSL_F_DTLS1_BUFFER_RECORD 247
1863#define SSL_F_DTLS1_CHECK_TIMEOUT_NUM 316
1864#define SSL_F_DTLS1_CLIENT_HELLO 248
1865#define SSL_F_DTLS1_CONNECT 249
1866#define SSL_F_DTLS1_ENC 250
1867#define SSL_F_DTLS1_GET_HELLO_VERIFY 251
1868#define SSL_F_DTLS1_GET_MESSAGE 252
1869#define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT 253
1870#define SSL_F_DTLS1_GET_RECORD 254
1871#define SSL_F_DTLS1_HANDLE_TIMEOUT 297
1872#define SSL_F_DTLS1_HEARTBEAT 305
1873#define SSL_F_DTLS1_OUTPUT_CERT_CHAIN 255
1874#define SSL_F_DTLS1_PREPROCESS_FRAGMENT 288
1875#define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE 256
1876#define SSL_F_DTLS1_PROCESS_RECORD 257
1877#define SSL_F_DTLS1_READ_BYTES 258
1878#define SSL_F_DTLS1_READ_FAILED 259
1879#define SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST 260
1880#define SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE 261
1881#define SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE 262
1882#define SSL_F_DTLS1_SEND_CLIENT_VERIFY 263
1883#define SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST 264
1884#define SSL_F_DTLS1_SEND_SERVER_CERTIFICATE 265
1885#define SSL_F_DTLS1_SEND_SERVER_HELLO 266
1886#define SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE 267
1887#define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268
1888#define SSL_F_GET_CLIENT_FINISHED 105
1889#define SSL_F_GET_CLIENT_HELLO 106
1890#define SSL_F_GET_CLIENT_MASTER_KEY 107
1891#define SSL_F_GET_SERVER_FINISHED 108
1892#define SSL_F_GET_SERVER_HELLO 109
1893#define SSL_F_GET_SERVER_VERIFY 110
1894#define SSL_F_I2D_SSL_SESSION 111
1895#define SSL_F_READ_N 112
1896#define SSL_F_REQUEST_CERTIFICATE 113
1897#define SSL_F_SERVER_FINISH 239
1898#define SSL_F_SERVER_HELLO 114
1899#define SSL_F_SERVER_VERIFY 240
1900#define SSL_F_SSL23_ACCEPT 115
1901#define SSL_F_SSL23_CLIENT_HELLO 116
1902#define SSL_F_SSL23_CONNECT 117
1903#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1904#define SSL_F_SSL23_GET_SERVER_HELLO 119
1905#define SSL_F_SSL23_PEEK 237
1906#define SSL_F_SSL23_READ 120
1907#define SSL_F_SSL23_WRITE 121
1908#define SSL_F_SSL2_ACCEPT 122
1909#define SSL_F_SSL2_CONNECT 123
1910#define SSL_F_SSL2_ENC_INIT 124
1911#define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241
1912#define SSL_F_SSL2_PEEK 234
1913#define SSL_F_SSL2_READ 125
1914#define SSL_F_SSL2_READ_INTERNAL 236
1915#define SSL_F_SSL2_SET_CERTIFICATE 126
1916#define SSL_F_SSL2_WRITE 127
1917#define SSL_F_SSL3_ACCEPT 128
1918#define SSL_F_SSL3_ADD_CERT_TO_BUF 296
1919#define SSL_F_SSL3_CALLBACK_CTRL 233
1920#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1921#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1922#define SSL_F_SSL3_CHECK_CLIENT_HELLO 304
1923#define SSL_F_SSL3_CLIENT_HELLO 131
1924#define SSL_F_SSL3_CONNECT 132
1925#define SSL_F_SSL3_CTRL 213
1926#define SSL_F_SSL3_CTX_CTRL 133
1927#define SSL_F_SSL3_DIGEST_CACHED_RECORDS 293
1928#define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC 292
1929#define SSL_F_SSL3_ENC 134
1930#define SSL_F_SSL3_GENERATE_KEY_BLOCK 238
1931#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1932#define SSL_F_SSL3_GET_CERT_STATUS 289
1933#define SSL_F_SSL3_GET_CERT_VERIFY 136
1934#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1935#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1936#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1937#define SSL_F_SSL3_GET_FINISHED 140
1938#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1939#define SSL_F_SSL3_GET_MESSAGE 142
1940#define SSL_F_SSL3_GET_NEW_SESSION_TICKET 283
1941#define SSL_F_SSL3_GET_NEXT_PROTO 306
1942#define SSL_F_SSL3_GET_RECORD 143
1943#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1944#define SSL_F_SSL3_GET_SERVER_DONE 145
1945#define SSL_F_SSL3_GET_SERVER_HELLO 146
1946#define SSL_F_SSL3_HANDSHAKE_MAC 285
1947#define SSL_F_SSL3_NEW_SESSION_TICKET 287
1948#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1949#define SSL_F_SSL3_PEEK 235
1950#define SSL_F_SSL3_READ_BYTES 148
1951#define SSL_F_SSL3_READ_N 149
1952#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1953#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1954#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1955#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1956#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1957#define SSL_F_SSL3_SEND_SERVER_HELLO 242
1958#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1959#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1960#define SSL_F_SSL3_SETUP_READ_BUFFER 156
1961#define SSL_F_SSL3_SETUP_WRITE_BUFFER 291
1962#define SSL_F_SSL3_WRITE_BYTES 158
1963#define SSL_F_SSL3_WRITE_PENDING 159
1964#define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT 298
1965#define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 277
1966#define SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT 307
1967#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1968#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1969#define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT 299
1970#define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 278
1971#define SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT 308
1972#define SSL_F_SSL_BAD_METHOD 160
1973#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1974#define SSL_F_SSL_CERT_DUP 221
1975#define SSL_F_SSL_CERT_INST 222
1976#define SSL_F_SSL_CERT_INSTANTIATE 214
1977#define SSL_F_SSL_CERT_NEW 162
1978#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1979#define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 280
1980#define SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG 279
1981#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1982#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1983#define SSL_F_SSL_CLEAR 164
1984#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1985#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1986#define SSL_F_SSL_CTRL 232
1987#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1988#define SSL_F_SSL_CTX_MAKE_PROFILES 309
1989#define SSL_F_SSL_CTX_NEW 169
1990#define SSL_F_SSL_CTX_SET_CIPHER_LIST 269
1991#define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE 290
1992#define SSL_F_SSL_CTX_SET_PURPOSE 226
1993#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1994#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1995#define SSL_F_SSL_CTX_SET_TRUST 229
1996#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1997#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1998#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1999#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
2000#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
2001#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
2002#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
2003#define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT 272
2004#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
2005#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
2006#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
2007#define SSL_F_SSL_DO_HANDSHAKE 180
2008#define SSL_F_SSL_GET_NEW_SESSION 181
2009#define SSL_F_SSL_GET_PREV_SESSION 217
2010#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
2011#define SSL_F_SSL_GET_SERVER_SEND_PKEY 317
2012#define SSL_F_SSL_GET_SIGN_PKEY 183
2013#define SSL_F_SSL_INIT_WBIO_BUFFER 184
2014#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
2015#define SSL_F_SSL_NEW 186
2016#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT 300
2017#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT 302
2018#define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT 310
2019#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT 301
2020#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT 303
2021#define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT 311
2022#define SSL_F_SSL_PEEK 270
2023#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT 281
2024#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT 282
2025#define SSL_F_SSL_READ 223
2026#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
2027#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
2028#define SSL_F_SSL_SESSION_NEW 189
2029#define SSL_F_SSL_SESSION_PRINT_FP 190
2030#define SSL_F_SSL_SESSION_SET1_ID_CONTEXT 312
2031#define SSL_F_SSL_SESS_CERT_NEW 225
2032#define SSL_F_SSL_SET_CERT 191
2033#define SSL_F_SSL_SET_CIPHER_LIST 271
2034#define SSL_F_SSL_SET_FD 192
2035#define SSL_F_SSL_SET_PKEY 193
2036#define SSL_F_SSL_SET_PURPOSE 227
2037#define SSL_F_SSL_SET_RFD 194
2038#define SSL_F_SSL_SET_SESSION 195
2039#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
2040#define SSL_F_SSL_SET_SESSION_TICKET_EXT 294
2041#define SSL_F_SSL_SET_TRUST 228
2042#define SSL_F_SSL_SET_WFD 196
2043#define SSL_F_SSL_SHUTDOWN 224
2044#define SSL_F_SSL_SRP_CTX_INIT 313
2045#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243
2046#define SSL_F_SSL_UNDEFINED_FUNCTION 197
2047#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244
2048#define SSL_F_SSL_USE_CERTIFICATE 198
2049#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
2050#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
2051#define SSL_F_SSL_USE_PRIVATEKEY 201
2052#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
2053#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
2054#define SSL_F_SSL_USE_PSK_IDENTITY_HINT 273
2055#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
2056#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
2057#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
2058#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
2059#define SSL_F_SSL_WRITE 208
2060#define SSL_F_TLS1_AEAD_CTX_INIT 339
2061#define SSL_F_TLS1_CERT_VERIFY_MAC 286
2062#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
2063#define SSL_F_TLS1_CHANGE_CIPHER_STATE_AEAD 340
2064#define SSL_F_TLS1_CHANGE_CIPHER_STATE_CIPHER 338
2065#define SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT 274
2066#define SSL_F_TLS1_ENC 210
2067#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL 314
2068#define SSL_F_TLS1_HEARTBEAT 315
2069#define SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT 275
2070#define SSL_F_TLS1_PREPARE_SERVERHELLO_TLSEXT 276
2071#define SSL_F_TLS1_PRF 284
2072#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
2073#define SSL_F_WRITE_PENDING 212
2074
2075/* Reason codes. */
2076#define SSL_R_APP_DATA_IN_HANDSHAKE 100
2077#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
2078#define SSL_R_BAD_ALERT_RECORD 101
2079#define SSL_R_BAD_AUTHENTICATION_TYPE 102
2080#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
2081#define SSL_R_BAD_CHECKSUM 104
2082#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
2083#define SSL_R_BAD_DECOMPRESSION 107
2084#define SSL_R_BAD_DH_G_LENGTH 108
2085#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
2086#define SSL_R_BAD_DH_P_LENGTH 110
2087#define SSL_R_BAD_DIGEST_LENGTH 111
2088#define SSL_R_BAD_DSA_SIGNATURE 112
2089#define SSL_R_BAD_ECC_CERT 304
2090#define SSL_R_BAD_ECDSA_SIGNATURE 305
2091#define SSL_R_BAD_ECPOINT 306
2092#define SSL_R_BAD_HANDSHAKE_LENGTH 332
2093#define SSL_R_BAD_HELLO_REQUEST 105
2094#define SSL_R_BAD_LENGTH 271
2095#define SSL_R_BAD_MAC_DECODE 113
2096#define SSL_R_BAD_MAC_LENGTH 333
2097#define SSL_R_BAD_MESSAGE_TYPE 114
2098#define SSL_R_BAD_PACKET_LENGTH 115
2099#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
2100#define SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH 316
2101#define SSL_R_BAD_RESPONSE_ARGUMENT 117
2102#define SSL_R_BAD_RSA_DECRYPT 118
2103#define SSL_R_BAD_RSA_ENCRYPT 119
2104#define SSL_R_BAD_RSA_E_LENGTH 120
2105#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
2106#define SSL_R_BAD_RSA_SIGNATURE 122
2107#define SSL_R_BAD_SIGNATURE 123
2108#define SSL_R_BAD_SRP_A_LENGTH 347
2109#define SSL_R_BAD_SRP_B_LENGTH 348
2110#define SSL_R_BAD_SRP_G_LENGTH 349
2111#define SSL_R_BAD_SRP_N_LENGTH 350
2112#define SSL_R_BAD_SRP_S_LENGTH 351
2113#define SSL_R_BAD_SRTP_MKI_VALUE 352
2114#define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST 353
2115#define SSL_R_BAD_SSL_FILETYPE 124
2116#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
2117#define SSL_R_BAD_STATE 126
2118#define SSL_R_BAD_WRITE_RETRY 127
2119#define SSL_R_BIO_NOT_SET 128
2120#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
2121#define SSL_R_BN_LIB 130
2122#define SSL_R_CA_DN_LENGTH_MISMATCH 131
2123#define SSL_R_CA_DN_TOO_LONG 132
2124#define SSL_R_CCS_RECEIVED_EARLY 133
2125#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
2126#define SSL_R_CERT_LENGTH_MISMATCH 135
2127#define SSL_R_CHALLENGE_IS_DIFFERENT 136
2128#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
2129#define SSL_R_CIPHER_COMPRESSION_UNAVAILABLE 371
2130#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
2131#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
2132#define SSL_R_CLIENTHELLO_TLSEXT 226
2133#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
2134#define SSL_R_COMPRESSION_DISABLED 343
2135#define SSL_R_COMPRESSION_FAILURE 141
2136#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307
2137#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
2138#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
2139#define SSL_R_CONNECTION_TYPE_NOT_SET 144
2140#define SSL_R_COOKIE_MISMATCH 308
2141#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
2142#define SSL_R_DATA_LENGTH_TOO_LONG 146
2143#define SSL_R_DECRYPTION_FAILED 147
2144#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281
2145#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
2146#define SSL_R_DIGEST_CHECK_FAILED 149
2147#define SSL_R_DTLS_MESSAGE_TOO_BIG 334
2148#define SSL_R_DUPLICATE_COMPRESSION_ID 309
2149#define SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT 317
2150#define SSL_R_ECC_CERT_NOT_FOR_SIGNING 318
2151#define SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE 322
2152#define SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE 323
2153#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER 310
2154#define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST 354
2155#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
2156#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282
2157#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
2158#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
2159#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
2160#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
2161#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS 355
2162#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION 356
2163#define SSL_R_HTTPS_PROXY_REQUEST 155
2164#define SSL_R_HTTP_REQUEST 156
2165#define SSL_R_ILLEGAL_PADDING 283
2166#define SSL_R_INAPPROPRIATE_FALLBACK 373
2167#define SSL_R_INCONSISTENT_COMPRESSION 340
2168#define SSL_R_INVALID_CHALLENGE_LENGTH 158
2169#define SSL_R_INVALID_COMMAND 280
2170#define SSL_R_INVALID_COMPRESSION_ALGORITHM 341
2171#define SSL_R_INVALID_PURPOSE 278
2172#define SSL_R_INVALID_SRP_USERNAME 357
2173#define SSL_R_INVALID_STATUS_RESPONSE 328
2174#define SSL_R_INVALID_TICKET_KEYS_LENGTH 325
2175#define SSL_R_INVALID_TRUST 279
2176#define SSL_R_KEY_ARG_TOO_LONG 284
2177#define SSL_R_KRB5 285
2178#define SSL_R_KRB5_C_CC_PRINC 286
2179#define SSL_R_KRB5_C_GET_CRED 287
2180#define SSL_R_KRB5_C_INIT 288
2181#define SSL_R_KRB5_C_MK_REQ 289
2182#define SSL_R_KRB5_S_BAD_TICKET 290
2183#define SSL_R_KRB5_S_INIT 291
2184#define SSL_R_KRB5_S_RD_REQ 292
2185#define SSL_R_KRB5_S_TKT_EXPIRED 293
2186#define SSL_R_KRB5_S_TKT_NYV 294
2187#define SSL_R_KRB5_S_TKT_SKEW 295
2188#define SSL_R_LENGTH_MISMATCH 159
2189#define SSL_R_LENGTH_TOO_SHORT 160
2190#define SSL_R_LIBRARY_BUG 274
2191#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
2192#define SSL_R_MESSAGE_TOO_LONG 296
2193#define SSL_R_MISSING_DH_DSA_CERT 162
2194#define SSL_R_MISSING_DH_KEY 163
2195#define SSL_R_MISSING_DH_RSA_CERT 164
2196#define SSL_R_MISSING_DSA_SIGNING_CERT 165
2197#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
2198#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
2199#define SSL_R_MISSING_RSA_CERTIFICATE 168
2200#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
2201#define SSL_R_MISSING_RSA_SIGNING_CERT 170
2202#define SSL_R_MISSING_SRP_PARAM 358
2203#define SSL_R_MISSING_TMP_DH_KEY 171
2204#define SSL_R_MISSING_TMP_ECDH_KEY 311
2205#define SSL_R_MISSING_TMP_RSA_KEY 172
2206#define SSL_R_MISSING_TMP_RSA_PKEY 173
2207#define SSL_R_MISSING_VERIFY_MESSAGE 174
2208#define SSL_R_MULTIPLE_SGC_RESTARTS 346
2209#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
2210#define SSL_R_NO_CERTIFICATES_RETURNED 176
2211#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
2212#define SSL_R_NO_CERTIFICATE_RETURNED 178
2213#define SSL_R_NO_CERTIFICATE_SET 179
2214#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
2215#define SSL_R_NO_CIPHERS_AVAILABLE 181
2216#define SSL_R_NO_CIPHERS_PASSED 182
2217#define SSL_R_NO_CIPHERS_SPECIFIED 183
2218#define SSL_R_NO_CIPHER_LIST 184
2219#define SSL_R_NO_CIPHER_MATCH 185
2220#define SSL_R_NO_CLIENT_CERT_METHOD 331
2221#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
2222#define SSL_R_NO_COMPRESSION_SPECIFIED 187
2223#define SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER 330
2224#define SSL_R_NO_METHOD_SPECIFIED 188
2225#define SSL_R_NO_PRIVATEKEY 189
2226#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
2227#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
2228#define SSL_R_NO_PUBLICKEY 192
2229#define SSL_R_NO_RENEGOTIATION 339
2230#define SSL_R_NO_REQUIRED_DIGEST 324
2231#define SSL_R_NO_SHARED_CIPHER 193
2232#define SSL_R_NO_SRTP_PROFILES 359
2233#define SSL_R_NO_VERIFY_CALLBACK 194
2234#define SSL_R_NULL_SSL_CTX 195
2235#define SSL_R_NULL_SSL_METHOD_PASSED 196
2236#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
2237#define SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED 344
2238#define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297
2239#define SSL_R_PACKET_LENGTH_TOO_LONG 198
2240#define SSL_R_PARSE_TLSEXT 227
2241#define SSL_R_PATH_TOO_LONG 270
2242#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
2243#define SSL_R_PEER_ERROR 200
2244#define SSL_R_PEER_ERROR_CERTIFICATE 201
2245#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
2246#define SSL_R_PEER_ERROR_NO_CIPHER 203
2247#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
2248#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
2249#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
2250#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
2251#define SSL_R_PSK_IDENTITY_NOT_FOUND 223
2252#define SSL_R_PSK_NO_CLIENT_CB 224
2253#define SSL_R_PSK_NO_SERVER_CB 225
2254#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
2255#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
2256#define SSL_R_PUBLIC_KEY_NOT_RSA 210
2257#define SSL_R_READ_BIO_NOT_SET 211
2258#define SSL_R_READ_TIMEOUT_EXPIRED 312
2259#define SSL_R_READ_WRONG_PACKET_TYPE 212
2260#define SSL_R_RECORD_LENGTH_MISMATCH 213
2261#define SSL_R_RECORD_TOO_LARGE 214
2262#define SSL_R_RECORD_TOO_SMALL 298
2263#define SSL_R_RENEGOTIATE_EXT_TOO_LONG 335
2264#define SSL_R_RENEGOTIATION_ENCODING_ERR 336
2265#define SSL_R_RENEGOTIATION_MISMATCH 337
2266#define SSL_R_REQUIRED_CIPHER_MISSING 215
2267#define SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING 342
2268#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
2269#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
2270#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
2271#define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING 345
2272#define SSL_R_SERVERHELLO_TLSEXT 275
2273#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
2274#define SSL_R_SHORT_READ 219
2275#define SSL_R_SIGNATURE_ALGORITHMS_ERROR 360
2276#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
2277#define SSL_R_SRP_A_CALC 361
2278#define SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES 362
2279#define SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG 363
2280#define SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE 364
2281#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
2282#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299
2283#define SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT 321
2284#define SSL_R_SSL3_EXT_INVALID_SERVERNAME 319
2285#define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 320
2286#define SSL_R_SSL3_SESSION_ID_TOO_LONG 300
2287#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
2288#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
2289#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
2290#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
2291#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
2292#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
2293#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
2294#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
2295#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
2296#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
2297#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
2298#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
2299#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
2300#define SSL_R_SSL_HANDSHAKE_FAILURE 229
2301#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
2302#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301
2303#define SSL_R_SSL_SESSION_ID_CONFLICT 302
2304#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
2305#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303
2306#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
2307#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
2308#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
2309#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
2310#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
2311#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
2312#define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086
2313#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
2314#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
2315#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
2316#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
2317#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
2318#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
2319#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
2320#define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE 1114
2321#define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE 1113
2322#define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE 1111
2323#define SSL_R_TLSV1_UNRECOGNIZED_NAME 1112
2324#define SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110
2325#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
2326#define SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT 365
2327#define SSL_R_TLS_HEARTBEAT_PENDING 366
2328#define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL 367
2329#define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 157
2330#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
2331#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
2332#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
2333#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
2334#define SSL_R_UNABLE_TO_DECODE_ECDH_CERTS 313
2335#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
2336#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
2337#define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314
2338#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
2339#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
2340#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
2341#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
2342#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
2343#define SSL_R_UNEXPECTED_MESSAGE 244
2344#define SSL_R_UNEXPECTED_RECORD 245
2345#define SSL_R_UNINITIALIZED 276
2346#define SSL_R_UNKNOWN_ALERT_TYPE 246
2347#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
2348#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
2349#define SSL_R_UNKNOWN_CIPHER_TYPE 249
2350#define SSL_R_UNKNOWN_DIGEST 368
2351#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
2352#define SSL_R_UNKNOWN_PKEY_TYPE 251
2353#define SSL_R_UNKNOWN_PROTOCOL 252
2354#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
2355#define SSL_R_UNKNOWN_SSL_VERSION 254
2356#define SSL_R_UNKNOWN_STATE 255
2357#define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED 338
2358#define SSL_R_UNSUPPORTED_CIPHER 256
2359#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
2360#define SSL_R_UNSUPPORTED_DIGEST_TYPE 326
2361#define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315
2362#define SSL_R_UNSUPPORTED_PROTOCOL 258
2363#define SSL_R_UNSUPPORTED_SSL_VERSION 259
2364#define SSL_R_UNSUPPORTED_STATUS_TYPE 329
2365#define SSL_R_USE_SRTP_NOT_NEGOTIATED 369
2366#define SSL_R_WRITE_BIO_NOT_SET 260
2367#define SSL_R_WRONG_CIPHER_RETURNED 261
2368#define SSL_R_WRONG_CURVE 378
2369#define SSL_R_WRONG_MESSAGE_TYPE 262
2370#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
2371#define SSL_R_WRONG_SIGNATURE_LENGTH 264
2372#define SSL_R_WRONG_SIGNATURE_SIZE 265
2373#define SSL_R_WRONG_SIGNATURE_TYPE 370
2374#define SSL_R_WRONG_SSL_VERSION 266
2375#define SSL_R_WRONG_VERSION_NUMBER 267
2376#define SSL_R_X509_LIB 268
2377#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
2378
2379#ifdef __cplusplus
2380}
2381#endif
2382#endif
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index 3a8d300729..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,153 +0,0 @@
1/* $OpenBSD: ssl2.h,v 1.12 2014/12/14 15:30:50 jsing Exp $ */
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#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER 32767u /* 2^15-1 */
137#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /* 2^14-1 */
138
139#define SSL2_CHALLENGE_LENGTH 16
140/*#define SSL2_CHALLENGE_LENGTH 32 */
141#define SSL2_MIN_CHALLENGE_LENGTH 16
142#define SSL2_MAX_CHALLENGE_LENGTH 32
143#define SSL2_CONNECTION_ID_LENGTH 16
144#define SSL2_MAX_CONNECTION_ID_LENGTH 16
145#define SSL2_SSL_SESSION_ID_LENGTH 16
146#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
147#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
148#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
149
150#ifdef __cplusplus
151}
152#endif
153#endif
diff --git a/src/lib/libssl/ssl23.h b/src/lib/libssl/ssl23.h
deleted file mode 100644
index 570e4b0171..0000000000
--- a/src/lib/libssl/ssl23.h
+++ /dev/null
@@ -1,82 +0,0 @@
1/* $OpenBSD: ssl23.h,v 1.4 2014/12/14 15:30:50 jsing Exp $ */
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
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h
deleted file mode 100644
index 5ec2fe6f88..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,617 +0,0 @@
1/* $OpenBSD: ssl3.h,v 1.41 2015/07/19 06:23:51 doug Exp $ */
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 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116
117#ifndef HEADER_SSL3_H
118#define HEADER_SSL3_H
119
120#include <openssl/buffer.h>
121#include <openssl/evp.h>
122#include <openssl/ssl.h>
123
124#ifdef __cplusplus
125extern "C" {
126#endif
127
128/* TLS_EMPTY_RENEGOTIATION_INFO_SCSV from RFC 5746. */
129#define SSL3_CK_SCSV 0x030000FF
130
131/* TLS_FALLBACK_SCSV from draft-ietf-tls-downgrade-scsv-03. */
132#define SSL3_CK_FALLBACK_SCSV 0x03005600
133
134#define SSL3_CK_RSA_NULL_MD5 0x03000001
135#define SSL3_CK_RSA_NULL_SHA 0x03000002
136#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
137#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
138#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
139#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
140#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
141#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
142#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
143#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
144
145#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
146#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
147#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
148#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
149#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
150#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
151
152#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
153#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
154#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
155#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
156#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
157#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
158
159#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
160#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
161#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
162#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
163#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
164
165/* VRS Additional Kerberos5 entries
166 */
167#define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E
168#define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F
169#define SSL3_CK_KRB5_RC4_128_SHA 0x03000020
170#define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021
171#define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022
172#define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023
173#define SSL3_CK_KRB5_RC4_128_MD5 0x03000024
174#define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025
175
176#define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026
177#define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027
178#define SSL3_CK_KRB5_RC4_40_SHA 0x03000028
179#define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029
180#define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A
181#define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B
182
183#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
184#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
185#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
186#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
187#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
188#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
189#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
190#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
191#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
192#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
193
194#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
195#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
196#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
197#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
198#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
199#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
200
201#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
202#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
203#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
204#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
205#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
206#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
207
208#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
209#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
210#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
211#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
212#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
213
214#define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA"
215#define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA"
216#define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA"
217#define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA"
218#define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5"
219#define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5"
220#define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5"
221#define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5"
222
223#define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA"
224#define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA"
225#define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA"
226#define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5"
227#define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5"
228#define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5"
229
230#define SSL3_SSL_SESSION_ID_LENGTH 32
231#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
232
233#define SSL3_MASTER_SECRET_SIZE 48
234#define SSL3_RANDOM_SIZE 32
235#define SSL3_SEQUENCE_SIZE 8
236#define SSL3_SESSION_ID_SIZE 32
237#define SSL3_CIPHER_VALUE_SIZE 2
238
239#define SSL3_RT_HEADER_LENGTH 5
240#define SSL3_HM_HEADER_LENGTH 4
241
242#define SSL3_ALIGN_PAYLOAD 8
243
244/* This is the maximum MAC (digest) size used by the SSL library.
245 * Currently maximum of 20 is used by SHA1, but we reserve for
246 * future extension for 512-bit hashes.
247 */
248
249#define SSL3_RT_MAX_MD_SIZE 64
250
251/* Maximum block size used in all ciphersuites. Currently 16 for AES.
252 */
253
254#define SSL_RT_MAX_CIPHER_BLOCK_SIZE 16
255
256#define SSL3_RT_MAX_EXTRA (16384)
257
258/* Maximum plaintext length: defined by SSL/TLS standards */
259#define SSL3_RT_MAX_PLAIN_LENGTH 16384
260/* Maximum compression overhead: defined by SSL/TLS standards */
261#define SSL3_RT_MAX_COMPRESSED_OVERHEAD 1024
262
263/* The standards give a maximum encryption overhead of 1024 bytes.
264 * In practice the value is lower than this. The overhead is the maximum
265 * number of padding bytes (256) plus the mac size.
266 */
267#define SSL3_RT_MAX_ENCRYPTED_OVERHEAD (256 + SSL3_RT_MAX_MD_SIZE)
268
269/* OpenSSL currently only uses a padding length of at most one block so
270 * the send overhead is smaller.
271 */
272
273#define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \
274 (SSL_RT_MAX_CIPHER_BLOCK_SIZE + SSL3_RT_MAX_MD_SIZE)
275
276/* If compression isn't used don't include the compression overhead */
277#define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH
278#define SSL3_RT_MAX_ENCRYPTED_LENGTH \
279 (SSL3_RT_MAX_ENCRYPTED_OVERHEAD+SSL3_RT_MAX_COMPRESSED_LENGTH)
280#define SSL3_RT_MAX_PACKET_SIZE \
281 (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
282
283#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
284#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
285
286#define SSL3_VERSION 0x0300
287#define SSL3_VERSION_MAJOR 0x03
288#define SSL3_VERSION_MINOR 0x00
289
290#define SSL3_RT_CHANGE_CIPHER_SPEC 20
291#define SSL3_RT_ALERT 21
292#define SSL3_RT_HANDSHAKE 22
293#define SSL3_RT_APPLICATION_DATA 23
294#define TLS1_RT_HEARTBEAT 24
295
296#define SSL3_AL_WARNING 1
297#define SSL3_AL_FATAL 2
298
299#define SSL3_AD_CLOSE_NOTIFY 0
300#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
301#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
302#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
303#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
304#define SSL3_AD_NO_CERTIFICATE 41
305#define SSL3_AD_BAD_CERTIFICATE 42
306#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
307#define SSL3_AD_CERTIFICATE_REVOKED 44
308#define SSL3_AD_CERTIFICATE_EXPIRED 45
309#define SSL3_AD_CERTIFICATE_UNKNOWN 46
310#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
311
312#define TLS1_HB_REQUEST 1
313#define TLS1_HB_RESPONSE 2
314
315#ifndef OPENSSL_NO_SSL_INTERN
316
317typedef struct ssl3_record_st {
318/*r */ int type; /* type of record */
319/*rw*/ unsigned int length; /* How many bytes available */
320/*r */ unsigned int off; /* read/write offset into 'buf' */
321/*rw*/ unsigned char *data; /* pointer to the record data */
322/*rw*/ unsigned char *input; /* where the decode bytes are */
323/*r */ unsigned long epoch; /* epoch number, needed by DTLS1 */
324/*r */ unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
325} SSL3_RECORD;
326
327typedef struct ssl3_buffer_st {
328 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
329 * see ssl3_setup_buffers() */
330 size_t len; /* buffer size */
331 int offset; /* where to 'copy from' */
332 int left; /* how many bytes left */
333} SSL3_BUFFER;
334
335#endif
336
337#define SSL3_CT_RSA_SIGN 1
338#define SSL3_CT_DSS_SIGN 2
339#define SSL3_CT_RSA_FIXED_DH 3
340#define SSL3_CT_DSS_FIXED_DH 4
341#define SSL3_CT_RSA_EPHEMERAL_DH 5
342#define SSL3_CT_DSS_EPHEMERAL_DH 6
343#define SSL3_CT_FORTEZZA_DMS 20
344/* SSL3_CT_NUMBER is used to size arrays and it must be large
345 * enough to contain all of the cert types defined either for
346 * SSLv3 and TLSv1.
347 */
348#define SSL3_CT_NUMBER 11
349
350
351#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
352#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
353#define SSL3_FLAGS_POP_BUFFER 0x0004
354#define TLS1_FLAGS_TLS_PADDING_BUG 0x0
355#define TLS1_FLAGS_SKIP_CERT_VERIFY 0x0010
356#define TLS1_FLAGS_KEEP_HANDSHAKE 0x0020
357#define SSL3_FLAGS_CCS_OK 0x0080
358
359#ifndef OPENSSL_NO_SSL_INTERN
360
361typedef struct ssl3_state_st {
362 long flags;
363 int delay_buf_pop_ret;
364
365 unsigned char read_sequence[SSL3_SEQUENCE_SIZE];
366 int read_mac_secret_size;
367 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
368 unsigned char write_sequence[SSL3_SEQUENCE_SIZE];
369 int write_mac_secret_size;
370 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
371
372 unsigned char server_random[SSL3_RANDOM_SIZE];
373 unsigned char client_random[SSL3_RANDOM_SIZE];
374
375 /* flags for countermeasure against known-IV weakness */
376 int need_empty_fragments;
377 int empty_fragment_done;
378
379 SSL3_BUFFER rbuf; /* read IO goes into here */
380 SSL3_BUFFER wbuf; /* write IO goes into here */
381
382 SSL3_RECORD rrec; /* each decoded record goes in here */
383 SSL3_RECORD wrec; /* goes out from here */
384
385 /* storage for Alert/Handshake protocol data received but not
386 * yet processed by ssl3_read_bytes: */
387 unsigned char alert_fragment[2];
388 unsigned int alert_fragment_len;
389 unsigned char handshake_fragment[4];
390 unsigned int handshake_fragment_len;
391
392 /* partial write - check the numbers match */
393 unsigned int wnum; /* number of bytes sent so far */
394 int wpend_tot; /* number bytes written */
395 int wpend_type;
396 int wpend_ret; /* number of bytes submitted */
397 const unsigned char *wpend_buf;
398
399 /* used during startup, digest all incoming/outgoing packets */
400 BIO *handshake_buffer;
401 /* When set of handshake digests is determined, buffer is hashed
402 * and freed and MD_CTX-es for all required digests are stored in
403 * this array */
404 EVP_MD_CTX **handshake_dgst;
405 /* this is set whenerver we see a change_cipher_spec message
406 * come in when we are not looking for one */
407 int change_cipher_spec;
408
409 int warn_alert;
410 int fatal_alert;
411 /* we allow one fatal and one warning alert to be outstanding,
412 * send close alert via the warning alert */
413 int alert_dispatch;
414 unsigned char send_alert[2];
415
416 /* This flag is set when we should renegotiate ASAP, basically when
417 * there is no more data in the read or write buffers */
418 int renegotiate;
419 int total_renegotiations;
420 int num_renegotiations;
421
422 int in_read_app_data;
423
424 struct {
425 /* actually only needs to be 16+20 */
426 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
427
428 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
429 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
430 int finish_md_len;
431 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
432 int peer_finish_md_len;
433
434 unsigned long message_size;
435 int message_type;
436
437 /* used to hold the new cipher we are going to use */
438 const SSL_CIPHER *new_cipher;
439 DH *dh;
440
441 EC_KEY *ecdh; /* holds short lived ECDH key */
442
443 /* used when SSL_ST_FLUSH_DATA is entered */
444 int next_state;
445
446 int reuse_message;
447
448 /* used for certificate requests */
449 int cert_req;
450 int ctype_num;
451 char ctype[SSL3_CT_NUMBER];
452 STACK_OF(X509_NAME) *ca_names;
453
454 int key_block_length;
455 unsigned char *key_block;
456
457 const EVP_CIPHER *new_sym_enc;
458 const EVP_AEAD *new_aead;
459 const EVP_MD *new_hash;
460 int new_mac_pkey_type;
461 int new_mac_secret_size;
462 int cert_request;
463 } tmp;
464
465 /* Connection binding to prevent renegotiation attacks */
466 unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
467 unsigned char previous_client_finished_len;
468 unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
469 unsigned char previous_server_finished_len;
470 int send_connection_binding; /* TODOEKR */
471
472 /* Set if we saw the Next Protocol Negotiation extension from our peer.
473 */
474 int next_proto_neg_seen;
475
476 /*
477 * ALPN information
478 * (we are in the process of transitioning from NPN to ALPN).
479 */
480
481 /*
482 * In a server these point to the selected ALPN protocol after the
483 * ClientHello has been processed. In a client these contain the
484 * protocol that the server selected once the ServerHello has been
485 * processed.
486 */
487 unsigned char *alpn_selected;
488 unsigned int alpn_selected_len;
489} SSL3_STATE;
490
491#endif
492
493/* SSLv3 */
494/*client */
495/* extra state */
496#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
497/* write to server */
498#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
499#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
500/* read from server */
501#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
502#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
503#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A (0x126|SSL_ST_CONNECT)
504#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B (0x127|SSL_ST_CONNECT)
505#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
506#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
507#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
508#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
509#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
510#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
511#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
512#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
513/* write to server */
514#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
515#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
516#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
517#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
518#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
519#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
520#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
521#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
522#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
523#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
524#define SSL3_ST_CW_NEXT_PROTO_A (0x200|SSL_ST_CONNECT)
525#define SSL3_ST_CW_NEXT_PROTO_B (0x201|SSL_ST_CONNECT)
526#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
527#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
528/* read from server */
529#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
530#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
531#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
532#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
533#define SSL3_ST_CR_SESSION_TICKET_A (0x1E0|SSL_ST_CONNECT)
534#define SSL3_ST_CR_SESSION_TICKET_B (0x1E1|SSL_ST_CONNECT)
535#define SSL3_ST_CR_CERT_STATUS_A (0x1F0|SSL_ST_CONNECT)
536#define SSL3_ST_CR_CERT_STATUS_B (0x1F1|SSL_ST_CONNECT)
537
538/* server */
539/* extra state */
540#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
541/* read from client */
542/* Do not change the number values, they do matter */
543#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
544#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
545#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
546/* write to client */
547#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A (0x113|SSL_ST_ACCEPT)
548#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B (0x114|SSL_ST_ACCEPT)
549#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
550#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
551#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
552#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
553#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
554#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
555#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
556#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
557#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
558#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
559#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
560#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
561#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
562/* read from client */
563#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
564#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
565#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
566#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
567#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
568#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
569#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
570#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
571#define SSL3_ST_SR_NEXT_PROTO_A (0x210|SSL_ST_ACCEPT)
572#define SSL3_ST_SR_NEXT_PROTO_B (0x211|SSL_ST_ACCEPT)
573#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
574#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
575/* write to client */
576#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
577#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
578#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
579#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
580#define SSL3_ST_SW_SESSION_TICKET_A (0x1F0|SSL_ST_ACCEPT)
581#define SSL3_ST_SW_SESSION_TICKET_B (0x1F1|SSL_ST_ACCEPT)
582#define SSL3_ST_SW_CERT_STATUS_A (0x200|SSL_ST_ACCEPT)
583#define SSL3_ST_SW_CERT_STATUS_B (0x201|SSL_ST_ACCEPT)
584
585#define SSL3_MT_HELLO_REQUEST 0
586#define SSL3_MT_CLIENT_HELLO 1
587#define SSL3_MT_SERVER_HELLO 2
588#define SSL3_MT_NEWSESSION_TICKET 4
589#define SSL3_MT_CERTIFICATE 11
590#define SSL3_MT_SERVER_KEY_EXCHANGE 12
591#define SSL3_MT_CERTIFICATE_REQUEST 13
592#define SSL3_MT_SERVER_DONE 14
593#define SSL3_MT_CERTIFICATE_VERIFY 15
594#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
595#define SSL3_MT_FINISHED 20
596#define SSL3_MT_CERTIFICATE_STATUS 22
597
598#define SSL3_MT_NEXT_PROTO 67
599
600#define DTLS1_MT_HELLO_VERIFY_REQUEST 3
601
602#define SSL3_MT_CCS 1
603
604/* These are used when changing over to a new cipher */
605#define SSL3_CC_READ 0x01
606#define SSL3_CC_WRITE 0x02
607#define SSL3_CC_CLIENT 0x10
608#define SSL3_CC_SERVER 0x20
609#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
610#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
611#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
612#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
613
614#ifdef __cplusplus
615}
616#endif
617#endif
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c
deleted file mode 100644
index 3010a735c9..0000000000
--- a/src/lib/libssl/ssl_algs.c
+++ /dev/null
@@ -1,131 +0,0 @@
1/* $OpenBSD: ssl_algs.c,v 1.22 2014/12/14 15:30:50 jsing Exp $ */
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
61#include <openssl/lhash.h>
62#include <openssl/objects.h>
63
64#include "ssl_locl.h"
65
66int
67SSL_library_init(void)
68{
69
70#ifndef OPENSSL_NO_DES
71 EVP_add_cipher(EVP_des_cbc());
72 EVP_add_cipher(EVP_des_ede3_cbc());
73#endif
74#ifndef OPENSSL_NO_IDEA
75 EVP_add_cipher(EVP_idea_cbc());
76#endif
77#ifndef OPENSSL_NO_RC4
78 EVP_add_cipher(EVP_rc4());
79#if !defined(OPENSSL_NO_MD5) && (defined(__x86_64) || defined(__x86_64__))
80 EVP_add_cipher(EVP_rc4_hmac_md5());
81#endif
82#endif
83#ifndef OPENSSL_NO_RC2
84 EVP_add_cipher(EVP_rc2_cbc());
85 /* Not actually used for SSL/TLS but this makes PKCS#12 work
86 * if an application only calls SSL_library_init().
87 */
88 EVP_add_cipher(EVP_rc2_40_cbc());
89#endif
90 EVP_add_cipher(EVP_aes_128_cbc());
91 EVP_add_cipher(EVP_aes_192_cbc());
92 EVP_add_cipher(EVP_aes_256_cbc());
93 EVP_add_cipher(EVP_aes_128_gcm());
94 EVP_add_cipher(EVP_aes_256_gcm());
95 EVP_add_cipher(EVP_aes_128_cbc_hmac_sha1());
96 EVP_add_cipher(EVP_aes_256_cbc_hmac_sha1());
97#ifndef OPENSSL_NO_CAMELLIA
98 EVP_add_cipher(EVP_camellia_128_cbc());
99 EVP_add_cipher(EVP_camellia_256_cbc());
100#endif
101#ifndef OPENSSL_NO_GOST
102 EVP_add_cipher(EVP_gost2814789_cfb64());
103 EVP_add_cipher(EVP_gost2814789_cnt());
104#endif
105
106 EVP_add_digest(EVP_md5());
107 EVP_add_digest_alias(SN_md5, "ssl2-md5");
108 EVP_add_digest_alias(SN_md5, "ssl3-md5");
109 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
110 EVP_add_digest_alias(SN_sha1, "ssl3-sha1");
111 EVP_add_digest_alias(SN_sha1WithRSAEncryption, SN_sha1WithRSA);
112 EVP_add_digest(EVP_sha224());
113 EVP_add_digest(EVP_sha256());
114 EVP_add_digest(EVP_sha384());
115 EVP_add_digest(EVP_sha512());
116 EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
117 EVP_add_digest_alias(SN_dsaWithSHA1, SN_dsaWithSHA1_2);
118 EVP_add_digest_alias(SN_dsaWithSHA1, "DSS1");
119 EVP_add_digest_alias(SN_dsaWithSHA1, "dss1");
120 EVP_add_digest(EVP_ecdsa());
121#ifndef OPENSSL_NO_GOST
122 EVP_add_digest(EVP_gostr341194());
123 EVP_add_digest(EVP_gost2814789imit());
124 EVP_add_digest(EVP_streebog256());
125 EVP_add_digest(EVP_streebog512());
126#endif
127 /* initialize cipher/digest methods table */
128 ssl_load_ciphers();
129 return (1);
130}
131
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index ee00cb286d..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,691 +0,0 @@
1/* $OpenBSD: ssl_asn1.c,v 1.41 2016/03/11 07:08:45 mmcc Exp $ */
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
62#include "ssl_locl.h"
63
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66
67/* XXX - these are here to avoid including asn1_mac.h */
68int asn1_GetSequence(ASN1_const_CTX *c, long *length);
69void asn1_add_error(const unsigned char *address, int offset);
70
71typedef struct ssl_session_asn1_st {
72 ASN1_INTEGER version;
73 ASN1_INTEGER ssl_version;
74 ASN1_OCTET_STRING cipher;
75 ASN1_OCTET_STRING master_key;
76 ASN1_OCTET_STRING session_id;
77 ASN1_OCTET_STRING session_id_context;
78 ASN1_INTEGER time;
79 ASN1_INTEGER timeout;
80 ASN1_INTEGER verify_result;
81 ASN1_OCTET_STRING tlsext_hostname;
82 ASN1_INTEGER tlsext_tick_lifetime;
83 ASN1_OCTET_STRING tlsext_tick;
84} SSL_SESSION_ASN1;
85
86int
87i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
88{
89#define LSIZE2 (sizeof(long)*2)
90 int v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0, v9 = 0, v10 = 0;
91 unsigned char buf[4], ibuf1[LSIZE2], ibuf2[LSIZE2];
92 unsigned char ibuf3[LSIZE2], ibuf4[LSIZE2], ibuf5[LSIZE2];
93 unsigned char ibuf6[LSIZE2];
94 SSL_SESSION_ASN1 a;
95 unsigned char *p;
96 int len = 0, ret;
97 long l;
98
99 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
100 return (0);
101
102 /*
103 * Note that I cheat in the following 2 assignments.
104 * I know that if the ASN1_INTEGER passed to ASN1_INTEGER_set
105 * is > sizeof(long)+1, the buffer will not be re-malloc()ed.
106 * This is a bit evil but makes things simple, no dynamic allocation
107 * to clean up :-)
108 */
109 a.version.length = LSIZE2;
110 a.version.type = V_ASN1_INTEGER;
111 a.version.data = ibuf1;
112 ASN1_INTEGER_set(&(a.version), SSL_SESSION_ASN1_VERSION);
113 len += i2d_ASN1_INTEGER(&(a.version), NULL);
114
115 a.ssl_version.length = LSIZE2;
116 a.ssl_version.type = V_ASN1_INTEGER;
117 a.ssl_version.data = ibuf2;
118 ASN1_INTEGER_set(&(a.ssl_version), in->ssl_version);
119 len += i2d_ASN1_INTEGER(&(a.ssl_version), NULL);
120
121 a.cipher.length = 2;
122 a.cipher.type = V_ASN1_OCTET_STRING;
123 l = (in->cipher == NULL) ? in->cipher_id : in->cipher->id;
124 buf[0] = ((unsigned char)(l >> 8L)) & 0xff;
125 buf[1] = ((unsigned char)(l)) & 0xff;
126 a.cipher.data = buf;
127 len += i2d_ASN1_OCTET_STRING(&(a.cipher), NULL);
128
129 a.master_key.length = in->master_key_length;
130 a.master_key.type = V_ASN1_OCTET_STRING;
131 a.master_key.data = in->master_key;
132 len += i2d_ASN1_OCTET_STRING(&(a.master_key), NULL);
133
134 a.session_id.length = in->session_id_length;
135 a.session_id.type = V_ASN1_OCTET_STRING;
136 a.session_id.data = in->session_id;
137 len += i2d_ASN1_OCTET_STRING(&(a.session_id), NULL);
138
139 if (in->time != 0L) {
140 a.time.length = LSIZE2;
141 a.time.type = V_ASN1_INTEGER;
142 a.time.data = ibuf3;
143 ASN1_INTEGER_set(&(a.time), in->time); /* XXX 2038 */
144 v1 = i2d_ASN1_INTEGER(&(a.time), NULL);
145 len += ASN1_object_size(1, v1, 1);
146 }
147
148 if (in->timeout != 0L) {
149 a.timeout.length = LSIZE2;
150 a.timeout.type = V_ASN1_INTEGER;
151 a.timeout.data = ibuf4;
152 ASN1_INTEGER_set(&(a.timeout), in->timeout);
153 v2 = i2d_ASN1_INTEGER(&(a.timeout), NULL);
154 len += ASN1_object_size(1, v2, 2);
155 }
156
157 if (in->peer != NULL) {
158 v3 = i2d_X509(in->peer, NULL);
159 len += ASN1_object_size(1, v3, 3);
160 }
161
162 a.session_id_context.length = in->sid_ctx_length;
163 a.session_id_context.type = V_ASN1_OCTET_STRING;
164 a.session_id_context.data = in->sid_ctx;
165 v4 = i2d_ASN1_OCTET_STRING(&(a.session_id_context), NULL);
166 len += ASN1_object_size(1, v4, 4);
167
168 if (in->verify_result != X509_V_OK) {
169 a.verify_result.length = LSIZE2;
170 a.verify_result.type = V_ASN1_INTEGER;
171 a.verify_result.data = ibuf5;
172 ASN1_INTEGER_set(&a.verify_result, in->verify_result);
173 v5 = i2d_ASN1_INTEGER(&(a.verify_result), NULL);
174 len += ASN1_object_size(1, v5, 5);
175 }
176
177 if (in->tlsext_hostname) {
178 a.tlsext_hostname.length = strlen(in->tlsext_hostname);
179 a.tlsext_hostname.type = V_ASN1_OCTET_STRING;
180 a.tlsext_hostname.data = (unsigned char *)in->tlsext_hostname;
181 v6 = i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), NULL);
182 len += ASN1_object_size(1, v6, 6);
183 }
184
185 /* 7 - PSK identity hint. */
186 /* 8 - PSK identity. */
187
188 if (in->tlsext_tick_lifetime_hint > 0) {
189 a.tlsext_tick_lifetime.length = LSIZE2;
190 a.tlsext_tick_lifetime.type = V_ASN1_INTEGER;
191 a.tlsext_tick_lifetime.data = ibuf6;
192 ASN1_INTEGER_set(&a.tlsext_tick_lifetime,
193 in->tlsext_tick_lifetime_hint);
194 v9 = i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), NULL);
195 len += ASN1_object_size(1, v9, 9);
196 }
197
198 if (in->tlsext_tick) {
199 a.tlsext_tick.length = in->tlsext_ticklen;
200 a.tlsext_tick.type = V_ASN1_OCTET_STRING;
201 a.tlsext_tick.data = (unsigned char *)in->tlsext_tick;
202 v10 = i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), NULL);
203 len += ASN1_object_size(1, v10, 10);
204 }
205
206 /* 11 - Compression method. */
207 /* 12 - SRP username. */
208
209 /* If given a NULL pointer, return the length only. */
210 ret = (ASN1_object_size(1, len, V_ASN1_SEQUENCE));
211 if (pp == NULL)
212 return (ret);
213
214 /* Burp out the ASN1. */
215 p = *pp;
216 ASN1_put_object(&p, 1, len, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
217 i2d_ASN1_INTEGER(&(a.version), &p);
218 i2d_ASN1_INTEGER(&(a.ssl_version), &p);
219 i2d_ASN1_OCTET_STRING(&(a.cipher), &p);
220 i2d_ASN1_OCTET_STRING(&(a.session_id), &p);
221 i2d_ASN1_OCTET_STRING(&(a.master_key), &p);
222 if (in->time != 0L) {
223 ASN1_put_object(&p, 1, v1, 1, V_ASN1_CONTEXT_SPECIFIC);
224 i2d_ASN1_INTEGER(&(a.time), &p);
225 }
226 if (in->timeout != 0L) {
227 ASN1_put_object(&p, 1, v2, 2, V_ASN1_CONTEXT_SPECIFIC);
228 i2d_ASN1_INTEGER(&(a.timeout), &p);
229 }
230 if (in->peer != NULL) {
231 ASN1_put_object(&p, 1, v3, 3, V_ASN1_CONTEXT_SPECIFIC);
232 i2d_X509(in->peer, &p);
233 }
234 ASN1_put_object(&p, 1, v4, 4, V_ASN1_CONTEXT_SPECIFIC);
235 i2d_ASN1_OCTET_STRING(&(a.session_id_context), &p);
236 if (in->verify_result != X509_V_OK) {
237 ASN1_put_object(&p, 1, v5, 5, V_ASN1_CONTEXT_SPECIFIC);
238 i2d_ASN1_INTEGER(&(a.verify_result), &p);
239 }
240 if (in->tlsext_hostname) {
241 ASN1_put_object(&p, 1, v6, 6, V_ASN1_CONTEXT_SPECIFIC);
242 i2d_ASN1_OCTET_STRING(&(a.tlsext_hostname), &p);
243 }
244 /* 7 - PSK identity hint. */
245 /* 8 - PSK identity. */
246 if (in->tlsext_tick_lifetime_hint > 0) {
247 ASN1_put_object(&p, 1, v9, 9, V_ASN1_CONTEXT_SPECIFIC);
248 i2d_ASN1_INTEGER(&(a.tlsext_tick_lifetime), &p);
249 }
250 if (in->tlsext_tick) {
251 ASN1_put_object(&p, 1, v10, 10, V_ASN1_CONTEXT_SPECIFIC);
252 i2d_ASN1_OCTET_STRING(&(a.tlsext_tick), &p);
253 }
254 /* 11 - Compression method. */
255 /* 12 - SRP username. */
256
257 *pp = p;
258 return (ret);
259}
260
261SSL_SESSION *
262d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
263{
264 SSL_SESSION *ret = NULL;
265 ASN1_const_CTX c;
266 ASN1_INTEGER ai, *aip;
267 ASN1_OCTET_STRING os, *osp;
268 int ssl_version = 0, i;
269 int Tinf, Ttag, Tclass;
270 long Tlen;
271 long id;
272
273 c.pp = pp;
274 c.p = *pp;
275 c.q = *pp;
276 c.max = (length == 0) ? 0 : (c.p + length);
277 c.slen = length;
278
279 if (a == NULL || *a == NULL) {
280 if ((ret = SSL_SESSION_new()) == NULL) {
281 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
282 goto err;
283 }
284 } else
285 ret = *a;
286
287 aip = &ai;
288 osp = &os;
289
290 if (!asn1_GetSequence(&c, &length)) {
291 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
292 goto err;
293 }
294
295 ai.data = NULL;
296 ai.length = 0;
297 c.q = c.p;
298 if (d2i_ASN1_INTEGER(&aip, &c.p, c.slen) == NULL) {
299 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
300 goto err;
301 }
302 c.slen -= (c.p - c.q);
303
304 if (ai.data != NULL) {
305 free(ai.data);
306 ai.data = NULL;
307 ai.length = 0;
308 }
309
310 /* we don't care about the version right now :-) */
311 c.q = c.p;
312 if (d2i_ASN1_INTEGER(&aip, &c.p, c.slen) == NULL) {
313 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
314 goto err;
315 }
316 c.slen -= (c.p - c.q);
317 ssl_version = (int)ASN1_INTEGER_get(aip);
318 ret->ssl_version = ssl_version;
319 if (ai.data != NULL) {
320 free(ai.data);
321 ai.data = NULL;
322 ai.length = 0;
323 }
324
325 os.data = NULL;
326 os.length = 0;
327 c.q = c.p;
328 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, c.slen) == NULL) {
329 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
330 goto err;
331 }
332 c.slen -= (c.p - c.q);
333 if ((ssl_version >> 8) >= SSL3_VERSION_MAJOR) {
334 if (os.length != 2) {
335 SSLerr(SSL_F_D2I_SSL_SESSION,
336 SSL_R_CIPHER_CODE_WRONG_LENGTH);
337 goto err;
338 }
339 id = 0x03000000L | ((unsigned long)os.data[0]<<8L) |
340 (unsigned long)os.data[1];
341 } else {
342 SSLerr(SSL_F_D2I_SSL_SESSION, SSL_R_UNKNOWN_SSL_VERSION);
343 goto err;
344 }
345
346 ret->cipher = NULL;
347 ret->cipher_id = id;
348
349 c.q = c.p;
350 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, c.slen) == NULL) {
351 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
352 goto err;
353 }
354 c.slen -= (c.p - c.q);
355
356 i = SSL3_MAX_SSL_SESSION_ID_LENGTH;
357 if (os.length > i)
358 os.length = i;
359 if (os.length > (int)sizeof(ret->session_id)) /* can't happen */
360 os.length = sizeof(ret->session_id);
361
362 ret->session_id_length = os.length;
363 OPENSSL_assert(os.length <= (int)sizeof(ret->session_id));
364 memcpy(ret->session_id, os.data, os.length);
365
366 c.q = c.p;
367 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, c.slen) == NULL) {
368 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
369 goto err;
370 }
371 c.slen -= (c.p - c.q);
372 if (os.length > SSL_MAX_MASTER_KEY_LENGTH)
373 ret->master_key_length = SSL_MAX_MASTER_KEY_LENGTH;
374 else
375 ret->master_key_length = os.length;
376 memcpy(ret->master_key, os.data, ret->master_key_length);
377
378 os.length = 0;
379
380 /* 1 - Time (INTEGER). */
381 /* XXX 2038 */
382 ai.length = 0;
383 if (c.slen != 0L &&
384 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 1)) {
385 c.q = c.p;
386 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
387 if (Tinf & 0x80) {
388 SSLerr(SSL_F_D2I_SSL_SESSION,
389 ERR_R_BAD_ASN1_OBJECT_HEADER);
390 goto err;
391 }
392 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
393 Tlen = c.slen - (c.p - c.q) - 2;
394 if (d2i_ASN1_INTEGER(&aip, &c.p, Tlen) == NULL) {
395 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
396 goto err;
397 }
398 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
399 Tlen = c.slen - (c.p - c.q);
400 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
401 SSLerr(SSL_F_D2I_SSL_SESSION,
402 ERR_R_MISSING_ASN1_EOS);
403 goto err;
404 }
405 }
406 c.slen -= (c.p - c.q);
407 }
408 if (ai.data != NULL) {
409 ret->time = ASN1_INTEGER_get(aip);
410 free(ai.data);
411 ai.data = NULL;
412 ai.length = 0;
413 } else
414 ret->time = time(NULL);
415
416 /* 2 - Timeout (INTEGER). */
417 ai.length = 0;
418 if (c.slen != 0L &&
419 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 2)) {
420 c.q = c.p;
421 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
422 if (Tinf & 0x80) {
423 SSLerr(SSL_F_D2I_SSL_SESSION,
424 ERR_R_BAD_ASN1_OBJECT_HEADER);
425 goto err;
426 }
427 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
428 Tlen = c.slen - (c.p - c.q) - 2;
429 if (d2i_ASN1_INTEGER(&aip, &c.p, Tlen) == NULL) {
430 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
431 goto err;
432 }
433 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
434 Tlen = c.slen - (c.p - c.q);
435 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
436 SSLerr(SSL_F_D2I_SSL_SESSION,
437 ERR_R_MISSING_ASN1_EOS);
438 goto err;
439 }
440 }
441 c.slen -= (c.p - c.q);
442 }
443 if (ai.data != NULL) {
444 ret->timeout = ASN1_INTEGER_get(aip);
445 free(ai.data);
446 ai.data = NULL;
447 ai.length = 0;
448 } else
449 ret->timeout = 3;
450
451 /* 3 - Peer (X509). */
452 X509_free(ret->peer);
453 ret->peer = NULL;
454
455 if (c.slen != 0L &&
456 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 3)) {
457 c.q = c.p;
458 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
459 if (Tinf & 0x80) {
460 SSLerr(SSL_F_D2I_SSL_SESSION,
461 ERR_R_BAD_ASN1_OBJECT_HEADER);
462 goto err;
463 }
464 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
465 Tlen = c.slen - (c.p - c.q) - 2;
466 if (d2i_X509(&ret->peer, &c.p, Tlen) == NULL) {
467 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
468 goto err;
469 }
470 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
471 Tlen = c.slen - (c.p - c.q);
472 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
473 SSLerr(SSL_F_D2I_SSL_SESSION,
474 ERR_R_MISSING_ASN1_EOS);
475 goto err;
476 }
477 }
478 c.slen -= (c.p - c.q);
479 }
480
481 /* 4 - Session ID (OCTET STRING). */
482 os.length = 0;
483 free(os.data);
484 os.data = NULL;
485 if (c.slen != 0L &&
486 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 4)) {
487 c.q = c.p;
488 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
489 if (Tinf & 0x80) {
490 SSLerr(SSL_F_D2I_SSL_SESSION,
491 ERR_R_BAD_ASN1_OBJECT_HEADER);
492 goto err;
493 }
494 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
495 Tlen = c.slen - (c.p - c.q) - 2;
496 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, Tlen) == NULL) {
497 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
498 goto err;
499 }
500 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
501 Tlen = c.slen - (c.p - c.q);
502 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
503 SSLerr(SSL_F_D2I_SSL_SESSION,
504 ERR_R_MISSING_ASN1_EOS);
505 goto err;
506 }
507 }
508 c.slen -= (c.p - c.q);
509 }
510 if (os.data != NULL) {
511 if (os.length > SSL_MAX_SID_CTX_LENGTH) {
512 SSLerr(SSL_F_D2I_SSL_SESSION, SSL_R_BAD_LENGTH);
513 goto err;
514 } else {
515 ret->sid_ctx_length = os.length;
516 memcpy(ret->sid_ctx, os.data, os.length);
517 }
518 free(os.data);
519 os.data = NULL;
520 os.length = 0;
521 } else
522 ret->sid_ctx_length = 0;
523
524 /* 5 - Verify_result. */
525 ai.length = 0;
526 if (c.slen != 0L &&
527 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 5)) {
528 c.q = c.p;
529 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
530 if (Tinf & 0x80) {
531 SSLerr(SSL_F_D2I_SSL_SESSION,
532 ERR_R_BAD_ASN1_OBJECT_HEADER);
533 goto err;
534 }
535 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
536 Tlen = c.slen - (c.p - c.q) - 2;
537 if (d2i_ASN1_INTEGER(&aip, &c.p, Tlen) == NULL) {
538 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
539 goto err;
540 }
541 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
542 Tlen = c.slen - (c.p - c.q);
543 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
544 SSLerr(SSL_F_D2I_SSL_SESSION,
545 ERR_R_MISSING_ASN1_EOS);
546 goto err;
547 }
548 }
549 c.slen -= (c.p - c.q);
550 }
551 if (ai.data != NULL) {
552 ret->verify_result = ASN1_INTEGER_get(aip);
553 free(ai.data);
554 ai.data = NULL;
555 ai.length = 0;
556 } else
557 ret->verify_result = X509_V_OK;
558
559 /* 6 - HostName (OCTET STRING). */
560 os.length = 0;
561 os.data = NULL;
562 if (c.slen != 0L &&
563 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 6)) {
564 c.q = c.p;
565 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
566 if (Tinf & 0x80) {
567 SSLerr(SSL_F_D2I_SSL_SESSION,
568 ERR_R_BAD_ASN1_OBJECT_HEADER);
569 goto err;
570 }
571 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
572 Tlen = c.slen - (c.p - c.q) - 2;
573 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, Tlen) == NULL) {
574 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
575 goto err;
576 }
577 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
578 Tlen = c.slen - (c.p - c.q);
579 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
580 SSLerr(SSL_F_D2I_SSL_SESSION,
581 ERR_R_MISSING_ASN1_EOS);
582 goto err;
583 }
584 }
585 c.slen -= (c.p - c.q);
586 }
587 if (os.data) {
588 ret->tlsext_hostname = strndup((char *)os.data, os.length);
589 free(os.data);
590 os.data = NULL;
591 os.length = 0;
592 } else
593 ret->tlsext_hostname = NULL;
594
595 /* 7 - PSK identity hint (OCTET STRING). */
596 /* 8 - PSK identity (OCTET STRING). */
597
598 /* 9 - Ticket lifetime. */
599 ai.length = 0;
600 if (c.slen != 0L &&
601 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 9)) {
602 c.q = c.p;
603 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
604 if (Tinf & 0x80) {
605 SSLerr(SSL_F_D2I_SSL_SESSION,
606 ERR_R_BAD_ASN1_OBJECT_HEADER);
607 goto err;
608 }
609 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
610 Tlen = c.slen - (c.p - c.q) - 2;
611 if (d2i_ASN1_INTEGER(&aip, &c.p, Tlen) == NULL) {
612 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
613 goto err;
614 }
615 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
616 Tlen = c.slen - (c.p - c.q);
617 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
618 SSLerr(SSL_F_D2I_SSL_SESSION,
619 ERR_R_MISSING_ASN1_EOS);
620 goto err;
621 }
622 }
623 c.slen -= (c.p - c.q);
624 }
625 if (ai.data != NULL) {
626 ret->tlsext_tick_lifetime_hint = ASN1_INTEGER_get(aip);
627 free(ai.data);
628 ai.data = NULL;
629 ai.length = 0;
630 } else if (ret->tlsext_ticklen && ret->session_id_length)
631 ret->tlsext_tick_lifetime_hint = -1;
632 else
633 ret->tlsext_tick_lifetime_hint = 0;
634 os.length = 0;
635 os.data = NULL;
636
637 /* 10 - Ticket (OCTET STRING). */
638 if (c.slen != 0L &&
639 *c.p == (V_ASN1_CONSTRUCTED | V_ASN1_CONTEXT_SPECIFIC | 10)) {
640 c.q = c.p;
641 Tinf = ASN1_get_object(&c.p, &Tlen, &Ttag, &Tclass, c.slen);
642 if (Tinf & 0x80) {
643 SSLerr(SSL_F_D2I_SSL_SESSION,
644 ERR_R_BAD_ASN1_OBJECT_HEADER);
645 goto err;
646 }
647 if (Tinf == (V_ASN1_CONSTRUCTED + 1))
648 Tlen = c.slen - (c.p - c.q) - 2;
649 if (d2i_ASN1_OCTET_STRING(&osp, &c.p, Tlen) == NULL) {
650 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
651 goto err;
652 }
653 if (Tinf == (V_ASN1_CONSTRUCTED + 1)) {
654 Tlen = c.slen - (c.p - c.q);
655 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) {
656 SSLerr(SSL_F_D2I_SSL_SESSION,
657 ERR_R_MISSING_ASN1_EOS);
658 goto err;
659 }
660 }
661 c.slen -= (c.p - c.q);
662 }
663 if (os.data) {
664 ret->tlsext_tick = os.data;
665 ret->tlsext_ticklen = os.length;
666 os.data = NULL;
667 os.length = 0;
668 } else
669 ret->tlsext_tick = NULL;
670
671 /* 11 - Compression method (OCTET STRING). */
672 /* 12 - SRP username (OCTET STRING). */
673
674 if (!asn1_const_Finish(&c)) {
675 SSLerr(SSL_F_D2I_SSL_SESSION, ERR_R_NESTED_ASN1_ERROR);
676 goto err;
677 }
678
679 *pp = c.p;
680 if (a != NULL)
681 *a = ret;
682
683 return (ret);
684
685err:
686 ERR_asprintf_error_data("offset=%d", (int)(c.q - *pp));
687 if (ret != NULL && (a == NULL || *a != ret))
688 SSL_SESSION_free(ret);
689
690 return (NULL);
691}
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index 7e92812e56..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,722 +0,0 @@
1/* $OpenBSD: ssl_cert.c,v 1.52 2016/03/11 07:08:45 mmcc Exp $ */
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-2007 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 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116
117#include <sys/types.h>
118
119#include <dirent.h>
120#include <stdio.h>
121#include <unistd.h>
122
123#include <openssl/bio.h>
124#include <openssl/bn.h>
125#include <openssl/dh.h>
126#include <openssl/objects.h>
127#include <openssl/opensslconf.h>
128#include <openssl/pem.h>
129#include <openssl/x509v3.h>
130
131#include "ssl_locl.h"
132
133int
134SSL_get_ex_data_X509_STORE_CTX_idx(void)
135{
136 static volatile int ssl_x509_store_ctx_idx = -1;
137 int got_write_lock = 0;
138
139 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
140
141 if (ssl_x509_store_ctx_idx < 0) {
142 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
143 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
144 got_write_lock = 1;
145
146 if (ssl_x509_store_ctx_idx < 0) {
147 ssl_x509_store_ctx_idx =
148 X509_STORE_CTX_get_ex_new_index(
149 0, "SSL for verify callback", NULL, NULL, NULL);
150 }
151 }
152
153 if (got_write_lock)
154 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
155 else
156 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
157
158 return ssl_x509_store_ctx_idx;
159}
160
161static void
162ssl_cert_set_default_md(CERT *cert)
163{
164 /* Set digest values to defaults */
165 cert->pkeys[SSL_PKEY_DSA_SIGN].digest = EVP_sha1();
166 cert->pkeys[SSL_PKEY_RSA_SIGN].digest = EVP_sha1();
167 cert->pkeys[SSL_PKEY_RSA_ENC].digest = EVP_sha1();
168 cert->pkeys[SSL_PKEY_ECC].digest = EVP_sha1();
169#ifndef OPENSSL_NO_GOST
170 cert->pkeys[SSL_PKEY_GOST01].digest = EVP_gostr341194();
171#endif
172}
173
174CERT *
175ssl_cert_new(void)
176{
177 CERT *ret;
178
179 ret = calloc(1, sizeof(CERT));
180 if (ret == NULL) {
181 SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE);
182 return (NULL);
183 }
184 ret->key = &(ret->pkeys[SSL_PKEY_RSA_ENC]);
185 ret->references = 1;
186 ssl_cert_set_default_md(ret);
187 return (ret);
188}
189
190CERT *
191ssl_cert_dup(CERT *cert)
192{
193 CERT *ret;
194 int i;
195
196 ret = calloc(1, sizeof(CERT));
197 if (ret == NULL) {
198 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
199 return (NULL);
200 }
201
202 /*
203 * same as ret->key = ret->pkeys + (cert->key - cert->pkeys),
204 * if you find that more readable
205 */
206 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
207
208 ret->valid = cert->valid;
209 ret->mask_k = cert->mask_k;
210 ret->mask_a = cert->mask_a;
211
212 if (cert->dh_tmp != NULL) {
213 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
214 if (ret->dh_tmp == NULL) {
215 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB);
216 goto err;
217 }
218 if (cert->dh_tmp->priv_key) {
219 BIGNUM *b = BN_dup(cert->dh_tmp->priv_key);
220 if (!b) {
221 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
222 goto err;
223 }
224 ret->dh_tmp->priv_key = b;
225 }
226 if (cert->dh_tmp->pub_key) {
227 BIGNUM *b = BN_dup(cert->dh_tmp->pub_key);
228 if (!b) {
229 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
230 goto err;
231 }
232 ret->dh_tmp->pub_key = b;
233 }
234 }
235 ret->dh_tmp_cb = cert->dh_tmp_cb;
236 ret->dh_tmp_auto = cert->dh_tmp_auto;
237
238 if (cert->ecdh_tmp) {
239 ret->ecdh_tmp = EC_KEY_dup(cert->ecdh_tmp);
240 if (ret->ecdh_tmp == NULL) {
241 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_EC_LIB);
242 goto err;
243 }
244 }
245 ret->ecdh_tmp_cb = cert->ecdh_tmp_cb;
246 ret->ecdh_tmp_auto = cert->ecdh_tmp_auto;
247
248 for (i = 0; i < SSL_PKEY_NUM; i++) {
249 if (cert->pkeys[i].x509 != NULL) {
250 ret->pkeys[i].x509 = cert->pkeys[i].x509;
251 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
252 CRYPTO_LOCK_X509);
253 }
254
255 if (cert->pkeys[i].privatekey != NULL) {
256 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
257 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
258 CRYPTO_LOCK_EVP_PKEY);
259
260 switch (i) {
261 /*
262 * If there was anything special to do for
263 * certain types of keys, we'd do it here.
264 * (Nothing at the moment, I think.)
265 */
266
267 case SSL_PKEY_RSA_ENC:
268 case SSL_PKEY_RSA_SIGN:
269 /* We have an RSA key. */
270 break;
271
272 case SSL_PKEY_DSA_SIGN:
273 /* We have a DSA key. */
274 break;
275
276 case SSL_PKEY_DH_RSA:
277 case SSL_PKEY_DH_DSA:
278 /* We have a DH key. */
279 break;
280
281 case SSL_PKEY_ECC:
282 /* We have an ECC key */
283 break;
284
285 default:
286 /* Can't happen. */
287 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
288 }
289 }
290 }
291
292 /*
293 * ret->extra_certs *should* exist, but currently the own certificate
294 * chain is held inside SSL_CTX
295 */
296
297 ret->references = 1;
298 /*
299 * Set digests to defaults. NB: we don't copy existing values
300 * as they will be set during handshake.
301 */
302 ssl_cert_set_default_md(ret);
303
304 return (ret);
305
306err:
307 DH_free(ret->dh_tmp);
308 EC_KEY_free(ret->ecdh_tmp);
309
310 for (i = 0; i < SSL_PKEY_NUM; i++) {
311 X509_free(ret->pkeys[i].x509);
312 EVP_PKEY_free(ret->pkeys[i].privatekey);
313 }
314 free (ret);
315 return NULL;
316}
317
318
319void
320ssl_cert_free(CERT *c)
321{
322 int i;
323
324 if (c == NULL)
325 return;
326
327 i = CRYPTO_add(&c->references, -1, CRYPTO_LOCK_SSL_CERT);
328 if (i > 0)
329 return;
330
331 DH_free(c->dh_tmp);
332 EC_KEY_free(c->ecdh_tmp);
333
334 for (i = 0; i < SSL_PKEY_NUM; i++) {
335 X509_free(c->pkeys[i].x509);
336 EVP_PKEY_free(c->pkeys[i].privatekey);
337 }
338
339 free(c);
340}
341
342int
343ssl_cert_inst(CERT **o)
344{
345 /*
346 * Create a CERT if there isn't already one
347 * (which cannot really happen, as it is initially created in
348 * SSL_CTX_new; but the earlier code usually allows for that one
349 * being non-existant, so we follow that behaviour, as it might
350 * turn out that there actually is a reason for it -- but I'm
351 * not sure that *all* of the existing code could cope with
352 * s->cert being NULL, otherwise we could do without the
353 * initialization in SSL_CTX_new).
354 */
355
356 if (o == NULL) {
357 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
358 return (0);
359 }
360 if (*o == NULL) {
361 if ((*o = ssl_cert_new()) == NULL) {
362 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
363 return (0);
364 }
365 }
366 return (1);
367}
368
369
370SESS_CERT *
371ssl_sess_cert_new(void)
372{
373 SESS_CERT *ret;
374
375 ret = calloc(1, sizeof *ret);
376 if (ret == NULL) {
377 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
378 return NULL;
379 }
380 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
381 ret->references = 1;
382
383 return ret;
384}
385
386void
387ssl_sess_cert_free(SESS_CERT *sc)
388{
389 int i;
390
391 if (sc == NULL)
392 return;
393
394 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
395 if (i > 0)
396 return;
397
398 /* i == 0 */
399 if (sc->cert_chain != NULL)
400 sk_X509_pop_free(sc->cert_chain, X509_free);
401 for (i = 0; i < SSL_PKEY_NUM; i++)
402 X509_free(sc->peer_pkeys[i].x509);
403
404 DH_free(sc->peer_dh_tmp);
405 EC_KEY_free(sc->peer_ecdh_tmp);
406
407 free(sc);
408}
409
410int
411ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk)
412{
413 X509_STORE_CTX ctx;
414 X509 *x;
415 int ret;
416
417 if ((sk == NULL) || (sk_X509_num(sk) == 0))
418 return (0);
419
420 x = sk_X509_value(sk, 0);
421 if (!X509_STORE_CTX_init(&ctx, s->ctx->cert_store, x, sk)) {
422 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN, ERR_R_X509_LIB);
423 return (0);
424 }
425 X509_STORE_CTX_set_ex_data(&ctx,
426 SSL_get_ex_data_X509_STORE_CTX_idx(), s);
427
428 /*
429 * We need to inherit the verify parameters. These can be
430 * determined by the context: if its a server it will verify
431 * SSL client certificates or vice versa.
432 */
433 X509_STORE_CTX_set_default(&ctx,
434 s->server ? "ssl_client" : "ssl_server");
435
436 /*
437 * Anything non-default in "param" should overwrite anything
438 * in the ctx.
439 */
440 X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(&ctx), s->param);
441
442 if (s->verify_callback)
443 X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback);
444
445 if (s->ctx->app_verify_callback != NULL)
446 ret = s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg);
447 else
448 ret = X509_verify_cert(&ctx);
449
450 s->verify_result = ctx.error;
451 X509_STORE_CTX_cleanup(&ctx);
452
453 return (ret);
454}
455
456static void
457set_client_CA_list(STACK_OF(X509_NAME) **ca_list,
458 STACK_OF(X509_NAME) *name_list)
459{
460 if (*ca_list != NULL)
461 sk_X509_NAME_pop_free(*ca_list, X509_NAME_free);
462
463 *ca_list = name_list;
464}
465
466STACK_OF(X509_NAME) *
467SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
468{
469 int i;
470 STACK_OF(X509_NAME) *ret;
471 X509_NAME *name;
472
473 ret = sk_X509_NAME_new_null();
474 for (i = 0; i < sk_X509_NAME_num(sk); i++) {
475 name = X509_NAME_dup(sk_X509_NAME_value(sk, i));
476 if ((name == NULL) || !sk_X509_NAME_push(ret, name)) {
477 sk_X509_NAME_pop_free(ret, X509_NAME_free);
478 return (NULL);
479 }
480 }
481 return (ret);
482}
483
484void
485SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list)
486{
487 set_client_CA_list(&(s->client_CA), name_list);
488}
489
490void
491SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list)
492{
493 set_client_CA_list(&(ctx->client_CA), name_list);
494}
495
496STACK_OF(X509_NAME) *
497SSL_CTX_get_client_CA_list(const SSL_CTX *ctx)
498{
499 return (ctx->client_CA);
500}
501
502STACK_OF(X509_NAME) *
503SSL_get_client_CA_list(const SSL *s)
504{
505 if (s->type == SSL_ST_CONNECT) {
506 /* We are in the client. */
507 if (((s->version >> 8) == SSL3_VERSION_MAJOR) &&
508 (s->s3 != NULL))
509 return (s->s3->tmp.ca_names);
510 else
511 return (NULL);
512 } else {
513 if (s->client_CA != NULL)
514 return (s->client_CA);
515 else
516 return (s->ctx->client_CA);
517 }
518}
519
520static int
521add_client_CA(STACK_OF(X509_NAME) **sk, X509 *x)
522{
523 X509_NAME *name;
524
525 if (x == NULL)
526 return (0);
527 if ((*sk == NULL) && ((*sk = sk_X509_NAME_new_null()) == NULL))
528 return (0);
529
530 if ((name = X509_NAME_dup(X509_get_subject_name(x))) == NULL)
531 return (0);
532
533 if (!sk_X509_NAME_push(*sk, name)) {
534 X509_NAME_free(name);
535 return (0);
536 }
537 return (1);
538}
539
540int
541SSL_add_client_CA(SSL *ssl, X509 *x)
542{
543 return (add_client_CA(&(ssl->client_CA), x));
544}
545
546int
547SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x)
548{
549 return (add_client_CA(&(ctx->client_CA), x));
550}
551
552static int
553xname_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
554{
555 return (X509_NAME_cmp(*a, *b));
556}
557
558/*!
559 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
560 * it doesn't really have anything to do with clients (except that a common use
561 * for a stack of CAs is to send it to the client). Actually, it doesn't have
562 * much to do with CAs, either, since it will load any old cert.
563 * \param file the file containing one or more certs.
564 * \return a ::STACK containing the certs.
565 */
566STACK_OF(X509_NAME) *
567SSL_load_client_CA_file(const char *file)
568{
569 BIO *in;
570 X509 *x = NULL;
571 X509_NAME *xn = NULL;
572 STACK_OF(X509_NAME) *ret = NULL, *sk;
573
574 sk = sk_X509_NAME_new(xname_cmp);
575
576 in = BIO_new(BIO_s_file_internal());
577
578 if ((sk == NULL) || (in == NULL)) {
579 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE, ERR_R_MALLOC_FAILURE);
580 goto err;
581 }
582
583 if (!BIO_read_filename(in, file))
584 goto err;
585
586 for (;;) {
587 if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL)
588 break;
589 if (ret == NULL) {
590 ret = sk_X509_NAME_new_null();
591 if (ret == NULL) {
592 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,
593 ERR_R_MALLOC_FAILURE);
594 goto err;
595 }
596 }
597 if ((xn = X509_get_subject_name(x)) == NULL) goto err;
598 /* check for duplicates */
599 xn = X509_NAME_dup(xn);
600 if (xn == NULL)
601 goto err;
602 if (sk_X509_NAME_find(sk, xn) >= 0)
603 X509_NAME_free(xn);
604 else {
605 sk_X509_NAME_push(sk, xn);
606 sk_X509_NAME_push(ret, xn);
607 }
608 }
609
610 if (0) {
611err:
612 if (ret != NULL)
613 sk_X509_NAME_pop_free(ret, X509_NAME_free);
614 ret = NULL;
615 }
616 if (sk != NULL)
617 sk_X509_NAME_free(sk);
618 BIO_free(in);
619 X509_free(x);
620 if (ret != NULL)
621 ERR_clear_error();
622 return (ret);
623}
624
625/*!
626 * Add a file of certs to a stack.
627 * \param stack the stack to add to.
628 * \param file the file to add from. All certs in this file that are not
629 * already in the stack will be added.
630 * \return 1 for success, 0 for failure. Note that in the case of failure some
631 * certs may have been added to \c stack.
632 */
633
634int
635SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
636 const char *file)
637{
638 BIO *in;
639 X509 *x = NULL;
640 X509_NAME *xn = NULL;
641 int ret = 1;
642 int (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b);
643
644 oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_cmp);
645
646 in = BIO_new(BIO_s_file_internal());
647
648 if (in == NULL) {
649 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,
650 ERR_R_MALLOC_FAILURE);
651 goto err;
652 }
653
654 if (!BIO_read_filename(in, file))
655 goto err;
656
657 for (;;) {
658 if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL)
659 break;
660 if ((xn = X509_get_subject_name(x)) == NULL) goto err;
661 xn = X509_NAME_dup(xn);
662 if (xn == NULL)
663 goto err;
664 if (sk_X509_NAME_find(stack, xn) >= 0)
665 X509_NAME_free(xn);
666 else
667 sk_X509_NAME_push(stack, xn);
668 }
669
670 ERR_clear_error();
671
672 if (0) {
673err:
674 ret = 0;
675 }
676 BIO_free(in);
677 X509_free(x);
678
679 (void)sk_X509_NAME_set_cmp_func(stack, oldcmp);
680
681 return ret;
682}
683
684/*!
685 * Add a directory of certs to a stack.
686 * \param stack the stack to append to.
687 * \param dir the directory to append from. All files in this directory will be
688 * examined as potential certs. Any that are acceptable to
689 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will
690 * be included.
691 * \return 1 for success, 0 for failure. Note that in the case of failure some
692 * certs may have been added to \c stack.
693 */
694
695int
696SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *dir)
697{
698 DIR *dirp = NULL;
699 char *path = NULL;
700 int ret = 0;
701
702 dirp = opendir(dir);
703 if (dirp) {
704 struct dirent *dp;
705 while ((dp = readdir(dirp)) != NULL) {
706 if (asprintf(&path, "%s/%s", dir, dp->d_name) != -1) {
707 ret = SSL_add_file_cert_subjects_to_stack(
708 stack, path);
709 free(path);
710 }
711 if (!ret)
712 break;
713 }
714 (void) closedir(dirp);
715 }
716 if (!ret) {
717 SYSerr(SYS_F_OPENDIR, errno);
718 ERR_asprintf_error_data("opendir ('%s')", dir);
719 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
720 }
721 return ret;
722}
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index 526d98e293..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1798 +0,0 @@
1/* $OpenBSD: ssl_ciph.c,v 1.86 2016/04/28 16:39:45 jsing Exp $ */
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-2007 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 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#include <stdio.h>
144
145#include <openssl/objects.h>
146
147#ifndef OPENSSL_NO_ENGINE
148#include <openssl/engine.h>
149#endif
150
151#include "ssl_locl.h"
152
153#define SSL_ENC_DES_IDX 0
154#define SSL_ENC_3DES_IDX 1
155#define SSL_ENC_RC4_IDX 2
156#define SSL_ENC_IDEA_IDX 3
157#define SSL_ENC_NULL_IDX 4
158#define SSL_ENC_AES128_IDX 5
159#define SSL_ENC_AES256_IDX 6
160#define SSL_ENC_CAMELLIA128_IDX 7
161#define SSL_ENC_CAMELLIA256_IDX 8
162#define SSL_ENC_GOST89_IDX 9
163#define SSL_ENC_AES128GCM_IDX 10
164#define SSL_ENC_AES256GCM_IDX 11
165#define SSL_ENC_NUM_IDX 12
166
167
168static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX] = {
169 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
170};
171
172#define SSL_MD_MD5_IDX 0
173#define SSL_MD_SHA1_IDX 1
174#define SSL_MD_GOST94_IDX 2
175#define SSL_MD_GOST89MAC_IDX 3
176#define SSL_MD_SHA256_IDX 4
177#define SSL_MD_SHA384_IDX 5
178#define SSL_MD_STREEBOG256_IDX 6
179#define SSL_MD_STREEBOG512_IDX 7
180/*Constant SSL_MAX_DIGEST equal to size of digests array should be
181 * defined in the
182 * ssl_locl.h */
183#define SSL_MD_NUM_IDX SSL_MAX_DIGEST
184static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX] = {
185 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
186};
187
188static int ssl_mac_pkey_id[SSL_MD_NUM_IDX] = {
189 EVP_PKEY_HMAC, EVP_PKEY_HMAC, EVP_PKEY_HMAC, EVP_PKEY_GOSTIMIT,
190 EVP_PKEY_HMAC, EVP_PKEY_HMAC, EVP_PKEY_HMAC, EVP_PKEY_HMAC,
191};
192
193static int ssl_mac_secret_size[SSL_MD_NUM_IDX] = {
194 0, 0, 0, 0, 0, 0, 0, 0
195};
196
197static int ssl_handshake_digest_flag[SSL_MD_NUM_IDX] = {
198 SSL_HANDSHAKE_MAC_MD5, SSL_HANDSHAKE_MAC_SHA,
199 SSL_HANDSHAKE_MAC_GOST94, 0, SSL_HANDSHAKE_MAC_SHA256,
200 SSL_HANDSHAKE_MAC_SHA384, SSL_HANDSHAKE_MAC_STREEBOG256,
201 SSL_HANDSHAKE_MAC_STREEBOG512
202};
203
204#define CIPHER_ADD 1
205#define CIPHER_KILL 2
206#define CIPHER_DEL 3
207#define CIPHER_ORD 4
208#define CIPHER_SPECIAL 5
209
210typedef struct cipher_order_st {
211 const SSL_CIPHER *cipher;
212 int active;
213 int dead;
214 struct cipher_order_st *next, *prev;
215} CIPHER_ORDER;
216
217static const SSL_CIPHER cipher_aliases[] = {
218
219 /* "ALL" doesn't include eNULL (must be specifically enabled) */
220 {
221 .name = SSL_TXT_ALL,
222 .algorithm_enc = ~SSL_eNULL,
223 },
224
225 /* "COMPLEMENTOFALL" */
226 {
227 .name = SSL_TXT_CMPALL,
228 .algorithm_enc = SSL_eNULL,
229 },
230
231 /*
232 * "COMPLEMENTOFDEFAULT"
233 * (does *not* include ciphersuites not found in ALL!)
234 */
235 {
236 .name = SSL_TXT_CMPDEF,
237 .algorithm_mkey = SSL_kDHE|SSL_kECDHE,
238 .algorithm_auth = SSL_aNULL,
239 .algorithm_enc = ~SSL_eNULL,
240 },
241
242 /*
243 * key exchange aliases
244 * (some of those using only a single bit here combine multiple key
245 * exchange algs according to the RFCs, e.g. kEDH combines DHE_DSS
246 * and DHE_RSA)
247 */
248 {
249 .name = SSL_TXT_kRSA,
250 .algorithm_mkey = SSL_kRSA,
251 },
252 {
253 .name = SSL_TXT_kEDH,
254 .algorithm_mkey = SSL_kDHE,
255 },
256 {
257 .name = SSL_TXT_DH,
258 .algorithm_mkey = SSL_kDHE,
259 },
260
261 {
262 .name = SSL_TXT_kECDHr,
263 .algorithm_mkey = SSL_kECDHr,
264 },
265 {
266 .name = SSL_TXT_kECDHe,
267 .algorithm_mkey = SSL_kECDHe,
268 },
269 {
270 .name = SSL_TXT_kECDH,
271 .algorithm_mkey = SSL_kECDHr|SSL_kECDHe,
272 },
273 {
274 .name = SSL_TXT_kEECDH,
275 .algorithm_mkey = SSL_kECDHE,
276 },
277 {
278 .name = SSL_TXT_ECDH,
279 .algorithm_mkey = SSL_kECDHr|SSL_kECDHe|SSL_kECDHE,
280 },
281
282 {
283 .name = SSL_TXT_kGOST,
284 .algorithm_mkey = SSL_kGOST,
285 },
286
287 /* server authentication aliases */
288 {
289 .name = SSL_TXT_aRSA,
290 .algorithm_auth = SSL_aRSA,
291 },
292 {
293 .name = SSL_TXT_aDSS,
294 .algorithm_auth = SSL_aDSS,
295 },
296 {
297 .name = SSL_TXT_DSS,
298 .algorithm_auth = SSL_aDSS,
299 },
300 {
301 .name = SSL_TXT_aNULL,
302 .algorithm_auth = SSL_aNULL,
303 },
304 {
305 .name = SSL_TXT_aECDH,
306 .algorithm_auth = SSL_aECDH,
307 },
308 {
309 .name = SSL_TXT_aECDSA,
310 .algorithm_auth = SSL_aECDSA,
311 },
312 {
313 .name = SSL_TXT_ECDSA,
314 .algorithm_auth = SSL_aECDSA,
315 },
316 {
317 .name = SSL_TXT_aGOST01,
318 .algorithm_auth = SSL_aGOST01,
319 },
320 {
321 .name = SSL_TXT_aGOST,
322 .algorithm_auth = SSL_aGOST01,
323 },
324
325 /* aliases combining key exchange and server authentication */
326 {
327 .name = SSL_TXT_DHE,
328 .algorithm_mkey = SSL_kDHE,
329 .algorithm_auth = ~SSL_aNULL,
330 },
331 {
332 .name = SSL_TXT_EDH,
333 .algorithm_mkey = SSL_kDHE,
334 .algorithm_auth = ~SSL_aNULL,
335 },
336 {
337 .name = SSL_TXT_ECDHE,
338 .algorithm_mkey = SSL_kECDHE,
339 .algorithm_auth = ~SSL_aNULL,
340 },
341 {
342 .name = SSL_TXT_EECDH,
343 .algorithm_mkey = SSL_kECDHE,
344 .algorithm_auth = ~SSL_aNULL,
345 },
346 {
347 .name = SSL_TXT_NULL,
348 .algorithm_enc = SSL_eNULL,
349 },
350 {
351 .name = SSL_TXT_RSA,
352 .algorithm_mkey = SSL_kRSA,
353 .algorithm_auth = SSL_aRSA,
354 },
355 {
356 .name = SSL_TXT_ADH,
357 .algorithm_mkey = SSL_kDHE,
358 .algorithm_auth = SSL_aNULL,
359 },
360 {
361 .name = SSL_TXT_AECDH,
362 .algorithm_mkey = SSL_kECDHE,
363 .algorithm_auth = SSL_aNULL,
364 },
365
366 /* symmetric encryption aliases */
367 {
368 .name = SSL_TXT_DES,
369 .algorithm_enc = SSL_DES,
370 },
371 {
372 .name = SSL_TXT_3DES,
373 .algorithm_enc = SSL_3DES,
374 },
375 {
376 .name = SSL_TXT_RC4,
377 .algorithm_enc = SSL_RC4,
378 },
379 {
380 .name = SSL_TXT_IDEA,
381 .algorithm_enc = SSL_IDEA,
382 },
383 {
384 .name = SSL_TXT_eNULL,
385 .algorithm_enc = SSL_eNULL,
386 },
387 {
388 .name = SSL_TXT_AES128,
389 .algorithm_enc = SSL_AES128|SSL_AES128GCM,
390 },
391 {
392 .name = SSL_TXT_AES256,
393 .algorithm_enc = SSL_AES256|SSL_AES256GCM,
394 },
395 {
396 .name = SSL_TXT_AES,
397 .algorithm_enc = SSL_AES,
398 },
399 {
400 .name = SSL_TXT_AES_GCM,
401 .algorithm_enc = SSL_AES128GCM|SSL_AES256GCM,
402 },
403 {
404 .name = SSL_TXT_CAMELLIA128,
405 .algorithm_enc = SSL_CAMELLIA128,
406 },
407 {
408 .name = SSL_TXT_CAMELLIA256,
409 .algorithm_enc = SSL_CAMELLIA256,
410 },
411 {
412 .name = SSL_TXT_CAMELLIA,
413 .algorithm_enc = SSL_CAMELLIA128|SSL_CAMELLIA256,
414 },
415 {
416 .name = SSL_TXT_CHACHA20,
417 .algorithm_enc = SSL_CHACHA20POLY1305|SSL_CHACHA20POLY1305_OLD,
418 },
419
420 /* MAC aliases */
421 {
422 .name = SSL_TXT_AEAD,
423 .algorithm_mac = SSL_AEAD,
424 },
425 {
426 .name = SSL_TXT_MD5,
427 .algorithm_mac = SSL_MD5,
428 },
429 {
430 .name = SSL_TXT_SHA1,
431 .algorithm_mac = SSL_SHA1,
432 },
433 {
434 .name = SSL_TXT_SHA,
435 .algorithm_mac = SSL_SHA1,
436 },
437 {
438 .name = SSL_TXT_GOST94,
439 .algorithm_mac = SSL_GOST94,
440 },
441 {
442 .name = SSL_TXT_GOST89MAC,
443 .algorithm_mac = SSL_GOST89MAC,
444 },
445 {
446 .name = SSL_TXT_SHA256,
447 .algorithm_mac = SSL_SHA256,
448 },
449 {
450 .name = SSL_TXT_SHA384,
451 .algorithm_mac = SSL_SHA384,
452 },
453 {
454 .name = SSL_TXT_STREEBOG256,
455 .algorithm_mac = SSL_STREEBOG256,
456 },
457 {
458 .name = SSL_TXT_STREEBOG512,
459 .algorithm_mac = SSL_STREEBOG512,
460 },
461
462 /* protocol version aliases */
463 {
464 .name = SSL_TXT_SSLV3,
465 .algorithm_ssl = SSL_SSLV3,
466 },
467 {
468 .name = SSL_TXT_TLSV1,
469 .algorithm_ssl = SSL_TLSV1,
470 },
471 {
472 .name = SSL_TXT_TLSV1_2,
473 .algorithm_ssl = SSL_TLSV1_2,
474 },
475
476 /* strength classes */
477 {
478 .name = SSL_TXT_LOW,
479 .algo_strength = SSL_LOW,
480 },
481 {
482 .name = SSL_TXT_MEDIUM,
483 .algo_strength = SSL_MEDIUM,
484 },
485 {
486 .name = SSL_TXT_HIGH,
487 .algo_strength = SSL_HIGH,
488 },
489};
490
491void
492ssl_load_ciphers(void)
493{
494 ssl_cipher_methods[SSL_ENC_DES_IDX] =
495 EVP_get_cipherbyname(SN_des_cbc);
496 ssl_cipher_methods[SSL_ENC_3DES_IDX] =
497 EVP_get_cipherbyname(SN_des_ede3_cbc);
498 ssl_cipher_methods[SSL_ENC_RC4_IDX] =
499 EVP_get_cipherbyname(SN_rc4);
500#ifndef OPENSSL_NO_IDEA
501 ssl_cipher_methods[SSL_ENC_IDEA_IDX] =
502 EVP_get_cipherbyname(SN_idea_cbc);
503#else
504 ssl_cipher_methods[SSL_ENC_IDEA_IDX] = NULL;
505#endif
506 ssl_cipher_methods[SSL_ENC_AES128_IDX] =
507 EVP_get_cipherbyname(SN_aes_128_cbc);
508 ssl_cipher_methods[SSL_ENC_AES256_IDX] =
509 EVP_get_cipherbyname(SN_aes_256_cbc);
510 ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX] =
511 EVP_get_cipherbyname(SN_camellia_128_cbc);
512 ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX] =
513 EVP_get_cipherbyname(SN_camellia_256_cbc);
514 ssl_cipher_methods[SSL_ENC_GOST89_IDX] =
515 EVP_get_cipherbyname(SN_gost89_cnt);
516
517 ssl_cipher_methods[SSL_ENC_AES128GCM_IDX] =
518 EVP_get_cipherbyname(SN_aes_128_gcm);
519 ssl_cipher_methods[SSL_ENC_AES256GCM_IDX] =
520 EVP_get_cipherbyname(SN_aes_256_gcm);
521
522 ssl_digest_methods[SSL_MD_MD5_IDX] =
523 EVP_get_digestbyname(SN_md5);
524 ssl_mac_secret_size[SSL_MD_MD5_IDX] =
525 EVP_MD_size(ssl_digest_methods[SSL_MD_MD5_IDX]);
526 OPENSSL_assert(ssl_mac_secret_size[SSL_MD_MD5_IDX] >= 0);
527 ssl_digest_methods[SSL_MD_SHA1_IDX] =
528 EVP_get_digestbyname(SN_sha1);
529 ssl_mac_secret_size[SSL_MD_SHA1_IDX] =
530 EVP_MD_size(ssl_digest_methods[SSL_MD_SHA1_IDX]);
531 OPENSSL_assert(ssl_mac_secret_size[SSL_MD_SHA1_IDX] >= 0);
532 ssl_digest_methods[SSL_MD_GOST94_IDX] =
533 EVP_get_digestbyname(SN_id_GostR3411_94);
534 if (ssl_digest_methods[SSL_MD_GOST94_IDX]) {
535 ssl_mac_secret_size[SSL_MD_GOST94_IDX] =
536 EVP_MD_size(ssl_digest_methods[SSL_MD_GOST94_IDX]);
537 OPENSSL_assert(ssl_mac_secret_size[SSL_MD_GOST94_IDX] >= 0);
538 }
539 ssl_digest_methods[SSL_MD_GOST89MAC_IDX] =
540 EVP_get_digestbyname(SN_id_Gost28147_89_MAC);
541 if (ssl_mac_pkey_id[SSL_MD_GOST89MAC_IDX]) {
542 ssl_mac_secret_size[SSL_MD_GOST89MAC_IDX] = 32;
543 }
544
545 ssl_digest_methods[SSL_MD_SHA256_IDX] =
546 EVP_get_digestbyname(SN_sha256);
547 ssl_mac_secret_size[SSL_MD_SHA256_IDX] =
548 EVP_MD_size(ssl_digest_methods[SSL_MD_SHA256_IDX]);
549 ssl_digest_methods[SSL_MD_SHA384_IDX] =
550 EVP_get_digestbyname(SN_sha384);
551 ssl_mac_secret_size[SSL_MD_SHA384_IDX] =
552 EVP_MD_size(ssl_digest_methods[SSL_MD_SHA384_IDX]);
553 ssl_digest_methods[SSL_MD_STREEBOG256_IDX] =
554 EVP_get_digestbyname(SN_id_tc26_gost3411_2012_256);
555 ssl_mac_secret_size[SSL_MD_STREEBOG256_IDX] =
556 EVP_MD_size(ssl_digest_methods[SSL_MD_STREEBOG256_IDX]);
557 ssl_digest_methods[SSL_MD_STREEBOG512_IDX] =
558 EVP_get_digestbyname(SN_id_tc26_gost3411_2012_512);
559 ssl_mac_secret_size[SSL_MD_STREEBOG512_IDX] =
560 EVP_MD_size(ssl_digest_methods[SSL_MD_STREEBOG512_IDX]);
561}
562
563int
564ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
565 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size)
566{
567 const SSL_CIPHER *c;
568 int i;
569
570 c = s->cipher;
571 if (c == NULL)
572 return (0);
573
574 /*
575 * This function does not handle EVP_AEAD.
576 * See ssl_cipher_get_aead_evp instead.
577 */
578 if (c->algorithm2 & SSL_CIPHER_ALGORITHM2_AEAD)
579 return(0);
580
581 if ((enc == NULL) || (md == NULL))
582 return (0);
583
584 switch (c->algorithm_enc) {
585 case SSL_DES:
586 i = SSL_ENC_DES_IDX;
587 break;
588 case SSL_3DES:
589 i = SSL_ENC_3DES_IDX;
590 break;
591 case SSL_RC4:
592 i = SSL_ENC_RC4_IDX;
593 break;
594 case SSL_IDEA:
595 i = SSL_ENC_IDEA_IDX;
596 break;
597 case SSL_eNULL:
598 i = SSL_ENC_NULL_IDX;
599 break;
600 case SSL_AES128:
601 i = SSL_ENC_AES128_IDX;
602 break;
603 case SSL_AES256:
604 i = SSL_ENC_AES256_IDX;
605 break;
606 case SSL_CAMELLIA128:
607 i = SSL_ENC_CAMELLIA128_IDX;
608 break;
609 case SSL_CAMELLIA256:
610 i = SSL_ENC_CAMELLIA256_IDX;
611 break;
612 case SSL_eGOST2814789CNT:
613 i = SSL_ENC_GOST89_IDX;
614 break;
615 case SSL_AES128GCM:
616 i = SSL_ENC_AES128GCM_IDX;
617 break;
618 case SSL_AES256GCM:
619 i = SSL_ENC_AES256GCM_IDX;
620 break;
621 default:
622 i = -1;
623 break;
624 }
625
626 if ((i < 0) || (i >= SSL_ENC_NUM_IDX))
627 *enc = NULL;
628 else {
629 if (i == SSL_ENC_NULL_IDX)
630 *enc = EVP_enc_null();
631 else
632 *enc = ssl_cipher_methods[i];
633 }
634
635 switch (c->algorithm_mac) {
636 case SSL_MD5:
637 i = SSL_MD_MD5_IDX;
638 break;
639 case SSL_SHA1:
640 i = SSL_MD_SHA1_IDX;
641 break;
642 case SSL_SHA256:
643 i = SSL_MD_SHA256_IDX;
644 break;
645 case SSL_SHA384:
646 i = SSL_MD_SHA384_IDX;
647 break;
648 case SSL_GOST94:
649 i = SSL_MD_GOST94_IDX;
650 break;
651 case SSL_GOST89MAC:
652 i = SSL_MD_GOST89MAC_IDX;
653 break;
654 case SSL_STREEBOG256:
655 i = SSL_MD_STREEBOG256_IDX;
656 break;
657 case SSL_STREEBOG512:
658 i = SSL_MD_STREEBOG512_IDX;
659 break;
660 default:
661 i = -1;
662 break;
663 }
664 if ((i < 0) || (i >= SSL_MD_NUM_IDX)) {
665 *md = NULL;
666
667 if (mac_pkey_type != NULL)
668 *mac_pkey_type = NID_undef;
669 if (mac_secret_size != NULL)
670 *mac_secret_size = 0;
671 if (c->algorithm_mac == SSL_AEAD)
672 mac_pkey_type = NULL;
673 } else {
674 *md = ssl_digest_methods[i];
675 if (mac_pkey_type != NULL)
676 *mac_pkey_type = ssl_mac_pkey_id[i];
677 if (mac_secret_size != NULL)
678 *mac_secret_size = ssl_mac_secret_size[i];
679 }
680
681 if ((*enc != NULL) &&
682 (*md != NULL || (EVP_CIPHER_flags(*enc)&EVP_CIPH_FLAG_AEAD_CIPHER)) &&
683 (!mac_pkey_type || *mac_pkey_type != NID_undef)) {
684 const EVP_CIPHER *evp;
685
686 if (s->ssl_version >> 8 != TLS1_VERSION_MAJOR ||
687 s->ssl_version < TLS1_VERSION)
688 return 1;
689
690 if (c->algorithm_enc == SSL_RC4 &&
691 c->algorithm_mac == SSL_MD5 &&
692 (evp = EVP_get_cipherbyname("RC4-HMAC-MD5")))
693 *enc = evp, *md = NULL;
694 else if (c->algorithm_enc == SSL_AES128 &&
695 c->algorithm_mac == SSL_SHA1 &&
696 (evp = EVP_get_cipherbyname("AES-128-CBC-HMAC-SHA1")))
697 *enc = evp, *md = NULL;
698 else if (c->algorithm_enc == SSL_AES256 &&
699 c->algorithm_mac == SSL_SHA1 &&
700 (evp = EVP_get_cipherbyname("AES-256-CBC-HMAC-SHA1")))
701 *enc = evp, *md = NULL;
702 return (1);
703 } else
704 return (0);
705}
706
707/*
708 * ssl_cipher_get_evp_aead sets aead to point to the correct EVP_AEAD object
709 * for s->cipher. It returns 1 on success and 0 on error.
710 */
711int
712ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead)
713{
714 const SSL_CIPHER *c = s->cipher;
715
716 *aead = NULL;
717
718 if (c == NULL)
719 return 0;
720 if ((c->algorithm2 & SSL_CIPHER_ALGORITHM2_AEAD) == 0)
721 return 0;
722
723 switch (c->algorithm_enc) {
724#ifndef OPENSSL_NO_AES
725 case SSL_AES128GCM:
726 *aead = EVP_aead_aes_128_gcm();
727 return 1;
728 case SSL_AES256GCM:
729 *aead = EVP_aead_aes_256_gcm();
730 return 1;
731#endif
732#if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
733 case SSL_CHACHA20POLY1305:
734 *aead = EVP_aead_chacha20_poly1305();
735 return 1;
736 case SSL_CHACHA20POLY1305_OLD:
737 *aead = EVP_aead_chacha20_poly1305_old();
738 return 1;
739#endif
740 default:
741 break;
742 }
743 return 0;
744}
745
746int
747ssl_get_handshake_digest(int idx, long *mask, const EVP_MD **md)
748{
749 if (idx < 0 || idx >= SSL_MD_NUM_IDX) {
750 return 0;
751 }
752 *mask = ssl_handshake_digest_flag[idx];
753 if (*mask)
754 *md = ssl_digest_methods[idx];
755 else
756 *md = NULL;
757 return 1;
758}
759
760#define ITEM_SEP(a) \
761 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
762
763static void
764ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
765 CIPHER_ORDER **tail)
766{
767 if (curr == *tail)
768 return;
769 if (curr == *head)
770 *head = curr->next;
771 if (curr->prev != NULL)
772 curr->prev->next = curr->next;
773 if (curr->next != NULL)
774 curr->next->prev = curr->prev;
775 (*tail)->next = curr;
776 curr->prev= *tail;
777 curr->next = NULL;
778 *tail = curr;
779}
780
781static void
782ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr,
783 CIPHER_ORDER **tail)
784{
785 if (curr == *head)
786 return;
787 if (curr == *tail)
788 *tail = curr->prev;
789 if (curr->next != NULL)
790 curr->next->prev = curr->prev;
791 if (curr->prev != NULL)
792 curr->prev->next = curr->next;
793 (*head)->prev = curr;
794 curr->next= *head;
795 curr->prev = NULL;
796 *head = curr;
797}
798
799static void
800ssl_cipher_get_disabled(unsigned long *mkey, unsigned long *auth,
801 unsigned long *enc, unsigned long *mac, unsigned long *ssl)
802{
803 *mkey = 0;
804 *auth = 0;
805 *enc = 0;
806 *mac = 0;
807 *ssl = 0;
808
809 /*
810 * Check for the availability of GOST 34.10 public/private key
811 * algorithms. If they are not available disable the associated
812 * authentication and key exchange algorithms.
813 */
814 if (EVP_PKEY_meth_find(NID_id_GostR3410_2001) == NULL) {
815 *auth |= SSL_aGOST01;
816 *mkey |= SSL_kGOST;
817 }
818
819#ifdef SSL_FORBID_ENULL
820 *enc |= SSL_eNULL;
821#endif
822
823 *enc |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES : 0;
824 *enc |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES : 0;
825 *enc |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 : 0;
826 *enc |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA : 0;
827 *enc |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES128 : 0;
828 *enc |= (ssl_cipher_methods[SSL_ENC_AES256_IDX] == NULL) ? SSL_AES256 : 0;
829 *enc |= (ssl_cipher_methods[SSL_ENC_AES128GCM_IDX] == NULL) ? SSL_AES128GCM : 0;
830 *enc |= (ssl_cipher_methods[SSL_ENC_AES256GCM_IDX] == NULL) ? SSL_AES256GCM : 0;
831 *enc |= (ssl_cipher_methods[SSL_ENC_CAMELLIA128_IDX] == NULL) ? SSL_CAMELLIA128 : 0;
832 *enc |= (ssl_cipher_methods[SSL_ENC_CAMELLIA256_IDX] == NULL) ? SSL_CAMELLIA256 : 0;
833 *enc |= (ssl_cipher_methods[SSL_ENC_GOST89_IDX] == NULL) ? SSL_eGOST2814789CNT : 0;
834
835 *mac |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 : 0;
836 *mac |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1 : 0;
837 *mac |= (ssl_digest_methods[SSL_MD_SHA256_IDX] == NULL) ? SSL_SHA256 : 0;
838 *mac |= (ssl_digest_methods[SSL_MD_SHA384_IDX] == NULL) ? SSL_SHA384 : 0;
839 *mac |= (ssl_digest_methods[SSL_MD_GOST94_IDX] == NULL) ? SSL_GOST94 : 0;
840 *mac |= (ssl_digest_methods[SSL_MD_GOST89MAC_IDX] == NULL) ? SSL_GOST89MAC : 0;
841 *mac |= (ssl_digest_methods[SSL_MD_STREEBOG256_IDX] == NULL) ? SSL_STREEBOG256 : 0;
842 *mac |= (ssl_digest_methods[SSL_MD_STREEBOG512_IDX] == NULL) ? SSL_STREEBOG512 : 0;
843
844}
845
846static void
847ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, int num_of_ciphers,
848 unsigned long disabled_mkey, unsigned long disabled_auth,
849 unsigned long disabled_enc, unsigned long disabled_mac,
850 unsigned long disabled_ssl, CIPHER_ORDER *co_list,
851 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
852{
853 int i, co_list_num;
854 const SSL_CIPHER *c;
855
856 /*
857 * We have num_of_ciphers descriptions compiled in, depending on the
858 * method selected (SSLv3, TLSv1, etc). These will later be sorted in
859 * a linked list with at most num entries.
860 */
861
862 /* Get the initial list of ciphers */
863 co_list_num = 0; /* actual count of ciphers */
864 for (i = 0; i < num_of_ciphers; i++) {
865 c = ssl_method->get_cipher(i);
866 /* drop those that use any of that is not available */
867 if ((c != NULL) && c->valid &&
868 !(c->algorithm_mkey & disabled_mkey) &&
869 !(c->algorithm_auth & disabled_auth) &&
870 !(c->algorithm_enc & disabled_enc) &&
871 !(c->algorithm_mac & disabled_mac) &&
872 !(c->algorithm_ssl & disabled_ssl)) {
873 co_list[co_list_num].cipher = c;
874 co_list[co_list_num].next = NULL;
875 co_list[co_list_num].prev = NULL;
876 co_list[co_list_num].active = 0;
877 co_list_num++;
878 /*
879 if (!sk_push(ca_list,(char *)c)) goto err;
880 */
881 }
882 }
883
884 /*
885 * Prepare linked list from list entries
886 */
887 if (co_list_num > 0) {
888 co_list[0].prev = NULL;
889
890 if (co_list_num > 1) {
891 co_list[0].next = &co_list[1];
892
893 for (i = 1; i < co_list_num - 1; i++) {
894 co_list[i].prev = &co_list[i - 1];
895 co_list[i].next = &co_list[i + 1];
896 }
897
898 co_list[co_list_num - 1].prev =
899 &co_list[co_list_num - 2];
900 }
901
902 co_list[co_list_num - 1].next = NULL;
903
904 *head_p = &co_list[0];
905 *tail_p = &co_list[co_list_num - 1];
906 }
907}
908
909static void
910ssl_cipher_collect_aliases(const SSL_CIPHER **ca_list, int num_of_group_aliases,
911 unsigned long disabled_mkey, unsigned long disabled_auth,
912 unsigned long disabled_enc, unsigned long disabled_mac,
913 unsigned long disabled_ssl, CIPHER_ORDER *head)
914{
915 CIPHER_ORDER *ciph_curr;
916 const SSL_CIPHER **ca_curr;
917 int i;
918 unsigned long mask_mkey = ~disabled_mkey;
919 unsigned long mask_auth = ~disabled_auth;
920 unsigned long mask_enc = ~disabled_enc;
921 unsigned long mask_mac = ~disabled_mac;
922 unsigned long mask_ssl = ~disabled_ssl;
923
924 /*
925 * First, add the real ciphers as already collected
926 */
927 ciph_curr = head;
928 ca_curr = ca_list;
929 while (ciph_curr != NULL) {
930 *ca_curr = ciph_curr->cipher;
931 ca_curr++;
932 ciph_curr = ciph_curr->next;
933 }
934
935 /*
936 * Now we add the available ones from the cipher_aliases[] table.
937 * They represent either one or more algorithms, some of which
938 * in any affected category must be supported (set in enabled_mask),
939 * or represent a cipher strength value (will be added in any case because algorithms=0).
940 */
941 for (i = 0; i < num_of_group_aliases; i++) {
942 unsigned long algorithm_mkey = cipher_aliases[i].algorithm_mkey;
943 unsigned long algorithm_auth = cipher_aliases[i].algorithm_auth;
944 unsigned long algorithm_enc = cipher_aliases[i].algorithm_enc;
945 unsigned long algorithm_mac = cipher_aliases[i].algorithm_mac;
946 unsigned long algorithm_ssl = cipher_aliases[i].algorithm_ssl;
947
948 if (algorithm_mkey)
949 if ((algorithm_mkey & mask_mkey) == 0)
950 continue;
951
952 if (algorithm_auth)
953 if ((algorithm_auth & mask_auth) == 0)
954 continue;
955
956 if (algorithm_enc)
957 if ((algorithm_enc & mask_enc) == 0)
958 continue;
959
960 if (algorithm_mac)
961 if ((algorithm_mac & mask_mac) == 0)
962 continue;
963
964 if (algorithm_ssl)
965 if ((algorithm_ssl & mask_ssl) == 0)
966 continue;
967
968 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
969 ca_curr++;
970 }
971
972 *ca_curr = NULL; /* end of list */
973}
974
975static void
976ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long alg_mkey,
977 unsigned long alg_auth, unsigned long alg_enc, unsigned long alg_mac,
978 unsigned long alg_ssl, unsigned long algo_strength,
979 int rule, int strength_bits, CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
980{
981 CIPHER_ORDER *head, *tail, *curr, *next, *last;
982 const SSL_CIPHER *cp;
983 int reverse = 0;
984
985
986 if (rule == CIPHER_DEL)
987 reverse = 1; /* needed to maintain sorting between currently deleted ciphers */
988
989 head = *head_p;
990 tail = *tail_p;
991
992 if (reverse) {
993 next = tail;
994 last = head;
995 } else {
996 next = head;
997 last = tail;
998 }
999
1000 curr = NULL;
1001 for (;;) {
1002 if (curr == last)
1003 break;
1004 curr = next;
1005 next = reverse ? curr->prev : curr->next;
1006
1007 cp = curr->cipher;
1008
1009 /*
1010 * Selection criteria is either the value of strength_bits
1011 * or the algorithms used.
1012 */
1013 if (strength_bits >= 0) {
1014 if (strength_bits != cp->strength_bits)
1015 continue;
1016 } else {
1017
1018 if (alg_mkey && !(alg_mkey & cp->algorithm_mkey))
1019 continue;
1020 if (alg_auth && !(alg_auth & cp->algorithm_auth))
1021 continue;
1022 if (alg_enc && !(alg_enc & cp->algorithm_enc))
1023 continue;
1024 if (alg_mac && !(alg_mac & cp->algorithm_mac))
1025 continue;
1026 if (alg_ssl && !(alg_ssl & cp->algorithm_ssl))
1027 continue;
1028 if ((algo_strength & SSL_STRONG_MASK) && !(algo_strength & SSL_STRONG_MASK & cp->algo_strength))
1029 continue;
1030 }
1031
1032
1033 /* add the cipher if it has not been added yet. */
1034 if (rule == CIPHER_ADD) {
1035 /* reverse == 0 */
1036 if (!curr->active) {
1037 ll_append_tail(&head, curr, &tail);
1038 curr->active = 1;
1039 }
1040 }
1041 /* Move the added cipher to this location */
1042 else if (rule == CIPHER_ORD) {
1043 /* reverse == 0 */
1044 if (curr->active) {
1045 ll_append_tail(&head, curr, &tail);
1046 }
1047 } else if (rule == CIPHER_DEL) {
1048 /* reverse == 1 */
1049 if (curr->active) {
1050 /* most recently deleted ciphersuites get best positions
1051 * for any future CIPHER_ADD (note that the CIPHER_DEL loop
1052 * works in reverse to maintain the order) */
1053 ll_append_head(&head, curr, &tail);
1054 curr->active = 0;
1055 }
1056 } else if (rule == CIPHER_KILL) {
1057 /* reverse == 0 */
1058 if (head == curr)
1059 head = curr->next;
1060 else
1061 curr->prev->next = curr->next;
1062 if (tail == curr)
1063 tail = curr->prev;
1064 curr->active = 0;
1065 if (curr->next != NULL)
1066 curr->next->prev = curr->prev;
1067 if (curr->prev != NULL)
1068 curr->prev->next = curr->next;
1069 curr->next = NULL;
1070 curr->prev = NULL;
1071 }
1072 }
1073
1074 *head_p = head;
1075 *tail_p = tail;
1076}
1077
1078static int
1079ssl_cipher_strength_sort(CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
1080{
1081 int max_strength_bits, i, *number_uses;
1082 CIPHER_ORDER *curr;
1083
1084 /*
1085 * This routine sorts the ciphers with descending strength. The sorting
1086 * must keep the pre-sorted sequence, so we apply the normal sorting
1087 * routine as '+' movement to the end of the list.
1088 */
1089 max_strength_bits = 0;
1090 curr = *head_p;
1091 while (curr != NULL) {
1092 if (curr->active &&
1093 (curr->cipher->strength_bits > max_strength_bits))
1094 max_strength_bits = curr->cipher->strength_bits;
1095 curr = curr->next;
1096 }
1097
1098 number_uses = calloc((max_strength_bits + 1), sizeof(int));
1099 if (!number_uses) {
1100 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE);
1101 return (0);
1102 }
1103
1104 /*
1105 * Now find the strength_bits values actually used
1106 */
1107 curr = *head_p;
1108 while (curr != NULL) {
1109 if (curr->active)
1110 number_uses[curr->cipher->strength_bits]++;
1111 curr = curr->next;
1112 }
1113 /*
1114 * Go through the list of used strength_bits values in descending
1115 * order.
1116 */
1117 for (i = max_strength_bits; i >= 0; i--)
1118 if (number_uses[i] > 0)
1119 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ORD, i, head_p, tail_p);
1120
1121 free(number_uses);
1122 return (1);
1123}
1124
1125static int
1126ssl_cipher_process_rulestr(const char *rule_str, CIPHER_ORDER **head_p,
1127 CIPHER_ORDER **tail_p, const SSL_CIPHER **ca_list)
1128{
1129 unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl;
1130 unsigned long algo_strength;
1131 int j, multi, found, rule, retval, ok, buflen;
1132 unsigned long cipher_id = 0;
1133 const char *l, *buf;
1134 char ch;
1135
1136 retval = 1;
1137 l = rule_str;
1138 for (;;) {
1139 ch = *l;
1140
1141 if (ch == '\0')
1142 break;
1143
1144 if (ch == '-') {
1145 rule = CIPHER_DEL;
1146 l++;
1147 } else if (ch == '+') {
1148 rule = CIPHER_ORD;
1149 l++;
1150 } else if (ch == '!') {
1151 rule = CIPHER_KILL;
1152 l++;
1153 } else if (ch == '@') {
1154 rule = CIPHER_SPECIAL;
1155 l++;
1156 } else {
1157 rule = CIPHER_ADD;
1158 }
1159
1160 if (ITEM_SEP(ch)) {
1161 l++;
1162 continue;
1163 }
1164
1165 alg_mkey = 0;
1166 alg_auth = 0;
1167 alg_enc = 0;
1168 alg_mac = 0;
1169 alg_ssl = 0;
1170 algo_strength = 0;
1171
1172 for (;;) {
1173 ch = *l;
1174 buf = l;
1175 buflen = 0;
1176 while (((ch >= 'A') && (ch <= 'Z')) ||
1177 ((ch >= '0') && (ch <= '9')) ||
1178 ((ch >= 'a') && (ch <= 'z')) ||
1179 (ch == '-') || (ch == '.')) {
1180 ch = *(++l);
1181 buflen++;
1182 }
1183
1184 if (buflen == 0) {
1185 /*
1186 * We hit something we cannot deal with,
1187 * it is no command or separator nor
1188 * alphanumeric, so we call this an error.
1189 */
1190 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
1191 SSL_R_INVALID_COMMAND);
1192 retval = found = 0;
1193 l++;
1194 break;
1195 }
1196
1197 if (rule == CIPHER_SPECIAL) {
1198 /* unused -- avoid compiler warning */
1199 found = 0;
1200 /* special treatment */
1201 break;
1202 }
1203
1204 /* check for multi-part specification */
1205 if (ch == '+') {
1206 multi = 1;
1207 l++;
1208 } else
1209 multi = 0;
1210
1211 /*
1212 * Now search for the cipher alias in the ca_list.
1213 * Be careful with the strncmp, because the "buflen"
1214 * limitation will make the rule "ADH:SOME" and the
1215 * cipher "ADH-MY-CIPHER" look like a match for
1216 * buflen=3. So additionally check whether the cipher
1217 * name found has the correct length. We can save a
1218 * strlen() call: just checking for the '\0' at the
1219 * right place is sufficient, we have to strncmp()
1220 * anyway (we cannot use strcmp(), because buf is not
1221 * '\0' terminated.)
1222 */
1223 j = found = 0;
1224 cipher_id = 0;
1225 while (ca_list[j]) {
1226 if (!strncmp(buf, ca_list[j]->name, buflen) &&
1227 (ca_list[j]->name[buflen] == '\0')) {
1228 found = 1;
1229 break;
1230 } else
1231 j++;
1232 }
1233
1234 if (!found)
1235 break; /* ignore this entry */
1236
1237 if (ca_list[j]->algorithm_mkey) {
1238 if (alg_mkey) {
1239 alg_mkey &= ca_list[j]->algorithm_mkey;
1240 if (!alg_mkey) {
1241 found = 0;
1242 break;
1243 }
1244 } else
1245 alg_mkey = ca_list[j]->algorithm_mkey;
1246 }
1247
1248 if (ca_list[j]->algorithm_auth) {
1249 if (alg_auth) {
1250 alg_auth &= ca_list[j]->algorithm_auth;
1251 if (!alg_auth) {
1252 found = 0;
1253 break;
1254 }
1255 } else
1256 alg_auth = ca_list[j]->algorithm_auth;
1257 }
1258
1259 if (ca_list[j]->algorithm_enc) {
1260 if (alg_enc) {
1261 alg_enc &= ca_list[j]->algorithm_enc;
1262 if (!alg_enc) {
1263 found = 0;
1264 break;
1265 }
1266 } else
1267 alg_enc = ca_list[j]->algorithm_enc;
1268 }
1269
1270 if (ca_list[j]->algorithm_mac) {
1271 if (alg_mac) {
1272 alg_mac &= ca_list[j]->algorithm_mac;
1273 if (!alg_mac) {
1274 found = 0;
1275 break;
1276 }
1277 } else
1278 alg_mac = ca_list[j]->algorithm_mac;
1279 }
1280
1281 if (ca_list[j]->algo_strength & SSL_STRONG_MASK) {
1282 if (algo_strength & SSL_STRONG_MASK) {
1283 algo_strength &=
1284 (ca_list[j]->algo_strength &
1285 SSL_STRONG_MASK) | ~SSL_STRONG_MASK;
1286 if (!(algo_strength &
1287 SSL_STRONG_MASK)) {
1288 found = 0;
1289 break;
1290 }
1291 } else
1292 algo_strength |=
1293 ca_list[j]->algo_strength &
1294 SSL_STRONG_MASK;
1295 }
1296
1297 if (ca_list[j]->valid) {
1298 /*
1299 * explicit ciphersuite found; its protocol
1300 * version does not become part of the search
1301 * pattern!
1302 */
1303 cipher_id = ca_list[j]->id;
1304 } else {
1305 /*
1306 * not an explicit ciphersuite; only in this
1307 * case, the protocol version is considered
1308 * part of the search pattern
1309 */
1310 if (ca_list[j]->algorithm_ssl) {
1311 if (alg_ssl) {
1312 alg_ssl &=
1313 ca_list[j]->algorithm_ssl;
1314 if (!alg_ssl) {
1315 found = 0;
1316 break;
1317 }
1318 } else
1319 alg_ssl =
1320 ca_list[j]->algorithm_ssl;
1321 }
1322 }
1323
1324 if (!multi)
1325 break;
1326 }
1327
1328 /*
1329 * Ok, we have the rule, now apply it
1330 */
1331 if (rule == CIPHER_SPECIAL) {
1332 /* special command */
1333 ok = 0;
1334 if ((buflen == 8) && !strncmp(buf, "STRENGTH", 8))
1335 ok = ssl_cipher_strength_sort(head_p, tail_p);
1336 else
1337 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
1338 SSL_R_INVALID_COMMAND);
1339 if (ok == 0)
1340 retval = 0;
1341 /*
1342 * We do not support any "multi" options
1343 * together with "@", so throw away the
1344 * rest of the command, if any left, until
1345 * end or ':' is found.
1346 */
1347 while ((*l != '\0') && !ITEM_SEP(*l))
1348 l++;
1349 } else if (found) {
1350 ssl_cipher_apply_rule(cipher_id, alg_mkey, alg_auth,
1351 alg_enc, alg_mac, alg_ssl, algo_strength, rule,
1352 -1, head_p, tail_p);
1353 } else {
1354 while ((*l != '\0') && !ITEM_SEP(*l))
1355 l++;
1356 }
1357 if (*l == '\0')
1358 break; /* done */
1359 }
1360
1361 return (retval);
1362}
1363
1364static inline int
1365ssl_aes_is_accelerated(void)
1366{
1367#if defined(__i386__) || defined(__x86_64__)
1368 return ((OPENSSL_cpu_caps() & (1ULL << 57)) != 0);
1369#else
1370 return (0);
1371#endif
1372}
1373
1374STACK_OF(SSL_CIPHER) *
1375ssl_create_cipher_list(const SSL_METHOD *ssl_method,
1376 STACK_OF(SSL_CIPHER) **cipher_list,
1377 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
1378 const char *rule_str)
1379{
1380 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
1381 unsigned long disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl;
1382 STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list;
1383 const char *rule_p;
1384 CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
1385 const SSL_CIPHER **ca_list = NULL;
1386
1387 /*
1388 * Return with error if nothing to do.
1389 */
1390 if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)
1391 return NULL;
1392
1393 /*
1394 * To reduce the work to do we only want to process the compiled
1395 * in algorithms, so we first get the mask of disabled ciphers.
1396 */
1397 ssl_cipher_get_disabled(&disabled_mkey, &disabled_auth, &disabled_enc, &disabled_mac, &disabled_ssl);
1398
1399 /*
1400 * Now we have to collect the available ciphers from the compiled
1401 * in ciphers. We cannot get more than the number compiled in, so
1402 * it is used for allocation.
1403 */
1404 num_of_ciphers = ssl_method->num_ciphers();
1405 co_list = reallocarray(NULL, num_of_ciphers, sizeof(CIPHER_ORDER));
1406 if (co_list == NULL) {
1407 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
1408 return(NULL); /* Failure */
1409 }
1410
1411 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,
1412 disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl,
1413 co_list, &head, &tail);
1414
1415
1416 /* Now arrange all ciphers by preference: */
1417
1418 /* Everything else being equal, prefer ephemeral ECDH over other key exchange mechanisms */
1419 ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1420 ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
1421
1422 if (ssl_aes_is_accelerated() == 1) {
1423 /*
1424 * We have hardware assisted AES - prefer AES as a symmetric
1425 * cipher, with CHACHA20 second.
1426 */
1427 ssl_cipher_apply_rule(0, 0, 0, SSL_AES, 0, 0, 0,
1428 CIPHER_ADD, -1, &head, &tail);
1429 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305,
1430 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1431 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305_OLD,
1432 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1433 } else {
1434 /*
1435 * CHACHA20 is fast and safe on all hardware and is thus our
1436 * preferred symmetric cipher, with AES second.
1437 */
1438 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305,
1439 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1440 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305_OLD,
1441 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1442 ssl_cipher_apply_rule(0, 0, 0, SSL_AES, 0, 0, 0,
1443 CIPHER_ADD, -1, &head, &tail);
1444 }
1445
1446 /* Temporarily enable everything else for sorting */
1447 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1448
1449 /* Low priority for MD5 */
1450 ssl_cipher_apply_rule(0, 0, 0, 0, SSL_MD5, 0, 0, CIPHER_ORD, -1, &head, &tail);
1451
1452 /* Move anonymous ciphers to the end. Usually, these will remain disabled.
1453 * (For applications that allow them, they aren't too bad, but we prefer
1454 * authenticated ciphers.) */
1455 ssl_cipher_apply_rule(0, 0, SSL_aNULL, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1456
1457 /* Move ciphers without forward secrecy to the end */
1458 ssl_cipher_apply_rule(0, 0, SSL_aECDH, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1459 ssl_cipher_apply_rule(0, SSL_kRSA, 0, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1460
1461 /* RC4 is sort of broken - move it to the end */
1462 ssl_cipher_apply_rule(0, 0, 0, SSL_RC4, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1463
1464 /* Now sort by symmetric encryption strength. The above ordering remains
1465 * in force within each class */
1466 if (!ssl_cipher_strength_sort(&head, &tail)) {
1467 free(co_list);
1468 return NULL;
1469 }
1470
1471 /* Now disable everything (maintaining the ordering!) */
1472 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
1473
1474
1475 /*
1476 * We also need cipher aliases for selecting based on the rule_str.
1477 * There might be two types of entries in the rule_str: 1) names
1478 * of ciphers themselves 2) aliases for groups of ciphers.
1479 * For 1) we need the available ciphers and for 2) the cipher
1480 * groups of cipher_aliases added together in one list (otherwise
1481 * we would be happy with just the cipher_aliases table).
1482 */
1483 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
1484 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
1485 ca_list = reallocarray(NULL, num_of_alias_max, sizeof(SSL_CIPHER *));
1486 if (ca_list == NULL) {
1487 free(co_list);
1488 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
1489 return(NULL); /* Failure */
1490 }
1491 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,
1492 disabled_mkey, disabled_auth, disabled_enc,
1493 disabled_mac, disabled_ssl, head);
1494
1495 /*
1496 * If the rule_string begins with DEFAULT, apply the default rule
1497 * before using the (possibly available) additional rules.
1498 */
1499 ok = 1;
1500 rule_p = rule_str;
1501 if (strncmp(rule_str, "DEFAULT", 7) == 0) {
1502 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
1503 &head, &tail, ca_list);
1504 rule_p += 7;
1505 if (*rule_p == ':')
1506 rule_p++;
1507 }
1508
1509 if (ok && (strlen(rule_p) > 0))
1510 ok = ssl_cipher_process_rulestr(rule_p, &head, &tail, ca_list);
1511
1512 free((void *)ca_list); /* Not needed anymore */
1513
1514 if (!ok) {
1515 /* Rule processing failure */
1516 free(co_list);
1517 return (NULL);
1518 }
1519
1520 /*
1521 * Allocate new "cipherstack" for the result, return with error
1522 * if we cannot get one.
1523 */
1524 if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {
1525 free(co_list);
1526 return (NULL);
1527 }
1528
1529 /*
1530 * The cipher selection for the list is done. The ciphers are added
1531 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
1532 */
1533 for (curr = head; curr != NULL; curr = curr->next) {
1534 if (curr->active) {
1535 sk_SSL_CIPHER_push(cipherstack, curr->cipher);
1536 }
1537 }
1538 free(co_list); /* Not needed any longer */
1539
1540 tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack);
1541 if (tmp_cipher_list == NULL) {
1542 sk_SSL_CIPHER_free(cipherstack);
1543 return NULL;
1544 }
1545 if (*cipher_list != NULL)
1546 sk_SSL_CIPHER_free(*cipher_list);
1547 *cipher_list = cipherstack;
1548 if (*cipher_list_by_id != NULL)
1549 sk_SSL_CIPHER_free(*cipher_list_by_id);
1550 *cipher_list_by_id = tmp_cipher_list;
1551 (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,
1552 ssl_cipher_ptr_id_cmp);
1553
1554 sk_SSL_CIPHER_sort(*cipher_list_by_id);
1555 return (cipherstack);
1556}
1557
1558const SSL_CIPHER *
1559SSL_CIPHER_get_by_id(unsigned int id)
1560{
1561 return ssl3_get_cipher_by_id(id);
1562}
1563
1564const SSL_CIPHER *
1565SSL_CIPHER_get_by_value(uint16_t value)
1566{
1567 return ssl3_get_cipher_by_value(value);
1568}
1569
1570char *
1571SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
1572{
1573 unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, alg2;
1574 const char *ver, *kx, *au, *enc, *mac;
1575 char *ret;
1576 int l;
1577
1578 alg_mkey = cipher->algorithm_mkey;
1579 alg_auth = cipher->algorithm_auth;
1580 alg_enc = cipher->algorithm_enc;
1581 alg_mac = cipher->algorithm_mac;
1582 alg_ssl = cipher->algorithm_ssl;
1583
1584 alg2 = cipher->algorithm2;
1585
1586 if (alg_ssl & SSL_SSLV3)
1587 ver = "SSLv3";
1588 else if (alg_ssl & SSL_TLSV1_2)
1589 ver = "TLSv1.2";
1590 else
1591 ver = "unknown";
1592
1593 switch (alg_mkey) {
1594 case SSL_kRSA:
1595 kx = "RSA";
1596 break;
1597 case SSL_kDHE:
1598 kx = "DH";
1599 break;
1600 case SSL_kECDHr:
1601 kx = "ECDH/RSA";
1602 break;
1603 case SSL_kECDHe:
1604 kx = "ECDH/ECDSA";
1605 break;
1606 case SSL_kECDHE:
1607 kx = "ECDH";
1608 break;
1609 case SSL_kGOST:
1610 kx = "GOST";
1611 break;
1612 default:
1613 kx = "unknown";
1614 }
1615
1616 switch (alg_auth) {
1617 case SSL_aRSA:
1618 au = "RSA";
1619 break;
1620 case SSL_aDSS:
1621 au = "DSS";
1622 break;
1623 case SSL_aECDH:
1624 au = "ECDH";
1625 break;
1626 case SSL_aNULL:
1627 au = "None";
1628 break;
1629 case SSL_aECDSA:
1630 au = "ECDSA";
1631 break;
1632 case SSL_aGOST01:
1633 au = "GOST01";
1634 break;
1635 default:
1636 au = "unknown";
1637 break;
1638 }
1639
1640 switch (alg_enc) {
1641 case SSL_DES:
1642 enc = "DES(56)";
1643 break;
1644 case SSL_3DES:
1645 enc = "3DES(168)";
1646 break;
1647 case SSL_RC4:
1648 enc = alg2 & SSL2_CF_8_BYTE_ENC ? "RC4(64)" : "RC4(128)";
1649 break;
1650 case SSL_IDEA:
1651 enc = "IDEA(128)";
1652 break;
1653 case SSL_eNULL:
1654 enc = "None";
1655 break;
1656 case SSL_AES128:
1657 enc = "AES(128)";
1658 break;
1659 case SSL_AES256:
1660 enc = "AES(256)";
1661 break;
1662 case SSL_AES128GCM:
1663 enc = "AESGCM(128)";
1664 break;
1665 case SSL_AES256GCM:
1666 enc = "AESGCM(256)";
1667 break;
1668 case SSL_CAMELLIA128:
1669 enc = "Camellia(128)";
1670 break;
1671 case SSL_CAMELLIA256:
1672 enc = "Camellia(256)";
1673 break;
1674 case SSL_CHACHA20POLY1305:
1675 enc = "ChaCha20-Poly1305";
1676 break;
1677 case SSL_CHACHA20POLY1305_OLD:
1678 enc = "ChaCha20-Poly1305-Old";
1679 break;
1680 case SSL_eGOST2814789CNT:
1681 enc = "GOST-28178-89-CNT";
1682 break;
1683 default:
1684 enc = "unknown";
1685 break;
1686 }
1687
1688 switch (alg_mac) {
1689 case SSL_MD5:
1690 mac = "MD5";
1691 break;
1692 case SSL_SHA1:
1693 mac = "SHA1";
1694 break;
1695 case SSL_SHA256:
1696 mac = "SHA256";
1697 break;
1698 case SSL_SHA384:
1699 mac = "SHA384";
1700 break;
1701 case SSL_AEAD:
1702 mac = "AEAD";
1703 break;
1704 case SSL_GOST94:
1705 mac = "GOST94";
1706 break;
1707 case SSL_GOST89MAC:
1708 mac = "GOST89IMIT";
1709 break;
1710 case SSL_STREEBOG256:
1711 mac = "STREEBOG256";
1712 break;
1713 case SSL_STREEBOG512:
1714 mac = "STREEBOG512";
1715 break;
1716 default:
1717 mac = "unknown";
1718 break;
1719 }
1720
1721 if (asprintf(&ret, "%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n",
1722 cipher->name, ver, kx, au, enc, mac) == -1)
1723 return "OPENSSL_malloc Error";
1724
1725 if (buf != NULL) {
1726 l = strlcpy(buf, ret, len);
1727 free(ret);
1728 ret = buf;
1729 if (l >= len)
1730 ret = "Buffer too small";
1731 }
1732
1733 return (ret);
1734}
1735
1736char *
1737SSL_CIPHER_get_version(const SSL_CIPHER *c)
1738{
1739 if (c == NULL)
1740 return("(NONE)");
1741 if ((c->id >> 24) == 3)
1742 return("TLSv1/SSLv3");
1743 else
1744 return("unknown");
1745}
1746
1747/* return the actual cipher being used */
1748const char *
1749SSL_CIPHER_get_name(const SSL_CIPHER *c)
1750{
1751 if (c != NULL)
1752 return (c->name);
1753 return("(NONE)");
1754}
1755
1756/* number of bits for symmetric cipher */
1757int
1758SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits)
1759{
1760 int ret = 0;
1761
1762 if (c != NULL) {
1763 if (alg_bits != NULL)
1764 *alg_bits = c->alg_bits;
1765 ret = c->strength_bits;
1766 }
1767 return (ret);
1768}
1769
1770unsigned long
1771SSL_CIPHER_get_id(const SSL_CIPHER *c)
1772{
1773 return c->id;
1774}
1775
1776uint16_t
1777SSL_CIPHER_get_value(const SSL_CIPHER *c)
1778{
1779 return ssl3_cipher_get_value(c);
1780}
1781
1782void *
1783SSL_COMP_get_compression_methods(void)
1784{
1785 return NULL;
1786}
1787
1788int
1789SSL_COMP_add_compression_method(int id, void *cm)
1790{
1791 return 1;
1792}
1793
1794const char *
1795SSL_COMP_get_name(const void *comp)
1796{
1797 return NULL;
1798}
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 04742b60ca..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,615 +0,0 @@
1/* $OpenBSD: ssl_err.c,v 1.29 2015/02/22 15:54:27 jsing Exp $ */
2/* ====================================================================
3 * Copyright (c) 1999-2011 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
63#include <openssl/err.h>
64#include <openssl/ssl.h>
65
66/* BEGIN ERROR CODES */
67#ifndef OPENSSL_NO_ERR
68
69#define ERR_FUNC(func) ERR_PACK(ERR_LIB_SSL,func,0)
70#define ERR_REASON(reason) ERR_PACK(ERR_LIB_SSL,0,reason)
71
72static ERR_STRING_DATA SSL_str_functs[]= {
73 {ERR_FUNC(SSL_F_CLIENT_CERTIFICATE), "CLIENT_CERTIFICATE"},
74 {ERR_FUNC(SSL_F_CLIENT_FINISHED), "CLIENT_FINISHED"},
75 {ERR_FUNC(SSL_F_CLIENT_HELLO), "CLIENT_HELLO"},
76 {ERR_FUNC(SSL_F_CLIENT_MASTER_KEY), "CLIENT_MASTER_KEY"},
77 {ERR_FUNC(SSL_F_D2I_SSL_SESSION), "d2i_SSL_SESSION"},
78 {ERR_FUNC(SSL_F_DO_DTLS1_WRITE), "DO_DTLS1_WRITE"},
79 {ERR_FUNC(SSL_F_DO_SSL3_WRITE), "DO_SSL3_WRITE"},
80 {ERR_FUNC(SSL_F_DTLS1_ACCEPT), "DTLS1_ACCEPT"},
81 {ERR_FUNC(SSL_F_DTLS1_ADD_CERT_TO_BUF), "DTLS1_ADD_CERT_TO_BUF"},
82 {ERR_FUNC(SSL_F_DTLS1_BUFFER_RECORD), "DTLS1_BUFFER_RECORD"},
83 {ERR_FUNC(SSL_F_DTLS1_CHECK_TIMEOUT_NUM), "DTLS1_CHECK_TIMEOUT_NUM"},
84 {ERR_FUNC(SSL_F_DTLS1_CLIENT_HELLO), "DTLS1_CLIENT_HELLO"},
85 {ERR_FUNC(SSL_F_DTLS1_CONNECT), "DTLS1_CONNECT"},
86 {ERR_FUNC(SSL_F_DTLS1_ENC), "DTLS1_ENC"},
87 {ERR_FUNC(SSL_F_DTLS1_GET_HELLO_VERIFY), "DTLS1_GET_HELLO_VERIFY"},
88 {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE), "DTLS1_GET_MESSAGE"},
89 {ERR_FUNC(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT), "DTLS1_GET_MESSAGE_FRAGMENT"},
90 {ERR_FUNC(SSL_F_DTLS1_GET_RECORD), "DTLS1_GET_RECORD"},
91 {ERR_FUNC(SSL_F_DTLS1_HANDLE_TIMEOUT), "DTLS1_HANDLE_TIMEOUT"},
92 {ERR_FUNC(SSL_F_DTLS1_HEARTBEAT), "DTLS1_HEARTBEAT"},
93 {ERR_FUNC(SSL_F_DTLS1_OUTPUT_CERT_CHAIN), "DTLS1_OUTPUT_CERT_CHAIN"},
94 {ERR_FUNC(SSL_F_DTLS1_PREPROCESS_FRAGMENT), "DTLS1_PREPROCESS_FRAGMENT"},
95 {ERR_FUNC(SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE), "DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE"},
96 {ERR_FUNC(SSL_F_DTLS1_PROCESS_RECORD), "DTLS1_PROCESS_RECORD"},
97 {ERR_FUNC(SSL_F_DTLS1_READ_BYTES), "DTLS1_READ_BYTES"},
98 {ERR_FUNC(SSL_F_DTLS1_READ_FAILED), "DTLS1_READ_FAILED"},
99 {ERR_FUNC(SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST), "DTLS1_SEND_CERTIFICATE_REQUEST"},
100 {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE), "DTLS1_SEND_CLIENT_CERTIFICATE"},
101 {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE), "DTLS1_SEND_CLIENT_KEY_EXCHANGE"},
102 {ERR_FUNC(SSL_F_DTLS1_SEND_CLIENT_VERIFY), "DTLS1_SEND_CLIENT_VERIFY"},
103 {ERR_FUNC(SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST), "DTLS1_SEND_HELLO_VERIFY_REQUEST"},
104 {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE), "DTLS1_SEND_SERVER_CERTIFICATE"},
105 {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_HELLO), "DTLS1_SEND_SERVER_HELLO"},
106 {ERR_FUNC(SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE), "DTLS1_SEND_SERVER_KEY_EXCHANGE"},
107 {ERR_FUNC(SSL_F_DTLS1_WRITE_APP_DATA_BYTES), "DTLS1_WRITE_APP_DATA_BYTES"},
108 {ERR_FUNC(SSL_F_GET_CLIENT_FINISHED), "GET_CLIENT_FINISHED"},
109 {ERR_FUNC(SSL_F_GET_CLIENT_HELLO), "GET_CLIENT_HELLO"},
110 {ERR_FUNC(SSL_F_GET_CLIENT_MASTER_KEY), "GET_CLIENT_MASTER_KEY"},
111 {ERR_FUNC(SSL_F_GET_SERVER_FINISHED), "GET_SERVER_FINISHED"},
112 {ERR_FUNC(SSL_F_GET_SERVER_HELLO), "GET_SERVER_HELLO"},
113 {ERR_FUNC(SSL_F_GET_SERVER_VERIFY), "GET_SERVER_VERIFY"},
114 {ERR_FUNC(SSL_F_I2D_SSL_SESSION), "i2d_SSL_SESSION"},
115 {ERR_FUNC(SSL_F_READ_N), "READ_N"},
116 {ERR_FUNC(SSL_F_REQUEST_CERTIFICATE), "REQUEST_CERTIFICATE"},
117 {ERR_FUNC(SSL_F_SERVER_FINISH), "SERVER_FINISH"},
118 {ERR_FUNC(SSL_F_SERVER_HELLO), "SERVER_HELLO"},
119 {ERR_FUNC(SSL_F_SERVER_VERIFY), "SERVER_VERIFY"},
120 {ERR_FUNC(SSL_F_SSL23_ACCEPT), "SSL23_ACCEPT"},
121 {ERR_FUNC(SSL_F_SSL23_CLIENT_HELLO), "SSL23_CLIENT_HELLO"},
122 {ERR_FUNC(SSL_F_SSL23_CONNECT), "SSL23_CONNECT"},
123 {ERR_FUNC(SSL_F_SSL23_GET_CLIENT_HELLO), "SSL23_GET_CLIENT_HELLO"},
124 {ERR_FUNC(SSL_F_SSL23_GET_SERVER_HELLO), "SSL23_GET_SERVER_HELLO"},
125 {ERR_FUNC(SSL_F_SSL23_PEEK), "SSL23_PEEK"},
126 {ERR_FUNC(SSL_F_SSL23_READ), "SSL23_READ"},
127 {ERR_FUNC(SSL_F_SSL23_WRITE), "SSL23_WRITE"},
128 {ERR_FUNC(SSL_F_SSL2_ACCEPT), "SSL2_ACCEPT"},
129 {ERR_FUNC(SSL_F_SSL2_CONNECT), "SSL2_CONNECT"},
130 {ERR_FUNC(SSL_F_SSL2_ENC_INIT), "SSL2_ENC_INIT"},
131 {ERR_FUNC(SSL_F_SSL2_GENERATE_KEY_MATERIAL), "SSL2_GENERATE_KEY_MATERIAL"},
132 {ERR_FUNC(SSL_F_SSL2_PEEK), "SSL2_PEEK"},
133 {ERR_FUNC(SSL_F_SSL2_READ), "SSL2_READ"},
134 {ERR_FUNC(SSL_F_SSL2_READ_INTERNAL), "SSL2_READ_INTERNAL"},
135 {ERR_FUNC(SSL_F_SSL2_SET_CERTIFICATE), "SSL2_SET_CERTIFICATE"},
136 {ERR_FUNC(SSL_F_SSL2_WRITE), "SSL2_WRITE"},
137 {ERR_FUNC(SSL_F_SSL3_ACCEPT), "SSL3_ACCEPT"},
138 {ERR_FUNC(SSL_F_SSL3_ADD_CERT_TO_BUF), "SSL3_ADD_CERT_TO_BUF"},
139 {ERR_FUNC(SSL_F_SSL3_CALLBACK_CTRL), "SSL3_CALLBACK_CTRL"},
140 {ERR_FUNC(SSL_F_SSL3_CHANGE_CIPHER_STATE), "SSL3_CHANGE_CIPHER_STATE"},
141 {ERR_FUNC(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM), "SSL3_CHECK_CERT_AND_ALGORITHM"},
142 {ERR_FUNC(SSL_F_SSL3_CHECK_CLIENT_HELLO), "SSL3_CHECK_CLIENT_HELLO"},
143 {ERR_FUNC(SSL_F_SSL3_CLIENT_HELLO), "SSL3_CLIENT_HELLO"},
144 {ERR_FUNC(SSL_F_SSL3_CONNECT), "SSL3_CONNECT"},
145 {ERR_FUNC(SSL_F_SSL3_CTRL), "SSL3_CTRL"},
146 {ERR_FUNC(SSL_F_SSL3_CTX_CTRL), "SSL3_CTX_CTRL"},
147 {ERR_FUNC(SSL_F_SSL3_DIGEST_CACHED_RECORDS), "SSL3_DIGEST_CACHED_RECORDS"},
148 {ERR_FUNC(SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC), "SSL3_DO_CHANGE_CIPHER_SPEC"},
149 {ERR_FUNC(SSL_F_SSL3_ENC), "SSL3_ENC"},
150 {ERR_FUNC(SSL_F_SSL3_GENERATE_KEY_BLOCK), "SSL3_GENERATE_KEY_BLOCK"},
151 {ERR_FUNC(SSL_F_SSL3_GET_CERTIFICATE_REQUEST), "SSL3_GET_CERTIFICATE_REQUEST"},
152 {ERR_FUNC(SSL_F_SSL3_GET_CERT_STATUS), "SSL3_GET_CERT_STATUS"},
153 {ERR_FUNC(SSL_F_SSL3_GET_CERT_VERIFY), "SSL3_GET_CERT_VERIFY"},
154 {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_CERTIFICATE), "SSL3_GET_CLIENT_CERTIFICATE"},
155 {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_HELLO), "SSL3_GET_CLIENT_HELLO"},
156 {ERR_FUNC(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
157 {ERR_FUNC(SSL_F_SSL3_GET_FINISHED), "SSL3_GET_FINISHED"},
158 {ERR_FUNC(SSL_F_SSL3_GET_KEY_EXCHANGE), "SSL3_GET_KEY_EXCHANGE"},
159 {ERR_FUNC(SSL_F_SSL3_GET_MESSAGE), "SSL3_GET_MESSAGE"},
160 {ERR_FUNC(SSL_F_SSL3_GET_NEW_SESSION_TICKET), "SSL3_GET_NEW_SESSION_TICKET"},
161 {ERR_FUNC(SSL_F_SSL3_GET_NEXT_PROTO), "SSL3_GET_NEXT_PROTO"},
162 {ERR_FUNC(SSL_F_SSL3_GET_RECORD), "SSL3_GET_RECORD"},
163 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_CERTIFICATE), "SSL3_GET_SERVER_CERTIFICATE"},
164 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_DONE), "SSL3_GET_SERVER_DONE"},
165 {ERR_FUNC(SSL_F_SSL3_GET_SERVER_HELLO), "SSL3_GET_SERVER_HELLO"},
166 {ERR_FUNC(SSL_F_SSL3_HANDSHAKE_MAC), "ssl3_handshake_mac"},
167 {ERR_FUNC(SSL_F_SSL3_NEW_SESSION_TICKET), "SSL3_NEW_SESSION_TICKET"},
168 {ERR_FUNC(SSL_F_SSL3_OUTPUT_CERT_CHAIN), "SSL3_OUTPUT_CERT_CHAIN"},
169 {ERR_FUNC(SSL_F_SSL3_PEEK), "SSL3_PEEK"},
170 {ERR_FUNC(SSL_F_SSL3_READ_BYTES), "SSL3_READ_BYTES"},
171 {ERR_FUNC(SSL_F_SSL3_READ_N), "SSL3_READ_N"},
172 {ERR_FUNC(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST), "SSL3_SEND_CERTIFICATE_REQUEST"},
173 {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE), "SSL3_SEND_CLIENT_CERTIFICATE"},
174 {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
175 {ERR_FUNC(SSL_F_SSL3_SEND_CLIENT_VERIFY), "SSL3_SEND_CLIENT_VERIFY"},
176 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_CERTIFICATE), "SSL3_SEND_SERVER_CERTIFICATE"},
177 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_HELLO), "SSL3_SEND_SERVER_HELLO"},
178 {ERR_FUNC(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
179 {ERR_FUNC(SSL_F_SSL3_SETUP_KEY_BLOCK), "SSL3_SETUP_KEY_BLOCK"},
180 {ERR_FUNC(SSL_F_SSL3_SETUP_READ_BUFFER), "SSL3_SETUP_READ_BUFFER"},
181 {ERR_FUNC(SSL_F_SSL3_SETUP_WRITE_BUFFER), "SSL3_SETUP_WRITE_BUFFER"},
182 {ERR_FUNC(SSL_F_SSL3_WRITE_BYTES), "SSL3_WRITE_BYTES"},
183 {ERR_FUNC(SSL_F_SSL3_WRITE_PENDING), "SSL3_WRITE_PENDING"},
184 {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT), "SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT"},
185 {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT), "SSL_ADD_CLIENTHELLO_TLSEXT"},
186 {ERR_FUNC(SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT), "SSL_ADD_CLIENTHELLO_USE_SRTP_EXT"},
187 {ERR_FUNC(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK), "SSL_add_dir_cert_subjects_to_stack"},
188 {ERR_FUNC(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK), "SSL_add_file_cert_subjects_to_stack"},
189 {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT), "SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT"},
190 {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_TLSEXT), "SSL_ADD_SERVERHELLO_TLSEXT"},
191 {ERR_FUNC(SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT), "SSL_ADD_SERVERHELLO_USE_SRTP_EXT"},
192 {ERR_FUNC(SSL_F_SSL_BAD_METHOD), "SSL_BAD_METHOD"},
193 {ERR_FUNC(SSL_F_SSL_BYTES_TO_CIPHER_LIST), "SSL_BYTES_TO_CIPHER_LIST"},
194 {ERR_FUNC(SSL_F_SSL_CERT_DUP), "SSL_CERT_DUP"},
195 {ERR_FUNC(SSL_F_SSL_CERT_INST), "SSL_CERT_INST"},
196 {ERR_FUNC(SSL_F_SSL_CERT_INSTANTIATE), "SSL_CERT_INSTANTIATE"},
197 {ERR_FUNC(SSL_F_SSL_CERT_NEW), "SSL_CERT_NEW"},
198 {ERR_FUNC(SSL_F_SSL_CHECK_PRIVATE_KEY), "SSL_check_private_key"},
199 {ERR_FUNC(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT), "SSL_CHECK_SERVERHELLO_TLSEXT"},
200 {ERR_FUNC(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG), "SSL_CHECK_SRVR_ECC_CERT_AND_ALG"},
201 {ERR_FUNC(SSL_F_SSL_CIPHER_PROCESS_RULESTR), "SSL_CIPHER_PROCESS_RULESTR"},
202 {ERR_FUNC(SSL_F_SSL_CIPHER_STRENGTH_SORT), "SSL_CIPHER_STRENGTH_SORT"},
203 {ERR_FUNC(SSL_F_SSL_CLEAR), "SSL_clear"},
204 {ERR_FUNC(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD), "SSL_COMP_add_compression_method"},
205 {ERR_FUNC(SSL_F_SSL_CREATE_CIPHER_LIST), "SSL_CREATE_CIPHER_LIST"},
206 {ERR_FUNC(SSL_F_SSL_CTRL), "SSL_ctrl"},
207 {ERR_FUNC(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY), "SSL_CTX_check_private_key"},
208 {ERR_FUNC(SSL_F_SSL_CTX_MAKE_PROFILES), "SSL_CTX_MAKE_PROFILES"},
209 {ERR_FUNC(SSL_F_SSL_CTX_NEW), "SSL_CTX_new"},
210 {ERR_FUNC(SSL_F_SSL_CTX_SET_CIPHER_LIST), "SSL_CTX_set_cipher_list"},
211 {ERR_FUNC(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE), "SSL_CTX_set_client_cert_engine"},
212 {ERR_FUNC(SSL_F_SSL_CTX_SET_PURPOSE), "SSL_CTX_set_purpose"},
213 {ERR_FUNC(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT), "SSL_CTX_set_session_id_context"},
214 {ERR_FUNC(SSL_F_SSL_CTX_SET_SSL_VERSION), "SSL_CTX_set_ssl_version"},
215 {ERR_FUNC(SSL_F_SSL_CTX_SET_TRUST), "SSL_CTX_set_trust"},
216 {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE), "SSL_CTX_use_certificate"},
217 {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1), "SSL_CTX_use_certificate_ASN1"},
218 {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE), "SSL_CTX_use_certificate_chain_file"},
219 {ERR_FUNC(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE), "SSL_CTX_use_certificate_file"},
220 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY), "SSL_CTX_use_PrivateKey"},
221 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1), "SSL_CTX_use_PrivateKey_ASN1"},
222 {ERR_FUNC(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE), "SSL_CTX_use_PrivateKey_file"},
223 {ERR_FUNC(SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT), "SSL_CTX_use_psk_identity_hint"},
224 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY), "SSL_CTX_use_RSAPrivateKey"},
225 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1), "SSL_CTX_use_RSAPrivateKey_ASN1"},
226 {ERR_FUNC(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE), "SSL_CTX_use_RSAPrivateKey_file"},
227 {ERR_FUNC(SSL_F_SSL_DO_HANDSHAKE), "SSL_do_handshake"},
228 {ERR_FUNC(SSL_F_SSL_GET_NEW_SESSION), "SSL_GET_NEW_SESSION"},
229 {ERR_FUNC(SSL_F_SSL_GET_PREV_SESSION), "SSL_GET_PREV_SESSION"},
230 {ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_CERT), "SSL_GET_SERVER_SEND_CERT"},
231 {ERR_FUNC(SSL_F_SSL_GET_SERVER_SEND_PKEY), "SSL_GET_SERVER_SEND_PKEY"},
232 {ERR_FUNC(SSL_F_SSL_GET_SIGN_PKEY), "SSL_GET_SIGN_PKEY"},
233 {ERR_FUNC(SSL_F_SSL_INIT_WBIO_BUFFER), "SSL_INIT_WBIO_BUFFER"},
234 {ERR_FUNC(SSL_F_SSL_LOAD_CLIENT_CA_FILE), "SSL_load_client_CA_file"},
235 {ERR_FUNC(SSL_F_SSL_NEW), "SSL_new"},
236 {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT), "SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT"},
237 {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT), "SSL_PARSE_CLIENTHELLO_TLSEXT"},
238 {ERR_FUNC(SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT), "SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT"},
239 {ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT), "SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT"},
240 {ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT), "SSL_PARSE_SERVERHELLO_TLSEXT"},
241 {ERR_FUNC(SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT), "SSL_PARSE_SERVERHELLO_USE_SRTP_EXT"},
242 {ERR_FUNC(SSL_F_SSL_PEEK), "SSL_peek"},
243 {ERR_FUNC(SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT), "SSL_PREPARE_CLIENTHELLO_TLSEXT"},
244 {ERR_FUNC(SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT), "SSL_PREPARE_SERVERHELLO_TLSEXT"},
245 {ERR_FUNC(SSL_F_SSL_READ), "SSL_read"},
246 {ERR_FUNC(SSL_F_SSL_RSA_PRIVATE_DECRYPT), "SSL_RSA_PRIVATE_DECRYPT"},
247 {ERR_FUNC(SSL_F_SSL_RSA_PUBLIC_ENCRYPT), "SSL_RSA_PUBLIC_ENCRYPT"},
248 {ERR_FUNC(SSL_F_SSL_SESSION_NEW), "SSL_SESSION_new"},
249 {ERR_FUNC(SSL_F_SSL_SESSION_PRINT_FP), "SSL_SESSION_print_fp"},
250 {ERR_FUNC(SSL_F_SSL_SESSION_SET1_ID_CONTEXT), "SSL_SESSION_set1_id_context"},
251 {ERR_FUNC(SSL_F_SSL_SESS_CERT_NEW), "SSL_SESS_CERT_NEW"},
252 {ERR_FUNC(SSL_F_SSL_SET_CERT), "SSL_SET_CERT"},
253 {ERR_FUNC(SSL_F_SSL_SET_CIPHER_LIST), "SSL_set_cipher_list"},
254 {ERR_FUNC(SSL_F_SSL_SET_FD), "SSL_set_fd"},
255 {ERR_FUNC(SSL_F_SSL_SET_PKEY), "SSL_SET_PKEY"},
256 {ERR_FUNC(SSL_F_SSL_SET_PURPOSE), "SSL_set_purpose"},
257 {ERR_FUNC(SSL_F_SSL_SET_RFD), "SSL_set_rfd"},
258 {ERR_FUNC(SSL_F_SSL_SET_SESSION), "SSL_set_session"},
259 {ERR_FUNC(SSL_F_SSL_SET_SESSION_ID_CONTEXT), "SSL_set_session_id_context"},
260 {ERR_FUNC(SSL_F_SSL_SET_SESSION_TICKET_EXT), "SSL_set_session_ticket_ext"},
261 {ERR_FUNC(SSL_F_SSL_SET_TRUST), "SSL_set_trust"},
262 {ERR_FUNC(SSL_F_SSL_SET_WFD), "SSL_set_wfd"},
263 {ERR_FUNC(SSL_F_SSL_SHUTDOWN), "SSL_shutdown"},
264 {ERR_FUNC(SSL_F_SSL_SRP_CTX_INIT), "SSL_SRP_CTX_init"},
265 {ERR_FUNC(SSL_F_SSL_UNDEFINED_CONST_FUNCTION), "SSL_UNDEFINED_CONST_FUNCTION"},
266 {ERR_FUNC(SSL_F_SSL_UNDEFINED_FUNCTION), "SSL_UNDEFINED_FUNCTION"},
267 {ERR_FUNC(SSL_F_SSL_UNDEFINED_VOID_FUNCTION), "SSL_UNDEFINED_VOID_FUNCTION"},
268 {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE), "SSL_use_certificate"},
269 {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_ASN1), "SSL_use_certificate_ASN1"},
270 {ERR_FUNC(SSL_F_SSL_USE_CERTIFICATE_FILE), "SSL_use_certificate_file"},
271 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY), "SSL_use_PrivateKey"},
272 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_ASN1), "SSL_use_PrivateKey_ASN1"},
273 {ERR_FUNC(SSL_F_SSL_USE_PRIVATEKEY_FILE), "SSL_use_PrivateKey_file"},
274 {ERR_FUNC(SSL_F_SSL_USE_PSK_IDENTITY_HINT), "SSL_use_psk_identity_hint"},
275 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY), "SSL_use_RSAPrivateKey"},
276 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1), "SSL_use_RSAPrivateKey_ASN1"},
277 {ERR_FUNC(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE), "SSL_use_RSAPrivateKey_file"},
278 {ERR_FUNC(SSL_F_SSL_VERIFY_CERT_CHAIN), "SSL_VERIFY_CERT_CHAIN"},
279 {ERR_FUNC(SSL_F_SSL_WRITE), "SSL_write"},
280 {ERR_FUNC(SSL_F_TLS1_AEAD_CTX_INIT), "TLS1_AEAD_CTX_INIT"},
281 {ERR_FUNC(SSL_F_TLS1_CERT_VERIFY_MAC), "tls1_cert_verify_mac"},
282 {ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE), "TLS1_CHANGE_CIPHER_STATE"},
283 {ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE_AEAD), "TLS1_CHANGE_CIPHER_STATE_AEAD"},
284 {ERR_FUNC(SSL_F_TLS1_CHANGE_CIPHER_STATE_CIPHER), "TLS1_CHANGE_CIPHER_STATE_CIPHER"},
285 {ERR_FUNC(SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT), "TLS1_CHECK_SERVERHELLO_TLSEXT"},
286 {ERR_FUNC(SSL_F_TLS1_ENC), "TLS1_ENC"},
287 {ERR_FUNC(SSL_F_TLS1_EXPORT_KEYING_MATERIAL), "TLS1_EXPORT_KEYING_MATERIAL"},
288 {ERR_FUNC(SSL_F_TLS1_HEARTBEAT), "SSL_F_TLS1_HEARTBEAT"},
289 {ERR_FUNC(SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT), "TLS1_PREPARE_CLIENTHELLO_TLSEXT"},
290 {ERR_FUNC(SSL_F_TLS1_PREPARE_SERVERHELLO_TLSEXT), "TLS1_PREPARE_SERVERHELLO_TLSEXT"},
291 {ERR_FUNC(SSL_F_TLS1_PRF), "tls1_prf"},
292 {ERR_FUNC(SSL_F_TLS1_SETUP_KEY_BLOCK), "TLS1_SETUP_KEY_BLOCK"},
293 {ERR_FUNC(SSL_F_WRITE_PENDING), "WRITE_PENDING"},
294 {0, NULL}
295};
296
297static ERR_STRING_DATA SSL_str_reasons[]= {
298 {ERR_REASON(SSL_R_APP_DATA_IN_HANDSHAKE) , "app data in handshake"},
299 {ERR_REASON(SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT), "attempt to reuse session in different context"},
300 {ERR_REASON(SSL_R_BAD_ALERT_RECORD) , "bad alert record"},
301 {ERR_REASON(SSL_R_BAD_AUTHENTICATION_TYPE), "bad authentication type"},
302 {ERR_REASON(SSL_R_BAD_CHANGE_CIPHER_SPEC), "bad change cipher spec"},
303 {ERR_REASON(SSL_R_BAD_CHECKSUM) , "bad checksum"},
304 {ERR_REASON(SSL_R_BAD_DATA_RETURNED_BY_CALLBACK), "bad data returned by callback"},
305 {ERR_REASON(SSL_R_BAD_DECOMPRESSION) , "bad decompression"},
306 {ERR_REASON(SSL_R_BAD_DH_G_LENGTH) , "bad dh g length"},
307 {ERR_REASON(SSL_R_BAD_DH_PUB_KEY_LENGTH) , "bad dh pub key length"},
308 {ERR_REASON(SSL_R_BAD_DH_P_LENGTH) , "bad dh p length"},
309 {ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) , "bad digest length"},
310 {ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) , "bad dsa signature"},
311 {ERR_REASON(SSL_R_BAD_ECC_CERT) , "bad ecc cert"},
312 {ERR_REASON(SSL_R_BAD_ECDSA_SIGNATURE) , "bad ecdsa signature"},
313 {ERR_REASON(SSL_R_BAD_ECPOINT) , "bad ecpoint"},
314 {ERR_REASON(SSL_R_BAD_HANDSHAKE_LENGTH) , "bad handshake length"},
315 {ERR_REASON(SSL_R_BAD_HELLO_REQUEST) , "bad hello request"},
316 {ERR_REASON(SSL_R_BAD_LENGTH) , "bad length"},
317 {ERR_REASON(SSL_R_BAD_MAC_DECODE) , "bad mac decode"},
318 {ERR_REASON(SSL_R_BAD_MAC_LENGTH) , "bad mac length"},
319 {ERR_REASON(SSL_R_BAD_MESSAGE_TYPE) , "bad message type"},
320 {ERR_REASON(SSL_R_BAD_PACKET_LENGTH) , "bad packet length"},
321 {ERR_REASON(SSL_R_BAD_PROTOCOL_VERSION_NUMBER), "bad protocol version number"},
322 {ERR_REASON(SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH), "bad psk identity hint length"},
323 {ERR_REASON(SSL_R_BAD_RESPONSE_ARGUMENT) , "bad response argument"},
324 {ERR_REASON(SSL_R_BAD_RSA_DECRYPT) , "bad rsa decrypt"},
325 {ERR_REASON(SSL_R_BAD_RSA_ENCRYPT) , "bad rsa encrypt"},
326 {ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) , "bad rsa e length"},
327 {ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH), "bad rsa modulus length"},
328 {ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) , "bad rsa signature"},
329 {ERR_REASON(SSL_R_BAD_SIGNATURE) , "bad signature"},
330 {ERR_REASON(SSL_R_BAD_SRP_A_LENGTH) , "bad srp a length"},
331 {ERR_REASON(SSL_R_BAD_SRP_B_LENGTH) , "bad srp b length"},
332 {ERR_REASON(SSL_R_BAD_SRP_G_LENGTH) , "bad srp g length"},
333 {ERR_REASON(SSL_R_BAD_SRP_N_LENGTH) , "bad srp n length"},
334 {ERR_REASON(SSL_R_BAD_SRP_S_LENGTH) , "bad srp s length"},
335 {ERR_REASON(SSL_R_BAD_SRTP_MKI_VALUE) , "bad srtp mki value"},
336 {ERR_REASON(SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST), "bad srtp protection profile list"},
337 {ERR_REASON(SSL_R_BAD_SSL_FILETYPE) , "bad ssl filetype"},
338 {ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH), "bad ssl session id length"},
339 {ERR_REASON(SSL_R_BAD_STATE) , "bad state"},
340 {ERR_REASON(SSL_R_BAD_WRITE_RETRY) , "bad write retry"},
341 {ERR_REASON(SSL_R_BIO_NOT_SET) , "bio not set"},
342 {ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG), "block cipher pad is wrong"},
343 {ERR_REASON(SSL_R_BN_LIB) , "bn lib"},
344 {ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) , "ca dn length mismatch"},
345 {ERR_REASON(SSL_R_CA_DN_TOO_LONG) , "ca dn too long"},
346 {ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) , "ccs received early"},
347 {ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED), "certificate verify failed"},
348 {ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) , "cert length mismatch"},
349 {ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT), "challenge is different"},
350 {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH), "cipher code wrong length"},
351 {ERR_REASON(SSL_R_CIPHER_COMPRESSION_UNAVAILABLE), "cipher compression unavailable"},
352 {ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE), "cipher or hash unavailable"},
353 {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR), "cipher table src error"},
354 {ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) , "clienthello tlsext"},
355 {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG), "compressed length too long"},
356 {ERR_REASON(SSL_R_COMPRESSION_DISABLED) , "compression disabled"},
357 {ERR_REASON(SSL_R_COMPRESSION_FAILURE) , "compression failure"},
358 {ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE), "compression id not within private range"},
359 {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR), "compression library error"},
360 {ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT), "connection id is different"},
361 {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET), "connection type not set"},
362 {ERR_REASON(SSL_R_COOKIE_MISMATCH) , "cookie mismatch"},
363 {ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED), "data between ccs and finished"},
364 {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) , "data length too long"},
365 {ERR_REASON(SSL_R_DECRYPTION_FAILED) , "decryption failed"},
366 {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC), "decryption failed or bad record mac"},
367 {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG), "dh public value length is wrong"},
368 {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) , "digest check failed"},
369 {ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) , "dtls message too big"},
370 {ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID), "duplicate compression id"},
371 {ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT), "ecc cert not for key agreement"},
372 {ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_SIGNING), "ecc cert not for signing"},
373 {ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE), "ecc cert should have rsa signature"},
374 {ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE), "ecc cert should have sha1 signature"},
375 {ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER), "ecgroup too large for cipher"},
376 {ERR_REASON(SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST), "empty srtp protection profile list"},
377 {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG), "encrypted length too long"},
378 {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY), "error generating tmp rsa key"},
379 {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST), "error in received cipher list"},
380 {ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE), "excessive message size"},
381 {ERR_REASON(SSL_R_EXTRA_DATA_IN_MESSAGE) , "extra data in message"},
382 {ERR_REASON(SSL_R_GOT_A_FIN_BEFORE_A_CCS), "got a fin before a ccs"},
383 {ERR_REASON(SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS), "got next proto before a ccs"},
384 {ERR_REASON(SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION), "got next proto without seeing extension"},
385 {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST) , "https proxy request"},
386 {ERR_REASON(SSL_R_HTTP_REQUEST) , "http request"},
387 {ERR_REASON(SSL_R_ILLEGAL_PADDING) , "illegal padding"},
388 {ERR_REASON(SSL_R_INAPPROPRIATE_FALLBACK), "inappropriate fallback"},
389 {ERR_REASON(SSL_R_INCONSISTENT_COMPRESSION), "inconsistent compression"},
390 {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH), "invalid challenge length"},
391 {ERR_REASON(SSL_R_INVALID_COMMAND) , "invalid command"},
392 {ERR_REASON(SSL_R_INVALID_COMPRESSION_ALGORITHM), "invalid compression algorithm"},
393 {ERR_REASON(SSL_R_INVALID_PURPOSE) , "invalid purpose"},
394 {ERR_REASON(SSL_R_INVALID_SRP_USERNAME) , "invalid srp username"},
395 {ERR_REASON(SSL_R_INVALID_STATUS_RESPONSE), "invalid status response"},
396 {ERR_REASON(SSL_R_INVALID_TICKET_KEYS_LENGTH), "invalid ticket keys length"},
397 {ERR_REASON(SSL_R_INVALID_TRUST) , "invalid trust"},
398 {ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) , "key arg too long"},
399 {ERR_REASON(SSL_R_KRB5) , "krb5"},
400 {ERR_REASON(SSL_R_KRB5_C_CC_PRINC) , "krb5 client cc principal (no tkt?)"},
401 {ERR_REASON(SSL_R_KRB5_C_GET_CRED) , "krb5 client get cred"},
402 {ERR_REASON(SSL_R_KRB5_C_INIT) , "krb5 client init"},
403 {ERR_REASON(SSL_R_KRB5_C_MK_REQ) , "krb5 client mk_req (expired tkt?)"},
404 {ERR_REASON(SSL_R_KRB5_S_BAD_TICKET) , "krb5 server bad ticket"},
405 {ERR_REASON(SSL_R_KRB5_S_INIT) , "krb5 server init"},
406 {ERR_REASON(SSL_R_KRB5_S_RD_REQ) , "krb5 server rd_req (keytab perms?)"},
407 {ERR_REASON(SSL_R_KRB5_S_TKT_EXPIRED) , "krb5 server tkt expired"},
408 {ERR_REASON(SSL_R_KRB5_S_TKT_NYV) , "krb5 server tkt not yet valid"},
409 {ERR_REASON(SSL_R_KRB5_S_TKT_SKEW) , "krb5 server tkt skew"},
410 {ERR_REASON(SSL_R_LENGTH_MISMATCH) , "length mismatch"},
411 {ERR_REASON(SSL_R_LENGTH_TOO_SHORT) , "length too short"},
412 {ERR_REASON(SSL_R_LIBRARY_BUG) , "library bug"},
413 {ERR_REASON(SSL_R_LIBRARY_HAS_NO_CIPHERS), "library has no ciphers"},
414 {ERR_REASON(SSL_R_MESSAGE_TOO_LONG) , "message too long"},
415 {ERR_REASON(SSL_R_MISSING_DH_DSA_CERT) , "missing dh dsa cert"},
416 {ERR_REASON(SSL_R_MISSING_DH_KEY) , "missing dh key"},
417 {ERR_REASON(SSL_R_MISSING_DH_RSA_CERT) , "missing dh rsa cert"},
418 {ERR_REASON(SSL_R_MISSING_DSA_SIGNING_CERT), "missing dsa signing cert"},
419 {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_DH_KEY), "missing export tmp dh key"},
420 {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_RSA_KEY), "missing export tmp rsa key"},
421 {ERR_REASON(SSL_R_MISSING_RSA_CERTIFICATE), "missing rsa certificate"},
422 {ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT), "missing rsa encrypting cert"},
423 {ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT), "missing rsa signing cert"},
424 {ERR_REASON(SSL_R_MISSING_SRP_PARAM) , "can't find SRP server param"},
425 {ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) , "missing tmp dh key"},
426 {ERR_REASON(SSL_R_MISSING_TMP_ECDH_KEY) , "missing tmp ecdh key"},
427 {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) , "missing tmp rsa key"},
428 {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) , "missing tmp rsa pkey"},
429 {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE), "missing verify message"},
430 {ERR_REASON(SSL_R_MULTIPLE_SGC_RESTARTS) , "multiple sgc restarts"},
431 {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET), "non sslv2 initial packet"},
432 {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED), "no certificates returned"},
433 {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED), "no certificate assigned"},
434 {ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED), "no certificate returned"},
435 {ERR_REASON(SSL_R_NO_CERTIFICATE_SET) , "no certificate set"},
436 {ERR_REASON(SSL_R_NO_CERTIFICATE_SPECIFIED), "no certificate specified"},
437 {ERR_REASON(SSL_R_NO_CIPHERS_AVAILABLE) , "no ciphers available"},
438 {ERR_REASON(SSL_R_NO_CIPHERS_PASSED) , "no ciphers passed"},
439 {ERR_REASON(SSL_R_NO_CIPHERS_SPECIFIED) , "no ciphers specified"},
440 {ERR_REASON(SSL_R_NO_CIPHER_LIST) , "no cipher list"},
441 {ERR_REASON(SSL_R_NO_CIPHER_MATCH) , "no cipher match"},
442 {ERR_REASON(SSL_R_NO_CLIENT_CERT_METHOD) , "no client cert method"},
443 {ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED), "no client cert received"},
444 {ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED), "no compression specified"},
445 {ERR_REASON(SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER), "Peer haven't sent GOST certificate, required for selected ciphersuite"},
446 {ERR_REASON(SSL_R_NO_METHOD_SPECIFIED) , "no method specified"},
447 {ERR_REASON(SSL_R_NO_PRIVATEKEY) , "no privatekey"},
448 {ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED), "no private key assigned"},
449 {ERR_REASON(SSL_R_NO_PROTOCOLS_AVAILABLE), "no protocols available"},
450 {ERR_REASON(SSL_R_NO_PUBLICKEY) , "no publickey"},
451 {ERR_REASON(SSL_R_NO_RENEGOTIATION) , "no renegotiation"},
452 {ERR_REASON(SSL_R_NO_REQUIRED_DIGEST) , "digest requred for handshake isn't computed"},
453 {ERR_REASON(SSL_R_NO_SHARED_CIPHER) , "no shared cipher"},
454 {ERR_REASON(SSL_R_NO_SRTP_PROFILES) , "no srtp profiles"},
455 {ERR_REASON(SSL_R_NO_VERIFY_CALLBACK) , "no verify callback"},
456 {ERR_REASON(SSL_R_NULL_SSL_CTX) , "null ssl ctx"},
457 {ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED), "null ssl method passed"},
458 {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED), "old session cipher not returned"},
459 {ERR_REASON(SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED), "old session compression algorithm not returned"},
460 {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE), "only tls allowed in fips mode"},
461 {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG), "packet length too long"},
462 {ERR_REASON(SSL_R_PARSE_TLSEXT) , "parse tlsext"},
463 {ERR_REASON(SSL_R_PATH_TOO_LONG) , "path too long"},
464 {ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE), "peer did not return a certificate"},
465 {ERR_REASON(SSL_R_PEER_ERROR) , "peer error"},
466 {ERR_REASON(SSL_R_PEER_ERROR_CERTIFICATE), "peer error certificate"},
467 {ERR_REASON(SSL_R_PEER_ERROR_NO_CERTIFICATE), "peer error no certificate"},
468 {ERR_REASON(SSL_R_PEER_ERROR_NO_CIPHER) , "peer error no cipher"},
469 {ERR_REASON(SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE), "peer error unsupported certificate type"},
470 {ERR_REASON(SSL_R_PRE_MAC_LENGTH_TOO_LONG), "pre mac length too long"},
471 {ERR_REASON(SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS), "problems mapping cipher functions"},
472 {ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN) , "protocol is shutdown"},
473 {ERR_REASON(SSL_R_PSK_IDENTITY_NOT_FOUND), "psk identity not found"},
474 {ERR_REASON(SSL_R_PSK_NO_CLIENT_CB) , "psk no client cb"},
475 {ERR_REASON(SSL_R_PSK_NO_SERVER_CB) , "psk no server cb"},
476 {ERR_REASON(SSL_R_PUBLIC_KEY_ENCRYPT_ERROR), "public key encrypt error"},
477 {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) , "public key is not rsa"},
478 {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) , "public key not rsa"},
479 {ERR_REASON(SSL_R_READ_BIO_NOT_SET) , "read bio not set"},
480 {ERR_REASON(SSL_R_READ_TIMEOUT_EXPIRED) , "read timeout expired"},
481 {ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE), "read wrong packet type"},
482 {ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH), "record length mismatch"},
483 {ERR_REASON(SSL_R_RECORD_TOO_LARGE) , "record too large"},
484 {ERR_REASON(SSL_R_RECORD_TOO_SMALL) , "record too small"},
485 {ERR_REASON(SSL_R_RENEGOTIATE_EXT_TOO_LONG), "renegotiate ext too long"},
486 {ERR_REASON(SSL_R_RENEGOTIATION_ENCODING_ERR), "renegotiation encoding err"},
487 {ERR_REASON(SSL_R_RENEGOTIATION_MISMATCH), "renegotiation mismatch"},
488 {ERR_REASON(SSL_R_REQUIRED_CIPHER_MISSING), "required cipher missing"},
489 {ERR_REASON(SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING), "required compresssion algorithm missing"},
490 {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO), "reuse cert length not zero"},
491 {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO), "reuse cert type not zero"},
492 {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO), "reuse cipher list not zero"},
493 {ERR_REASON(SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING), "scsv received when renegotiating"},
494 {ERR_REASON(SSL_R_SERVERHELLO_TLSEXT) , "serverhello tlsext"},
495 {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED), "session id context uninitialized"},
496 {ERR_REASON(SSL_R_SHORT_READ) , "short read"},
497 {ERR_REASON(SSL_R_SIGNATURE_ALGORITHMS_ERROR), "signature algorithms error"},
498 {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE), "signature for non signing certificate"},
499 {ERR_REASON(SSL_R_SRP_A_CALC) , "error with the srp params"},
500 {ERR_REASON(SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES), "srtp could not allocate profiles"},
501 {ERR_REASON(SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG), "srtp protection profile list too long"},
502 {ERR_REASON(SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE), "srtp unknown protection profile"},
503 {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE), "ssl23 doing session id reuse"},
504 {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG), "ssl2 connection id too long"},
505 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT), "ssl3 ext invalid ecpointformat"},
506 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME), "ssl3 ext invalid servername"},
507 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE), "ssl3 ext invalid servername type"},
508 {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG), "ssl3 session id too long"},
509 {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT), "ssl3 session id too short"},
510 {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE), "sslv3 alert bad certificate"},
511 {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_RECORD_MAC), "sslv3 alert bad record mac"},
512 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED), "sslv3 alert certificate expired"},
513 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED), "sslv3 alert certificate revoked"},
514 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN), "sslv3 alert certificate unknown"},
515 {ERR_REASON(SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE), "sslv3 alert decompression failure"},
516 {ERR_REASON(SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE), "sslv3 alert handshake failure"},
517 {ERR_REASON(SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER), "sslv3 alert illegal parameter"},
518 {ERR_REASON(SSL_R_SSLV3_ALERT_NO_CERTIFICATE), "sslv3 alert no certificate"},
519 {ERR_REASON(SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE), "sslv3 alert unexpected message"},
520 {ERR_REASON(SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE), "sslv3 alert unsupported certificate"},
521 {ERR_REASON(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION), "ssl ctx has no default ssl version"},
522 {ERR_REASON(SSL_R_SSL_HANDSHAKE_FAILURE) , "ssl handshake failure"},
523 {ERR_REASON(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS), "ssl library has no ciphers"},
524 {ERR_REASON(SSL_R_SSL_SESSION_ID_CALLBACK_FAILED), "ssl session id callback failed"},
525 {ERR_REASON(SSL_R_SSL_SESSION_ID_CONFLICT), "ssl session id conflict"},
526 {ERR_REASON(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG), "ssl session id context too long"},
527 {ERR_REASON(SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH), "ssl session id has bad length"},
528 {ERR_REASON(SSL_R_SSL_SESSION_ID_IS_DIFFERENT), "ssl session id is different"},
529 {ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED), "tlsv1 alert access denied"},
530 {ERR_REASON(SSL_R_TLSV1_ALERT_DECODE_ERROR), "tlsv1 alert decode error"},
531 {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED), "tlsv1 alert decryption failed"},
532 {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPT_ERROR), "tlsv1 alert decrypt error"},
533 {ERR_REASON(SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION), "tlsv1 alert export restriction"},
534 {ERR_REASON(SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK), "tlsv1 alert inappropriate fallback"},
535 {ERR_REASON(SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY), "tlsv1 alert insufficient security"},
536 {ERR_REASON(SSL_R_TLSV1_ALERT_INTERNAL_ERROR), "tlsv1 alert internal error"},
537 {ERR_REASON(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION), "tlsv1 alert no renegotiation"},
538 {ERR_REASON(SSL_R_TLSV1_ALERT_PROTOCOL_VERSION), "tlsv1 alert protocol version"},
539 {ERR_REASON(SSL_R_TLSV1_ALERT_RECORD_OVERFLOW), "tlsv1 alert record overflow"},
540 {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA), "tlsv1 alert unknown ca"},
541 {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED), "tlsv1 alert user cancelled"},
542 {ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE), "tlsv1 bad certificate hash value"},
543 {ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE), "tlsv1 bad certificate status response"},
544 {ERR_REASON(SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE), "tlsv1 certificate unobtainable"},
545 {ERR_REASON(SSL_R_TLSV1_UNRECOGNIZED_NAME), "tlsv1 unrecognized name"},
546 {ERR_REASON(SSL_R_TLSV1_UNSUPPORTED_EXTENSION), "tlsv1 unsupported extension"},
547 {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER), "tls client cert req with anon cipher"},
548 {ERR_REASON(SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT), "peer does not accept heartbeats"},
549 {ERR_REASON(SSL_R_TLS_HEARTBEAT_PENDING) , "heartbeat request already pending"},
550 {ERR_REASON(SSL_R_TLS_ILLEGAL_EXPORTER_LABEL), "tls illegal exporter label"},
551 {ERR_REASON(SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST), "tls invalid ecpointformat list"},
552 {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST), "tls peer did not respond with certificate list"},
553 {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG), "tls rsa encrypted value length is wrong"},
554 {ERR_REASON(SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER), "tried to use unsupported cipher"},
555 {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS), "unable to decode dh certs"},
556 {ERR_REASON(SSL_R_UNABLE_TO_DECODE_ECDH_CERTS), "unable to decode ecdh certs"},
557 {ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY), "unable to extract public key"},
558 {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS), "unable to find dh parameters"},
559 {ERR_REASON(SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS), "unable to find ecdh parameters"},
560 {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS), "unable to find public key parameters"},
561 {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD), "unable to find ssl method"},
562 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES), "unable to load ssl2 md5 routines"},
563 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES), "unable to load ssl3 md5 routines"},
564 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES), "unable to load ssl3 sha1 routines"},
565 {ERR_REASON(SSL_R_UNEXPECTED_MESSAGE) , "unexpected message"},
566 {ERR_REASON(SSL_R_UNEXPECTED_RECORD) , "unexpected record"},
567 {ERR_REASON(SSL_R_UNINITIALIZED) , "uninitialized"},
568 {ERR_REASON(SSL_R_UNKNOWN_ALERT_TYPE) , "unknown alert type"},
569 {ERR_REASON(SSL_R_UNKNOWN_CERTIFICATE_TYPE), "unknown certificate type"},
570 {ERR_REASON(SSL_R_UNKNOWN_CIPHER_RETURNED), "unknown cipher returned"},
571 {ERR_REASON(SSL_R_UNKNOWN_CIPHER_TYPE) , "unknown cipher type"},
572 {ERR_REASON(SSL_R_UNKNOWN_DIGEST) , "unknown digest"},
573 {ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE), "unknown key exchange type"},
574 {ERR_REASON(SSL_R_UNKNOWN_PKEY_TYPE) , "unknown pkey type"},
575 {ERR_REASON(SSL_R_UNKNOWN_PROTOCOL) , "unknown protocol"},
576 {ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE), "unknown remote error type"},
577 {ERR_REASON(SSL_R_UNKNOWN_SSL_VERSION) , "unknown ssl version"},
578 {ERR_REASON(SSL_R_UNKNOWN_STATE) , "unknown state"},
579 {ERR_REASON(SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED), "unsafe legacy renegotiation disabled"},
580 {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) , "unsupported cipher"},
581 {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM), "unsupported compression algorithm"},
582 {ERR_REASON(SSL_R_UNSUPPORTED_DIGEST_TYPE), "unsupported digest type"},
583 {ERR_REASON(SSL_R_UNSUPPORTED_ELLIPTIC_CURVE), "unsupported elliptic curve"},
584 {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) , "unsupported protocol"},
585 {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION), "unsupported ssl version"},
586 {ERR_REASON(SSL_R_UNSUPPORTED_STATUS_TYPE), "unsupported status type"},
587 {ERR_REASON(SSL_R_USE_SRTP_NOT_NEGOTIATED), "use srtp not negotiated"},
588 {ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) , "write bio not set"},
589 {ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) , "wrong cipher returned"},
590 {ERR_REASON(SSL_R_WRONG_CURVE) , "wrong curve"},
591 {ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) , "wrong message type"},
592 {ERR_REASON(SSL_R_WRONG_NUMBER_OF_KEY_BITS), "wrong number of key bits"},
593 {ERR_REASON(SSL_R_WRONG_SIGNATURE_LENGTH), "wrong signature length"},
594 {ERR_REASON(SSL_R_WRONG_SIGNATURE_SIZE) , "wrong signature size"},
595 {ERR_REASON(SSL_R_WRONG_SIGNATURE_TYPE) , "wrong signature type"},
596 {ERR_REASON(SSL_R_WRONG_SSL_VERSION) , "wrong ssl version"},
597 {ERR_REASON(SSL_R_WRONG_VERSION_NUMBER) , "wrong version number"},
598 {ERR_REASON(SSL_R_X509_LIB) , "x509 lib"},
599 {ERR_REASON(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS), "x509 verification setup problems"},
600 {0, NULL}
601};
602
603#endif
604
605void
606ERR_load_SSL_strings(void)
607{
608#ifndef OPENSSL_NO_ERR
609
610 if (ERR_func_error_string(SSL_str_functs[0].error) == NULL) {
611 ERR_load_strings(0, SSL_str_functs);
612 ERR_load_strings(0, SSL_str_reasons);
613 }
614#endif
615}
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c
deleted file mode 100644
index 9aad13cdc5..0000000000
--- a/src/lib/libssl/ssl_err2.c
+++ /dev/null
@@ -1,72 +0,0 @@
1/* $OpenBSD: ssl_err2.c,v 1.7 2014/12/14 15:30:50 jsing Exp $ */
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
61#include <openssl/err.h>
62#include <openssl/ssl.h>
63
64void
65SSL_load_error_strings(void)
66{
67#ifndef OPENSSL_NO_ERR
68 ERR_load_crypto_strings();
69 ERR_load_SSL_strings();
70#endif
71}
72
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
deleted file mode 100644
index 5b9b952e72..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,3062 +0,0 @@
1/* $OpenBSD: ssl_lib.c,v 1.116 2015/10/25 15:52:49 doug Exp $ */
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-2007 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 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#include <stdio.h>
144
145#include "ssl_locl.h"
146
147#include <openssl/bn.h>
148#include <openssl/dh.h>
149#include <openssl/lhash.h>
150#include <openssl/objects.h>
151#include <openssl/ocsp.h>
152#include <openssl/x509v3.h>
153
154#ifndef OPENSSL_NO_ENGINE
155#include <openssl/engine.h>
156#endif
157
158#include "bytestring.h"
159
160const char *SSL_version_str = OPENSSL_VERSION_TEXT;
161
162SSL3_ENC_METHOD ssl3_undef_enc_method = {
163 /*
164 * Evil casts, but these functions are only called if there's a
165 * library bug.
166 */
167 .enc = (int (*)(SSL *, int))ssl_undefined_function,
168 .mac = (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
169 .setup_key_block = ssl_undefined_function,
170 .generate_master_secret = (int (*)(SSL *, unsigned char *,
171 unsigned char *, int))ssl_undefined_function,
172 .change_cipher_state = (int (*)(SSL*, int))ssl_undefined_function,
173 .final_finish_mac = (int (*)(SSL *, const char*, int,
174 unsigned char *))ssl_undefined_function,
175 .finish_mac_length = 0,
176 .cert_verify_mac = (int (*)(SSL *, int,
177 unsigned char *))ssl_undefined_function,
178 .client_finished_label = NULL,
179 .client_finished_label_len = 0,
180 .server_finished_label = NULL,
181 .server_finished_label_len = 0,
182 .alert_value = (int (*)(int))ssl_undefined_function,
183 .export_keying_material = (int (*)(SSL *, unsigned char *, size_t,
184 const char *, size_t, const unsigned char *, size_t,
185 int use_context))ssl_undefined_function,
186 .enc_flags = 0,
187};
188
189int
190SSL_clear(SSL *s)
191{
192 if (s->method == NULL) {
193 SSLerr(SSL_F_SSL_CLEAR, SSL_R_NO_METHOD_SPECIFIED);
194 return (0);
195 }
196
197 if (ssl_clear_bad_session(s)) {
198 SSL_SESSION_free(s->session);
199 s->session = NULL;
200 }
201
202 s->error = 0;
203 s->hit = 0;
204 s->shutdown = 0;
205
206 if (s->renegotiate) {
207 SSLerr(SSL_F_SSL_CLEAR, ERR_R_INTERNAL_ERROR);
208 return (0);
209 }
210
211 s->type = 0;
212
213 s->state = SSL_ST_BEFORE|((s->server) ? SSL_ST_ACCEPT : SSL_ST_CONNECT);
214
215 s->version = s->method->version;
216 s->client_version = s->version;
217 s->rwstate = SSL_NOTHING;
218 s->rstate = SSL_ST_READ_HEADER;
219
220 BUF_MEM_free(s->init_buf);
221 s->init_buf = NULL;
222
223 ssl_clear_cipher_ctx(s);
224 ssl_clear_hash_ctx(&s->read_hash);
225 ssl_clear_hash_ctx(&s->write_hash);
226
227 s->first_packet = 0;
228
229 /*
230 * Check to see if we were changed into a different method, if
231 * so, revert back if we are not doing session-id reuse.
232 */
233 if (!s->in_handshake && (s->session == NULL) &&
234 (s->method != s->ctx->method)) {
235 s->method->ssl_free(s);
236 s->method = s->ctx->method;
237 if (!s->method->ssl_new(s))
238 return (0);
239 } else
240 s->method->ssl_clear(s);
241
242 return (1);
243}
244
245/* Used to change an SSL_CTXs default SSL method type */
246int
247SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth)
248{
249 STACK_OF(SSL_CIPHER) *sk;
250
251 ctx->method = meth;
252
253 sk = ssl_create_cipher_list(ctx->method, &(ctx->cipher_list),
254 &(ctx->cipher_list_by_id), SSL_DEFAULT_CIPHER_LIST);
255 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) {
256 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,
257 SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
258 return (0);
259 }
260 return (1);
261}
262
263SSL *
264SSL_new(SSL_CTX *ctx)
265{
266 SSL *s;
267
268 if (ctx == NULL) {
269 SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);
270 return (NULL);
271 }
272 if (ctx->method == NULL) {
273 SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
274 return (NULL);
275 }
276
277 s = calloc(1, sizeof(SSL));
278 if (s == NULL)
279 goto err;
280
281
282 s->options = ctx->options;
283 s->mode = ctx->mode;
284 s->max_cert_list = ctx->max_cert_list;
285
286 if (ctx->cert != NULL) {
287 /*
288 * Earlier library versions used to copy the pointer to
289 * the CERT, not its contents; only when setting new
290 * parameters for the per-SSL copy, ssl_cert_new would be
291 * called (and the direct reference to the per-SSL_CTX
292 * settings would be lost, but those still were indirectly
293 * accessed for various purposes, and for that reason they
294 * used to be known as s->ctx->default_cert).
295 * Now we don't look at the SSL_CTX's CERT after having
296 * duplicated it once.
297 */
298 s->cert = ssl_cert_dup(ctx->cert);
299 if (s->cert == NULL)
300 goto err;
301 } else
302 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
303
304 s->read_ahead = ctx->read_ahead;
305 s->msg_callback = ctx->msg_callback;
306 s->msg_callback_arg = ctx->msg_callback_arg;
307 s->verify_mode = ctx->verify_mode;
308 s->sid_ctx_length = ctx->sid_ctx_length;
309 OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);
310 memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));
311 s->verify_callback = ctx->default_verify_callback;
312 s->generate_session_id = ctx->generate_session_id;
313
314 s->param = X509_VERIFY_PARAM_new();
315 if (!s->param)
316 goto err;
317 X509_VERIFY_PARAM_inherit(s->param, ctx->param);
318 s->quiet_shutdown = ctx->quiet_shutdown;
319 s->max_send_fragment = ctx->max_send_fragment;
320
321 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
322 s->ctx = ctx;
323 s->tlsext_debug_cb = 0;
324 s->tlsext_debug_arg = NULL;
325 s->tlsext_ticket_expected = 0;
326 s->tlsext_status_type = -1;
327 s->tlsext_status_expected = 0;
328 s->tlsext_ocsp_ids = NULL;
329 s->tlsext_ocsp_exts = NULL;
330 s->tlsext_ocsp_resp = NULL;
331 s->tlsext_ocsp_resplen = -1;
332 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
333 s->initial_ctx = ctx;
334 s->next_proto_negotiated = NULL;
335
336 if (s->ctx->alpn_client_proto_list != NULL) {
337 s->alpn_client_proto_list =
338 malloc(s->ctx->alpn_client_proto_list_len);
339 if (s->alpn_client_proto_list == NULL)
340 goto err;
341 memcpy(s->alpn_client_proto_list,
342 s->ctx->alpn_client_proto_list,
343 s->ctx->alpn_client_proto_list_len);
344 s->alpn_client_proto_list_len =
345 s->ctx->alpn_client_proto_list_len;
346 }
347
348 s->verify_result = X509_V_OK;
349
350 s->method = ctx->method;
351
352 if (!s->method->ssl_new(s))
353 goto err;
354
355 s->references = 1;
356 s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;
357
358 SSL_clear(s);
359
360 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
361
362 return (s);
363
364err:
365 SSL_free(s);
366 SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);
367 return (NULL);
368}
369
370int
371SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
372 unsigned int sid_ctx_len)
373{
374 if (sid_ctx_len > sizeof ctx->sid_ctx) {
375 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,
376 SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
377 return (0);
378 }
379 ctx->sid_ctx_length = sid_ctx_len;
380 memcpy(ctx->sid_ctx, sid_ctx, sid_ctx_len);
381
382 return (1);
383}
384
385int
386SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
387 unsigned int sid_ctx_len)
388{
389 if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
390 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,
391 SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
392 return (0);
393 }
394 ssl->sid_ctx_length = sid_ctx_len;
395 memcpy(ssl->sid_ctx, sid_ctx, sid_ctx_len);
396
397 return (1);
398}
399
400int
401SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb)
402{
403 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
404 ctx->generate_session_id = cb;
405 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
406 return (1);
407}
408
409int
410SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb)
411{
412 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
413 ssl->generate_session_id = cb;
414 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
415 return (1);
416}
417
418int
419SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
420 unsigned int id_len)
421{
422 /*
423 * A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp
424 * shows how we can "construct" a session to give us the desired
425 * check - ie. to find if there's a session in the hash table
426 * that would conflict with any new session built out of this
427 * id/id_len and the ssl_version in use by this SSL.
428 */
429 SSL_SESSION r, *p;
430
431 if (id_len > sizeof r.session_id)
432 return (0);
433
434 r.ssl_version = ssl->version;
435 r.session_id_length = id_len;
436 memcpy(r.session_id, id, id_len);
437
438 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
439 p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r);
440 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
441 return (p != NULL);
442}
443
444int
445SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
446{
447 return (X509_VERIFY_PARAM_set_purpose(s->param, purpose));
448}
449
450int
451SSL_set_purpose(SSL *s, int purpose)
452{
453 return (X509_VERIFY_PARAM_set_purpose(s->param, purpose));
454}
455
456int
457SSL_CTX_set_trust(SSL_CTX *s, int trust)
458{
459 return (X509_VERIFY_PARAM_set_trust(s->param, trust));
460}
461
462int
463SSL_set_trust(SSL *s, int trust)
464{
465 return (X509_VERIFY_PARAM_set_trust(s->param, trust));
466}
467
468int
469SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm)
470{
471 return (X509_VERIFY_PARAM_set1(ctx->param, vpm));
472}
473
474int
475SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm)
476{
477 return (X509_VERIFY_PARAM_set1(ssl->param, vpm));
478}
479
480void
481SSL_free(SSL *s)
482{
483 int i;
484
485 if (s == NULL)
486 return;
487
488 i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);
489 if (i > 0)
490 return;
491
492 if (s->param)
493 X509_VERIFY_PARAM_free(s->param);
494
495 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
496
497 if (s->bbio != NULL) {
498 /* If the buffering BIO is in place, pop it off */
499 if (s->bbio == s->wbio) {
500 s->wbio = BIO_pop(s->wbio);
501 }
502 BIO_free(s->bbio);
503 s->bbio = NULL;
504 }
505
506 if (s->rbio != s->wbio)
507 BIO_free_all(s->rbio);
508 BIO_free_all(s->wbio);
509
510 if (s->init_buf != NULL)
511 BUF_MEM_free(s->init_buf);
512
513 /* add extra stuff */
514 if (s->cipher_list != NULL)
515 sk_SSL_CIPHER_free(s->cipher_list);
516 if (s->cipher_list_by_id != NULL)
517 sk_SSL_CIPHER_free(s->cipher_list_by_id);
518
519 /* Make the next call work :-) */
520 if (s->session != NULL) {
521 ssl_clear_bad_session(s);
522 SSL_SESSION_free(s->session);
523 }
524
525 ssl_clear_cipher_ctx(s);
526 ssl_clear_hash_ctx(&s->read_hash);
527 ssl_clear_hash_ctx(&s->write_hash);
528
529 if (s->cert != NULL)
530 ssl_cert_free(s->cert);
531 /* Free up if allocated */
532
533 free(s->tlsext_hostname);
534 SSL_CTX_free(s->initial_ctx);
535 free(s->tlsext_ecpointformatlist);
536 free(s->tlsext_ellipticcurvelist);
537 if (s->tlsext_ocsp_exts)
538 sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
539 X509_EXTENSION_free);
540 if (s->tlsext_ocsp_ids)
541 sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);
542 free(s->tlsext_ocsp_resp);
543
544 if (s->client_CA != NULL)
545 sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);
546
547 if (s->method != NULL)
548 s->method->ssl_free(s);
549
550 SSL_CTX_free(s->ctx);
551
552
553 free(s->next_proto_negotiated);
554 free(s->alpn_client_proto_list);
555
556#ifndef OPENSSL_NO_SRTP
557 if (s->srtp_profiles)
558 sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);
559#endif
560
561 free(s);
562}
563
564void
565SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio)
566{
567 /* If the output buffering BIO is still in place, remove it */
568 if (s->bbio != NULL) {
569 if (s->wbio == s->bbio) {
570 s->wbio = s->wbio->next_bio;
571 s->bbio->next_bio = NULL;
572 }
573 }
574
575 if (s->rbio != rbio && s->rbio != s->wbio)
576 BIO_free_all(s->rbio);
577 if (s->wbio != wbio)
578 BIO_free_all(s->wbio);
579 s->rbio = rbio;
580 s->wbio = wbio;
581}
582
583BIO *
584SSL_get_rbio(const SSL *s)
585{
586 return (s->rbio);
587}
588
589BIO *
590SSL_get_wbio(const SSL *s)
591{
592 return (s->wbio);
593}
594
595int
596SSL_get_fd(const SSL *s)
597{
598 return (SSL_get_rfd(s));
599}
600
601int
602SSL_get_rfd(const SSL *s)
603{
604 int ret = -1;
605 BIO *b, *r;
606
607 b = SSL_get_rbio(s);
608 r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR);
609 if (r != NULL)
610 BIO_get_fd(r, &ret);
611 return (ret);
612}
613
614int
615SSL_get_wfd(const SSL *s)
616{
617 int ret = -1;
618 BIO *b, *r;
619
620 b = SSL_get_wbio(s);
621 r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR);
622 if (r != NULL)
623 BIO_get_fd(r, &ret);
624 return (ret);
625}
626
627int
628SSL_set_fd(SSL *s, int fd)
629{
630 int ret = 0;
631 BIO *bio = NULL;
632
633 bio = BIO_new(BIO_s_socket());
634
635 if (bio == NULL) {
636 SSLerr(SSL_F_SSL_SET_FD, ERR_R_BUF_LIB);
637 goto err;
638 }
639 BIO_set_fd(bio, fd, BIO_NOCLOSE);
640 SSL_set_bio(s, bio, bio);
641 ret = 1;
642err:
643 return (ret);
644}
645
646int
647SSL_set_wfd(SSL *s, int fd)
648{
649 int ret = 0;
650 BIO *bio = NULL;
651
652 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
653 || ((int)BIO_get_fd(s->rbio, NULL) != fd)) {
654 bio = BIO_new(BIO_s_socket());
655
656 if (bio == NULL) {
657 SSLerr(SSL_F_SSL_SET_WFD, ERR_R_BUF_LIB);
658 goto err;
659 }
660 BIO_set_fd(bio, fd, BIO_NOCLOSE);
661 SSL_set_bio(s, SSL_get_rbio(s), bio);
662 } else
663 SSL_set_bio(s, SSL_get_rbio(s), SSL_get_rbio(s));
664 ret = 1;
665err:
666 return (ret);
667}
668
669int
670SSL_set_rfd(SSL *s, int fd)
671{
672 int ret = 0;
673 BIO *bio = NULL;
674
675 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
676 || ((int)BIO_get_fd(s->wbio, NULL) != fd)) {
677 bio = BIO_new(BIO_s_socket());
678
679 if (bio == NULL) {
680 SSLerr(SSL_F_SSL_SET_RFD, ERR_R_BUF_LIB);
681 goto err;
682 }
683 BIO_set_fd(bio, fd, BIO_NOCLOSE);
684 SSL_set_bio(s, bio, SSL_get_wbio(s));
685 } else
686 SSL_set_bio(s, SSL_get_wbio(s), SSL_get_wbio(s));
687 ret = 1;
688err:
689 return (ret);
690}
691
692
693/* return length of latest Finished message we sent, copy to 'buf' */
694size_t
695SSL_get_finished(const SSL *s, void *buf, size_t count)
696{
697 size_t ret = 0;
698
699 if (s->s3 != NULL) {
700 ret = s->s3->tmp.finish_md_len;
701 if (count > ret)
702 count = ret;
703 memcpy(buf, s->s3->tmp.finish_md, count);
704 }
705 return (ret);
706}
707
708/* return length of latest Finished message we expected, copy to 'buf' */
709size_t
710SSL_get_peer_finished(const SSL *s, void *buf, size_t count)
711{
712 size_t ret = 0;
713
714 if (s->s3 != NULL) {
715 ret = s->s3->tmp.peer_finish_md_len;
716 if (count > ret)
717 count = ret;
718 memcpy(buf, s->s3->tmp.peer_finish_md, count);
719 }
720 return (ret);
721}
722
723
724int
725SSL_get_verify_mode(const SSL *s)
726{
727 return (s->verify_mode);
728}
729
730int
731SSL_get_verify_depth(const SSL *s)
732{
733 return (X509_VERIFY_PARAM_get_depth(s->param));
734}
735
736int
737(*SSL_get_verify_callback(const SSL *s))(int, X509_STORE_CTX *)
738{
739 return (s->verify_callback);
740}
741
742int
743SSL_CTX_get_verify_mode(const SSL_CTX *ctx)
744{
745 return (ctx->verify_mode);
746}
747
748int
749SSL_CTX_get_verify_depth(const SSL_CTX *ctx)
750{
751 return (X509_VERIFY_PARAM_get_depth(ctx->param));
752}
753
754int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *)
755{
756 return (ctx->default_verify_callback);
757}
758
759void
760SSL_set_verify(SSL *s, int mode,
761 int (*callback)(int ok, X509_STORE_CTX *ctx))
762{
763 s->verify_mode = mode;
764 if (callback != NULL)
765 s->verify_callback = callback;
766}
767
768void
769SSL_set_verify_depth(SSL *s, int depth)
770{
771 X509_VERIFY_PARAM_set_depth(s->param, depth);
772}
773
774void
775SSL_set_read_ahead(SSL *s, int yes)
776{
777 s->read_ahead = yes;
778}
779
780int
781SSL_get_read_ahead(const SSL *s)
782{
783 return (s->read_ahead);
784}
785
786int
787SSL_pending(const SSL *s)
788{
789 /*
790 * SSL_pending cannot work properly if read-ahead is enabled
791 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)),
792 * and it is impossible to fix since SSL_pending cannot report
793 * errors that may be observed while scanning the new data.
794 * (Note that SSL_pending() is often used as a boolean value,
795 * so we'd better not return -1.)
796 */
797 return (s->method->ssl_pending(s));
798}
799
800X509 *
801SSL_get_peer_certificate(const SSL *s)
802{
803 X509 *r;
804
805 if ((s == NULL) || (s->session == NULL))
806 r = NULL;
807 else
808 r = s->session->peer;
809
810 if (r == NULL)
811 return (r);
812
813 CRYPTO_add(&r->references, 1, CRYPTO_LOCK_X509);
814
815 return (r);
816}
817
818STACK_OF(X509) *
819SSL_get_peer_cert_chain(const SSL *s)
820{
821 STACK_OF(X509) *r;
822
823 if ((s == NULL) || (s->session == NULL) ||
824 (s->session->sess_cert == NULL))
825 r = NULL;
826 else
827 r = s->session->sess_cert->cert_chain;
828
829 /*
830 * If we are a client, cert_chain includes the peer's own
831 * certificate;
832 * if we are a server, it does not.
833 */
834 return (r);
835}
836
837/*
838 * Now in theory, since the calling process own 't' it should be safe to
839 * modify. We need to be able to read f without being hassled
840 */
841void
842SSL_copy_session_id(SSL *t, const SSL *f)
843{
844 CERT *tmp;
845
846 /* Do we need to to SSL locking? */
847 SSL_set_session(t, SSL_get_session(f));
848
849 /*
850 * What if we are setup as SSLv2 but want to talk SSLv3 or
851 * vice-versa.
852 */
853 if (t->method != f->method) {
854 t->method->ssl_free(t); /* cleanup current */
855 t->method=f->method; /* change method */
856 t->method->ssl_new(t); /* setup new */
857 }
858
859 tmp = t->cert;
860 if (f->cert != NULL) {
861 CRYPTO_add(&f->cert->references, 1, CRYPTO_LOCK_SSL_CERT);
862 t->cert = f->cert;
863 } else
864 t->cert = NULL;
865 if (tmp != NULL)
866 ssl_cert_free(tmp);
867 SSL_set_session_id_context(t, f->sid_ctx, f->sid_ctx_length);
868}
869
870/* Fix this so it checks all the valid key/cert options */
871int
872SSL_CTX_check_private_key(const SSL_CTX *ctx)
873{
874 if ((ctx == NULL) || (ctx->cert == NULL) ||
875 (ctx->cert->key->x509 == NULL)) {
876 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,
877 SSL_R_NO_CERTIFICATE_ASSIGNED);
878 return (0);
879 }
880 if (ctx->cert->key->privatekey == NULL) {
881 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,
882 SSL_R_NO_PRIVATE_KEY_ASSIGNED);
883 return (0);
884 }
885 return (X509_check_private_key(ctx->cert->key->x509,
886 ctx->cert->key->privatekey));
887}
888
889/* Fix this function so that it takes an optional type parameter */
890int
891SSL_check_private_key(const SSL *ssl)
892{
893 if (ssl == NULL) {
894 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,
895 ERR_R_PASSED_NULL_PARAMETER);
896 return (0);
897 }
898 if (ssl->cert == NULL) {
899 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,
900 SSL_R_NO_CERTIFICATE_ASSIGNED);
901 return (0);
902 }
903 if (ssl->cert->key->x509 == NULL) {
904 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,
905 SSL_R_NO_CERTIFICATE_ASSIGNED);
906 return (0);
907 }
908 if (ssl->cert->key->privatekey == NULL) {
909 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,
910 SSL_R_NO_PRIVATE_KEY_ASSIGNED);
911 return (0);
912 }
913 return (X509_check_private_key(ssl->cert->key->x509,
914 ssl->cert->key->privatekey));
915}
916
917int
918SSL_accept(SSL *s)
919{
920 if (s->handshake_func == NULL)
921 SSL_set_accept_state(s); /* Not properly initialized yet */
922
923 return (s->method->ssl_accept(s));
924}
925
926int
927SSL_connect(SSL *s)
928{
929 if (s->handshake_func == NULL)
930 SSL_set_connect_state(s); /* Not properly initialized yet */
931
932 return (s->method->ssl_connect(s));
933}
934
935long
936SSL_get_default_timeout(const SSL *s)
937{
938 return (s->method->get_timeout());
939}
940
941int
942SSL_read(SSL *s, void *buf, int num)
943{
944 if (s->handshake_func == NULL) {
945 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
946 return (-1);
947 }
948
949 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
950 s->rwstate = SSL_NOTHING;
951 return (0);
952 }
953 return (s->method->ssl_read(s, buf, num));
954}
955
956int
957SSL_peek(SSL *s, void *buf, int num)
958{
959 if (s->handshake_func == NULL) {
960 SSLerr(SSL_F_SSL_PEEK, SSL_R_UNINITIALIZED);
961 return (-1);
962 }
963
964 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
965 return (0);
966 }
967 return (s->method->ssl_peek(s, buf, num));
968}
969
970int
971SSL_write(SSL *s, const void *buf, int num)
972{
973 if (s->handshake_func == NULL) {
974 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
975 return (-1);
976 }
977
978 if (s->shutdown & SSL_SENT_SHUTDOWN) {
979 s->rwstate = SSL_NOTHING;
980 SSLerr(SSL_F_SSL_WRITE, SSL_R_PROTOCOL_IS_SHUTDOWN);
981 return (-1);
982 }
983 return (s->method->ssl_write(s, buf, num));
984}
985
986int
987SSL_shutdown(SSL *s)
988{
989 /*
990 * Note that this function behaves differently from what one might
991 * expect. Return values are 0 for no success (yet),
992 * 1 for success; but calling it once is usually not enough,
993 * even if blocking I/O is used (see ssl3_shutdown).
994 */
995
996 if (s->handshake_func == NULL) {
997 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
998 return (-1);
999 }
1000
1001 if ((s != NULL) && !SSL_in_init(s))
1002 return (s->method->ssl_shutdown(s));
1003 else
1004 return (1);
1005}
1006
1007int
1008SSL_renegotiate(SSL *s)
1009{
1010 if (s->renegotiate == 0)
1011 s->renegotiate = 1;
1012
1013 s->new_session = 1;
1014
1015 return (s->method->ssl_renegotiate(s));
1016}
1017
1018int
1019SSL_renegotiate_abbreviated(SSL *s)
1020{
1021 if (s->renegotiate == 0)
1022 s->renegotiate = 1;
1023
1024 s->new_session = 0;
1025
1026 return (s->method->ssl_renegotiate(s));
1027}
1028
1029int
1030SSL_renegotiate_pending(SSL *s)
1031{
1032 /*
1033 * Becomes true when negotiation is requested;
1034 * false again once a handshake has finished.
1035 */
1036 return (s->renegotiate != 0);
1037}
1038
1039long
1040SSL_ctrl(SSL *s, int cmd, long larg, void *parg)
1041{
1042 long l;
1043
1044 switch (cmd) {
1045 case SSL_CTRL_GET_READ_AHEAD:
1046 return (s->read_ahead);
1047 case SSL_CTRL_SET_READ_AHEAD:
1048 l = s->read_ahead;
1049 s->read_ahead = larg;
1050 return (l);
1051
1052 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
1053 s->msg_callback_arg = parg;
1054 return (1);
1055
1056 case SSL_CTRL_OPTIONS:
1057 return (s->options|=larg);
1058 case SSL_CTRL_CLEAR_OPTIONS:
1059 return (s->options&=~larg);
1060 case SSL_CTRL_MODE:
1061 return (s->mode|=larg);
1062 case SSL_CTRL_CLEAR_MODE:
1063 return (s->mode &=~larg);
1064 case SSL_CTRL_GET_MAX_CERT_LIST:
1065 return (s->max_cert_list);
1066 case SSL_CTRL_SET_MAX_CERT_LIST:
1067 l = s->max_cert_list;
1068 s->max_cert_list = larg;
1069 return (l);
1070 case SSL_CTRL_SET_MTU:
1071#ifndef OPENSSL_NO_DTLS1
1072 if (larg < (long)dtls1_min_mtu())
1073 return (0);
1074#endif
1075 if (SSL_IS_DTLS(s)) {
1076 s->d1->mtu = larg;
1077 return (larg);
1078 }
1079 return (0);
1080 case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
1081 if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
1082 return (0);
1083 s->max_send_fragment = larg;
1084 return (1);
1085 case SSL_CTRL_GET_RI_SUPPORT:
1086 if (s->s3)
1087 return (s->s3->send_connection_binding);
1088 else return (0);
1089 default:
1090 return (s->method->ssl_ctrl(s, cmd, larg, parg));
1091 }
1092}
1093
1094long
1095SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
1096{
1097 switch (cmd) {
1098 case SSL_CTRL_SET_MSG_CALLBACK:
1099 s->msg_callback = (void (*)(int write_p, int version,
1100 int content_type, const void *buf, size_t len,
1101 SSL *ssl, void *arg))(fp);
1102 return (1);
1103
1104 default:
1105 return (s->method->ssl_callback_ctrl(s, cmd, fp));
1106 }
1107}
1108
1109LHASH_OF(SSL_SESSION) *
1110SSL_CTX_sessions(SSL_CTX *ctx)
1111{
1112 return (ctx->sessions);
1113}
1114
1115long
1116SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
1117{
1118 long l;
1119
1120 switch (cmd) {
1121 case SSL_CTRL_GET_READ_AHEAD:
1122 return (ctx->read_ahead);
1123 case SSL_CTRL_SET_READ_AHEAD:
1124 l = ctx->read_ahead;
1125 ctx->read_ahead = larg;
1126 return (l);
1127
1128 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
1129 ctx->msg_callback_arg = parg;
1130 return (1);
1131
1132 case SSL_CTRL_GET_MAX_CERT_LIST:
1133 return (ctx->max_cert_list);
1134 case SSL_CTRL_SET_MAX_CERT_LIST:
1135 l = ctx->max_cert_list;
1136 ctx->max_cert_list = larg;
1137 return (l);
1138
1139 case SSL_CTRL_SET_SESS_CACHE_SIZE:
1140 l = ctx->session_cache_size;
1141 ctx->session_cache_size = larg;
1142 return (l);
1143 case SSL_CTRL_GET_SESS_CACHE_SIZE:
1144 return (ctx->session_cache_size);
1145 case SSL_CTRL_SET_SESS_CACHE_MODE:
1146 l = ctx->session_cache_mode;
1147 ctx->session_cache_mode = larg;
1148 return (l);
1149 case SSL_CTRL_GET_SESS_CACHE_MODE:
1150 return (ctx->session_cache_mode);
1151
1152 case SSL_CTRL_SESS_NUMBER:
1153 return (lh_SSL_SESSION_num_items(ctx->sessions));
1154 case SSL_CTRL_SESS_CONNECT:
1155 return (ctx->stats.sess_connect);
1156 case SSL_CTRL_SESS_CONNECT_GOOD:
1157 return (ctx->stats.sess_connect_good);
1158 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
1159 return (ctx->stats.sess_connect_renegotiate);
1160 case SSL_CTRL_SESS_ACCEPT:
1161 return (ctx->stats.sess_accept);
1162 case SSL_CTRL_SESS_ACCEPT_GOOD:
1163 return (ctx->stats.sess_accept_good);
1164 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
1165 return (ctx->stats.sess_accept_renegotiate);
1166 case SSL_CTRL_SESS_HIT:
1167 return (ctx->stats.sess_hit);
1168 case SSL_CTRL_SESS_CB_HIT:
1169 return (ctx->stats.sess_cb_hit);
1170 case SSL_CTRL_SESS_MISSES:
1171 return (ctx->stats.sess_miss);
1172 case SSL_CTRL_SESS_TIMEOUTS:
1173 return (ctx->stats.sess_timeout);
1174 case SSL_CTRL_SESS_CACHE_FULL:
1175 return (ctx->stats.sess_cache_full);
1176 case SSL_CTRL_OPTIONS:
1177 return (ctx->options|=larg);
1178 case SSL_CTRL_CLEAR_OPTIONS:
1179 return (ctx->options&=~larg);
1180 case SSL_CTRL_MODE:
1181 return (ctx->mode|=larg);
1182 case SSL_CTRL_CLEAR_MODE:
1183 return (ctx->mode&=~larg);
1184 case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
1185 if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
1186 return (0);
1187 ctx->max_send_fragment = larg;
1188 return (1);
1189 default:
1190 return (ctx->method->ssl_ctx_ctrl(ctx, cmd, larg, parg));
1191 }
1192}
1193
1194long
1195SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
1196{
1197 switch (cmd) {
1198 case SSL_CTRL_SET_MSG_CALLBACK:
1199 ctx->msg_callback = (void (*)(int write_p, int version,
1200 int content_type, const void *buf, size_t len, SSL *ssl,
1201 void *arg))(fp);
1202 return (1);
1203
1204 default:
1205 return (ctx->method->ssl_ctx_callback_ctrl(ctx, cmd, fp));
1206 }
1207}
1208
1209int
1210ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
1211{
1212 long l;
1213
1214 l = a->id - b->id;
1215 if (l == 0L)
1216 return (0);
1217 else
1218 return ((l > 0) ? 1:-1);
1219}
1220
1221int
1222ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1223 const SSL_CIPHER * const *bp)
1224{
1225 long l;
1226
1227 l = (*ap)->id - (*bp)->id;
1228 if (l == 0L)
1229 return (0);
1230 else
1231 return ((l > 0) ? 1:-1);
1232}
1233
1234/*
1235 * Return a STACK of the ciphers available for the SSL and in order of
1236 * preference.
1237 */
1238STACK_OF(SSL_CIPHER) *
1239SSL_get_ciphers(const SSL *s)
1240{
1241 if (s != NULL) {
1242 if (s->cipher_list != NULL) {
1243 return (s->cipher_list);
1244 } else if ((s->ctx != NULL) && (s->ctx->cipher_list != NULL)) {
1245 return (s->ctx->cipher_list);
1246 }
1247 }
1248 return (NULL);
1249}
1250
1251/*
1252 * Return a STACK of the ciphers available for the SSL and in order of
1253 * algorithm id.
1254 */
1255STACK_OF(SSL_CIPHER) *
1256ssl_get_ciphers_by_id(SSL *s)
1257{
1258 if (s != NULL) {
1259 if (s->cipher_list_by_id != NULL) {
1260 return (s->cipher_list_by_id);
1261 } else if ((s->ctx != NULL) &&
1262 (s->ctx->cipher_list_by_id != NULL)) {
1263 return (s->ctx->cipher_list_by_id);
1264 }
1265 }
1266 return (NULL);
1267}
1268
1269/* The old interface to get the same thing as SSL_get_ciphers(). */
1270const char *
1271SSL_get_cipher_list(const SSL *s, int n)
1272{
1273 SSL_CIPHER *c;
1274 STACK_OF(SSL_CIPHER) *sk;
1275
1276 if (s == NULL)
1277 return (NULL);
1278 sk = SSL_get_ciphers(s);
1279 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
1280 return (NULL);
1281 c = sk_SSL_CIPHER_value(sk, n);
1282 if (c == NULL)
1283 return (NULL);
1284 return (c->name);
1285}
1286
1287/* Specify the ciphers to be used by default by the SSL_CTX. */
1288int
1289SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
1290{
1291 STACK_OF(SSL_CIPHER) *sk;
1292
1293 sk = ssl_create_cipher_list(ctx->method, &ctx->cipher_list,
1294 &ctx->cipher_list_by_id, str);
1295 /*
1296 * ssl_create_cipher_list may return an empty stack if it
1297 * was unable to find a cipher matching the given rule string
1298 * (for example if the rule string specifies a cipher which
1299 * has been disabled). This is not an error as far as
1300 * ssl_create_cipher_list is concerned, and hence
1301 * ctx->cipher_list and ctx->cipher_list_by_id has been
1302 * updated.
1303 */
1304 if (sk == NULL)
1305 return (0);
1306 else if (sk_SSL_CIPHER_num(sk) == 0) {
1307 SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
1308 return (0);
1309 }
1310 return (1);
1311}
1312
1313/* Specify the ciphers to be used by the SSL. */
1314int
1315SSL_set_cipher_list(SSL *s, const char *str)
1316{
1317 STACK_OF(SSL_CIPHER) *sk;
1318
1319 sk = ssl_create_cipher_list(s->ctx->method, &s->cipher_list,
1320 &s->cipher_list_by_id, str);
1321 /* see comment in SSL_CTX_set_cipher_list */
1322 if (sk == NULL)
1323 return (0);
1324 else if (sk_SSL_CIPHER_num(sk) == 0) {
1325 SSLerr(SSL_F_SSL_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
1326 return (0);
1327 }
1328 return (1);
1329}
1330
1331/* works well for SSLv2, not so good for SSLv3 */
1332char *
1333SSL_get_shared_ciphers(const SSL *s, char *buf, int len)
1334{
1335 char *end;
1336 STACK_OF(SSL_CIPHER) *sk;
1337 SSL_CIPHER *c;
1338 size_t curlen = 0;
1339 int i;
1340
1341 if (s->session == NULL || s->session->ciphers == NULL || len < 2)
1342 return (NULL);
1343
1344 sk = s->session->ciphers;
1345 if (sk_SSL_CIPHER_num(sk) == 0)
1346 return (NULL);
1347
1348 buf[0] = '\0';
1349 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
1350 c = sk_SSL_CIPHER_value(sk, i);
1351 end = buf + curlen;
1352 if (strlcat(buf, c->name, len) >= len ||
1353 (curlen = strlcat(buf, ":", len)) >= len) {
1354 /* remove truncated cipher from list */
1355 *end = '\0';
1356 break;
1357 }
1358 }
1359 /* remove trailing colon */
1360 if ((end = strrchr(buf, ':')) != NULL)
1361 *end = '\0';
1362 return (buf);
1363}
1364
1365int
1366ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p)
1367{
1368 int i;
1369 SSL_CIPHER *c;
1370 unsigned char *q;
1371
1372 if (sk == NULL)
1373 return (0);
1374 q = p;
1375
1376 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
1377 c = sk_SSL_CIPHER_value(sk, i);
1378
1379 /* Skip TLS v1.2 only ciphersuites if lower than v1.2 */
1380 if ((c->algorithm_ssl & SSL_TLSV1_2) &&
1381 (TLS1_get_client_version(s) < TLS1_2_VERSION))
1382 continue;
1383
1384 s2n(ssl3_cipher_get_value(c), p);
1385 }
1386
1387 /*
1388 * If p == q, no ciphers and caller indicates an error. Otherwise
1389 * add SCSV if not renegotiating.
1390 */
1391 if (p != q && !s->renegotiate)
1392 s2n(SSL3_CK_SCSV & SSL3_CK_VALUE_MASK, p);
1393
1394 return (p - q);
1395}
1396
1397STACK_OF(SSL_CIPHER) *
1398ssl_bytes_to_cipher_list(SSL *s, const unsigned char *p, int num)
1399{
1400 CBS cbs;
1401 const SSL_CIPHER *c;
1402 STACK_OF(SSL_CIPHER) *sk = NULL;
1403 unsigned long cipher_id;
1404 uint16_t cipher_value, max_version;
1405
1406 if (s->s3)
1407 s->s3->send_connection_binding = 0;
1408
1409 /*
1410 * RFC 5246 section 7.4.1.2 defines the interval as [2,2^16-2].
1411 */
1412 if (num < 2 || num > 0x10000 - 2) {
1413 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,
1414 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1415 return (NULL);
1416 }
1417
1418 if ((sk = sk_SSL_CIPHER_new_null()) == NULL) {
1419 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST, ERR_R_MALLOC_FAILURE);
1420 goto err;
1421 }
1422
1423 CBS_init(&cbs, p, num);
1424 while (CBS_len(&cbs) > 0) {
1425 if (!CBS_get_u16(&cbs, &cipher_value)) {
1426 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,
1427 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1428 goto err;
1429 }
1430
1431 cipher_id = SSL3_CK_ID | cipher_value;
1432
1433 if (s->s3 != NULL && cipher_id == SSL3_CK_SCSV) {
1434 /*
1435 * TLS_EMPTY_RENEGOTIATION_INFO_SCSV is fatal if
1436 * renegotiating.
1437 */
1438 if (s->renegotiate) {
1439 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,
1440 SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING);
1441 ssl3_send_alert(s, SSL3_AL_FATAL,
1442 SSL_AD_HANDSHAKE_FAILURE);
1443
1444 goto err;
1445 }
1446 s->s3->send_connection_binding = 1;
1447 continue;
1448 }
1449
1450 if (cipher_id == SSL3_CK_FALLBACK_SCSV) {
1451 /*
1452 * TLS_FALLBACK_SCSV indicates that the client
1453 * previously tried a higher protocol version.
1454 * Fail if the current version is an unexpected
1455 * downgrade.
1456 */
1457 max_version = ssl_max_server_version(s);
1458 if (max_version == 0 || s->version < max_version) {
1459 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,
1460 SSL_R_INAPPROPRIATE_FALLBACK);
1461 if (s->s3 != NULL)
1462 ssl3_send_alert(s, SSL3_AL_FATAL,
1463 SSL_AD_INAPPROPRIATE_FALLBACK);
1464 goto err;
1465 }
1466 continue;
1467 }
1468
1469 if ((c = ssl3_get_cipher_by_value(cipher_value)) != NULL) {
1470 if (!sk_SSL_CIPHER_push(sk, c)) {
1471 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,
1472 ERR_R_MALLOC_FAILURE);
1473 goto err;
1474 }
1475 }
1476 }
1477
1478 return (sk);
1479
1480err:
1481 sk_SSL_CIPHER_free(sk);
1482
1483 return (NULL);
1484}
1485
1486
1487/*
1488 * Return a servername extension value if provided in Client Hello, or NULL.
1489 * So far, only host_name types are defined (RFC 3546).
1490 */
1491const char *
1492SSL_get_servername(const SSL *s, const int type)
1493{
1494 if (type != TLSEXT_NAMETYPE_host_name)
1495 return (NULL);
1496
1497 return (s->session && !s->tlsext_hostname ?
1498 s->session->tlsext_hostname :
1499 s->tlsext_hostname);
1500}
1501
1502int
1503SSL_get_servername_type(const SSL *s)
1504{
1505 if (s->session &&
1506 (!s->tlsext_hostname ?
1507 s->session->tlsext_hostname : s->tlsext_hostname))
1508 return (TLSEXT_NAMETYPE_host_name);
1509 return (-1);
1510}
1511
1512/*
1513 * SSL_select_next_proto implements the standard protocol selection. It is
1514 * expected that this function is called from the callback set by
1515 * SSL_CTX_set_next_proto_select_cb.
1516 *
1517 * The protocol data is assumed to be a vector of 8-bit, length prefixed byte
1518 * strings. The length byte itself is not included in the length. A byte
1519 * string of length 0 is invalid. No byte string may be truncated.
1520 *
1521 * The current, but experimental algorithm for selecting the protocol is:
1522 *
1523 * 1) If the server doesn't support NPN then this is indicated to the
1524 * callback. In this case, the client application has to abort the connection
1525 * or have a default application level protocol.
1526 *
1527 * 2) If the server supports NPN, but advertises an empty list then the
1528 * client selects the first protcol in its list, but indicates via the
1529 * API that this fallback case was enacted.
1530 *
1531 * 3) Otherwise, the client finds the first protocol in the server's list
1532 * that it supports and selects this protocol. This is because it's
1533 * assumed that the server has better information about which protocol
1534 * a client should use.
1535 *
1536 * 4) If the client doesn't support any of the server's advertised
1537 * protocols, then this is treated the same as case 2.
1538 *
1539 * It returns either
1540 * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
1541 * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
1542 */
1543int
1544SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
1545 const unsigned char *server, unsigned int server_len,
1546 const unsigned char *client, unsigned int client_len)
1547{
1548 unsigned int i, j;
1549 const unsigned char *result;
1550 int status = OPENSSL_NPN_UNSUPPORTED;
1551
1552 /*
1553 * For each protocol in server preference order,
1554 * see if we support it.
1555 */
1556 for (i = 0; i < server_len; ) {
1557 for (j = 0; j < client_len; ) {
1558 if (server[i] == client[j] &&
1559 memcmp(&server[i + 1],
1560 &client[j + 1], server[i]) == 0) {
1561 /* We found a match */
1562 result = &server[i];
1563 status = OPENSSL_NPN_NEGOTIATED;
1564 goto found;
1565 }
1566 j += client[j];
1567 j++;
1568 }
1569 i += server[i];
1570 i++;
1571 }
1572
1573 /* There's no overlap between our protocols and the server's list. */
1574 result = client;
1575 status = OPENSSL_NPN_NO_OVERLAP;
1576
1577found:
1578 *out = (unsigned char *) result + 1;
1579 *outlen = result[0];
1580 return (status);
1581}
1582
1583/*
1584 * SSL_get0_next_proto_negotiated sets *data and *len to point to the client's
1585 * requested protocol for this connection and returns 0. If the client didn't
1586 * request any protocol, then *data is set to NULL.
1587 *
1588 * Note that the client can request any protocol it chooses. The value returned
1589 * from this function need not be a member of the list of supported protocols
1590 * provided by the callback.
1591 */
1592void
1593SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
1594 unsigned *len)
1595{
1596 *data = s->next_proto_negotiated;
1597 if (!*data) {
1598 *len = 0;
1599 } else {
1600 *len = s->next_proto_negotiated_len;
1601 }
1602}
1603
1604/*
1605 * SSL_CTX_set_next_protos_advertised_cb sets a callback that is called when a
1606 * TLS server needs a list of supported protocols for Next Protocol
1607 * Negotiation. The returned list must be in wire format. The list is returned
1608 * by setting |out| to point to it and |outlen| to its length. This memory will
1609 * not be modified, but one should assume that the SSL* keeps a reference to
1610 * it.
1611 *
1612 * The callback should return SSL_TLSEXT_ERR_OK if it wishes to advertise.
1613 * Otherwise, no such extension will be included in the ServerHello.
1614 */
1615void
1616SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx, int (*cb) (SSL *ssl,
1617 const unsigned char **out, unsigned int *outlen, void *arg), void *arg)
1618{
1619 ctx->next_protos_advertised_cb = cb;
1620 ctx->next_protos_advertised_cb_arg = arg;
1621}
1622
1623/*
1624 * SSL_CTX_set_next_proto_select_cb sets a callback that is called when a
1625 * client needs to select a protocol from the server's provided list. |out|
1626 * must be set to point to the selected protocol (which may be within |in|).
1627 * The length of the protocol name must be written into |outlen|. The server's
1628 * advertised protocols are provided in |in| and |inlen|. The callback can
1629 * assume that |in| is syntactically valid.
1630 *
1631 * The client must select a protocol. It is fatal to the connection if this
1632 * callback returns a value other than SSL_TLSEXT_ERR_OK.
1633 */
1634void
1635SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s,
1636 unsigned char **out, unsigned char *outlen, const unsigned char *in,
1637 unsigned int inlen, void *arg), void *arg)
1638{
1639 ctx->next_proto_select_cb = cb;
1640 ctx->next_proto_select_cb_arg = arg;
1641}
1642
1643/*
1644 * SSL_CTX_set_alpn_protos sets the ALPN protocol list to the specified
1645 * protocols, which must be in wire-format (i.e. a series of non-empty,
1646 * 8-bit length-prefixed strings). Returns 0 on success.
1647 */
1648int
1649SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
1650 unsigned int protos_len)
1651{
1652 free(ctx->alpn_client_proto_list);
1653 if ((ctx->alpn_client_proto_list = malloc(protos_len)) == NULL)
1654 return (1);
1655 memcpy(ctx->alpn_client_proto_list, protos, protos_len);
1656 ctx->alpn_client_proto_list_len = protos_len;
1657
1658 return (0);
1659}
1660
1661/*
1662 * SSL_set_alpn_protos sets the ALPN protocol list to the specified
1663 * protocols, which must be in wire-format (i.e. a series of non-empty,
1664 * 8-bit length-prefixed strings). Returns 0 on success.
1665 */
1666int
1667SSL_set_alpn_protos(SSL *ssl, const unsigned char* protos,
1668 unsigned int protos_len)
1669{
1670 free(ssl->alpn_client_proto_list);
1671 if ((ssl->alpn_client_proto_list = malloc(protos_len)) == NULL)
1672 return (1);
1673 memcpy(ssl->alpn_client_proto_list, protos, protos_len);
1674 ssl->alpn_client_proto_list_len = protos_len;
1675
1676 return (0);
1677}
1678
1679/*
1680 * SSL_CTX_set_alpn_select_cb sets a callback function that is called during
1681 * ClientHello processing in order to select an ALPN protocol from the
1682 * client's list of offered protocols.
1683 */
1684void
1685SSL_CTX_set_alpn_select_cb(SSL_CTX* ctx,
1686 int (*cb) (SSL *ssl, const unsigned char **out, unsigned char *outlen,
1687 const unsigned char *in, unsigned int inlen, void *arg), void *arg)
1688{
1689 ctx->alpn_select_cb = cb;
1690 ctx->alpn_select_cb_arg = arg;
1691}
1692
1693/*
1694 * SSL_get0_alpn_selected gets the selected ALPN protocol (if any). On return
1695 * it sets data to point to len bytes of protocol name (not including the
1696 * leading length-prefix byte). If the server didn't respond with* a negotiated
1697 * protocol then len will be zero.
1698 */
1699void
1700SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
1701 unsigned *len)
1702{
1703 *data = NULL;
1704 *len = 0;
1705
1706 if (ssl->s3 != NULL) {
1707 *data = ssl->s3->alpn_selected;
1708 *len = ssl->s3->alpn_selected_len;
1709 }
1710}
1711
1712int
1713SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
1714 const char *label, size_t llen, const unsigned char *p, size_t plen,
1715 int use_context)
1716{
1717 return (s->method->ssl3_enc->export_keying_material(s, out, olen,
1718 label, llen, p, plen, use_context));
1719}
1720
1721static unsigned long
1722ssl_session_hash(const SSL_SESSION *a)
1723{
1724 unsigned long l;
1725
1726 l = (unsigned long)
1727 ((unsigned int) a->session_id[0] )|
1728 ((unsigned int) a->session_id[1]<< 8L)|
1729 ((unsigned long)a->session_id[2]<<16L)|
1730 ((unsigned long)a->session_id[3]<<24L);
1731 return (l);
1732}
1733
1734/*
1735 * NB: If this function (or indeed the hash function which uses a sort of
1736 * coarser function than this one) is changed, ensure
1737 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
1738 * able to construct an SSL_SESSION that will collide with any existing session
1739 * with a matching session ID.
1740 */
1741static int
1742ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
1743{
1744 if (a->ssl_version != b->ssl_version)
1745 return (1);
1746 if (a->session_id_length != b->session_id_length)
1747 return (1);
1748 if (timingsafe_memcmp(a->session_id, b->session_id, a->session_id_length) != 0)
1749 return (1);
1750 return (0);
1751}
1752
1753/*
1754 * These wrapper functions should remain rather than redeclaring
1755 * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
1756 * variable. The reason is that the functions aren't static, they're exposed via
1757 * ssl.h.
1758 */
1759static
1760IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION)
1761static
1762IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION)
1763
1764SSL_CTX *
1765SSL_CTX_new(const SSL_METHOD *meth)
1766{
1767 SSL_CTX *ret = NULL;
1768
1769 if (meth == NULL) {
1770 SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_NULL_SSL_METHOD_PASSED);
1771 return (NULL);
1772 }
1773
1774 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {
1775 SSLerr(SSL_F_SSL_CTX_NEW,
1776 SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1777 goto err;
1778 }
1779 ret = calloc(1, sizeof(SSL_CTX));
1780 if (ret == NULL)
1781 goto err;
1782
1783 ret->method = meth;
1784
1785 ret->cert_store = NULL;
1786 ret->session_cache_mode = SSL_SESS_CACHE_SERVER;
1787 ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1788 ret->session_cache_head = NULL;
1789 ret->session_cache_tail = NULL;
1790
1791 /* We take the system default */
1792 ret->session_timeout = meth->get_timeout();
1793
1794 ret->new_session_cb = 0;
1795 ret->remove_session_cb = 0;
1796 ret->get_session_cb = 0;
1797 ret->generate_session_id = 0;
1798
1799 memset((char *)&ret->stats, 0, sizeof(ret->stats));
1800
1801 ret->references = 1;
1802 ret->quiet_shutdown = 0;
1803
1804 ret->info_callback = NULL;
1805
1806 ret->app_verify_callback = 0;
1807 ret->app_verify_arg = NULL;
1808
1809 ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;
1810 ret->read_ahead = 0;
1811 ret->msg_callback = 0;
1812 ret->msg_callback_arg = NULL;
1813 ret->verify_mode = SSL_VERIFY_NONE;
1814 ret->sid_ctx_length = 0;
1815 ret->default_verify_callback = NULL;
1816 if ((ret->cert = ssl_cert_new()) == NULL)
1817 goto err;
1818
1819 ret->default_passwd_callback = 0;
1820 ret->default_passwd_callback_userdata = NULL;
1821 ret->client_cert_cb = 0;
1822 ret->app_gen_cookie_cb = 0;
1823 ret->app_verify_cookie_cb = 0;
1824
1825 ret->sessions = lh_SSL_SESSION_new();
1826 if (ret->sessions == NULL)
1827 goto err;
1828 ret->cert_store = X509_STORE_new();
1829 if (ret->cert_store == NULL)
1830 goto err;
1831
1832 ssl_create_cipher_list(ret->method, &ret->cipher_list,
1833 &ret->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST);
1834 if (ret->cipher_list == NULL ||
1835 sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
1836 SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);
1837 goto err2;
1838 }
1839
1840 ret->param = X509_VERIFY_PARAM_new();
1841 if (!ret->param)
1842 goto err;
1843
1844 if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) {
1845 SSLerr(SSL_F_SSL_CTX_NEW,
1846 SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1847 goto err2;
1848 }
1849 if ((ret->sha1 = EVP_get_digestbyname("ssl3-sha1")) == NULL) {
1850 SSLerr(SSL_F_SSL_CTX_NEW,
1851 SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1852 goto err2;
1853 }
1854
1855 if ((ret->client_CA = sk_X509_NAME_new_null()) == NULL)
1856 goto err;
1857
1858 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);
1859
1860 ret->extra_certs = NULL;
1861
1862 ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
1863
1864 ret->tlsext_servername_callback = 0;
1865 ret->tlsext_servername_arg = NULL;
1866
1867 /* Setup RFC4507 ticket keys */
1868 arc4random_buf(ret->tlsext_tick_key_name, 16);
1869 arc4random_buf(ret->tlsext_tick_hmac_key, 16);
1870 arc4random_buf(ret->tlsext_tick_aes_key, 16);
1871
1872 ret->tlsext_status_cb = 0;
1873 ret->tlsext_status_arg = NULL;
1874
1875 ret->next_protos_advertised_cb = 0;
1876 ret->next_proto_select_cb = 0;
1877#ifndef OPENSSL_NO_ENGINE
1878 ret->client_cert_engine = NULL;
1879#ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO
1880#define eng_strx(x) #x
1881#define eng_str(x) eng_strx(x)
1882 /* Use specific client engine automatically... ignore errors */
1883 {
1884 ENGINE *eng;
1885 eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));
1886 if (!eng) {
1887 ERR_clear_error();
1888 ENGINE_load_builtin_engines();
1889 eng = ENGINE_by_id(eng_str(
1890 OPENSSL_SSL_CLIENT_ENGINE_AUTO));
1891 }
1892 if (!eng || !SSL_CTX_set_client_cert_engine(ret, eng))
1893 ERR_clear_error();
1894 }
1895#endif
1896#endif
1897 /*
1898 * Default is to connect to non-RI servers. When RI is more widely
1899 * deployed might change this.
1900 */
1901 ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;
1902
1903 return (ret);
1904err:
1905 SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);
1906err2:
1907 SSL_CTX_free(ret);
1908 return (NULL);
1909}
1910
1911void
1912SSL_CTX_free(SSL_CTX *a)
1913{
1914 int i;
1915
1916 if (a == NULL)
1917 return;
1918
1919 i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX);
1920 if (i > 0)
1921 return;
1922
1923 if (a->param)
1924 X509_VERIFY_PARAM_free(a->param);
1925
1926 /*
1927 * Free internal session cache. However: the remove_cb() may reference
1928 * the ex_data of SSL_CTX, thus the ex_data store can only be removed
1929 * after the sessions were flushed.
1930 * As the ex_data handling routines might also touch the session cache,
1931 * the most secure solution seems to be: empty (flush) the cache, then
1932 * free ex_data, then finally free the cache.
1933 * (See ticket [openssl.org #212].)
1934 */
1935 if (a->sessions != NULL)
1936 SSL_CTX_flush_sessions(a, 0);
1937
1938 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);
1939
1940 if (a->sessions != NULL)
1941 lh_SSL_SESSION_free(a->sessions);
1942
1943 if (a->cert_store != NULL)
1944 X509_STORE_free(a->cert_store);
1945 if (a->cipher_list != NULL)
1946 sk_SSL_CIPHER_free(a->cipher_list);
1947 if (a->cipher_list_by_id != NULL)
1948 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1949 if (a->cert != NULL)
1950 ssl_cert_free(a->cert);
1951 if (a->client_CA != NULL)
1952 sk_X509_NAME_pop_free(a->client_CA, X509_NAME_free);
1953 if (a->extra_certs != NULL)
1954 sk_X509_pop_free(a->extra_certs, X509_free);
1955
1956#ifndef OPENSSL_NO_SRTP
1957 if (a->srtp_profiles)
1958 sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);
1959#endif
1960
1961#ifndef OPENSSL_NO_ENGINE
1962 if (a->client_cert_engine)
1963 ENGINE_finish(a->client_cert_engine);
1964#endif
1965
1966 free(a->alpn_client_proto_list);
1967
1968 free(a);
1969}
1970
1971void
1972SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1973{
1974 ctx->default_passwd_callback = cb;
1975}
1976
1977void
1978SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u)
1979{
1980 ctx->default_passwd_callback_userdata = u;
1981}
1982
1983void
1984SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *,
1985 void *), void *arg)
1986{
1987 ctx->app_verify_callback = cb;
1988 ctx->app_verify_arg = arg;
1989}
1990
1991void
1992SSL_CTX_set_verify(SSL_CTX *ctx, int mode, int (*cb)(int, X509_STORE_CTX *))
1993{
1994 ctx->verify_mode = mode;
1995 ctx->default_verify_callback = cb;
1996}
1997
1998void
1999SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth)
2000{
2001 X509_VERIFY_PARAM_set_depth(ctx->param, depth);
2002}
2003
2004void
2005ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
2006{
2007 CERT_PKEY *cpk;
2008 int rsa_enc, rsa_sign, dh_tmp, dsa_sign;
2009 unsigned long mask_k, mask_a;
2010 int have_ecc_cert, ecdh_ok, ecdsa_ok;
2011 int have_ecdh_tmp;
2012 X509 *x = NULL;
2013 EVP_PKEY *ecc_pkey = NULL;
2014 int signature_nid = 0, pk_nid = 0, md_nid = 0;
2015
2016 if (c == NULL)
2017 return;
2018
2019 dh_tmp = (c->dh_tmp != NULL || c->dh_tmp_cb != NULL ||
2020 c->dh_tmp_auto != 0);
2021
2022 have_ecdh_tmp = (c->ecdh_tmp != NULL || c->ecdh_tmp_cb != NULL ||
2023 c->ecdh_tmp_auto != 0);
2024 cpk = &(c->pkeys[SSL_PKEY_RSA_ENC]);
2025 rsa_enc = (cpk->x509 != NULL && cpk->privatekey != NULL);
2026 cpk = &(c->pkeys[SSL_PKEY_RSA_SIGN]);
2027 rsa_sign = (cpk->x509 != NULL && cpk->privatekey != NULL);
2028 cpk = &(c->pkeys[SSL_PKEY_DSA_SIGN]);
2029 dsa_sign = (cpk->x509 != NULL && cpk->privatekey != NULL);
2030/* FIX THIS EAY EAY EAY */
2031 cpk = &(c->pkeys[SSL_PKEY_ECC]);
2032 have_ecc_cert = (cpk->x509 != NULL && cpk->privatekey != NULL);
2033 mask_k = 0;
2034 mask_a = 0;
2035
2036 cpk = &(c->pkeys[SSL_PKEY_GOST01]);
2037 if (cpk->x509 != NULL && cpk->privatekey !=NULL) {
2038 mask_k |= SSL_kGOST;
2039 mask_a |= SSL_aGOST01;
2040 }
2041
2042 if (rsa_enc)
2043 mask_k|=SSL_kRSA;
2044
2045 if (dh_tmp)
2046 mask_k|=SSL_kDHE;
2047
2048 if (rsa_enc || rsa_sign)
2049 mask_a|=SSL_aRSA;
2050
2051 if (dsa_sign)
2052 mask_a|=SSL_aDSS;
2053
2054 mask_a|=SSL_aNULL;
2055
2056 /*
2057 * An ECC certificate may be usable for ECDH and/or
2058 * ECDSA cipher suites depending on the key usage extension.
2059 */
2060 if (have_ecc_cert) {
2061 /* This call populates extension flags (ex_flags) */
2062 x = (c->pkeys[SSL_PKEY_ECC]).x509;
2063 X509_check_purpose(x, -1, 0);
2064 ecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ?
2065 (x->ex_kusage & X509v3_KU_KEY_AGREEMENT) : 1;
2066 ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ?
2067 (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1;
2068 ecc_pkey = X509_get_pubkey(x);
2069 EVP_PKEY_free(ecc_pkey);
2070 if ((x->sig_alg) && (x->sig_alg->algorithm)) {
2071 signature_nid = OBJ_obj2nid(x->sig_alg->algorithm);
2072 OBJ_find_sigid_algs(signature_nid, &md_nid, &pk_nid);
2073 }
2074 if (ecdh_ok) {
2075 if (pk_nid == NID_rsaEncryption || pk_nid == NID_rsa) {
2076 mask_k|=SSL_kECDHr;
2077 mask_a|=SSL_aECDH;
2078 }
2079 if (pk_nid == NID_X9_62_id_ecPublicKey) {
2080 mask_k|=SSL_kECDHe;
2081 mask_a|=SSL_aECDH;
2082 }
2083 }
2084 if (ecdsa_ok)
2085 mask_a|=SSL_aECDSA;
2086 }
2087
2088 if (have_ecdh_tmp) {
2089 mask_k|=SSL_kECDHE;
2090 }
2091
2092
2093 c->mask_k = mask_k;
2094 c->mask_a = mask_a;
2095 c->valid = 1;
2096}
2097
2098/* This handy macro borrowed from crypto/x509v3/v3_purp.c */
2099#define ku_reject(x, usage) \
2100 (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage)))
2101
2102
2103int
2104ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s)
2105{
2106 unsigned long alg_k, alg_a;
2107 int signature_nid = 0, md_nid = 0, pk_nid = 0;
2108 const SSL_CIPHER *cs = s->s3->tmp.new_cipher;
2109
2110 alg_k = cs->algorithm_mkey;
2111 alg_a = cs->algorithm_auth;
2112
2113 /* This call populates the ex_flags field correctly */
2114 X509_check_purpose(x, -1, 0);
2115 if ((x->sig_alg) && (x->sig_alg->algorithm)) {
2116 signature_nid = OBJ_obj2nid(x->sig_alg->algorithm);
2117 OBJ_find_sigid_algs(signature_nid, &md_nid, &pk_nid);
2118 }
2119 if (alg_k & SSL_kECDHe || alg_k & SSL_kECDHr) {
2120 /* key usage, if present, must allow key agreement */
2121 if (ku_reject(x, X509v3_KU_KEY_AGREEMENT)) {
2122 SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG,
2123 SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT);
2124 return (0);
2125 }
2126 if ((alg_k & SSL_kECDHe) && TLS1_get_version(s) <
2127 TLS1_2_VERSION) {
2128 /* signature alg must be ECDSA */
2129 if (pk_nid != NID_X9_62_id_ecPublicKey) {
2130 SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG,
2131 SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE);
2132 return (0);
2133 }
2134 }
2135 if ((alg_k & SSL_kECDHr) && TLS1_get_version(s) <
2136 TLS1_2_VERSION) {
2137 /* signature alg must be RSA */
2138 if (pk_nid != NID_rsaEncryption && pk_nid != NID_rsa) {
2139 SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG,
2140 SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE);
2141 return (0);
2142 }
2143 }
2144 }
2145 if (alg_a & SSL_aECDSA) {
2146 /* key usage, if present, must allow signing */
2147 if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE)) {
2148 SSLerr(SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG,
2149 SSL_R_ECC_CERT_NOT_FOR_SIGNING);
2150 return (0);
2151 }
2152 }
2153
2154 return (1);
2155 /* all checks are ok */
2156}
2157
2158
2159/* THIS NEEDS CLEANING UP */
2160CERT_PKEY *
2161ssl_get_server_send_pkey(const SSL *s)
2162{
2163 unsigned long alg_k, alg_a;
2164 CERT *c;
2165 int i;
2166
2167 c = s->cert;
2168 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
2169
2170 alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
2171 alg_a = s->s3->tmp.new_cipher->algorithm_auth;
2172
2173 if (alg_k & (SSL_kECDHr|SSL_kECDHe)) {
2174 /*
2175 * We don't need to look at SSL_kECDHE
2176 * since no certificate is needed for
2177 * anon ECDH and for authenticated
2178 * ECDHE, the check for the auth
2179 * algorithm will set i correctly
2180 * NOTE: For ECDH-RSA, we need an ECC
2181 * not an RSA cert but for EECDH-RSA
2182 * we need an RSA cert. Placing the
2183 * checks for SSL_kECDH before RSA
2184 * checks ensures the correct cert is chosen.
2185 */
2186 i = SSL_PKEY_ECC;
2187 } else if (alg_a & SSL_aECDSA) {
2188 i = SSL_PKEY_ECC;
2189 } else if (alg_a & SSL_aDSS) {
2190 i = SSL_PKEY_DSA_SIGN;
2191 } else if (alg_a & SSL_aRSA) {
2192 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
2193 i = SSL_PKEY_RSA_SIGN;
2194 else
2195 i = SSL_PKEY_RSA_ENC;
2196 } else if (alg_a & SSL_aGOST01) {
2197 i = SSL_PKEY_GOST01;
2198 } else { /* if (alg_a & SSL_aNULL) */
2199 SSLerr(SSL_F_SSL_GET_SERVER_SEND_PKEY, ERR_R_INTERNAL_ERROR);
2200 return (NULL);
2201 }
2202
2203 return (c->pkeys + i);
2204}
2205
2206X509 *
2207ssl_get_server_send_cert(const SSL *s)
2208{
2209 CERT_PKEY *cpk;
2210
2211 cpk = ssl_get_server_send_pkey(s);
2212 if (!cpk)
2213 return (NULL);
2214 return (cpk->x509);
2215}
2216
2217EVP_PKEY *
2218ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *cipher, const EVP_MD **pmd)
2219{
2220 unsigned long alg_a;
2221 CERT *c;
2222 int idx = -1;
2223
2224 alg_a = cipher->algorithm_auth;
2225 c = s->cert;
2226
2227 if ((alg_a & SSL_aDSS) &&
2228 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
2229 idx = SSL_PKEY_DSA_SIGN;
2230 else if (alg_a & SSL_aRSA) {
2231 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
2232 idx = SSL_PKEY_RSA_SIGN;
2233 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
2234 idx = SSL_PKEY_RSA_ENC;
2235 } else if ((alg_a & SSL_aECDSA) &&
2236 (c->pkeys[SSL_PKEY_ECC].privatekey != NULL))
2237 idx = SSL_PKEY_ECC;
2238 if (idx == -1) {
2239 SSLerr(SSL_F_SSL_GET_SIGN_PKEY, ERR_R_INTERNAL_ERROR);
2240 return (NULL);
2241 }
2242 if (pmd)
2243 *pmd = c->pkeys[idx].digest;
2244 return (c->pkeys[idx].privatekey);
2245}
2246
2247DH *
2248ssl_get_auto_dh(SSL *s)
2249{
2250 CERT_PKEY *cpk;
2251 int keylen;
2252 DH *dhp;
2253
2254 if (s->cert->dh_tmp_auto == 2) {
2255 keylen = 1024;
2256 } else if (s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) {
2257 keylen = 1024;
2258 if (s->s3->tmp.new_cipher->strength_bits == 256)
2259 keylen = 3072;
2260 } else {
2261 if ((cpk = ssl_get_server_send_pkey(s)) == NULL)
2262 return (NULL);
2263 if (cpk->privatekey == NULL || cpk->privatekey->pkey.dh == NULL)
2264 return (NULL);
2265 keylen = EVP_PKEY_bits(cpk->privatekey);
2266 }
2267
2268 if ((dhp = DH_new()) == NULL)
2269 return (NULL);
2270
2271 dhp->g = BN_new();
2272 if (dhp->g != NULL)
2273 BN_set_word(dhp->g, 2);
2274
2275 if (keylen >= 8192)
2276 dhp->p = get_rfc3526_prime_8192(NULL);
2277 else if (keylen >= 4096)
2278 dhp->p = get_rfc3526_prime_4096(NULL);
2279 else if (keylen >= 3072)
2280 dhp->p = get_rfc3526_prime_3072(NULL);
2281 else if (keylen >= 2048)
2282 dhp->p = get_rfc3526_prime_2048(NULL);
2283 else if (keylen >= 1536)
2284 dhp->p = get_rfc3526_prime_1536(NULL);
2285 else
2286 dhp->p = get_rfc2409_prime_1024(NULL);
2287
2288 if (dhp->p == NULL || dhp->g == NULL) {
2289 DH_free(dhp);
2290 return (NULL);
2291 }
2292 return (dhp);
2293}
2294
2295void
2296ssl_update_cache(SSL *s, int mode)
2297{
2298 int i;
2299
2300 /*
2301 * If the session_id_length is 0, we are not supposed to cache it,
2302 * and it would be rather hard to do anyway :-)
2303 */
2304 if (s->session->session_id_length == 0)
2305 return;
2306
2307 i = s->session_ctx->session_cache_mode;
2308 if ((i & mode) && (!s->hit) && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE)
2309 || SSL_CTX_add_session(s->session_ctx, s->session))
2310 && (s->session_ctx->new_session_cb != NULL)) {
2311 CRYPTO_add(&s->session->references, 1, CRYPTO_LOCK_SSL_SESSION);
2312 if (!s->session_ctx->new_session_cb(s, s->session))
2313 SSL_SESSION_free(s->session);
2314 }
2315
2316 /* auto flush every 255 connections */
2317 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
2318 ((i & mode) == mode)) {
2319 if ((((mode & SSL_SESS_CACHE_CLIENT) ?
2320 s->session_ctx->stats.sess_connect_good :
2321 s->session_ctx->stats.sess_accept_good) & 0xff) == 0xff) {
2322 SSL_CTX_flush_sessions(s->session_ctx, time(NULL));
2323 }
2324 }
2325}
2326
2327const SSL_METHOD *
2328SSL_get_ssl_method(SSL *s)
2329{
2330 return (s->method);
2331}
2332
2333int
2334SSL_set_ssl_method(SSL *s, const SSL_METHOD *meth)
2335{
2336 int conn = -1;
2337 int ret = 1;
2338
2339 if (s->method != meth) {
2340 if (s->handshake_func != NULL)
2341 conn = (s->handshake_func == s->method->ssl_connect);
2342
2343 if (s->method->version == meth->version)
2344 s->method = meth;
2345 else {
2346 s->method->ssl_free(s);
2347 s->method = meth;
2348 ret = s->method->ssl_new(s);
2349 }
2350
2351 if (conn == 1)
2352 s->handshake_func = meth->ssl_connect;
2353 else if (conn == 0)
2354 s->handshake_func = meth->ssl_accept;
2355 }
2356 return (ret);
2357}
2358
2359int
2360SSL_get_error(const SSL *s, int i)
2361{
2362 int reason;
2363 unsigned long l;
2364 BIO *bio;
2365
2366 if (i > 0)
2367 return (SSL_ERROR_NONE);
2368
2369 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
2370 * etc, where we do encode the error */
2371 if ((l = ERR_peek_error()) != 0) {
2372 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
2373 return (SSL_ERROR_SYSCALL);
2374 else
2375 return (SSL_ERROR_SSL);
2376 }
2377
2378 if ((i < 0) && SSL_want_read(s)) {
2379 bio = SSL_get_rbio(s);
2380 if (BIO_should_read(bio)) {
2381 return (SSL_ERROR_WANT_READ);
2382 } else if (BIO_should_write(bio)) {
2383 /*
2384 * This one doesn't make too much sense... We never
2385 * try to write to the rbio, and an application
2386 * program where rbio and wbio are separate couldn't
2387 * even know what it should wait for. However if we
2388 * ever set s->rwstate incorrectly (so that we have
2389 * SSL_want_read(s) instead of SSL_want_write(s))
2390 * and rbio and wbio *are* the same, this test works
2391 * around that bug; so it might be safer to keep it.
2392 */
2393 return (SSL_ERROR_WANT_WRITE);
2394 } else if (BIO_should_io_special(bio)) {
2395 reason = BIO_get_retry_reason(bio);
2396 if (reason == BIO_RR_CONNECT)
2397 return (SSL_ERROR_WANT_CONNECT);
2398 else if (reason == BIO_RR_ACCEPT)
2399 return (SSL_ERROR_WANT_ACCEPT);
2400 else
2401 return (SSL_ERROR_SYSCALL); /* unknown */
2402 }
2403 }
2404
2405 if ((i < 0) && SSL_want_write(s)) {
2406 bio = SSL_get_wbio(s);
2407 if (BIO_should_write(bio)) {
2408 return (SSL_ERROR_WANT_WRITE);
2409 } else if (BIO_should_read(bio)) {
2410 /*
2411 * See above (SSL_want_read(s) with
2412 * BIO_should_write(bio))
2413 */
2414 return (SSL_ERROR_WANT_READ);
2415 } else if (BIO_should_io_special(bio)) {
2416 reason = BIO_get_retry_reason(bio);
2417 if (reason == BIO_RR_CONNECT)
2418 return (SSL_ERROR_WANT_CONNECT);
2419 else if (reason == BIO_RR_ACCEPT)
2420 return (SSL_ERROR_WANT_ACCEPT);
2421 else
2422 return (SSL_ERROR_SYSCALL);
2423 }
2424 }
2425 if ((i < 0) && SSL_want_x509_lookup(s)) {
2426 return (SSL_ERROR_WANT_X509_LOOKUP);
2427 }
2428
2429 if (i == 0) {
2430 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
2431 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
2432 return (SSL_ERROR_ZERO_RETURN);
2433 }
2434 return (SSL_ERROR_SYSCALL);
2435}
2436
2437int
2438SSL_do_handshake(SSL *s)
2439{
2440 int ret = 1;
2441
2442 if (s->handshake_func == NULL) {
2443 SSLerr(SSL_F_SSL_DO_HANDSHAKE, SSL_R_CONNECTION_TYPE_NOT_SET);
2444 return (-1);
2445 }
2446
2447 s->method->ssl_renegotiate_check(s);
2448
2449 if (SSL_in_init(s) || SSL_in_before(s)) {
2450 ret = s->handshake_func(s);
2451 }
2452 return (ret);
2453}
2454
2455/*
2456 * For the next 2 functions, SSL_clear() sets shutdown and so
2457 * one of these calls will reset it
2458 */
2459void
2460SSL_set_accept_state(SSL *s)
2461{
2462 s->server = 1;
2463 s->shutdown = 0;
2464 s->state = SSL_ST_ACCEPT|SSL_ST_BEFORE;
2465 s->handshake_func = s->method->ssl_accept;
2466 /* clear the current cipher */
2467 ssl_clear_cipher_ctx(s);
2468 ssl_clear_hash_ctx(&s->read_hash);
2469 ssl_clear_hash_ctx(&s->write_hash);
2470}
2471
2472void
2473SSL_set_connect_state(SSL *s)
2474{
2475 s->server = 0;
2476 s->shutdown = 0;
2477 s->state = SSL_ST_CONNECT|SSL_ST_BEFORE;
2478 s->handshake_func = s->method->ssl_connect;
2479 /* clear the current cipher */
2480 ssl_clear_cipher_ctx(s);
2481 ssl_clear_hash_ctx(&s->read_hash);
2482 ssl_clear_hash_ctx(&s->write_hash);
2483}
2484
2485int
2486ssl_undefined_function(SSL *s)
2487{
2488 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,
2489 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2490 return (0);
2491}
2492
2493int
2494ssl_undefined_void_function(void)
2495{
2496 SSLerr(SSL_F_SSL_UNDEFINED_VOID_FUNCTION,
2497 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2498 return (0);
2499}
2500
2501int
2502ssl_undefined_const_function(const SSL *s)
2503{
2504 SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION,
2505 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2506 return (0);
2507}
2508
2509const char *
2510ssl_version_string(int ver)
2511{
2512 switch (ver) {
2513 case DTLS1_VERSION:
2514 return (SSL_TXT_DTLS1);
2515 case TLS1_VERSION:
2516 return (SSL_TXT_TLSV1);
2517 case TLS1_1_VERSION:
2518 return (SSL_TXT_TLSV1_1);
2519 case TLS1_2_VERSION:
2520 return (SSL_TXT_TLSV1_2);
2521 default:
2522 return ("unknown");
2523 }
2524}
2525
2526const char *
2527SSL_get_version(const SSL *s)
2528{
2529 return ssl_version_string(s->version);
2530}
2531
2532uint16_t
2533ssl_max_server_version(SSL *s)
2534{
2535 uint16_t max_version;
2536
2537 /*
2538 * The SSL method will be changed during version negotiation, as such
2539 * we want to use the SSL method from the context.
2540 */
2541 max_version = s->ctx->method->version;
2542
2543 if (SSL_IS_DTLS(s))
2544 return (DTLS1_VERSION);
2545
2546 if ((s->options & SSL_OP_NO_TLSv1_2) == 0 &&
2547 max_version >= TLS1_2_VERSION)
2548 return (TLS1_2_VERSION);
2549 if ((s->options & SSL_OP_NO_TLSv1_1) == 0 &&
2550 max_version >= TLS1_1_VERSION)
2551 return (TLS1_1_VERSION);
2552 if ((s->options & SSL_OP_NO_TLSv1) == 0 &&
2553 max_version >= TLS1_VERSION)
2554 return (TLS1_VERSION);
2555
2556 return (0);
2557}
2558
2559SSL *
2560SSL_dup(SSL *s)
2561{
2562 STACK_OF(X509_NAME) *sk;
2563 X509_NAME *xn;
2564 SSL *ret;
2565 int i;
2566
2567 if ((ret = SSL_new(SSL_get_SSL_CTX(s))) == NULL)
2568 return (NULL);
2569
2570 ret->version = s->version;
2571 ret->type = s->type;
2572 ret->method = s->method;
2573
2574 if (s->session != NULL) {
2575 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
2576 SSL_copy_session_id(ret, s);
2577 } else {
2578 /*
2579 * No session has been established yet, so we have to expect
2580 * that s->cert or ret->cert will be changed later --
2581 * they should not both point to the same object,
2582 * and thus we can't use SSL_copy_session_id.
2583 */
2584
2585 ret->method->ssl_free(ret);
2586 ret->method = s->method;
2587 ret->method->ssl_new(ret);
2588
2589 if (s->cert != NULL) {
2590 if (ret->cert != NULL) {
2591 ssl_cert_free(ret->cert);
2592 }
2593 ret->cert = ssl_cert_dup(s->cert);
2594 if (ret->cert == NULL)
2595 goto err;
2596 }
2597
2598 SSL_set_session_id_context(ret,
2599 s->sid_ctx, s->sid_ctx_length);
2600 }
2601
2602 ret->options = s->options;
2603 ret->mode = s->mode;
2604 SSL_set_max_cert_list(ret, SSL_get_max_cert_list(s));
2605 SSL_set_read_ahead(ret, SSL_get_read_ahead(s));
2606 ret->msg_callback = s->msg_callback;
2607 ret->msg_callback_arg = s->msg_callback_arg;
2608 SSL_set_verify(ret, SSL_get_verify_mode(s),
2609 SSL_get_verify_callback(s));
2610 SSL_set_verify_depth(ret, SSL_get_verify_depth(s));
2611 ret->generate_session_id = s->generate_session_id;
2612
2613 SSL_set_info_callback(ret, SSL_get_info_callback(s));
2614
2615 ret->debug = s->debug;
2616
2617 /* copy app data, a little dangerous perhaps */
2618 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL,
2619 &ret->ex_data, &s->ex_data))
2620 goto err;
2621
2622 /* setup rbio, and wbio */
2623 if (s->rbio != NULL) {
2624 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
2625 goto err;
2626 }
2627 if (s->wbio != NULL) {
2628 if (s->wbio != s->rbio) {
2629 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
2630 goto err;
2631 } else
2632 ret->wbio = ret->rbio;
2633 }
2634 ret->rwstate = s->rwstate;
2635 ret->in_handshake = s->in_handshake;
2636 ret->handshake_func = s->handshake_func;
2637 ret->server = s->server;
2638 ret->renegotiate = s->renegotiate;
2639 ret->new_session = s->new_session;
2640 ret->quiet_shutdown = s->quiet_shutdown;
2641 ret->shutdown = s->shutdown;
2642 /* SSL_dup does not really work at any state, though */
2643 ret->state=s->state;
2644 ret->rstate = s->rstate;
2645
2646 /*
2647 * Would have to copy ret->init_buf, ret->init_msg, ret->init_num,
2648 * ret->init_off
2649 */
2650 ret->init_num = 0;
2651
2652 ret->hit = s->hit;
2653
2654 X509_VERIFY_PARAM_inherit(ret->param, s->param);
2655
2656 /* dup the cipher_list and cipher_list_by_id stacks */
2657 if (s->cipher_list != NULL) {
2658 if ((ret->cipher_list =
2659 sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
2660 goto err;
2661 }
2662 if (s->cipher_list_by_id != NULL) {
2663 if ((ret->cipher_list_by_id =
2664 sk_SSL_CIPHER_dup(s->cipher_list_by_id)) == NULL)
2665 goto err;
2666 }
2667
2668 /* Dup the client_CA list */
2669 if (s->client_CA != NULL) {
2670 if ((sk = sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
2671 ret->client_CA = sk;
2672 for (i = 0; i < sk_X509_NAME_num(sk); i++) {
2673 xn = sk_X509_NAME_value(sk, i);
2674 if (sk_X509_NAME_set(sk, i,
2675 X509_NAME_dup(xn)) == NULL) {
2676 X509_NAME_free(xn);
2677 goto err;
2678 }
2679 }
2680 }
2681
2682 if (0) {
2683err:
2684 if (ret != NULL)
2685 SSL_free(ret);
2686 ret = NULL;
2687 }
2688 return (ret);
2689}
2690
2691void
2692ssl_clear_cipher_ctx(SSL *s)
2693{
2694 EVP_CIPHER_CTX_free(s->enc_read_ctx);
2695 s->enc_read_ctx = NULL;
2696 EVP_CIPHER_CTX_free(s->enc_write_ctx);
2697 s->enc_write_ctx = NULL;
2698
2699 if (s->aead_read_ctx != NULL) {
2700 EVP_AEAD_CTX_cleanup(&s->aead_read_ctx->ctx);
2701 free(s->aead_read_ctx);
2702 s->aead_read_ctx = NULL;
2703 }
2704 if (s->aead_write_ctx != NULL) {
2705 EVP_AEAD_CTX_cleanup(&s->aead_write_ctx->ctx);
2706 free(s->aead_write_ctx);
2707 s->aead_write_ctx = NULL;
2708 }
2709
2710}
2711
2712/* Fix this function so that it takes an optional type parameter */
2713X509 *
2714SSL_get_certificate(const SSL *s)
2715{
2716 if (s->cert != NULL)
2717 return (s->cert->key->x509);
2718 else
2719 return (NULL);
2720}
2721
2722/* Fix this function so that it takes an optional type parameter */
2723EVP_PKEY *
2724SSL_get_privatekey(SSL *s)
2725{
2726 if (s->cert != NULL)
2727 return (s->cert->key->privatekey);
2728 else
2729 return (NULL);
2730}
2731
2732const SSL_CIPHER *
2733SSL_get_current_cipher(const SSL *s)
2734{
2735 if ((s->session != NULL) && (s->session->cipher != NULL))
2736 return (s->session->cipher);
2737 return (NULL);
2738}
2739const void *
2740SSL_get_current_compression(SSL *s)
2741{
2742 return (NULL);
2743}
2744
2745const void *
2746SSL_get_current_expansion(SSL *s)
2747{
2748 return (NULL);
2749}
2750
2751int
2752ssl_init_wbio_buffer(SSL *s, int push)
2753{
2754 BIO *bbio;
2755
2756 if (s->bbio == NULL) {
2757 bbio = BIO_new(BIO_f_buffer());
2758 if (bbio == NULL)
2759 return (0);
2760 s->bbio = bbio;
2761 } else {
2762 bbio = s->bbio;
2763 if (s->bbio == s->wbio)
2764 s->wbio = BIO_pop(s->wbio);
2765 }
2766 (void)BIO_reset(bbio);
2767/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
2768 if (!BIO_set_read_buffer_size(bbio, 1)) {
2769 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER, ERR_R_BUF_LIB);
2770 return (0);
2771 }
2772 if (push) {
2773 if (s->wbio != bbio)
2774 s->wbio = BIO_push(bbio, s->wbio);
2775 } else {
2776 if (s->wbio == bbio)
2777 s->wbio = BIO_pop(bbio);
2778 }
2779 return (1);
2780}
2781
2782void
2783ssl_free_wbio_buffer(SSL *s)
2784{
2785 if (s == NULL)
2786 return;
2787
2788 if (s->bbio == NULL)
2789 return;
2790
2791 if (s->bbio == s->wbio) {
2792 /* remove buffering */
2793 s->wbio = BIO_pop(s->wbio);
2794 }
2795 BIO_free(s->bbio);
2796 s->bbio = NULL;
2797}
2798
2799void
2800SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode)
2801{
2802 ctx->quiet_shutdown = mode;
2803}
2804
2805int
2806SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx)
2807{
2808 return (ctx->quiet_shutdown);
2809}
2810
2811void
2812SSL_set_quiet_shutdown(SSL *s, int mode)
2813{
2814 s->quiet_shutdown = mode;
2815}
2816
2817int
2818SSL_get_quiet_shutdown(const SSL *s)
2819{
2820 return (s->quiet_shutdown);
2821}
2822
2823void
2824SSL_set_shutdown(SSL *s, int mode)
2825{
2826 s->shutdown = mode;
2827}
2828
2829int
2830SSL_get_shutdown(const SSL *s)
2831{
2832 return (s->shutdown);
2833}
2834
2835int
2836SSL_version(const SSL *s)
2837{
2838 return (s->version);
2839}
2840
2841SSL_CTX *
2842SSL_get_SSL_CTX(const SSL *ssl)
2843{
2844 return (ssl->ctx);
2845}
2846
2847SSL_CTX *
2848SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx)
2849{
2850 if (ssl->ctx == ctx)
2851 return (ssl->ctx);
2852 if (ctx == NULL)
2853 ctx = ssl->initial_ctx;
2854 if (ssl->cert != NULL)
2855 ssl_cert_free(ssl->cert);
2856 ssl->cert = ssl_cert_dup(ctx->cert);
2857 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
2858 SSL_CTX_free(ssl->ctx); /* decrement reference count */
2859 ssl->ctx = ctx;
2860 return (ssl->ctx);
2861}
2862
2863int
2864SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
2865{
2866 return (X509_STORE_set_default_paths(ctx->cert_store));
2867}
2868
2869int
2870SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
2871 const char *CApath)
2872{
2873 return (X509_STORE_load_locations(ctx->cert_store, CAfile, CApath));
2874}
2875
2876int
2877SSL_CTX_load_verify_mem(SSL_CTX *ctx, void *buf, int len)
2878{
2879 return (X509_STORE_load_mem(ctx->cert_store, buf, len));
2880}
2881
2882void
2883SSL_set_info_callback(SSL *ssl, void (*cb)(const SSL *ssl, int type, int val))
2884{
2885 ssl->info_callback = cb;
2886}
2887
2888void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type, int val)
2889{
2890 return (ssl->info_callback);
2891}
2892
2893int
2894SSL_state(const SSL *ssl)
2895{
2896 return (ssl->state);
2897}
2898
2899void
2900SSL_set_state(SSL *ssl, int state)
2901{
2902 ssl->state = state;
2903}
2904
2905void
2906SSL_set_verify_result(SSL *ssl, long arg)
2907{
2908 ssl->verify_result = arg;
2909}
2910
2911long
2912SSL_get_verify_result(const SSL *ssl)
2913{
2914 return (ssl->verify_result);
2915}
2916
2917int
2918SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
2919 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
2920{
2921 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp,
2922 new_func, dup_func, free_func));
2923}
2924
2925int
2926SSL_set_ex_data(SSL *s, int idx, void *arg)
2927{
2928 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
2929}
2930
2931void *
2932SSL_get_ex_data(const SSL *s, int idx)
2933{
2934 return (CRYPTO_get_ex_data(&s->ex_data, idx));
2935}
2936
2937int
2938SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
2939 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
2940{
2941 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp,
2942 new_func, dup_func, free_func));
2943}
2944
2945int
2946SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)
2947{
2948 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
2949}
2950
2951void *
2952SSL_CTX_get_ex_data(const SSL_CTX *s, int idx)
2953{
2954 return (CRYPTO_get_ex_data(&s->ex_data, idx));
2955}
2956
2957int
2958ssl_ok(SSL *s)
2959{
2960 return (1);
2961}
2962
2963X509_STORE *
2964SSL_CTX_get_cert_store(const SSL_CTX *ctx)
2965{
2966 return (ctx->cert_store);
2967}
2968
2969void
2970SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store)
2971{
2972 if (ctx->cert_store != NULL)
2973 X509_STORE_free(ctx->cert_store);
2974 ctx->cert_store = store;
2975}
2976
2977int
2978SSL_want(const SSL *s)
2979{
2980 return (s->rwstate);
2981}
2982
2983void
2984SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, RSA *(*cb)(SSL *ssl, int is_export,
2985 int keylength))
2986{
2987 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb);
2988}
2989
2990void
2991SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int is_export,
2992 int keylength))
2993{
2994 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb);
2995}
2996
2997void
2998SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, DH *(*dh)(SSL *ssl, int is_export,
2999 int keylength))
3000{
3001 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
3002}
3003
3004void
3005SSL_set_tmp_dh_callback(SSL *ssl, DH *(*dh)(SSL *ssl, int is_export,
3006 int keylength))
3007{
3008 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
3009}
3010
3011void
3012SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx, EC_KEY *(*ecdh)(SSL *ssl,
3013 int is_export, int keylength))
3014{
3015 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH_CB,
3016 (void (*)(void))ecdh);
3017}
3018
3019void
3020SSL_set_tmp_ecdh_callback(SSL *ssl, EC_KEY *(*ecdh)(SSL *ssl, int is_export,
3021 int keylength))
3022{
3023 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh);
3024}
3025
3026
3027void
3028SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version,
3029 int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
3030{
3031 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK,
3032 (void (*)(void))cb);
3033}
3034
3035void
3036SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
3037 int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
3038{
3039 SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
3040}
3041
3042void
3043ssl_clear_hash_ctx(EVP_MD_CTX **hash)
3044{
3045 if (*hash)
3046 EVP_MD_CTX_destroy(*hash);
3047 *hash = NULL;
3048}
3049
3050void
3051SSL_set_debug(SSL *s, int debug)
3052{
3053 s->debug = debug;
3054}
3055
3056int
3057SSL_cache_hit(SSL *s)
3058{
3059 return (s->hit);
3060}
3061
3062IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
deleted file mode 100644
index 2a521fe26a..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,847 +0,0 @@
1/* $OpenBSD: ssl_locl.h,v 1.129 2016/04/28 16:39:45 jsing Exp $ */
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-2007 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 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#ifndef HEADER_SSL_LOCL_H
144#define HEADER_SSL_LOCL_H
145
146#include <sys/types.h>
147
148#include <errno.h>
149#include <stdlib.h>
150#include <string.h>
151#include <time.h>
152#include <unistd.h>
153
154#include <openssl/opensslconf.h>
155#include <openssl/bio.h>
156#include <openssl/buffer.h>
157#include <openssl/dsa.h>
158#include <openssl/err.h>
159#include <openssl/rsa.h>
160#include <openssl/ssl.h>
161#include <openssl/stack.h>
162
163#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
164 l|=(((unsigned long)(*((c)++)))<< 8), \
165 l|=(((unsigned long)(*((c)++)))<<16), \
166 l|=(((unsigned long)(*((c)++)))<<24))
167
168/* NOTE - c is not incremented as per c2l */
169#define c2ln(c,l1,l2,n) { \
170 c+=n; \
171 l1=l2=0; \
172 switch (n) { \
173 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
174 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
175 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
176 case 5: l2|=((unsigned long)(*(--(c)))); \
177 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
178 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
179 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
180 case 1: l1|=((unsigned long)(*(--(c)))); \
181 } \
182 }
183
184#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
185 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
186 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
187 *((c)++)=(unsigned char)(((l)>>24)&0xff))
188
189#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
190 l|=((unsigned long)(*((c)++)))<<16, \
191 l|=((unsigned long)(*((c)++)))<< 8, \
192 l|=((unsigned long)(*((c)++))))
193
194#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
195 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
196 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
197 *((c)++)=(unsigned char)(((l) )&0xff))
198
199#define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
200 *((c)++)=(unsigned char)(((l)>>48)&0xff), \
201 *((c)++)=(unsigned char)(((l)>>40)&0xff), \
202 *((c)++)=(unsigned char)(((l)>>32)&0xff), \
203 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
204 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
205 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
206 *((c)++)=(unsigned char)(((l) )&0xff))
207
208/* NOTE - c is not incremented as per l2c */
209#define l2cn(l1,l2,c,n) { \
210 c+=n; \
211 switch (n) { \
212 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
213 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
214 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
215 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
216 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
217 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
218 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
219 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
220 } \
221 }
222
223#define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
224 (((unsigned int)(c[1])) )),c+=2)
225#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
226 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
227
228#define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \
229 (((unsigned long)(c[1]))<< 8)| \
230 (((unsigned long)(c[2])) )),c+=3)
231
232#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
233 c[1]=(unsigned char)(((l)>> 8)&0xff), \
234 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
235
236/* LOCAL STUFF */
237
238#define SSL_DECRYPT 0
239#define SSL_ENCRYPT 1
240
241/*
242 * Define the Bitmasks for SSL_CIPHER.algorithms.
243 * This bits are used packed as dense as possible. If new methods/ciphers
244 * etc will be added, the bits a likely to change, so this information
245 * is for internal library use only, even though SSL_CIPHER.algorithms
246 * can be publicly accessed.
247 * Use the according functions for cipher management instead.
248 *
249 * The bit mask handling in the selection and sorting scheme in
250 * ssl_create_cipher_list() has only limited capabilities, reflecting
251 * that the different entities within are mutually exclusive:
252 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
253 */
254
255/* Bits for algorithm_mkey (key exchange algorithm) */
256#define SSL_kRSA 0x00000001L /* RSA key exchange */
257#define SSL_kDHE 0x00000008L /* tmp DH key no DH cert */
258#define SSL_kECDHr 0x00000020L /* ECDH cert, RSA CA cert */
259#define SSL_kECDHe 0x00000040L /* ECDH cert, ECDSA CA cert */
260#define SSL_kECDHE 0x00000080L /* ephemeral ECDH */
261#define SSL_kGOST 0x00000200L /* GOST key exchange */
262
263/* Bits for algorithm_auth (server authentication) */
264#define SSL_aRSA 0x00000001L /* RSA auth */
265#define SSL_aDSS 0x00000002L /* DSS auth */
266#define SSL_aNULL 0x00000004L /* no auth (i.e. use ADH or AECDH) */
267#define SSL_aECDH 0x00000010L /* Fixed ECDH auth (kECDHe or kECDHr) */
268#define SSL_aECDSA 0x00000040L /* ECDSA auth*/
269#define SSL_aGOST01 0x00000200L /* GOST R 34.10-2001 signature auth */
270
271
272/* Bits for algorithm_enc (symmetric encryption) */
273#define SSL_DES 0x00000001L
274#define SSL_3DES 0x00000002L
275#define SSL_RC4 0x00000004L
276#define SSL_IDEA 0x00000008L
277#define SSL_eNULL 0x00000010L
278#define SSL_AES128 0x00000020L
279#define SSL_AES256 0x00000040L
280#define SSL_CAMELLIA128 0x00000080L
281#define SSL_CAMELLIA256 0x00000100L
282#define SSL_eGOST2814789CNT 0x00000200L
283#define SSL_AES128GCM 0x00000400L
284#define SSL_AES256GCM 0x00000800L
285#define SSL_CHACHA20POLY1305 0x00001000L
286#define SSL_CHACHA20POLY1305_OLD 0x00002000L
287
288#define SSL_AES (SSL_AES128|SSL_AES256|SSL_AES128GCM|SSL_AES256GCM)
289#define SSL_CAMELLIA (SSL_CAMELLIA128|SSL_CAMELLIA256)
290
291
292/* Bits for algorithm_mac (symmetric authentication) */
293
294#define SSL_MD5 0x00000001L
295#define SSL_SHA1 0x00000002L
296#define SSL_GOST94 0x00000004L
297#define SSL_GOST89MAC 0x00000008L
298#define SSL_SHA256 0x00000010L
299#define SSL_SHA384 0x00000020L
300/* Not a real MAC, just an indication it is part of cipher */
301#define SSL_AEAD 0x00000040L
302#define SSL_STREEBOG256 0x00000080L
303#define SSL_STREEBOG512 0x00000100L
304
305/* Bits for algorithm_ssl (protocol version) */
306#define SSL_SSLV3 0x00000002L
307#define SSL_TLSV1 SSL_SSLV3 /* for now */
308#define SSL_TLSV1_2 0x00000004L
309
310
311/* Bits for algorithm2 (handshake digests and other extra flags) */
312
313#define SSL_HANDSHAKE_MAC_MD5 0x10
314#define SSL_HANDSHAKE_MAC_SHA 0x20
315#define SSL_HANDSHAKE_MAC_GOST94 0x40
316#define SSL_HANDSHAKE_MAC_SHA256 0x80
317#define SSL_HANDSHAKE_MAC_SHA384 0x100
318#define SSL_HANDSHAKE_MAC_STREEBOG256 0x200
319#define SSL_HANDSHAKE_MAC_STREEBOG512 0x400
320#define SSL_HANDSHAKE_MAC_DEFAULT (SSL_HANDSHAKE_MAC_MD5 | SSL_HANDSHAKE_MAC_SHA)
321
322/* When adding new digest in the ssl_ciph.c and increment SSM_MD_NUM_IDX
323 * make sure to update this constant too */
324#define SSL_MAX_DIGEST 8
325
326#define SSL3_CK_ID 0x03000000
327#define SSL3_CK_VALUE_MASK 0x0000ffff
328
329#define TLS1_PRF_DGST_MASK (0xff << TLS1_PRF_DGST_SHIFT)
330
331#define TLS1_PRF_DGST_SHIFT 10
332#define TLS1_PRF_MD5 (SSL_HANDSHAKE_MAC_MD5 << TLS1_PRF_DGST_SHIFT)
333#define TLS1_PRF_SHA1 (SSL_HANDSHAKE_MAC_SHA << TLS1_PRF_DGST_SHIFT)
334#define TLS1_PRF_SHA256 (SSL_HANDSHAKE_MAC_SHA256 << TLS1_PRF_DGST_SHIFT)
335#define TLS1_PRF_SHA384 (SSL_HANDSHAKE_MAC_SHA384 << TLS1_PRF_DGST_SHIFT)
336#define TLS1_PRF_GOST94 (SSL_HANDSHAKE_MAC_GOST94 << TLS1_PRF_DGST_SHIFT)
337#define TLS1_PRF_STREEBOG256 (SSL_HANDSHAKE_MAC_STREEBOG256 << TLS1_PRF_DGST_SHIFT)
338#define TLS1_PRF (TLS1_PRF_MD5 | TLS1_PRF_SHA1)
339
340/* Stream MAC for GOST ciphersuites from cryptopro draft
341 * (currently this also goes into algorithm2) */
342#define TLS1_STREAM_MAC 0x04
343
344/*
345 * SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD is an algorithm2 flag that
346 * indicates that the variable part of the nonce is included as a prefix of
347 * the record (AES-GCM, for example, does this with an 8-byte variable nonce.)
348 */
349#define SSL_CIPHER_ALGORITHM2_VARIABLE_NONCE_IN_RECORD (1 << 22)
350
351/*
352 * SSL_CIPHER_ALGORITHM2_AEAD is an algorithm2 flag that indicates the cipher
353 * is implemented via an EVP_AEAD.
354 */
355#define SSL_CIPHER_ALGORITHM2_AEAD (1 << 23)
356
357/*
358 * SSL_CIPHER_AEAD_FIXED_NONCE_LEN returns the number of bytes of fixed nonce
359 * for an SSL_CIPHER with the SSL_CIPHER_ALGORITHM2_AEAD flag.
360 */
361#define SSL_CIPHER_AEAD_FIXED_NONCE_LEN(ssl_cipher) \
362 (((ssl_cipher->algorithm2 >> 24) & 0xf) * 2)
363
364/*
365 * Cipher strength information.
366 */
367#define SSL_STRONG_MASK 0x000001fcL
368#define SSL_STRONG_NONE 0x00000004L
369#define SSL_LOW 0x00000020L
370#define SSL_MEDIUM 0x00000040L
371#define SSL_HIGH 0x00000080L
372
373/*
374 * The keylength (measured in RSA key bits, I guess) for temporary keys.
375 * Cipher argument is so that this can be variable in the future.
376 */
377#define SSL_C_PKEYLENGTH(c) 1024
378
379/* Check if an SSL structure is using DTLS. */
380#define SSL_IS_DTLS(s) (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS)
381
382/* See if we need explicit IV. */
383#define SSL_USE_EXPLICIT_IV(s) \
384 (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_EXPLICIT_IV)
385
386/* See if we use signature algorithms extension. */
387#define SSL_USE_SIGALGS(s) \
388 (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_SIGALGS)
389
390/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
391#define SSL_USE_TLS1_2_CIPHERS(s) \
392 (s->method->ssl3_enc->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
393
394/* Mostly for SSLv3 */
395#define SSL_PKEY_RSA_ENC 0
396#define SSL_PKEY_RSA_SIGN 1
397#define SSL_PKEY_DSA_SIGN 2
398#define SSL_PKEY_DH_RSA 3
399#define SSL_PKEY_DH_DSA 4
400#define SSL_PKEY_ECC 5
401#define SSL_PKEY_GOST01 6
402#define SSL_PKEY_NUM 7
403
404/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
405 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
406 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
407 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
408 * SSL_aRSA <- RSA_ENC | RSA_SIGN
409 * SSL_aDSS <- DSA_SIGN
410 */
411
412/*
413#define CERT_INVALID 0
414#define CERT_PUBLIC_KEY 1
415#define CERT_PRIVATE_KEY 2
416*/
417
418/* From ECC-TLS draft, used in encoding the curve type in
419 * ECParameters
420 */
421#define EXPLICIT_PRIME_CURVE_TYPE 1
422#define EXPLICIT_CHAR2_CURVE_TYPE 2
423#define NAMED_CURVE_TYPE 3
424
425typedef struct cert_pkey_st {
426 X509 *x509;
427 EVP_PKEY *privatekey;
428 /* Digest to use when signing */
429 const EVP_MD *digest;
430} CERT_PKEY;
431
432typedef struct cert_st {
433 /* Current active set */
434 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
435 * Probably it would make more sense to store
436 * an index, not a pointer. */
437
438 /* The following masks are for the key and auth
439 * algorithms that are supported by the certs below */
440 int valid;
441 unsigned long mask_k;
442 unsigned long mask_a;
443
444 DH *dh_tmp;
445 DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
446 int dh_tmp_auto;
447
448 EC_KEY *ecdh_tmp;
449 EC_KEY *(*ecdh_tmp_cb)(SSL *ssl, int is_export, int keysize);
450 int ecdh_tmp_auto;
451
452 CERT_PKEY pkeys[SSL_PKEY_NUM];
453
454 int references; /* >1 only if SSL_copy_session_id is used */
455} CERT;
456
457
458typedef struct sess_cert_st {
459 STACK_OF(X509) *cert_chain; /* as received from peer */
460
461 /* The 'peer_...' members are used only by clients. */
462 int peer_cert_type;
463
464 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
465 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
466 /* Obviously we don't have the private keys of these,
467 * so maybe we shouldn't even use the CERT_PKEY type here. */
468
469 DH *peer_dh_tmp;
470 EC_KEY *peer_ecdh_tmp;
471
472 int references; /* actually always 1 at the moment */
473} SESS_CERT;
474
475
476/*#define SSL_DEBUG */
477/*#define RSA_DEBUG */
478
479/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
480 * It is a bit of a mess of functions, but hell, think of it as
481 * an opaque structure :-) */
482typedef struct ssl3_enc_method {
483 int (*enc)(SSL *, int);
484 int (*mac)(SSL *, unsigned char *, int);
485 int (*setup_key_block)(SSL *);
486 int (*generate_master_secret)(SSL *, unsigned char *,
487 unsigned char *, int);
488 int (*change_cipher_state)(SSL *, int);
489 int (*final_finish_mac)(SSL *, const char *, int, unsigned char *);
490 int finish_mac_length;
491 int (*cert_verify_mac)(SSL *, int, unsigned char *);
492 const char *client_finished_label;
493 int client_finished_label_len;
494 const char *server_finished_label;
495 int server_finished_label_len;
496 int (*alert_value)(int);
497 int (*export_keying_material)(SSL *, unsigned char *, size_t,
498 const char *, size_t, const unsigned char *, size_t,
499 int use_context);
500 /* Flags indicating protocol version requirements. */
501 unsigned int enc_flags;
502} SSL3_ENC_METHOD;
503
504/*
505 * Flag values for enc_flags.
506 */
507
508/* Uses explicit IV. */
509#define SSL_ENC_FLAG_EXPLICIT_IV (1 << 0)
510
511/* Uses signature algorithms extension. */
512#define SSL_ENC_FLAG_SIGALGS (1 << 1)
513
514/* Uses SHA256 default PRF. */
515#define SSL_ENC_FLAG_SHA256_PRF (1 << 2)
516
517/* Is DTLS. */
518#define SSL_ENC_FLAG_DTLS (1 << 3)
519
520/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
521#define SSL_ENC_FLAG_TLS1_2_CIPHERS (1 << 4)
522
523/*
524 * ssl_aead_ctx_st contains information about an AEAD that is being used to
525 * encrypt an SSL connection.
526 */
527struct ssl_aead_ctx_st {
528 EVP_AEAD_CTX ctx;
529 /*
530 * fixed_nonce contains any bytes of the nonce that are fixed for all
531 * records.
532 */
533 unsigned char fixed_nonce[12];
534 unsigned char fixed_nonce_len;
535 unsigned char variable_nonce_len;
536 unsigned char xor_fixed_nonce;
537 unsigned char tag_len;
538 /*
539 * variable_nonce_in_record is non-zero if the variable nonce
540 * for a record is included as a prefix before the ciphertext.
541 */
542 char variable_nonce_in_record;
543};
544
545extern SSL3_ENC_METHOD ssl3_undef_enc_method;
546extern SSL_CIPHER ssl3_ciphers[];
547
548const char *ssl_version_string(int ver);
549uint16_t ssl_max_server_version(SSL *s);
550
551extern SSL3_ENC_METHOD DTLSv1_enc_data;
552extern SSL3_ENC_METHOD TLSv1_enc_data;
553extern SSL3_ENC_METHOD TLSv1_1_enc_data;
554extern SSL3_ENC_METHOD TLSv1_2_enc_data;
555
556void ssl_clear_cipher_ctx(SSL *s);
557int ssl_clear_bad_session(SSL *s);
558CERT *ssl_cert_new(void);
559CERT *ssl_cert_dup(CERT *cert);
560int ssl_cert_inst(CERT **o);
561void ssl_cert_free(CERT *c);
562SESS_CERT *ssl_sess_cert_new(void);
563void ssl_sess_cert_free(SESS_CERT *sc);
564int ssl_get_new_session(SSL *s, int session);
565int ssl_get_prev_session(SSL *s, unsigned char *session, int len,
566 const unsigned char *limit);
567int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
568DECLARE_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
569int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
570 const SSL_CIPHER * const *bp);
571STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, const unsigned char *p,
572 int num);
573int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk,
574 unsigned char *p);
575STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
576 STACK_OF(SSL_CIPHER) **pref, STACK_OF(SSL_CIPHER) **sorted,
577 const char *rule_str);
578void ssl_update_cache(SSL *s, int mode);
579int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
580 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size);
581int ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead);
582int ssl_get_handshake_digest(int i, long *mask, const EVP_MD **md);
583
584int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
585int ssl_undefined_function(SSL *s);
586int ssl_undefined_void_function(void);
587int ssl_undefined_const_function(const SSL *s);
588CERT_PKEY *ssl_get_server_send_pkey(const SSL *s);
589X509 *ssl_get_server_send_cert(const SSL *);
590EVP_PKEY *ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *c, const EVP_MD **pmd);
591DH *ssl_get_auto_dh(SSL *s);
592int ssl_cert_type(X509 *x, EVP_PKEY *pkey);
593void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);
594STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
595int ssl_verify_alarm_type(long type);
596void ssl_load_ciphers(void);
597
598const SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
599int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
600int ssl3_send_server_certificate(SSL *s);
601int ssl3_send_newsession_ticket(SSL *s);
602int ssl3_send_cert_status(SSL *s);
603int ssl3_get_finished(SSL *s, int state_a, int state_b);
604int ssl3_send_change_cipher_spec(SSL *s, int state_a, int state_b);
605int ssl3_do_write(SSL *s, int type);
606int ssl3_send_alert(SSL *s, int level, int desc);
607int ssl3_get_req_cert_type(SSL *s, unsigned char *p);
608long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
609int ssl3_send_finished(SSL *s, int a, int b, const char *sender, int slen);
610int ssl3_num_ciphers(void);
611const SSL_CIPHER *ssl3_get_cipher(unsigned int u);
612const SSL_CIPHER *ssl3_get_cipher_by_id(unsigned int id);
613const SSL_CIPHER *ssl3_get_cipher_by_value(uint16_t value);
614uint16_t ssl3_cipher_get_value(const SSL_CIPHER *c);
615int ssl3_renegotiate(SSL *ssl);
616
617int ssl3_renegotiate_check(SSL *ssl);
618
619int ssl3_dispatch_alert(SSL *s);
620int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
621int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
622unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
623SSL_CIPHER *ssl3_choose_cipher(SSL *ssl, STACK_OF(SSL_CIPHER) *clnt,
624 STACK_OF(SSL_CIPHER) *srvr);
625int ssl3_setup_buffers(SSL *s);
626int ssl3_setup_init_buffer(SSL *s);
627int ssl3_setup_read_buffer(SSL *s);
628int ssl3_setup_write_buffer(SSL *s);
629int ssl3_release_read_buffer(SSL *s);
630int ssl3_release_write_buffer(SSL *s);
631int ssl3_new(SSL *s);
632void ssl3_free(SSL *s);
633int ssl3_accept(SSL *s);
634int ssl3_connect(SSL *s);
635int ssl3_read(SSL *s, void *buf, int len);
636int ssl3_peek(SSL *s, void *buf, int len);
637int ssl3_write(SSL *s, const void *buf, int len);
638int ssl3_shutdown(SSL *s);
639void ssl3_clear(SSL *s);
640long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
641long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
642long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
643long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
644int ssl3_pending(const SSL *s);
645
646int ssl3_handshake_msg_hdr_len(SSL *s);
647unsigned char *ssl3_handshake_msg_start(SSL *s, uint8_t htype);
648void ssl3_handshake_msg_finish(SSL *s, unsigned int len);
649int ssl3_handshake_write(SSL *s);
650
651void tls1_record_sequence_increment(unsigned char *seq);
652int ssl3_do_change_cipher_spec(SSL *ssl);
653
654int ssl23_read(SSL *s, void *buf, int len);
655int ssl23_peek(SSL *s, void *buf, int len);
656int ssl23_write(SSL *s, const void *buf, int len);
657long ssl23_default_timeout(void);
658
659long tls1_default_timeout(void);
660int dtls1_do_write(SSL *s, int type);
661int ssl3_read_n(SSL *s, int n, int max, int extend);
662int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
663int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
664 unsigned int len);
665unsigned char *dtls1_set_message_header(SSL *s, unsigned char *p,
666 unsigned char mt, unsigned long len, unsigned long frag_off,
667 unsigned long frag_len);
668
669int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len);
670int dtls1_write_bytes(SSL *s, int type, const void *buf, int len);
671
672int dtls1_send_change_cipher_spec(SSL *s, int a, int b);
673unsigned long dtls1_output_cert_chain(SSL *s, X509 *x);
674int dtls1_read_failed(SSL *s, int code);
675int dtls1_buffer_message(SSL *s, int ccs);
676int dtls1_retransmit_message(SSL *s, unsigned short seq,
677 unsigned long frag_off, int *found);
678int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
679int dtls1_retransmit_buffered_messages(SSL *s);
680void dtls1_clear_record_buffer(SSL *s);
681int dtls1_get_message_header(unsigned char *data,
682 struct hm_header_st *msg_hdr);
683void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr);
684void dtls1_reset_seq_numbers(SSL *s, int rw);
685void dtls1_build_sequence_number(unsigned char *dst, unsigned char *seq,
686 unsigned short epoch);
687long dtls1_default_timeout(void);
688struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft);
689int dtls1_check_timeout_num(SSL *s);
690int dtls1_handle_timeout(SSL *s);
691const SSL_CIPHER *dtls1_get_cipher(unsigned int u);
692void dtls1_start_timer(SSL *s);
693void dtls1_stop_timer(SSL *s);
694int dtls1_is_timer_expired(SSL *s);
695void dtls1_double_timeout(SSL *s);
696unsigned int dtls1_min_mtu(void);
697
698/* some client-only functions */
699int ssl3_client_hello(SSL *s);
700int ssl3_get_server_hello(SSL *s);
701int ssl3_get_certificate_request(SSL *s);
702int ssl3_get_new_session_ticket(SSL *s);
703int ssl3_get_cert_status(SSL *s);
704int ssl3_get_server_done(SSL *s);
705int ssl3_send_client_verify(SSL *s);
706int ssl3_send_client_certificate(SSL *s);
707int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
708int ssl3_send_client_key_exchange(SSL *s);
709int ssl3_get_key_exchange(SSL *s);
710int ssl3_get_server_certificate(SSL *s);
711int ssl3_check_cert_and_algorithm(SSL *s);
712int ssl3_check_finished(SSL *s);
713int ssl3_send_next_proto(SSL *s);
714
715int dtls1_send_client_certificate(SSL *s);
716
717/* some server-only functions */
718int ssl3_get_client_hello(SSL *s);
719int ssl3_send_server_hello(SSL *s);
720int ssl3_send_hello_request(SSL *s);
721int ssl3_send_server_key_exchange(SSL *s);
722int ssl3_send_certificate_request(SSL *s);
723int ssl3_send_server_done(SSL *s);
724int ssl3_get_client_certificate(SSL *s);
725int ssl3_get_client_key_exchange(SSL *s);
726int ssl3_get_cert_verify(SSL *s);
727int ssl3_get_next_proto(SSL *s);
728
729int dtls1_send_server_certificate(SSL *s);
730
731int ssl23_accept(SSL *s);
732int ssl23_connect(SSL *s);
733int ssl23_read_bytes(SSL *s, int n);
734int ssl23_write_bytes(SSL *s);
735
736int tls1_new(SSL *s);
737void tls1_free(SSL *s);
738void tls1_clear(SSL *s);
739long tls1_ctrl(SSL *s, int cmd, long larg, void *parg);
740long tls1_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
741
742int dtls1_new(SSL *s);
743int dtls1_accept(SSL *s);
744int dtls1_connect(SSL *s);
745void dtls1_free(SSL *s);
746void dtls1_clear(SSL *s);
747long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
748int dtls1_shutdown(SSL *s);
749
750long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
751int dtls1_get_record(SSL *s);
752int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
753 unsigned int len);
754int dtls1_dispatch_alert(SSL *s);
755int dtls1_enc(SSL *s, int snd);
756
757int ssl_init_wbio_buffer(SSL *s, int push);
758void ssl_free_wbio_buffer(SSL *s);
759
760int tls1_init_finished_mac(SSL *s);
761void tls1_finish_mac(SSL *s, const unsigned char *buf, int len);
762void tls1_free_digest_list(SSL *s);
763void tls1_cleanup_key_block(SSL *s);
764int tls1_digest_cached_records(SSL *s);
765int tls1_change_cipher_state(SSL *s, int which);
766int tls1_setup_key_block(SSL *s);
767int tls1_enc(SSL *s, int snd);
768int tls1_final_finish_mac(SSL *s, const char *str, int slen, unsigned char *p);
769int tls1_cert_verify_mac(SSL *s, int md_nid, unsigned char *p);
770int tls1_mac(SSL *ssl, unsigned char *md, int snd);
771int tls1_generate_master_secret(SSL *s, unsigned char *out,
772 unsigned char *p, int len);
773int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
774 const char *label, size_t llen, const unsigned char *p, size_t plen,
775 int use_context);
776int tls1_alert_code(int code);
777int ssl_ok(SSL *s);
778
779int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s);
780
781SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
782
783int tls1_ec_curve_id2nid(uint16_t curve_id);
784uint16_t tls1_ec_nid2curve_id(int nid);
785int tls1_check_curve(SSL *s, const unsigned char *p, size_t len);
786int tls1_get_shared_curve(SSL *s);
787
788unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p,
789 unsigned char *limit);
790
791unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p,
792 unsigned char *limit);
793
794int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data,
795 unsigned char *d, int n, int *al);
796int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data,
797 unsigned char *d, int n, int *al);
798int ssl_check_clienthello_tlsext_early(SSL *s);
799int ssl_check_clienthello_tlsext_late(SSL *s);
800int ssl_check_serverhello_tlsext(SSL *s);
801
802#define tlsext_tick_md EVP_sha256
803int tls1_process_ticket(SSL *s, const unsigned char *session_id, int len,
804 const unsigned char *limit, SSL_SESSION **ret);
805int tls12_get_sigandhash(unsigned char *p, const EVP_PKEY *pk,
806 const EVP_MD *md);
807int tls12_get_sigid(const EVP_PKEY *pk);
808const EVP_MD *tls12_get_hash(unsigned char hash_alg);
809
810void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
811int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p,
812 int *len, int maxlen);
813int ssl_parse_serverhello_renegotiate_ext(SSL *s, const unsigned char *d,
814 int len, int *al);
815int ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p,
816 int *len, int maxlen);
817int ssl_parse_clienthello_renegotiate_ext(SSL *s, const unsigned char *d,
818 int len, int *al);
819long ssl_get_algorithm2(SSL *s);
820int tls1_process_sigalgs(SSL *s, const unsigned char *data, int dsize);
821int tls12_get_req_sig_algs(SSL *s, unsigned char *p);
822
823int tls1_check_ec_server_key(SSL *s);
824int tls1_check_ec_tmp_key(SSL *s);
825
826int ssl_add_clienthello_use_srtp_ext(SSL *s, unsigned char *p,
827 int *len, int maxlen);
828int ssl_parse_clienthello_use_srtp_ext(SSL *s, const unsigned char *d,
829 int len, int *al);
830int ssl_add_serverhello_use_srtp_ext(SSL *s, unsigned char *p,
831 int *len, int maxlen);
832int ssl_parse_serverhello_use_srtp_ext(SSL *s, const unsigned char *d,
833 int len, int *al);
834
835/* s3_cbc.c */
836void ssl3_cbc_copy_mac(unsigned char *out, const SSL3_RECORD *rec,
837 unsigned md_size, unsigned orig_len);
838int tls1_cbc_remove_padding(const SSL *s, SSL3_RECORD *rec,
839 unsigned block_size, unsigned mac_size);
840char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
841int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out,
842 size_t *md_out_size, const unsigned char header[13],
843 const unsigned char *data, size_t data_plus_mac_size,
844 size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret,
845 unsigned mac_secret_length, char is_sslv3);
846
847#endif
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index 7481524942..0000000000
--- a/src/lib/libssl/ssl_rsa.c
+++ /dev/null
@@ -1,751 +0,0 @@
1/* $OpenBSD: ssl_rsa.c,v 1.21 2016/03/11 07:08:45 mmcc Exp $ */
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
61#include "ssl_locl.h"
62
63#include <openssl/bio.h>
64#include <openssl/evp.h>
65#include <openssl/objects.h>
66#include <openssl/pem.h>
67#include <openssl/x509.h>
68
69static int ssl_set_cert(CERT *c, X509 *x509);
70static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
71static int ssl_ctx_use_certificate_chain_bio(SSL_CTX *, BIO *);
72
73int
74SSL_use_certificate(SSL *ssl, X509 *x)
75{
76 if (x == NULL) {
77 SSLerr(SSL_F_SSL_USE_CERTIFICATE, ERR_R_PASSED_NULL_PARAMETER);
78 return (0);
79 }
80 if (!ssl_cert_inst(&ssl->cert)) {
81 SSLerr(SSL_F_SSL_USE_CERTIFICATE, ERR_R_MALLOC_FAILURE);
82 return (0);
83 }
84 return (ssl_set_cert(ssl->cert, x));
85}
86
87int
88SSL_use_certificate_file(SSL *ssl, const char *file, int type)
89{
90 int j;
91 BIO *in;
92 int ret = 0;
93 X509 *x = NULL;
94
95 in = BIO_new(BIO_s_file_internal());
96 if (in == NULL) {
97 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, ERR_R_BUF_LIB);
98 goto end;
99 }
100
101 if (BIO_read_filename(in, file) <= 0) {
102 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, ERR_R_SYS_LIB);
103 goto end;
104 }
105 if (type == SSL_FILETYPE_ASN1) {
106 j = ERR_R_ASN1_LIB;
107 x = d2i_X509_bio(in, NULL);
108 } else if (type == SSL_FILETYPE_PEM) {
109 j = ERR_R_PEM_LIB;
110 x = PEM_read_bio_X509(in, NULL,
111 ssl->ctx->default_passwd_callback,
112 ssl->ctx->default_passwd_callback_userdata);
113 } else {
114 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, SSL_R_BAD_SSL_FILETYPE);
115 goto end;
116 }
117
118 if (x == NULL) {
119 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE, j);
120 goto end;
121 }
122
123 ret = SSL_use_certificate(ssl, x);
124end:
125 X509_free(x);
126 BIO_free(in);
127 return (ret);
128}
129
130int
131SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len)
132{
133 X509 *x;
134 int ret;
135
136 x = d2i_X509(NULL, &d,(long)len);
137 if (x == NULL) {
138 SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1, ERR_R_ASN1_LIB);
139 return (0);
140 }
141
142 ret = SSL_use_certificate(ssl, x);
143 X509_free(x);
144 return (ret);
145}
146
147int
148SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
149{
150 EVP_PKEY *pkey;
151 int ret;
152
153 if (rsa == NULL) {
154 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER);
155 return (0);
156 }
157 if (!ssl_cert_inst(&ssl->cert)) {
158 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY, ERR_R_MALLOC_FAILURE);
159 return (0);
160 }
161 if ((pkey = EVP_PKEY_new()) == NULL) {
162 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY, ERR_R_EVP_LIB);
163 return (0);
164 }
165
166 RSA_up_ref(rsa);
167 EVP_PKEY_assign_RSA(pkey, rsa);
168
169 ret = ssl_set_pkey(ssl->cert, pkey);
170 EVP_PKEY_free(pkey);
171 return (ret);
172}
173
174static int
175ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
176{
177 int i;
178
179 i = ssl_cert_type(NULL, pkey);
180 if (i < 0) {
181 SSLerr(SSL_F_SSL_SET_PKEY, SSL_R_UNKNOWN_CERTIFICATE_TYPE);
182 return (0);
183 }
184
185 if (c->pkeys[i].x509 != NULL) {
186 EVP_PKEY *pktmp;
187 pktmp = X509_get_pubkey(c->pkeys[i].x509);
188 EVP_PKEY_copy_parameters(pktmp, pkey);
189 EVP_PKEY_free(pktmp);
190 ERR_clear_error();
191
192 /*
193 * Don't check the public/private key, this is mostly
194 * for smart cards.
195 */
196 if ((pkey->type == EVP_PKEY_RSA) &&
197 (RSA_flags(pkey->pkey.rsa) & RSA_METHOD_FLAG_NO_CHECK))
198;
199 else
200 if (!X509_check_private_key(c->pkeys[i].x509, pkey)) {
201 X509_free(c->pkeys[i].x509);
202 c->pkeys[i].x509 = NULL;
203 return 0;
204 }
205 }
206
207 EVP_PKEY_free(c->pkeys[i].privatekey);
208 CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
209 c->pkeys[i].privatekey = pkey;
210 c->key = &(c->pkeys[i]);
211
212 c->valid = 0;
213 return (1);
214}
215
216int
217SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
218{
219 int j, ret = 0;
220 BIO *in;
221 RSA *rsa = NULL;
222
223 in = BIO_new(BIO_s_file_internal());
224 if (in == NULL) {
225 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, ERR_R_BUF_LIB);
226 goto end;
227 }
228
229 if (BIO_read_filename(in, file) <= 0) {
230 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, ERR_R_SYS_LIB);
231 goto end;
232 }
233 if (type == SSL_FILETYPE_ASN1) {
234 j = ERR_R_ASN1_LIB;
235 rsa = d2i_RSAPrivateKey_bio(in, NULL);
236 } else if (type == SSL_FILETYPE_PEM) {
237 j = ERR_R_PEM_LIB;
238 rsa = PEM_read_bio_RSAPrivateKey(in, NULL,
239 ssl->ctx->default_passwd_callback,
240 ssl->ctx->default_passwd_callback_userdata);
241 } else {
242 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, SSL_R_BAD_SSL_FILETYPE);
243 goto end;
244 }
245 if (rsa == NULL) {
246 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE, j);
247 goto end;
248 }
249 ret = SSL_use_RSAPrivateKey(ssl, rsa);
250 RSA_free(rsa);
251end:
252 BIO_free(in);
253 return (ret);
254}
255
256int
257SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len)
258{
259 int ret;
260 const unsigned char *p;
261 RSA *rsa;
262
263 p = d;
264 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) {
265 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1, ERR_R_ASN1_LIB);
266 return (0);
267 }
268
269 ret = SSL_use_RSAPrivateKey(ssl, rsa);
270 RSA_free(rsa);
271 return (ret);
272}
273
274int
275SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
276{
277 int ret;
278
279 if (pkey == NULL) {
280 SSLerr(SSL_F_SSL_USE_PRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER);
281 return (0);
282 }
283 if (!ssl_cert_inst(&ssl->cert)) {
284 SSLerr(SSL_F_SSL_USE_PRIVATEKEY, ERR_R_MALLOC_FAILURE);
285 return (0);
286 }
287 ret = ssl_set_pkey(ssl->cert, pkey);
288 return (ret);
289}
290
291int
292SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
293{
294 int j, ret = 0;
295 BIO *in;
296 EVP_PKEY *pkey = NULL;
297
298 in = BIO_new(BIO_s_file_internal());
299 if (in == NULL) {
300 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE, ERR_R_BUF_LIB);
301 goto end;
302 }
303
304 if (BIO_read_filename(in, file) <= 0) {
305 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE, ERR_R_SYS_LIB);
306 goto end;
307 }
308 if (type == SSL_FILETYPE_PEM) {
309 j = ERR_R_PEM_LIB;
310 pkey = PEM_read_bio_PrivateKey(in, NULL,
311 ssl->ctx->default_passwd_callback,
312 ssl->ctx->default_passwd_callback_userdata);
313 } else if (type == SSL_FILETYPE_ASN1) {
314 j = ERR_R_ASN1_LIB;
315 pkey = d2i_PrivateKey_bio(in, NULL);
316 } else {
317 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE, SSL_R_BAD_SSL_FILETYPE);
318 goto end;
319 }
320 if (pkey == NULL) {
321 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE, j);
322 goto end;
323 }
324 ret = SSL_use_PrivateKey(ssl, pkey);
325 EVP_PKEY_free(pkey);
326end:
327 BIO_free(in);
328 return (ret);
329}
330
331int
332SSL_use_PrivateKey_ASN1(int type, SSL *ssl, const unsigned char *d, long len)
333{
334 int ret;
335 const unsigned char *p;
336 EVP_PKEY *pkey;
337
338 p = d;
339 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) {
340 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1, ERR_R_ASN1_LIB);
341 return (0);
342 }
343
344 ret = SSL_use_PrivateKey(ssl, pkey);
345 EVP_PKEY_free(pkey);
346 return (ret);
347}
348
349int
350SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
351{
352 if (x == NULL) {
353 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, ERR_R_PASSED_NULL_PARAMETER);
354 return (0);
355 }
356 if (!ssl_cert_inst(&ctx->cert)) {
357 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, ERR_R_MALLOC_FAILURE);
358 return (0);
359 }
360 return (ssl_set_cert(ctx->cert, x));
361}
362
363static int
364ssl_set_cert(CERT *c, X509 *x)
365{
366 EVP_PKEY *pkey;
367 int i;
368
369 pkey = X509_get_pubkey(x);
370 if (pkey == NULL) {
371 SSLerr(SSL_F_SSL_SET_CERT, SSL_R_X509_LIB);
372 return (0);
373 }
374
375 i = ssl_cert_type(x, pkey);
376 if (i < 0) {
377 SSLerr(SSL_F_SSL_SET_CERT, SSL_R_UNKNOWN_CERTIFICATE_TYPE);
378 EVP_PKEY_free(pkey);
379 return (0);
380 }
381
382 if (c->pkeys[i].privatekey != NULL) {
383 EVP_PKEY_copy_parameters(pkey, c->pkeys[i].privatekey);
384 ERR_clear_error();
385
386 /*
387 * Don't check the public/private key, this is mostly
388 * for smart cards.
389 */
390 if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) &&
391 (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) &
392 RSA_METHOD_FLAG_NO_CHECK))
393;
394 else
395 if (!X509_check_private_key(x, c->pkeys[i].privatekey)) {
396 /*
397 * don't fail for a cert/key mismatch, just free
398 * current private key (when switching to a different
399 * cert & key, first this function should be used,
400 * then ssl_set_pkey
401 */
402 EVP_PKEY_free(c->pkeys[i].privatekey);
403 c->pkeys[i].privatekey = NULL;
404 /* clear error queue */
405 ERR_clear_error();
406 }
407 }
408
409 EVP_PKEY_free(pkey);
410
411 X509_free(c->pkeys[i].x509);
412 CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
413 c->pkeys[i].x509 = x;
414 c->key = &(c->pkeys[i]);
415
416 c->valid = 0;
417 return (1);
418}
419
420int
421SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
422{
423 int j;
424 BIO *in;
425 int ret = 0;
426 X509 *x = NULL;
427
428 in = BIO_new(BIO_s_file_internal());
429 if (in == NULL) {
430 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_BUF_LIB);
431 goto end;
432 }
433
434 if (BIO_read_filename(in, file) <= 0) {
435 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, ERR_R_SYS_LIB);
436 goto end;
437 }
438 if (type == SSL_FILETYPE_ASN1) {
439 j = ERR_R_ASN1_LIB;
440 x = d2i_X509_bio(in, NULL);
441 } else if (type == SSL_FILETYPE_PEM) {
442 j = ERR_R_PEM_LIB;
443 x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
444 ctx->default_passwd_callback_userdata);
445 } else {
446 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, SSL_R_BAD_SSL_FILETYPE);
447 goto end;
448 }
449
450 if (x == NULL) {
451 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE, j);
452 goto end;
453 }
454
455 ret = SSL_CTX_use_certificate(ctx, x);
456end:
457 X509_free(x);
458 BIO_free(in);
459 return (ret);
460}
461
462int
463SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d)
464{
465 X509 *x;
466 int ret;
467
468 x = d2i_X509(NULL, &d,(long)len);
469 if (x == NULL) {
470 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1, ERR_R_ASN1_LIB);
471 return (0);
472 }
473
474 ret = SSL_CTX_use_certificate(ctx, x);
475 X509_free(x);
476 return (ret);
477}
478
479int
480SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
481{
482 int ret;
483 EVP_PKEY *pkey;
484
485 if (rsa == NULL) {
486 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER);
487 return (0);
488 }
489 if (!ssl_cert_inst(&ctx->cert)) {
490 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY, ERR_R_MALLOC_FAILURE);
491 return (0);
492 }
493 if ((pkey = EVP_PKEY_new()) == NULL) {
494 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY, ERR_R_EVP_LIB);
495 return (0);
496 }
497
498 RSA_up_ref(rsa);
499 EVP_PKEY_assign_RSA(pkey, rsa);
500
501 ret = ssl_set_pkey(ctx->cert, pkey);
502 EVP_PKEY_free(pkey);
503 return (ret);
504}
505
506int
507SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
508{
509 int j, ret = 0;
510 BIO *in;
511 RSA *rsa = NULL;
512
513 in = BIO_new(BIO_s_file_internal());
514 if (in == NULL) {
515 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE, ERR_R_BUF_LIB);
516 goto end;
517 }
518
519 if (BIO_read_filename(in, file) <= 0) {
520 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE, ERR_R_SYS_LIB);
521 goto end;
522 }
523 if (type == SSL_FILETYPE_ASN1) {
524 j = ERR_R_ASN1_LIB;
525 rsa = d2i_RSAPrivateKey_bio(in, NULL);
526 } else if (type == SSL_FILETYPE_PEM) {
527 j = ERR_R_PEM_LIB;
528 rsa = PEM_read_bio_RSAPrivateKey(in, NULL,
529 ctx->default_passwd_callback,
530 ctx->default_passwd_callback_userdata);
531 } else {
532 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE, SSL_R_BAD_SSL_FILETYPE);
533 goto end;
534 }
535 if (rsa == NULL) {
536 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE, j);
537 goto end;
538 }
539 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
540 RSA_free(rsa);
541end:
542 BIO_free(in);
543 return (ret);
544}
545
546int
547SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len)
548{
549 int ret;
550 const unsigned char *p;
551 RSA *rsa;
552
553 p = d;
554 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) {
555 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1, ERR_R_ASN1_LIB);
556 return (0);
557 }
558
559 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
560 RSA_free(rsa);
561 return (ret);
562}
563
564int
565SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
566{
567 if (pkey == NULL) {
568 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,
569 ERR_R_PASSED_NULL_PARAMETER);
570 return (0);
571 }
572 if (!ssl_cert_inst(&ctx->cert)) {
573 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY, ERR_R_MALLOC_FAILURE);
574 return (0);
575 }
576 return (ssl_set_pkey(ctx->cert, pkey));
577}
578
579int
580SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
581{
582 int j, ret = 0;
583 BIO *in;
584 EVP_PKEY *pkey = NULL;
585
586 in = BIO_new(BIO_s_file_internal());
587 if (in == NULL) {
588 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, ERR_R_BUF_LIB);
589 goto end;
590 }
591
592 if (BIO_read_filename(in, file) <= 0) {
593 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, ERR_R_SYS_LIB);
594 goto end;
595 }
596 if (type == SSL_FILETYPE_PEM) {
597 j = ERR_R_PEM_LIB;
598 pkey = PEM_read_bio_PrivateKey(in, NULL,
599 ctx->default_passwd_callback,
600 ctx->default_passwd_callback_userdata);
601 } else if (type == SSL_FILETYPE_ASN1) {
602 j = ERR_R_ASN1_LIB;
603 pkey = d2i_PrivateKey_bio(in, NULL);
604 } else {
605 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,
606 SSL_R_BAD_SSL_FILETYPE);
607 goto end;
608 }
609 if (pkey == NULL) {
610 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE, j);
611 goto end;
612 }
613 ret = SSL_CTX_use_PrivateKey(ctx, pkey);
614 EVP_PKEY_free(pkey);
615end:
616 BIO_free(in);
617 return (ret);
618}
619
620int
621SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d,
622 long len)
623{
624 int ret;
625 const unsigned char *p;
626 EVP_PKEY *pkey;
627
628 p = d;
629 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) {
630 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1, ERR_R_ASN1_LIB);
631 return (0);
632 }
633
634 ret = SSL_CTX_use_PrivateKey(ctx, pkey);
635 EVP_PKEY_free(pkey);
636 return (ret);
637}
638
639
640/*
641 * Read a bio that contains our certificate in "PEM" format,
642 * possibly followed by a sequence of CA certificates that should be
643 * sent to the peer in the Certificate message.
644 */
645static int
646ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in)
647{
648 int ret = 0;
649 X509 *x = NULL;
650
651 ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */
652
653 x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback,
654 ctx->default_passwd_callback_userdata);
655 if (x == NULL) {
656 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB);
657 goto end;
658 }
659
660 ret = SSL_CTX_use_certificate(ctx, x);
661
662 if (ERR_peek_error() != 0)
663 ret = 0;
664 /* Key/certificate mismatch doesn't imply ret==0 ... */
665 if (ret) {
666 /*
667 * If we could set up our certificate, now proceed to
668 * the CA certificates.
669 */
670 X509 *ca;
671 int r;
672 unsigned long err;
673
674 if (ctx->extra_certs != NULL) {
675 sk_X509_pop_free(ctx->extra_certs, X509_free);
676 ctx->extra_certs = NULL;
677 }
678
679 while ((ca = PEM_read_bio_X509(in, NULL,
680 ctx->default_passwd_callback,
681 ctx->default_passwd_callback_userdata)) != NULL) {
682 r = SSL_CTX_add_extra_chain_cert(ctx, ca);
683 if (!r) {
684 X509_free(ca);
685 ret = 0;
686 goto end;
687 }
688 /*
689 * Note that we must not free r if it was successfully
690 * added to the chain (while we must free the main
691 * certificate, since its reference count is increased
692 * by SSL_CTX_use_certificate).
693 */
694 }
695
696 /* When the while loop ends, it's usually just EOF. */
697 err = ERR_peek_last_error();
698 if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
699 ERR_GET_REASON(err) == PEM_R_NO_START_LINE)
700 ERR_clear_error();
701 else
702 ret = 0; /* some real error */
703 }
704
705end:
706 X509_free(x);
707 return (ret);
708}
709
710int
711SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
712{
713 BIO *in;
714 int ret = 0;
715
716 in = BIO_new(BIO_s_file_internal());
717 if (in == NULL) {
718 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB);
719 goto end;
720 }
721
722 if (BIO_read_filename(in, file) <= 0) {
723 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_SYS_LIB);
724 goto end;
725 }
726
727 ret = ssl_ctx_use_certificate_chain_bio(ctx, in);
728
729end:
730 BIO_free(in);
731 return (ret);
732}
733
734int
735SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
736{
737 BIO *in;
738 int ret = 0;
739
740 in = BIO_new_mem_buf(buf, len);
741 if (in == NULL) {
742 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB);
743 goto end;
744 }
745
746 ret = ssl_ctx_use_certificate_chain_bio(ctx, in);
747
748end:
749 BIO_free(in);
750 return (ret);
751}
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
deleted file mode 100644
index 16dd5c444c..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,1099 +0,0 @@
1/* $OpenBSD: ssl_sess.c,v 1.49 2016/03/11 07:08:45 mmcc Exp $ */
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-2006 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 2005 Nokia. All rights reserved.
113 *
114 * The portions of the attached software ("Contribution") is developed by
115 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
116 * license.
117 *
118 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
119 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
120 * support (see RFC 4279) to OpenSSL.
121 *
122 * No patent licenses or other rights except those expressly stated in
123 * the OpenSSL open source license shall be deemed granted or received
124 * expressly, by implication, estoppel, or otherwise.
125 *
126 * No assurances are provided by Nokia that the Contribution does not
127 * infringe the patent or other intellectual property rights of any third
128 * party or that the license provides you with all the necessary rights
129 * to make use of the Contribution.
130 *
131 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
132 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
133 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
134 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
135 * OTHERWISE.
136 */
137
138#include <openssl/lhash.h>
139
140#ifndef OPENSSL_NO_ENGINE
141#include <openssl/engine.h>
142#endif
143
144#include "ssl_locl.h"
145
146static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
147static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s);
148static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
149
150/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
151SSL_SESSION *
152SSL_get_session(const SSL *ssl)
153{
154 return (ssl->session);
155}
156
157/* variant of SSL_get_session: caller really gets something */
158SSL_SESSION *
159SSL_get1_session(SSL *ssl)
160{
161 SSL_SESSION *sess;
162
163 /*
164 * Need to lock this all up rather than just use CRYPTO_add so that
165 * somebody doesn't free ssl->session between when we check it's
166 * non-null and when we up the reference count.
167 */
168 CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION);
169 sess = ssl->session;
170 if (sess)
171 sess->references++;
172 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION);
173
174 return (sess);
175}
176
177int
178SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
179 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
180{
181 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION,
182 argl, argp, new_func, dup_func, free_func);
183}
184
185int
186SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
187{
188 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
189}
190
191void *
192SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
193{
194 return (CRYPTO_get_ex_data(&s->ex_data, idx));
195}
196
197SSL_SESSION *
198SSL_SESSION_new(void)
199{
200 SSL_SESSION *ss;
201
202 ss = calloc(1, sizeof(SSL_SESSION));
203 if (ss == NULL) {
204 SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE);
205 return (0);
206 }
207
208 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
209 ss->references = 1;
210 ss->timeout=60*5+4; /* 5 minute timeout by default */
211 ss->time = time(NULL);
212 ss->prev = NULL;
213 ss->next = NULL;
214 ss->tlsext_hostname = NULL;
215
216 ss->tlsext_ecpointformatlist_length = 0;
217 ss->tlsext_ecpointformatlist = NULL;
218 ss->tlsext_ellipticcurvelist_length = 0;
219 ss->tlsext_ellipticcurvelist = NULL;
220
221 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
222
223 return (ss);
224}
225
226const unsigned char *
227SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
228{
229 if (len)
230 *len = s->session_id_length;
231 return s->session_id;
232}
233
234unsigned int
235SSL_SESSION_get_compress_id(const SSL_SESSION *s)
236{
237 return 0;
238}
239
240/*
241 * SSLv3/TLSv1 has 32 bytes (256 bits) of session ID space. As such, filling
242 * the ID with random gunk repeatedly until we have no conflict is going to
243 * complete in one iteration pretty much "most" of the time (btw:
244 * understatement). So, if it takes us 10 iterations and we still can't avoid
245 * a conflict - well that's a reasonable point to call it quits. Either the
246 * arc4random code is broken or someone is trying to open roughly very close to
247 * 2^128 (or 2^256) SSL sessions to our server. How you might store that many
248 * sessions is perhaps a more interesting question...
249 */
250
251#define MAX_SESS_ID_ATTEMPTS 10
252
253static int
254def_generate_session_id(const SSL *ssl, unsigned char *id, unsigned int *id_len)
255{
256 unsigned int retry = 0;
257
258 do {
259 arc4random_buf(id, *id_len);
260 } while (SSL_has_matching_session_id(ssl, id, *id_len) &&
261 (++retry < MAX_SESS_ID_ATTEMPTS));
262
263 if (retry < MAX_SESS_ID_ATTEMPTS)
264 return 1;
265
266 /* else - woops a session_id match */
267 /* XXX We should also check the external cache --
268 * but the probability of a collision is negligible, and
269 * we could not prevent the concurrent creation of sessions
270 * with identical IDs since we currently don't have means
271 * to atomically check whether a session ID already exists
272 * and make a reservation for it if it does not
273 * (this problem applies to the internal cache as well).
274 */
275 return 0;
276}
277
278int
279ssl_get_new_session(SSL *s, int session)
280{
281 unsigned int tmp;
282 SSL_SESSION *ss = NULL;
283 GEN_SESSION_CB cb = def_generate_session_id;
284
285 /* This gets used by clients and servers. */
286
287 if ((ss = SSL_SESSION_new()) == NULL)
288 return (0);
289
290 /* If the context has a default timeout, use it */
291 if (s->session_ctx->session_timeout == 0)
292 ss->timeout = SSL_get_default_timeout(s);
293 else
294 ss->timeout = s->session_ctx->session_timeout;
295
296 if (s->session != NULL) {
297 SSL_SESSION_free(s->session);
298 s->session = NULL;
299 }
300
301 if (session) {
302 switch (s->version) {
303 case TLS1_VERSION:
304 case TLS1_1_VERSION:
305 case TLS1_2_VERSION:
306 case DTLS1_VERSION:
307 ss->ssl_version = s->version;
308 ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
309 break;
310 default:
311 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
312 SSL_R_UNSUPPORTED_SSL_VERSION);
313 SSL_SESSION_free(ss);
314 return (0);
315 }
316
317 /* If RFC4507 ticket use empty session ID. */
318 if (s->tlsext_ticket_expected) {
319 ss->session_id_length = 0;
320 goto sess_id_done;
321 }
322
323 /* Choose which callback will set the session ID. */
324 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
325 if (s->generate_session_id)
326 cb = s->generate_session_id;
327 else if (s->session_ctx->generate_session_id)
328 cb = s->session_ctx->generate_session_id;
329 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
330
331 /* Choose a session ID. */
332 tmp = ss->session_id_length;
333 if (!cb(s, ss->session_id, &tmp)) {
334 /* The callback failed */
335 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
336 SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
337 SSL_SESSION_free(ss);
338 return (0);
339 }
340
341 /*
342 * Don't allow the callback to set the session length to zero.
343 * nor set it higher than it was.
344 */
345 if (!tmp || (tmp > ss->session_id_length)) {
346 /* The callback set an illegal length */
347 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
348 SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
349 SSL_SESSION_free(ss);
350 return (0);
351 }
352 ss->session_id_length = tmp;
353
354 /* Finally, check for a conflict. */
355 if (SSL_has_matching_session_id(s, ss->session_id,
356 ss->session_id_length)) {
357 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
358 SSL_R_SSL_SESSION_ID_CONFLICT);
359 SSL_SESSION_free(ss);
360 return (0);
361 }
362
363sess_id_done:
364 if (s->tlsext_hostname) {
365 ss->tlsext_hostname = strdup(s->tlsext_hostname);
366 if (ss->tlsext_hostname == NULL) {
367 SSLerr(SSL_F_SSL_GET_NEW_SESSION,
368 ERR_R_INTERNAL_ERROR);
369 SSL_SESSION_free(ss);
370 return 0;
371 }
372 }
373 } else {
374 ss->session_id_length = 0;
375 }
376
377 if (s->sid_ctx_length > sizeof ss->sid_ctx) {
378 SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR);
379 SSL_SESSION_free(ss);
380 return 0;
381 }
382
383 memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length);
384 ss->sid_ctx_length = s->sid_ctx_length;
385 s->session = ss;
386 ss->ssl_version = s->version;
387 ss->verify_result = X509_V_OK;
388
389 return (1);
390}
391
392/*
393 * ssl_get_prev attempts to find an SSL_SESSION to be used to resume this
394 * connection. It is only called by servers.
395 *
396 * session_id: points at the session ID in the ClientHello. This code will
397 * read past the end of this in order to parse out the session ticket
398 * extension, if any.
399 * len: the length of the session ID.
400 * limit: a pointer to the first byte after the ClientHello.
401 *
402 * Returns:
403 * -1: error
404 * 0: a session may have been found.
405 *
406 * Side effects:
407 * - If a session is found then s->session is pointed at it (after freeing
408 * an existing session if need be) and s->verify_result is set from the
409 * session.
410 * - Both for new and resumed sessions, s->tlsext_ticket_expected is set
411 * to 1 if the server should issue a new session ticket (to 0 otherwise).
412 */
413int
414ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
415 const unsigned char *limit)
416{
417 SSL_SESSION *ret = NULL;
418 int fatal = 0;
419 int try_session_cache = 1;
420 int r;
421
422 /* This is used only by servers. */
423
424 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
425 goto err;
426
427 if (len == 0)
428 try_session_cache = 0;
429
430 /* Sets s->tlsext_ticket_expected. */
431 r = tls1_process_ticket(s, session_id, len, limit, &ret);
432 switch (r) {
433 case -1: /* Error during processing */
434 fatal = 1;
435 goto err;
436 case 0: /* No ticket found */
437 case 1: /* Zero length ticket found */
438 break; /* Ok to carry on processing session id. */
439 case 2: /* Ticket found but not decrypted. */
440 case 3: /* Ticket decrypted, *ret has been set. */
441 try_session_cache = 0;
442 break;
443 default:
444 abort();
445 }
446
447 if (try_session_cache && ret == NULL &&
448 !(s->session_ctx->session_cache_mode &
449 SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) {
450 SSL_SESSION data;
451 data.ssl_version = s->version;
452 data.session_id_length = len;
453 memcpy(data.session_id, session_id, len);
454
455 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
456 ret = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data);
457 if (ret != NULL) {
458 /* Don't allow other threads to steal it. */
459 CRYPTO_add(&ret->references, 1,
460 CRYPTO_LOCK_SSL_SESSION);
461 }
462 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
463
464 if (ret == NULL)
465 s->session_ctx->stats.sess_miss++;
466 }
467
468 if (try_session_cache && ret == NULL &&
469 s->session_ctx->get_session_cb != NULL) {
470 int copy = 1;
471
472 if ((ret = s->session_ctx->get_session_cb(s, session_id,
473 len, &copy))) {
474 s->session_ctx->stats.sess_cb_hit++;
475
476 /*
477 * Increment reference count now if the session
478 * callback asks us to do so (note that if the session
479 * structures returned by the callback are shared
480 * between threads, it must handle the reference count
481 * itself [i.e. copy == 0], or things won't be
482 * thread-safe).
483 */
484 if (copy)
485 CRYPTO_add(&ret->references, 1,
486 CRYPTO_LOCK_SSL_SESSION);
487
488 /*
489 * Add the externally cached session to the internal
490 * cache as well if and only if we are supposed to.
491 */
492 if (!(s->session_ctx->session_cache_mode &
493 SSL_SESS_CACHE_NO_INTERNAL_STORE))
494 /*
495 * The following should not return 1,
496 * otherwise, things are very strange.
497 */
498 SSL_CTX_add_session(s->session_ctx, ret);
499 }
500 }
501
502 if (ret == NULL)
503 goto err;
504
505 /* Now ret is non-NULL and we own one of its reference counts. */
506
507 if (ret->sid_ctx_length != s->sid_ctx_length ||
508 timingsafe_memcmp(ret->sid_ctx,
509 s->sid_ctx, ret->sid_ctx_length) != 0) {
510 /* We have the session requested by the client, but we don't
511 * want to use it in this context. */
512 goto err; /* treat like cache miss */
513 }
514
515 if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) {
516 /*
517 * We can't be sure if this session is being used out of
518 * context, which is especially important for SSL_VERIFY_PEER.
519 * The application should have used
520 * SSL[_CTX]_set_session_id_context.
521 *
522 * For this error case, we generate an error instead of treating
523 * the event like a cache miss (otherwise it would be easy for
524 * applications to effectively disable the session cache by
525 * accident without anyone noticing).
526 */
527 SSLerr(SSL_F_SSL_GET_PREV_SESSION,
528 SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
529 fatal = 1;
530 goto err;
531 }
532
533 if (ret->cipher == NULL) {
534 ret->cipher = ssl3_get_cipher_by_id(ret->cipher_id);
535 if (ret->cipher == NULL)
536 goto err;
537 }
538
539 if (ret->timeout < (time(NULL) - ret->time)) {
540 /* timeout */
541 s->session_ctx->stats.sess_timeout++;
542 if (try_session_cache) {
543 /* session was from the cache, so remove it */
544 SSL_CTX_remove_session(s->session_ctx, ret);
545 }
546 goto err;
547 }
548
549 s->session_ctx->stats.sess_hit++;
550
551 if (s->session != NULL)
552 SSL_SESSION_free(s->session);
553 s->session = ret;
554 s->verify_result = s->session->verify_result;
555 return 1;
556
557err:
558 if (ret != NULL) {
559 SSL_SESSION_free(ret);
560 if (!try_session_cache) {
561 /*
562 * The session was from a ticket, so we should
563 * issue a ticket for the new session.
564 */
565 s->tlsext_ticket_expected = 1;
566 }
567 }
568 if (fatal)
569 return -1;
570 else
571 return 0;
572}
573
574int
575SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
576{
577 int ret = 0;
578 SSL_SESSION *s;
579
580 /*
581 * Add just 1 reference count for the SSL_CTX's session cache
582 * even though it has two ways of access: each session is in a
583 * doubly linked list and an lhash.
584 */
585 CRYPTO_add(&c->references, 1, CRYPTO_LOCK_SSL_SESSION);
586
587 /*
588 * If session c is in already in cache, we take back the increment
589 * later.
590 */
591 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
592 s = lh_SSL_SESSION_insert(ctx->sessions, c);
593
594 /*
595 * s != NULL iff we already had a session with the given PID.
596 * In this case, s == c should hold (then we did not really modify
597 * ctx->sessions), or we're in trouble.
598 */
599 if (s != NULL && s != c) {
600 /* We *are* in trouble ... */
601 SSL_SESSION_list_remove(ctx, s);
602 SSL_SESSION_free(s);
603 /*
604 * ... so pretend the other session did not exist in cache
605 * (we cannot handle two SSL_SESSION structures with identical
606 * session ID in the same cache, which could happen e.g. when
607 * two threads concurrently obtain the same session from an
608 * external cache).
609 */
610 s = NULL;
611 }
612
613 /* Put at the head of the queue unless it is already in the cache */
614 if (s == NULL)
615 SSL_SESSION_list_add(ctx, c);
616
617 if (s != NULL) {
618 /*
619 * existing cache entry -- decrement previously incremented
620 * reference count because it already takes into account the
621 * cache.
622 */
623 SSL_SESSION_free(s); /* s == c */
624 ret = 0;
625 } else {
626 /*
627 * New cache entry -- remove old ones if cache has become
628 * too large.
629 */
630
631 ret = 1;
632
633 if (SSL_CTX_sess_get_cache_size(ctx) > 0) {
634 while (SSL_CTX_sess_number(ctx) >
635 SSL_CTX_sess_get_cache_size(ctx)) {
636 if (!remove_session_lock(ctx,
637 ctx->session_cache_tail, 0))
638 break;
639 else
640 ctx->stats.sess_cache_full++;
641 }
642 }
643 }
644 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
645 return (ret);
646}
647
648int
649SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
650{
651 return remove_session_lock(ctx, c, 1);
652}
653
654static int
655remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
656{
657 SSL_SESSION *r;
658 int ret = 0;
659
660 if ((c != NULL) && (c->session_id_length != 0)) {
661 if (lck)
662 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
663 if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
664 ret = 1;
665 r = lh_SSL_SESSION_delete(ctx->sessions, c);
666 SSL_SESSION_list_remove(ctx, c);
667 }
668 if (lck)
669 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
670
671 if (ret) {
672 r->not_resumable = 1;
673 if (ctx->remove_session_cb != NULL)
674 ctx->remove_session_cb(ctx, r);
675 SSL_SESSION_free(r);
676 }
677 } else
678 ret = 0;
679 return (ret);
680}
681
682void
683SSL_SESSION_free(SSL_SESSION *ss)
684{
685 int i;
686
687 if (ss == NULL)
688 return;
689
690 i = CRYPTO_add(&ss->references, -1, CRYPTO_LOCK_SSL_SESSION);
691 if (i > 0)
692 return;
693
694 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
695
696 explicit_bzero(ss->master_key, sizeof ss->master_key);
697 explicit_bzero(ss->session_id, sizeof ss->session_id);
698 if (ss->sess_cert != NULL)
699 ssl_sess_cert_free(ss->sess_cert);
700 X509_free(ss->peer);
701 if (ss->ciphers != NULL)
702 sk_SSL_CIPHER_free(ss->ciphers);
703 free(ss->tlsext_hostname);
704 free(ss->tlsext_tick);
705 ss->tlsext_ecpointformatlist_length = 0;
706 free(ss->tlsext_ecpointformatlist);
707 ss->tlsext_ellipticcurvelist_length = 0;
708 free(ss->tlsext_ellipticcurvelist);
709 explicit_bzero(ss, sizeof(*ss));
710 free(ss);
711}
712
713int
714SSL_set_session(SSL *s, SSL_SESSION *session)
715{
716 int ret = 0;
717 const SSL_METHOD *meth;
718
719 if (session != NULL) {
720 meth = s->ctx->method->get_ssl_method(session->ssl_version);
721 if (meth == NULL)
722 meth = s->method->get_ssl_method(session->ssl_version);
723 if (meth == NULL) {
724 SSLerr(SSL_F_SSL_SET_SESSION,
725 SSL_R_UNABLE_TO_FIND_SSL_METHOD);
726 return (0);
727 }
728
729 if (meth != s->method) {
730 if (!SSL_set_ssl_method(s, meth))
731 return (0);
732 }
733
734
735 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
736 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION);
737 if (s->session != NULL)
738 SSL_SESSION_free(s->session);
739 s->session = session;
740 s->verify_result = s->session->verify_result;
741 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
742 ret = 1;
743 } else {
744 if (s->session != NULL) {
745 SSL_SESSION_free(s->session);
746 s->session = NULL;
747 }
748
749 meth = s->ctx->method;
750 if (meth != s->method) {
751 if (!SSL_set_ssl_method(s, meth))
752 return (0);
753 }
754 ret = 1;
755 }
756 return (ret);
757}
758
759long
760SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
761{
762 if (s == NULL)
763 return (0);
764 s->timeout = t;
765 return (1);
766}
767
768long
769SSL_SESSION_get_timeout(const SSL_SESSION *s)
770{
771 if (s == NULL)
772 return (0);
773 return (s->timeout);
774}
775
776/* XXX 2038 */
777long
778SSL_SESSION_get_time(const SSL_SESSION *s)
779{
780 if (s == NULL)
781 return (0);
782 return (s->time);
783}
784
785/* XXX 2038 */
786long
787SSL_SESSION_set_time(SSL_SESSION *s, long t)
788{
789 if (s == NULL)
790 return (0);
791 s->time = t;
792 return (t);
793}
794
795X509 *
796SSL_SESSION_get0_peer(SSL_SESSION *s)
797{
798 return s->peer;
799}
800
801int
802SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
803 unsigned int sid_ctx_len)
804{
805 if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
806 SSLerr(SSL_F_SSL_SESSION_SET1_ID_CONTEXT,
807 SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
808 return 0;
809 }
810 s->sid_ctx_length = sid_ctx_len;
811 memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
812
813 return 1;
814}
815
816long
817SSL_CTX_set_timeout(SSL_CTX *s, long t)
818{
819 long l;
820
821 if (s == NULL)
822 return (0);
823 l = s->session_timeout;
824 s->session_timeout = t;
825
826 return (l);
827}
828
829long
830SSL_CTX_get_timeout(const SSL_CTX *s)
831{
832 if (s == NULL)
833 return (0);
834 return (s->session_timeout);
835}
836
837int
838SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s,
839 void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers,
840 SSL_CIPHER **cipher, void *arg), void *arg)
841{
842 if (s == NULL)
843 return (0);
844 s->tls_session_secret_cb = tls_session_secret_cb;
845 s->tls_session_secret_cb_arg = arg;
846 return (1);
847}
848
849int
850SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
851 void *arg)
852{
853 if (s == NULL)
854 return (0);
855 s->tls_session_ticket_ext_cb = cb;
856 s->tls_session_ticket_ext_cb_arg = arg;
857 return (1);
858}
859
860int
861SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
862{
863 if (s->version >= TLS1_VERSION) {
864 free(s->tlsext_session_ticket);
865 s->tlsext_session_ticket =
866 malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
867 if (!s->tlsext_session_ticket) {
868 SSLerr(SSL_F_SSL_SET_SESSION_TICKET_EXT,
869 ERR_R_MALLOC_FAILURE);
870 return 0;
871 }
872
873 if (ext_data) {
874 s->tlsext_session_ticket->length = ext_len;
875 s->tlsext_session_ticket->data =
876 s->tlsext_session_ticket + 1;
877 memcpy(s->tlsext_session_ticket->data,
878 ext_data, ext_len);
879 } else {
880 s->tlsext_session_ticket->length = 0;
881 s->tlsext_session_ticket->data = NULL;
882 }
883
884 return 1;
885 }
886
887 return 0;
888}
889
890typedef struct timeout_param_st {
891 SSL_CTX *ctx;
892 long time;
893 LHASH_OF(SSL_SESSION) *cache;
894} TIMEOUT_PARAM;
895
896static void
897timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p)
898{
899 if ((p->time == 0) || (p->time > (s->time + s->timeout))) {
900 /* timeout */
901 /* The reason we don't call SSL_CTX_remove_session() is to
902 * save on locking overhead */
903 (void)lh_SSL_SESSION_delete(p->cache, s);
904 SSL_SESSION_list_remove(p->ctx, s);
905 s->not_resumable = 1;
906 if (p->ctx->remove_session_cb != NULL)
907 p->ctx->remove_session_cb(p->ctx, s);
908 SSL_SESSION_free(s);
909 }
910}
911
912static
913IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION, TIMEOUT_PARAM)
914
915/* XXX 2038 */
916void
917SSL_CTX_flush_sessions(SSL_CTX *s, long t)
918{
919 unsigned long i;
920 TIMEOUT_PARAM tp;
921
922 tp.ctx = s;
923 tp.cache = s->sessions;
924 if (tp.cache == NULL)
925 return;
926 tp.time = t;
927 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
928 i = CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;
929 CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = 0;
930 lh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),
931 TIMEOUT_PARAM, &tp);
932 CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = i;
933 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
934}
935
936int
937ssl_clear_bad_session(SSL *s)
938{
939 if ((s->session != NULL) && !(s->shutdown & SSL_SENT_SHUTDOWN) &&
940 !(SSL_in_init(s) || SSL_in_before(s))) {
941 SSL_CTX_remove_session(s->ctx, s->session);
942 return (1);
943 } else
944 return (0);
945}
946
947/* locked by SSL_CTX in the calling function */
948static void
949SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
950{
951 if ((s->next == NULL) || (s->prev == NULL))
952 return;
953
954 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) {
955 /* last element in list */
956 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
957 /* only one element in list */
958 ctx->session_cache_head = NULL;
959 ctx->session_cache_tail = NULL;
960 } else {
961 ctx->session_cache_tail = s->prev;
962 s->prev->next =
963 (SSL_SESSION *)&(ctx->session_cache_tail);
964 }
965 } else {
966 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
967 /* first element in list */
968 ctx->session_cache_head = s->next;
969 s->next->prev =
970 (SSL_SESSION *)&(ctx->session_cache_head);
971 } else {
972 /* middle of list */
973 s->next->prev = s->prev;
974 s->prev->next = s->next;
975 }
976 }
977 s->prev = s->next = NULL;
978}
979
980static void
981SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
982{
983 if ((s->next != NULL) && (s->prev != NULL))
984 SSL_SESSION_list_remove(ctx, s);
985
986 if (ctx->session_cache_head == NULL) {
987 ctx->session_cache_head = s;
988 ctx->session_cache_tail = s;
989 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
990 s->next = (SSL_SESSION *)&(ctx->session_cache_tail);
991 } else {
992 s->next = ctx->session_cache_head;
993 s->next->prev = s;
994 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
995 ctx->session_cache_head = s;
996 }
997}
998
999void
1000SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
1001 int (*cb)(struct ssl_st *ssl, SSL_SESSION *sess)) {
1002 ctx->new_session_cb = cb;
1003}
1004
1005int
1006(*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *sess)
1007{
1008 return ctx->new_session_cb;
1009}
1010
1011void
1012SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
1013 void (*cb)(SSL_CTX *ctx, SSL_SESSION *sess))
1014{
1015 ctx->remove_session_cb = cb;
1016}
1017
1018void
1019(*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(SSL_CTX * ctx, SSL_SESSION *sess)
1020{
1021 return ctx->remove_session_cb;
1022}
1023
1024void
1025SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, SSL_SESSION *(*cb)(struct ssl_st *ssl,
1026 unsigned char *data, int len, int *copy))
1027{
1028 ctx->get_session_cb = cb;
1029}
1030
1031SSL_SESSION *
1032(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl, unsigned char *data,
1033 int len, int *copy)
1034{
1035 return ctx->get_session_cb;
1036}
1037
1038void
1039SSL_CTX_set_info_callback(SSL_CTX *ctx,
1040 void (*cb)(const SSL *ssl, int type, int val))
1041{
1042 ctx->info_callback = cb;
1043}
1044
1045void
1046(*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl, int type, int val)
1047{
1048 return ctx->info_callback;
1049}
1050
1051void
1052SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
1053 int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey))
1054{
1055 ctx->client_cert_cb = cb;
1056}
1057
1058int
1059(*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL * ssl, X509 ** x509,
1060 EVP_PKEY **pkey)
1061{
1062 return ctx->client_cert_cb;
1063}
1064
1065#ifndef OPENSSL_NO_ENGINE
1066int
1067SSL_CTX_set_client_cert_engine(SSL_CTX *ctx, ENGINE *e)
1068{
1069 if (!ENGINE_init(e)) {
1070 SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE,
1071 ERR_R_ENGINE_LIB);
1072 return 0;
1073 }
1074 if (!ENGINE_get_ssl_client_cert_function(e)) {
1075 SSLerr(SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE,
1076 SSL_R_NO_CLIENT_CERT_METHOD);
1077 ENGINE_finish(e);
1078 return 0;
1079 }
1080 ctx->client_cert_engine = e;
1081 return 1;
1082}
1083#endif
1084
1085void
1086SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
1087 int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len))
1088{
1089 ctx->app_gen_cookie_cb = cb;
1090}
1091
1092void
1093SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
1094 int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int cookie_len))
1095{
1096 ctx->app_verify_cookie_cb = cb;
1097}
1098
1099IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index 6d67d19c25..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,801 +0,0 @@
1/* $OpenBSD: ssl_stat.c,v 1.12 2014/11/16 14:12:47 jsing Exp $ */
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 2005 Nokia. All rights reserved.
60 *
61 * The portions of the attached software ("Contribution") is developed by
62 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63 * license.
64 *
65 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67 * support (see RFC 4279) to OpenSSL.
68 *
69 * No patent licenses or other rights except those expressly stated in
70 * the OpenSSL open source license shall be deemed granted or received
71 * expressly, by implication, estoppel, or otherwise.
72 *
73 * No assurances are provided by Nokia that the Contribution does not
74 * infringe the patent or other intellectual property rights of any third
75 * party or that the license provides you with all the necessary rights
76 * to make use of the Contribution.
77 *
78 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82 * OTHERWISE.
83 */
84
85#include <stdio.h>
86
87#include "ssl_locl.h"
88
89const char *
90SSL_state_string_long(const SSL *s)
91{
92 const char *str;
93
94 switch (s->state) {
95 case SSL_ST_BEFORE:
96 str = "before SSL initialization";
97 break;
98 case SSL_ST_ACCEPT:
99 str = "before accept initialization";
100 break;
101 case SSL_ST_CONNECT:
102 str = "before connect initialization";
103 break;
104 case SSL_ST_OK:
105 str = "SSL negotiation finished successfully";
106 break;
107 case SSL_ST_RENEGOTIATE:
108 str = "SSL renegotiate ciphers";
109 break;
110 case SSL_ST_BEFORE|SSL_ST_CONNECT:
111 str = "before/connect initialization";
112 break;
113 case SSL_ST_OK|SSL_ST_CONNECT:
114 str = "ok/connect SSL initialization";
115 break;
116 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
117 str = "before/accept initialization";
118 break;
119 case SSL_ST_OK|SSL_ST_ACCEPT:
120 str = "ok/accept SSL initialization";
121 break;
122
123 /* SSLv3 additions */
124 case SSL3_ST_CW_CLNT_HELLO_A:
125 str = "SSLv3 write client hello A";
126 break;
127 case SSL3_ST_CW_CLNT_HELLO_B:
128 str = "SSLv3 write client hello B";
129 break;
130 case SSL3_ST_CR_SRVR_HELLO_A:
131 str = "SSLv3 read server hello A";
132 break;
133 case SSL3_ST_CR_SRVR_HELLO_B:
134 str = "SSLv3 read server hello B";
135 break;
136 case SSL3_ST_CR_CERT_A:
137 str = "SSLv3 read server certificate A";
138 break;
139 case SSL3_ST_CR_CERT_B:
140 str = "SSLv3 read server certificate B";
141 break;
142 case SSL3_ST_CR_KEY_EXCH_A:
143 str = "SSLv3 read server key exchange A";
144 break;
145 case SSL3_ST_CR_KEY_EXCH_B:
146 str = "SSLv3 read server key exchange B";
147 break;
148 case SSL3_ST_CR_CERT_REQ_A:
149 str = "SSLv3 read server certificate request A";
150 break;
151 case SSL3_ST_CR_CERT_REQ_B:
152 str = "SSLv3 read server certificate request B";
153 break;
154 case SSL3_ST_CR_SESSION_TICKET_A:
155 str = "SSLv3 read server session ticket A";
156 break;
157 case SSL3_ST_CR_SESSION_TICKET_B:
158 str = "SSLv3 read server session ticket B";
159 break;
160 case SSL3_ST_CR_SRVR_DONE_A:
161 str = "SSLv3 read server done A";
162 break;
163 case SSL3_ST_CR_SRVR_DONE_B:
164 str = "SSLv3 read server done B";
165 break;
166 case SSL3_ST_CW_CERT_A:
167 str = "SSLv3 write client certificate A";
168 break;
169 case SSL3_ST_CW_CERT_B:
170 str = "SSLv3 write client certificate B";
171 break;
172 case SSL3_ST_CW_CERT_C:
173 str = "SSLv3 write client certificate C";
174 break;
175 case SSL3_ST_CW_CERT_D:
176 str = "SSLv3 write client certificate D";
177 break;
178 case SSL3_ST_CW_KEY_EXCH_A:
179 str = "SSLv3 write client key exchange A";
180 break;
181 case SSL3_ST_CW_KEY_EXCH_B:
182 str = "SSLv3 write client key exchange B";
183 break;
184 case SSL3_ST_CW_CERT_VRFY_A:
185 str = "SSLv3 write certificate verify A";
186 break;
187 case SSL3_ST_CW_CERT_VRFY_B:
188 str = "SSLv3 write certificate verify B";
189 break;
190
191 case SSL3_ST_CW_CHANGE_A:
192 case SSL3_ST_SW_CHANGE_A:
193 str = "SSLv3 write change cipher spec A";
194 break;
195 case SSL3_ST_CW_CHANGE_B:
196 case SSL3_ST_SW_CHANGE_B:
197 str = "SSLv3 write change cipher spec B";
198 break;
199 case SSL3_ST_CW_FINISHED_A:
200 case SSL3_ST_SW_FINISHED_A:
201 str = "SSLv3 write finished A";
202 break;
203 case SSL3_ST_CW_FINISHED_B:
204 case SSL3_ST_SW_FINISHED_B:
205 str = "SSLv3 write finished B";
206 break;
207 case SSL3_ST_CR_CHANGE_A:
208 case SSL3_ST_SR_CHANGE_A:
209 str = "SSLv3 read change cipher spec A";
210 break;
211 case SSL3_ST_CR_CHANGE_B:
212 case SSL3_ST_SR_CHANGE_B:
213 str = "SSLv3 read change cipher spec B";
214 break;
215 case SSL3_ST_CR_FINISHED_A:
216 case SSL3_ST_SR_FINISHED_A:
217 str = "SSLv3 read finished A";
218 break;
219 case SSL3_ST_CR_FINISHED_B:
220 case SSL3_ST_SR_FINISHED_B:
221 str = "SSLv3 read finished B";
222 break;
223
224 case SSL3_ST_CW_FLUSH:
225 case SSL3_ST_SW_FLUSH:
226 str = "SSLv3 flush data";
227 break;
228
229 case SSL3_ST_SR_CLNT_HELLO_A:
230 str = "SSLv3 read client hello A";
231 break;
232 case SSL3_ST_SR_CLNT_HELLO_B:
233 str = "SSLv3 read client hello B";
234 break;
235 case SSL3_ST_SR_CLNT_HELLO_C:
236 str = "SSLv3 read client hello C";
237 break;
238 case SSL3_ST_SW_HELLO_REQ_A:
239 str = "SSLv3 write hello request A";
240 break;
241 case SSL3_ST_SW_HELLO_REQ_B:
242 str = "SSLv3 write hello request B";
243 break;
244 case SSL3_ST_SW_HELLO_REQ_C:
245 str = "SSLv3 write hello request C";
246 break;
247 case SSL3_ST_SW_SRVR_HELLO_A:
248 str = "SSLv3 write server hello A";
249 break;
250 case SSL3_ST_SW_SRVR_HELLO_B:
251 str = "SSLv3 write server hello B";
252 break;
253 case SSL3_ST_SW_CERT_A:
254 str = "SSLv3 write certificate A";
255 break;
256 case SSL3_ST_SW_CERT_B:
257 str = "SSLv3 write certificate B";
258 break;
259 case SSL3_ST_SW_KEY_EXCH_A:
260 str = "SSLv3 write key exchange A";
261 break;
262 case SSL3_ST_SW_KEY_EXCH_B:
263 str = "SSLv3 write key exchange B";
264 break;
265 case SSL3_ST_SW_CERT_REQ_A:
266 str = "SSLv3 write certificate request A";
267 break;
268 case SSL3_ST_SW_CERT_REQ_B:
269 str = "SSLv3 write certificate request B";
270 break;
271 case SSL3_ST_SW_SESSION_TICKET_A:
272 str = "SSLv3 write session ticket A";
273 break;
274 case SSL3_ST_SW_SESSION_TICKET_B:
275 str = "SSLv3 write session ticket B";
276 break;
277 case SSL3_ST_SW_SRVR_DONE_A:
278 str = "SSLv3 write server done A";
279 break;
280 case SSL3_ST_SW_SRVR_DONE_B:
281 str = "SSLv3 write server done B";
282 break;
283 case SSL3_ST_SR_CERT_A:
284 str = "SSLv3 read client certificate A";
285 break;
286 case SSL3_ST_SR_CERT_B:
287 str = "SSLv3 read client certificate B";
288 break;
289 case SSL3_ST_SR_KEY_EXCH_A:
290 str = "SSLv3 read client key exchange A";
291 break;
292 case SSL3_ST_SR_KEY_EXCH_B:
293 str = "SSLv3 read client key exchange B";
294 break;
295 case SSL3_ST_SR_CERT_VRFY_A:
296 str = "SSLv3 read certificate verify A";
297 break;
298 case SSL3_ST_SR_CERT_VRFY_B:
299 str = "SSLv3 read certificate verify B";
300 break;
301
302 /* DTLS */
303 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
304 str = "DTLS1 read hello verify request A";
305 break;
306 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
307 str = "DTLS1 read hello verify request B";
308 break;
309 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
310 str = "DTLS1 write hello verify request A";
311 break;
312 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
313 str = "DTLS1 write hello verify request B";
314 break;
315
316 default:
317 str = "unknown state";
318 break;
319 }
320 return (str);
321}
322
323const char *
324SSL_rstate_string_long(const SSL *s)
325{
326 const char *str;
327
328 switch (s->rstate) {
329 case SSL_ST_READ_HEADER:
330 str = "read header";
331 break;
332 case SSL_ST_READ_BODY:
333 str = "read body";
334 break;
335 case SSL_ST_READ_DONE:
336 str = "read done";
337 break;
338 default:
339 str = "unknown";
340 break;
341 }
342 return (str);
343}
344
345const char *
346SSL_state_string(const SSL *s)
347{
348 const char *str;
349
350 switch (s->state) {
351 case SSL_ST_BEFORE:
352 str = "PINIT ";
353 break;
354 case SSL_ST_ACCEPT:
355 str = "AINIT ";
356 break;
357 case SSL_ST_CONNECT:
358 str = "CINIT ";
359 break;
360 case SSL_ST_OK:
361 str = "SSLOK ";
362 break;
363
364 /* SSLv3 additions */
365 case SSL3_ST_SW_FLUSH:
366 case SSL3_ST_CW_FLUSH:
367 str = "3FLUSH";
368 break;
369 case SSL3_ST_CW_CLNT_HELLO_A:
370 str = "3WCH_A";
371 break;
372 case SSL3_ST_CW_CLNT_HELLO_B:
373 str = "3WCH_B";
374 break;
375 case SSL3_ST_CR_SRVR_HELLO_A:
376 str = "3RSH_A";
377 break;
378 case SSL3_ST_CR_SRVR_HELLO_B:
379 str = "3RSH_B";
380 break;
381 case SSL3_ST_CR_CERT_A:
382 str = "3RSC_A";
383 break;
384 case SSL3_ST_CR_CERT_B:
385 str = "3RSC_B";
386 break;
387 case SSL3_ST_CR_KEY_EXCH_A:
388 str = "3RSKEA";
389 break;
390 case SSL3_ST_CR_KEY_EXCH_B:
391 str = "3RSKEB";
392 break;
393 case SSL3_ST_CR_CERT_REQ_A:
394 str = "3RCR_A";
395 break;
396 case SSL3_ST_CR_CERT_REQ_B:
397 str = "3RCR_B";
398 break;
399 case SSL3_ST_CR_SRVR_DONE_A:
400 str = "3RSD_A";
401 break;
402 case SSL3_ST_CR_SRVR_DONE_B:
403 str = "3RSD_B";
404 break;
405 case SSL3_ST_CW_CERT_A:
406 str = "3WCC_A";
407 break;
408 case SSL3_ST_CW_CERT_B:
409 str = "3WCC_B";
410 break;
411 case SSL3_ST_CW_CERT_C:
412 str = "3WCC_C";
413 break;
414 case SSL3_ST_CW_CERT_D:
415 str = "3WCC_D";
416 break;
417 case SSL3_ST_CW_KEY_EXCH_A:
418 str = "3WCKEA";
419 break;
420 case SSL3_ST_CW_KEY_EXCH_B:
421 str = "3WCKEB";
422 break;
423 case SSL3_ST_CW_CERT_VRFY_A:
424 str = "3WCV_A";
425 break;
426 case SSL3_ST_CW_CERT_VRFY_B:
427 str = "3WCV_B";
428 break;
429
430 case SSL3_ST_SW_CHANGE_A:
431 case SSL3_ST_CW_CHANGE_A:
432 str = "3WCCSA";
433 break;
434 case SSL3_ST_SW_CHANGE_B:
435 case SSL3_ST_CW_CHANGE_B:
436 str = "3WCCSB";
437 break;
438 case SSL3_ST_SW_FINISHED_A:
439 case SSL3_ST_CW_FINISHED_A:
440 str = "3WFINA";
441 break;
442 case SSL3_ST_SW_FINISHED_B:
443 case SSL3_ST_CW_FINISHED_B:
444 str = "3WFINB";
445 break;
446 case SSL3_ST_SR_CHANGE_A:
447 case SSL3_ST_CR_CHANGE_A:
448 str = "3RCCSA";
449 break;
450 case SSL3_ST_SR_CHANGE_B:
451 case SSL3_ST_CR_CHANGE_B:
452 str = "3RCCSB";
453 break;
454 case SSL3_ST_SR_FINISHED_A:
455 case SSL3_ST_CR_FINISHED_A:
456 str = "3RFINA";
457 break;
458 case SSL3_ST_SR_FINISHED_B:
459 case SSL3_ST_CR_FINISHED_B:
460 str = "3RFINB";
461 break;
462
463 case SSL3_ST_SW_HELLO_REQ_A:
464 str = "3WHR_A";
465 break;
466 case SSL3_ST_SW_HELLO_REQ_B:
467 str = "3WHR_B";
468 break;
469 case SSL3_ST_SW_HELLO_REQ_C:
470 str = "3WHR_C";
471 break;
472 case SSL3_ST_SR_CLNT_HELLO_A:
473 str = "3RCH_A";
474 break;
475 case SSL3_ST_SR_CLNT_HELLO_B:
476 str = "3RCH_B";
477 break;
478 case SSL3_ST_SR_CLNT_HELLO_C:
479 str = "3RCH_C";
480 break;
481 case SSL3_ST_SW_SRVR_HELLO_A:
482 str = "3WSH_A";
483 break;
484 case SSL3_ST_SW_SRVR_HELLO_B:
485 str = "3WSH_B";
486 break;
487 case SSL3_ST_SW_CERT_A:
488 str = "3WSC_A";
489 break;
490 case SSL3_ST_SW_CERT_B:
491 str = "3WSC_B";
492 break;
493 case SSL3_ST_SW_KEY_EXCH_A:
494 str = "3WSKEA";
495 break;
496 case SSL3_ST_SW_KEY_EXCH_B:
497 str = "3WSKEB";
498 break;
499 case SSL3_ST_SW_CERT_REQ_A:
500 str = "3WCR_A";
501 break;
502 case SSL3_ST_SW_CERT_REQ_B:
503 str = "3WCR_B";
504 break;
505 case SSL3_ST_SW_SRVR_DONE_A:
506 str = "3WSD_A";
507 break;
508 case SSL3_ST_SW_SRVR_DONE_B:
509 str = "3WSD_B";
510 break;
511 case SSL3_ST_SR_CERT_A:
512 str = "3RCC_A";
513 break;
514 case SSL3_ST_SR_CERT_B:
515 str = "3RCC_B";
516 break;
517 case SSL3_ST_SR_KEY_EXCH_A:
518 str = "3RCKEA";
519 break;
520 case SSL3_ST_SR_KEY_EXCH_B:
521 str = "3RCKEB";
522 break;
523 case SSL3_ST_SR_CERT_VRFY_A:
524 str = "3RCV_A";
525 break;
526 case SSL3_ST_SR_CERT_VRFY_B:
527 str = "3RCV_B";
528 break;
529
530 /* DTLS */
531 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
532 str = "DRCHVA";
533 break;
534 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
535 str = "DRCHVB";
536 break;
537 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
538 str = "DWCHVA";
539 break;
540 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
541 str = "DWCHVB";
542 break;
543
544 default:
545 str = "UNKWN ";
546 break;
547 }
548 return (str);
549}
550
551const char *
552SSL_alert_type_string_long(int value)
553{
554 value >>= 8;
555 if (value == SSL3_AL_WARNING)
556 return ("warning");
557 else if (value == SSL3_AL_FATAL)
558 return ("fatal");
559 else
560 return ("unknown");
561}
562
563const char *
564SSL_alert_type_string(int value)
565{
566 value >>= 8;
567 if (value == SSL3_AL_WARNING)
568 return ("W");
569 else if (value == SSL3_AL_FATAL)
570 return ("F");
571 else
572 return ("U");
573}
574
575const char *
576SSL_alert_desc_string(int value)
577{
578 const char *str;
579
580 switch (value & 0xff) {
581 case SSL3_AD_CLOSE_NOTIFY:
582 str = "CN";
583 break;
584 case SSL3_AD_UNEXPECTED_MESSAGE:
585 str = "UM";
586 break;
587 case SSL3_AD_BAD_RECORD_MAC:
588 str = "BM";
589 break;
590 case SSL3_AD_DECOMPRESSION_FAILURE:
591 str = "DF";
592 break;
593 case SSL3_AD_HANDSHAKE_FAILURE:
594 str = "HF";
595 break;
596 case SSL3_AD_NO_CERTIFICATE:
597 str = "NC";
598 break;
599 case SSL3_AD_BAD_CERTIFICATE:
600 str = "BC";
601 break;
602 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
603 str = "UC";
604 break;
605 case SSL3_AD_CERTIFICATE_REVOKED:
606 str = "CR";
607 break;
608 case SSL3_AD_CERTIFICATE_EXPIRED:
609 str = "CE";
610 break;
611 case SSL3_AD_CERTIFICATE_UNKNOWN:
612 str = "CU";
613 break;
614 case SSL3_AD_ILLEGAL_PARAMETER:
615 str = "IP";
616 break;
617 case TLS1_AD_DECRYPTION_FAILED:
618 str = "DC";
619 break;
620 case TLS1_AD_RECORD_OVERFLOW:
621 str = "RO";
622 break;
623 case TLS1_AD_UNKNOWN_CA:
624 str = "CA";
625 break;
626 case TLS1_AD_ACCESS_DENIED:
627 str = "AD";
628 break;
629 case TLS1_AD_DECODE_ERROR:
630 str = "DE";
631 break;
632 case TLS1_AD_DECRYPT_ERROR:
633 str = "CY";
634 break;
635 case TLS1_AD_EXPORT_RESTRICTION:
636 str = "ER";
637 break;
638 case TLS1_AD_PROTOCOL_VERSION:
639 str = "PV";
640 break;
641 case TLS1_AD_INSUFFICIENT_SECURITY:
642 str = "IS";
643 break;
644 case TLS1_AD_INTERNAL_ERROR:
645 str = "IE";
646 break;
647 case TLS1_AD_USER_CANCELLED:
648 str = "US";
649 break;
650 case TLS1_AD_NO_RENEGOTIATION:
651 str = "NR";
652 break;
653 case TLS1_AD_UNSUPPORTED_EXTENSION:
654 str = "UE";
655 break;
656 case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
657 str = "CO";
658 break;
659 case TLS1_AD_UNRECOGNIZED_NAME:
660 str = "UN";
661 break;
662 case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
663 str = "BR";
664 break;
665 case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
666 str = "BH";
667 break;
668 case TLS1_AD_UNKNOWN_PSK_IDENTITY:
669 str = "UP";
670 break;
671 default:
672 str = "UK";
673 break;
674 }
675 return (str);
676}
677
678const char *
679SSL_alert_desc_string_long(int value)
680{
681 const char *str;
682
683 switch (value & 0xff) {
684 case SSL3_AD_CLOSE_NOTIFY:
685 str = "close notify";
686 break;
687 case SSL3_AD_UNEXPECTED_MESSAGE:
688 str = "unexpected_message";
689 break;
690 case SSL3_AD_BAD_RECORD_MAC:
691 str = "bad record mac";
692 break;
693 case SSL3_AD_DECOMPRESSION_FAILURE:
694 str = "decompression failure";
695 break;
696 case SSL3_AD_HANDSHAKE_FAILURE:
697 str = "handshake failure";
698 break;
699 case SSL3_AD_NO_CERTIFICATE:
700 str = "no certificate";
701 break;
702 case SSL3_AD_BAD_CERTIFICATE:
703 str = "bad certificate";
704 break;
705 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
706 str = "unsupported certificate";
707 break;
708 case SSL3_AD_CERTIFICATE_REVOKED:
709 str = "certificate revoked";
710 break;
711 case SSL3_AD_CERTIFICATE_EXPIRED:
712 str = "certificate expired";
713 break;
714 case SSL3_AD_CERTIFICATE_UNKNOWN:
715 str = "certificate unknown";
716 break;
717 case SSL3_AD_ILLEGAL_PARAMETER:
718 str = "illegal parameter";
719 break;
720 case TLS1_AD_DECRYPTION_FAILED:
721 str = "decryption failed";
722 break;
723 case TLS1_AD_RECORD_OVERFLOW:
724 str = "record overflow";
725 break;
726 case TLS1_AD_UNKNOWN_CA:
727 str = "unknown CA";
728 break;
729 case TLS1_AD_ACCESS_DENIED:
730 str = "access denied";
731 break;
732 case TLS1_AD_DECODE_ERROR:
733 str = "decode error";
734 break;
735 case TLS1_AD_DECRYPT_ERROR:
736 str = "decrypt error";
737 break;
738 case TLS1_AD_EXPORT_RESTRICTION:
739 str = "export restriction";
740 break;
741 case TLS1_AD_PROTOCOL_VERSION:
742 str = "protocol version";
743 break;
744 case TLS1_AD_INSUFFICIENT_SECURITY:
745 str = "insufficient security";
746 break;
747 case TLS1_AD_INTERNAL_ERROR:
748 str = "internal error";
749 break;
750 case TLS1_AD_USER_CANCELLED:
751 str = "user canceled";
752 break;
753 case TLS1_AD_NO_RENEGOTIATION:
754 str = "no renegotiation";
755 break;
756 case TLS1_AD_UNSUPPORTED_EXTENSION:
757 str = "unsupported extension";
758 break;
759 case TLS1_AD_CERTIFICATE_UNOBTAINABLE:
760 str = "certificate unobtainable";
761 break;
762 case TLS1_AD_UNRECOGNIZED_NAME:
763 str = "unrecognized name";
764 break;
765 case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
766 str = "bad certificate status response";
767 break;
768 case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE:
769 str = "bad certificate hash value";
770 break;
771 case TLS1_AD_UNKNOWN_PSK_IDENTITY:
772 str = "unknown PSK identity";
773 break;
774 default:
775 str = "unknown";
776 break;
777 }
778 return (str);
779}
780
781const char *
782SSL_rstate_string(const SSL *s)
783{
784 const char *str;
785
786 switch (s->rstate) {
787 case SSL_ST_READ_HEADER:
788 str = "RH";
789 break;
790 case SSL_ST_READ_BODY:
791 str = "RB";
792 break;
793 case SSL_ST_READ_DONE:
794 str = "RD";
795 break;
796 default:
797 str = "unknown";
798 break;
799 }
800 return (str);
801}
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index c3626dc03a..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/* $OpenBSD: ssl_txt.c,v 1.26 2014/12/14 15:30:50 jsing Exp $ */
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 2005 Nokia. All rights reserved.
60 *
61 * The portions of the attached software ("Contribution") is developed by
62 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63 * license.
64 *
65 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67 * support (see RFC 4279) to OpenSSL.
68 *
69 * No patent licenses or other rights except those expressly stated in
70 * the OpenSSL open source license shall be deemed granted or received
71 * expressly, by implication, estoppel, or otherwise.
72 *
73 * No assurances are provided by Nokia that the Contribution does not
74 * infringe the patent or other intellectual property rights of any third
75 * party or that the license provides you with all the necessary rights
76 * to make use of the Contribution.
77 *
78 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82 * OTHERWISE.
83 */
84
85#include <stdio.h>
86
87#include <openssl/buffer.h>
88
89#include "ssl_locl.h"
90
91int
92SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
93{
94 BIO *b;
95 int ret;
96
97 if ((b = BIO_new(BIO_s_file_internal())) == NULL) {
98 SSLerr(SSL_F_SSL_SESSION_PRINT_FP, ERR_R_BUF_LIB);
99 return (0);
100 }
101 BIO_set_fp(b, fp, BIO_NOCLOSE);
102 ret = SSL_SESSION_print(b, x);
103 BIO_free(b);
104 return (ret);
105}
106
107int
108SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
109{
110 unsigned int i;
111 const char *s;
112
113 if (x == NULL)
114 goto err;
115 if (BIO_puts(bp, "SSL-Session:\n") <= 0)
116 goto err;
117
118 s = ssl_version_string(x->ssl_version);
119 if (BIO_printf(bp, " Protocol : %s\n", s) <= 0)
120 goto err;
121
122 if (x->cipher == NULL) {
123 if (((x->cipher_id) & 0xff000000) == 0x02000000) {
124 if (BIO_printf(bp, " Cipher : %06lX\n", x->cipher_id&0xffffff) <= 0)
125 goto err;
126 } else {
127 if (BIO_printf(bp, " Cipher : %04lX\n", x->cipher_id&0xffff) <= 0)
128 goto err;
129 }
130 } else {
131 if (BIO_printf(bp, " Cipher : %s\n",((x->cipher == NULL)?"unknown":x->cipher->name)) <= 0)
132 goto err;
133 }
134 if (BIO_puts(bp, " Session-ID: ") <= 0)
135 goto err;
136 for (i = 0; i < x->session_id_length; i++) {
137 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
138 goto err;
139 }
140 if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0)
141 goto err;
142 for (i = 0; i < x->sid_ctx_length; i++) {
143 if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
144 goto err;
145 }
146 if (BIO_puts(bp, "\n Master-Key: ") <= 0)
147 goto err;
148 for (i = 0; i < (unsigned int)x->master_key_length; i++) {
149 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
150 goto err;
151 }
152 if (x->tlsext_tick_lifetime_hint) {
153 if (BIO_printf(bp,
154 "\n TLS session ticket lifetime hint: %ld (seconds)",
155 x->tlsext_tick_lifetime_hint) <= 0)
156 goto err;
157 }
158 if (x->tlsext_tick) {
159 if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0)
160 goto err;
161 if (BIO_dump_indent(bp, (char *)x->tlsext_tick, x->tlsext_ticklen, 4) <= 0)
162 goto err;
163 }
164
165 if (x->time != 0) {
166 if (BIO_printf(bp, "\n Start Time: %lld", (long long)x->time) <= 0)
167 goto err;
168 }
169 if (x->timeout != 0L) {
170 if (BIO_printf(bp, "\n Timeout : %ld (sec)", x->timeout) <= 0)
171 goto err;
172 }
173 if (BIO_puts(bp, "\n") <= 0)
174 goto err;
175
176 if (BIO_puts(bp, " Verify return code: ") <= 0)
177 goto err;
178
179 if (BIO_printf(bp, "%ld (%s)\n", x->verify_result,
180 X509_verify_cert_error_string(x->verify_result)) <= 0)
181 goto err;
182
183 return (1);
184err:
185 return (0);
186}
187