1 /* $OpenBSD: ssl_lib.c,v 1.182 2018/03/17 16:20:01 beck Exp $ */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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)"
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
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.]
58 /* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
87 * 6. Redistributions of any form whatsoever must retain the following
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
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 * ====================================================================
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).
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.
116 /* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
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.
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.
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.
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
145 #include "ssl_locl.h"
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>
154 #ifndef OPENSSL_NO_ENGINE
155 #include <openssl/engine.h>
158 #include "bytestring.h"
160 const char *SSL_version_str
= OPENSSL_VERSION_TEXT
;
165 if (s
->method
== NULL
) {
166 SSLerror(s
, SSL_R_NO_METHOD_SPECIFIED
);
170 if (ssl_clear_bad_session(s
)) {
171 SSL_SESSION_free(s
->session
);
176 s
->internal
->hit
= 0;
177 s
->internal
->shutdown
= 0;
179 if (s
->internal
->renegotiate
) {
180 SSLerror(s
, ERR_R_INTERNAL_ERROR
);
184 s
->internal
->type
= 0;
186 s
->version
= s
->method
->internal
->version
;
187 s
->client_version
= s
->version
;
188 s
->internal
->rwstate
= SSL_NOTHING
;
189 s
->internal
->rstate
= SSL_ST_READ_HEADER
;
191 BUF_MEM_free(s
->internal
->init_buf
);
192 s
->internal
->init_buf
= NULL
;
194 ssl_clear_cipher_ctx(s
);
195 ssl_clear_hash_ctx(&s
->read_hash
);
196 ssl_clear_hash_ctx(&s
->internal
->write_hash
);
198 s
->internal
->first_packet
= 0;
201 * Check to see if we were changed into a different method, if
202 * so, revert back if we are not doing session-id reuse.
204 if (!s
->internal
->in_handshake
&& (s
->session
== NULL
) &&
205 (s
->method
!= s
->ctx
->method
)) {
206 s
->method
->internal
->ssl_free(s
);
207 s
->method
= s
->ctx
->method
;
208 if (!s
->method
->internal
->ssl_new(s
))
211 s
->method
->internal
->ssl_clear(s
);
213 S3I(s
)->hs
.state
= SSL_ST_BEFORE
|((s
->server
) ? SSL_ST_ACCEPT
: SSL_ST_CONNECT
);
218 /* Used to change an SSL_CTXs default SSL method type */
220 SSL_CTX_set_ssl_version(SSL_CTX
*ctx
, const SSL_METHOD
*meth
)
222 STACK_OF(SSL_CIPHER
) *sk
;
226 sk
= ssl_create_cipher_list(ctx
->method
, &(ctx
->cipher_list
),
227 &(ctx
->internal
->cipher_list_by_id
), SSL_DEFAULT_CIPHER_LIST
);
228 if ((sk
== NULL
) || (sk_SSL_CIPHER_num(sk
) <= 0)) {
229 SSLerrorx(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS
);
236 SSL_new(SSL_CTX
*ctx
)
241 SSLerrorx(SSL_R_NULL_SSL_CTX
);
244 if (ctx
->method
== NULL
) {
245 SSLerrorx(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION
);
249 if ((s
= calloc(1, sizeof(*s
))) == NULL
) {
250 SSLerrorx(ERR_R_MALLOC_FAILURE
);
253 if ((s
->internal
= calloc(1, sizeof(*s
->internal
))) == NULL
) {
255 SSLerrorx(ERR_R_MALLOC_FAILURE
);
259 s
->internal
->min_version
= ctx
->internal
->min_version
;
260 s
->internal
->max_version
= ctx
->internal
->max_version
;
262 s
->internal
->options
= ctx
->internal
->options
;
263 s
->internal
->mode
= ctx
->internal
->mode
;
264 s
->internal
->max_cert_list
= ctx
->internal
->max_cert_list
;
266 if (ctx
->internal
->cert
!= NULL
) {
268 * Earlier library versions used to copy the pointer to
269 * the CERT, not its contents; only when setting new
270 * parameters for the per-SSL copy, ssl_cert_new would be
271 * called (and the direct reference to the per-SSL_CTX
272 * settings would be lost, but those still were indirectly
273 * accessed for various purposes, and for that reason they
274 * used to be known as s->ctx->default_cert).
275 * Now we don't look at the SSL_CTX's CERT after having
276 * duplicated it once.
278 s
->cert
= ssl_cert_dup(ctx
->internal
->cert
);
282 s
->cert
=NULL
; /* Cannot really happen (see SSL_CTX_new) */
284 s
->internal
->read_ahead
= ctx
->internal
->read_ahead
;
285 s
->internal
->msg_callback
= ctx
->internal
->msg_callback
;
286 s
->internal
->msg_callback_arg
= ctx
->internal
->msg_callback_arg
;
287 s
->verify_mode
= ctx
->verify_mode
;
288 s
->sid_ctx_length
= ctx
->sid_ctx_length
;
289 OPENSSL_assert(s
->sid_ctx_length
<= sizeof s
->sid_ctx
);
290 memcpy(&s
->sid_ctx
, &ctx
->sid_ctx
, sizeof(s
->sid_ctx
));
291 s
->internal
->verify_callback
= ctx
->internal
->default_verify_callback
;
292 s
->internal
->generate_session_id
= ctx
->internal
->generate_session_id
;
294 s
->param
= X509_VERIFY_PARAM_new();
297 X509_VERIFY_PARAM_inherit(s
->param
, ctx
->param
);
298 s
->internal
->quiet_shutdown
= ctx
->internal
->quiet_shutdown
;
299 s
->max_send_fragment
= ctx
->internal
->max_send_fragment
;
301 CRYPTO_add(&ctx
->references
, 1, CRYPTO_LOCK_SSL_CTX
);
303 s
->internal
->tlsext_debug_cb
= 0;
304 s
->internal
->tlsext_debug_arg
= NULL
;
305 s
->internal
->tlsext_ticket_expected
= 0;
306 s
->tlsext_status_type
= -1;
307 s
->internal
->tlsext_status_expected
= 0;
308 s
->internal
->tlsext_ocsp_ids
= NULL
;
309 s
->internal
->tlsext_ocsp_exts
= NULL
;
310 s
->internal
->tlsext_ocsp_resp
= NULL
;
311 s
->internal
->tlsext_ocsp_resplen
= -1;
312 CRYPTO_add(&ctx
->references
, 1, CRYPTO_LOCK_SSL_CTX
);
313 s
->initial_ctx
= ctx
;
315 if (ctx
->internal
->tlsext_ecpointformatlist
!= NULL
) {
316 s
->internal
->tlsext_ecpointformatlist
=
317 calloc(ctx
->internal
->tlsext_ecpointformatlist_length
,
318 sizeof(ctx
->internal
->tlsext_ecpointformatlist
[0]));
319 if (s
->internal
->tlsext_ecpointformatlist
== NULL
)
321 memcpy(s
->internal
->tlsext_ecpointformatlist
,
322 ctx
->internal
->tlsext_ecpointformatlist
,
323 ctx
->internal
->tlsext_ecpointformatlist_length
*
324 sizeof(ctx
->internal
->tlsext_ecpointformatlist
[0]));
325 s
->internal
->tlsext_ecpointformatlist_length
=
326 ctx
->internal
->tlsext_ecpointformatlist_length
;
328 if (ctx
->internal
->tlsext_supportedgroups
!= NULL
) {
329 s
->internal
->tlsext_supportedgroups
=
330 calloc(ctx
->internal
->tlsext_supportedgroups_length
,
331 sizeof(ctx
->internal
->tlsext_supportedgroups
));
332 if (s
->internal
->tlsext_supportedgroups
== NULL
)
334 memcpy(s
->internal
->tlsext_supportedgroups
,
335 ctx
->internal
->tlsext_supportedgroups
,
336 ctx
->internal
->tlsext_supportedgroups_length
*
337 sizeof(ctx
->internal
->tlsext_supportedgroups
[0]));
338 s
->internal
->tlsext_supportedgroups_length
=
339 ctx
->internal
->tlsext_supportedgroups_length
;
342 if (s
->ctx
->internal
->alpn_client_proto_list
!= NULL
) {
343 s
->internal
->alpn_client_proto_list
=
344 malloc(s
->ctx
->internal
->alpn_client_proto_list_len
);
345 if (s
->internal
->alpn_client_proto_list
== NULL
)
347 memcpy(s
->internal
->alpn_client_proto_list
,
348 s
->ctx
->internal
->alpn_client_proto_list
,
349 s
->ctx
->internal
->alpn_client_proto_list_len
);
350 s
->internal
->alpn_client_proto_list_len
=
351 s
->ctx
->internal
->alpn_client_proto_list_len
;
354 s
->verify_result
= X509_V_OK
;
356 s
->method
= ctx
->method
;
358 if (!s
->method
->internal
->ssl_new(s
))
362 s
->server
= (ctx
->method
->internal
->ssl_accept
== ssl_undefined_function
) ? 0 : 1;
366 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL
, s
, &s
->internal
->ex_data
);
372 SSLerrorx(ERR_R_MALLOC_FAILURE
);
377 SSL_CTX_set_session_id_context(SSL_CTX
*ctx
, const unsigned char *sid_ctx
,
378 unsigned int sid_ctx_len
)
380 if (sid_ctx_len
> sizeof ctx
->sid_ctx
) {
381 SSLerrorx(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG
);
384 ctx
->sid_ctx_length
= sid_ctx_len
;
385 memcpy(ctx
->sid_ctx
, sid_ctx
, sid_ctx_len
);
391 SSL_set_session_id_context(SSL
*ssl
, const unsigned char *sid_ctx
,
392 unsigned int sid_ctx_len
)
394 if (sid_ctx_len
> SSL_MAX_SID_CTX_LENGTH
) {
395 SSLerror(ssl
, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG
);
398 ssl
->sid_ctx_length
= sid_ctx_len
;
399 memcpy(ssl
->sid_ctx
, sid_ctx
, sid_ctx_len
);
405 SSL_CTX_set_generate_session_id(SSL_CTX
*ctx
, GEN_SESSION_CB cb
)
407 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX
);
408 ctx
->internal
->generate_session_id
= cb
;
409 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX
);
414 SSL_set_generate_session_id(SSL
*ssl
, GEN_SESSION_CB cb
)
416 CRYPTO_w_lock(CRYPTO_LOCK_SSL
);
417 ssl
->internal
->generate_session_id
= cb
;
418 CRYPTO_w_unlock(CRYPTO_LOCK_SSL
);
423 SSL_has_matching_session_id(const SSL
*ssl
, const unsigned char *id
,
427 * A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp
428 * shows how we can "construct" a session to give us the desired
429 * check - ie. to find if there's a session in the hash table
430 * that would conflict with any new session built out of this
431 * id/id_len and the ssl_version in use by this SSL.
435 if (id_len
> sizeof r
.session_id
)
438 r
.ssl_version
= ssl
->version
;
439 r
.session_id_length
= id_len
;
440 memcpy(r
.session_id
, id
, id_len
);
442 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX
);
443 p
= lh_SSL_SESSION_retrieve(ssl
->ctx
->internal
->sessions
, &r
);
444 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX
);
449 SSL_CTX_set_purpose(SSL_CTX
*s
, int purpose
)
451 return (X509_VERIFY_PARAM_set_purpose(s
->param
, purpose
));
455 SSL_set_purpose(SSL
*s
, int purpose
)
457 return (X509_VERIFY_PARAM_set_purpose(s
->param
, purpose
));
461 SSL_CTX_set_trust(SSL_CTX
*s
, int trust
)
463 return (X509_VERIFY_PARAM_set_trust(s
->param
, trust
));
467 SSL_set_trust(SSL
*s
, int trust
)
469 return (X509_VERIFY_PARAM_set_trust(s
->param
, trust
));
473 SSL_CTX_get0_param(SSL_CTX
*ctx
)
479 SSL_CTX_set1_param(SSL_CTX
*ctx
, X509_VERIFY_PARAM
*vpm
)
481 return (X509_VERIFY_PARAM_set1(ctx
->param
, vpm
));
485 SSL_get0_param(SSL
*ssl
)
491 SSL_set1_param(SSL
*ssl
, X509_VERIFY_PARAM
*vpm
)
493 return (X509_VERIFY_PARAM_set1(ssl
->param
, vpm
));
504 i
= CRYPTO_add(&s
->references
, -1, CRYPTO_LOCK_SSL
);
508 X509_VERIFY_PARAM_free(s
->param
);
510 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL
, s
, &s
->internal
->ex_data
);
512 if (s
->bbio
!= NULL
) {
513 /* If the buffering BIO is in place, pop it off */
514 if (s
->bbio
== s
->wbio
) {
515 s
->wbio
= BIO_pop(s
->wbio
);
521 if (s
->rbio
!= s
->wbio
)
522 BIO_free_all(s
->rbio
);
523 BIO_free_all(s
->wbio
);
525 BUF_MEM_free(s
->internal
->init_buf
);
527 /* add extra stuff */
528 sk_SSL_CIPHER_free(s
->cipher_list
);
529 sk_SSL_CIPHER_free(s
->internal
->cipher_list_by_id
);
531 /* Make the next call work :-) */
532 if (s
->session
!= NULL
) {
533 ssl_clear_bad_session(s
);
534 SSL_SESSION_free(s
->session
);
537 ssl_clear_cipher_ctx(s
);
538 ssl_clear_hash_ctx(&s
->read_hash
);
539 ssl_clear_hash_ctx(&s
->internal
->write_hash
);
541 ssl_cert_free(s
->cert
);
543 free(s
->tlsext_hostname
);
544 SSL_CTX_free(s
->initial_ctx
);
546 free(s
->internal
->tlsext_ecpointformatlist
);
547 free(s
->internal
->tlsext_supportedgroups
);
549 sk_X509_EXTENSION_pop_free(s
->internal
->tlsext_ocsp_exts
,
550 X509_EXTENSION_free
);
551 sk_OCSP_RESPID_pop_free(s
->internal
->tlsext_ocsp_ids
, OCSP_RESPID_free
);
552 free(s
->internal
->tlsext_ocsp_resp
);
554 sk_X509_NAME_pop_free(s
->internal
->client_CA
, X509_NAME_free
);
556 if (s
->method
!= NULL
)
557 s
->method
->internal
->ssl_free(s
);
559 SSL_CTX_free(s
->ctx
);
561 free(s
->internal
->alpn_client_proto_list
);
563 #ifndef OPENSSL_NO_SRTP
564 sk_SRTP_PROTECTION_PROFILE_free(s
->internal
->srtp_profiles
);
574 int refs
= CRYPTO_add(&s
->references
, 1, CRYPTO_LOCK_SSL
);
575 return (refs
> 1) ? 1 : 0;
579 SSL_set_bio(SSL
*s
, BIO
*rbio
, BIO
*wbio
)
581 /* If the output buffering BIO is still in place, remove it */
582 if (s
->bbio
!= NULL
) {
583 if (s
->wbio
== s
->bbio
) {
584 s
->wbio
= s
->wbio
->next_bio
;
585 s
->bbio
->next_bio
= NULL
;
589 if (s
->rbio
!= rbio
&& s
->rbio
!= s
->wbio
)
590 BIO_free_all(s
->rbio
);
592 BIO_free_all(s
->wbio
);
598 SSL_get_rbio(const SSL
*s
)
604 SSL_get_wbio(const SSL
*s
)
610 SSL_get_fd(const SSL
*s
)
612 return (SSL_get_rfd(s
));
616 SSL_get_rfd(const SSL
*s
)
622 r
= BIO_find_type(b
, BIO_TYPE_DESCRIPTOR
);
629 SSL_get_wfd(const SSL
*s
)
635 r
= BIO_find_type(b
, BIO_TYPE_DESCRIPTOR
);
642 SSL_set_fd(SSL
*s
, int fd
)
647 bio
= BIO_new(BIO_s_socket());
650 SSLerror(s
, ERR_R_BUF_LIB
);
653 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
654 SSL_set_bio(s
, bio
, bio
);
661 SSL_set_wfd(SSL
*s
, int fd
)
666 if ((s
->rbio
== NULL
) || (BIO_method_type(s
->rbio
) != BIO_TYPE_SOCKET
)
667 || ((int)BIO_get_fd(s
->rbio
, NULL
) != fd
)) {
668 bio
= BIO_new(BIO_s_socket());
671 SSLerror(s
, ERR_R_BUF_LIB
);
674 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
675 SSL_set_bio(s
, SSL_get_rbio(s
), bio
);
677 SSL_set_bio(s
, SSL_get_rbio(s
), SSL_get_rbio(s
));
684 SSL_set_rfd(SSL
*s
, int fd
)
689 if ((s
->wbio
== NULL
) || (BIO_method_type(s
->wbio
) != BIO_TYPE_SOCKET
)
690 || ((int)BIO_get_fd(s
->wbio
, NULL
) != fd
)) {
691 bio
= BIO_new(BIO_s_socket());
694 SSLerror(s
, ERR_R_BUF_LIB
);
697 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
698 SSL_set_bio(s
, bio
, SSL_get_wbio(s
));
700 SSL_set_bio(s
, SSL_get_wbio(s
), SSL_get_wbio(s
));
707 /* return length of latest Finished message we sent, copy to 'buf' */
709 SSL_get_finished(const SSL
*s
, void *buf
, size_t count
)
714 ret
= S3I(s
)->tmp
.finish_md_len
;
717 memcpy(buf
, S3I(s
)->tmp
.finish_md
, count
);
722 /* return length of latest Finished message we expected, copy to 'buf' */
724 SSL_get_peer_finished(const SSL
*s
, void *buf
, size_t count
)
729 ret
= S3I(s
)->tmp
.peer_finish_md_len
;
732 memcpy(buf
, S3I(s
)->tmp
.peer_finish_md
, count
);
739 SSL_get_verify_mode(const SSL
*s
)
741 return (s
->verify_mode
);
745 SSL_get_verify_depth(const SSL
*s
)
747 return (X509_VERIFY_PARAM_get_depth(s
->param
));
751 (*SSL_get_verify_callback(const SSL
*s
))(int, X509_STORE_CTX
*)
753 return (s
->internal
->verify_callback
);
757 SSL_CTX_get_verify_mode(const SSL_CTX
*ctx
)
759 return (ctx
->verify_mode
);
763 SSL_CTX_get_verify_depth(const SSL_CTX
*ctx
)
765 return (X509_VERIFY_PARAM_get_depth(ctx
->param
));
769 (*SSL_CTX_get_verify_callback(const SSL_CTX
*ctx
))(int, X509_STORE_CTX
*)
771 return (ctx
->internal
->default_verify_callback
);
775 SSL_set_verify(SSL
*s
, int mode
,
776 int (*callback
)(int ok
, X509_STORE_CTX
*ctx
))
778 s
->verify_mode
= mode
;
779 if (callback
!= NULL
)
780 s
->internal
->verify_callback
= callback
;
784 SSL_set_verify_depth(SSL
*s
, int depth
)
786 X509_VERIFY_PARAM_set_depth(s
->param
, depth
);
790 SSL_set_read_ahead(SSL
*s
, int yes
)
792 s
->internal
->read_ahead
= yes
;
796 SSL_get_read_ahead(const SSL
*s
)
798 return (s
->internal
->read_ahead
);
802 SSL_pending(const SSL
*s
)
805 * SSL_pending cannot work properly if read-ahead is enabled
806 * (SSL_[CTX_]ctrl(..., SSL_CTRL_SET_READ_AHEAD, 1, NULL)),
807 * and it is impossible to fix since SSL_pending cannot report
808 * errors that may be observed while scanning the new data.
809 * (Note that SSL_pending() is often used as a boolean value,
810 * so we'd better not return -1.)
812 return (s
->method
->internal
->ssl_pending(s
));
816 SSL_get_peer_certificate(const SSL
*s
)
820 if ((s
== NULL
) || (s
->session
== NULL
))
823 r
= s
->session
->peer
;
828 CRYPTO_add(&r
->references
, 1, CRYPTO_LOCK_X509
);
834 SSL_get_peer_cert_chain(const SSL
*s
)
838 if ((s
== NULL
) || (s
->session
== NULL
) ||
839 (SSI(s
)->sess_cert
== NULL
))
842 r
= SSI(s
)->sess_cert
->cert_chain
;
845 * If we are a client, cert_chain includes the peer's own
847 * if we are a server, it does not.
853 * Now in theory, since the calling process own 't' it should be safe to
854 * modify. We need to be able to read f without being hassled
857 SSL_copy_session_id(SSL
*t
, const SSL
*f
)
861 /* Do we need to to SSL locking? */
862 SSL_set_session(t
, SSL_get_session(f
));
865 * What if we are setup as SSLv2 but want to talk SSLv3 or
868 if (t
->method
!= f
->method
) {
869 t
->method
->internal
->ssl_free(t
); /* cleanup current */
870 t
->method
= f
->method
; /* change method */
871 t
->method
->internal
->ssl_new(t
); /* setup new */
875 if (f
->cert
!= NULL
) {
876 CRYPTO_add(&f
->cert
->references
, 1, CRYPTO_LOCK_SSL_CERT
);
881 SSL_set_session_id_context(t
, f
->sid_ctx
, f
->sid_ctx_length
);
884 /* Fix this so it checks all the valid key/cert options */
886 SSL_CTX_check_private_key(const SSL_CTX
*ctx
)
888 if ((ctx
== NULL
) || (ctx
->internal
->cert
== NULL
) ||
889 (ctx
->internal
->cert
->key
->x509
== NULL
)) {
890 SSLerrorx(SSL_R_NO_CERTIFICATE_ASSIGNED
);
893 if (ctx
->internal
->cert
->key
->privatekey
== NULL
) {
894 SSLerrorx(SSL_R_NO_PRIVATE_KEY_ASSIGNED
);
897 return (X509_check_private_key(ctx
->internal
->cert
->key
->x509
,
898 ctx
->internal
->cert
->key
->privatekey
));
901 /* Fix this function so that it takes an optional type parameter */
903 SSL_check_private_key(const SSL
*ssl
)
906 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER
);
909 if (ssl
->cert
== NULL
) {
910 SSLerror(ssl
, SSL_R_NO_CERTIFICATE_ASSIGNED
);
913 if (ssl
->cert
->key
->x509
== NULL
) {
914 SSLerror(ssl
, SSL_R_NO_CERTIFICATE_ASSIGNED
);
917 if (ssl
->cert
->key
->privatekey
== NULL
) {
918 SSLerror(ssl
, SSL_R_NO_PRIVATE_KEY_ASSIGNED
);
921 return (X509_check_private_key(ssl
->cert
->key
->x509
,
922 ssl
->cert
->key
->privatekey
));
928 if (s
->internal
->handshake_func
== NULL
)
929 SSL_set_accept_state(s
); /* Not properly initialized yet */
931 return (s
->method
->internal
->ssl_accept(s
));
937 if (s
->internal
->handshake_func
== NULL
)
938 SSL_set_connect_state(s
); /* Not properly initialized yet */
940 return (s
->method
->internal
->ssl_connect(s
));
944 SSL_is_server(const SSL
*s
)
950 SSL_get_default_timeout(const SSL
*s
)
952 return (s
->method
->internal
->get_timeout());
956 SSL_read(SSL
*s
, void *buf
, int num
)
958 if (s
->internal
->handshake_func
== NULL
) {
959 SSLerror(s
, SSL_R_UNINITIALIZED
);
963 if (s
->internal
->shutdown
& SSL_RECEIVED_SHUTDOWN
) {
964 s
->internal
->rwstate
= SSL_NOTHING
;
967 return (s
->method
->internal
->ssl_read(s
, buf
, num
));
971 SSL_peek(SSL
*s
, void *buf
, int num
)
973 if (s
->internal
->handshake_func
== NULL
) {
974 SSLerror(s
, SSL_R_UNINITIALIZED
);
978 if (s
->internal
->shutdown
& SSL_RECEIVED_SHUTDOWN
) {
981 return (s
->method
->internal
->ssl_peek(s
, buf
, num
));
985 SSL_write(SSL
*s
, const void *buf
, int num
)
987 if (s
->internal
->handshake_func
== NULL
) {
988 SSLerror(s
, SSL_R_UNINITIALIZED
);
992 if (s
->internal
->shutdown
& SSL_SENT_SHUTDOWN
) {
993 s
->internal
->rwstate
= SSL_NOTHING
;
994 SSLerror(s
, SSL_R_PROTOCOL_IS_SHUTDOWN
);
997 return (s
->method
->internal
->ssl_write(s
, buf
, num
));
1001 SSL_shutdown(SSL
*s
)
1004 * Note that this function behaves differently from what one might
1005 * expect. Return values are 0 for no success (yet),
1006 * 1 for success; but calling it once is usually not enough,
1007 * even if blocking I/O is used (see ssl3_shutdown).
1010 if (s
->internal
->handshake_func
== NULL
) {
1011 SSLerror(s
, SSL_R_UNINITIALIZED
);
1015 if ((s
!= NULL
) && !SSL_in_init(s
))
1016 return (s
->method
->internal
->ssl_shutdown(s
));
1022 SSL_renegotiate(SSL
*s
)
1024 if (s
->internal
->renegotiate
== 0)
1025 s
->internal
->renegotiate
= 1;
1027 s
->internal
->new_session
= 1;
1029 return (s
->method
->internal
->ssl_renegotiate(s
));
1033 SSL_renegotiate_abbreviated(SSL
*s
)
1035 if (s
->internal
->renegotiate
== 0)
1036 s
->internal
->renegotiate
= 1;
1038 s
->internal
->new_session
= 0;
1040 return (s
->method
->internal
->ssl_renegotiate(s
));
1044 SSL_renegotiate_pending(SSL
*s
)
1047 * Becomes true when negotiation is requested;
1048 * false again once a handshake has finished.
1050 return (s
->internal
->renegotiate
!= 0);
1054 SSL_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
)
1059 case SSL_CTRL_GET_READ_AHEAD
:
1060 return (s
->internal
->read_ahead
);
1061 case SSL_CTRL_SET_READ_AHEAD
:
1062 l
= s
->internal
->read_ahead
;
1063 s
->internal
->read_ahead
= larg
;
1066 case SSL_CTRL_SET_MSG_CALLBACK_ARG
:
1067 s
->internal
->msg_callback_arg
= parg
;
1070 case SSL_CTRL_OPTIONS
:
1071 return (s
->internal
->options
|=larg
);
1072 case SSL_CTRL_CLEAR_OPTIONS
:
1073 return (s
->internal
->options
&=~larg
);
1075 return (s
->internal
->mode
|=larg
);
1076 case SSL_CTRL_CLEAR_MODE
:
1077 return (s
->internal
->mode
&=~larg
);
1078 case SSL_CTRL_GET_MAX_CERT_LIST
:
1079 return (s
->internal
->max_cert_list
);
1080 case SSL_CTRL_SET_MAX_CERT_LIST
:
1081 l
= s
->internal
->max_cert_list
;
1082 s
->internal
->max_cert_list
= larg
;
1084 case SSL_CTRL_SET_MTU
:
1085 #ifndef OPENSSL_NO_DTLS1
1086 if (larg
< (long)dtls1_min_mtu())
1089 if (SSL_IS_DTLS(s
)) {
1094 case SSL_CTRL_SET_MAX_SEND_FRAGMENT
:
1095 if (larg
< 512 || larg
> SSL3_RT_MAX_PLAIN_LENGTH
)
1097 s
->max_send_fragment
= larg
;
1099 case SSL_CTRL_GET_RI_SUPPORT
:
1101 return (S3I(s
)->send_connection_binding
);
1105 return dtls1_ctrl(s
, cmd
, larg
, parg
);
1106 return ssl3_ctrl(s
, cmd
, larg
, parg
);
1111 SSL_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)(void))
1114 case SSL_CTRL_SET_MSG_CALLBACK
:
1115 s
->internal
->msg_callback
= (void (*)(int write_p
, int version
,
1116 int content_type
, const void *buf
, size_t len
,
1117 SSL
*ssl
, void *arg
))(fp
);
1121 return (ssl3_callback_ctrl(s
, cmd
, fp
));
1125 struct lhash_st_SSL_SESSION
*
1126 SSL_CTX_sessions(SSL_CTX
*ctx
)
1128 return (ctx
->internal
->sessions
);
1132 SSL_CTX_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, void *parg
)
1137 case SSL_CTRL_GET_READ_AHEAD
:
1138 return (ctx
->internal
->read_ahead
);
1139 case SSL_CTRL_SET_READ_AHEAD
:
1140 l
= ctx
->internal
->read_ahead
;
1141 ctx
->internal
->read_ahead
= larg
;
1144 case SSL_CTRL_SET_MSG_CALLBACK_ARG
:
1145 ctx
->internal
->msg_callback_arg
= parg
;
1148 case SSL_CTRL_GET_MAX_CERT_LIST
:
1149 return (ctx
->internal
->max_cert_list
);
1150 case SSL_CTRL_SET_MAX_CERT_LIST
:
1151 l
= ctx
->internal
->max_cert_list
;
1152 ctx
->internal
->max_cert_list
= larg
;
1155 case SSL_CTRL_SET_SESS_CACHE_SIZE
:
1156 l
= ctx
->internal
->session_cache_size
;
1157 ctx
->internal
->session_cache_size
= larg
;
1159 case SSL_CTRL_GET_SESS_CACHE_SIZE
:
1160 return (ctx
->internal
->session_cache_size
);
1161 case SSL_CTRL_SET_SESS_CACHE_MODE
:
1162 l
= ctx
->internal
->session_cache_mode
;
1163 ctx
->internal
->session_cache_mode
= larg
;
1165 case SSL_CTRL_GET_SESS_CACHE_MODE
:
1166 return (ctx
->internal
->session_cache_mode
);
1168 case SSL_CTRL_SESS_NUMBER
:
1169 return (lh_SSL_SESSION_num_items(ctx
->internal
->sessions
));
1170 case SSL_CTRL_SESS_CONNECT
:
1171 return (ctx
->internal
->stats
.sess_connect
);
1172 case SSL_CTRL_SESS_CONNECT_GOOD
:
1173 return (ctx
->internal
->stats
.sess_connect_good
);
1174 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE
:
1175 return (ctx
->internal
->stats
.sess_connect_renegotiate
);
1176 case SSL_CTRL_SESS_ACCEPT
:
1177 return (ctx
->internal
->stats
.sess_accept
);
1178 case SSL_CTRL_SESS_ACCEPT_GOOD
:
1179 return (ctx
->internal
->stats
.sess_accept_good
);
1180 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE
:
1181 return (ctx
->internal
->stats
.sess_accept_renegotiate
);
1182 case SSL_CTRL_SESS_HIT
:
1183 return (ctx
->internal
->stats
.sess_hit
);
1184 case SSL_CTRL_SESS_CB_HIT
:
1185 return (ctx
->internal
->stats
.sess_cb_hit
);
1186 case SSL_CTRL_SESS_MISSES
:
1187 return (ctx
->internal
->stats
.sess_miss
);
1188 case SSL_CTRL_SESS_TIMEOUTS
:
1189 return (ctx
->internal
->stats
.sess_timeout
);
1190 case SSL_CTRL_SESS_CACHE_FULL
:
1191 return (ctx
->internal
->stats
.sess_cache_full
);
1192 case SSL_CTRL_OPTIONS
:
1193 return (ctx
->internal
->options
|=larg
);
1194 case SSL_CTRL_CLEAR_OPTIONS
:
1195 return (ctx
->internal
->options
&=~larg
);
1197 return (ctx
->internal
->mode
|=larg
);
1198 case SSL_CTRL_CLEAR_MODE
:
1199 return (ctx
->internal
->mode
&=~larg
);
1200 case SSL_CTRL_SET_MAX_SEND_FRAGMENT
:
1201 if (larg
< 512 || larg
> SSL3_RT_MAX_PLAIN_LENGTH
)
1203 ctx
->internal
->max_send_fragment
= larg
;
1206 return (ssl3_ctx_ctrl(ctx
, cmd
, larg
, parg
));
1211 SSL_CTX_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)(void))
1214 case SSL_CTRL_SET_MSG_CALLBACK
:
1215 ctx
->internal
->msg_callback
= (void (*)(int write_p
, int version
,
1216 int content_type
, const void *buf
, size_t len
, SSL
*ssl
,
1221 return (ssl3_ctx_callback_ctrl(ctx
, cmd
, fp
));
1226 ssl_cipher_id_cmp(const SSL_CIPHER
*a
, const SSL_CIPHER
*b
)
1234 return ((l
> 0) ? 1:-1);
1238 ssl_cipher_ptr_id_cmp(const SSL_CIPHER
* const *ap
,
1239 const SSL_CIPHER
* const *bp
)
1243 l
= (*ap
)->id
- (*bp
)->id
;
1247 return ((l
> 0) ? 1:-1);
1251 * Return a STACK of the ciphers available for the SSL and in order of
1254 STACK_OF(SSL_CIPHER
) *
1255 SSL_get_ciphers(const SSL
*s
)
1258 if (s
->cipher_list
!= NULL
) {
1259 return (s
->cipher_list
);
1260 } else if ((s
->ctx
!= NULL
) && (s
->ctx
->cipher_list
!= NULL
)) {
1261 return (s
->ctx
->cipher_list
);
1268 * Return a STACK of the ciphers available for the SSL and in order of
1271 STACK_OF(SSL_CIPHER
) *
1272 ssl_get_ciphers_by_id(SSL
*s
)
1275 if (s
->internal
->cipher_list_by_id
!= NULL
) {
1276 return (s
->internal
->cipher_list_by_id
);
1277 } else if ((s
->ctx
!= NULL
) &&
1278 (s
->ctx
->internal
->cipher_list_by_id
!= NULL
)) {
1279 return (s
->ctx
->internal
->cipher_list_by_id
);
1285 /* See if we have any ECC cipher suites. */
1287 ssl_has_ecc_ciphers(SSL
*s
)
1289 STACK_OF(SSL_CIPHER
) *ciphers
;
1290 unsigned long alg_k
, alg_a
;
1294 if (s
->version
== DTLS1_VERSION
)
1296 if ((ciphers
= SSL_get_ciphers(s
)) == NULL
)
1299 for (i
= 0; i
< sk_SSL_CIPHER_num(ciphers
); i
++) {
1300 cipher
= sk_SSL_CIPHER_value(ciphers
, i
);
1302 alg_k
= cipher
->algorithm_mkey
;
1303 alg_a
= cipher
->algorithm_auth
;
1305 if ((alg_k
& SSL_kECDHE
) || (alg_a
& SSL_aECDSA
))
1312 /* The old interface to get the same thing as SSL_get_ciphers(). */
1314 SSL_get_cipher_list(const SSL
*s
, int n
)
1317 STACK_OF(SSL_CIPHER
) *sk
;
1321 sk
= SSL_get_ciphers(s
);
1322 if ((sk
== NULL
) || (sk_SSL_CIPHER_num(sk
) <= n
))
1324 c
= sk_SSL_CIPHER_value(sk
, n
);
1330 STACK_OF(SSL_CIPHER
) *
1331 SSL_CTX_get_ciphers(const SSL_CTX
*ctx
)
1333 return ctx
->cipher_list
;
1336 /* Specify the ciphers to be used by default by the SSL_CTX. */
1338 SSL_CTX_set_cipher_list(SSL_CTX
*ctx
, const char *str
)
1340 STACK_OF(SSL_CIPHER
) *sk
;
1342 sk
= ssl_create_cipher_list(ctx
->method
, &ctx
->cipher_list
,
1343 &ctx
->internal
->cipher_list_by_id
, str
);
1345 * ssl_create_cipher_list may return an empty stack if it
1346 * was unable to find a cipher matching the given rule string
1347 * (for example if the rule string specifies a cipher which
1348 * has been disabled). This is not an error as far as
1349 * ssl_create_cipher_list is concerned, and hence
1350 * ctx->cipher_list and ctx->internal->cipher_list_by_id has been
1355 else if (sk_SSL_CIPHER_num(sk
) == 0) {
1356 SSLerrorx(SSL_R_NO_CIPHER_MATCH
);
1362 /* Specify the ciphers to be used by the SSL. */
1364 SSL_set_cipher_list(SSL
*s
, const char *str
)
1366 STACK_OF(SSL_CIPHER
) *sk
;
1368 sk
= ssl_create_cipher_list(s
->ctx
->method
, &s
->cipher_list
,
1369 &s
->internal
->cipher_list_by_id
, str
);
1370 /* see comment in SSL_CTX_set_cipher_list */
1373 else if (sk_SSL_CIPHER_num(sk
) == 0) {
1374 SSLerror(s
, SSL_R_NO_CIPHER_MATCH
);
1380 /* works well for SSLv2, not so good for SSLv3 */
1382 SSL_get_shared_ciphers(const SSL
*s
, char *buf
, int len
)
1385 STACK_OF(SSL_CIPHER
) *sk
;
1390 if (s
->session
== NULL
|| s
->session
->ciphers
== NULL
|| len
< 2)
1393 sk
= s
->session
->ciphers
;
1394 if (sk_SSL_CIPHER_num(sk
) == 0)
1398 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
1399 c
= sk_SSL_CIPHER_value(sk
, i
);
1401 if (strlcat(buf
, c
->name
, len
) >= len
||
1402 (curlen
= strlcat(buf
, ":", len
)) >= len
) {
1403 /* remove truncated cipher from list */
1408 /* remove trailing colon */
1409 if ((end
= strrchr(buf
, ':')) != NULL
)
1415 ssl_cipher_list_to_bytes(SSL
*s
, STACK_OF(SSL_CIPHER
) *ciphers
, CBB
*cbb
)
1418 int num_ciphers
= 0;
1421 if (ciphers
== NULL
)
1424 for (i
= 0; i
< sk_SSL_CIPHER_num(ciphers
); i
++) {
1425 if ((cipher
= sk_SSL_CIPHER_value(ciphers
, i
)) == NULL
)
1428 /* Skip TLS v1.2 only ciphersuites if lower than v1.2 */
1429 if ((cipher
->algorithm_ssl
& SSL_TLSV1_2
) &&
1430 (TLS1_get_client_version(s
) < TLS1_2_VERSION
))
1433 if (!CBB_add_u16(cbb
, ssl3_cipher_get_value(cipher
)))
1439 /* Add SCSV if there are other ciphers and we're not renegotiating. */
1440 if (num_ciphers
> 0 && !s
->internal
->renegotiate
) {
1441 if (!CBB_add_u16(cbb
, SSL3_CK_SCSV
& SSL3_CK_VALUE_MASK
))
1445 if (!CBB_flush(cbb
))
1451 STACK_OF(SSL_CIPHER
) *
1452 ssl_bytes_to_cipher_list(SSL
*s
, CBS
*cbs
)
1454 STACK_OF(SSL_CIPHER
) *ciphers
= NULL
;
1455 const SSL_CIPHER
*cipher
;
1456 uint16_t cipher_value
, max_version
;
1457 unsigned long cipher_id
;
1460 S3I(s
)->send_connection_binding
= 0;
1462 if ((ciphers
= sk_SSL_CIPHER_new_null()) == NULL
) {
1463 SSLerror(s
, ERR_R_MALLOC_FAILURE
);
1467 while (CBS_len(cbs
) > 0) {
1468 if (!CBS_get_u16(cbs
, &cipher_value
)) {
1469 SSLerror(s
, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST
);
1473 cipher_id
= SSL3_CK_ID
| cipher_value
;
1475 if (s
->s3
!= NULL
&& cipher_id
== SSL3_CK_SCSV
) {
1477 * TLS_EMPTY_RENEGOTIATION_INFO_SCSV is fatal if
1480 if (s
->internal
->renegotiate
) {
1481 SSLerror(s
, SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING
);
1482 ssl3_send_alert(s
, SSL3_AL_FATAL
,
1483 SSL_AD_HANDSHAKE_FAILURE
);
1487 S3I(s
)->send_connection_binding
= 1;
1491 if (cipher_id
== SSL3_CK_FALLBACK_SCSV
) {
1493 * TLS_FALLBACK_SCSV indicates that the client
1494 * previously tried a higher protocol version.
1495 * Fail if the current version is an unexpected
1498 max_version
= ssl_max_server_version(s
);
1499 if (max_version
== 0 || s
->version
< max_version
) {
1500 SSLerror(s
, SSL_R_INAPPROPRIATE_FALLBACK
);
1502 ssl3_send_alert(s
, SSL3_AL_FATAL
,
1503 SSL_AD_INAPPROPRIATE_FALLBACK
);
1509 if ((cipher
= ssl3_get_cipher_by_value(cipher_value
)) != NULL
) {
1510 if (!sk_SSL_CIPHER_push(ciphers
, cipher
)) {
1511 SSLerror(s
, ERR_R_MALLOC_FAILURE
);
1520 sk_SSL_CIPHER_free(ciphers
);
1527 * Return a servername extension value if provided in Client Hello, or NULL.
1528 * So far, only host_name types are defined (RFC 3546).
1531 SSL_get_servername(const SSL
*s
, const int type
)
1533 if (type
!= TLSEXT_NAMETYPE_host_name
)
1536 return (s
->session
&& !s
->tlsext_hostname
?
1537 s
->session
->tlsext_hostname
:
1538 s
->tlsext_hostname
);
1542 SSL_get_servername_type(const SSL
*s
)
1545 (!s
->tlsext_hostname
?
1546 s
->session
->tlsext_hostname
: s
->tlsext_hostname
))
1547 return (TLSEXT_NAMETYPE_host_name
);
1552 * SSL_select_next_proto implements standard protocol selection. It is
1553 * expected that this function is called from the callback set by
1554 * SSL_CTX_set_alpn_select_cb.
1556 * The protocol data is assumed to be a vector of 8-bit, length prefixed byte
1557 * strings. The length byte itself is not included in the length. A byte
1558 * string of length 0 is invalid. No byte string may be truncated.
1560 * It returns either:
1561 * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
1562 * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
1565 SSL_select_next_proto(unsigned char **out
, unsigned char *outlen
,
1566 const unsigned char *server
, unsigned int server_len
,
1567 const unsigned char *client
, unsigned int client_len
)
1570 const unsigned char *result
;
1571 int status
= OPENSSL_NPN_UNSUPPORTED
;
1574 * For each protocol in server preference order,
1575 * see if we support it.
1577 for (i
= 0; i
< server_len
; ) {
1578 for (j
= 0; j
< client_len
; ) {
1579 if (server
[i
] == client
[j
] &&
1580 memcmp(&server
[i
+ 1],
1581 &client
[j
+ 1], server
[i
]) == 0) {
1582 /* We found a match */
1583 result
= &server
[i
];
1584 status
= OPENSSL_NPN_NEGOTIATED
;
1594 /* There's no overlap between our protocols and the server's list. */
1596 status
= OPENSSL_NPN_NO_OVERLAP
;
1599 *out
= (unsigned char *) result
+ 1;
1600 *outlen
= result
[0];
1604 /* SSL_get0_next_proto_negotiated is deprecated. */
1606 SSL_get0_next_proto_negotiated(const SSL
*s
, const unsigned char **data
,
1613 /* SSL_CTX_set_next_protos_advertised_cb is deprecated. */
1615 SSL_CTX_set_next_protos_advertised_cb(SSL_CTX
*ctx
, int (*cb
) (SSL
*ssl
,
1616 const unsigned char **out
, unsigned int *outlen
, void *arg
), void *arg
)
1620 /* SSL_CTX_set_next_proto_select_cb is deprecated. */
1622 SSL_CTX_set_next_proto_select_cb(SSL_CTX
*ctx
, int (*cb
) (SSL
*s
,
1623 unsigned char **out
, unsigned char *outlen
, const unsigned char *in
,
1624 unsigned int inlen
, void *arg
), void *arg
)
1629 * SSL_CTX_set_alpn_protos sets the ALPN protocol list to the specified
1630 * protocols, which must be in wire-format (i.e. a series of non-empty,
1631 * 8-bit length-prefixed strings). Returns 0 on success.
1634 SSL_CTX_set_alpn_protos(SSL_CTX
*ctx
, const unsigned char *protos
,
1635 unsigned int protos_len
)
1639 if (protos
== NULL
|| protos_len
== 0)
1642 free(ctx
->internal
->alpn_client_proto_list
);
1643 ctx
->internal
->alpn_client_proto_list
= NULL
;
1644 ctx
->internal
->alpn_client_proto_list_len
= 0;
1646 if ((ctx
->internal
->alpn_client_proto_list
= malloc(protos_len
))
1649 ctx
->internal
->alpn_client_proto_list_len
= protos_len
;
1651 memcpy(ctx
->internal
->alpn_client_proto_list
, protos
, protos_len
);
1656 /* NOTE: Return values are the reverse of what you expect. */
1661 * SSL_set_alpn_protos sets the ALPN protocol list to the specified
1662 * protocols, which must be in wire-format (i.e. a series of non-empty,
1663 * 8-bit length-prefixed strings). Returns 0 on success.
1666 SSL_set_alpn_protos(SSL
*ssl
, const unsigned char *protos
,
1667 unsigned int protos_len
)
1671 if (protos
== NULL
|| protos_len
== 0)
1674 free(ssl
->internal
->alpn_client_proto_list
);
1675 ssl
->internal
->alpn_client_proto_list
= NULL
;
1676 ssl
->internal
->alpn_client_proto_list_len
= 0;
1678 if ((ssl
->internal
->alpn_client_proto_list
= malloc(protos_len
))
1681 ssl
->internal
->alpn_client_proto_list_len
= protos_len
;
1683 memcpy(ssl
->internal
->alpn_client_proto_list
, protos
, protos_len
);
1688 /* NOTE: Return values are the reverse of what you expect. */
1693 * SSL_CTX_set_alpn_select_cb sets a callback function that is called during
1694 * ClientHello processing in order to select an ALPN protocol from the
1695 * client's list of offered protocols.
1698 SSL_CTX_set_alpn_select_cb(SSL_CTX
* ctx
,
1699 int (*cb
) (SSL
*ssl
, const unsigned char **out
, unsigned char *outlen
,
1700 const unsigned char *in
, unsigned int inlen
, void *arg
), void *arg
)
1702 ctx
->internal
->alpn_select_cb
= cb
;
1703 ctx
->internal
->alpn_select_cb_arg
= arg
;
1707 * SSL_get0_alpn_selected gets the selected ALPN protocol (if any). On return
1708 * it sets data to point to len bytes of protocol name (not including the
1709 * leading length-prefix byte). If the server didn't respond with* a negotiated
1710 * protocol then len will be zero.
1713 SSL_get0_alpn_selected(const SSL
*ssl
, const unsigned char **data
,
1719 if (ssl
->s3
!= NULL
) {
1720 *data
= ssl
->s3
->internal
->alpn_selected
;
1721 *len
= ssl
->s3
->internal
->alpn_selected_len
;
1726 SSL_export_keying_material(SSL
*s
, unsigned char *out
, size_t olen
,
1727 const char *label
, size_t llen
, const unsigned char *p
, size_t plen
,
1730 return (tls1_export_keying_material(s
, out
, olen
,
1731 label
, llen
, p
, plen
, use_context
));
1734 static unsigned long
1735 ssl_session_hash(const SSL_SESSION
*a
)
1740 ((unsigned int) a
->session_id
[0] )|
1741 ((unsigned int) a
->session_id
[1]<< 8L)|
1742 ((unsigned long)a
->session_id
[2]<<16L)|
1743 ((unsigned long)a
->session_id
[3]<<24L);
1748 * NB: If this function (or indeed the hash function which uses a sort of
1749 * coarser function than this one) is changed, ensure
1750 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
1751 * able to construct an SSL_SESSION that will collide with any existing session
1752 * with a matching session ID.
1755 ssl_session_cmp(const SSL_SESSION
*a
, const SSL_SESSION
*b
)
1757 if (a
->ssl_version
!= b
->ssl_version
)
1759 if (a
->session_id_length
!= b
->session_id_length
)
1761 if (timingsafe_memcmp(a
->session_id
, b
->session_id
, a
->session_id_length
) != 0)
1767 * These wrapper functions should remain rather than redeclaring
1768 * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
1769 * variable. The reason is that the functions aren't static, they're exposed via
1772 static unsigned long
1773 ssl_session_LHASH_HASH(const void *arg
)
1775 const SSL_SESSION
*a
= arg
;
1777 return ssl_session_hash(a
);
1781 ssl_session_LHASH_COMP(const void *arg1
, const void *arg2
)
1783 const SSL_SESSION
*a
= arg1
;
1784 const SSL_SESSION
*b
= arg2
;
1786 return ssl_session_cmp(a
, b
);
1790 SSL_CTX_new(const SSL_METHOD
*meth
)
1794 if (!OPENSSL_init_ssl(0, NULL
)) {
1795 SSLerrorx(SSL_R_LIBRARY_BUG
);
1800 SSLerrorx(SSL_R_NULL_SSL_METHOD_PASSED
);
1804 if ((ret
= calloc(1, sizeof(*ret
))) == NULL
) {
1805 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1808 if ((ret
->internal
= calloc(1, sizeof(*ret
->internal
))) == NULL
) {
1810 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1814 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {
1815 SSLerrorx(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS
);
1820 ret
->internal
->min_version
= meth
->internal
->min_version
;
1821 ret
->internal
->max_version
= meth
->internal
->max_version
;
1823 ret
->cert_store
= NULL
;
1824 ret
->internal
->session_cache_mode
= SSL_SESS_CACHE_SERVER
;
1825 ret
->internal
->session_cache_size
= SSL_SESSION_CACHE_MAX_SIZE_DEFAULT
;
1826 ret
->internal
->session_cache_head
= NULL
;
1827 ret
->internal
->session_cache_tail
= NULL
;
1829 /* We take the system default */
1830 ret
->session_timeout
= meth
->internal
->get_timeout();
1832 ret
->internal
->new_session_cb
= 0;
1833 ret
->internal
->remove_session_cb
= 0;
1834 ret
->internal
->get_session_cb
= 0;
1835 ret
->internal
->generate_session_id
= 0;
1837 memset((char *)&ret
->internal
->stats
, 0, sizeof(ret
->internal
->stats
));
1839 ret
->references
= 1;
1840 ret
->internal
->quiet_shutdown
= 0;
1842 ret
->internal
->info_callback
= NULL
;
1844 ret
->internal
->app_verify_callback
= 0;
1845 ret
->internal
->app_verify_arg
= NULL
;
1847 ret
->internal
->max_cert_list
= SSL_MAX_CERT_LIST_DEFAULT
;
1848 ret
->internal
->read_ahead
= 0;
1849 ret
->internal
->msg_callback
= 0;
1850 ret
->internal
->msg_callback_arg
= NULL
;
1851 ret
->verify_mode
= SSL_VERIFY_NONE
;
1852 ret
->sid_ctx_length
= 0;
1853 ret
->internal
->default_verify_callback
= NULL
;
1854 if ((ret
->internal
->cert
= ssl_cert_new()) == NULL
)
1857 ret
->default_passwd_callback
= 0;
1858 ret
->default_passwd_callback_userdata
= NULL
;
1859 ret
->internal
->client_cert_cb
= 0;
1860 ret
->internal
->app_gen_cookie_cb
= 0;
1861 ret
->internal
->app_verify_cookie_cb
= 0;
1863 ret
->internal
->sessions
= lh_SSL_SESSION_new();
1864 if (ret
->internal
->sessions
== NULL
)
1866 ret
->cert_store
= X509_STORE_new();
1867 if (ret
->cert_store
== NULL
)
1870 ssl_create_cipher_list(ret
->method
, &ret
->cipher_list
,
1871 &ret
->internal
->cipher_list_by_id
, SSL_DEFAULT_CIPHER_LIST
);
1872 if (ret
->cipher_list
== NULL
||
1873 sk_SSL_CIPHER_num(ret
->cipher_list
) <= 0) {
1874 SSLerrorx(SSL_R_LIBRARY_HAS_NO_CIPHERS
);
1878 ret
->param
= X509_VERIFY_PARAM_new();
1882 if ((ret
->internal
->client_CA
= sk_X509_NAME_new_null()) == NULL
)
1885 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX
, ret
, &ret
->internal
->ex_data
);
1887 ret
->extra_certs
= NULL
;
1889 ret
->internal
->max_send_fragment
= SSL3_RT_MAX_PLAIN_LENGTH
;
1891 ret
->internal
->tlsext_servername_callback
= 0;
1892 ret
->internal
->tlsext_servername_arg
= NULL
;
1894 /* Setup RFC4507 ticket keys */
1895 arc4random_buf(ret
->internal
->tlsext_tick_key_name
, 16);
1896 arc4random_buf(ret
->internal
->tlsext_tick_hmac_key
, 16);
1897 arc4random_buf(ret
->internal
->tlsext_tick_aes_key
, 16);
1899 ret
->internal
->tlsext_status_cb
= 0;
1900 ret
->internal
->tlsext_status_arg
= NULL
;
1902 #ifndef OPENSSL_NO_ENGINE
1903 ret
->internal
->client_cert_engine
= NULL
;
1904 #ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO
1905 #define eng_strx(x) #x
1906 #define eng_str(x) eng_strx(x)
1907 /* Use specific client engine automatically... ignore errors */
1910 eng
= ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO
));
1913 ENGINE_load_builtin_engines();
1914 eng
= ENGINE_by_id(eng_str(
1915 OPENSSL_SSL_CLIENT_ENGINE_AUTO
));
1917 if (!eng
|| !SSL_CTX_set_client_cert_engine(ret
, eng
))
1923 * Default is to connect to non-RI servers. When RI is more widely
1924 * deployed might change this.
1926 ret
->internal
->options
|= SSL_OP_LEGACY_SERVER_CONNECT
;
1930 SSLerrorx(ERR_R_MALLOC_FAILURE
);
1937 SSL_CTX_free(SSL_CTX
*ctx
)
1944 i
= CRYPTO_add(&ctx
->references
, -1, CRYPTO_LOCK_SSL_CTX
);
1948 X509_VERIFY_PARAM_free(ctx
->param
);
1951 * Free internal session cache. However: the remove_cb() may reference
1952 * the ex_data of SSL_CTX, thus the ex_data store can only be removed
1953 * after the sessions were flushed.
1954 * As the ex_data handling routines might also touch the session cache,
1955 * the most secure solution seems to be: empty (flush) the cache, then
1956 * free ex_data, then finally free the cache.
1957 * (See ticket [openssl.org #212].)
1959 if (ctx
->internal
->sessions
!= NULL
)
1960 SSL_CTX_flush_sessions(ctx
, 0);
1962 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX
, ctx
, &ctx
->internal
->ex_data
);
1964 lh_SSL_SESSION_free(ctx
->internal
->sessions
);
1966 X509_STORE_free(ctx
->cert_store
);
1967 sk_SSL_CIPHER_free(ctx
->cipher_list
);
1968 sk_SSL_CIPHER_free(ctx
->internal
->cipher_list_by_id
);
1969 ssl_cert_free(ctx
->internal
->cert
);
1970 sk_X509_NAME_pop_free(ctx
->internal
->client_CA
, X509_NAME_free
);
1971 sk_X509_pop_free(ctx
->extra_certs
, X509_free
);
1973 #ifndef OPENSSL_NO_SRTP
1974 if (ctx
->internal
->srtp_profiles
)
1975 sk_SRTP_PROTECTION_PROFILE_free(ctx
->internal
->srtp_profiles
);
1978 #ifndef OPENSSL_NO_ENGINE
1979 if (ctx
->internal
->client_cert_engine
)
1980 ENGINE_finish(ctx
->internal
->client_cert_engine
);
1983 free(ctx
->internal
->tlsext_ecpointformatlist
);
1984 free(ctx
->internal
->tlsext_supportedgroups
);
1986 free(ctx
->internal
->alpn_client_proto_list
);
1988 free(ctx
->internal
);
1993 SSL_CTX_up_ref(SSL_CTX
*ctx
)
1995 int refs
= CRYPTO_add(&ctx
->references
, 1, CRYPTO_LOCK_SSL_CTX
);
1996 return ((refs
> 1) ? 1 : 0);
2000 SSL_CTX_get_default_passwd_cb(SSL_CTX
*ctx
)
2002 return (ctx
->default_passwd_callback
);
2006 SSL_CTX_set_default_passwd_cb(SSL_CTX
*ctx
, pem_password_cb
*cb
)
2008 ctx
->default_passwd_callback
= cb
;
2012 SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX
*ctx
)
2014 return ctx
->default_passwd_callback_userdata
;
2018 SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX
*ctx
, void *u
)
2020 ctx
->default_passwd_callback_userdata
= u
;
2024 SSL_CTX_set_cert_verify_callback(SSL_CTX
*ctx
, int (*cb
)(X509_STORE_CTX
*,
2027 ctx
->internal
->app_verify_callback
= cb
;
2028 ctx
->internal
->app_verify_arg
= arg
;
2032 SSL_CTX_set_verify(SSL_CTX
*ctx
, int mode
, int (*cb
)(int, X509_STORE_CTX
*))
2034 ctx
->verify_mode
= mode
;
2035 ctx
->internal
->default_verify_callback
= cb
;
2039 SSL_CTX_set_verify_depth(SSL_CTX
*ctx
, int depth
)
2041 X509_VERIFY_PARAM_set_depth(ctx
->param
, depth
);
2045 ssl_set_cert_masks(CERT
*c
, const SSL_CIPHER
*cipher
)
2047 int rsa_enc
, rsa_sign
, dh_tmp
;
2049 unsigned long mask_k
, mask_a
;
2056 dh_tmp
= (c
->dh_tmp
!= NULL
|| c
->dh_tmp_cb
!= NULL
||
2057 c
->dh_tmp_auto
!= 0);
2059 cpk
= &(c
->pkeys
[SSL_PKEY_RSA_ENC
]);
2060 rsa_enc
= (cpk
->x509
!= NULL
&& cpk
->privatekey
!= NULL
);
2061 cpk
= &(c
->pkeys
[SSL_PKEY_RSA_SIGN
]);
2062 rsa_sign
= (cpk
->x509
!= NULL
&& cpk
->privatekey
!= NULL
);
2063 cpk
= &(c
->pkeys
[SSL_PKEY_ECC
]);
2064 have_ecc_cert
= (cpk
->x509
!= NULL
&& cpk
->privatekey
!= NULL
);
2069 cpk
= &(c
->pkeys
[SSL_PKEY_GOST01
]);
2070 if (cpk
->x509
!= NULL
&& cpk
->privatekey
!=NULL
) {
2071 mask_k
|= SSL_kGOST
;
2072 mask_a
|= SSL_aGOST01
;
2081 if (rsa_enc
|| rsa_sign
)
2084 mask_a
|= SSL_aNULL
;
2087 * An ECC certificate may be usable for ECDH and/or
2088 * ECDSA cipher suites depending on the key usage extension.
2090 if (have_ecc_cert
) {
2091 x
= (c
->pkeys
[SSL_PKEY_ECC
]).x509
;
2093 /* This call populates extension flags (ex_flags). */
2094 X509_check_purpose(x
, -1, 0);
2096 /* Key usage, if present, must allow signing. */
2097 if ((x
->ex_flags
& EXFLAG_KUSAGE
) == 0 ||
2098 (x
->ex_kusage
& X509v3_KU_DIGITAL_SIGNATURE
))
2099 mask_a
|= SSL_aECDSA
;
2102 mask_k
|= SSL_kECDHE
;
2109 /* See if this handshake is using an ECC cipher suite. */
2111 ssl_using_ecc_cipher(SSL
*s
)
2113 unsigned long alg_a
, alg_k
;
2115 alg_a
= S3I(s
)->hs
.new_cipher
->algorithm_auth
;
2116 alg_k
= S3I(s
)->hs
.new_cipher
->algorithm_mkey
;
2118 return SSI(s
)->tlsext_ecpointformatlist
!= NULL
&&
2119 SSI(s
)->tlsext_ecpointformatlist_length
> 0 &&
2120 ((alg_k
& SSL_kECDHE
) || (alg_a
& SSL_aECDSA
));
2124 ssl_check_srvr_ecc_cert_and_alg(X509
*x
, SSL
*s
)
2126 const SSL_CIPHER
*cs
= S3I(s
)->hs
.new_cipher
;
2127 unsigned long alg_a
;
2129 alg_a
= cs
->algorithm_auth
;
2131 if (alg_a
& SSL_aECDSA
) {
2132 /* This call populates extension flags (ex_flags). */
2133 X509_check_purpose(x
, -1, 0);
2135 /* Key usage, if present, must allow signing. */
2136 if ((x
->ex_flags
& EXFLAG_KUSAGE
) &&
2137 ((x
->ex_kusage
& X509v3_KU_DIGITAL_SIGNATURE
) == 0)) {
2138 SSLerror(s
, SSL_R_ECC_CERT_NOT_FOR_SIGNING
);
2147 ssl_get_server_send_pkey(const SSL
*s
)
2149 unsigned long alg_a
;
2154 ssl_set_cert_masks(c
, S3I(s
)->hs
.new_cipher
);
2156 alg_a
= S3I(s
)->hs
.new_cipher
->algorithm_auth
;
2158 if (alg_a
& SSL_aECDSA
) {
2160 } else if (alg_a
& SSL_aRSA
) {
2161 if (c
->pkeys
[SSL_PKEY_RSA_ENC
].x509
== NULL
)
2162 i
= SSL_PKEY_RSA_SIGN
;
2164 i
= SSL_PKEY_RSA_ENC
;
2165 } else if (alg_a
& SSL_aGOST01
) {
2166 i
= SSL_PKEY_GOST01
;
2167 } else { /* if (alg_a & SSL_aNULL) */
2168 SSLerror(s
, ERR_R_INTERNAL_ERROR
);
2172 return (c
->pkeys
+ i
);
2176 ssl_get_server_send_cert(const SSL
*s
)
2180 cpk
= ssl_get_server_send_pkey(s
);
2187 ssl_get_sign_pkey(SSL
*s
, const SSL_CIPHER
*cipher
, const EVP_MD
**pmd
)
2189 unsigned long alg_a
;
2193 alg_a
= cipher
->algorithm_auth
;
2196 if (alg_a
& SSL_aRSA
) {
2197 if (c
->pkeys
[SSL_PKEY_RSA_SIGN
].privatekey
!= NULL
)
2198 idx
= SSL_PKEY_RSA_SIGN
;
2199 else if (c
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
!= NULL
)
2200 idx
= SSL_PKEY_RSA_ENC
;
2201 } else if ((alg_a
& SSL_aECDSA
) &&
2202 (c
->pkeys
[SSL_PKEY_ECC
].privatekey
!= NULL
))
2205 SSLerror(s
, ERR_R_INTERNAL_ERROR
);
2209 *pmd
= c
->pkeys
[idx
].digest
;
2210 return (c
->pkeys
[idx
].privatekey
);
2214 ssl_get_auto_dh(SSL
*s
)
2220 if (s
->cert
->dh_tmp_auto
== 2) {
2222 } else if (S3I(s
)->hs
.new_cipher
->algorithm_auth
& SSL_aNULL
) {
2224 if (S3I(s
)->hs
.new_cipher
->strength_bits
== 256)
2227 if ((cpk
= ssl_get_server_send_pkey(s
)) == NULL
)
2229 if (cpk
->privatekey
== NULL
|| cpk
->privatekey
->pkey
.dh
== NULL
)
2231 keylen
= EVP_PKEY_bits(cpk
->privatekey
);
2234 if ((dhp
= DH_new()) == NULL
)
2239 BN_set_word(dhp
->g
, 2);
2242 dhp
->p
= get_rfc3526_prime_8192(NULL
);
2243 else if (keylen
>= 4096)
2244 dhp
->p
= get_rfc3526_prime_4096(NULL
);
2245 else if (keylen
>= 3072)
2246 dhp
->p
= get_rfc3526_prime_3072(NULL
);
2247 else if (keylen
>= 2048)
2248 dhp
->p
= get_rfc3526_prime_2048(NULL
);
2249 else if (keylen
>= 1536)
2250 dhp
->p
= get_rfc3526_prime_1536(NULL
);
2252 dhp
->p
= get_rfc2409_prime_1024(NULL
);
2254 if (dhp
->p
== NULL
|| dhp
->g
== NULL
) {
2262 ssl_update_cache(SSL
*s
, int mode
)
2267 * If the session_id_length is 0, we are not supposed to cache it,
2268 * and it would be rather hard to do anyway :-)
2270 if (s
->session
->session_id_length
== 0)
2273 i
= s
->session_ctx
->internal
->session_cache_mode
;
2274 if ((i
& mode
) && (!s
->internal
->hit
) && ((i
& SSL_SESS_CACHE_NO_INTERNAL_STORE
)
2275 || SSL_CTX_add_session(s
->session_ctx
, s
->session
))
2276 && (s
->session_ctx
->internal
->new_session_cb
!= NULL
)) {
2277 CRYPTO_add(&s
->session
->references
, 1, CRYPTO_LOCK_SSL_SESSION
);
2278 if (!s
->session_ctx
->internal
->new_session_cb(s
, s
->session
))
2279 SSL_SESSION_free(s
->session
);
2282 /* auto flush every 255 connections */
2283 if ((!(i
& SSL_SESS_CACHE_NO_AUTO_CLEAR
)) &&
2284 ((i
& mode
) == mode
)) {
2285 if ((((mode
& SSL_SESS_CACHE_CLIENT
) ?
2286 s
->session_ctx
->internal
->stats
.sess_connect_good
:
2287 s
->session_ctx
->internal
->stats
.sess_accept_good
) & 0xff) == 0xff) {
2288 SSL_CTX_flush_sessions(s
->session_ctx
, time(NULL
));
2294 SSL_get_ssl_method(SSL
*s
)
2300 SSL_set_ssl_method(SSL
*s
, const SSL_METHOD
*meth
)
2305 if (s
->method
!= meth
) {
2306 if (s
->internal
->handshake_func
!= NULL
)
2307 conn
= (s
->internal
->handshake_func
== s
->method
->internal
->ssl_connect
);
2309 if (s
->method
->internal
->version
== meth
->internal
->version
)
2312 s
->method
->internal
->ssl_free(s
);
2314 ret
= s
->method
->internal
->ssl_new(s
);
2318 s
->internal
->handshake_func
= meth
->internal
->ssl_connect
;
2320 s
->internal
->handshake_func
= meth
->internal
->ssl_accept
;
2326 SSL_get_error(const SSL
*s
, int i
)
2333 return (SSL_ERROR_NONE
);
2335 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
2336 * etc, where we do encode the error */
2337 if ((l
= ERR_peek_error()) != 0) {
2338 if (ERR_GET_LIB(l
) == ERR_LIB_SYS
)
2339 return (SSL_ERROR_SYSCALL
);
2341 return (SSL_ERROR_SSL
);
2344 if ((i
< 0) && SSL_want_read(s
)) {
2345 bio
= SSL_get_rbio(s
);
2346 if (BIO_should_read(bio
)) {
2347 return (SSL_ERROR_WANT_READ
);
2348 } else if (BIO_should_write(bio
)) {
2350 * This one doesn't make too much sense... We never
2351 * try to write to the rbio, and an application
2352 * program where rbio and wbio are separate couldn't
2353 * even know what it should wait for. However if we
2354 * ever set s->internal->rwstate incorrectly (so that we have
2355 * SSL_want_read(s) instead of SSL_want_write(s))
2356 * and rbio and wbio *are* the same, this test works
2357 * around that bug; so it might be safer to keep it.
2359 return (SSL_ERROR_WANT_WRITE
);
2360 } else if (BIO_should_io_special(bio
)) {
2361 reason
= BIO_get_retry_reason(bio
);
2362 if (reason
== BIO_RR_CONNECT
)
2363 return (SSL_ERROR_WANT_CONNECT
);
2364 else if (reason
== BIO_RR_ACCEPT
)
2365 return (SSL_ERROR_WANT_ACCEPT
);
2367 return (SSL_ERROR_SYSCALL
); /* unknown */
2371 if ((i
< 0) && SSL_want_write(s
)) {
2372 bio
= SSL_get_wbio(s
);
2373 if (BIO_should_write(bio
)) {
2374 return (SSL_ERROR_WANT_WRITE
);
2375 } else if (BIO_should_read(bio
)) {
2377 * See above (SSL_want_read(s) with
2378 * BIO_should_write(bio))
2380 return (SSL_ERROR_WANT_READ
);
2381 } else if (BIO_should_io_special(bio
)) {
2382 reason
= BIO_get_retry_reason(bio
);
2383 if (reason
== BIO_RR_CONNECT
)
2384 return (SSL_ERROR_WANT_CONNECT
);
2385 else if (reason
== BIO_RR_ACCEPT
)
2386 return (SSL_ERROR_WANT_ACCEPT
);
2388 return (SSL_ERROR_SYSCALL
);
2391 if ((i
< 0) && SSL_want_x509_lookup(s
)) {
2392 return (SSL_ERROR_WANT_X509_LOOKUP
);
2396 if ((s
->internal
->shutdown
& SSL_RECEIVED_SHUTDOWN
) &&
2397 (S3I(s
)->warn_alert
== SSL_AD_CLOSE_NOTIFY
))
2398 return (SSL_ERROR_ZERO_RETURN
);
2400 return (SSL_ERROR_SYSCALL
);
2404 SSL_do_handshake(SSL
*s
)
2408 if (s
->internal
->handshake_func
== NULL
) {
2409 SSLerror(s
, SSL_R_CONNECTION_TYPE_NOT_SET
);
2413 s
->method
->internal
->ssl_renegotiate_check(s
);
2415 if (SSL_in_init(s
) || SSL_in_before(s
)) {
2416 ret
= s
->internal
->handshake_func(s
);
2422 * For the next 2 functions, SSL_clear() sets shutdown and so
2423 * one of these calls will reset it
2426 SSL_set_accept_state(SSL
*s
)
2429 s
->internal
->shutdown
= 0;
2430 S3I(s
)->hs
.state
= SSL_ST_ACCEPT
|SSL_ST_BEFORE
;
2431 s
->internal
->handshake_func
= s
->method
->internal
->ssl_accept
;
2432 /* clear the current cipher */
2433 ssl_clear_cipher_ctx(s
);
2434 ssl_clear_hash_ctx(&s
->read_hash
);
2435 ssl_clear_hash_ctx(&s
->internal
->write_hash
);
2439 SSL_set_connect_state(SSL
*s
)
2442 s
->internal
->shutdown
= 0;
2443 S3I(s
)->hs
.state
= SSL_ST_CONNECT
|SSL_ST_BEFORE
;
2444 s
->internal
->handshake_func
= s
->method
->internal
->ssl_connect
;
2445 /* clear the current cipher */
2446 ssl_clear_cipher_ctx(s
);
2447 ssl_clear_hash_ctx(&s
->read_hash
);
2448 ssl_clear_hash_ctx(&s
->internal
->write_hash
);
2452 ssl_undefined_function(SSL
*s
)
2454 SSLerror(s
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2459 ssl_undefined_void_function(void)
2461 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2466 ssl_undefined_const_function(const SSL
*s
)
2468 SSLerror(s
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2473 ssl_version_string(int ver
)
2477 return (SSL_TXT_DTLS1
);
2479 return (SSL_TXT_TLSV1
);
2480 case TLS1_1_VERSION
:
2481 return (SSL_TXT_TLSV1_1
);
2482 case TLS1_2_VERSION
:
2483 return (SSL_TXT_TLSV1_2
);
2490 SSL_get_version(const SSL
*s
)
2492 return ssl_version_string(s
->version
);
2498 STACK_OF(X509_NAME
) *sk
;
2503 if ((ret
= SSL_new(SSL_get_SSL_CTX(s
))) == NULL
)
2506 ret
->version
= s
->version
;
2507 ret
->internal
->type
= s
->internal
->type
;
2508 ret
->method
= s
->method
;
2510 if (s
->session
!= NULL
) {
2511 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
2512 SSL_copy_session_id(ret
, s
);
2515 * No session has been established yet, so we have to expect
2516 * that s->cert or ret->cert will be changed later --
2517 * they should not both point to the same object,
2518 * and thus we can't use SSL_copy_session_id.
2521 ret
->method
->internal
->ssl_free(ret
);
2522 ret
->method
= s
->method
;
2523 ret
->method
->internal
->ssl_new(ret
);
2525 if (s
->cert
!= NULL
) {
2526 ssl_cert_free(ret
->cert
);
2527 ret
->cert
= ssl_cert_dup(s
->cert
);
2528 if (ret
->cert
== NULL
)
2532 SSL_set_session_id_context(ret
,
2533 s
->sid_ctx
, s
->sid_ctx_length
);
2536 ret
->internal
->options
= s
->internal
->options
;
2537 ret
->internal
->mode
= s
->internal
->mode
;
2538 SSL_set_max_cert_list(ret
, SSL_get_max_cert_list(s
));
2539 SSL_set_read_ahead(ret
, SSL_get_read_ahead(s
));
2540 ret
->internal
->msg_callback
= s
->internal
->msg_callback
;
2541 ret
->internal
->msg_callback_arg
= s
->internal
->msg_callback_arg
;
2542 SSL_set_verify(ret
, SSL_get_verify_mode(s
),
2543 SSL_get_verify_callback(s
));
2544 SSL_set_verify_depth(ret
, SSL_get_verify_depth(s
));
2545 ret
->internal
->generate_session_id
= s
->internal
->generate_session_id
;
2547 SSL_set_info_callback(ret
, SSL_get_info_callback(s
));
2549 ret
->internal
->debug
= s
->internal
->debug
;
2551 /* copy app data, a little dangerous perhaps */
2552 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL
,
2553 &ret
->internal
->ex_data
, &s
->internal
->ex_data
))
2556 /* setup rbio, and wbio */
2557 if (s
->rbio
!= NULL
) {
2558 if (!BIO_dup_state(s
->rbio
,(char *)&ret
->rbio
))
2561 if (s
->wbio
!= NULL
) {
2562 if (s
->wbio
!= s
->rbio
) {
2563 if (!BIO_dup_state(s
->wbio
,(char *)&ret
->wbio
))
2566 ret
->wbio
= ret
->rbio
;
2568 ret
->internal
->rwstate
= s
->internal
->rwstate
;
2569 ret
->internal
->in_handshake
= s
->internal
->in_handshake
;
2570 ret
->internal
->handshake_func
= s
->internal
->handshake_func
;
2571 ret
->server
= s
->server
;
2572 ret
->internal
->renegotiate
= s
->internal
->renegotiate
;
2573 ret
->internal
->new_session
= s
->internal
->new_session
;
2574 ret
->internal
->quiet_shutdown
= s
->internal
->quiet_shutdown
;
2575 ret
->internal
->shutdown
= s
->internal
->shutdown
;
2576 /* SSL_dup does not really work at any state, though */
2577 S3I(ret
)->hs
.state
= S3I(s
)->hs
.state
;
2578 ret
->internal
->rstate
= s
->internal
->rstate
;
2581 * Would have to copy ret->init_buf, ret->init_msg, ret->init_num,
2584 ret
->internal
->init_num
= 0;
2586 ret
->internal
->hit
= s
->internal
->hit
;
2588 X509_VERIFY_PARAM_inherit(ret
->param
, s
->param
);
2590 /* dup the cipher_list and cipher_list_by_id stacks */
2591 if (s
->cipher_list
!= NULL
) {
2592 if ((ret
->cipher_list
=
2593 sk_SSL_CIPHER_dup(s
->cipher_list
)) == NULL
)
2596 if (s
->internal
->cipher_list_by_id
!= NULL
) {
2597 if ((ret
->internal
->cipher_list_by_id
=
2598 sk_SSL_CIPHER_dup(s
->internal
->cipher_list_by_id
)) == NULL
)
2602 /* Dup the client_CA list */
2603 if (s
->internal
->client_CA
!= NULL
) {
2604 if ((sk
= sk_X509_NAME_dup(s
->internal
->client_CA
)) == NULL
) goto err
;
2605 ret
->internal
->client_CA
= sk
;
2606 for (i
= 0; i
< sk_X509_NAME_num(sk
); i
++) {
2607 xn
= sk_X509_NAME_value(sk
, i
);
2608 if (sk_X509_NAME_set(sk
, i
,
2609 X509_NAME_dup(xn
)) == NULL
) {
2626 ssl_clear_cipher_ctx(SSL
*s
)
2628 EVP_CIPHER_CTX_free(s
->enc_read_ctx
);
2629 s
->enc_read_ctx
= NULL
;
2630 EVP_CIPHER_CTX_free(s
->internal
->enc_write_ctx
);
2631 s
->internal
->enc_write_ctx
= NULL
;
2633 if (s
->internal
->aead_read_ctx
!= NULL
) {
2634 EVP_AEAD_CTX_cleanup(&s
->internal
->aead_read_ctx
->ctx
);
2635 free(s
->internal
->aead_read_ctx
);
2636 s
->internal
->aead_read_ctx
= NULL
;
2638 if (s
->internal
->aead_write_ctx
!= NULL
) {
2639 EVP_AEAD_CTX_cleanup(&s
->internal
->aead_write_ctx
->ctx
);
2640 free(s
->internal
->aead_write_ctx
);
2641 s
->internal
->aead_write_ctx
= NULL
;
2646 /* Fix this function so that it takes an optional type parameter */
2648 SSL_get_certificate(const SSL
*s
)
2650 if (s
->cert
!= NULL
)
2651 return (s
->cert
->key
->x509
);
2656 /* Fix this function so that it takes an optional type parameter */
2658 SSL_get_privatekey(SSL
*s
)
2660 if (s
->cert
!= NULL
)
2661 return (s
->cert
->key
->privatekey
);
2667 SSL_get_current_cipher(const SSL
*s
)
2669 if ((s
->session
!= NULL
) && (s
->session
->cipher
!= NULL
))
2670 return (s
->session
->cipher
);
2674 SSL_get_current_compression(SSL
*s
)
2680 SSL_get_current_expansion(SSL
*s
)
2686 SSL_get_client_random(const SSL
*s
, unsigned char *out
, size_t max_out
)
2688 size_t len
= sizeof(s
->s3
->client_random
);
2696 memcpy(out
, s
->s3
->client_random
, len
);
2702 SSL_get_server_random(const SSL
*s
, unsigned char *out
, size_t max_out
)
2704 size_t len
= sizeof(s
->s3
->server_random
);
2712 memcpy(out
, s
->s3
->server_random
, len
);
2718 ssl_init_wbio_buffer(SSL
*s
, int push
)
2722 if (s
->bbio
== NULL
) {
2723 bbio
= BIO_new(BIO_f_buffer());
2729 if (s
->bbio
== s
->wbio
)
2730 s
->wbio
= BIO_pop(s
->wbio
);
2732 (void)BIO_reset(bbio
);
2733 /* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
2734 if (!BIO_set_read_buffer_size(bbio
, 1)) {
2735 SSLerror(s
, ERR_R_BUF_LIB
);
2739 if (s
->wbio
!= bbio
)
2740 s
->wbio
= BIO_push(bbio
, s
->wbio
);
2742 if (s
->wbio
== bbio
)
2743 s
->wbio
= BIO_pop(bbio
);
2749 ssl_free_wbio_buffer(SSL
*s
)
2754 if (s
->bbio
== NULL
)
2757 if (s
->bbio
== s
->wbio
) {
2758 /* remove buffering */
2759 s
->wbio
= BIO_pop(s
->wbio
);
2766 SSL_CTX_set_quiet_shutdown(SSL_CTX
*ctx
, int mode
)
2768 ctx
->internal
->quiet_shutdown
= mode
;
2772 SSL_CTX_get_quiet_shutdown(const SSL_CTX
*ctx
)
2774 return (ctx
->internal
->quiet_shutdown
);
2778 SSL_set_quiet_shutdown(SSL
*s
, int mode
)
2780 s
->internal
->quiet_shutdown
= mode
;
2784 SSL_get_quiet_shutdown(const SSL
*s
)
2786 return (s
->internal
->quiet_shutdown
);
2790 SSL_set_shutdown(SSL
*s
, int mode
)
2792 s
->internal
->shutdown
= mode
;
2796 SSL_get_shutdown(const SSL
*s
)
2798 return (s
->internal
->shutdown
);
2802 SSL_version(const SSL
*s
)
2804 return (s
->version
);
2808 SSL_get_SSL_CTX(const SSL
*ssl
)
2814 SSL_set_SSL_CTX(SSL
*ssl
, SSL_CTX
* ctx
)
2816 CERT
*ocert
= ssl
->cert
;
2818 if (ssl
->ctx
== ctx
)
2821 ctx
= ssl
->initial_ctx
;
2822 ssl
->cert
= ssl_cert_dup(ctx
->internal
->cert
);
2823 if (ocert
!= NULL
) {
2825 /* Copy negotiated digests from original certificate. */
2826 for (i
= 0; i
< SSL_PKEY_NUM
; i
++)
2827 ssl
->cert
->pkeys
[i
].digest
= ocert
->pkeys
[i
].digest
;
2828 ssl_cert_free(ocert
);
2830 CRYPTO_add(&ctx
->references
, 1, CRYPTO_LOCK_SSL_CTX
);
2831 SSL_CTX_free(ssl
->ctx
); /* decrement reference count */
2837 SSL_CTX_set_default_verify_paths(SSL_CTX
*ctx
)
2839 return (X509_STORE_set_default_paths(ctx
->cert_store
));
2843 SSL_CTX_load_verify_locations(SSL_CTX
*ctx
, const char *CAfile
,
2846 return (X509_STORE_load_locations(ctx
->cert_store
, CAfile
, CApath
));
2850 SSL_CTX_load_verify_mem(SSL_CTX
*ctx
, void *buf
, int len
)
2852 return (X509_STORE_load_mem(ctx
->cert_store
, buf
, len
));
2856 SSL_set_info_callback(SSL
*ssl
, void (*cb
)(const SSL
*ssl
, int type
, int val
))
2858 ssl
->internal
->info_callback
= cb
;
2861 void (*SSL_get_info_callback(const SSL
*ssl
))(const SSL
*ssl
, int type
, int val
)
2863 return (ssl
->internal
->info_callback
);
2867 SSL_state(const SSL
*ssl
)
2869 return (S3I(ssl
)->hs
.state
);
2873 SSL_set_state(SSL
*ssl
, int state
)
2875 S3I(ssl
)->hs
.state
= state
;
2879 SSL_set_verify_result(SSL
*ssl
, long arg
)
2881 ssl
->verify_result
= arg
;
2885 SSL_get_verify_result(const SSL
*ssl
)
2887 return (ssl
->verify_result
);
2891 SSL_get_ex_new_index(long argl
, void *argp
, CRYPTO_EX_new
*new_func
,
2892 CRYPTO_EX_dup
*dup_func
, CRYPTO_EX_free
*free_func
)
2894 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL
, argl
, argp
,
2895 new_func
, dup_func
, free_func
));
2899 SSL_set_ex_data(SSL
*s
, int idx
, void *arg
)
2901 return (CRYPTO_set_ex_data(&s
->internal
->ex_data
, idx
, arg
));
2905 SSL_get_ex_data(const SSL
*s
, int idx
)
2907 return (CRYPTO_get_ex_data(&s
->internal
->ex_data
, idx
));
2911 SSL_CTX_get_ex_new_index(long argl
, void *argp
, CRYPTO_EX_new
*new_func
,
2912 CRYPTO_EX_dup
*dup_func
, CRYPTO_EX_free
*free_func
)
2914 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX
, argl
, argp
,
2915 new_func
, dup_func
, free_func
));
2919 SSL_CTX_set_ex_data(SSL_CTX
*s
, int idx
, void *arg
)
2921 return (CRYPTO_set_ex_data(&s
->internal
->ex_data
, idx
, arg
));
2925 SSL_CTX_get_ex_data(const SSL_CTX
*s
, int idx
)
2927 return (CRYPTO_get_ex_data(&s
->internal
->ex_data
, idx
));
2937 SSL_CTX_get_cert_store(const SSL_CTX
*ctx
)
2939 return (ctx
->cert_store
);
2943 SSL_CTX_set_cert_store(SSL_CTX
*ctx
, X509_STORE
*store
)
2945 X509_STORE_free(ctx
->cert_store
);
2946 ctx
->cert_store
= store
;
2950 SSL_CTX_get0_certificate(const SSL_CTX
*ctx
)
2952 if (ctx
->internal
->cert
== NULL
)
2955 return ctx
->internal
->cert
->key
->x509
;
2959 SSL_want(const SSL
*s
)
2961 return (s
->internal
->rwstate
);
2965 SSL_CTX_set_tmp_rsa_callback(SSL_CTX
*ctx
, RSA
*(*cb
)(SSL
*ssl
, int is_export
,
2968 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_RSA_CB
,(void (*)(void))cb
);
2972 SSL_set_tmp_rsa_callback(SSL
*ssl
, RSA
*(*cb
)(SSL
*ssl
, int is_export
,
2975 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_RSA_CB
,(void (*)(void))cb
);
2979 SSL_CTX_set_tmp_dh_callback(SSL_CTX
*ctx
, DH
*(*dh
)(SSL
*ssl
, int is_export
,
2982 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_DH_CB
,(void (*)(void))dh
);
2986 SSL_set_tmp_dh_callback(SSL
*ssl
, DH
*(*dh
)(SSL
*ssl
, int is_export
,
2989 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_DH_CB
,(void (*)(void))dh
);
2993 SSL_CTX_set_tmp_ecdh_callback(SSL_CTX
*ctx
, EC_KEY
*(*ecdh
)(SSL
*ssl
,
2994 int is_export
, int keylength
))
2996 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_ECDH_CB
,
2997 (void (*)(void))ecdh
);
3001 SSL_set_tmp_ecdh_callback(SSL
*ssl
, EC_KEY
*(*ecdh
)(SSL
*ssl
, int is_export
,
3004 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_ECDH_CB
,(void (*)(void))ecdh
);
3009 SSL_CTX_set_msg_callback(SSL_CTX
*ctx
, void (*cb
)(int write_p
, int version
,
3010 int content_type
, const void *buf
, size_t len
, SSL
*ssl
, void *arg
))
3012 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_MSG_CALLBACK
,
3013 (void (*)(void))cb
);
3017 SSL_set_msg_callback(SSL
*ssl
, void (*cb
)(int write_p
, int version
,
3018 int content_type
, const void *buf
, size_t len
, SSL
*ssl
, void *arg
))
3020 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_MSG_CALLBACK
, (void (*)(void))cb
);
3024 ssl_clear_hash_ctx(EVP_MD_CTX
**hash
)
3027 EVP_MD_CTX_destroy(*hash
);
3032 SSL_set_debug(SSL
*s
, int debug
)
3034 s
->internal
->debug
= debug
;
3038 SSL_cache_hit(SSL
*s
)
3040 return (s
->internal
->hit
);
3044 SSL_CTX_get_min_proto_version(SSL_CTX
*ctx
)
3046 return ctx
->internal
->min_version
;
3050 SSL_CTX_set_min_proto_version(SSL_CTX
*ctx
, uint16_t version
)
3052 return ssl_version_set_min(ctx
->method
, version
,
3053 ctx
->internal
->max_version
, &ctx
->internal
->min_version
);
3057 SSL_CTX_get_max_proto_version(SSL_CTX
*ctx
)
3059 return ctx
->internal
->max_version
;
3063 SSL_CTX_set_max_proto_version(SSL_CTX
*ctx
, uint16_t version
)
3065 return ssl_version_set_max(ctx
->method
, version
,
3066 ctx
->internal
->min_version
, &ctx
->internal
->max_version
);
3070 SSL_get_min_proto_version(SSL
*ssl
)
3072 return ssl
->internal
->min_version
;
3076 SSL_set_min_proto_version(SSL
*ssl
, uint16_t version
)
3078 return ssl_version_set_min(ssl
->method
, version
,
3079 ssl
->internal
->max_version
, &ssl
->internal
->min_version
);
3082 SSL_get_max_proto_version(SSL
*ssl
)
3084 return ssl
->internal
->max_version
;
3088 SSL_set_max_proto_version(SSL
*ssl
, uint16_t version
)
3090 return ssl_version_set_max(ssl
->method
, version
,
3091 ssl
->internal
->min_version
, &ssl
->internal
->max_version
);
3095 ssl_cipher_id_cmp_BSEARCH_CMP_FN(const void *a_
, const void *b_
)
3097 SSL_CIPHER
const *a
= a_
;
3098 SSL_CIPHER
const *b
= b_
;
3099 return ssl_cipher_id_cmp(a
, b
);
3103 OBJ_bsearch_ssl_cipher_id(SSL_CIPHER
*key
, SSL_CIPHER
const *base
, int num
)
3105 return (SSL_CIPHER
*)OBJ_bsearch_(key
, base
, num
, sizeof(SSL_CIPHER
),
3106 ssl_cipher_id_cmp_BSEARCH_CMP_FN
);