Lines Matching refs:ssl
48 int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl, in mbedtls_ssl_set_client_transport_id() argument
52 if (ssl->conf->endpoint != MBEDTLS_SSL_IS_SERVER) { in mbedtls_ssl_set_client_transport_id()
56 mbedtls_free(ssl->cli_id); in mbedtls_ssl_set_client_transport_id()
58 if ((ssl->cli_id = mbedtls_calloc(1, ilen)) == NULL) { in mbedtls_ssl_set_client_transport_id()
62 memcpy(ssl->cli_id, info, ilen); in mbedtls_ssl_set_client_transport_id()
63 ssl->cli_id_len = ilen; in mbedtls_ssl_set_client_transport_id()
107 static int ssl_parse_renegotiation_info(mbedtls_ssl_context *ssl, in ssl_parse_renegotiation_info() argument
112 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_parse_renegotiation_info()
114 if (len != 1 + ssl->verify_data_len || in ssl_parse_renegotiation_info()
115 buf[0] != ssl->verify_data_len || in ssl_parse_renegotiation_info()
116 mbedtls_ct_memcmp(buf + 1, ssl->peer_verify_data, in ssl_parse_renegotiation_info()
117 ssl->verify_data_len) != 0) { in ssl_parse_renegotiation_info()
119 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_renegotiation_info()
128 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_renegotiation_info()
133 ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; in ssl_parse_renegotiation_info()
181 static int ssl_parse_supported_groups_ext(mbedtls_ssl_context *ssl, in ssl_parse_supported_groups_ext() argument
191 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_supported_groups_ext()
199 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_supported_groups_ext()
205 if (ssl->handshake->curves_tls_id != NULL) { in ssl_parse_supported_groups_ext()
207 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_supported_groups_ext()
221 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_supported_groups_ext()
226 ssl->handshake->curves_tls_id = curves_tls_id; in ssl_parse_supported_groups_ext()
246 static int ssl_parse_supported_point_formats(mbedtls_ssl_context *ssl, in ssl_parse_supported_point_formats() argument
255 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_supported_point_formats()
267 ssl->handshake->ecdh_ctx.point_format = p[0]; in ssl_parse_supported_point_formats()
271 mbedtls_ecjpake_set_point_format(&ssl->handshake->ecjpake_ctx, in ssl_parse_supported_point_formats()
290 static int ssl_parse_ecjpake_kkpp(mbedtls_ssl_context *ssl, in ssl_parse_ecjpake_kkpp() argument
297 if (ssl->handshake->psa_pake_ctx_is_ok != 1) in ssl_parse_ecjpake_kkpp()
299 if (mbedtls_ecjpake_check(&ssl->handshake->ecjpake_ctx) != 0) in ssl_parse_ecjpake_kkpp()
308 &ssl->handshake->psa_pake_ctx, buf, len, in ssl_parse_ecjpake_kkpp()
310 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_parse_ecjpake_kkpp()
311 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_parse_ecjpake_kkpp()
315 ssl, in ssl_parse_ecjpake_kkpp()
322 if ((ret = mbedtls_ecjpake_read_round_one(&ssl->handshake->ecjpake_ctx, in ssl_parse_ecjpake_kkpp()
325 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_ecjpake_kkpp()
332 ssl->handshake->cli_exts |= MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK; in ssl_parse_ecjpake_kkpp()
340 static int ssl_parse_max_fragment_length_ext(mbedtls_ssl_context *ssl, in ssl_parse_max_fragment_length_ext() argument
346 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_max_fragment_length_ext()
351 ssl->session_negotiate->mfl_code = buf[0]; in ssl_parse_max_fragment_length_ext()
359 static int ssl_parse_cid_ext(mbedtls_ssl_context *ssl, in ssl_parse_cid_ext() argument
366 if (ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_cid_ext()
368 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_cid_ext()
381 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_cid_ext()
391 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_cid_ext()
397 if (ssl->negotiate_cid == MBEDTLS_SSL_CID_DISABLED) { in ssl_parse_cid_ext()
406 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_cid_ext()
411 ssl->handshake->cid_in_use = MBEDTLS_SSL_CID_ENABLED; in ssl_parse_cid_ext()
412 ssl->handshake->peer_cid_len = (uint8_t) peer_cid_len; in ssl_parse_cid_ext()
413 memcpy(ssl->handshake->peer_cid, buf, peer_cid_len); in ssl_parse_cid_ext()
424 static int ssl_parse_encrypt_then_mac_ext(mbedtls_ssl_context *ssl, in ssl_parse_encrypt_then_mac_ext() argument
430 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_encrypt_then_mac_ext()
437 if (ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_ENABLED) { in ssl_parse_encrypt_then_mac_ext()
438 ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_ENABLED; in ssl_parse_encrypt_then_mac_ext()
447 static int ssl_parse_extended_ms_ext(mbedtls_ssl_context *ssl, in ssl_parse_extended_ms_ext() argument
453 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_extended_ms_ext()
460 if (ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_ENABLED) { in ssl_parse_extended_ms_ext()
461 ssl->handshake->extended_ms = MBEDTLS_SSL_EXTENDED_MS_ENABLED; in ssl_parse_extended_ms_ext()
470 static int ssl_parse_session_ticket_ext(mbedtls_ssl_context *ssl, in ssl_parse_session_ticket_ext() argument
479 if (ssl->conf->f_ticket_parse == NULL || in ssl_parse_session_ticket_ext()
480 ssl->conf->f_ticket_write == NULL) { in ssl_parse_session_ticket_ext()
485 ssl->handshake->new_session_ticket = 1; in ssl_parse_session_ticket_ext()
494 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_parse_session_ticket_ext()
503 if ((ret = ssl->conf->f_ticket_parse(ssl->conf->p_ticket, &session, in ssl_parse_session_ticket_ext()
522 session.id_len = ssl->session_negotiate->id_len; in ssl_parse_session_ticket_ext()
523 memcpy(&session.id, ssl->session_negotiate->id, session.id_len); in ssl_parse_session_ticket_ext()
525 mbedtls_ssl_session_free(ssl->session_negotiate); in ssl_parse_session_ticket_ext()
526 memcpy(ssl->session_negotiate, &session, sizeof(mbedtls_ssl_session)); in ssl_parse_session_ticket_ext()
533 ssl->handshake->resume = 1; in ssl_parse_session_ticket_ext()
536 ssl->handshake->new_session_ticket = 0; in ssl_parse_session_ticket_ext()
544 static int ssl_parse_use_srtp_ext(mbedtls_ssl_context *ssl, in ssl_parse_use_srtp_ext() argument
556 if ((ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) || in ssl_parse_use_srtp_ext()
557 (ssl->conf->dtls_srtp_profile_list == NULL) || in ssl_parse_use_srtp_ext()
558 (ssl->conf->dtls_srtp_profile_list_len == 0)) { in ssl_parse_use_srtp_ext()
580 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_use_srtp_ext()
585 ssl->dtls_srtp_info.chosen_dtls_srtp_profile = MBEDTLS_TLS_SRTP_UNSET; in ssl_parse_use_srtp_ext()
594 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_use_srtp_ext()
614 for (i = 0; i < ssl->conf->dtls_srtp_profile_list_len; i++) { in ssl_parse_use_srtp_ext()
615 if (client_protection == ssl->conf->dtls_srtp_profile_list[i]) { in ssl_parse_use_srtp_ext()
616 ssl->dtls_srtp_info.chosen_dtls_srtp_profile = ssl->conf->dtls_srtp_profile_list[i]; in ssl_parse_use_srtp_ext()
623 if (ssl->dtls_srtp_info.chosen_dtls_srtp_profile != MBEDTLS_TLS_SRTP_UNSET) { in ssl_parse_use_srtp_ext()
633 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_use_srtp_ext()
639 if (ssl->conf->dtls_srtp_mki_support == MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED && in ssl_parse_use_srtp_ext()
641 ssl->dtls_srtp_info.mki_len = mki_length; in ssl_parse_use_srtp_ext()
643 memcpy(ssl->dtls_srtp_info.mki_value, buf, mki_length); in ssl_parse_use_srtp_ext()
645 MBEDTLS_SSL_DEBUG_BUF(3, "using mki", ssl->dtls_srtp_info.mki_value, in ssl_parse_use_srtp_ext()
646 ssl->dtls_srtp_info.mki_len); in ssl_parse_use_srtp_ext()
687 static int ssl_pick_cert(mbedtls_ssl_context *ssl, in ssl_pick_cert() argument
703 if (ssl->handshake->sni_key_cert != NULL) { in ssl_pick_cert()
704 list = ssl->handshake->sni_key_cert; in ssl_pick_cert()
707 list = ssl->conf->key_cert; in ssl_pick_cert()
734 key_type_matches = ((ssl->conf->f_async_sign_start != NULL || in ssl_pick_cert()
735 ssl->conf->f_async_decrypt_start != NULL || in ssl_pick_cert()
768 ssl->handshake->curves_tls_id) != 0) { in ssl_pick_cert()
780 ssl->handshake->key_cert = cur; in ssl_pick_cert()
782 ssl->handshake->key_cert->cert); in ssl_pick_cert()
795 static int ssl_ciphersuite_match(mbedtls_ssl_context *ssl, int suite_id, in ssl_ciphersuite_match() argument
813 if (suite_info->min_tls_version > ssl->tls_version || in ssl_ciphersuite_match()
814 suite_info->max_tls_version < ssl->tls_version) { in ssl_ciphersuite_match()
821 (ssl->handshake->cli_exts & MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK) == 0) { in ssl_ciphersuite_match()
832 (ssl->handshake->curves_tls_id == NULL || in ssl_ciphersuite_match()
833 ssl->handshake->curves_tls_id[0] == 0)) { in ssl_ciphersuite_match()
844 ssl_conf_has_psk_or_cb(ssl->conf) == 0) { in ssl_ciphersuite_match()
858 if (ssl_pick_cert(ssl, suite_info) != 0) { in ssl_ciphersuite_match()
871 ssl, mbedtls_ssl_sig_from_pk_alg(sig_type)) == MBEDTLS_SSL_HASH_NONE) { in ssl_ciphersuite_match()
887 static int ssl_parse_client_hello(mbedtls_ssl_context *ssl) in ssl_parse_client_hello() argument
928 renegotiating = (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE); in ssl_parse_client_hello()
930 if (!renegotiating && !ssl->keep_current_message) { in ssl_parse_client_hello()
931 if ((ret = mbedtls_ssl_fetch_input(ssl, 5)) != 0) { in ssl_parse_client_hello()
938 buf = ssl->in_hdr; in ssl_parse_client_hello()
940 MBEDTLS_SSL_DEBUG_BUF(4, "record header", buf, mbedtls_ssl_in_hdr_len(ssl)); in ssl_parse_client_hello()
960 MBEDTLS_GET_UINT16_BE(ssl->in_len, 0))); in ssl_parse_client_hello()
968 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM in ssl_parse_client_hello()
970 && ssl->renego_status == MBEDTLS_SSL_INITIAL_HANDSHAKE in ssl_parse_client_hello()
974 if (ssl->in_ctr[0] != 0 || ssl->in_ctr[1] != 0) { in ssl_parse_client_hello()
979 memcpy(&ssl->cur_out_ctr[2], ssl->in_ctr + 2, in ssl_parse_client_hello()
980 sizeof(ssl->cur_out_ctr) - 2); in ssl_parse_client_hello()
983 if (mbedtls_ssl_dtls_replay_check(ssl) != 0) { in ssl_parse_client_hello()
985 ssl->next_record_offset = 0; in ssl_parse_client_hello()
986 ssl->in_left = 0; in ssl_parse_client_hello()
991 mbedtls_ssl_dtls_replay_update(ssl); in ssl_parse_client_hello()
996 msg_len = MBEDTLS_GET_UINT16_BE(ssl->in_len, 0); in ssl_parse_client_hello()
999 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_parse_client_hello()
1001 msg_len = ssl->in_hslen; in ssl_parse_client_hello()
1005 if (ssl->keep_current_message) { in ssl_parse_client_hello()
1006 ssl->keep_current_message = 0; in ssl_parse_client_hello()
1013 if ((ret = mbedtls_ssl_fetch_input(ssl, in ssl_parse_client_hello()
1014 mbedtls_ssl_in_hdr_len(ssl) + msg_len)) != 0) { in ssl_parse_client_hello()
1021 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1022 ssl->next_record_offset = msg_len + mbedtls_ssl_in_hdr_len(ssl); in ssl_parse_client_hello()
1025 ssl->in_left = 0; in ssl_parse_client_hello()
1029 buf = ssl->in_msg; in ssl_parse_client_hello()
1033 ret = ssl->handshake->update_checksum(ssl, buf, msg_len); in ssl_parse_client_hello()
1047 if (msg_len < mbedtls_ssl_hs_hdr_len(ssl)) { in ssl_parse_client_hello()
1072 if (msg_len != mbedtls_ssl_hs_hdr_len(ssl) + handshake_len) { in ssl_parse_client_hello()
1075 (unsigned) mbedtls_ssl_hs_hdr_len(ssl), in ssl_parse_client_hello()
1082 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1088 if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS) { in ssl_parse_client_hello()
1090 unsigned int cli_msg_seq = (unsigned int) MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4); in ssl_parse_client_hello()
1091 if (cli_msg_seq != ssl->handshake->in_msg_seq) { in ssl_parse_client_hello()
1094 ssl->handshake->in_msg_seq)); in ssl_parse_client_hello()
1098 ssl->handshake->in_msg_seq++; in ssl_parse_client_hello()
1102 unsigned int cli_msg_seq = (unsigned int) MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4); in ssl_parse_client_hello()
1103 ssl->handshake->out_msg_seq = cli_msg_seq; in ssl_parse_client_hello()
1104 ssl->handshake->in_msg_seq = cli_msg_seq + 1; in ssl_parse_client_hello()
1112 fragment_offset = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 6); in ssl_parse_client_hello()
1113 fragment_length = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 9); in ssl_parse_client_hello()
1114 length = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 1); in ssl_parse_client_hello()
1127 buf += mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_hello()
1128 msg_len -= mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_hello()
1161 ssl->tls_version = (mbedtls_ssl_protocol_version) mbedtls_ssl_read_version(buf, in ssl_parse_client_hello()
1162 … ssl->conf->transport); in ssl_parse_client_hello()
1163 ssl->session_negotiate->tls_version = ssl->tls_version; in ssl_parse_client_hello()
1164 ssl->session_negotiate->endpoint = ssl->conf->endpoint; in ssl_parse_client_hello()
1166 if (ssl->tls_version != MBEDTLS_SSL_VERSION_TLS1_2) { in ssl_parse_client_hello()
1168 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1178 memcpy(ssl->handshake->randbytes, buf + 2, 32); in ssl_parse_client_hello()
1185 if (sess_len > sizeof(ssl->session_negotiate->id) || in ssl_parse_client_hello()
1188 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1195 ssl->session_negotiate->id_len = sess_len; in ssl_parse_client_hello()
1196 memset(ssl->session_negotiate->id, 0, in ssl_parse_client_hello()
1197 sizeof(ssl->session_negotiate->id)); in ssl_parse_client_hello()
1198 memcpy(ssl->session_negotiate->id, buf + 35, in ssl_parse_client_hello()
1199 ssl->session_negotiate->id_len); in ssl_parse_client_hello()
1205 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1211 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1220 if (ssl->conf->f_cookie_check != NULL in ssl_parse_client_hello()
1222 && ssl->renego_status == MBEDTLS_SSL_INITIAL_HANDSHAKE in ssl_parse_client_hello()
1225 if (ssl->conf->f_cookie_check(ssl->conf->p_cookie, in ssl_parse_client_hello()
1227 ssl->cli_id, ssl->cli_id_len) != 0) { in ssl_parse_client_hello()
1229 ssl->handshake->cookie_verify_result = 1; in ssl_parse_client_hello()
1232 ssl->handshake->cookie_verify_result = 0; in ssl_parse_client_hello()
1261 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1283 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1298 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1307 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1323 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1332 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1340 ret = mbedtls_ssl_parse_server_name_ext(ssl, ext + 4, in ssl_parse_client_hello()
1354 ret = ssl_parse_renegotiation_info(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1364 ret = mbedtls_ssl_parse_sig_alg_ext(ssl, ext + 4, ext + 4 + ext_size); in ssl_parse_client_hello()
1379 ret = ssl_parse_supported_groups_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1387 ssl->handshake->cli_exts |= MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT; in ssl_parse_client_hello()
1389 ret = ssl_parse_supported_point_formats(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1402 ret = ssl_parse_ecjpake_kkpp(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1413 ret = ssl_parse_max_fragment_length_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1424 ret = ssl_parse_cid_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1435 ret = ssl_parse_encrypt_then_mac_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1446 ret = ssl_parse_extended_ms_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1457 ret = ssl_parse_session_ticket_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1468 ret = mbedtls_ssl_parse_alpn_ext(ssl, ext + 4, in ssl_parse_client_hello()
1480 ret = ssl_parse_use_srtp_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1503 uint16_t *received_sig_algs = ssl->handshake->received_sig_algs; in ssl_parse_client_hello()
1532 if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS) { in ssl_parse_client_hello()
1535 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1540 ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; in ssl_parse_client_hello()
1548 if (ssl->secure_renegotiation != MBEDTLS_SSL_SECURE_RENEGOTIATION && in ssl_parse_client_hello()
1549 ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE) { in ssl_parse_client_hello()
1554 else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1555 ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION && in ssl_parse_client_hello()
1559 } else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1560 ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && in ssl_parse_client_hello()
1561 ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) { in ssl_parse_client_hello()
1564 } else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1565 ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && in ssl_parse_client_hello()
1573 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1581 if (ssl->conf->f_cert_cb && (ret = ssl->conf->f_cert_cb(ssl)) != 0) { in ssl_parse_client_hello()
1586 ssl->handshake->sni_name = NULL; in ssl_parse_client_hello()
1587 ssl->handshake->sni_name_len = 0; in ssl_parse_client_hello()
1597 ciphersuites = ssl->conf->ciphersuite_list; in ssl_parse_client_hello()
1600 if (ssl->conf->respect_cli_pref == MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT) { in ssl_parse_client_hello()
1609 if ((ret = ssl_ciphersuite_match(ssl, ciphersuites[i], in ssl_parse_client_hello()
1628 if ((ret = ssl_ciphersuite_match(ssl, ciphersuites[i], in ssl_parse_client_hello()
1643 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1648 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1656 ssl->session_negotiate->ciphersuite = ciphersuites[i]; in ssl_parse_client_hello()
1657 ssl->handshake->ciphersuite_info = ciphersuite_info; in ssl_parse_client_hello()
1659 ssl->state++; in ssl_parse_client_hello()
1662 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1663 mbedtls_ssl_recv_flight_completed(ssl); in ssl_parse_client_hello()
1673 ssl, mbedtls_ssl_sig_from_pk_alg(sig_alg)); in ssl_parse_client_hello()
1688 static void ssl_write_cid_ext(mbedtls_ssl_context *ssl, in ssl_write_cid_ext() argument
1694 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_cid_ext()
1700 if (ssl->handshake->cid_in_use == MBEDTLS_SSL_CID_DISABLED) { in ssl_write_cid_ext()
1706 if (end < p || (size_t) (end - p) < (unsigned) (ssl->own_cid_len + 5)) { in ssl_write_cid_ext()
1720 ext_len = (size_t) ssl->own_cid_len + 1; in ssl_write_cid_ext()
1724 *p++ = (uint8_t) ssl->own_cid_len; in ssl_write_cid_ext()
1725 memcpy(p, ssl->own_cid, ssl->own_cid_len); in ssl_write_cid_ext()
1727 *olen = ssl->own_cid_len + 5; in ssl_write_cid_ext()
1732 static void ssl_write_encrypt_then_mac_ext(mbedtls_ssl_context *ssl, in ssl_write_encrypt_then_mac_ext() argument
1746 ssl->session_negotiate->ciphersuite); in ssl_write_encrypt_then_mac_ext()
1748 ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_DISABLED; in ssl_write_encrypt_then_mac_ext()
1752 ssl->session_negotiate->encrypt_then_mac, in ssl_write_encrypt_then_mac_ext()
1756 ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_DISABLED; in ssl_write_encrypt_then_mac_ext()
1760 if (ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED) { in ssl_write_encrypt_then_mac_ext()
1778 static void ssl_write_extended_ms_ext(mbedtls_ssl_context *ssl, in ssl_write_extended_ms_ext() argument
1784 if (ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED) { in ssl_write_extended_ms_ext()
1803 static void ssl_write_session_ticket_ext(mbedtls_ssl_context *ssl, in ssl_write_session_ticket_ext() argument
1809 if (ssl->handshake->new_session_ticket == 0) { in ssl_write_session_ticket_ext()
1826 static void ssl_write_renegotiation_ext(mbedtls_ssl_context *ssl, in ssl_write_renegotiation_ext() argument
1832 if (ssl->secure_renegotiation != MBEDTLS_SSL_SECURE_RENEGOTIATION) { in ssl_write_renegotiation_ext()
1843 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_write_renegotiation_ext()
1845 *p++ = (ssl->verify_data_len * 2 + 1) & 0xFF; in ssl_write_renegotiation_ext()
1846 *p++ = ssl->verify_data_len * 2 & 0xFF; in ssl_write_renegotiation_ext()
1848 memcpy(p, ssl->peer_verify_data, ssl->verify_data_len); in ssl_write_renegotiation_ext()
1849 p += ssl->verify_data_len; in ssl_write_renegotiation_ext()
1850 memcpy(p, ssl->own_verify_data, ssl->verify_data_len); in ssl_write_renegotiation_ext()
1851 p += ssl->verify_data_len; in ssl_write_renegotiation_ext()
1864 static void ssl_write_max_fragment_length_ext(mbedtls_ssl_context *ssl, in ssl_write_max_fragment_length_ext() argument
1870 if (ssl->session_negotiate->mfl_code == MBEDTLS_SSL_MAX_FRAG_LEN_NONE) { in ssl_write_max_fragment_length_ext()
1883 *p++ = ssl->session_negotiate->mfl_code; in ssl_write_max_fragment_length_ext()
1892 static void ssl_write_supported_point_formats_ext(mbedtls_ssl_context *ssl, in ssl_write_supported_point_formats_ext() argument
1897 ((void) ssl); in ssl_write_supported_point_formats_ext()
1899 if ((ssl->handshake->cli_exts & in ssl_write_supported_point_formats_ext()
1923 static void ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context *ssl, in ssl_write_ecjpake_kkpp_ext() argument
1929 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_ecjpake_kkpp_ext()
1935 if (ssl->handshake->ciphersuite_info->key_exchange != in ssl_write_ecjpake_kkpp_ext()
1951 ret = mbedtls_psa_ecjpake_write_round(&ssl->handshake->psa_pake_ctx, in ssl_write_ecjpake_kkpp_ext()
1955 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_write_ecjpake_kkpp_ext()
1956 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_write_ecjpake_kkpp_ext()
1961 ret = mbedtls_ecjpake_write_round_one(&ssl->handshake->ecjpake_ctx, in ssl_write_ecjpake_kkpp_ext()
1963 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_write_ecjpake_kkpp_ext()
1978 static void ssl_write_use_srtp_ext(mbedtls_ssl_context *ssl, in ssl_write_use_srtp_ext() argument
1984 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_use_srtp_ext()
1988 if ((ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) || in ssl_write_use_srtp_ext()
1989 (ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET)) { in ssl_write_use_srtp_ext()
1995 if (ssl->conf->dtls_srtp_mki_support == MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED) { in ssl_write_use_srtp_ext()
1996 mki_len = ssl->dtls_srtp_info.mki_len; in ssl_write_use_srtp_ext()
2025 ssl->dtls_srtp_info.chosen_dtls_srtp_profile); in ssl_write_use_srtp_ext()
2034 memcpy(&buf[9], ssl->dtls_srtp_info.mki_value, mki_len); in ssl_write_use_srtp_ext()
2042 static int ssl_write_hello_verify_request(mbedtls_ssl_context *ssl) in ssl_write_hello_verify_request() argument
2045 unsigned char *p = ssl->out_msg + 4; in ssl_write_hello_verify_request()
2059 mbedtls_ssl_write_version(p, ssl->conf->transport, ssl->tls_version); in ssl_write_hello_verify_request()
2064 if (ssl->conf->f_cookie_write == NULL) { in ssl_write_hello_verify_request()
2072 if ((ret = ssl->conf->f_cookie_write(ssl->conf->p_cookie, in ssl_write_hello_verify_request()
2073 &p, ssl->out_buf + MBEDTLS_SSL_OUT_BUFFER_LEN, in ssl_write_hello_verify_request()
2074 ssl->cli_id, ssl->cli_id_len)) != 0) { in ssl_write_hello_verify_request()
2083 ssl->out_msglen = (size_t) (p - ssl->out_msg); in ssl_write_hello_verify_request()
2084 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_hello_verify_request()
2085 ssl->out_msg[0] = MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST; in ssl_write_hello_verify_request()
2087 ssl->state = MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT; in ssl_write_hello_verify_request()
2089 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_hello_verify_request()
2095 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_hello_verify_request()
2096 (ret = mbedtls_ssl_flight_transmit(ssl)) != 0) { in ssl_write_hello_verify_request()
2108 static void ssl_handle_id_based_session_resumption(mbedtls_ssl_context *ssl) in ssl_handle_id_based_session_resumption() argument
2112 mbedtls_ssl_session * const session = ssl->session_negotiate; in ssl_handle_id_based_session_resumption()
2116 if (ssl->handshake->resume == 1) { in ssl_handle_id_based_session_resumption()
2122 if (ssl->conf->f_get_cache == NULL) { in ssl_handle_id_based_session_resumption()
2126 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_handle_id_based_session_resumption()
2133 ret = ssl->conf->f_get_cache(ssl->conf->p_cache, in ssl_handle_id_based_session_resumption()
2152 ssl->handshake->resume = 1; in ssl_handle_id_based_session_resumption()
2160 static int ssl_write_server_hello(mbedtls_ssl_context *ssl) in ssl_write_server_hello() argument
2172 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_server_hello()
2173 ssl->handshake->cookie_verify_result != 0) { in ssl_write_server_hello()
2177 return ssl_write_hello_verify_request(ssl); in ssl_write_server_hello()
2188 buf = ssl->out_msg; in ssl_write_server_hello()
2191 mbedtls_ssl_write_version(p, ssl->conf->transport, ssl->tls_version); in ssl_write_server_hello()
2205 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 4)) != 0) { in ssl_write_server_hello()
2212 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 20)) != 0) { in ssl_write_server_hello()
2225 if (mbedtls_ssl_conf_is_tls13_enabled(ssl->conf)) { in ssl_write_server_hello()
2238 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 8)) != 0) { in ssl_write_server_hello()
2244 memcpy(ssl->handshake->randbytes + 32, buf + 6, 32); in ssl_write_server_hello()
2248 ssl_handle_id_based_session_resumption(ssl); in ssl_write_server_hello()
2250 if (ssl->handshake->resume == 0) { in ssl_write_server_hello()
2255 ssl->state++; in ssl_write_server_hello()
2258 ssl->session_negotiate->start = mbedtls_time(NULL); in ssl_write_server_hello()
2262 if (ssl->handshake->new_session_ticket != 0) { in ssl_write_server_hello()
2263 ssl->session_negotiate->id_len = n = 0; in ssl_write_server_hello()
2264 memset(ssl->session_negotiate->id, 0, 32); in ssl_write_server_hello()
2268 ssl->session_negotiate->id_len = n = 32; in ssl_write_server_hello()
2269 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, ssl->session_negotiate->id, in ssl_write_server_hello()
2278 n = ssl->session_negotiate->id_len; in ssl_write_server_hello()
2279 ssl->state = MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC; in ssl_write_server_hello()
2281 if ((ret = mbedtls_ssl_derive_keys(ssl)) != 0) { in ssl_write_server_hello()
2295 *p++ = (unsigned char) ssl->session_negotiate->id_len; in ssl_write_server_hello()
2296 memcpy(p, ssl->session_negotiate->id, ssl->session_negotiate->id_len); in ssl_write_server_hello()
2297 p += ssl->session_negotiate->id_len; in ssl_write_server_hello()
2302 ssl->handshake->resume ? "a" : "no")); in ssl_write_server_hello()
2304 MBEDTLS_PUT_UINT16_BE(ssl->session_negotiate->ciphersuite, p, 0); in ssl_write_server_hello()
2309 … mbedtls_ssl_get_ciphersuite_name(ssl->session_negotiate->ciphersuite))); in ssl_write_server_hello()
2316 ssl_write_renegotiation_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2320 ssl_write_max_fragment_length_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2325 ssl_write_cid_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2330 ssl_write_encrypt_then_mac_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2335 ssl_write_extended_ms_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2340 ssl_write_session_ticket_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2348 mbedtls_ssl_ciphersuite_from_id(ssl->session_negotiate->ciphersuite); in ssl_write_server_hello()
2350 ssl_write_supported_point_formats_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2356 ssl_write_ecjpake_kkpp_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2362 if ((ret = mbedtls_ssl_write_alpn_ext(ssl, p + 2 + ext_len, end, &olen)) in ssl_write_server_hello()
2371 ssl_write_use_srtp_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2383 ssl->out_msglen = (size_t) (p - buf); in ssl_write_server_hello()
2384 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_hello()
2385 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO; in ssl_write_server_hello()
2387 ret = mbedtls_ssl_write_handshake_msg(ssl); in ssl_write_server_hello()
2396 static int ssl_write_certificate_request(mbedtls_ssl_context *ssl) in ssl_write_certificate_request() argument
2399 ssl->handshake->ciphersuite_info; in ssl_write_certificate_request()
2405 ssl->state++; in ssl_write_certificate_request()
2414 static int ssl_write_certificate_request(mbedtls_ssl_context *ssl) in ssl_write_certificate_request() argument
2418 ssl->handshake->ciphersuite_info; in ssl_write_certificate_request()
2422 const unsigned char * const end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_certificate_request()
2428 ssl->state++; in ssl_write_certificate_request()
2431 if (ssl->handshake->sni_authmode != MBEDTLS_SSL_VERIFY_UNSET) { in ssl_write_certificate_request()
2432 authmode = ssl->handshake->sni_authmode; in ssl_write_certificate_request()
2435 authmode = ssl->conf->authmode; in ssl_write_certificate_request()
2455 buf = ssl->out_msg; in ssl_write_certificate_request()
2491 const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl); in ssl_write_certificate_request()
2499 if (mbedtls_ssl_set_calc_verify_md(ssl, hash)) { in ssl_write_certificate_request()
2502 if (!mbedtls_ssl_sig_alg_is_supported(ssl, *sig_alg)) { in ssl_write_certificate_request()
2527 if (ssl->conf->cert_req_ca_list == MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED) { in ssl_write_certificate_request()
2535 if (ssl->handshake->dn_hints != NULL) { in ssl_write_certificate_request()
2536 crt = ssl->handshake->dn_hints; in ssl_write_certificate_request()
2539 if (ssl->conf->dn_hints != NULL) { in ssl_write_certificate_request()
2540 crt = ssl->conf->dn_hints; in ssl_write_certificate_request()
2544 if (ssl->handshake->sni_ca_chain != NULL) { in ssl_write_certificate_request()
2545 crt = ssl->handshake->sni_ca_chain; in ssl_write_certificate_request()
2548 crt = ssl->conf->ca_chain; in ssl_write_certificate_request()
2572 ssl->out_msglen = (size_t) (p - buf); in ssl_write_certificate_request()
2573 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_certificate_request()
2574 ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE_REQUEST; in ssl_write_certificate_request()
2575 MBEDTLS_PUT_UINT16_BE(total_dn_size, ssl->out_msg, 4 + ct_len + sa_len); in ssl_write_certificate_request()
2577 ret = mbedtls_ssl_write_handshake_msg(ssl); in ssl_write_certificate_request()
2589 static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl) in ssl_get_ecdh_params_from_cert() argument
2605 pk = mbedtls_ssl_own_key(ssl); in ssl_get_ecdh_params_from_cert()
2631 ssl->handshake->xxdh_psa_type = psa_get_key_type(&key_attributes); in ssl_get_ecdh_params_from_cert()
2632 ssl->handshake->xxdh_psa_bits = psa_get_key_bits(&key_attributes); in ssl_get_ecdh_params_from_cert()
2638 ssl->handshake->xxdh_psa_privkey = pk->priv_id; in ssl_get_ecdh_params_from_cert()
2639 ssl->handshake->xxdh_psa_privkey_is_external = 1; in ssl_get_ecdh_params_from_cert()
2650 PSA_KEY_TYPE_ECC_KEY_PAIR(ssl->handshake->xxdh_psa_type)); in ssl_get_ecdh_params_from_cert()
2651 psa_set_key_bits(&key_attributes, ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2659 &ssl->handshake->xxdh_psa_privkey); in ssl_get_ecdh_params_from_cert()
2667 ssl->handshake->xxdh_psa_privkey_is_external = 0; in ssl_get_ecdh_params_from_cert()
2690 &ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2692 ssl->handshake->xxdh_psa_type = key_type; in ssl_get_ecdh_params_from_cert()
2698 PSA_KEY_TYPE_ECC_KEY_PAIR(ssl->handshake->xxdh_psa_type)); in ssl_get_ecdh_params_from_cert()
2699 psa_set_key_bits(&key_attributes, ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2708 &ssl->handshake->xxdh_psa_privkey); in ssl_get_ecdh_params_from_cert()
2731 static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl) in ssl_get_ecdh_params_from_cert() argument
2735 const mbedtls_pk_context *private_key = mbedtls_ssl_own_key(ssl); in ssl_get_ecdh_params_from_cert()
2746 if ((ret = mbedtls_ecdh_get_params(&ssl->handshake->ecdh_ctx, in ssl_get_ecdh_params_from_cert()
2747 mbedtls_pk_ec_ro(*mbedtls_ssl_own_key(ssl)), in ssl_get_ecdh_params_from_cert()
2762 static int ssl_resume_server_key_exchange(mbedtls_ssl_context *ssl, in ssl_resume_server_key_exchange() argument
2770 unsigned char *sig_start = ssl->out_msg + ssl->out_msglen + 2; in ssl_resume_server_key_exchange()
2771 size_t sig_max_len = (ssl->out_buf + MBEDTLS_SSL_OUT_CONTENT_LEN in ssl_resume_server_key_exchange()
2773 int ret = ssl->conf->f_async_resume(ssl, in ssl_resume_server_key_exchange()
2776 ssl->handshake->async_in_progress = 0; in ssl_resume_server_key_exchange()
2777 mbedtls_ssl_set_async_operation_data(ssl, NULL); in ssl_resume_server_key_exchange()
2789 static int ssl_prepare_server_key_exchange(mbedtls_ssl_context *ssl, in ssl_prepare_server_key_exchange() argument
2793 ssl->handshake->ciphersuite_info; in ssl_prepare_server_key_exchange()
2808 size_t out_buf_len = ssl->out_buf_len - (size_t) (ssl->out_msg - ssl->out_buf); in ssl_prepare_server_key_exchange()
2810 size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (size_t) (ssl->out_msg - ssl->out_buf); in ssl_prepare_server_key_exchange()
2814 ssl->out_msglen = 4; /* header (type:1, length:3) to be written later */ in ssl_prepare_server_key_exchange()
2829 unsigned char *out_p = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
2830 unsigned char *end_p = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN - in ssl_prepare_server_key_exchange()
2831 ssl->out_msglen; in ssl_prepare_server_key_exchange()
2852 ret = mbedtls_psa_ecjpake_write_round(&ssl->handshake->psa_pake_ctx, in ssl_prepare_server_key_exchange()
2857 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_prepare_server_key_exchange()
2858 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_prepare_server_key_exchange()
2864 ssl->out_msglen += output_offset; in ssl_prepare_server_key_exchange()
2869 &ssl->handshake->ecjpake_ctx, in ssl_prepare_server_key_exchange()
2870 ssl->out_msg + ssl->out_msglen, in ssl_prepare_server_key_exchange()
2871 MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, &len, in ssl_prepare_server_key_exchange()
2872 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_prepare_server_key_exchange()
2878 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
2892 ssl->out_msg[ssl->out_msglen++] = 0x00; in ssl_prepare_server_key_exchange()
2893 ssl->out_msg[ssl->out_msglen++] = 0x00; in ssl_prepare_server_key_exchange()
2906 if (ssl->conf->dhm_P.p == NULL || ssl->conf->dhm_G.p == NULL) { in ssl_prepare_server_key_exchange()
2920 if ((ret = mbedtls_dhm_set_group(&ssl->handshake->dhm_ctx, in ssl_prepare_server_key_exchange()
2921 &ssl->conf->dhm_P, in ssl_prepare_server_key_exchange()
2922 &ssl->conf->dhm_G)) != 0) { in ssl_prepare_server_key_exchange()
2928 &ssl->handshake->dhm_ctx, in ssl_prepare_server_key_exchange()
2929 (int) mbedtls_dhm_get_len(&ssl->handshake->dhm_ctx), in ssl_prepare_server_key_exchange()
2930 ssl->out_msg + ssl->out_msglen, &len, in ssl_prepare_server_key_exchange()
2931 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
2937 dig_signed = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
2940 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
2942 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: X ", &ssl->handshake->dhm_ctx.X); in ssl_prepare_server_key_exchange()
2943 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: P ", &ssl->handshake->dhm_ctx.P); in ssl_prepare_server_key_exchange()
2944 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: G ", &ssl->handshake->dhm_ctx.G); in ssl_prepare_server_key_exchange()
2945 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: GX", &ssl->handshake->dhm_ctx.GX); in ssl_prepare_server_key_exchange()
2962 uint16_t *curr_tls_id = ssl->handshake->curves_tls_id; in ssl_prepare_server_key_exchange()
2963 const uint16_t *group_list = mbedtls_ssl_get_groups(ssl); in ssl_prepare_server_key_exchange()
2972 for (curr_tls_id = ssl->handshake->curves_tls_id; in ssl_prepare_server_key_exchange()
2992 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_prepare_server_key_exchange()
2993 uint8_t *p = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
3053 - (own_pubkey - ssl->out_msg)); in ssl_prepare_server_key_exchange()
3075 if ((ret = mbedtls_ecdh_setup(&ssl->handshake->ecdh_ctx, in ssl_prepare_server_key_exchange()
3082 &ssl->handshake->ecdh_ctx, &len, in ssl_prepare_server_key_exchange()
3083 ssl->out_msg + ssl->out_msglen, in ssl_prepare_server_key_exchange()
3084 MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, in ssl_prepare_server_key_exchange()
3085 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
3090 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_prepare_server_key_exchange()
3095 dig_signed = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
3098 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
3115 size_t dig_signed_len = (size_t) (ssl->out_msg + ssl->out_msglen - dig_signed); in ssl_prepare_server_key_exchange()
3132 ssl, mbedtls_ssl_sig_from_pk_alg(sig_alg)); in ssl_prepare_server_key_exchange()
3151 ret = mbedtls_ssl_get_key_exchange_md_tls1_2(ssl, hash, &hashlen, in ssl_prepare_server_key_exchange()
3184 ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_hash_from_md_alg(md_alg); in ssl_prepare_server_key_exchange()
3185 ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_sig_from_pk_alg(sig_alg); in ssl_prepare_server_key_exchange()
3188 if (ssl->conf->f_async_sign_start != NULL) { in ssl_prepare_server_key_exchange()
3189 ret = ssl->conf->f_async_sign_start(ssl, in ssl_prepare_server_key_exchange()
3190 mbedtls_ssl_own_cert(ssl), in ssl_prepare_server_key_exchange()
3197 ssl->handshake->async_in_progress = 1; in ssl_prepare_server_key_exchange()
3198 return ssl_resume_server_key_exchange(ssl, signature_len); in ssl_prepare_server_key_exchange()
3200 ssl->handshake->async_in_progress = 1; in ssl_prepare_server_key_exchange()
3209 if (mbedtls_ssl_own_key(ssl) == NULL) { in ssl_prepare_server_key_exchange()
3219 if ((ret = mbedtls_pk_sign(mbedtls_ssl_own_key(ssl), in ssl_prepare_server_key_exchange()
3221 ssl->out_msg + ssl->out_msglen + 2, in ssl_prepare_server_key_exchange()
3222 out_buf_len - ssl->out_msglen - 2, in ssl_prepare_server_key_exchange()
3224 ssl->conf->f_rng, in ssl_prepare_server_key_exchange()
3225 ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
3240 static int ssl_write_server_key_exchange(mbedtls_ssl_context *ssl) in ssl_write_server_key_exchange() argument
3246 ssl->handshake->ciphersuite_info; in ssl_write_server_key_exchange()
3259 ret = ssl_get_ecdh_params_from_cert(ssl); in ssl_write_server_key_exchange()
3270 ssl->state++; in ssl_write_server_key_exchange()
3279 if (ssl->handshake->async_in_progress != 0) { in ssl_write_server_key_exchange()
3281 ret = ssl_resume_server_key_exchange(ssl, &signature_len); in ssl_write_server_key_exchange()
3287 ret = ssl_prepare_server_key_exchange(ssl, &signature_len); in ssl_write_server_key_exchange()
3298 ssl->out_msglen = 0; in ssl_write_server_key_exchange()
3308 ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_1(signature_len); in ssl_write_server_key_exchange()
3309 ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_0(signature_len); in ssl_write_server_key_exchange()
3312 ssl->out_msg + ssl->out_msglen, in ssl_write_server_key_exchange()
3316 ssl->out_msglen += signature_len; in ssl_write_server_key_exchange()
3321 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_key_exchange()
3322 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE; in ssl_write_server_key_exchange()
3324 ssl->state++; in ssl_write_server_key_exchange()
3326 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_server_key_exchange()
3336 static int ssl_write_server_hello_done(mbedtls_ssl_context *ssl) in ssl_write_server_hello_done() argument
3342 ssl->out_msglen = 4; in ssl_write_server_hello_done()
3343 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_hello_done()
3344 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO_DONE; in ssl_write_server_hello_done()
3346 ssl->state++; in ssl_write_server_hello_done()
3349 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_write_server_hello_done()
3350 mbedtls_ssl_send_flight_completed(ssl); in ssl_write_server_hello_done()
3354 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_server_hello_done()
3360 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_server_hello_done()
3361 (ret = mbedtls_ssl_flight_transmit(ssl)) != 0) { in ssl_write_server_hello_done()
3375 static int ssl_parse_client_dh_public(mbedtls_ssl_context *ssl, unsigned char **p, in ssl_parse_client_dh_public() argument
3397 if ((ret = mbedtls_dhm_read_public(&ssl->handshake->dhm_ctx, *p, n)) != 0) { in ssl_parse_client_dh_public()
3404 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: GY", &ssl->handshake->dhm_ctx.GY); in ssl_parse_client_dh_public()
3416 static int ssl_resume_decrypt_pms(mbedtls_ssl_context *ssl, in ssl_resume_decrypt_pms() argument
3421 int ret = ssl->conf->f_async_resume(ssl, in ssl_resume_decrypt_pms()
3424 ssl->handshake->async_in_progress = 0; in ssl_resume_decrypt_pms()
3425 mbedtls_ssl_set_async_operation_data(ssl, NULL); in ssl_resume_decrypt_pms()
3433 static int ssl_decrypt_encrypted_pms(mbedtls_ssl_context *ssl, in ssl_decrypt_encrypted_pms() argument
3442 mbedtls_x509_crt *own_cert = mbedtls_ssl_own_cert(ssl); in ssl_decrypt_encrypted_pms()
3448 mbedtls_pk_context *private_key = mbedtls_ssl_own_key(ssl); in ssl_decrypt_encrypted_pms()
3454 if (ssl->handshake->async_in_progress != 0) { in ssl_decrypt_encrypted_pms()
3456 return ssl_resume_decrypt_pms(ssl, in ssl_decrypt_encrypted_pms()
3483 if (ssl->conf->f_async_decrypt_start != NULL) { in ssl_decrypt_encrypted_pms()
3484 ret = ssl->conf->f_async_decrypt_start(ssl, in ssl_decrypt_encrypted_pms()
3485 mbedtls_ssl_own_cert(ssl), in ssl_decrypt_encrypted_pms()
3492 ssl->handshake->async_in_progress = 1; in ssl_decrypt_encrypted_pms()
3493 return ssl_resume_decrypt_pms(ssl, in ssl_decrypt_encrypted_pms()
3498 ssl->handshake->async_in_progress = 1; in ssl_decrypt_encrypted_pms()
3514 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_decrypt_encrypted_pms()
3519 static int ssl_parse_encrypted_pms(mbedtls_ssl_context *ssl, in ssl_parse_encrypted_pms() argument
3525 unsigned char *pms = ssl->handshake->premaster + pms_offset; in ssl_parse_encrypted_pms()
3541 ret = ssl_decrypt_encrypted_pms(ssl, p, end, in ssl_parse_encrypted_pms()
3552 mbedtls_ssl_write_version(ver, ssl->conf->transport, in ssl_parse_encrypted_pms()
3553 ssl->session_negotiate->tls_version); in ssl_parse_encrypted_pms()
3572 ret = ssl->conf->f_rng(ssl->conf->p_rng, fake_pms, sizeof(fake_pms)); in ssl_parse_encrypted_pms()
3585 if (sizeof(ssl->handshake->premaster) < pms_offset || in ssl_parse_encrypted_pms()
3586 sizeof(ssl->handshake->premaster) - pms_offset < 48) { in ssl_parse_encrypted_pms()
3590 ssl->handshake->pmslen = 48; in ssl_parse_encrypted_pms()
3594 mbedtls_ct_memcpy_if(diff, pms, fake_pms, peer_pms, ssl->handshake->pmslen); in ssl_parse_encrypted_pms()
3603 static int ssl_parse_client_psk_identity(mbedtls_ssl_context *ssl, unsigned char **p, in ssl_parse_client_psk_identity() argument
3609 if (ssl_conf_has_psk_or_cb(ssl->conf) == 0) { in ssl_parse_client_psk_identity()
3630 if (ssl->conf->f_psk != NULL) { in ssl_parse_client_psk_identity()
3631 if (ssl->conf->f_psk(ssl->conf->p_psk, ssl, *p, n) != 0) { in ssl_parse_client_psk_identity()
3637 if (n != ssl->conf->psk_identity_len || in ssl_parse_client_psk_identity()
3638 mbedtls_ct_memcmp(ssl->conf->psk_identity, *p, n) != 0) { in ssl_parse_client_psk_identity()
3645 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_psk_identity()
3657 static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl) in ssl_parse_client_key_exchange() argument
3663 ciphersuite_info = ssl->handshake->ciphersuite_info; in ssl_parse_client_key_exchange()
3672 (ssl->handshake->async_in_progress != 0)) { in ssl_parse_client_key_exchange()
3679 if ((ret = mbedtls_ssl_read_record(ssl, 1)) != 0) { in ssl_parse_client_key_exchange()
3684 p = ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_key_exchange()
3685 end = ssl->in_msg + ssl->in_hslen; in ssl_parse_client_key_exchange()
3687 if (ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE) { in ssl_parse_client_key_exchange()
3692 if (ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE) { in ssl_parse_client_key_exchange()
3699 if ((ret = ssl_parse_client_dh_public(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3709 if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx, in ssl_parse_client_key_exchange()
3710 ssl->handshake->premaster, in ssl_parse_client_key_exchange()
3712 &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
3713 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3718 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: K ", &ssl->handshake->dhm_ctx.K); in ssl_parse_client_key_exchange()
3733 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_parse_client_key_exchange()
3791 if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3797 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3800 if ((ret = mbedtls_ecdh_calc_secret(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3801 &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
3802 ssl->handshake->premaster, in ssl_parse_client_key_exchange()
3804 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3809 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3819 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3830 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3842 if (ssl->handshake->async_in_progress != 0) { in ssl_parse_client_key_exchange()
3849 p += ssl->conf->psk_identity_len + 2; in ssl_parse_client_key_exchange()
3852 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3857 if ((ret = ssl_parse_encrypted_pms(ssl, p, end, 2)) != 0) { in ssl_parse_client_key_exchange()
3863 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3874 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3878 if ((ret = ssl_parse_client_dh_public(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3889 unsigned char *pms = ssl->handshake->premaster; in ssl_parse_client_key_exchange()
3890 unsigned char *pms_end = pms + sizeof(ssl->handshake->premaster); in ssl_parse_client_key_exchange()
3894 if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx, in ssl_parse_client_key_exchange()
3896 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3903 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: K ", &ssl->handshake->dhm_ctx.K); in ssl_parse_client_key_exchange()
3905 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3921 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_parse_client_key_exchange()
3923 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3969 unsigned char *psm = ssl->handshake->premaster; in ssl_parse_client_key_exchange()
3971 psm + sizeof(ssl->handshake->premaster); in ssl_parse_client_key_exchange()
3999 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
4004 if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
4010 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
4013 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
4024 if ((ret = ssl_parse_encrypted_pms(ssl, p, end, 0)) != 0) { in ssl_parse_client_key_exchange()
4034 &ssl->handshake->psa_pake_ctx, p, (size_t) (end - p), in ssl_parse_client_key_exchange()
4036 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_parse_client_key_exchange()
4037 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_parse_client_key_exchange()
4043 ret = mbedtls_ecjpake_read_round_two(&ssl->handshake->ecjpake_ctx, in ssl_parse_client_key_exchange()
4050 ret = mbedtls_ecjpake_derive_secret(&ssl->handshake->ecjpake_ctx, in ssl_parse_client_key_exchange()
4051 ssl->handshake->premaster, 32, &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
4052 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_parse_client_key_exchange()
4065 if ((ret = mbedtls_ssl_derive_keys(ssl)) != 0) { in ssl_parse_client_key_exchange()
4070 ssl->state++; in ssl_parse_client_key_exchange()
4079 static int ssl_parse_certificate_verify(mbedtls_ssl_context *ssl) in ssl_parse_certificate_verify() argument
4082 ssl->handshake->ciphersuite_info; in ssl_parse_certificate_verify()
4088 ssl->state++; in ssl_parse_certificate_verify()
4097 static int ssl_parse_certificate_verify(mbedtls_ssl_context *ssl) in ssl_parse_certificate_verify() argument
4107 ssl->handshake->ciphersuite_info; in ssl_parse_certificate_verify()
4114 ssl->state++; in ssl_parse_certificate_verify()
4119 if (ssl->session_negotiate->peer_cert == NULL) { in ssl_parse_certificate_verify()
4121 ssl->state++; in ssl_parse_certificate_verify()
4125 if (ssl->session_negotiate->peer_cert_digest == NULL) { in ssl_parse_certificate_verify()
4127 ssl->state++; in ssl_parse_certificate_verify()
4133 ret = mbedtls_ssl_read_record(ssl, 0 /* no checksum update */); in ssl_parse_certificate_verify()
4139 ssl->state++; in ssl_parse_certificate_verify()
4142 if (ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE || in ssl_parse_certificate_verify()
4143 ssl->in_msg[0] != MBEDTLS_SSL_HS_CERTIFICATE_VERIFY) { in ssl_parse_certificate_verify()
4148 i = mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_certificate_verify()
4151 peer_pk = &ssl->handshake->peer_pubkey; in ssl_parse_certificate_verify()
4153 if (ssl->session_negotiate->peer_cert == NULL) { in ssl_parse_certificate_verify()
4157 peer_pk = &ssl->session_negotiate->peer_cert->pk; in ssl_parse_certificate_verify()
4166 if (i + 2 > ssl->in_hslen) { in ssl_parse_certificate_verify()
4174 md_alg = mbedtls_ssl_md_alg_from_hash(ssl->in_msg[i]); in ssl_parse_certificate_verify()
4176 if (md_alg == MBEDTLS_MD_NONE || mbedtls_ssl_set_calc_verify_md(ssl, ssl->in_msg[i])) { in ssl_parse_certificate_verify()
4196 if ((pk_alg = mbedtls_ssl_pk_alg_from_sig(ssl->in_msg[i])) in ssl_parse_certificate_verify()
4213 if (i + 2 > ssl->in_hslen) { in ssl_parse_certificate_verify()
4218 sig_len = MBEDTLS_GET_UINT16_BE(ssl->in_msg, i); in ssl_parse_certificate_verify()
4221 if (i + sig_len != ssl->in_hslen) { in ssl_parse_certificate_verify()
4229 ret = ssl->handshake->calc_verify(ssl, hash, &dummy_hlen); in ssl_parse_certificate_verify()
4238 ssl->in_msg + i, sig_len)) != 0) { in ssl_parse_certificate_verify()
4243 ret = mbedtls_ssl_update_handshake_status(ssl); in ssl_parse_certificate_verify()
4257 static int ssl_write_new_session_ticket(mbedtls_ssl_context *ssl) in ssl_write_new_session_ticket() argument
4265 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_new_session_ticket()
4266 ssl->out_msg[0] = MBEDTLS_SSL_HS_NEW_SESSION_TICKET; in ssl_write_new_session_ticket()
4280 ssl->session_negotiate->ticket_creation_time = mbedtls_ms_time(); in ssl_write_new_session_ticket()
4282 if ((ret = ssl->conf->f_ticket_write(ssl->conf->p_ticket, in ssl_write_new_session_ticket()
4283 ssl->session_negotiate, in ssl_write_new_session_ticket()
4284 ssl->out_msg + 10, in ssl_write_new_session_ticket()
4285 ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN, in ssl_write_new_session_ticket()
4291 MBEDTLS_PUT_UINT32_BE(lifetime, ssl->out_msg, 4); in ssl_write_new_session_ticket()
4292 MBEDTLS_PUT_UINT16_BE(tlen, ssl->out_msg, 8); in ssl_write_new_session_ticket()
4293 ssl->out_msglen = 10 + tlen; in ssl_write_new_session_ticket()
4299 ssl->handshake->new_session_ticket = 0; in ssl_write_new_session_ticket()
4301 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_new_session_ticket()
4315 int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context *ssl) in mbedtls_ssl_handshake_server_step() argument
4319 MBEDTLS_SSL_DEBUG_MSG(2, ("server state: %d", ssl->state)); in mbedtls_ssl_handshake_server_step()
4321 switch (ssl->state) { in mbedtls_ssl_handshake_server_step()
4323 ssl->state = MBEDTLS_SSL_CLIENT_HELLO; in mbedtls_ssl_handshake_server_step()
4330 ret = ssl_parse_client_hello(ssl); in mbedtls_ssl_handshake_server_step()
4346 ret = ssl_write_server_hello(ssl); in mbedtls_ssl_handshake_server_step()
4350 ret = mbedtls_ssl_write_certificate(ssl); in mbedtls_ssl_handshake_server_step()
4354 ret = ssl_write_server_key_exchange(ssl); in mbedtls_ssl_handshake_server_step()
4358 ret = ssl_write_certificate_request(ssl); in mbedtls_ssl_handshake_server_step()
4362 ret = ssl_write_server_hello_done(ssl); in mbedtls_ssl_handshake_server_step()
4373 ret = mbedtls_ssl_parse_certificate(ssl); in mbedtls_ssl_handshake_server_step()
4377 ret = ssl_parse_client_key_exchange(ssl); in mbedtls_ssl_handshake_server_step()
4381 ret = ssl_parse_certificate_verify(ssl); in mbedtls_ssl_handshake_server_step()
4385 ret = mbedtls_ssl_parse_change_cipher_spec(ssl); in mbedtls_ssl_handshake_server_step()
4389 ret = mbedtls_ssl_parse_finished(ssl); in mbedtls_ssl_handshake_server_step()
4399 if (ssl->handshake->new_session_ticket != 0) { in mbedtls_ssl_handshake_server_step()
4400 ret = ssl_write_new_session_ticket(ssl); in mbedtls_ssl_handshake_server_step()
4403 ret = mbedtls_ssl_write_change_cipher_spec(ssl); in mbedtls_ssl_handshake_server_step()
4407 ret = mbedtls_ssl_write_finished(ssl); in mbedtls_ssl_handshake_server_step()
4412 ssl->state = MBEDTLS_SSL_HANDSHAKE_WRAPUP; in mbedtls_ssl_handshake_server_step()
4416 mbedtls_ssl_handshake_wrapup(ssl); in mbedtls_ssl_handshake_server_step()
4420 MBEDTLS_SSL_DEBUG_MSG(1, ("invalid state %d", ssl->state)); in mbedtls_ssl_handshake_server_step()