@@ -13103,12 +13103,14 @@ int MatchDomainName(const char* pattern, int patternLen, const char* str,
1310313103 * domain Domain name to compare against.
1310413104 * domainLen Length of the domain name.
1310513105 * checkCN Whether to check the common name.
13106+ * flags Matching flags.
13107+ * isIP Whether the domain is an IP address.
1310613108 * returns 1 : match was found.
1310713109 * 0 : no match found.
1310813110 * -1 : No matches and wild pattern match failed.
1310913111 */
1311013112int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
13111- int* checkCN, unsigned int flags)
13113+ int* checkCN, unsigned int flags, byte isIP )
1311213114{
1311313115 int match = 0;
1311413116 DNS_entry* altName = NULL;
@@ -13117,14 +13119,13 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
1311713119
1311813120 WOLFSSL_MSG("Checking AltNames");
1311913121
13120- if (dCert)
13122+ if (dCert != NULL )
1312113123 altName = dCert->altNames;
1312213124
13123- if (checkCN != NULL) {
13125+ if (checkCN != NULL)
1312413126 *checkCN = (altName == NULL) ? 1 : 0;
13125- }
1312613127
13127- while ( altName) {
13128+ for (; altName != NULL; altName = altName->next ) {
1312813129 WOLFSSL_MSG("\tindividual AltName check");
1312913130
1313013131#ifdef WOLFSSL_IP_ALT_NAME
@@ -13139,6 +13140,12 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
1313913140 len = (word32)altName->len;
1314013141 }
1314113142
13143+ if ((isIP && (altName->type != ASN_IP_TYPE)) ||
13144+ (!isIP && (altName->type == ASN_IP_TYPE))) {
13145+ WOLFSSL_MSG("\tAltName type mismatch, continue");
13146+ continue;
13147+ }
13148+
1314213149 if (MatchDomainName(buf, (int)len, domain, domainLen, flags)) {
1314313150 match = 1;
1314413151 if (checkCN != NULL) {
@@ -13152,8 +13159,6 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
1315213159 match = -1;
1315313160 WOLFSSL_MSG("\twildcard match failed");
1315413161 }
13155-
13156- altName = altName->next;
1315713162 }
1315813163
1315913164 return match;
@@ -13166,16 +13171,18 @@ int CheckForAltNames(DecodedCert* dCert, const char* domain, word32 domainLen,
1316613171 * dcert Decoded certificate.
1316713172 * domainName The domain name.
1316813173 * domainNameLen The length of the domain name.
13174+ * flags Matching flags.
13175+ * isIP Whether the domain name is an IP address.
1316913176 * returns DOMAIN_NAME_MISMATCH when no match found and 0 on success.
1317013177 */
1317113178int CheckHostName(DecodedCert* dCert, const char *domainName,
13172- size_t domainNameLen, unsigned int flags)
13179+ size_t domainNameLen, unsigned int flags, byte isIP )
1317313180{
1317413181 int checkCN;
1317513182 int ret = WC_NO_ERR_TRACE(DOMAIN_NAME_MISMATCH);
1317613183
1317713184 if (CheckForAltNames(dCert, domainName, (word32)domainNameLen,
13178- &checkCN, flags) != 1) {
13185+ &checkCN, flags, isIP ) != 1) {
1317913186 ret = DOMAIN_NAME_MISMATCH;
1318013187 WOLFSSL_MSG("DomainName match on alt names failed");
1318113188 }
@@ -13203,7 +13210,7 @@ int CheckIPAddr(DecodedCert* dCert, const char* ipasc)
1320313210{
1320413211 WOLFSSL_MSG("Checking IPAddr");
1320513212
13206- return CheckHostName(dCert, ipasc, (size_t)XSTRLEN(ipasc), 0);
13213+ return CheckHostName(dCert, ipasc, (size_t)XSTRLEN(ipasc), 0, 1 );
1320713214}
1320813215
1320913216
@@ -14413,7 +14420,7 @@ int DoVerifyCallback(WOLFSSL_CERT_MANAGER* cm, WOLFSSL* ssl, int cert_err,
1441314420 /* If altNames names is present, then subject common name is ignored */
1441414421 if (args->dCert->altNames != NULL) {
1441514422 if (CheckForAltNames(args->dCert, ssl->param->hostName,
14416- (word32)XSTRLEN(ssl->param->hostName), NULL, 0) != 1) {
14423+ (word32)XSTRLEN(ssl->param->hostName), NULL, 0, 0 ) != 1) {
1441714424 if (cert_err == 0) {
1441814425 ret = DOMAIN_NAME_MISMATCH;
1441914426 WOLFSSL_ERROR_VERBOSE(ret);
@@ -16452,7 +16459,7 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
1645216459 (ssl->buffers.domainName.buffer == NULL ? 0 :
1645316460 (word32)XSTRLEN(
1645416461 (const char *)ssl->buffers.domainName.buffer)),
16455- NULL, 0) != 1) {
16462+ NULL, 0, 0 ) != 1) {
1645616463 WOLFSSL_MSG("DomainName match on alt names failed");
1645716464 /* try to get peer key still */
1645816465 ret = DOMAIN_NAME_MISMATCH;
0 commit comments