Lines Matching +full:- +full:s

2  * Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
40 * send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or
43 int ssl3_do_write(SSL *s, int type) in ssl3_do_write() argument
48 ret = ssl3_write_bytes(s, type, &s->init_buf->data[s->init_off], in ssl3_do_write()
49 s->init_num, &written); in ssl3_do_write()
51 return -1; in ssl3_do_write()
54 * should not be done for 'Hello Request's, but in that case we'll in ssl3_do_write()
58 if (!SSL_IS_TLS13(s) || (s->statem.hand_state != TLS_ST_SW_SESSION_TICKET in ssl3_do_write()
59 && s->statem.hand_state != TLS_ST_CW_KEY_UPDATE in ssl3_do_write()
60 && s->statem.hand_state != TLS_ST_SW_KEY_UPDATE)) in ssl3_do_write()
61 if (!ssl3_finish_mac(s, in ssl3_do_write()
62 (unsigned char *)&s->init_buf->data[s->init_off], in ssl3_do_write()
64 return -1; in ssl3_do_write()
65 if (written == s->init_num) { in ssl3_do_write()
66 if (s->msg_callback) in ssl3_do_write()
67 s->msg_callback(1, s->version, type, s->init_buf->data, in ssl3_do_write()
68 (size_t)(s->init_off + s->init_num), s, in ssl3_do_write()
69 s->msg_callback_arg); in ssl3_do_write()
72 s->init_off += written; in ssl3_do_write()
73 s->init_num -= written; in ssl3_do_write()
77 int tls_close_construct_packet(SSL *s, WPACKET *pkt, int htype) in tls_close_construct_packet() argument
85 s->init_num = (int)msglen; in tls_close_construct_packet()
86 s->init_off = 0; in tls_close_construct_packet()
91 int tls_setup_handshake(SSL *s) in tls_setup_handshake() argument
95 if (!ssl3_init_finished_mac(s)) { in tls_setup_handshake()
101 memset(s->ext.extflags, 0, sizeof(s->ext.extflags)); in tls_setup_handshake()
103 if (ssl_get_min_max_version(s, &ver_min, &ver_max, NULL) != 0) { in tls_setup_handshake()
104 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_NO_PROTOCOLS_AVAILABLE); in tls_setup_handshake()
108 /* Sanity check that we have MD5-SHA1 if we need it */ in tls_setup_handshake()
109 if (s->ctx->ssl_digest_methods[SSL_MD_MD5_SHA1_IDX] == NULL) { in tls_setup_handshake()
112 /* We don't have MD5-SHA1 - do we need it? */ in tls_setup_handshake()
113 if (SSL_IS_DTLS(s)) { in tls_setup_handshake()
121 SSLfatal_data(s, SSL_AD_HANDSHAKE_FAILURE, in tls_setup_handshake()
124 " MD5-SHA1 digest but it is not available" in tls_setup_handshake()
132 if (SSL_IS_DTLS(s)) { in tls_setup_handshake()
134 ok = SSL_set_min_proto_version(s, DTLS1_2_VERSION); in tls_setup_handshake()
137 ok = SSL_set_min_proto_version(s, TLS1_2_VERSION); in tls_setup_handshake()
141 SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE, ERR_R_INTERNAL_ERROR); in tls_setup_handshake()
147 if (s->server) { in tls_setup_handshake()
148 STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(s); in tls_setup_handshake()
159 if (SSL_IS_DTLS(s)) { in tls_setup_handshake()
160 if (DTLS_VERSION_GE(ver_max, c->min_dtls) && in tls_setup_handshake()
161 DTLS_VERSION_LE(ver_max, c->max_dtls)) in tls_setup_handshake()
163 } else if (ver_max >= c->min_tls && ver_max <= c->max_tls) { in tls_setup_handshake()
170 SSLfatal_data(s, SSL_AD_HANDSHAKE_FAILURE, in tls_setup_handshake()
176 if (SSL_IS_FIRST_HANDSHAKE(s)) { in tls_setup_handshake()
177 /* N.B. s->session_ctx == s->ctx here */ in tls_setup_handshake()
178 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_accept); in tls_setup_handshake()
180 /* N.B. s->ctx may not equal s->session_ctx */ in tls_setup_handshake()
181 ssl_tsan_counter(s->ctx, &s->ctx->stats.sess_accept_renegotiate); in tls_setup_handshake()
183 s->s3.tmp.cert_request = 0; in tls_setup_handshake()
186 if (SSL_IS_FIRST_HANDSHAKE(s)) in tls_setup_handshake()
187 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_connect); in tls_setup_handshake()
189 ssl_tsan_counter(s->session_ctx, in tls_setup_handshake()
190 &s->session_ctx->stats.sess_connect_renegotiate); in tls_setup_handshake()
193 memset(s->s3.client_random, 0, sizeof(s->s3.client_random)); in tls_setup_handshake()
194 s->hit = 0; in tls_setup_handshake()
196 s->s3.tmp.cert_req = 0; in tls_setup_handshake()
198 if (SSL_IS_DTLS(s)) in tls_setup_handshake()
199 s->statem.use_timer = 1; in tls_setup_handshake()
206 * Size of the to-be-signed TLS13 data, without the hash size itself:
212 static int get_cert_verify_tbs_data(SSL *s, unsigned char *tls13tbs, in get_cert_verify_tbs_data() argument
228 if (SSL_IS_TLS13(s)) { in get_cert_verify_tbs_data()
231 /* Set the first 64 bytes of to-be-signed data to octet 32 */ in get_cert_verify_tbs_data()
234 if (s->statem.hand_state == TLS_ST_CR_CERT_VRFY in get_cert_verify_tbs_data()
235 || s->statem.hand_state == TLS_ST_SW_CERT_VRFY) in get_cert_verify_tbs_data()
245 if (s->statem.hand_state == TLS_ST_CR_CERT_VRFY in get_cert_verify_tbs_data()
246 || s->statem.hand_state == TLS_ST_SR_CERT_VRFY) { in get_cert_verify_tbs_data()
247 memcpy(tls13tbs + TLS13_TBS_PREAMBLE_SIZE, s->cert_verify_hash, in get_cert_verify_tbs_data()
248 s->cert_verify_hash_len); in get_cert_verify_tbs_data()
249 hashlen = s->cert_verify_hash_len; in get_cert_verify_tbs_data()
250 } else if (!ssl_handshake_hash(s, tls13tbs + TLS13_TBS_PREAMBLE_SIZE, in get_cert_verify_tbs_data()
262 retlen = retlen_l = BIO_get_mem_data(s->s3.handshake_buffer, hdata); in get_cert_verify_tbs_data()
264 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in get_cert_verify_tbs_data()
273 int tls_construct_cert_verify(SSL *s, WPACKET *pkt) in tls_construct_cert_verify() argument
283 const SIGALG_LOOKUP *lu = s->s3.tmp.sigalg; in tls_construct_cert_verify()
285 if (lu == NULL || s->s3.tmp.cert == NULL) { in tls_construct_cert_verify()
286 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_cert_verify()
289 pkey = s->s3.tmp.cert->privatekey; in tls_construct_cert_verify()
291 if (pkey == NULL || !tls1_lookup_md(s->ctx, lu, &md)) { in tls_construct_cert_verify()
292 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_cert_verify()
298 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in tls_construct_cert_verify()
303 if (!get_cert_verify_tbs_data(s, tls13tbs, &hdata, &hdatalen)) { in tls_construct_cert_verify()
308 if (SSL_USE_SIGALGS(s) && !WPACKET_put_bytes_u16(pkt, lu->sigalg)) { in tls_construct_cert_verify()
309 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_cert_verify()
315 s->ctx->libctx, s->ctx->propq, pkey, in tls_construct_cert_verify()
317 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
321 if (lu->sig == EVP_PKEY_RSA_PSS) { in tls_construct_cert_verify()
325 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
329 if (s->version == SSL3_VERSION) { in tls_construct_cert_verify()
336 (int)s->session->master_key_length, in tls_construct_cert_verify()
337 s->session->master_key) <= 0 in tls_construct_cert_verify()
340 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
346 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
355 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
361 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_construct_cert_verify()
368 int pktype = lu->sig; in tls_construct_cert_verify()
378 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_cert_verify()
383 if (!ssl3_digest_cached_records(s, 0)) { in tls_construct_cert_verify()
397 MSG_PROCESS_RETURN tls_process_cert_verify(SSL *s, PACKET *pkt) in tls_process_cert_verify() argument
416 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in tls_process_cert_verify()
420 peer = s->session->peer; in tls_process_cert_verify()
423 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_process_cert_verify()
428 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, in tls_process_cert_verify()
433 if (SSL_USE_SIGALGS(s)) { in tls_process_cert_verify()
437 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_PACKET); in tls_process_cert_verify()
440 if (tls12_check_peer_sigalg(s, sigalg, pkey) <= 0) { in tls_process_cert_verify()
444 } else if (!tls1_set_peer_legacy_sigalg(s, pkey)) { in tls_process_cert_verify()
445 SSLfatal(s, SSL_AD_INTERNAL_ERROR, in tls_process_cert_verify()
450 if (!tls1_lookup_md(s->ctx, s->s3.tmp.peer_sigalg, &md)) { in tls_process_cert_verify()
451 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_process_cert_verify()
455 if (SSL_USE_SIGALGS(s)) in tls_process_cert_verify()
456 OSSL_TRACE1(TLS, "USING TLSv1.2 HASH %s\n", in tls_process_cert_verify()
465 if (!SSL_USE_SIGALGS(s) in tls_process_cert_verify()
475 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH); in tls_process_cert_verify()
480 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH); in tls_process_cert_verify()
484 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH); in tls_process_cert_verify()
488 if (!get_cert_verify_tbs_data(s, tls13tbs, &hdata, &hdatalen)) { in tls_process_cert_verify()
493 OSSL_TRACE1(TLS, "Using client verify alg %s\n", in tls_process_cert_verify()
498 s->ctx->libctx, s->ctx->propq, pkey, in tls_process_cert_verify()
500 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_process_cert_verify()
510 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in tls_process_cert_verify()
519 if (SSL_USE_PSS(s)) { in tls_process_cert_verify()
523 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_process_cert_verify()
527 if (s->version == SSL3_VERSION) { in tls_process_cert_verify()
530 (int)s->session->master_key_length, in tls_process_cert_verify()
531 s->session->master_key) <= 0) { in tls_process_cert_verify()
532 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_EVP_LIB); in tls_process_cert_verify()
536 SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_R_BAD_SIGNATURE); in tls_process_cert_verify()
542 SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_R_BAD_SIGNATURE); in tls_process_cert_verify()
555 if (!s->server && SSL_IS_TLS13(s) && s->s3.tmp.cert_req == 1) in tls_process_cert_verify()
560 BIO_free(s->s3.handshake_buffer); in tls_process_cert_verify()
561 s->s3.handshake_buffer = NULL; in tls_process_cert_verify()
569 int tls_construct_finished(SSL *s, WPACKET *pkt) in tls_construct_finished() argument
576 if (!s->server && s->post_handshake_auth != SSL_PHA_REQUESTED) in tls_construct_finished()
577 s->statem.cleanuphand = 1; in tls_construct_finished()
583 if (SSL_IS_TLS13(s) in tls_construct_finished()
584 && !s->server in tls_construct_finished()
585 && s->s3.tmp.cert_req == 0 in tls_construct_finished()
586 && (!s->method->ssl3_enc->change_cipher_state(s, in tls_construct_finished()
592 if (s->server) { in tls_construct_finished()
593 sender = s->method->ssl3_enc->server_finished_label; in tls_construct_finished()
594 slen = s->method->ssl3_enc->server_finished_label_len; in tls_construct_finished()
596 sender = s->method->ssl3_enc->client_finished_label; in tls_construct_finished()
597 slen = s->method->ssl3_enc->client_finished_label_len; in tls_construct_finished()
600 finish_md_len = s->method->ssl3_enc->final_finish_mac(s, in tls_construct_finished()
602 s->s3.tmp.finish_md); in tls_construct_finished()
608 s->s3.tmp.finish_md_len = finish_md_len; in tls_construct_finished()
610 if (!WPACKET_memcpy(pkt, s->s3.tmp.finish_md, finish_md_len)) { in tls_construct_finished()
611 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_finished()
617 * TLSv1.3: there's a different key schedule for that. in tls_construct_finished()
619 if (!SSL_IS_TLS13(s) && !ssl_log_secret(s, MASTER_SECRET_LABEL, in tls_construct_finished()
620 s->session->master_key, in tls_construct_finished()
621 s->session->master_key_length)) { in tls_construct_finished()
630 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_finished()
633 if (!s->server) { in tls_construct_finished()
634 memcpy(s->s3.previous_client_finished, s->s3.tmp.finish_md, in tls_construct_finished()
636 s->s3.previous_client_finished_len = finish_md_len; in tls_construct_finished()
638 memcpy(s->s3.previous_server_finished, s->s3.tmp.finish_md, in tls_construct_finished()
640 s->s3.previous_server_finished_len = finish_md_len; in tls_construct_finished()
646 int tls_construct_key_update(SSL *s, WPACKET *pkt) in tls_construct_key_update() argument
648 if (!WPACKET_put_bytes_u8(pkt, s->key_update)) { in tls_construct_key_update()
649 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_key_update()
653 s->key_update = SSL_KEY_UPDATE_NONE; in tls_construct_key_update()
657 MSG_PROCESS_RETURN tls_process_key_update(SSL *s, PACKET *pkt) in tls_process_key_update() argument
665 if (RECORD_LAYER_processed_read_pending(&s->rlayer)) { in tls_process_key_update()
666 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_NOT_ON_RECORD_BOUNDARY); in tls_process_key_update()
672 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_KEY_UPDATE); in tls_process_key_update()
682 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_KEY_UPDATE); in tls_process_key_update()
692 s->key_update = SSL_KEY_UPDATE_NOT_REQUESTED; in tls_process_key_update()
694 if (!tls13_update_key(s, 0)) { in tls_process_key_update()
706 int ssl3_take_mac(SSL *s) in ssl3_take_mac() argument
711 if (!s->server) { in ssl3_take_mac()
712 sender = s->method->ssl3_enc->server_finished_label; in ssl3_take_mac()
713 slen = s->method->ssl3_enc->server_finished_label_len; in ssl3_take_mac()
715 sender = s->method->ssl3_enc->client_finished_label; in ssl3_take_mac()
716 slen = s->method->ssl3_enc->client_finished_label_len; in ssl3_take_mac()
719 s->s3.tmp.peer_finish_md_len = in ssl3_take_mac()
720 s->method->ssl3_enc->final_finish_mac(s, sender, slen, in ssl3_take_mac()
721 s->s3.tmp.peer_finish_md); in ssl3_take_mac()
723 if (s->s3.tmp.peer_finish_md_len == 0) { in ssl3_take_mac()
731 MSG_PROCESS_RETURN tls_process_change_cipher_spec(SSL *s, PACKET *pkt) in tls_process_change_cipher_spec() argument
741 if (SSL_IS_DTLS(s)) { in tls_process_change_cipher_spec()
742 if ((s->version == DTLS1_BAD_VER in tls_process_change_cipher_spec()
744 || (s->version != DTLS1_BAD_VER in tls_process_change_cipher_spec()
745 && remain != DTLS1_CCS_HEADER_LENGTH - 1)) { in tls_process_change_cipher_spec()
746 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_CHANGE_CIPHER_SPEC); in tls_process_change_cipher_spec()
751 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_CHANGE_CIPHER_SPEC); in tls_process_change_cipher_spec()
757 if (s->s3.tmp.new_cipher == NULL) { in tls_process_change_cipher_spec()
758 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_CCS_RECEIVED_EARLY); in tls_process_change_cipher_spec()
762 s->s3.change_cipher_spec = 1; in tls_process_change_cipher_spec()
763 if (!ssl3_do_change_cipher_spec(s)) { in tls_process_change_cipher_spec()
764 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_process_change_cipher_spec()
768 if (SSL_IS_DTLS(s)) { in tls_process_change_cipher_spec()
769 dtls1_reset_seq_numbers(s, SSL3_CC_READ); in tls_process_change_cipher_spec()
771 if (s->version == DTLS1_BAD_VER) in tls_process_change_cipher_spec()
772 s->d1->handshake_read_seq++; in tls_process_change_cipher_spec()
777 * SCTP-Auth can be deleted when a CCS is sent. Will be ignored if no in tls_process_change_cipher_spec()
780 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD, 1, NULL); in tls_process_change_cipher_spec()
787 MSG_PROCESS_RETURN tls_process_finished(SSL *s, PACKET *pkt) in tls_process_finished() argument
793 if (s->server) { in tls_process_finished()
799 s->statem.enc_read_state = ENC_READ_STATE_VALID; in tls_process_finished()
800 if (s->post_handshake_auth != SSL_PHA_REQUESTED) in tls_process_finished()
801 s->statem.cleanuphand = 1; in tls_process_finished()
802 if (SSL_IS_TLS13(s) && !tls13_save_handshake_digest_for_pha(s)) { in tls_process_finished()
812 if (SSL_IS_TLS13(s) && RECORD_LAYER_processed_read_pending(&s->rlayer)) { in tls_process_finished()
813 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_NOT_ON_RECORD_BOUNDARY); in tls_process_finished()
818 if (!SSL_IS_TLS13(s) && !s->s3.change_cipher_spec) { in tls_process_finished()
819 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_R_GOT_A_FIN_BEFORE_A_CCS); in tls_process_finished()
822 s->s3.change_cipher_spec = 0; in tls_process_finished()
824 md_len = s->s3.tmp.peer_finish_md_len; in tls_process_finished()
827 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_BAD_DIGEST_LENGTH); in tls_process_finished()
831 if (CRYPTO_memcmp(PACKET_data(pkt), s->s3.tmp.peer_finish_md, in tls_process_finished()
833 SSLfatal(s, SSL_AD_DECRYPT_ERROR, SSL_R_DIGEST_CHECK_FAILED); in tls_process_finished()
841 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_process_finished()
844 if (s->server) { in tls_process_finished()
845 memcpy(s->s3.previous_client_finished, s->s3.tmp.peer_finish_md, in tls_process_finished()
847 s->s3.previous_client_finished_len = md_len; in tls_process_finished()
849 memcpy(s->s3.previous_server_finished, s->s3.tmp.peer_finish_md, in tls_process_finished()
851 s->s3.previous_server_finished_len = md_len; in tls_process_finished()
858 if (SSL_IS_TLS13(s)) { in tls_process_finished()
859 if (s->server) { in tls_process_finished()
860 if (s->post_handshake_auth != SSL_PHA_REQUESTED && in tls_process_finished()
861 !s->method->ssl3_enc->change_cipher_state(s, in tls_process_finished()
869 if (!s->method->ssl3_enc->generate_master_secret(s, in tls_process_finished()
870 s->master_secret, s->handshake_secret, 0, in tls_process_finished()
875 if (!s->method->ssl3_enc->change_cipher_state(s, in tls_process_finished()
880 if (!tls_process_initial_server_flight(s)) { in tls_process_finished()
890 int tls_construct_change_cipher_spec(SSL *s, WPACKET *pkt) in tls_construct_change_cipher_spec() argument
893 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_construct_change_cipher_spec()
901 static int ssl_add_cert_to_wpacket(SSL *s, WPACKET *pkt, X509 *x, int chain) in ssl_add_cert_to_wpacket() argument
908 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_BUF_LIB); in ssl_add_cert_to_wpacket()
913 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in ssl_add_cert_to_wpacket()
917 if (SSL_IS_TLS13(s) in ssl_add_cert_to_wpacket()
918 && !tls_construct_extensions(s, pkt, SSL_EXT_TLS1_3_CERTIFICATE, x, in ssl_add_cert_to_wpacket()
928 static int ssl_add_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk) in ssl_add_cert_chain() argument
936 if (cpk == NULL || cpk->x509 == NULL) in ssl_add_cert_chain()
939 x = cpk->x509; in ssl_add_cert_chain()
944 if (cpk->chain != NULL) in ssl_add_cert_chain()
945 extra_certs = cpk->chain; in ssl_add_cert_chain()
947 extra_certs = s->ctx->extra_certs; in ssl_add_cert_chain()
949 if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || extra_certs) in ssl_add_cert_chain()
951 else if (s->cert->chain_store) in ssl_add_cert_chain()
952 chain_store = s->cert->chain_store; in ssl_add_cert_chain()
954 chain_store = s->ctx->cert_store; in ssl_add_cert_chain()
957 X509_STORE_CTX *xs_ctx = X509_STORE_CTX_new_ex(s->ctx->libctx, in ssl_add_cert_chain()
958 s->ctx->propq); in ssl_add_cert_chain()
961 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in ssl_add_cert_chain()
966 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_X509_LIB); in ssl_add_cert_chain()
973 * the cert - we're just building as much of the chain as we can in ssl_add_cert_chain()
979 i = ssl_security_cert_chain(s, chain, NULL, 0); in ssl_add_cert_chain()
988 SSLfatal(s, SSL_AD_INTERNAL_ERROR, i); in ssl_add_cert_chain()
995 if (!ssl_add_cert_to_wpacket(s, pkt, x, i)) { in ssl_add_cert_chain()
1003 i = ssl_security_cert_chain(s, extra_certs, x, 0); in ssl_add_cert_chain()
1005 SSLfatal(s, SSL_AD_INTERNAL_ERROR, i); in ssl_add_cert_chain()
1008 if (!ssl_add_cert_to_wpacket(s, pkt, x, 0)) { in ssl_add_cert_chain()
1014 if (!ssl_add_cert_to_wpacket(s, pkt, x, i + 1)) { in ssl_add_cert_chain()
1023 unsigned long ssl3_output_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk) in ssl3_output_cert_chain() argument
1026 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in ssl3_output_cert_chain()
1030 if (!ssl_add_cert_chain(s, pkt, cpk)) in ssl3_output_cert_chain()
1034 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in ssl3_output_cert_chain()
1046 WORK_STATE tls_finish_handshake(SSL *s, ossl_unused WORK_STATE wst, in tls_finish_handshake() argument
1050 int cleanuphand = s->statem.cleanuphand; in tls_finish_handshake()
1053 if (!SSL_IS_DTLS(s) in tls_finish_handshake()
1056 * RFC6083: SCTP provides a reliable and in-sequence transport service for DTLS in tls_finish_handshake()
1061 || BIO_dgram_is_sctp(SSL_get_wbio(s)) in tls_finish_handshake()
1068 BUF_MEM_free(s->init_buf); in tls_finish_handshake()
1069 s->init_buf = NULL; in tls_finish_handshake()
1072 if (!ssl_free_wbio_buffer(s)) { in tls_finish_handshake()
1073 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls_finish_handshake()
1076 s->init_num = 0; in tls_finish_handshake()
1079 if (SSL_IS_TLS13(s) && !s->server in tls_finish_handshake()
1080 && s->post_handshake_auth == SSL_PHA_REQUESTED) in tls_finish_handshake()
1081 s->post_handshake_auth = SSL_PHA_EXT_SENT; in tls_finish_handshake()
1089 s->renegotiate = 0; in tls_finish_handshake()
1090 s->new_session = 0; in tls_finish_handshake()
1091 s->statem.cleanuphand = 0; in tls_finish_handshake()
1092 s->ext.ticket_expected = 0; in tls_finish_handshake()
1094 ssl3_cleanup_key_block(s); in tls_finish_handshake()
1096 if (s->server) { in tls_finish_handshake()
1101 if (!SSL_IS_TLS13(s)) in tls_finish_handshake()
1102 ssl_update_cache(s, SSL_SESS_CACHE_SERVER); in tls_finish_handshake()
1104 /* N.B. s->ctx may not equal s->session_ctx */ in tls_finish_handshake()
1105 ssl_tsan_counter(s->ctx, &s->ctx->stats.sess_accept_good); in tls_finish_handshake()
1106 s->handshake_func = ossl_statem_accept; in tls_finish_handshake()
1108 if (SSL_IS_TLS13(s)) { in tls_finish_handshake()
1113 if ((s->session_ctx->session_cache_mode in tls_finish_handshake()
1115 SSL_CTX_remove_session(s->session_ctx, s->session); in tls_finish_handshake()
1121 ssl_update_cache(s, SSL_SESS_CACHE_CLIENT); in tls_finish_handshake()
1123 if (s->hit) in tls_finish_handshake()
1124 ssl_tsan_counter(s->session_ctx, in tls_finish_handshake()
1125 &s->session_ctx->stats.sess_hit); in tls_finish_handshake()
1127 s->handshake_func = ossl_statem_connect; in tls_finish_handshake()
1128 ssl_tsan_counter(s->session_ctx, in tls_finish_handshake()
1129 &s->session_ctx->stats.sess_connect_good); in tls_finish_handshake()
1132 if (SSL_IS_DTLS(s)) { in tls_finish_handshake()
1134 s->d1->handshake_read_seq = 0; in tls_finish_handshake()
1135 s->d1->handshake_write_seq = 0; in tls_finish_handshake()
1136 s->d1->next_handshake_write_seq = 0; in tls_finish_handshake()
1137 dtls1_clear_received_buffer(s); in tls_finish_handshake()
1141 if (s->info_callback != NULL) in tls_finish_handshake()
1142 cb = s->info_callback; in tls_finish_handshake()
1143 else if (s->ctx->info_callback != NULL) in tls_finish_handshake()
1144 cb = s->ctx->info_callback; in tls_finish_handshake()
1147 ossl_statem_set_in_init(s, 0); in tls_finish_handshake()
1151 || !SSL_IS_TLS13(s) in tls_finish_handshake()
1152 || SSL_IS_FIRST_HANDSHAKE(s)) in tls_finish_handshake()
1153 cb(s, SSL_CB_HANDSHAKE_DONE, 1); in tls_finish_handshake()
1158 ossl_statem_set_in_init(s, 1); in tls_finish_handshake()
1165 int tls_get_message_header(SSL *s, int *mt) in tls_get_message_header() argument
1167 /* s->init_num < SSL3_HM_HEADER_LENGTH */ in tls_get_message_header()
1172 p = (unsigned char *)s->init_buf->data; in tls_get_message_header()
1175 while (s->init_num < SSL3_HM_HEADER_LENGTH) { in tls_get_message_header()
1176 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type, in tls_get_message_header()
1177 &p[s->init_num], in tls_get_message_header()
1178 SSL3_HM_HEADER_LENGTH - s->init_num, in tls_get_message_header()
1181 s->rwstate = SSL_READING; in tls_get_message_header()
1189 if (s->init_num != 0 || readbytes != 1 || p[0] != SSL3_MT_CCS) { in tls_get_message_header()
1190 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, in tls_get_message_header()
1194 if (s->statem.hand_state == TLS_ST_BEFORE in tls_get_message_header()
1195 && (s->s3.flags & TLS1_FLAGS_STATELESS) != 0) { in tls_get_message_header()
1205 s->s3.tmp.message_type = *mt = SSL3_MT_CHANGE_CIPHER_SPEC; in tls_get_message_header()
1206 s->init_num = readbytes - 1; in tls_get_message_header()
1207 s->init_msg = s->init_buf->data; in tls_get_message_header()
1208 s->s3.tmp.message_size = readbytes; in tls_get_message_header()
1211 SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, in tls_get_message_header()
1215 s->init_num += readbytes; in tls_get_message_header()
1219 if (!s->server) in tls_get_message_header()
1220 if (s->statem.hand_state != TLS_ST_OK in tls_get_message_header()
1223 * The server may always send 'Hello Request' messages -- in tls_get_message_header()
1229 s->init_num = 0; in tls_get_message_header()
1232 if (s->msg_callback) in tls_get_message_header()
1233 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, in tls_get_message_header()
1234 p, SSL3_HM_HEADER_LENGTH, s, in tls_get_message_header()
1235 s->msg_callback_arg); in tls_get_message_header()
1238 /* s->init_num == SSL3_HM_HEADER_LENGTH */ in tls_get_message_header()
1241 s->s3.tmp.message_type = *(p++); in tls_get_message_header()
1243 if (RECORD_LAYER_is_sslv2_record(&s->rlayer)) { in tls_get_message_header()
1251 l = RECORD_LAYER_get_rrec_length(&s->rlayer) in tls_get_message_header()
1253 s->s3.tmp.message_size = l; in tls_get_message_header()
1255 s->init_msg = s->init_buf->data; in tls_get_message_header()
1256 s->init_num = SSL3_HM_HEADER_LENGTH; in tls_get_message_header()
1260 if (l > (INT_MAX - SSL3_HM_HEADER_LENGTH)) { in tls_get_message_header()
1261 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, in tls_get_message_header()
1265 s->s3.tmp.message_size = l; in tls_get_message_header()
1267 s->init_msg = s->init_buf->data + SSL3_HM_HEADER_LENGTH; in tls_get_message_header()
1268 s->init_num = 0; in tls_get_message_header()
1274 int tls_get_message_body(SSL *s, size_t *len) in tls_get_message_body() argument
1280 if (s->s3.tmp.message_type == SSL3_MT_CHANGE_CIPHER_SPEC) { in tls_get_message_body()
1282 *len = (unsigned long)s->init_num; in tls_get_message_body()
1286 p = s->init_msg; in tls_get_message_body()
1287 n = s->s3.tmp.message_size - s->init_num; in tls_get_message_body()
1289 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL, in tls_get_message_body()
1290 &p[s->init_num], n, 0, &readbytes); in tls_get_message_body()
1292 s->rwstate = SSL_READING; in tls_get_message_body()
1296 s->init_num += readbytes; in tls_get_message_body()
1297 n -= readbytes; in tls_get_message_body()
1304 if (*(s->init_buf->data) == SSL3_MT_FINISHED && !ssl3_take_mac(s)) { in tls_get_message_body()
1311 if (RECORD_LAYER_is_sslv2_record(&s->rlayer)) { in tls_get_message_body()
1312 if (!ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, in tls_get_message_body()
1313 s->init_num)) { in tls_get_message_body()
1318 if (s->msg_callback) in tls_get_message_body()
1319 s->msg_callback(0, SSL2_VERSION, 0, s->init_buf->data, in tls_get_message_body()
1320 (size_t)s->init_num, s, s->msg_callback_arg); in tls_get_message_body()
1330 if (!SSL_IS_TLS13(s) || (s->s3.tmp.message_type != SSL3_MT_NEWSESSION_TICKET in tls_get_message_body()
1331 && s->s3.tmp.message_type != SSL3_MT_KEY_UPDATE)) { in tls_get_message_body()
1332 if (s->s3.tmp.message_type != SSL3_MT_SERVER_HELLO in tls_get_message_body()
1333 || s->init_num < SERVER_HELLO_RANDOM_OFFSET + SSL3_RANDOM_SIZE in tls_get_message_body()
1335 s->init_buf->data + SERVER_HELLO_RANDOM_OFFSET, in tls_get_message_body()
1337 if (!ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, in tls_get_message_body()
1338 s->init_num + SSL3_HM_HEADER_LENGTH)) { in tls_get_message_body()
1345 if (s->msg_callback) in tls_get_message_body()
1346 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, in tls_get_message_body()
1347 (size_t)s->init_num + SSL3_HM_HEADER_LENGTH, s, in tls_get_message_body()
1348 s->msg_callback_arg); in tls_get_message_body()
1351 *len = s->init_num; in tls_get_message_body()
1405 for (tp = x509table; tp->x509err != X509_V_OK; ++tp) in ssl_x509err2alert()
1406 if (tp->x509err == x509err) in ssl_x509err2alert()
1408 return tp->alert; in ssl_x509err2alert()
1411 int ssl_allow_compression(SSL *s) in ssl_allow_compression() argument
1413 if (s->options & SSL_OP_NO_COMPRESSION) in ssl_allow_compression()
1415 return ssl_security(s, SSL_SECOP_COMPRESSION, 0, 0, NULL); in ssl_allow_compression()
1418 static int version_cmp(const SSL *s, int a, int b) in version_cmp() argument
1420 int dtls = SSL_IS_DTLS(s); in version_cmp()
1425 return a < b ? -1 : 1; in version_cmp()
1426 return DTLS_VERSION_LT(a, b) ? -1 : 1; in version_cmp()
1491 * ssl_method_error - Check whether an SSL_METHOD is enabled.
1493 * @s: The SSL handle for the candidate method
1498 static int ssl_method_error(const SSL *s, const SSL_METHOD *method) in ssl_method_error() argument
1500 int version = method->version; in ssl_method_error()
1502 if ((s->min_proto_version != 0 && in ssl_method_error()
1503 version_cmp(s, version, s->min_proto_version) < 0) || in ssl_method_error()
1504 ssl_security(s, SSL_SECOP_VERSION, 0, version, NULL) == 0) in ssl_method_error()
1507 if (s->max_proto_version != 0 && in ssl_method_error()
1508 version_cmp(s, version, s->max_proto_version) > 0) in ssl_method_error()
1511 if ((s->options & method->mask) != 0) in ssl_method_error()
1513 if ((method->flags & SSL_METHOD_NO_SUITEB) != 0 && tls1_suiteb(s)) in ssl_method_error()
1524 static int is_tls13_capable(const SSL *s) in is_tls13_capable() argument
1529 if (!ossl_assert(s->ctx != NULL) || !ossl_assert(s->session_ctx != NULL)) in is_tls13_capable()
1536 if (s->ctx->ext.servername_cb != NULL in is_tls13_capable()
1537 || s->session_ctx->ext.servername_cb != NULL) in is_tls13_capable()
1541 if (s->psk_server_callback != NULL) in is_tls13_capable()
1545 if (s->psk_find_session_cb != NULL || s->cert->cert_cb != NULL) in is_tls13_capable()
1559 if (!ssl_has_cert(s, i)) in is_tls13_capable()
1568 curve = ssl_get_EC_curve_nid(s->cert->pkeys[SSL_PKEY_ECC].privatekey); in is_tls13_capable()
1569 if (tls_check_sigalg_curve(s, curve)) in is_tls13_capable()
1577 * ssl_version_supported - Check that the specified `version` is supported by
1580 * @s: The SSL handle for the candidate method
1585 int ssl_version_supported(const SSL *s, int version, const SSL_METHOD **meth) in ssl_version_supported() argument
1590 switch (s->method->version) { in ssl_version_supported()
1592 /* Version should match method version for non-ANY method */ in ssl_version_supported()
1593 return version_cmp(s, version, s->version) == 0; in ssl_version_supported()
1603 vent->version != 0 && version_cmp(s, version, vent->version) <= 0; in ssl_version_supported()
1605 if (vent->cmeth != NULL in ssl_version_supported()
1606 && version_cmp(s, version, vent->version) == 0 in ssl_version_supported()
1607 && ssl_method_error(s, vent->cmeth()) == 0 in ssl_version_supported()
1608 && (!s->server in ssl_version_supported()
1610 || is_tls13_capable(s))) { in ssl_version_supported()
1612 *meth = vent->cmeth(); in ssl_version_supported()
1620 * ssl_check_version_downgrade - In response to RFC7507 SCSV version
1624 * @s server SSL handle.
1628 int ssl_check_version_downgrade(SSL *s) in ssl_check_version_downgrade() argument
1635 * (according to s->ctx->method, as version negotiation may have changed in ssl_check_version_downgrade()
1636 * s->method). in ssl_check_version_downgrade()
1638 if (s->version == s->ctx->method->version) in ssl_check_version_downgrade()
1642 * Apparently we're using a version-flexible SSL_METHOD (not at its in ssl_check_version_downgrade()
1645 if (s->ctx->method->version == TLS_method()->version) in ssl_check_version_downgrade()
1647 else if (s->ctx->method->version == DTLS_method()->version) in ssl_check_version_downgrade()
1654 for (vent = table; vent->version != 0; ++vent) { in ssl_check_version_downgrade()
1655 if (vent->smeth != NULL && ssl_method_error(s, vent->smeth()) == 0) in ssl_check_version_downgrade()
1656 return s->version == vent->version; in ssl_check_version_downgrade()
1662 * ssl_set_version_bound - set an upper or lower bound on the supported (D)TLS
1663 * protocols, provided the initial (D)TLS method is version-flexible. This
1664 * function sanity-checks the proposed value and makes sure the method is
1665 * version-flexible, then sets the limit if all is well.
1691 /*- in ssl_set_version_bound()
1696 * Note that for both lower-bounds we use explicit versions, not in ssl_set_version_bound()
1698 * configurations. If the MIN (supported) version ever rises, the user's in ssl_set_version_bound()
1702 * We ignore attempts to set bounds on version-inflexible methods, in ssl_set_version_bound()
1722 static void check_for_downgrade(SSL *s, int vers, DOWNGRADE *dgrd) in check_for_downgrade() argument
1725 && ssl_version_supported(s, TLS1_3_VERSION, NULL)) { in check_for_downgrade()
1727 } else if (!SSL_IS_DTLS(s) in check_for_downgrade()
1736 && ssl_version_supported(s, TLS1_2_VERSION, NULL)) { in check_for_downgrade()
1744 * ssl_choose_server_version - Choose server (D)TLS version. Called when the
1748 * @s: server SSL handle.
1752 int ssl_choose_server_version(SSL *s, CLIENTHELLO_MSG *hello, DOWNGRADE *dgrd) in ssl_choose_server_version() argument
1754 /*- in ssl_choose_server_version()
1755 * With version-flexible methods we have an initial state with: in ssl_choose_server_version()
1757 * s->method->version == (D)TLS_ANY_VERSION, in ssl_choose_server_version()
1758 * s->version == (D)TLS_MAX_VERSION_INTERNAL. in ssl_choose_server_version()
1760 * So we detect version-flexible methods via the method version, not the in ssl_choose_server_version()
1763 int server_version = s->method->version; in ssl_choose_server_version()
1764 int client_version = hello->legacy_version; in ssl_choose_server_version()
1770 s->client_version = client_version; in ssl_choose_server_version()
1774 if (!SSL_IS_TLS13(s)) { in ssl_choose_server_version()
1775 if (version_cmp(s, client_version, s->version) < 0) in ssl_choose_server_version()
1781 * that's OK. It is up to the caller to not choose fixed protocol in ssl_choose_server_version()
1783 * ssl_method_error(s, s->method) in ssl_choose_server_version()
1800 suppversions = &hello->pre_proc_exts[TLSEXT_IDX_supported_versions]; in ssl_choose_server_version()
1803 if (!suppversions->present && s->hello_retry_request != SSL_HRR_NONE) in ssl_choose_server_version()
1806 if (suppversions->present && !SSL_IS_DTLS(s)) { in ssl_choose_server_version()
1812 suppversions->parsed = 1; in ssl_choose_server_version()
1814 if (!PACKET_as_length_prefixed_1(&suppversions->data, &versionslist)) { in ssl_choose_server_version()
1832 if (version_cmp(s, candidate_vers, best_vers) <= 0) in ssl_choose_server_version()
1834 if (ssl_version_supported(s, candidate_vers, &best_method)) in ssl_choose_server_version()
1843 if (s->hello_retry_request != SSL_HRR_NONE) { in ssl_choose_server_version()
1852 check_for_downgrade(s, best_vers, dgrd); in ssl_choose_server_version()
1853 s->version = best_vers; in ssl_choose_server_version()
1854 s->method = best_method; in ssl_choose_server_version()
1864 if (version_cmp(s, client_version, TLS1_3_VERSION) >= 0) in ssl_choose_server_version()
1871 for (vent = table; vent->version != 0; ++vent) { in ssl_choose_server_version()
1874 if (vent->smeth == NULL || in ssl_choose_server_version()
1875 version_cmp(s, client_version, vent->version) < 0) in ssl_choose_server_version()
1877 method = vent->smeth(); in ssl_choose_server_version()
1878 if (ssl_method_error(s, method) == 0) { in ssl_choose_server_version()
1879 check_for_downgrade(s, vent->version, dgrd); in ssl_choose_server_version()
1880 s->version = vent->version; in ssl_choose_server_version()
1881 s->method = method; in ssl_choose_server_version()
1890 * ssl_choose_client_version - Choose client (D)TLS version. Called when the
1894 * @s: client SSL handle.
1895 * @version: The proposed version from the server's HELLO.
1900 int ssl_choose_client_version(SSL *s, int version, RAW_EXTENSION *extensions) in ssl_choose_client_version() argument
1906 origv = s->version; in ssl_choose_client_version()
1907 s->version = version; in ssl_choose_client_version()
1909 /* This will overwrite s->version if the extension is present */ in ssl_choose_client_version()
1910 if (!tls_parse_extension(s, TLSEXT_IDX_supported_versions, in ssl_choose_client_version()
1914 s->version = origv; in ssl_choose_client_version()
1918 if (s->hello_retry_request != SSL_HRR_NONE in ssl_choose_client_version()
1919 && s->version != TLS1_3_VERSION) { in ssl_choose_client_version()
1920 s->version = origv; in ssl_choose_client_version()
1921 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_WRONG_SSL_VERSION); in ssl_choose_client_version()
1925 switch (s->method->version) { in ssl_choose_client_version()
1927 if (s->version != s->method->version) { in ssl_choose_client_version()
1928 s->version = origv; in ssl_choose_client_version()
1929 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_WRONG_SSL_VERSION); in ssl_choose_client_version()
1935 * that's OK. It is up to the caller to not choose fixed protocol in ssl_choose_client_version()
1937 * ssl_method_error(s, s->method) in ssl_choose_client_version()
1948 ret = ssl_get_min_max_version(s, &ver_min, &ver_max, &real_max); in ssl_choose_client_version()
1950 s->version = origv; in ssl_choose_client_version()
1951 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, ret); in ssl_choose_client_version()
1954 if (SSL_IS_DTLS(s) ? DTLS_VERSION_LT(s->version, ver_min) in ssl_choose_client_version()
1955 : s->version < ver_min) { in ssl_choose_client_version()
1956 s->version = origv; in ssl_choose_client_version()
1957 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_UNSUPPORTED_PROTOCOL); in ssl_choose_client_version()
1959 } else if (SSL_IS_DTLS(s) ? DTLS_VERSION_GT(s->version, ver_max) in ssl_choose_client_version()
1960 : s->version > ver_max) { in ssl_choose_client_version()
1961 s->version = origv; in ssl_choose_client_version()
1962 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_UNSUPPORTED_PROTOCOL); in ssl_choose_client_version()
1966 if ((s->mode & SSL_MODE_SEND_FALLBACK_SCSV) == 0) in ssl_choose_client_version()
1970 if (s->version == TLS1_2_VERSION && real_max > s->version) { in ssl_choose_client_version()
1972 s->s3.server_random + SSL3_RANDOM_SIZE in ssl_choose_client_version()
1973 - sizeof(tls12downgrade), in ssl_choose_client_version()
1975 s->version = origv; in ssl_choose_client_version()
1976 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, in ssl_choose_client_version()
1980 } else if (!SSL_IS_DTLS(s) in ssl_choose_client_version()
1981 && s->version < TLS1_2_VERSION in ssl_choose_client_version()
1982 && real_max > s->version) { in ssl_choose_client_version()
1984 s->s3.server_random + SSL3_RANDOM_SIZE in ssl_choose_client_version()
1985 - sizeof(tls11downgrade), in ssl_choose_client_version()
1987 s->version = origv; in ssl_choose_client_version()
1988 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, in ssl_choose_client_version()
1994 for (vent = table; vent->version != 0; ++vent) { in ssl_choose_client_version()
1995 if (vent->cmeth == NULL || s->version != vent->version) in ssl_choose_client_version()
1998 s->method = vent->cmeth(); in ssl_choose_client_version()
2002 s->version = origv; in ssl_choose_client_version()
2003 SSLfatal(s, SSL_AD_PROTOCOL_VERSION, SSL_R_UNSUPPORTED_PROTOCOL); in ssl_choose_client_version()
2008 * ssl_get_min_max_version - get minimum and maximum protocol version
2009 * @s: The SSL connection
2013 * where that hole lies above at least one run-time enabled
2023 * TLS 1.1 is disabled, but the security level, Suite-B and/or MinProtocol
2029 int ssl_get_min_max_version(const SSL *s, int *min_version, int *max_version, in ssl_get_min_max_version() argument
2039 switch (s->method->version) { in ssl_get_min_max_version()
2044 * that's OK. It is up to the caller to not choose fixed protocol in ssl_get_min_max_version()
2046 * ssl_method_error(s, s->method) in ssl_get_min_max_version()
2048 *min_version = *max_version = s->version; in ssl_get_min_max_version()
2068 * (protocol version client is disabled at compile-time) is also a "hole". in ssl_get_min_max_version()
2090 for (vent = table; vent->version != 0; ++vent) { in ssl_get_min_max_version()
2095 if (vent->cmeth == NULL) { in ssl_get_min_max_version()
2100 method = vent->cmeth(); in ssl_get_min_max_version()
2103 tmp_real_max = vent->version; in ssl_get_min_max_version()
2105 if (ssl_method_error(s, method) != 0) { in ssl_get_min_max_version()
2109 *min_version = method->version; in ssl_get_min_max_version()
2113 version = (single = method)->version; in ssl_get_min_max_version()
2129 * ssl_set_client_hello_version - Work out what version we should be using for
2132 * @s: client SSL handle.
2136 int ssl_set_client_hello_version(SSL *s) in ssl_set_client_hello_version() argument
2144 if (!SSL_IS_FIRST_HANDSHAKE(s)) in ssl_set_client_hello_version()
2147 ret = ssl_get_min_max_version(s, &ver_min, &ver_max, NULL); in ssl_set_client_hello_version()
2152 s->version = ver_max; in ssl_set_client_hello_version()
2155 if (!SSL_IS_DTLS(s) && ver_max > TLS1_2_VERSION) in ssl_set_client_hello_version()
2158 s->client_version = ver_max; in ssl_set_client_hello_version()
2168 int check_in_list(SSL *s, uint16_t group_id, const uint16_t *groups, in check_in_list() argument
2181 || tls_group_allowed(s, group, SSL_SECOP_CURVE_CHECK))) { in check_in_list()
2190 int create_synthetic_message_hash(SSL *s, const unsigned char *hashval, in create_synthetic_message_hash() argument
2203 if (!ssl3_digest_cached_records(s, 0) in create_synthetic_message_hash()
2204 || !ssl_handshake_hash(s, hashvaltmp, sizeof(hashvaltmp), in create_synthetic_message_hash()
2212 if (!ssl3_init_finished_mac(s)) { in create_synthetic_message_hash()
2219 msghdr[SSL3_HM_HEADER_LENGTH - 1] = (unsigned char)hashlen; in create_synthetic_message_hash()
2220 if (!ssl3_finish_mac(s, msghdr, SSL3_HM_HEADER_LENGTH) in create_synthetic_message_hash()
2221 || !ssl3_finish_mac(s, hashval, hashlen)) { in create_synthetic_message_hash()
2227 * Now re-inject the HRR and current message if appropriate (we just deleted in create_synthetic_message_hash()
2232 && (!ssl3_finish_mac(s, hrr, hrrlen) in create_synthetic_message_hash()
2233 || !ssl3_finish_mac(s, (unsigned char *)s->init_buf->data, in create_synthetic_message_hash()
2234 s->s3.tmp.message_size in create_synthetic_message_hash()
2248 int parse_ca_names(SSL *s, PACKET *pkt) in parse_ca_names() argument
2255 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in parse_ca_names()
2260 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH); in parse_ca_names()
2270 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_LENGTH_MISMATCH); in parse_ca_names()
2276 SSLfatal(s, SSL_AD_DECODE_ERROR, ERR_R_ASN1_LIB); in parse_ca_names()
2280 SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_R_CA_DN_LENGTH_MISMATCH); in parse_ca_names()
2285 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in parse_ca_names()
2291 sk_X509_NAME_pop_free(s->s3.tmp.peer_ca_names, X509_NAME_free); in parse_ca_names()
2292 s->s3.tmp.peer_ca_names = ca_sk; in parse_ca_names()
2302 const STACK_OF(X509_NAME) *get_ca_names(SSL *s) in STACK_OF()
2306 if (s->server) { in STACK_OF()
2307 ca_sk = SSL_get_client_CA_list(s); in STACK_OF()
2313 ca_sk = SSL_get0_CA_list(s); in STACK_OF()
2318 int construct_ca_names(SSL *s, const STACK_OF(X509_NAME) *ca_sk, WPACKET *pkt) in construct_ca_names() argument
2320 /* Start sub-packet for client CA list */ in construct_ca_names()
2322 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in construct_ca_names()
2326 if ((ca_sk != NULL) && !(s->options & SSL_OP_DISABLE_TLSEXT_CA_NAMES)) { in construct_ca_names()
2339 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in construct_ca_names()
2346 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in construct_ca_names()
2354 size_t construct_key_exchange_tbs(SSL *s, unsigned char **ptbs, in construct_key_exchange_tbs() argument
2361 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE); in construct_key_exchange_tbs()
2364 memcpy(tbs, s->s3.client_random, SSL3_RANDOM_SIZE); in construct_key_exchange_tbs()
2365 memcpy(tbs + SSL3_RANDOM_SIZE, s->s3.server_random, SSL3_RANDOM_SIZE); in construct_key_exchange_tbs()
2374 * Saves the current handshake digest for Post-Handshake Auth,
2377 int tls13_save_handshake_digest_for_pha(SSL *s) in tls13_save_handshake_digest_for_pha() argument
2379 if (s->pha_dgst == NULL) { in tls13_save_handshake_digest_for_pha()
2380 if (!ssl3_digest_cached_records(s, 1)) in tls13_save_handshake_digest_for_pha()
2384 s->pha_dgst = EVP_MD_CTX_new(); in tls13_save_handshake_digest_for_pha()
2385 if (s->pha_dgst == NULL) { in tls13_save_handshake_digest_for_pha()
2386 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls13_save_handshake_digest_for_pha()
2389 if (!EVP_MD_CTX_copy_ex(s->pha_dgst, in tls13_save_handshake_digest_for_pha()
2390 s->s3.handshake_dgst)) { in tls13_save_handshake_digest_for_pha()
2391 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls13_save_handshake_digest_for_pha()
2392 EVP_MD_CTX_free(s->pha_dgst); in tls13_save_handshake_digest_for_pha()
2393 s->pha_dgst = NULL; in tls13_save_handshake_digest_for_pha()
2401 * Restores the Post-Handshake Auth handshake digest
2404 int tls13_restore_handshake_digest_for_pha(SSL *s) in tls13_restore_handshake_digest_for_pha() argument
2406 if (s->pha_dgst == NULL) { in tls13_restore_handshake_digest_for_pha()
2407 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls13_restore_handshake_digest_for_pha()
2410 if (!EVP_MD_CTX_copy_ex(s->s3.handshake_dgst, in tls13_restore_handshake_digest_for_pha()
2411 s->pha_dgst)) { in tls13_restore_handshake_digest_for_pha()
2412 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR); in tls13_restore_handshake_digest_for_pha()