Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13488,7 +13488,10 @@ int CheckHostName(DecodedCert* dCert, const char *domainName,
}

#ifndef WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY
if (checkCN == 1) {
/* RFC 6125: IP address identities must appear in an iPAddress SAN and
* must never be matched against the Subject Common Name. Skip the CN
* fallback when verifying an IP address. */
if (checkCN == 1 && !isIP) {
Comment thread
embhorn marked this conversation as resolved.
if (MatchDomainName(dCert->subjectCN, dCert->subjectCNLen,
domainName, (word32)domainNameLen, flags) == 1) {
ret = 0;
Expand Down
162 changes: 162 additions & 0 deletions tests/api/test_ossl_x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,168 @@ int test_wolfSSL_X509_check_ip_asc(void)
ExpectIntEQ(wolfSSL_X509_check_ip_asc(NULL, "0.0.0.0", 0), 0);
ExpectIntEQ(wolfSSL_X509_check_ip_asc(empty, "127.128.0.255", 0), 0);

/* Regression test: a certificate with CN=<ip> and no SAN extension
Comment thread
embhorn marked this conversation as resolved.
* must NOT be accepted for IP verification. RFC 6125 requires that IP
* identities appear in an iPAddress SAN; the Subject CN must never be
* matched against an IP address. Likewise a CN of "*.0.0.1" must not
* wildcard-match "127.0.0.1" -- RFC 6125 Section 7.2 prohibits wildcard
* matching for IP addresses. */
{
/* Self-signed cert, Subject CN="127.0.0.1", no extensions. */
static const unsigned char cn_ip_literal_der[] = {
0x30, 0x82, 0x02, 0xaf, 0x30, 0x82, 0x01, 0x97, 0x02, 0x14, 0x03,
Comment thread
embhorn marked this conversation as resolved.
Outdated
0xe8, 0x5c, 0xb5, 0x56, 0x65, 0x58, 0xd4, 0xd9, 0x86, 0x9c, 0xe7,
0x5b, 0x71, 0xe9, 0xd3, 0x33, 0xe1, 0xa2, 0xdc, 0x30, 0x0d, 0x06,
0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
0x00, 0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04,
0x03, 0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e,
0x31, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x30, 0x38,
0x32, 0x30, 0x32, 0x35, 0x33, 0x33, 0x5a, 0x17, 0x0d, 0x33, 0x36,
0x30, 0x34, 0x30, 0x35, 0x32, 0x30, 0x32, 0x35, 0x33, 0x33, 0x5a,
0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03,
0x0c, 0x09, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31,
0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00,
0xb9, 0xcc, 0x99, 0xf7, 0xbf, 0x7c, 0x4f, 0xec, 0x7f, 0xe6, 0x17,
0x4e, 0xe3, 0xd9, 0xe5, 0x25, 0x7d, 0xab, 0xa8, 0x66, 0xb0, 0x4d,
0x41, 0x5c, 0x20, 0xd8, 0x67, 0xf5, 0xa3, 0xcd, 0x9e, 0x12, 0x7f,
0x09, 0x00, 0xeb, 0x6b, 0xfc, 0x7e, 0x14, 0x10, 0xa0, 0x10, 0x2e,
0x1f, 0xe8, 0xad, 0xec, 0xe8, 0x86, 0x54, 0xa2, 0xc4, 0x58, 0x65,
0x26, 0x95, 0x76, 0xa1, 0xe1, 0x02, 0x52, 0x81, 0xcb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x3f, 0x71, 0x50, 0x56, 0xd2, 0x88, 0xfc, 0x53,
0xc5, 0x11, 0x45, 0x1e, 0x8a, 0xb7, 0x0a, 0x83, 0x9e, 0x89, 0x63,
0x24, 0x3e, 0x8c, 0xbd, 0xed, 0xec, 0xf4, 0x19, 0x32, 0x13, 0xcf,
0xe7, 0xdd, 0xe6, 0x84, 0xed, 0xe7, 0xf7, 0xf9, 0x50, 0x2f, 0x7b,
0xac, 0x7d, 0xf9, 0x0f, 0x61, 0xd1, 0xf7, 0x59, 0xf0, 0x91, 0x73,
0x26, 0x5a, 0xba, 0x24, 0xc8, 0x49, 0x86, 0xc1, 0x1a, 0x42, 0x68,
0x70, 0xbf, 0x94, 0x69, 0xd0, 0xd5, 0x26, 0x7e, 0x3c, 0xa9, 0x69,
0x6f, 0xb1, 0xcc, 0xdf, 0x4d, 0xed, 0x91, 0x6d, 0xdf, 0x45, 0x71,
0xf0, 0x88, 0x69, 0x74, 0x49, 0x2c, 0x5e, 0x77, 0xed, 0x92, 0x36,
0x7f, 0x1a, 0x83, 0x36, 0x42, 0x17, 0x5a, 0xda, 0x91
};
/* Self-signed cert, Subject CN="*.0.0.1", no extensions. */
static const unsigned char cn_ip_wildcard_der[] = {
0x30, 0x82, 0x02, 0xab, 0x30, 0x82, 0x01, 0x93, 0x02, 0x14, 0x3a,
Comment thread
embhorn marked this conversation as resolved.
Outdated
0x4e, 0xfc, 0xf1, 0x5f, 0xcb, 0xe3, 0x6a, 0xae, 0x7f, 0xd6, 0x79,
0xbd, 0x40, 0xc9, 0x64, 0x41, 0xc6, 0xf0, 0x56, 0x30, 0x0d, 0x06,
0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
0x00, 0x30, 0x12, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
0x03, 0x0c, 0x07, 0x2a, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30,
0x1e, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x30, 0x38, 0x32, 0x30,
0x32, 0x35, 0x33, 0x33, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34,
0x30, 0x35, 0x32, 0x30, 0x32, 0x35, 0x33, 0x33, 0x5a, 0x30, 0x12,
0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x07,
0x2a, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x82, 0x01, 0x22,
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,
0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xb9, 0xcc, 0x99, 0xf7,
0xbf, 0x7c, 0x4f, 0xec, 0x7f, 0xe6, 0x17, 0x4e, 0xe3, 0xd9, 0xe5,
0x25, 0x7d, 0xab, 0xa8, 0x66, 0xb0, 0x4d, 0x41, 0x5c, 0x20, 0xd8,
0x67, 0xf5, 0xa3, 0xcd, 0x9e, 0x12, 0x7f, 0x09, 0x00, 0xeb, 0x6b,
0xfc, 0x7e, 0x14, 0x10, 0xa0, 0x10, 0x2e, 0x1f, 0xe8, 0xad, 0xec,
0xe8, 0x86, 0x54, 0xa2, 0xc4, 0x58, 0x65, 0x26, 0x95, 0x76, 0xa1,
0xe1, 0x02, 0x52, 0x81, 0xcb, 0x7e, 0x8e, 0xb2, 0x31, 0xc9, 0x58,
0x9a, 0xdc, 0x69, 0xab, 0x8d, 0x23, 0xcd, 0x96, 0x19, 0x1c, 0x68,
0x69, 0xb5, 0x7d, 0x23, 0xe3, 0x58, 0xe6, 0x26, 0xcc, 0x05, 0x40,
0xd2, 0xa9, 0xb1, 0x09, 0x9c, 0xc8, 0x4a, 0xfc, 0x0a, 0x20, 0xba,
0xc0, 0x12, 0x3b, 0x97, 0x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8, 0x14, 0x02, 0xbf, 0x69, 0x6f, 0x70, 0x21, 0xae, 0xd4, 0x12,
0x4f, 0xd1, 0x9f, 0xe6, 0x56, 0x11, 0x80, 0x39, 0x66, 0xe0, 0xd4,
0x56, 0x5b, 0x32, 0xc6, 0x6c, 0xb8, 0xd2, 0xf4, 0x23, 0x7f, 0xbb,
0x62, 0x2f, 0x5d, 0x67, 0x37, 0x38, 0x74, 0xca, 0xb3, 0x3f, 0x17,
0x53, 0x97, 0xa4, 0xbd, 0xda, 0x26, 0x6a, 0xb3, 0xd9, 0x9f, 0xac,
0xd2, 0x58, 0x4f, 0x24, 0x8c
};
Comment thread
embhorn marked this conversation as resolved.
Outdated
WOLFSSL_X509 *cn_lit = NULL;
WOLFSSL_X509 *cn_wild = NULL;

ExpectNotNull(cn_lit = wolfSSL_X509_load_certificate_buffer(
cn_ip_literal_der, (int)sizeof(cn_ip_literal_der),
WOLFSSL_FILETYPE_ASN1));
ExpectNotNull(cn_wild = wolfSSL_X509_load_certificate_buffer(
cn_ip_wildcard_der, (int)sizeof(cn_ip_wildcard_der),
WOLFSSL_FILETYPE_ASN1));

/* CN=127.0.0.1 with no SAN must NOT match the IP "127.0.0.1". */
ExpectIntEQ(wolfSSL_X509_check_ip_asc(cn_lit, "127.0.0.1", 0), 0);
/* CN=*.0.0.1 with no SAN must NOT wildcard-match "127.0.0.1". */
ExpectIntEQ(wolfSSL_X509_check_ip_asc(cn_wild, "127.0.0.1", 0), 0);
/* CN-based hostname matching must still work for hostname checks
* (sanity check that the fix didn't over-correct). */
ExpectIntEQ(wolfSSL_X509_check_host(cn_wild, "1.0.0.1",
XSTRLEN("1.0.0.1"), 0, NULL), 1);
Comment thread
embhorn marked this conversation as resolved.
Comment thread
embhorn marked this conversation as resolved.

wolfSSL_X509_free(cn_wild);
wolfSSL_X509_free(cn_lit);
}

wolfSSL_X509_free(empty);
wolfSSL_X509_free(x509);
#endif
Expand Down
Loading