Bug 903885, fix IDNA wildcard handling, r=kaie
authorChristian Heimes <sites@cheimes.de>
Mon, 24 Feb 2014 17:50:25 +0100
changeset 11045 15ea62260c21d83e1ada26019f437833cbb0c6f5
parent 11044 bc3fc2667a9416591fcd7a6690aa49dca0503649
child 11046 2ffa40a3ff5584139c58fe65e44f788daf239aef
push id308
push userkaie@kuix.de
push dateMon, 24 Feb 2014 16:50:34 +0000
reviewerskaie
bugs903885
Bug 903885, fix IDNA wildcard handling, r=kaie
lib/certdb/certdb.c
--- a/lib/certdb/certdb.c
+++ b/lib/certdb/certdb.c
@@ -1381,28 +1381,32 @@ cert_TestHostName(char * cn, const char 
 	    return rv;
 	}
     } else {
 	/* New approach conforms to RFC 2818. */
 	char *wildcard    = PORT_Strchr(cn, '*');
 	char *firstcndot  = PORT_Strchr(cn, '.');
 	char *secondcndot = firstcndot ? PORT_Strchr(firstcndot+1, '.') : NULL;
 	char *firsthndot  = PORT_Strchr(hn, '.');
+	/* RFC 6125 IDN matching */
+	int firstace      = PORT_Strncasecmp('xn--', cn, 4);
 
 	/* For a cn pattern to be considered valid, the wildcard character...
 	 * - may occur only in a DNS name with at least 3 components, and
 	 * - may occur only as last character in the first component, and
-	 * - may be preceded by additional characters
+	 * - may be preceded by additional characters, and
+	 * - must not be preceded by an IDN ACE prefix (xn--)
 	 */
 	if (wildcard && secondcndot && secondcndot[1] && firsthndot 
 	    && firstcndot  - wildcard  == 1
 	    && secondcndot - firstcndot > 1
 	    && PORT_Strrchr(cn, '*') == wildcard
 	    && !PORT_Strncasecmp(cn, hn, wildcard - cn)
-	    && !PORT_Strcasecmp(firstcndot, firsthndot)) {
+	    && !PORT_Strcasecmp(firstcndot, firsthndot)
+	    && firstace != 0) {
 	    /* valid wildcard pattern match */
 	    return SECSuccess;
 	}
     }
     /* String cn has no wildcard or shell expression.  
      * Compare entire string hn with cert name. 
      */
     if (PORT_Strcasecmp(hn, cn) == 0) {