1 /* $OpenBSD: ssl_lib.c,v 1.115 2015/10/19 17:59:39 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
;
162 SSL3_ENC_METHOD ssl3_undef_enc_method
= {
164 * Evil casts, but these functions are only called if there's a
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
,
192 if (s
->method
== NULL
) {
193 SSLerr(SSL_F_SSL_CLEAR
, SSL_R_NO_METHOD_SPECIFIED
);
197 if (ssl_clear_bad_session(s
)) {
198 SSL_SESSION_free(s
->session
);
206 if (s
->renegotiate
) {
207 SSLerr(SSL_F_SSL_CLEAR
, ERR_R_INTERNAL_ERROR
);
213 s
->state
= SSL_ST_BEFORE
|((s
->server
) ? SSL_ST_ACCEPT
: SSL_ST_CONNECT
);
215 s
->version
= s
->method
->version
;
216 s
->client_version
= s
->version
;
217 s
->rwstate
= SSL_NOTHING
;
218 s
->rstate
= SSL_ST_READ_HEADER
;
220 BUF_MEM_free(s
->init_buf
);
223 ssl_clear_cipher_ctx(s
);
224 ssl_clear_hash_ctx(&s
->read_hash
);
225 ssl_clear_hash_ctx(&s
->write_hash
);
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.
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
))
240 s
->method
->ssl_clear(s
);
245 /* Used to change an SSL_CTXs default SSL method type */
247 SSL_CTX_set_ssl_version(SSL_CTX
*ctx
, const SSL_METHOD
*meth
)
249 STACK_OF(SSL_CIPHER
) *sk
;
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
);
264 SSL_new(SSL_CTX
*ctx
)
269 SSLerr(SSL_F_SSL_NEW
, SSL_R_NULL_SSL_CTX
);
272 if (ctx
->method
== NULL
) {
273 SSLerr(SSL_F_SSL_NEW
, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION
);
277 s
= calloc(1, sizeof(SSL
));
282 s
->options
= ctx
->options
;
284 s
->max_cert_list
= ctx
->max_cert_list
;
286 if (ctx
->cert
!= NULL
) {
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.
298 s
->cert
= ssl_cert_dup(ctx
->cert
);
302 s
->cert
=NULL
; /* Cannot really happen (see SSL_CTX_new) */
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
;
314 s
->param
= X509_VERIFY_PARAM_new();
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
;
321 CRYPTO_add(&ctx
->references
, 1, CRYPTO_LOCK_SSL_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
;
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
)
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
;
348 s
->verify_result
= X509_V_OK
;
350 s
->method
= ctx
->method
;
352 if (!s
->method
->ssl_new(s
))
356 s
->server
= (ctx
->method
->ssl_accept
== ssl_undefined_function
) ? 0 : 1;
360 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL
, s
, &s
->ex_data
);
366 SSLerr(SSL_F_SSL_NEW
, ERR_R_MALLOC_FAILURE
);
371 SSL_CTX_set_session_id_context(SSL_CTX
*ctx
, const unsigned char *sid_ctx
,
372 unsigned int sid_ctx_len
)
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
);
379 ctx
->sid_ctx_length
= sid_ctx_len
;
380 memcpy(ctx
->sid_ctx
, sid_ctx
, sid_ctx_len
);
386 SSL_set_session_id_context(SSL
*ssl
, const unsigned char *sid_ctx
,
387 unsigned int sid_ctx_len
)
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
);
394 ssl
->sid_ctx_length
= sid_ctx_len
;
395 memcpy(ssl
->sid_ctx
, sid_ctx
, sid_ctx_len
);
401 SSL_CTX_set_generate_session_id(SSL_CTX
*ctx
, GEN_SESSION_CB cb
)
403 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX
);
404 ctx
->generate_session_id
= cb
;
405 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX
);
410 SSL_set_generate_session_id(SSL
*ssl
, GEN_SESSION_CB cb
)
412 CRYPTO_w_lock(CRYPTO_LOCK_SSL
);
413 ssl
->generate_session_id
= cb
;
414 CRYPTO_w_unlock(CRYPTO_LOCK_SSL
);
419 SSL_has_matching_session_id(const SSL
*ssl
, const unsigned char *id
,
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.
431 if (id_len
> sizeof r
.session_id
)
434 r
.ssl_version
= ssl
->version
;
435 r
.session_id_length
= id_len
;
436 memcpy(r
.session_id
, id
, id_len
);
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
);
445 SSL_CTX_set_purpose(SSL_CTX
*s
, int purpose
)
447 return (X509_VERIFY_PARAM_set_purpose(s
->param
, purpose
));
451 SSL_set_purpose(SSL
*s
, int purpose
)
453 return (X509_VERIFY_PARAM_set_purpose(s
->param
, purpose
));
457 SSL_CTX_set_trust(SSL_CTX
*s
, int trust
)
459 return (X509_VERIFY_PARAM_set_trust(s
->param
, trust
));
463 SSL_set_trust(SSL
*s
, int trust
)
465 return (X509_VERIFY_PARAM_set_trust(s
->param
, trust
));
469 SSL_CTX_set1_param(SSL_CTX
*ctx
, X509_VERIFY_PARAM
*vpm
)
471 return (X509_VERIFY_PARAM_set1(ctx
->param
, vpm
));
475 SSL_set1_param(SSL
*ssl
, X509_VERIFY_PARAM
*vpm
)
477 return (X509_VERIFY_PARAM_set1(ssl
->param
, vpm
));
488 i
= CRYPTO_add(&s
->references
, -1, CRYPTO_LOCK_SSL
);
493 X509_VERIFY_PARAM_free(s
->param
);
495 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL
, s
, &s
->ex_data
);
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
);
506 if (s
->rbio
!= s
->wbio
)
507 BIO_free_all(s
->rbio
);
508 BIO_free_all(s
->wbio
);
510 if (s
->init_buf
!= NULL
)
511 BUF_MEM_free(s
->init_buf
);
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
);
519 /* Make the next call work :-) */
520 if (s
->session
!= NULL
) {
521 ssl_clear_bad_session(s
);
522 SSL_SESSION_free(s
->session
);
525 ssl_clear_cipher_ctx(s
);
526 ssl_clear_hash_ctx(&s
->read_hash
);
527 ssl_clear_hash_ctx(&s
->write_hash
);
530 ssl_cert_free(s
->cert
);
531 /* Free up if allocated */
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
);
544 if (s
->client_CA
!= NULL
)
545 sk_X509_NAME_pop_free(s
->client_CA
, X509_NAME_free
);
547 if (s
->method
!= NULL
)
548 s
->method
->ssl_free(s
);
550 SSL_CTX_free(s
->ctx
);
553 free(s
->next_proto_negotiated
);
554 free(s
->alpn_client_proto_list
);
556 #ifndef OPENSSL_NO_SRTP
557 if (s
->srtp_profiles
)
558 sk_SRTP_PROTECTION_PROFILE_free(s
->srtp_profiles
);
565 SSL_set_bio(SSL
*s
, BIO
*rbio
, BIO
*wbio
)
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
;
575 if (s
->rbio
!= rbio
&& s
->rbio
!= s
->wbio
)
576 BIO_free_all(s
->rbio
);
578 BIO_free_all(s
->wbio
);
584 SSL_get_rbio(const SSL
*s
)
590 SSL_get_wbio(const SSL
*s
)
596 SSL_get_fd(const SSL
*s
)
598 return (SSL_get_rfd(s
));
602 SSL_get_rfd(const SSL
*s
)
608 r
= BIO_find_type(b
, BIO_TYPE_DESCRIPTOR
);
615 SSL_get_wfd(const SSL
*s
)
621 r
= BIO_find_type(b
, BIO_TYPE_DESCRIPTOR
);
628 SSL_set_fd(SSL
*s
, int fd
)
633 bio
= BIO_new(BIO_s_socket());
636 SSLerr(SSL_F_SSL_SET_FD
, ERR_R_BUF_LIB
);
639 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
640 SSL_set_bio(s
, bio
, bio
);
647 SSL_set_wfd(SSL
*s
, int fd
)
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());
657 SSLerr(SSL_F_SSL_SET_WFD
, ERR_R_BUF_LIB
);
660 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
661 SSL_set_bio(s
, SSL_get_rbio(s
), bio
);
663 SSL_set_bio(s
, SSL_get_rbio(s
), SSL_get_rbio(s
));
670 SSL_set_rfd(SSL
*s
, int fd
)
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());
680 SSLerr(SSL_F_SSL_SET_RFD
, ERR_R_BUF_LIB
);
683 BIO_set_fd(bio
, fd
, BIO_NOCLOSE
);
684 SSL_set_bio(s
, bio
, SSL_get_wbio(s
));
686 SSL_set_bio(s
, SSL_get_wbio(s
), SSL_get_wbio(s
));
693 /* return length of latest Finished message we sent, copy to 'buf' */
695 SSL_get_finished(const SSL
*s
, void *buf
, size_t count
)
700 ret
= s
->s3
->tmp
.finish_md_len
;
703 memcpy(buf
, s
->s3
->tmp
.finish_md
, count
);
708 /* return length of latest Finished message we expected, copy to 'buf' */
710 SSL_get_peer_finished(const SSL
*s
, void *buf
, size_t count
)
715 ret
= s
->s3
->tmp
.peer_finish_md_len
;
718 memcpy(buf
, s
->s3
->tmp
.peer_finish_md
, count
);
725 SSL_get_verify_mode(const SSL
*s
)
727 return (s
->verify_mode
);
731 SSL_get_verify_depth(const SSL
*s
)
733 return (X509_VERIFY_PARAM_get_depth(s
->param
));
737 (*SSL_get_verify_callback(const SSL
*s
))(int, X509_STORE_CTX
*)
739 return (s
->verify_callback
);
743 SSL_CTX_get_verify_mode(const SSL_CTX
*ctx
)
745 return (ctx
->verify_mode
);
749 SSL_CTX_get_verify_depth(const SSL_CTX
*ctx
)
751 return (X509_VERIFY_PARAM_get_depth(ctx
->param
));
754 int (*SSL_CTX_get_verify_callback(const SSL_CTX
*ctx
))(int, X509_STORE_CTX
*)
756 return (ctx
->default_verify_callback
);
760 SSL_set_verify(SSL
*s
, int mode
,
761 int (*callback
)(int ok
, X509_STORE_CTX
*ctx
))
763 s
->verify_mode
= mode
;
764 if (callback
!= NULL
)
765 s
->verify_callback
= callback
;
769 SSL_set_verify_depth(SSL
*s
, int depth
)
771 X509_VERIFY_PARAM_set_depth(s
->param
, depth
);
775 SSL_set_read_ahead(SSL
*s
, int yes
)
781 SSL_get_read_ahead(const SSL
*s
)
783 return (s
->read_ahead
);
787 SSL_pending(const SSL
*s
)
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.)
797 return (s
->method
->ssl_pending(s
));
801 SSL_get_peer_certificate(const SSL
*s
)
805 if ((s
== NULL
) || (s
->session
== NULL
))
808 r
= s
->session
->peer
;
813 CRYPTO_add(&r
->references
, 1, CRYPTO_LOCK_X509
);
819 SSL_get_peer_cert_chain(const SSL
*s
)
823 if ((s
== NULL
) || (s
->session
== NULL
) ||
824 (s
->session
->sess_cert
== NULL
))
827 r
= s
->session
->sess_cert
->cert_chain
;
830 * If we are a client, cert_chain includes the peer's own
832 * if we are a server, it does not.
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
842 SSL_copy_session_id(SSL
*t
, const SSL
*f
)
846 /* Do we need to to SSL locking? */
847 SSL_set_session(t
, SSL_get_session(f
));
850 * What if we are setup as SSLv2 but want to talk SSLv3 or
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 */
860 if (f
->cert
!= NULL
) {
861 CRYPTO_add(&f
->cert
->references
, 1, CRYPTO_LOCK_SSL_CERT
);
867 SSL_set_session_id_context(t
, f
->sid_ctx
, f
->sid_ctx_length
);
870 /* Fix this so it checks all the valid key/cert options */
872 SSL_CTX_check_private_key(const SSL_CTX
*ctx
)
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
);
880 if (ctx
->cert
->key
->privatekey
== NULL
) {
881 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY
,
882 SSL_R_NO_PRIVATE_KEY_ASSIGNED
);
885 return (X509_check_private_key(ctx
->cert
->key
->x509
,
886 ctx
->cert
->key
->privatekey
));
889 /* Fix this function so that it takes an optional type parameter */
891 SSL_check_private_key(const SSL
*ssl
)
894 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY
,
895 ERR_R_PASSED_NULL_PARAMETER
);
898 if (ssl
->cert
== NULL
) {
899 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY
,
900 SSL_R_NO_CERTIFICATE_ASSIGNED
);
903 if (ssl
->cert
->key
->x509
== NULL
) {
904 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY
,
905 SSL_R_NO_CERTIFICATE_ASSIGNED
);
908 if (ssl
->cert
->key
->privatekey
== NULL
) {
909 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY
,
910 SSL_R_NO_PRIVATE_KEY_ASSIGNED
);
913 return (X509_check_private_key(ssl
->cert
->key
->x509
,
914 ssl
->cert
->key
->privatekey
));
920 if (s
->handshake_func
== NULL
)
921 SSL_set_accept_state(s
); /* Not properly initialized yet */
923 return (s
->method
->ssl_accept(s
));
929 if (s
->handshake_func
== NULL
)
930 SSL_set_connect_state(s
); /* Not properly initialized yet */
932 return (s
->method
->ssl_connect(s
));
936 SSL_get_default_timeout(const SSL
*s
)
938 return (s
->method
->get_timeout());
942 SSL_read(SSL
*s
, void *buf
, int num
)
944 if (s
->handshake_func
== NULL
) {
945 SSLerr(SSL_F_SSL_READ
, SSL_R_UNINITIALIZED
);
949 if (s
->shutdown
& SSL_RECEIVED_SHUTDOWN
) {
950 s
->rwstate
= SSL_NOTHING
;
953 return (s
->method
->ssl_read(s
, buf
, num
));
957 SSL_peek(SSL
*s
, void *buf
, int num
)
959 if (s
->handshake_func
== NULL
) {
960 SSLerr(SSL_F_SSL_PEEK
, SSL_R_UNINITIALIZED
);
964 if (s
->shutdown
& SSL_RECEIVED_SHUTDOWN
) {
967 return (s
->method
->ssl_peek(s
, buf
, num
));
971 SSL_write(SSL
*s
, const void *buf
, int num
)
973 if (s
->handshake_func
== NULL
) {
974 SSLerr(SSL_F_SSL_WRITE
, SSL_R_UNINITIALIZED
);
978 if (s
->shutdown
& SSL_SENT_SHUTDOWN
) {
979 s
->rwstate
= SSL_NOTHING
;
980 SSLerr(SSL_F_SSL_WRITE
, SSL_R_PROTOCOL_IS_SHUTDOWN
);
983 return (s
->method
->ssl_write(s
, buf
, num
));
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).
996 if (s
->handshake_func
== NULL
) {
997 SSLerr(SSL_F_SSL_SHUTDOWN
, SSL_R_UNINITIALIZED
);
1001 if ((s
!= NULL
) && !SSL_in_init(s
))
1002 return (s
->method
->ssl_shutdown(s
));
1008 SSL_renegotiate(SSL
*s
)
1010 if (s
->renegotiate
== 0)
1015 return (s
->method
->ssl_renegotiate(s
));
1019 SSL_renegotiate_abbreviated(SSL
*s
)
1021 if (s
->renegotiate
== 0)
1026 return (s
->method
->ssl_renegotiate(s
));
1030 SSL_renegotiate_pending(SSL
*s
)
1033 * Becomes true when negotiation is requested;
1034 * false again once a handshake has finished.
1036 return (s
->renegotiate
!= 0);
1040 SSL_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
)
1045 case SSL_CTRL_GET_READ_AHEAD
:
1046 return (s
->read_ahead
);
1047 case SSL_CTRL_SET_READ_AHEAD
:
1049 s
->read_ahead
= larg
;
1052 case SSL_CTRL_SET_MSG_CALLBACK_ARG
:
1053 s
->msg_callback_arg
= parg
;
1056 case SSL_CTRL_OPTIONS
:
1057 return (s
->options
|=larg
);
1058 case SSL_CTRL_CLEAR_OPTIONS
:
1059 return (s
->options
&=~larg
);
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
;
1070 case SSL_CTRL_SET_MTU
:
1071 #ifndef OPENSSL_NO_DTLS1
1072 if (larg
< (long)dtls1_min_mtu())
1075 if (SSL_IS_DTLS(s
)) {
1080 case SSL_CTRL_SET_MAX_SEND_FRAGMENT
:
1081 if (larg
< 512 || larg
> SSL3_RT_MAX_PLAIN_LENGTH
)
1083 s
->max_send_fragment
= larg
;
1085 case SSL_CTRL_GET_RI_SUPPORT
:
1087 return (s
->s3
->send_connection_binding
);
1090 return (s
->method
->ssl_ctrl(s
, cmd
, larg
, parg
));
1095 SSL_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)(void))
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
);
1105 return (s
->method
->ssl_callback_ctrl(s
, cmd
, fp
));
1109 LHASH_OF(SSL_SESSION
) *
1110 SSL_CTX_sessions(SSL_CTX
*ctx
)
1112 return (ctx
->sessions
);
1116 SSL_CTX_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, void *parg
)
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
;
1128 case SSL_CTRL_SET_MSG_CALLBACK_ARG
:
1129 ctx
->msg_callback_arg
= parg
;
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
;
1139 case SSL_CTRL_SET_SESS_CACHE_SIZE
:
1140 l
= ctx
->session_cache_size
;
1141 ctx
->session_cache_size
= larg
;
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
;
1149 case SSL_CTRL_GET_SESS_CACHE_MODE
:
1150 return (ctx
->session_cache_mode
);
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
);
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
)
1187 ctx
->max_send_fragment
= larg
;
1190 return (ctx
->method
->ssl_ctx_ctrl(ctx
, cmd
, larg
, parg
));
1195 SSL_CTX_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)(void))
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
,
1205 return (ctx
->method
->ssl_ctx_callback_ctrl(ctx
, cmd
, fp
));
1210 ssl_cipher_id_cmp(const SSL_CIPHER
*a
, const SSL_CIPHER
*b
)
1218 return ((l
> 0) ? 1:-1);
1222 ssl_cipher_ptr_id_cmp(const SSL_CIPHER
* const *ap
,
1223 const SSL_CIPHER
* const *bp
)
1227 l
= (*ap
)->id
- (*bp
)->id
;
1231 return ((l
> 0) ? 1:-1);
1235 * Return a STACK of the ciphers available for the SSL and in order of
1238 STACK_OF(SSL_CIPHER
) *
1239 SSL_get_ciphers(const SSL
*s
)
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
);
1252 * Return a STACK of the ciphers available for the SSL and in order of
1255 STACK_OF(SSL_CIPHER
) *
1256 ssl_get_ciphers_by_id(SSL
*s
)
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
);
1269 /* The old interface to get the same thing as SSL_get_ciphers(). */
1271 SSL_get_cipher_list(const SSL
*s
, int n
)
1274 STACK_OF(SSL_CIPHER
) *sk
;
1278 sk
= SSL_get_ciphers(s
);
1279 if ((sk
== NULL
) || (sk_SSL_CIPHER_num(sk
) <= n
))
1281 c
= sk_SSL_CIPHER_value(sk
, n
);
1287 /* Specify the ciphers to be used by default by the SSL_CTX. */
1289 SSL_CTX_set_cipher_list(SSL_CTX
*ctx
, const char *str
)
1291 STACK_OF(SSL_CIPHER
) *sk
;
1293 sk
= ssl_create_cipher_list(ctx
->method
, &ctx
->cipher_list
,
1294 &ctx
->cipher_list_by_id
, str
);
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
1306 else if (sk_SSL_CIPHER_num(sk
) == 0) {
1307 SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST
, SSL_R_NO_CIPHER_MATCH
);
1313 /* Specify the ciphers to be used by the SSL. */
1315 SSL_set_cipher_list(SSL
*s
, const char *str
)
1317 STACK_OF(SSL_CIPHER
) *sk
;
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 */
1324 else if (sk_SSL_CIPHER_num(sk
) == 0) {
1325 SSLerr(SSL_F_SSL_SET_CIPHER_LIST
, SSL_R_NO_CIPHER_MATCH
);
1331 /* works well for SSLv2, not so good for SSLv3 */
1333 SSL_get_shared_ciphers(const SSL
*s
, char *buf
, int len
)
1336 STACK_OF(SSL_CIPHER
) *sk
;
1341 if (s
->session
== NULL
|| s
->session
->ciphers
== NULL
|| len
< 2)
1344 sk
= s
->session
->ciphers
;
1345 if (sk_SSL_CIPHER_num(sk
) == 0)
1349 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
1350 c
= sk_SSL_CIPHER_value(sk
, i
);
1352 if (strlcat(buf
, c
->name
, len
) >= len
||
1353 (curlen
= strlcat(buf
, ":", len
)) >= len
) {
1354 /* remove truncated cipher from list */
1359 /* remove trailing colon */
1360 if ((end
= strrchr(buf
, ':')) != NULL
)
1366 ssl_cipher_list_to_bytes(SSL
*s
, STACK_OF(SSL_CIPHER
) *sk
, unsigned char *p
)
1376 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
1377 c
= sk_SSL_CIPHER_value(sk
, i
);
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
))
1384 s2n(ssl3_cipher_get_value(c
), p
);
1388 * If p == q, no ciphers and caller indicates an error. Otherwise
1389 * add SCSV if not renegotiating.
1391 if (p
!= q
&& !s
->renegotiate
)
1392 s2n(SSL3_CK_SCSV
& SSL3_CK_VALUE_MASK
, p
);
1397 STACK_OF(SSL_CIPHER
) *
1398 ssl_bytes_to_cipher_list(SSL
*s
, const unsigned char *p
, int num
)
1401 const SSL_CIPHER
*c
;
1402 STACK_OF(SSL_CIPHER
) *sk
= NULL
;
1403 unsigned long cipher_id
;
1404 uint16_t cipher_value
, max_version
;
1407 s
->s3
->send_connection_binding
= 0;
1410 * RFC 5246 section 7.4.1.2 defines the interval as [2,2^16-2].
1412 if (num
< 2 || num
> 0x10000 - 2) {
1413 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST
,
1414 SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST
);
1418 if ((sk
= sk_SSL_CIPHER_new_null()) == NULL
) {
1419 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST
, ERR_R_MALLOC_FAILURE
);
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
);
1431 cipher_id
= SSL3_CK_ID
| cipher_value
;
1433 if (s
->s3
!= NULL
&& cipher_id
== SSL3_CK_SCSV
) {
1435 * TLS_EMPTY_RENEGOTIATION_INFO_SCSV is fatal if
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
);
1446 s
->s3
->send_connection_binding
= 1;
1450 if (cipher_id
== SSL3_CK_FALLBACK_SCSV
) {
1452 * TLS_FALLBACK_SCSV indicates that the client
1453 * previously tried a higher protocol version.
1454 * Fail if the current version is an unexpected
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
);
1462 ssl3_send_alert(s
, SSL3_AL_FATAL
,
1463 SSL_AD_INAPPROPRIATE_FALLBACK
);
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
);
1481 sk_SSL_CIPHER_free(sk
);
1488 * Return a servername extension value if provided in Client Hello, or NULL.
1489 * So far, only host_name types are defined (RFC 3546).
1492 SSL_get_servername(const SSL
*s
, const int type
)
1494 if (type
!= TLSEXT_NAMETYPE_host_name
)
1497 return (s
->session
&& !s
->tlsext_hostname
?
1498 s
->session
->tlsext_hostname
:
1499 s
->tlsext_hostname
);
1503 SSL_get_servername_type(const SSL
*s
)
1506 (!s
->tlsext_hostname
?
1507 s
->session
->tlsext_hostname
: s
->tlsext_hostname
))
1508 return (TLSEXT_NAMETYPE_host_name
);
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.
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.
1521 * The current, but experimental algorithm for selecting the protocol is:
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.
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.
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.
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.
1540 * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
1541 * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
1544 SSL_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
)
1549 const unsigned char *result
;
1550 int status
= OPENSSL_NPN_UNSUPPORTED
;
1553 * For each protocol in server preference order,
1554 * see if we support it.
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
;
1573 /* There's no overlap between our protocols and the server's list. */
1575 status
= OPENSSL_NPN_NO_OVERLAP
;
1578 *out
= (unsigned char *) result
+ 1;
1579 *outlen
= result
[0];
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.
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.
1593 SSL_get0_next_proto_negotiated(const SSL
*s
, const unsigned char **data
,
1596 *data
= s
->next_proto_negotiated
;
1600 *len
= s
->next_proto_negotiated_len
;
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
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.
1616 SSL_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
)
1619 ctx
->next_protos_advertised_cb
= cb
;
1620 ctx
->next_protos_advertised_cb_arg
= arg
;
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.
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.
1635 SSL_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
)
1639 ctx
->next_proto_select_cb
= cb
;
1640 ctx
->next_proto_select_cb_arg
= arg
;
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.
1649 SSL_CTX_set_alpn_protos(SSL_CTX
*ctx
, const unsigned char *protos
,
1650 unsigned int protos_len
)
1652 free(ctx
->alpn_client_proto_list
);
1653 if ((ctx
->alpn_client_proto_list
= malloc(protos_len
)) == NULL
)
1655 memcpy(ctx
->alpn_client_proto_list
, protos
, protos_len
);
1656 ctx
->alpn_client_proto_list_len
= protos_len
;
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.
1667 SSL_set_alpn_protos(SSL
*ssl
, const unsigned char* protos
,
1668 unsigned int protos_len
)
1670 free(ssl
->alpn_client_proto_list
);
1671 if ((ssl
->alpn_client_proto_list
= malloc(protos_len
)) == NULL
)
1673 memcpy(ssl
->alpn_client_proto_list
, protos
, protos_len
);
1674 ssl
->alpn_client_proto_list_len
= protos_len
;
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.
1685 SSL_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
)
1689 ctx
->alpn_select_cb
= cb
;
1690 ctx
->alpn_select_cb_arg
= arg
;
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.
1700 SSL_get0_alpn_selected(const SSL
*ssl
, const unsigned char **data
,
1706 if (ssl
->s3
!= NULL
) {
1707 *data
= ssl
->s3
->alpn_selected
;
1708 *len
= ssl
->s3
->alpn_selected_len
;
1713 SSL_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
,
1717 return (s
->method
->ssl3_enc
->export_keying_material(s
, out
, olen
,
1718 label
, llen
, p
, plen
, use_context
));
1721 static unsigned long
1722 ssl_session_hash(const SSL_SESSION
*a
)
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);
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.
1742 ssl_session_cmp(const SSL_SESSION
*a
, const SSL_SESSION
*b
)
1744 if (a
->ssl_version
!= b
->ssl_version
)
1746 if (a
->session_id_length
!= b
->session_id_length
)
1748 if (timingsafe_memcmp(a
->session_id
, b
->session_id
, a
->session_id_length
) != 0)
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
1760 IMPLEMENT_LHASH_HASH_FN(ssl_session
, SSL_SESSION
)
1762 IMPLEMENT_LHASH_COMP_FN(ssl_session
, SSL_SESSION
)
1765 SSL_CTX_new(const SSL_METHOD
*meth
)
1767 SSL_CTX
*ret
= NULL
;
1770 SSLerr(SSL_F_SSL_CTX_NEW
, SSL_R_NULL_SSL_METHOD_PASSED
);
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
);
1779 ret
= calloc(1, sizeof(SSL_CTX
));
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
;
1791 /* We take the system default */
1792 ret
->session_timeout
= meth
->get_timeout();
1794 ret
->new_session_cb
= 0;
1795 ret
->remove_session_cb
= 0;
1796 ret
->get_session_cb
= 0;
1797 ret
->generate_session_id
= 0;
1799 memset((char *)&ret
->stats
, 0, sizeof(ret
->stats
));
1801 ret
->references
= 1;
1802 ret
->quiet_shutdown
= 0;
1804 ret
->info_callback
= NULL
;
1806 ret
->app_verify_callback
= 0;
1807 ret
->app_verify_arg
= NULL
;
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
)
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;
1825 ret
->sessions
= lh_SSL_SESSION_new();
1826 if (ret
->sessions
== NULL
)
1828 ret
->cert_store
= X509_STORE_new();
1829 if (ret
->cert_store
== NULL
)
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
);
1840 ret
->param
= X509_VERIFY_PARAM_new();
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
);
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
);
1855 if ((ret
->client_CA
= sk_X509_NAME_new_null()) == NULL
)
1858 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX
, ret
, &ret
->ex_data
);
1860 ret
->extra_certs
= NULL
;
1862 ret
->max_send_fragment
= SSL3_RT_MAX_PLAIN_LENGTH
;
1864 ret
->tlsext_servername_callback
= 0;
1865 ret
->tlsext_servername_arg
= NULL
;
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);
1872 ret
->tlsext_status_cb
= 0;
1873 ret
->tlsext_status_arg
= NULL
;
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 */
1885 eng
= ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO
));
1888 ENGINE_load_builtin_engines();
1889 eng
= ENGINE_by_id(eng_str(
1890 OPENSSL_SSL_CLIENT_ENGINE_AUTO
));
1892 if (!eng
|| !SSL_CTX_set_client_cert_engine(ret
, eng
))
1898 * Default is to connect to non-RI servers. When RI is more widely
1899 * deployed might change this.
1901 ret
->options
|= SSL_OP_LEGACY_SERVER_CONNECT
;
1905 SSLerr(SSL_F_SSL_CTX_NEW
, ERR_R_MALLOC_FAILURE
);
1912 SSL_CTX_free(SSL_CTX
*a
)
1919 i
= CRYPTO_add(&a
->references
, -1, CRYPTO_LOCK_SSL_CTX
);
1924 X509_VERIFY_PARAM_free(a
->param
);
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].)
1935 if (a
->sessions
!= NULL
)
1936 SSL_CTX_flush_sessions(a
, 0);
1938 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX
, a
, &a
->ex_data
);
1940 if (a
->sessions
!= NULL
)
1941 lh_SSL_SESSION_free(a
->sessions
);
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
);
1956 #ifndef OPENSSL_NO_SRTP
1957 if (a
->srtp_profiles
)
1958 sk_SRTP_PROTECTION_PROFILE_free(a
->srtp_profiles
);
1961 #ifndef OPENSSL_NO_ENGINE
1962 if (a
->client_cert_engine
)
1963 ENGINE_finish(a
->client_cert_engine
);
1966 free(a
->alpn_client_proto_list
);
1972 SSL_CTX_set_default_passwd_cb(SSL_CTX
*ctx
, pem_password_cb
*cb
)
1974 ctx
->default_passwd_callback
= cb
;
1978 SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX
*ctx
, void *u
)
1980 ctx
->default_passwd_callback_userdata
= u
;
1984 SSL_CTX_set_cert_verify_callback(SSL_CTX
*ctx
, int (*cb
)(X509_STORE_CTX
*,
1987 ctx
->app_verify_callback
= cb
;
1988 ctx
->app_verify_arg
= arg
;
1992 SSL_CTX_set_verify(SSL_CTX
*ctx
, int mode
, int (*cb
)(int, X509_STORE_CTX
*))
1994 ctx
->verify_mode
= mode
;
1995 ctx
->default_verify_callback
= cb
;
1999 SSL_CTX_set_verify_depth(SSL_CTX
*ctx
, int depth
)
2001 X509_VERIFY_PARAM_set_depth(ctx
->param
, depth
);
2005 ssl_set_cert_masks(CERT
*c
, const SSL_CIPHER
*cipher
)
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
;
2013 EVP_PKEY
*ecc_pkey
= NULL
;
2014 int signature_nid
= 0, pk_nid
= 0, md_nid
= 0;
2019 dh_tmp
= (c
->dh_tmp
!= NULL
|| c
->dh_tmp_cb
!= NULL
||
2020 c
->dh_tmp_auto
!= 0);
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
);
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
;
2048 if (rsa_enc
|| rsa_sign
)
2057 * An ECC certificate may be usable for ECDH and/or
2058 * ECDSA cipher suites depending on the key usage extension.
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
);
2075 if (pk_nid
== NID_rsaEncryption
|| pk_nid
== NID_rsa
) {
2079 if (pk_nid
== NID_X9_62_id_ecPublicKey
) {
2088 if (have_ecdh_tmp
) {
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)))
2104 ssl_check_srvr_ecc_cert_and_alg(X509
*x
, SSL
*s
)
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
;
2110 alg_k
= cs
->algorithm_mkey
;
2111 alg_a
= cs
->algorithm_auth
;
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
);
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
);
2126 if ((alg_k
& SSL_kECDHe
) && TLS1_get_version(s
) <
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
);
2135 if ((alg_k
& SSL_kECDHr
) && TLS1_get_version(s
) <
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
);
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
);
2155 /* all checks are ok */
2159 /* THIS NEEDS CLEANING UP */
2161 ssl_get_server_send_pkey(const SSL
*s
)
2163 unsigned long alg_k
, alg_a
;
2168 ssl_set_cert_masks(c
, s
->s3
->tmp
.new_cipher
);
2170 alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
2171 alg_a
= s
->s3
->tmp
.new_cipher
->algorithm_auth
;
2173 if (alg_k
& (SSL_kECDHr
|SSL_kECDHe
)) {
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.
2187 } else if (alg_a
& SSL_aECDSA
) {
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
;
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
);
2203 return (c
->pkeys
+ i
);
2207 ssl_get_server_send_cert(const SSL
*s
)
2211 cpk
= ssl_get_server_send_pkey(s
);
2218 ssl_get_sign_pkey(SSL
*s
, const SSL_CIPHER
*cipher
, const EVP_MD
**pmd
)
2220 unsigned long alg_a
;
2224 alg_a
= cipher
->algorithm_auth
;
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
))
2239 SSLerr(SSL_F_SSL_GET_SIGN_PKEY
, ERR_R_INTERNAL_ERROR
);
2243 *pmd
= c
->pkeys
[idx
].digest
;
2244 return (c
->pkeys
[idx
].privatekey
);
2248 ssl_get_auto_dh(SSL
*s
)
2254 if (s
->cert
->dh_tmp_auto
== 2) {
2256 } else if (s
->s3
->tmp
.new_cipher
->algorithm_auth
& SSL_aNULL
) {
2258 if (s
->s3
->tmp
.new_cipher
->strength_bits
== 256)
2261 if ((cpk
= ssl_get_server_send_pkey(s
)) == NULL
)
2263 if (cpk
->privatekey
== NULL
|| cpk
->privatekey
->pkey
.dh
== NULL
)
2265 keylen
= EVP_PKEY_bits(cpk
->privatekey
);
2268 if ((dhp
= DH_new()) == NULL
)
2273 BN_set_word(dhp
->g
, 2);
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
);
2286 dhp
->p
= get_rfc2409_prime_1024(NULL
);
2288 if (dhp
->p
== NULL
|| dhp
->g
== NULL
) {
2296 ssl_update_cache(SSL
*s
, int mode
)
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 :-)
2304 if (s
->session
->session_id_length
== 0)
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
);
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
));
2328 SSL_get_ssl_method(SSL
*s
)
2334 SSL_set_ssl_method(SSL
*s
, const SSL_METHOD
*meth
)
2339 if (s
->method
!= meth
) {
2340 if (s
->handshake_func
!= NULL
)
2341 conn
= (s
->handshake_func
== s
->method
->ssl_connect
);
2343 if (s
->method
->version
== meth
->version
)
2346 s
->method
->ssl_free(s
);
2348 ret
= s
->method
->ssl_new(s
);
2352 s
->handshake_func
= meth
->ssl_connect
;
2354 s
->handshake_func
= meth
->ssl_accept
;
2360 SSL_get_error(const SSL
*s
, int i
)
2367 return (SSL_ERROR_NONE
);
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
);
2375 return (SSL_ERROR_SSL
);
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
)) {
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.
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
);
2401 return (SSL_ERROR_SYSCALL
); /* unknown */
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
)) {
2411 * See above (SSL_want_read(s) with
2412 * BIO_should_write(bio))
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
);
2422 return (SSL_ERROR_SYSCALL
);
2425 if ((i
< 0) && SSL_want_x509_lookup(s
)) {
2426 return (SSL_ERROR_WANT_X509_LOOKUP
);
2430 if ((s
->shutdown
& SSL_RECEIVED_SHUTDOWN
) &&
2431 (s
->s3
->warn_alert
== SSL_AD_CLOSE_NOTIFY
))
2432 return (SSL_ERROR_ZERO_RETURN
);
2434 return (SSL_ERROR_SYSCALL
);
2438 SSL_do_handshake(SSL
*s
)
2442 if (s
->handshake_func
== NULL
) {
2443 SSLerr(SSL_F_SSL_DO_HANDSHAKE
, SSL_R_CONNECTION_TYPE_NOT_SET
);
2447 s
->method
->ssl_renegotiate_check(s
);
2449 if (SSL_in_init(s
) || SSL_in_before(s
)) {
2450 ret
= s
->handshake_func(s
);
2456 * For the next 2 functions, SSL_clear() sets shutdown and so
2457 * one of these calls will reset it
2460 SSL_set_accept_state(SSL
*s
)
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
);
2473 SSL_set_connect_state(SSL
*s
)
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
);
2486 ssl_undefined_function(SSL
*s
)
2488 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION
,
2489 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2494 ssl_undefined_void_function(void)
2496 SSLerr(SSL_F_SSL_UNDEFINED_VOID_FUNCTION
,
2497 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2502 ssl_undefined_const_function(const SSL
*s
)
2504 SSLerr(SSL_F_SSL_UNDEFINED_CONST_FUNCTION
,
2505 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2510 ssl_version_string(int ver
)
2514 return (SSL_TXT_DTLS1
);
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
);
2527 SSL_get_version(const SSL
*s
)
2529 return ssl_version_string(s
->version
);
2533 ssl_max_server_version(SSL
*s
)
2535 uint16_t max_version
;
2538 * The SSL method will be changed during version negotiation, as such
2539 * we want to use the SSL method from the context.
2541 max_version
= s
->ctx
->method
->version
;
2544 return (DTLS1_VERSION
);
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
);
2562 STACK_OF(X509_NAME
) *sk
;
2567 if ((ret
= SSL_new(SSL_get_SSL_CTX(s
))) == NULL
)
2570 ret
->version
= s
->version
;
2571 ret
->type
= s
->type
;
2572 ret
->method
= s
->method
;
2574 if (s
->session
!= NULL
) {
2575 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
2576 SSL_copy_session_id(ret
, s
);
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.
2585 ret
->method
->ssl_free(ret
);
2586 ret
->method
= s
->method
;
2587 ret
->method
->ssl_new(ret
);
2589 if (s
->cert
!= NULL
) {
2590 if (ret
->cert
!= NULL
) {
2591 ssl_cert_free(ret
->cert
);
2593 ret
->cert
= ssl_cert_dup(s
->cert
);
2594 if (ret
->cert
== NULL
)
2598 SSL_set_session_id_context(ret
,
2599 s
->sid_ctx
, s
->sid_ctx_length
);
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
;
2613 SSL_set_info_callback(ret
, SSL_get_info_callback(s
));
2615 ret
->debug
= s
->debug
;
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
))
2622 /* setup rbio, and wbio */
2623 if (s
->rbio
!= NULL
) {
2624 if (!BIO_dup_state(s
->rbio
,(char *)&ret
->rbio
))
2627 if (s
->wbio
!= NULL
) {
2628 if (s
->wbio
!= s
->rbio
) {
2629 if (!BIO_dup_state(s
->wbio
,(char *)&ret
->wbio
))
2632 ret
->wbio
= ret
->rbio
;
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
;
2647 * Would have to copy ret->init_buf, ret->init_msg, ret->init_num,
2654 X509_VERIFY_PARAM_inherit(ret
->param
, s
->param
);
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
)
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
)
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
) {
2692 ssl_clear_cipher_ctx(SSL
*s
)
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
;
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
;
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
;
2712 /* Fix this function so that it takes an optional type parameter */
2714 SSL_get_certificate(const SSL
*s
)
2716 if (s
->cert
!= NULL
)
2717 return (s
->cert
->key
->x509
);
2722 /* Fix this function so that it takes an optional type parameter */
2724 SSL_get_privatekey(SSL
*s
)
2726 if (s
->cert
!= NULL
)
2727 return (s
->cert
->key
->privatekey
);
2733 SSL_get_current_cipher(const SSL
*s
)
2735 if ((s
->session
!= NULL
) && (s
->session
->cipher
!= NULL
))
2736 return (s
->session
->cipher
);
2740 SSL_get_current_compression(SSL
*s
)
2746 SSL_get_current_expansion(SSL
*s
)
2752 ssl_init_wbio_buffer(SSL
*s
, int push
)
2756 if (s
->bbio
== NULL
) {
2757 bbio
= BIO_new(BIO_f_buffer());
2763 if (s
->bbio
== s
->wbio
)
2764 s
->wbio
= BIO_pop(s
->wbio
);
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
);
2773 if (s
->wbio
!= bbio
)
2774 s
->wbio
= BIO_push(bbio
, s
->wbio
);
2776 if (s
->wbio
== bbio
)
2777 s
->wbio
= BIO_pop(bbio
);
2783 ssl_free_wbio_buffer(SSL
*s
)
2788 if (s
->bbio
== NULL
)
2791 if (s
->bbio
== s
->wbio
) {
2792 /* remove buffering */
2793 s
->wbio
= BIO_pop(s
->wbio
);
2800 SSL_CTX_set_quiet_shutdown(SSL_CTX
*ctx
, int mode
)
2802 ctx
->quiet_shutdown
= mode
;
2806 SSL_CTX_get_quiet_shutdown(const SSL_CTX
*ctx
)
2808 return (ctx
->quiet_shutdown
);
2812 SSL_set_quiet_shutdown(SSL
*s
, int mode
)
2814 s
->quiet_shutdown
= mode
;
2818 SSL_get_quiet_shutdown(const SSL
*s
)
2820 return (s
->quiet_shutdown
);
2824 SSL_set_shutdown(SSL
*s
, int mode
)
2830 SSL_get_shutdown(const SSL
*s
)
2832 return (s
->shutdown
);
2836 SSL_version(const SSL
*s
)
2838 return (s
->version
);
2842 SSL_get_SSL_CTX(const SSL
*ssl
)
2848 SSL_set_SSL_CTX(SSL
*ssl
, SSL_CTX
* ctx
)
2850 if (ssl
->ctx
== ctx
)
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 */
2864 SSL_CTX_set_default_verify_paths(SSL_CTX
*ctx
)
2866 return (X509_STORE_set_default_paths(ctx
->cert_store
));
2870 SSL_CTX_load_verify_locations(SSL_CTX
*ctx
, const char *CAfile
,
2873 return (X509_STORE_load_locations(ctx
->cert_store
, CAfile
, CApath
));
2877 SSL_CTX_load_verify_mem(SSL_CTX
*ctx
, void *buf
, int len
)
2879 return (X509_STORE_load_mem(ctx
->cert_store
, buf
, len
));
2883 SSL_set_info_callback(SSL
*ssl
, void (*cb
)(const SSL
*ssl
, int type
, int val
))
2885 ssl
->info_callback
= cb
;
2888 void (*SSL_get_info_callback(const SSL
*ssl
))(const SSL
*ssl
, int type
, int val
)
2890 return (ssl
->info_callback
);
2894 SSL_state(const SSL
*ssl
)
2896 return (ssl
->state
);
2900 SSL_set_state(SSL
*ssl
, int state
)
2906 SSL_set_verify_result(SSL
*ssl
, long arg
)
2908 ssl
->verify_result
= arg
;
2912 SSL_get_verify_result(const SSL
*ssl
)
2914 return (ssl
->verify_result
);
2918 SSL_get_ex_new_index(long argl
, void *argp
, CRYPTO_EX_new
*new_func
,
2919 CRYPTO_EX_dup
*dup_func
, CRYPTO_EX_free
*free_func
)
2921 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL
, argl
, argp
,
2922 new_func
, dup_func
, free_func
));
2926 SSL_set_ex_data(SSL
*s
, int idx
, void *arg
)
2928 return (CRYPTO_set_ex_data(&s
->ex_data
, idx
, arg
));
2932 SSL_get_ex_data(const SSL
*s
, int idx
)
2934 return (CRYPTO_get_ex_data(&s
->ex_data
, idx
));
2938 SSL_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
)
2941 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX
, argl
, argp
,
2942 new_func
, dup_func
, free_func
));
2946 SSL_CTX_set_ex_data(SSL_CTX
*s
, int idx
, void *arg
)
2948 return (CRYPTO_set_ex_data(&s
->ex_data
, idx
, arg
));
2952 SSL_CTX_get_ex_data(const SSL_CTX
*s
, int idx
)
2954 return (CRYPTO_get_ex_data(&s
->ex_data
, idx
));
2964 SSL_CTX_get_cert_store(const SSL_CTX
*ctx
)
2966 return (ctx
->cert_store
);
2970 SSL_CTX_set_cert_store(SSL_CTX
*ctx
, X509_STORE
*store
)
2972 if (ctx
->cert_store
!= NULL
)
2973 X509_STORE_free(ctx
->cert_store
);
2974 ctx
->cert_store
= store
;
2978 SSL_want(const SSL
*s
)
2980 return (s
->rwstate
);
2984 SSL_CTX_set_tmp_rsa_callback(SSL_CTX
*ctx
, RSA
*(*cb
)(SSL
*ssl
, int is_export
,
2987 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_RSA_CB
,(void (*)(void))cb
);
2991 SSL_set_tmp_rsa_callback(SSL
*ssl
, RSA
*(*cb
)(SSL
*ssl
, int is_export
,
2994 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_RSA_CB
,(void (*)(void))cb
);
2998 SSL_CTX_set_tmp_dh_callback(SSL_CTX
*ctx
, DH
*(*dh
)(SSL
*ssl
, int is_export
,
3001 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_DH_CB
,(void (*)(void))dh
);
3005 SSL_set_tmp_dh_callback(SSL
*ssl
, DH
*(*dh
)(SSL
*ssl
, int is_export
,
3008 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_DH_CB
,(void (*)(void))dh
);
3012 SSL_CTX_set_tmp_ecdh_callback(SSL_CTX
*ctx
, EC_KEY
*(*ecdh
)(SSL
*ssl
,
3013 int is_export
, int keylength
))
3015 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_TMP_ECDH_CB
,
3016 (void (*)(void))ecdh
);
3020 SSL_set_tmp_ecdh_callback(SSL
*ssl
, EC_KEY
*(*ecdh
)(SSL
*ssl
, int is_export
,
3023 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_TMP_ECDH_CB
,(void (*)(void))ecdh
);
3028 SSL_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
))
3031 SSL_CTX_callback_ctrl(ctx
, SSL_CTRL_SET_MSG_CALLBACK
,
3032 (void (*)(void))cb
);
3036 SSL_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
))
3039 SSL_callback_ctrl(ssl
, SSL_CTRL_SET_MSG_CALLBACK
, (void (*)(void))cb
);
3043 ssl_clear_hash_ctx(EVP_MD_CTX
**hash
)
3046 EVP_MD_CTX_destroy(*hash
);
3051 SSL_set_debug(SSL
*s
, int debug
)
3057 SSL_cache_hit(SSL
*s
)
3062 IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER
, SSL_CIPHER
, ssl_cipher_id
);