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()
770 ssl->handshake->curves_tls_id) != 0) { in ssl_pick_cert()
782 ssl->handshake->key_cert = cur; in ssl_pick_cert()
784 ssl->handshake->key_cert->cert); in ssl_pick_cert()
797 static int ssl_ciphersuite_match(mbedtls_ssl_context *ssl, int suite_id, in ssl_ciphersuite_match() argument
815 if (suite_info->min_tls_version > ssl->tls_version || in ssl_ciphersuite_match()
816 suite_info->max_tls_version < ssl->tls_version) { in ssl_ciphersuite_match()
823 (ssl->handshake->cli_exts & MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK) == 0) { in ssl_ciphersuite_match()
834 (ssl->handshake->curves_tls_id == NULL || in ssl_ciphersuite_match()
835 ssl->handshake->curves_tls_id[0] == 0)) { in ssl_ciphersuite_match()
846 ssl_conf_has_psk_or_cb(ssl->conf) == 0) { in ssl_ciphersuite_match()
860 if (ssl_pick_cert(ssl, suite_info) != 0) { in ssl_ciphersuite_match()
873 ssl, mbedtls_ssl_sig_from_pk_alg(sig_type)) == MBEDTLS_SSL_HASH_NONE) { in ssl_ciphersuite_match()
889 static int ssl_parse_client_hello(mbedtls_ssl_context *ssl) in ssl_parse_client_hello() argument
930 renegotiating = (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE); in ssl_parse_client_hello()
932 if (!renegotiating && !ssl->keep_current_message) { in ssl_parse_client_hello()
933 if ((ret = mbedtls_ssl_fetch_input(ssl, 5)) != 0) { in ssl_parse_client_hello()
940 buf = ssl->in_hdr; in ssl_parse_client_hello()
942 MBEDTLS_SSL_DEBUG_BUF(4, "record header", buf, mbedtls_ssl_in_hdr_len(ssl)); in ssl_parse_client_hello()
962 MBEDTLS_GET_UINT16_BE(ssl->in_len, 0))); in ssl_parse_client_hello()
970 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM in ssl_parse_client_hello()
972 && ssl->renego_status == MBEDTLS_SSL_INITIAL_HANDSHAKE in ssl_parse_client_hello()
976 if (ssl->in_ctr[0] != 0 || ssl->in_ctr[1] != 0) { in ssl_parse_client_hello()
981 memcpy(&ssl->cur_out_ctr[2], ssl->in_ctr + 2, in ssl_parse_client_hello()
982 sizeof(ssl->cur_out_ctr) - 2); in ssl_parse_client_hello()
985 if (mbedtls_ssl_dtls_replay_check(ssl) != 0) { in ssl_parse_client_hello()
987 ssl->next_record_offset = 0; in ssl_parse_client_hello()
988 ssl->in_left = 0; in ssl_parse_client_hello()
993 mbedtls_ssl_dtls_replay_update(ssl); in ssl_parse_client_hello()
998 msg_len = MBEDTLS_GET_UINT16_BE(ssl->in_len, 0); in ssl_parse_client_hello()
1001 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_parse_client_hello()
1003 msg_len = ssl->in_hslen; in ssl_parse_client_hello()
1007 if (ssl->keep_current_message) { in ssl_parse_client_hello()
1008 ssl->keep_current_message = 0; in ssl_parse_client_hello()
1015 if ((ret = mbedtls_ssl_fetch_input(ssl, in ssl_parse_client_hello()
1016 mbedtls_ssl_in_hdr_len(ssl) + msg_len)) != 0) { in ssl_parse_client_hello()
1023 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1024 ssl->next_record_offset = msg_len + mbedtls_ssl_in_hdr_len(ssl); in ssl_parse_client_hello()
1027 ssl->in_left = 0; in ssl_parse_client_hello()
1031 buf = ssl->in_msg; in ssl_parse_client_hello()
1035 ret = ssl->handshake->update_checksum(ssl, buf, msg_len); in ssl_parse_client_hello()
1049 if (msg_len < mbedtls_ssl_hs_hdr_len(ssl)) { in ssl_parse_client_hello()
1074 if (msg_len != mbedtls_ssl_hs_hdr_len(ssl) + handshake_len) { in ssl_parse_client_hello()
1077 (unsigned) mbedtls_ssl_hs_hdr_len(ssl), in ssl_parse_client_hello()
1084 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1090 if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS) { in ssl_parse_client_hello()
1092 unsigned int cli_msg_seq = (unsigned int) MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4); in ssl_parse_client_hello()
1093 if (cli_msg_seq != ssl->handshake->in_msg_seq) { in ssl_parse_client_hello()
1096 ssl->handshake->in_msg_seq)); in ssl_parse_client_hello()
1100 ssl->handshake->in_msg_seq++; in ssl_parse_client_hello()
1104 unsigned int cli_msg_seq = (unsigned int) MBEDTLS_GET_UINT16_BE(ssl->in_msg, 4); in ssl_parse_client_hello()
1105 ssl->handshake->out_msg_seq = cli_msg_seq; in ssl_parse_client_hello()
1106 ssl->handshake->in_msg_seq = cli_msg_seq + 1; in ssl_parse_client_hello()
1114 fragment_offset = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 6); in ssl_parse_client_hello()
1115 fragment_length = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 9); in ssl_parse_client_hello()
1116 length = MBEDTLS_GET_UINT24_BE(ssl->in_msg, 1); in ssl_parse_client_hello()
1129 buf += mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_hello()
1130 msg_len -= mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_hello()
1163 ssl->tls_version = (mbedtls_ssl_protocol_version) mbedtls_ssl_read_version(buf, in ssl_parse_client_hello()
1164 … ssl->conf->transport); in ssl_parse_client_hello()
1165 ssl->session_negotiate->tls_version = ssl->tls_version; in ssl_parse_client_hello()
1166 ssl->session_negotiate->endpoint = ssl->conf->endpoint; in ssl_parse_client_hello()
1168 if (ssl->tls_version != MBEDTLS_SSL_VERSION_TLS1_2) { in ssl_parse_client_hello()
1170 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1180 memcpy(ssl->handshake->randbytes, buf + 2, 32); in ssl_parse_client_hello()
1187 if (sess_len > sizeof(ssl->session_negotiate->id) || in ssl_parse_client_hello()
1190 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1197 ssl->session_negotiate->id_len = sess_len; in ssl_parse_client_hello()
1198 memset(ssl->session_negotiate->id, 0, in ssl_parse_client_hello()
1199 sizeof(ssl->session_negotiate->id)); in ssl_parse_client_hello()
1200 memcpy(ssl->session_negotiate->id, buf + 35, in ssl_parse_client_hello()
1201 ssl->session_negotiate->id_len); in ssl_parse_client_hello()
1207 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1213 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1222 if (ssl->conf->f_cookie_check != NULL in ssl_parse_client_hello()
1224 && ssl->renego_status == MBEDTLS_SSL_INITIAL_HANDSHAKE in ssl_parse_client_hello()
1227 if (ssl->conf->f_cookie_check(ssl->conf->p_cookie, in ssl_parse_client_hello()
1229 ssl->cli_id, ssl->cli_id_len) != 0) { in ssl_parse_client_hello()
1231 ssl->handshake->cookie_verify_result = 1; in ssl_parse_client_hello()
1234 ssl->handshake->cookie_verify_result = 0; in ssl_parse_client_hello()
1263 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1285 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1300 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1309 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1325 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1334 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1342 ret = mbedtls_ssl_parse_server_name_ext(ssl, ext + 4, in ssl_parse_client_hello()
1356 ret = ssl_parse_renegotiation_info(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1366 ret = mbedtls_ssl_parse_sig_alg_ext(ssl, ext + 4, ext + 4 + ext_size); in ssl_parse_client_hello()
1381 ret = ssl_parse_supported_groups_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1389 ssl->handshake->cli_exts |= MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT; in ssl_parse_client_hello()
1391 ret = ssl_parse_supported_point_formats(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1404 ret = ssl_parse_ecjpake_kkpp(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1415 ret = ssl_parse_max_fragment_length_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1426 ret = ssl_parse_cid_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1437 ret = ssl_parse_encrypt_then_mac_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1448 ret = ssl_parse_extended_ms_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1459 ret = ssl_parse_session_ticket_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1470 ret = mbedtls_ssl_parse_alpn_ext(ssl, ext + 4, in ssl_parse_client_hello()
1482 ret = ssl_parse_use_srtp_ext(ssl, ext + 4, ext_size); in ssl_parse_client_hello()
1505 uint16_t *received_sig_algs = ssl->handshake->received_sig_algs; in ssl_parse_client_hello()
1534 if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS) { in ssl_parse_client_hello()
1537 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1542 ssl->secure_renegotiation = MBEDTLS_SSL_SECURE_RENEGOTIATION; in ssl_parse_client_hello()
1550 if (ssl->secure_renegotiation != MBEDTLS_SSL_SECURE_RENEGOTIATION && in ssl_parse_client_hello()
1551 ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE) { in ssl_parse_client_hello()
1556 else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1557 ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION && in ssl_parse_client_hello()
1561 } else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1562 ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && in ssl_parse_client_hello()
1563 ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) { in ssl_parse_client_hello()
1566 } else if (ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && in ssl_parse_client_hello()
1567 ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && in ssl_parse_client_hello()
1575 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1583 if (ssl->conf->f_cert_cb && (ret = ssl->conf->f_cert_cb(ssl)) != 0) { in ssl_parse_client_hello()
1588 ssl->handshake->sni_name = NULL; in ssl_parse_client_hello()
1589 ssl->handshake->sni_name_len = 0; in ssl_parse_client_hello()
1599 ciphersuites = ssl->conf->ciphersuite_list; in ssl_parse_client_hello()
1602 if (ssl->conf->respect_cli_pref == MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT) { in ssl_parse_client_hello()
1611 if ((ret = ssl_ciphersuite_match(ssl, ciphersuites[i], in ssl_parse_client_hello()
1630 if ((ret = ssl_ciphersuite_match(ssl, ciphersuites[i], in ssl_parse_client_hello()
1645 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1650 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_hello()
1658 ssl->session_negotiate->ciphersuite = ciphersuites[i]; in ssl_parse_client_hello()
1659 ssl->handshake->ciphersuite_info = ciphersuite_info; in ssl_parse_client_hello()
1661 ssl->state++; in ssl_parse_client_hello()
1664 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_parse_client_hello()
1665 mbedtls_ssl_recv_flight_completed(ssl); in ssl_parse_client_hello()
1675 ssl, mbedtls_ssl_sig_from_pk_alg(sig_alg)); in ssl_parse_client_hello()
1690 static void ssl_write_cid_ext(mbedtls_ssl_context *ssl, in ssl_write_cid_ext() argument
1696 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_cid_ext()
1702 if (ssl->handshake->cid_in_use == MBEDTLS_SSL_CID_DISABLED) { in ssl_write_cid_ext()
1708 if (end < p || (size_t) (end - p) < (unsigned) (ssl->own_cid_len + 5)) { in ssl_write_cid_ext()
1722 ext_len = (size_t) ssl->own_cid_len + 1; in ssl_write_cid_ext()
1726 *p++ = (uint8_t) ssl->own_cid_len; in ssl_write_cid_ext()
1727 memcpy(p, ssl->own_cid, ssl->own_cid_len); in ssl_write_cid_ext()
1729 *olen = ssl->own_cid_len + 5; in ssl_write_cid_ext()
1734 static void ssl_write_encrypt_then_mac_ext(mbedtls_ssl_context *ssl, in ssl_write_encrypt_then_mac_ext() argument
1748 ssl->session_negotiate->ciphersuite); in ssl_write_encrypt_then_mac_ext()
1750 ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_DISABLED; in ssl_write_encrypt_then_mac_ext()
1754 ssl->session_negotiate->encrypt_then_mac, in ssl_write_encrypt_then_mac_ext()
1758 ssl->session_negotiate->encrypt_then_mac = MBEDTLS_SSL_ETM_DISABLED; in ssl_write_encrypt_then_mac_ext()
1762 if (ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED) { in ssl_write_encrypt_then_mac_ext()
1780 static void ssl_write_extended_ms_ext(mbedtls_ssl_context *ssl, in ssl_write_extended_ms_ext() argument
1786 if (ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED) { in ssl_write_extended_ms_ext()
1805 static void ssl_write_session_ticket_ext(mbedtls_ssl_context *ssl, in ssl_write_session_ticket_ext() argument
1811 if (ssl->handshake->new_session_ticket == 0) { in ssl_write_session_ticket_ext()
1828 static void ssl_write_renegotiation_ext(mbedtls_ssl_context *ssl, in ssl_write_renegotiation_ext() argument
1834 if (ssl->secure_renegotiation != MBEDTLS_SSL_SECURE_RENEGOTIATION) { in ssl_write_renegotiation_ext()
1845 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_write_renegotiation_ext()
1847 *p++ = (ssl->verify_data_len * 2 + 1) & 0xFF; in ssl_write_renegotiation_ext()
1848 *p++ = ssl->verify_data_len * 2 & 0xFF; in ssl_write_renegotiation_ext()
1850 memcpy(p, ssl->peer_verify_data, ssl->verify_data_len); in ssl_write_renegotiation_ext()
1851 p += ssl->verify_data_len; in ssl_write_renegotiation_ext()
1852 memcpy(p, ssl->own_verify_data, ssl->verify_data_len); in ssl_write_renegotiation_ext()
1853 p += ssl->verify_data_len; in ssl_write_renegotiation_ext()
1866 static void ssl_write_max_fragment_length_ext(mbedtls_ssl_context *ssl, in ssl_write_max_fragment_length_ext() argument
1872 if (ssl->session_negotiate->mfl_code == MBEDTLS_SSL_MAX_FRAG_LEN_NONE) { in ssl_write_max_fragment_length_ext()
1885 *p++ = ssl->session_negotiate->mfl_code; in ssl_write_max_fragment_length_ext()
1894 static void ssl_write_supported_point_formats_ext(mbedtls_ssl_context *ssl, in ssl_write_supported_point_formats_ext() argument
1899 ((void) ssl); in ssl_write_supported_point_formats_ext()
1901 if ((ssl->handshake->cli_exts & in ssl_write_supported_point_formats_ext()
1925 static void ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context *ssl, in ssl_write_ecjpake_kkpp_ext() argument
1931 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_ecjpake_kkpp_ext()
1937 if (ssl->handshake->ciphersuite_info->key_exchange != in ssl_write_ecjpake_kkpp_ext()
1953 ret = mbedtls_psa_ecjpake_write_round(&ssl->handshake->psa_pake_ctx, in ssl_write_ecjpake_kkpp_ext()
1957 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_write_ecjpake_kkpp_ext()
1958 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_write_ecjpake_kkpp_ext()
1963 ret = mbedtls_ecjpake_write_round_one(&ssl->handshake->ecjpake_ctx, in ssl_write_ecjpake_kkpp_ext()
1965 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_write_ecjpake_kkpp_ext()
1980 static void ssl_write_use_srtp_ext(mbedtls_ssl_context *ssl, in ssl_write_use_srtp_ext() argument
1986 const unsigned char *end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_use_srtp_ext()
1990 if ((ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) || in ssl_write_use_srtp_ext()
1991 (ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET)) { in ssl_write_use_srtp_ext()
1997 if (ssl->conf->dtls_srtp_mki_support == MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED) { in ssl_write_use_srtp_ext()
1998 mki_len = ssl->dtls_srtp_info.mki_len; in ssl_write_use_srtp_ext()
2027 ssl->dtls_srtp_info.chosen_dtls_srtp_profile); in ssl_write_use_srtp_ext()
2036 memcpy(&buf[9], ssl->dtls_srtp_info.mki_value, mki_len); in ssl_write_use_srtp_ext()
2044 static int ssl_write_hello_verify_request(mbedtls_ssl_context *ssl) in ssl_write_hello_verify_request() argument
2047 unsigned char *p = ssl->out_msg + 4; in ssl_write_hello_verify_request()
2061 mbedtls_ssl_write_version(p, ssl->conf->transport, ssl->tls_version); in ssl_write_hello_verify_request()
2066 if (ssl->conf->f_cookie_write == NULL) { in ssl_write_hello_verify_request()
2074 if ((ret = ssl->conf->f_cookie_write(ssl->conf->p_cookie, in ssl_write_hello_verify_request()
2075 &p, ssl->out_buf + MBEDTLS_SSL_OUT_BUFFER_LEN, in ssl_write_hello_verify_request()
2076 ssl->cli_id, ssl->cli_id_len)) != 0) { in ssl_write_hello_verify_request()
2085 ssl->out_msglen = (size_t) (p - ssl->out_msg); in ssl_write_hello_verify_request()
2086 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_hello_verify_request()
2087 ssl->out_msg[0] = MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST; in ssl_write_hello_verify_request()
2089 ssl->state = MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT; in ssl_write_hello_verify_request()
2091 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_hello_verify_request()
2097 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_hello_verify_request()
2098 (ret = mbedtls_ssl_flight_transmit(ssl)) != 0) { in ssl_write_hello_verify_request()
2110 static void ssl_handle_id_based_session_resumption(mbedtls_ssl_context *ssl) in ssl_handle_id_based_session_resumption() argument
2114 mbedtls_ssl_session * const session = ssl->session_negotiate; in ssl_handle_id_based_session_resumption()
2118 if (ssl->handshake->resume == 1) { in ssl_handle_id_based_session_resumption()
2124 if (ssl->conf->f_get_cache == NULL) { in ssl_handle_id_based_session_resumption()
2128 if (ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE) { in ssl_handle_id_based_session_resumption()
2135 ret = ssl->conf->f_get_cache(ssl->conf->p_cache, in ssl_handle_id_based_session_resumption()
2154 ssl->handshake->resume = 1; in ssl_handle_id_based_session_resumption()
2162 static int ssl_write_server_hello(mbedtls_ssl_context *ssl) in ssl_write_server_hello() argument
2174 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_server_hello()
2175 ssl->handshake->cookie_verify_result != 0) { in ssl_write_server_hello()
2179 return ssl_write_hello_verify_request(ssl); in ssl_write_server_hello()
2190 buf = ssl->out_msg; in ssl_write_server_hello()
2193 mbedtls_ssl_write_version(p, ssl->conf->transport, ssl->tls_version); in ssl_write_server_hello()
2207 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 4)) != 0) { in ssl_write_server_hello()
2214 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 20)) != 0) { in ssl_write_server_hello()
2227 if (mbedtls_ssl_conf_is_tls13_enabled(ssl->conf)) { in ssl_write_server_hello()
2240 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, p, 8)) != 0) { in ssl_write_server_hello()
2246 memcpy(ssl->handshake->randbytes + 32, buf + 6, 32); in ssl_write_server_hello()
2250 ssl_handle_id_based_session_resumption(ssl); in ssl_write_server_hello()
2252 if (ssl->handshake->resume == 0) { in ssl_write_server_hello()
2257 ssl->state++; in ssl_write_server_hello()
2260 ssl->session_negotiate->start = mbedtls_time(NULL); in ssl_write_server_hello()
2264 if (ssl->handshake->new_session_ticket != 0) { in ssl_write_server_hello()
2265 ssl->session_negotiate->id_len = n = 0; in ssl_write_server_hello()
2266 memset(ssl->session_negotiate->id, 0, 32); in ssl_write_server_hello()
2270 ssl->session_negotiate->id_len = n = 32; in ssl_write_server_hello()
2271 if ((ret = ssl->conf->f_rng(ssl->conf->p_rng, ssl->session_negotiate->id, in ssl_write_server_hello()
2280 n = ssl->session_negotiate->id_len; in ssl_write_server_hello()
2281 ssl->state = MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC; in ssl_write_server_hello()
2283 if ((ret = mbedtls_ssl_derive_keys(ssl)) != 0) { in ssl_write_server_hello()
2297 *p++ = (unsigned char) ssl->session_negotiate->id_len; in ssl_write_server_hello()
2298 memcpy(p, ssl->session_negotiate->id, ssl->session_negotiate->id_len); in ssl_write_server_hello()
2299 p += ssl->session_negotiate->id_len; in ssl_write_server_hello()
2304 ssl->handshake->resume ? "a" : "no")); in ssl_write_server_hello()
2306 MBEDTLS_PUT_UINT16_BE(ssl->session_negotiate->ciphersuite, p, 0); in ssl_write_server_hello()
2311 … mbedtls_ssl_get_ciphersuite_name(ssl->session_negotiate->ciphersuite))); in ssl_write_server_hello()
2318 ssl_write_renegotiation_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2322 ssl_write_max_fragment_length_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2327 ssl_write_cid_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2332 ssl_write_encrypt_then_mac_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2337 ssl_write_extended_ms_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2342 ssl_write_session_ticket_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2350 mbedtls_ssl_ciphersuite_from_id(ssl->session_negotiate->ciphersuite); in ssl_write_server_hello()
2352 ssl_write_supported_point_formats_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2358 ssl_write_ecjpake_kkpp_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2364 if ((ret = mbedtls_ssl_write_alpn_ext(ssl, p + 2 + ext_len, end, &olen)) in ssl_write_server_hello()
2373 ssl_write_use_srtp_ext(ssl, p + 2 + ext_len, &olen); in ssl_write_server_hello()
2385 ssl->out_msglen = (size_t) (p - buf); in ssl_write_server_hello()
2386 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_hello()
2387 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO; in ssl_write_server_hello()
2389 ret = mbedtls_ssl_write_handshake_msg(ssl); in ssl_write_server_hello()
2398 static int ssl_write_certificate_request(mbedtls_ssl_context *ssl) in ssl_write_certificate_request() argument
2401 ssl->handshake->ciphersuite_info; in ssl_write_certificate_request()
2407 ssl->state++; in ssl_write_certificate_request()
2416 static int ssl_write_certificate_request(mbedtls_ssl_context *ssl) in ssl_write_certificate_request() argument
2420 ssl->handshake->ciphersuite_info; in ssl_write_certificate_request()
2424 const unsigned char * const end = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN; in ssl_write_certificate_request()
2430 ssl->state++; in ssl_write_certificate_request()
2433 if (ssl->handshake->sni_authmode != MBEDTLS_SSL_VERIFY_UNSET) { in ssl_write_certificate_request()
2434 authmode = ssl->handshake->sni_authmode; in ssl_write_certificate_request()
2437 authmode = ssl->conf->authmode; in ssl_write_certificate_request()
2457 buf = ssl->out_msg; in ssl_write_certificate_request()
2493 const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl); in ssl_write_certificate_request()
2501 if (mbedtls_ssl_set_calc_verify_md(ssl, hash)) { in ssl_write_certificate_request()
2504 if (!mbedtls_ssl_sig_alg_is_supported(ssl, *sig_alg)) { in ssl_write_certificate_request()
2529 if (ssl->conf->cert_req_ca_list == MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED) { in ssl_write_certificate_request()
2537 if (ssl->handshake->dn_hints != NULL) { in ssl_write_certificate_request()
2538 crt = ssl->handshake->dn_hints; in ssl_write_certificate_request()
2541 if (ssl->conf->dn_hints != NULL) { in ssl_write_certificate_request()
2542 crt = ssl->conf->dn_hints; in ssl_write_certificate_request()
2546 if (ssl->handshake->sni_ca_chain != NULL) { in ssl_write_certificate_request()
2547 crt = ssl->handshake->sni_ca_chain; in ssl_write_certificate_request()
2550 crt = ssl->conf->ca_chain; in ssl_write_certificate_request()
2574 ssl->out_msglen = (size_t) (p - buf); in ssl_write_certificate_request()
2575 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_certificate_request()
2576 ssl->out_msg[0] = MBEDTLS_SSL_HS_CERTIFICATE_REQUEST; in ssl_write_certificate_request()
2577 MBEDTLS_PUT_UINT16_BE(total_dn_size, ssl->out_msg, 4 + ct_len + sa_len); in ssl_write_certificate_request()
2579 ret = mbedtls_ssl_write_handshake_msg(ssl); in ssl_write_certificate_request()
2591 static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl) in ssl_get_ecdh_params_from_cert() argument
2607 pk = mbedtls_ssl_own_key(ssl); in ssl_get_ecdh_params_from_cert()
2633 ssl->handshake->xxdh_psa_type = psa_get_key_type(&key_attributes); in ssl_get_ecdh_params_from_cert()
2634 ssl->handshake->xxdh_psa_bits = psa_get_key_bits(&key_attributes); in ssl_get_ecdh_params_from_cert()
2647 PSA_KEY_TYPE_ECC_KEY_PAIR(ssl->handshake->xxdh_psa_type)); in ssl_get_ecdh_params_from_cert()
2648 psa_set_key_bits(&key_attributes, ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2656 &ssl->handshake->xxdh_psa_privkey); in ssl_get_ecdh_params_from_cert()
2664 ssl->handshake->xxdh_psa_privkey_is_external = 0; in ssl_get_ecdh_params_from_cert()
2674 ssl->handshake->xxdh_psa_privkey = pk->priv_id; in ssl_get_ecdh_params_from_cert()
2675 ssl->handshake->xxdh_psa_privkey_is_external = 1; in ssl_get_ecdh_params_from_cert()
2697 &ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2699 ssl->handshake->xxdh_psa_type = key_type; in ssl_get_ecdh_params_from_cert()
2705 PSA_KEY_TYPE_ECC_KEY_PAIR(ssl->handshake->xxdh_psa_type)); in ssl_get_ecdh_params_from_cert()
2706 psa_set_key_bits(&key_attributes, ssl->handshake->xxdh_psa_bits); in ssl_get_ecdh_params_from_cert()
2715 &ssl->handshake->xxdh_psa_privkey); in ssl_get_ecdh_params_from_cert()
2738 static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context *ssl) in ssl_get_ecdh_params_from_cert() argument
2742 const mbedtls_pk_context *private_key = mbedtls_ssl_own_key(ssl); in ssl_get_ecdh_params_from_cert()
2753 if ((ret = mbedtls_ecdh_get_params(&ssl->handshake->ecdh_ctx, in ssl_get_ecdh_params_from_cert()
2754 mbedtls_pk_ec_ro(*mbedtls_ssl_own_key(ssl)), in ssl_get_ecdh_params_from_cert()
2769 static int ssl_resume_server_key_exchange(mbedtls_ssl_context *ssl, in ssl_resume_server_key_exchange() argument
2777 unsigned char *sig_start = ssl->out_msg + ssl->out_msglen + 2; in ssl_resume_server_key_exchange()
2778 size_t sig_max_len = (ssl->out_buf + MBEDTLS_SSL_OUT_CONTENT_LEN in ssl_resume_server_key_exchange()
2780 int ret = ssl->conf->f_async_resume(ssl, in ssl_resume_server_key_exchange()
2783 ssl->handshake->async_in_progress = 0; in ssl_resume_server_key_exchange()
2784 mbedtls_ssl_set_async_operation_data(ssl, NULL); in ssl_resume_server_key_exchange()
2796 static int ssl_prepare_server_key_exchange(mbedtls_ssl_context *ssl, in ssl_prepare_server_key_exchange() argument
2800 ssl->handshake->ciphersuite_info; in ssl_prepare_server_key_exchange()
2815 size_t out_buf_len = ssl->out_buf_len - (size_t) (ssl->out_msg - ssl->out_buf); in ssl_prepare_server_key_exchange()
2817 size_t out_buf_len = MBEDTLS_SSL_OUT_BUFFER_LEN - (size_t) (ssl->out_msg - ssl->out_buf); in ssl_prepare_server_key_exchange()
2821 ssl->out_msglen = 4; /* header (type:1, length:3) to be written later */ in ssl_prepare_server_key_exchange()
2836 unsigned char *out_p = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
2837 unsigned char *end_p = ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN - in ssl_prepare_server_key_exchange()
2838 ssl->out_msglen; in ssl_prepare_server_key_exchange()
2859 ret = mbedtls_psa_ecjpake_write_round(&ssl->handshake->psa_pake_ctx, in ssl_prepare_server_key_exchange()
2864 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_prepare_server_key_exchange()
2865 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_prepare_server_key_exchange()
2871 ssl->out_msglen += output_offset; in ssl_prepare_server_key_exchange()
2876 &ssl->handshake->ecjpake_ctx, in ssl_prepare_server_key_exchange()
2877 ssl->out_msg + ssl->out_msglen, in ssl_prepare_server_key_exchange()
2878 MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, &len, in ssl_prepare_server_key_exchange()
2879 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_prepare_server_key_exchange()
2885 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
2899 ssl->out_msg[ssl->out_msglen++] = 0x00; in ssl_prepare_server_key_exchange()
2900 ssl->out_msg[ssl->out_msglen++] = 0x00; in ssl_prepare_server_key_exchange()
2913 if (ssl->conf->dhm_P.p == NULL || ssl->conf->dhm_G.p == NULL) { in ssl_prepare_server_key_exchange()
2927 if ((ret = mbedtls_dhm_set_group(&ssl->handshake->dhm_ctx, in ssl_prepare_server_key_exchange()
2928 &ssl->conf->dhm_P, in ssl_prepare_server_key_exchange()
2929 &ssl->conf->dhm_G)) != 0) { in ssl_prepare_server_key_exchange()
2935 &ssl->handshake->dhm_ctx, in ssl_prepare_server_key_exchange()
2936 (int) mbedtls_dhm_get_len(&ssl->handshake->dhm_ctx), in ssl_prepare_server_key_exchange()
2937 ssl->out_msg + ssl->out_msglen, &len, in ssl_prepare_server_key_exchange()
2938 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
2944 dig_signed = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
2947 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
2949 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: X ", &ssl->handshake->dhm_ctx.X); in ssl_prepare_server_key_exchange()
2950 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: P ", &ssl->handshake->dhm_ctx.P); in ssl_prepare_server_key_exchange()
2951 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: G ", &ssl->handshake->dhm_ctx.G); in ssl_prepare_server_key_exchange()
2952 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: GX", &ssl->handshake->dhm_ctx.GX); in ssl_prepare_server_key_exchange()
2969 uint16_t *curr_tls_id = ssl->handshake->curves_tls_id; in ssl_prepare_server_key_exchange()
2970 const uint16_t *group_list = mbedtls_ssl_get_groups(ssl); in ssl_prepare_server_key_exchange()
2979 for (curr_tls_id = ssl->handshake->curves_tls_id; in ssl_prepare_server_key_exchange()
2999 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_prepare_server_key_exchange()
3000 uint8_t *p = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
3060 - (own_pubkey - ssl->out_msg)); in ssl_prepare_server_key_exchange()
3082 if ((ret = mbedtls_ecdh_setup(&ssl->handshake->ecdh_ctx, in ssl_prepare_server_key_exchange()
3089 &ssl->handshake->ecdh_ctx, &len, in ssl_prepare_server_key_exchange()
3090 ssl->out_msg + ssl->out_msglen, in ssl_prepare_server_key_exchange()
3091 MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, in ssl_prepare_server_key_exchange()
3092 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
3097 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_prepare_server_key_exchange()
3102 dig_signed = ssl->out_msg + ssl->out_msglen; in ssl_prepare_server_key_exchange()
3105 ssl->out_msglen += len; in ssl_prepare_server_key_exchange()
3122 size_t dig_signed_len = (size_t) (ssl->out_msg + ssl->out_msglen - dig_signed); in ssl_prepare_server_key_exchange()
3139 ssl, mbedtls_ssl_sig_from_pk_alg(sig_alg)); in ssl_prepare_server_key_exchange()
3158 ret = mbedtls_ssl_get_key_exchange_md_tls1_2(ssl, hash, &hashlen, in ssl_prepare_server_key_exchange()
3191 ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_hash_from_md_alg(md_alg); in ssl_prepare_server_key_exchange()
3192 ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_sig_from_pk_alg(sig_alg); in ssl_prepare_server_key_exchange()
3195 if (ssl->conf->f_async_sign_start != NULL) { in ssl_prepare_server_key_exchange()
3196 ret = ssl->conf->f_async_sign_start(ssl, in ssl_prepare_server_key_exchange()
3197 mbedtls_ssl_own_cert(ssl), in ssl_prepare_server_key_exchange()
3204 ssl->handshake->async_in_progress = 1; in ssl_prepare_server_key_exchange()
3205 return ssl_resume_server_key_exchange(ssl, signature_len); in ssl_prepare_server_key_exchange()
3207 ssl->handshake->async_in_progress = 1; in ssl_prepare_server_key_exchange()
3216 if (mbedtls_ssl_own_key(ssl) == NULL) { in ssl_prepare_server_key_exchange()
3226 if ((ret = mbedtls_pk_sign(mbedtls_ssl_own_key(ssl), in ssl_prepare_server_key_exchange()
3228 ssl->out_msg + ssl->out_msglen + 2, in ssl_prepare_server_key_exchange()
3229 out_buf_len - ssl->out_msglen - 2, in ssl_prepare_server_key_exchange()
3231 ssl->conf->f_rng, in ssl_prepare_server_key_exchange()
3232 ssl->conf->p_rng)) != 0) { in ssl_prepare_server_key_exchange()
3247 static int ssl_write_server_key_exchange(mbedtls_ssl_context *ssl) in ssl_write_server_key_exchange() argument
3253 ssl->handshake->ciphersuite_info; in ssl_write_server_key_exchange()
3266 ret = ssl_get_ecdh_params_from_cert(ssl); in ssl_write_server_key_exchange()
3277 ssl->state++; in ssl_write_server_key_exchange()
3286 if (ssl->handshake->async_in_progress != 0) { in ssl_write_server_key_exchange()
3288 ret = ssl_resume_server_key_exchange(ssl, &signature_len); in ssl_write_server_key_exchange()
3294 ret = ssl_prepare_server_key_exchange(ssl, &signature_len); in ssl_write_server_key_exchange()
3305 ssl->out_msglen = 0; in ssl_write_server_key_exchange()
3315 ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_1(signature_len); in ssl_write_server_key_exchange()
3316 ssl->out_msg[ssl->out_msglen++] = MBEDTLS_BYTE_0(signature_len); in ssl_write_server_key_exchange()
3319 ssl->out_msg + ssl->out_msglen, in ssl_write_server_key_exchange()
3323 ssl->out_msglen += signature_len; in ssl_write_server_key_exchange()
3328 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_key_exchange()
3329 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE; in ssl_write_server_key_exchange()
3331 ssl->state++; in ssl_write_server_key_exchange()
3333 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_server_key_exchange()
3343 static int ssl_write_server_hello_done(mbedtls_ssl_context *ssl) in ssl_write_server_hello_done() argument
3349 ssl->out_msglen = 4; in ssl_write_server_hello_done()
3350 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_server_hello_done()
3351 ssl->out_msg[0] = MBEDTLS_SSL_HS_SERVER_HELLO_DONE; in ssl_write_server_hello_done()
3353 ssl->state++; in ssl_write_server_hello_done()
3356 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { in ssl_write_server_hello_done()
3357 mbedtls_ssl_send_flight_completed(ssl); in ssl_write_server_hello_done()
3361 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_server_hello_done()
3367 if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && in ssl_write_server_hello_done()
3368 (ret = mbedtls_ssl_flight_transmit(ssl)) != 0) { in ssl_write_server_hello_done()
3382 static int ssl_parse_client_dh_public(mbedtls_ssl_context *ssl, unsigned char **p, in ssl_parse_client_dh_public() argument
3404 if ((ret = mbedtls_dhm_read_public(&ssl->handshake->dhm_ctx, *p, n)) != 0) { in ssl_parse_client_dh_public()
3411 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: GY", &ssl->handshake->dhm_ctx.GY); in ssl_parse_client_dh_public()
3423 static int ssl_resume_decrypt_pms(mbedtls_ssl_context *ssl, in ssl_resume_decrypt_pms() argument
3428 int ret = ssl->conf->f_async_resume(ssl, in ssl_resume_decrypt_pms()
3431 ssl->handshake->async_in_progress = 0; in ssl_resume_decrypt_pms()
3432 mbedtls_ssl_set_async_operation_data(ssl, NULL); in ssl_resume_decrypt_pms()
3440 static int ssl_decrypt_encrypted_pms(mbedtls_ssl_context *ssl, in ssl_decrypt_encrypted_pms() argument
3449 mbedtls_x509_crt *own_cert = mbedtls_ssl_own_cert(ssl); in ssl_decrypt_encrypted_pms()
3455 mbedtls_pk_context *private_key = mbedtls_ssl_own_key(ssl); in ssl_decrypt_encrypted_pms()
3461 if (ssl->handshake->async_in_progress != 0) { in ssl_decrypt_encrypted_pms()
3463 return ssl_resume_decrypt_pms(ssl, in ssl_decrypt_encrypted_pms()
3490 if (ssl->conf->f_async_decrypt_start != NULL) { in ssl_decrypt_encrypted_pms()
3491 ret = ssl->conf->f_async_decrypt_start(ssl, in ssl_decrypt_encrypted_pms()
3492 mbedtls_ssl_own_cert(ssl), in ssl_decrypt_encrypted_pms()
3499 ssl->handshake->async_in_progress = 1; in ssl_decrypt_encrypted_pms()
3500 return ssl_resume_decrypt_pms(ssl, in ssl_decrypt_encrypted_pms()
3505 ssl->handshake->async_in_progress = 1; in ssl_decrypt_encrypted_pms()
3521 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_decrypt_encrypted_pms()
3526 static int ssl_parse_encrypted_pms(mbedtls_ssl_context *ssl, in ssl_parse_encrypted_pms() argument
3532 unsigned char *pms = ssl->handshake->premaster + pms_offset; in ssl_parse_encrypted_pms()
3548 ret = ssl_decrypt_encrypted_pms(ssl, p, end, in ssl_parse_encrypted_pms()
3559 mbedtls_ssl_write_version(ver, ssl->conf->transport, in ssl_parse_encrypted_pms()
3560 ssl->session_negotiate->tls_version); in ssl_parse_encrypted_pms()
3579 ret = ssl->conf->f_rng(ssl->conf->p_rng, fake_pms, sizeof(fake_pms)); in ssl_parse_encrypted_pms()
3592 if (sizeof(ssl->handshake->premaster) < pms_offset || in ssl_parse_encrypted_pms()
3593 sizeof(ssl->handshake->premaster) - pms_offset < 48) { in ssl_parse_encrypted_pms()
3597 ssl->handshake->pmslen = 48; in ssl_parse_encrypted_pms()
3601 mbedtls_ct_memcpy_if(diff, pms, fake_pms, peer_pms, ssl->handshake->pmslen); in ssl_parse_encrypted_pms()
3610 static int ssl_parse_client_psk_identity(mbedtls_ssl_context *ssl, unsigned char **p, in ssl_parse_client_psk_identity() argument
3616 if (ssl_conf_has_psk_or_cb(ssl->conf) == 0) { in ssl_parse_client_psk_identity()
3637 if (ssl->conf->f_psk != NULL) { in ssl_parse_client_psk_identity()
3638 if (ssl->conf->f_psk(ssl->conf->p_psk, ssl, *p, n) != 0) { in ssl_parse_client_psk_identity()
3644 if (n != ssl->conf->psk_identity_len || in ssl_parse_client_psk_identity()
3645 mbedtls_ct_memcmp(ssl->conf->psk_identity, *p, n) != 0) { in ssl_parse_client_psk_identity()
3652 mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, in ssl_parse_client_psk_identity()
3664 static int ssl_parse_client_key_exchange(mbedtls_ssl_context *ssl) in ssl_parse_client_key_exchange() argument
3670 ciphersuite_info = ssl->handshake->ciphersuite_info; in ssl_parse_client_key_exchange()
3679 (ssl->handshake->async_in_progress != 0)) { in ssl_parse_client_key_exchange()
3686 if ((ret = mbedtls_ssl_read_record(ssl, 1)) != 0) { in ssl_parse_client_key_exchange()
3691 p = ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_client_key_exchange()
3692 end = ssl->in_msg + ssl->in_hslen; in ssl_parse_client_key_exchange()
3694 if (ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE) { in ssl_parse_client_key_exchange()
3699 if (ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE) { in ssl_parse_client_key_exchange()
3706 if ((ret = ssl_parse_client_dh_public(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3716 if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx, in ssl_parse_client_key_exchange()
3717 ssl->handshake->premaster, in ssl_parse_client_key_exchange()
3719 &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
3720 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3725 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: K ", &ssl->handshake->dhm_ctx.K); in ssl_parse_client_key_exchange()
3740 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_parse_client_key_exchange()
3798 if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3804 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3807 if ((ret = mbedtls_ecdh_calc_secret(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3808 &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
3809 ssl->handshake->premaster, in ssl_parse_client_key_exchange()
3811 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3816 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
3826 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3837 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3849 if (ssl->handshake->async_in_progress != 0) { in ssl_parse_client_key_exchange()
3856 p += ssl->conf->psk_identity_len + 2; in ssl_parse_client_key_exchange()
3859 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3864 if ((ret = ssl_parse_encrypted_pms(ssl, p, end, 2)) != 0) { in ssl_parse_client_key_exchange()
3870 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3881 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3885 if ((ret = ssl_parse_client_dh_public(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3896 unsigned char *pms = ssl->handshake->premaster; in ssl_parse_client_key_exchange()
3897 unsigned char *pms_end = pms + sizeof(ssl->handshake->premaster); in ssl_parse_client_key_exchange()
3901 if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx, in ssl_parse_client_key_exchange()
3903 ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { in ssl_parse_client_key_exchange()
3910 MBEDTLS_SSL_DEBUG_MPI(3, "DHM: K ", &ssl->handshake->dhm_ctx.K); in ssl_parse_client_key_exchange()
3912 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
3928 mbedtls_ssl_handshake_params *handshake = ssl->handshake; in ssl_parse_client_key_exchange()
3930 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
3976 unsigned char *psm = ssl->handshake->premaster; in ssl_parse_client_key_exchange()
3978 psm + sizeof(ssl->handshake->premaster); in ssl_parse_client_key_exchange()
4006 if ((ret = ssl_parse_client_psk_identity(ssl, &p, end)) != 0) { in ssl_parse_client_key_exchange()
4011 if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
4017 MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, in ssl_parse_client_key_exchange()
4020 if ((ret = mbedtls_ssl_psk_derive_premaster(ssl, in ssl_parse_client_key_exchange()
4031 if ((ret = ssl_parse_encrypted_pms(ssl, p, end, 0)) != 0) { in ssl_parse_client_key_exchange()
4041 &ssl->handshake->psa_pake_ctx, p, (size_t) (end - p), in ssl_parse_client_key_exchange()
4043 psa_destroy_key(ssl->handshake->psa_pake_password); in ssl_parse_client_key_exchange()
4044 psa_pake_abort(&ssl->handshake->psa_pake_ctx); in ssl_parse_client_key_exchange()
4050 ret = mbedtls_ecjpake_read_round_two(&ssl->handshake->ecjpake_ctx, in ssl_parse_client_key_exchange()
4057 ret = mbedtls_ecjpake_derive_secret(&ssl->handshake->ecjpake_ctx, in ssl_parse_client_key_exchange()
4058 ssl->handshake->premaster, 32, &ssl->handshake->pmslen, in ssl_parse_client_key_exchange()
4059 ssl->conf->f_rng, ssl->conf->p_rng); in ssl_parse_client_key_exchange()
4072 if ((ret = mbedtls_ssl_derive_keys(ssl)) != 0) { in ssl_parse_client_key_exchange()
4077 ssl->state++; in ssl_parse_client_key_exchange()
4086 static int ssl_parse_certificate_verify(mbedtls_ssl_context *ssl) in ssl_parse_certificate_verify() argument
4089 ssl->handshake->ciphersuite_info; in ssl_parse_certificate_verify()
4095 ssl->state++; in ssl_parse_certificate_verify()
4104 static int ssl_parse_certificate_verify(mbedtls_ssl_context *ssl) in ssl_parse_certificate_verify() argument
4114 ssl->handshake->ciphersuite_info; in ssl_parse_certificate_verify()
4121 ssl->state++; in ssl_parse_certificate_verify()
4126 if (ssl->session_negotiate->peer_cert == NULL) { in ssl_parse_certificate_verify()
4128 ssl->state++; in ssl_parse_certificate_verify()
4132 if (ssl->session_negotiate->peer_cert_digest == NULL) { in ssl_parse_certificate_verify()
4134 ssl->state++; in ssl_parse_certificate_verify()
4140 ret = mbedtls_ssl_read_record(ssl, 0 /* no checksum update */); in ssl_parse_certificate_verify()
4146 ssl->state++; in ssl_parse_certificate_verify()
4149 if (ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE || in ssl_parse_certificate_verify()
4150 ssl->in_msg[0] != MBEDTLS_SSL_HS_CERTIFICATE_VERIFY) { in ssl_parse_certificate_verify()
4155 i = mbedtls_ssl_hs_hdr_len(ssl); in ssl_parse_certificate_verify()
4158 peer_pk = &ssl->handshake->peer_pubkey; in ssl_parse_certificate_verify()
4160 if (ssl->session_negotiate->peer_cert == NULL) { in ssl_parse_certificate_verify()
4164 peer_pk = &ssl->session_negotiate->peer_cert->pk; in ssl_parse_certificate_verify()
4173 if (i + 2 > ssl->in_hslen) { in ssl_parse_certificate_verify()
4181 md_alg = mbedtls_ssl_md_alg_from_hash(ssl->in_msg[i]); in ssl_parse_certificate_verify()
4183 if (md_alg == MBEDTLS_MD_NONE || mbedtls_ssl_set_calc_verify_md(ssl, ssl->in_msg[i])) { in ssl_parse_certificate_verify()
4203 if ((pk_alg = mbedtls_ssl_pk_alg_from_sig(ssl->in_msg[i])) in ssl_parse_certificate_verify()
4220 if (i + 2 > ssl->in_hslen) { in ssl_parse_certificate_verify()
4225 sig_len = MBEDTLS_GET_UINT16_BE(ssl->in_msg, i); in ssl_parse_certificate_verify()
4228 if (i + sig_len != ssl->in_hslen) { in ssl_parse_certificate_verify()
4236 ret = ssl->handshake->calc_verify(ssl, hash, &dummy_hlen); in ssl_parse_certificate_verify()
4245 ssl->in_msg + i, sig_len)) != 0) { in ssl_parse_certificate_verify()
4250 ret = mbedtls_ssl_update_handshake_status(ssl); in ssl_parse_certificate_verify()
4264 static int ssl_write_new_session_ticket(mbedtls_ssl_context *ssl) in ssl_write_new_session_ticket() argument
4272 ssl->out_msgtype = MBEDTLS_SSL_MSG_HANDSHAKE; in ssl_write_new_session_ticket()
4273 ssl->out_msg[0] = MBEDTLS_SSL_HS_NEW_SESSION_TICKET; in ssl_write_new_session_ticket()
4287 ssl->session_negotiate->ticket_creation_time = mbedtls_ms_time(); in ssl_write_new_session_ticket()
4289 if ((ret = ssl->conf->f_ticket_write(ssl->conf->p_ticket, in ssl_write_new_session_ticket()
4290 ssl->session_negotiate, in ssl_write_new_session_ticket()
4291 ssl->out_msg + 10, in ssl_write_new_session_ticket()
4292 ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN, in ssl_write_new_session_ticket()
4298 MBEDTLS_PUT_UINT32_BE(lifetime, ssl->out_msg, 4); in ssl_write_new_session_ticket()
4299 MBEDTLS_PUT_UINT16_BE(tlen, ssl->out_msg, 8); in ssl_write_new_session_ticket()
4300 ssl->out_msglen = 10 + tlen; in ssl_write_new_session_ticket()
4306 ssl->handshake->new_session_ticket = 0; in ssl_write_new_session_ticket()
4308 if ((ret = mbedtls_ssl_write_handshake_msg(ssl)) != 0) { in ssl_write_new_session_ticket()
4322 int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context *ssl) in mbedtls_ssl_handshake_server_step() argument
4326 MBEDTLS_SSL_DEBUG_MSG(2, ("server state: %d", ssl->state)); in mbedtls_ssl_handshake_server_step()
4328 switch (ssl->state) { in mbedtls_ssl_handshake_server_step()
4330 ssl->state = MBEDTLS_SSL_CLIENT_HELLO; in mbedtls_ssl_handshake_server_step()
4337 ret = ssl_parse_client_hello(ssl); in mbedtls_ssl_handshake_server_step()
4353 ret = ssl_write_server_hello(ssl); in mbedtls_ssl_handshake_server_step()
4357 ret = mbedtls_ssl_write_certificate(ssl); in mbedtls_ssl_handshake_server_step()
4361 ret = ssl_write_server_key_exchange(ssl); in mbedtls_ssl_handshake_server_step()
4365 ret = ssl_write_certificate_request(ssl); in mbedtls_ssl_handshake_server_step()
4369 ret = ssl_write_server_hello_done(ssl); in mbedtls_ssl_handshake_server_step()
4380 ret = mbedtls_ssl_parse_certificate(ssl); in mbedtls_ssl_handshake_server_step()
4384 ret = ssl_parse_client_key_exchange(ssl); in mbedtls_ssl_handshake_server_step()
4388 ret = ssl_parse_certificate_verify(ssl); in mbedtls_ssl_handshake_server_step()
4392 ret = mbedtls_ssl_parse_change_cipher_spec(ssl); in mbedtls_ssl_handshake_server_step()
4396 ret = mbedtls_ssl_parse_finished(ssl); in mbedtls_ssl_handshake_server_step()
4406 if (ssl->handshake->new_session_ticket != 0) { in mbedtls_ssl_handshake_server_step()
4407 ret = ssl_write_new_session_ticket(ssl); in mbedtls_ssl_handshake_server_step()
4410 ret = mbedtls_ssl_write_change_cipher_spec(ssl); in mbedtls_ssl_handshake_server_step()
4414 ret = mbedtls_ssl_write_finished(ssl); in mbedtls_ssl_handshake_server_step()
4419 ssl->state = MBEDTLS_SSL_HANDSHAKE_WRAPUP; in mbedtls_ssl_handshake_server_step()
4423 mbedtls_ssl_handshake_wrapup(ssl); in mbedtls_ssl_handshake_server_step()
4427 MBEDTLS_SSL_DEBUG_MSG(1, ("invalid state %d", ssl->state)); in mbedtls_ssl_handshake_server_step()