Last active
December 20, 2015 10:19
-
-
Save afrase/6114216 to your computer and use it in GitHub Desktop.
Coldfusion cfhttp certificate issue with subject alternative names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check whether the name in the certificate matches the host | |
* we're talking to. | |
*/ | |
private static void checkCert(X509Certificate cert, String host) | |
throws IOException | |
{ | |
String name; | |
try | |
{ | |
name = ((sun.security.x509.X500Name) cert.getSubjectDN()). | |
getCommonName().toLowerCase(); | |
} | |
catch (Throwable t) | |
{ return; } // Oh well, can't check the name in that case | |
if (Util.wildcardMatch(name, host)) | |
return; | |
//MACROMEDIA - If the host name does not match, check with the alternate subject names. | |
try{ | |
Collection altNames = cert.getSubjectAlternativeNames(); | |
if(altNames != null) | |
{ | |
for(Iterator iter = altNames.iterator(); iter.hasNext();) | |
{ | |
// THE FIX | |
// 2nd entry in the list will be the subject name. | |
String altName = (String) ((List) iter.next()).toArray()[1]; | |
if(Util.wildcardMatch((String) list.get(1), host)) | |
return; | |
} | |
} | |
}catch(Throwable t){ | |
} | |
throw new SSLException("Name in certificate `" + name + "' does not " + | |
"match host name `" + host + "'"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check whether the name in the certificate matches the host | |
* we're talking to. | |
*/ | |
private static void checkCert(X509Certificate cert, String host) | |
throws IOException | |
{ | |
String name; | |
try | |
{ | |
name = ((sun.security.x509.X500Name) cert.getSubjectDN()). | |
getCommonName().toLowerCase(); | |
} | |
catch (Throwable t) | |
{ return; } // Oh well, can't check the name in that case | |
if (Util.wildcardMatch(name, host)) | |
return; | |
//MACROMEDIA - If the host name does not match, check with the alternate subject names. | |
try{ | |
Collection altNames = cert.getSubjectAlternativeNames(); | |
if(altNames != null) | |
{ | |
for(Iterator iter = altNames.iterator(); iter.hasNext();) | |
{ | |
// THE PROBLEM | |
// the subject alternative name is in the same case as it appears | |
// in the certificate. | |
List list = (List) iter.next(); | |
// 2nd entry in the list will be the subject name. | |
if(Util.wildcardMatch((String) list.get(1), host)) | |
return; | |
} | |
} | |
}catch(Throwable t){ | |
} | |
throw new SSLException("Name in certificate `" + name + "' does not " + | |
"match host name `" + host + "'"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment