}
}
if (names.isEmpty())
{
throw new TransportException("SSL hostname verification failed. Certificate for did not contain CN or DNS subjectAlt");
}
boolean match = false;
final String hostName = hostnameExpected.trim().toLowerCase();
for (String cn : names)
{
boolean doWildcard = cn.startsWith("*.") &&
cn.lastIndexOf('.') >= 3 &&
!cn.matches("\\*\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
match = doWildcard
? hostName.endsWith(cn.substring(1)) && hostName.indexOf(".") == (1 + hostName.length() - cn.length())
: hostName.equals(cn);
if (match)
{
break;
}
}
if (!match)
{
throw new TransportException("SSL hostname verification failed." +
" Expected : " + hostnameExpected +
" Found in cert : " + names);
}
}
catch (InvalidNameException e)
{
throw new TransportException("SSL hostname verification failed. Could not parse name " + dn, e);
}
catch (CertificateParsingException e)
{
throw new TransportException("SSL hostname verification failed. Could not parse certificate: " + e.getMessage(), e);
}
}