|
|
@ -299,4 +299,35 @@ public final class DefaultHostnameVerifier implements HostnameVerifier { |
|
|
|
static List<SubjectName> getSubjectAltNames(final X509Certificate cert) { |
|
|
|
static List<SubjectName> getSubjectAltNames(final X509Certificate cert) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
final Collection<List<?>> entries = cert.getSubjectAlternativeNames(); |
|
|
|
final Collection<List<?>> entries = cert.getSubjectAlternativeNames(); |
|
|
|
if (entrie |
|
|
|
if (entries == null) { |
|
|
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final List<SubjectName> result = new ArrayList<SubjectName>(); |
|
|
|
|
|
|
|
for (List<?> entry: entries) { |
|
|
|
|
|
|
|
final Integer type = entry.size() >= 2 ? (Integer) entry.get(0) : null; |
|
|
|
|
|
|
|
if (type != null) { |
|
|
|
|
|
|
|
final String s = (String) entry.get(1); |
|
|
|
|
|
|
|
result.add(new SubjectName(s, type)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} catch (final CertificateParsingException ignore) { |
|
|
|
|
|
|
|
return Collections.emptyList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* Normalize IPv6 or DNS name. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static String normaliseAddress(final String hostname) { |
|
|
|
|
|
|
|
if (hostname == null) { |
|
|
|
|
|
|
|
return hostname; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
final InetAddress inetAddress = InetAddress.getByName(hostname); |
|
|
|
|
|
|
|
return inetAddress.getHostAddress(); |
|
|
|
|
|
|
|
} catch (final UnknownHostException unexpected) { // Should not happen, because we check for IPv6 address above
|
|
|
|
|
|
|
|
return hostname; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|