Summary
I am using custom certificates with CN=hostname and one additional properly tagged SANs (rfc822Name). The new hostname verification configured via mbedlts_ssl_set_hostname fails for such certificates.
System information
Mbed TLS version (number or commit id): 3.6.3
Expected behavior
I am not an expert on x509, but I assume a certificate with properly formatted subject with CN=hostname and SAN without additional DNS name or IP address should validate.
Actual behavior
Validation of server certificate fails when it contains properly defined CN=hostname in subject, and contains additional SANs, none of which are IP, DNS, or URI.
Additional information
The actual validation of cert and hostname happens here:
|
ret = mbedtls_x509_crt_verify_restartable( |
When presence of SANs is detected, the check ignores subject CN entirely, and examines the SANs only.
|
if (crt->ext_types & MBEDTLS_X509_EXT_SUBJECT_ALT_NAME) { |
|
if (x509_crt_check_san(&crt->subject_alt_names, cn, cn_len) == 0) { |
|
return; |
|
} |
|
} else { |
|
for (name = &crt->subject; name != NULL; name = name->next) { |
|
if (MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &name->oid) == 0 && |
|
x509_crt_check_cn(&name->val, cn, cn_len) == 0) { |
|
return; |
|
} |
|
} |
|
|
|
} |
And when SANs are analyzed, only the IP, DNS, and URI tags are examined. Presence of none is indicated as an error and certificate is flagged as untrusted.
|
case MBEDTLS_X509_SAN_DNS_NAME: |
|
if (x509_crt_check_cn(&cur->buf, cn, cn_len) == 0) { |
|
return 0; |
|
} |
|
break; |
|
case MBEDTLS_X509_SAN_IP_ADDRESS: |
|
san_ip = 1; |
|
break; |
|
case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER: |
|
san_uri = 1; |
|
break; |
Suggested fix
Unless I am missing something from the X509 standard, which I may of course, I believe that subject CN should be validated in addition to any additional DNS, IP, or URI SANs... and result presented when any of these pass.
Summary
I am using custom certificates with
CN=hostnameand one additional properly tagged SANs (rfc822Name). The new hostname verification configured viambedlts_ssl_set_hostnamefails for such certificates.System information
Mbed TLS version (number or commit id): 3.6.3
Expected behavior
I am not an expert on x509, but I assume a certificate with properly formatted subject with
CN=hostnameand SAN without additional DNS name or IP address should validate.Actual behavior
Validation of server certificate fails when it contains properly defined
CN=hostnamein subject, and contains additional SANs, none of which are IP, DNS, or URI.Additional information
The actual validation of cert and hostname happens here:
mbedtls/library/ssl_tls.c
Line 8823 in 6bf29fd
When presence of SANs is detected, the check ignores subject
CNentirely, and examines the SANs only.mbedtls/library/x509_crt.c
Lines 2960 to 2972 in 6bf29fd
And when SANs are analyzed, only the IP, DNS, and URI tags are examined. Presence of none is indicated as an error and certificate is flagged as untrusted.
mbedtls/library/x509_crt.c
Lines 2920 to 2930 in 6bf29fd
Suggested fix
Unless I am missing something from the X509 standard, which I may of course, I believe that subject
CNshould be validated in addition to any additional DNS, IP, or URI SANs... and result presented when any of these pass.