Lines Matching +full:- +full:- +full:version
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
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()
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()
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()
85 s->init_num = (int)msglen; in tls_close_construct_packet()
86 s->init_off = 0; in tls_close_construct_packet()
101 memset(s->ext.extflags, 0, sizeof(s->ext.extflags)); 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()
123 "The max supported SSL/TLS version needs the" in tls_setup_handshake()
124 " MD5-SHA1 digest but it is not available" in tls_setup_handshake()
147 if (s->server) { in tls_setup_handshake()
152 * Sanity check that the maximum version we accept has ciphers 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()
173 "SSL/TLS version"); 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()
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()
199 s->statem.use_timer = 1; in tls_setup_handshake()
206 * Size of the to-be-signed TLS13 data, without the hash size itself:
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()
262 retlen = retlen_l = BIO_get_mem_data(s->s3.handshake_buffer, hdata); in get_cert_verify_tbs_data()
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()
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()
308 if (SSL_USE_SIGALGS(s) && !WPACKET_put_bytes_u16(pkt, lu->sigalg)) { in tls_construct_cert_verify()
315 s->ctx->libctx, s->ctx->propq, pkey, in tls_construct_cert_verify()
321 if (lu->sig == EVP_PKEY_RSA_PSS) { 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()
368 int pktype = lu->sig; in tls_construct_cert_verify()
420 peer = s->session->peer; in tls_process_cert_verify()
450 if (!tls1_lookup_md(s->ctx, s->s3.tmp.peer_sigalg, &md)) { in tls_process_cert_verify()
498 s->ctx->libctx, s->ctx->propq, pkey, 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()
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()
576 if (!s->server && s->post_handshake_auth != SSL_PHA_REQUESTED) in tls_construct_finished()
577 s->statem.cleanuphand = 1; 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()
620 s->session->master_key, in tls_construct_finished()
621 s->session->master_key_length)) { 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()
648 if (!WPACKET_put_bytes_u8(pkt, s->key_update)) { in tls_construct_key_update()
653 s->key_update = SSL_KEY_UPDATE_NONE; in tls_construct_key_update()
665 if (RECORD_LAYER_processed_read_pending(&s->rlayer)) { in tls_process_key_update()
692 s->key_update = SSL_KEY_UPDATE_NOT_REQUESTED; in tls_process_key_update()
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()
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()
757 if (s->s3.tmp.new_cipher == NULL) { in tls_process_change_cipher_spec()
762 s->s3.change_cipher_spec = 1; 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()
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()
812 if (SSL_IS_TLS13(s) && RECORD_LAYER_processed_read_pending(&s->rlayer)) { in tls_process_finished()
818 if (!SSL_IS_TLS13(s) && !s->s3.change_cipher_spec) { 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()
831 if (CRYPTO_memcmp(PACKET_data(pkt), s->s3.tmp.peer_finish_md, 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()
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()
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()
973 * the cert - we're just building as much of the chain as we can in ssl_add_cert_chain()
1050 int cleanuphand = s->statem.cleanuphand; in tls_finish_handshake()
1056 * RFC6083: SCTP provides a reliable and in-sequence transport service for DTLS in tls_finish_handshake()
1068 BUF_MEM_free(s->init_buf); in tls_finish_handshake()
1069 s->init_buf = NULL; 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()
1096 if (s->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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
1413 if (s->options & SSL_OP_NO_COMPRESSION) in ssl_allow_compression()
1425 return a < b ? -1 : 1; in version_cmp()
1426 return DTLS_VERSION_LT(a, b) ? -1 : 1; in version_cmp()
1430 int version; member
1491 * ssl_method_error - Check whether an SSL_METHOD is enabled.
1500 int version = method->version; in ssl_method_error() local
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()
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()
1568 curve = ssl_get_EC_curve_nid(s->cert->pkeys[SSL_PKEY_ECC].privatekey); in is_tls13_capable()
1577 * ssl_version_supported - Check that the specified `version` is supported by
1581 * @version: Protocol version to test against
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()
1609 || version != TLS1_3_VERSION in ssl_version_supported()
1612 *meth = vent->cmeth(); in ssl_version_supported()
1620 * ssl_check_version_downgrade - In response to RFC7507 SCSV version
1622 * supported protocol version.
1626 * Returns 1 when using the highest enabled version, 0 otherwise.
1634 * Check that the current protocol is the highest enabled version in ssl_check_version_downgrade()
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()
1643 * highest protocol version). 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.
1667 * @method_version: The version of the current SSL_METHOD.
1668 * @version: the intended limit.
1673 int ssl_set_version_bound(int method_version, int version, int *bound) in ssl_set_version_bound() argument
1678 if (version == 0) { in ssl_set_version_bound()
1679 *bound = version; in ssl_set_version_bound()
1683 valid_tls = version >= SSL3_VERSION && version <= TLS_MAX_VERSION_INTERNAL; in ssl_set_version_bound()
1685 DTLS_VERSION_LE(version, DTLS_MAX_VERSION_INTERNAL) && in ssl_set_version_bound()
1686 DTLS_VERSION_GE(version, DTLS1_BAD_VER); in ssl_set_version_bound()
1691 /*- in ssl_set_version_bound()
1694 * Note, DTLS version numbers are decreasing, use comparison macros. 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()
1711 *bound = version; in ssl_set_version_bound()
1716 *bound = version; in ssl_set_version_bound()
1744 * ssl_choose_server_version - Choose server (D)TLS version. Called when the
1745 * client HELLO is received to select the final server protocol version and
1746 * the version specific method.
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()
1761 * handle version. 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()
1775 if (version_cmp(s, client_version, s->version) < 0) in ssl_choose_server_version()
1779 * If this SSL handle is not from a version flexible method we don't 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()
1843 if (s->hello_retry_request != SSL_HRR_NONE) { 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()
1862 * version we can negotiate is TLSv1.2 in ssl_choose_server_version()
1868 * No supported versions extension, so we just use the version supplied in 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()
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
1891 * server HELLO is received to select the final client protocol version and
1892 * the version specific method.
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()
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()
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()
1933 * If this SSL handle is not from a version flexible method we don't in ssl_choose_client_version()
1937 * ssl_method_error(s, s->method) in ssl_choose_client_version()
1950 s->version = origv; 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()
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()
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()
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()
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()
2008 * ssl_get_min_max_version - get minimum and maximum protocol version
2010 * @min_version: The minimum supported version
2011 * @max_version: The maximum supported version
2012 * @real_max: The highest version below the lowest compile time version hole
2013 * where that hole lies above at least one run-time enabled
2016 * Work out what version we should be using for the initial ClientHello if the
2017 * version is initially (D)TLS_ANY_VERSION. We apply any explicit SSL_OP_NO_xxx
2020 * so we don't advertise the wrong protocol version to only reject the outcome later.
2023 * TLS 1.1 is disabled, but the security level, Suite-B and/or MinProtocol
2032 int version, tmp_real_max; in ssl_get_min_max_version() local
2039 switch (s->method->version) { in ssl_get_min_max_version()
2042 * If this SSL handle is not from a version flexible method we don't 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()
2050 * Providing a real_max only makes sense where we're using a version in ssl_get_min_max_version()
2066 * below X enabled. This is required in order to maintain the "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()
2070 * Our initial state is hole == 1, version == 0. That is, versions above in ssl_get_min_max_version()
2071 * the first version in the method table are disabled (a "hole" above in ssl_get_min_max_version()
2072 * the valid protocol entries) and we don't have a selected version yet. in ssl_get_min_max_version()
2074 * Whenever "hole == 1", and we hit an enabled method, its version becomes in ssl_get_min_max_version()
2075 * the selected version, and the method becomes a candidate "single" in ssl_get_min_max_version()
2085 *min_version = version = 0; in ssl_get_min_max_version()
2090 for (vent = table; vent->version != 0; ++vent) { in ssl_get_min_max_version()
2093 * "version capability" vector. 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()
2109 *min_version = method->version; in ssl_get_min_max_version()
2113 version = (single = method)->version; in ssl_get_min_max_version()
2114 *min_version = version; in ssl_get_min_max_version()
2119 *max_version = version; in ssl_get_min_max_version()
2122 if (version == 0) in ssl_get_min_max_version()
2129 * ssl_set_client_hello_version - Work out what version we should be using for
2142 * last time, regardless of which version we eventually negotiated. in ssl_set_client_hello_version()
2152 s->version = ver_max; in ssl_set_client_hello_version()
2158 s->client_version = ver_max; in ssl_set_client_hello_version()
2219 msghdr[SSL3_HM_HEADER_LENGTH - 1] = (unsigned char)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()
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()
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()
2306 if (s->server) { in STACK_OF()
2320 /* Start sub-packet for client CA list */ in construct_ca_names()
2326 if ((ca_sk != NULL) && !(s->options & SSL_OP_DISABLE_TLSEXT_CA_NAMES)) { in construct_ca_names()
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,
2379 if (s->pha_dgst == NULL) { 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()
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()
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
2406 if (s->pha_dgst == NULL) { 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()