mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge branch 'development-restricted' into merge-from-restricted
* development-restricted: Add missing credit for set_hostname issue Add changelog entry for TLS 1.2 Finished fix TLS1.2: Check for failures in Finished calculation ssl_session_reset: preserve HOSTNAME_SET flag Document the need to call mbedtls_ssl_set_hostname Improve documentation of mbedtls_ssl_set_hostname Changelog entries for requiring mbedls_ssl_set_hostname() in TLS clients Add a note about calling mbedtls_ssl_set_hostname to mbedtls_ssl_setup mbedtls_ssl_set_hostname tests: add tests with CA callback Call mbedtls_ssl_set_hostname in the generic endpoint setup in unit tests Require calling mbedtls_ssl_set_hostname() for security Create error code for mbedtls_ssl_set_hostname not called Keep track of whether mbedtls_ssl_set_hostname() has been called Access ssl->hostname through abstractions in certificate verification mbedtls_ssl_set_hostname tests: baseline Add a flags field to mbedtls_ssl_context Automate MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK dependency Make guards more consistent between X.509-has-certs and SSL-has-certs Fix Doxygen markup Make ticket_alpn field private Conflicts: programs/ssl/ssl_test_common_source.c
This commit is contained in:
@ -1410,6 +1410,7 @@ int mbedtls_ssl_session_reset_int(mbedtls_ssl_context *ssl, int partial)
|
||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
ssl->state = MBEDTLS_SSL_HELLO_REQUEST;
|
||||
ssl->flags &= MBEDTLS_SSL_CONTEXT_FLAGS_KEEP_AT_SESSION;
|
||||
ssl->tls_version = ssl->conf->max_tls_version;
|
||||
|
||||
mbedtls_ssl_session_reset_msg_layer(ssl, partial);
|
||||
@ -2455,6 +2456,31 @@ void mbedtls_ssl_conf_groups(mbedtls_ssl_config *conf,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
|
||||
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
||||
/** Whether mbedtls_ssl_set_hostname() has been called.
|
||||
*
|
||||
* \param[in] ssl SSL context
|
||||
*
|
||||
* \return \c 1 if mbedtls_ssl_set_hostname() has been called on \p ssl
|
||||
* (including `mbedtls_ssl_set_hostname(ssl, NULL)`),
|
||||
* otherwise \c 0.
|
||||
*/
|
||||
static int mbedtls_ssl_has_set_hostname_been_called(
|
||||
const mbedtls_ssl_context *ssl)
|
||||
{
|
||||
return (ssl->flags & MBEDTLS_SSL_CONTEXT_FLAG_HOSTNAME_SET) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mbedtls_ssl_free_hostname(mbedtls_ssl_context *ssl)
|
||||
{
|
||||
if (ssl->hostname != NULL) {
|
||||
mbedtls_zeroize_and_free(ssl->hostname, strlen(ssl->hostname));
|
||||
}
|
||||
ssl->hostname = NULL;
|
||||
}
|
||||
|
||||
int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
|
||||
{
|
||||
/* Initialize to suppress unnecessary compiler warning */
|
||||
@ -2472,10 +2498,7 @@ int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
|
||||
|
||||
/* Now it's clear that we will overwrite the old hostname,
|
||||
* so we can free it safely */
|
||||
|
||||
if (ssl->hostname != NULL) {
|
||||
mbedtls_zeroize_and_free(ssl->hostname, strlen(ssl->hostname));
|
||||
}
|
||||
mbedtls_ssl_free_hostname(ssl);
|
||||
|
||||
/* Passing NULL as hostname shall clear the old one */
|
||||
|
||||
@ -2492,6 +2515,8 @@ int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
|
||||
ssl->hostname[hostname_len] = '\0';
|
||||
}
|
||||
|
||||
ssl->flags |= MBEDTLS_SSL_CONTEXT_FLAG_HOSTNAME_SET;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
@ -5229,9 +5254,7 @@ void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
if (ssl->hostname != NULL) {
|
||||
mbedtls_zeroize_and_free(ssl->hostname, strlen(ssl->hostname));
|
||||
}
|
||||
mbedtls_ssl_free_hostname(ssl);
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
|
||||
@ -7454,6 +7477,7 @@ int mbedtls_ssl_write_finished(mbedtls_ssl_context *ssl)
|
||||
ret = ssl->handshake->calc_finished(ssl, ssl->out_msg + 4, ssl->conf->endpoint);
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "calc_finished", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -7567,6 +7591,7 @@ int mbedtls_ssl_parse_finished(mbedtls_ssl_context *ssl)
|
||||
ret = ssl->handshake->calc_finished(ssl, buf, ssl->conf->endpoint ^ 1);
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "calc_finished", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_ssl_read_record(ssl, 1)) != 0) {
|
||||
@ -8747,6 +8772,25 @@ int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt *cert,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int get_hostname_for_verification(mbedtls_ssl_context *ssl,
|
||||
const char **hostname)
|
||||
{
|
||||
if (!mbedtls_ssl_has_set_hostname_been_called(ssl)) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(1, ("Certificate verification without having set hostname"));
|
||||
if (mbedtls_ssl_conf_get_endpoint(ssl->conf) == MBEDTLS_SSL_IS_CLIENT &&
|
||||
ssl->conf->authmode == MBEDTLS_SSL_VERIFY_REQUIRED) {
|
||||
return MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME;
|
||||
}
|
||||
}
|
||||
|
||||
*hostname = ssl->hostname;
|
||||
if (*hostname == NULL) {
|
||||
MBEDTLS_SSL_DEBUG_MSG(2, ("Certificate verification without CN verification"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_ssl_verify_certificate(mbedtls_ssl_context *ssl,
|
||||
int authmode,
|
||||
mbedtls_x509_crt *chain,
|
||||
@ -8772,7 +8816,13 @@ int mbedtls_ssl_verify_certificate(mbedtls_ssl_context *ssl,
|
||||
p_vrfy = ssl->conf->p_vrfy;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
const char *hostname = "";
|
||||
int ret = get_hostname_for_verification(ssl, &hostname);
|
||||
if (ret != 0) {
|
||||
MBEDTLS_SSL_DEBUG_RET(1, "get_hostname_for_verification", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int have_ca_chain_or_callback = 0;
|
||||
#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
|
||||
if (ssl->conf->f_ca_cb != NULL) {
|
||||
@ -8785,7 +8835,7 @@ int mbedtls_ssl_verify_certificate(mbedtls_ssl_context *ssl,
|
||||
ssl->conf->f_ca_cb,
|
||||
ssl->conf->p_ca_cb,
|
||||
ssl->conf->cert_profile,
|
||||
ssl->hostname,
|
||||
hostname,
|
||||
&ssl->session_negotiate->verify_result,
|
||||
f_vrfy, p_vrfy);
|
||||
} else
|
||||
@ -8812,7 +8862,7 @@ int mbedtls_ssl_verify_certificate(mbedtls_ssl_context *ssl,
|
||||
chain,
|
||||
ca_chain, ca_crl,
|
||||
ssl->conf->cert_profile,
|
||||
ssl->hostname,
|
||||
hostname,
|
||||
&ssl->session_negotiate->verify_result,
|
||||
f_vrfy, p_vrfy, rs_ctx);
|
||||
}
|
||||
|
Reference in New Issue
Block a user