mirror of
https://github.com/ARMmbed/mbedtls.git
synced 2025-05-10 00:49:04 +08:00
Merge pull request #7575 from AndrzejKurek/URI-SAN-verification
Add partial support for URI SubjectAltNames verification
This commit is contained in:
commit
5c3d6e277c
4
ChangeLog.d/basic-uri-verification.txt
Normal file
4
ChangeLog.d/basic-uri-verification.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Features
|
||||||
|
* X.509 hostname verification now partially supports URI Subject Alternate
|
||||||
|
Names. Only exact matching, without any normalization procedures
|
||||||
|
described in 7.4 of RFC5280, will result in a positive URI verification.
|
@ -656,8 +656,12 @@ int mbedtls_x509_crt_verify_info(char *buf, size_t size, const char *prefix,
|
|||||||
* \param cn The expected Common Name. This will be checked to be
|
* \param cn The expected Common Name. This will be checked to be
|
||||||
* present in the certificate's subjectAltNames extension or,
|
* present in the certificate's subjectAltNames extension or,
|
||||||
* if this extension is absent, as a CN component in its
|
* if this extension is absent, as a CN component in its
|
||||||
* Subject name. DNS names and IP addresses are supported. This
|
* Subject name. DNS names and IP addresses are fully
|
||||||
* may be \c NULL if the CN need not be verified.
|
* supported, while the URI subtype is partially supported:
|
||||||
|
* only exact matching, without any normalization procedures
|
||||||
|
* described in 7.4 of RFC5280, will result in a positive
|
||||||
|
* URI verification.
|
||||||
|
* This may be \c NULL if the CN need not be verified.
|
||||||
* \param flags The address at which to store the result of the verification.
|
* \param flags The address at which to store the result of the verification.
|
||||||
* If the verification couldn't be completed, the flag value is
|
* If the verification couldn't be completed, the flag value is
|
||||||
* set to (uint32_t) -1.
|
* set to (uint32_t) -1.
|
||||||
|
@ -2911,6 +2911,21 @@ static int x509_crt_check_san_ip(const mbedtls_x509_sequence *san,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int x509_crt_check_san_uri(const mbedtls_x509_sequence *san,
|
||||||
|
const char *cn, size_t cn_len)
|
||||||
|
{
|
||||||
|
for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
|
||||||
|
const unsigned char san_type = (unsigned char) cur->buf.tag &
|
||||||
|
MBEDTLS_ASN1_TAG_VALUE_MASK;
|
||||||
|
if (san_type == MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER &&
|
||||||
|
cur->buf.len == cn_len && memcmp(cur->buf.p, cn, cn_len) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for SAN match, see RFC 5280 Section 4.2.1.6
|
* Check for SAN match, see RFC 5280 Section 4.2.1.6
|
||||||
*/
|
*/
|
||||||
@ -2918,23 +2933,38 @@ static int x509_crt_check_san(const mbedtls_x509_sequence *san,
|
|||||||
const char *cn, size_t cn_len)
|
const char *cn, size_t cn_len)
|
||||||
{
|
{
|
||||||
int san_ip = 0;
|
int san_ip = 0;
|
||||||
|
int san_uri = 0;
|
||||||
|
/* Prioritize DNS name over other subtypes due to popularity */
|
||||||
for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
|
for (const mbedtls_x509_sequence *cur = san; cur != NULL; cur = cur->next) {
|
||||||
switch ((unsigned char) cur->buf.tag & MBEDTLS_ASN1_TAG_VALUE_MASK) {
|
switch ((unsigned char) cur->buf.tag & MBEDTLS_ASN1_TAG_VALUE_MASK) {
|
||||||
case MBEDTLS_X509_SAN_DNS_NAME: /* dNSName */
|
case MBEDTLS_X509_SAN_DNS_NAME:
|
||||||
if (x509_crt_check_cn(&cur->buf, cn, cn_len) == 0) {
|
if (x509_crt_check_cn(&cur->buf, cn, cn_len) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MBEDTLS_X509_SAN_IP_ADDRESS: /* iPAddress */
|
case MBEDTLS_X509_SAN_IP_ADDRESS:
|
||||||
san_ip = 1;
|
san_ip = 1;
|
||||||
break;
|
break;
|
||||||
|
case MBEDTLS_X509_SAN_UNIFORM_RESOURCE_IDENTIFIER:
|
||||||
|
san_uri = 1;
|
||||||
|
break;
|
||||||
/* (We may handle other types here later.) */
|
/* (We may handle other types here later.) */
|
||||||
default: /* Unrecognized type */
|
default: /* Unrecognized type */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (san_ip) {
|
||||||
|
if (x509_crt_check_san_ip(san, cn, cn_len) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (san_uri) {
|
||||||
|
if (x509_crt_check_san_uri(san, cn, cn_len) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return san_ip ? x509_crt_check_san_ip(san, cn, cn_len) : -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1043,6 +1043,22 @@ X509 CRT verification: mismatching IPv6 in SubjectAltName
|
|||||||
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
||||||
x509_verify:"data_files/server5-tricky-ip-san.crt":"data_files/server5-tricky-ip-san.crt":"data_files/crl_sha256.pem":"6162\:6364\:\:6F6D":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_CN_MISMATCH:"":"NULL"
|
x509_verify:"data_files/server5-tricky-ip-san.crt":"data_files/server5-tricky-ip-san.crt":"data_files/crl_sha256.pem":"6162\:6364\:\:6F6D":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_CN_MISMATCH:"":"NULL"
|
||||||
|
|
||||||
|
X509 CRT verification: matching URI in SubjectAltName
|
||||||
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
||||||
|
x509_verify:"data_files/rsa_single_san_uri.crt.der":"data_files/rsa_single_san_uri.crt.der":"data_files/crl_sha256.pem":"urn\:example.com\:5ff40f78-9210-494f-8206-c2c082f0609c":0:0:"":"NULL"
|
||||||
|
|
||||||
|
X509 CRT verification: URI with trailing data in SubjectAltName
|
||||||
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
||||||
|
x509_verify:"data_files/rsa_single_san_uri.crt.der":"data_files/rsa_single_san_uri.crt.der":"data_files/crl_sha256.pem":"urn\:example.com\:5ff40f78-9210-494f-8206-c2c082f0609cz":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_CN_MISMATCH:"":"NULL"
|
||||||
|
|
||||||
|
X509 CRT verification: URI with preceding data in SubjectAltName
|
||||||
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
||||||
|
x509_verify:"data_files/rsa_single_san_uri.crt.der":"data_files/rsa_single_san_uri.crt.der":"data_files/crl_sha256.pem":"zurn\:example.com\:5ff40f78-9210-494f-8206-c2c082f0609c":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_CN_MISMATCH:"":"NULL"
|
||||||
|
|
||||||
|
X509 CRT verification: URI with bad data in SubjectAltName
|
||||||
|
depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_PK_CAN_ECDSA_SOME:MBEDTLS_MD_CAN_SHA256:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_RSA_C
|
||||||
|
x509_verify:"data_files/rsa_single_san_uri.crt.der":"data_files/rsa_single_san_uri.crt.der":"data_files/crl_sha256.pem":"bad\:example.com\:5ff40f78-9210-494f-8206-c2c082f0609c":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_CN_MISMATCH:"":"NULL"
|
||||||
|
|
||||||
X509 CRT parse CN: IPv4 valid address
|
X509 CRT parse CN: IPv4 valid address
|
||||||
x509_crt_parse_cn_inet_pton:"10.10.10.10":"0A0A0A0A":4
|
x509_crt_parse_cn_inet_pton:"10.10.10.10":"0A0A0A0A":4
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user