X509Utils: handle CertificateParsingException in getDisplayNameFromCertificate() if certificate has no SubjectAltName extension

This fix makes the method compatible with JDK 18. Previously, it relied
on the method returning `null` if the extension is not present.
This commit is contained in:
Andreas Schildbach 2022-03-31 11:10:16 +02:00
parent 4be4a3f9f8
commit 4a6219bf57

View file

@ -66,12 +66,16 @@ public class X509Utils {
else if (type.equals(RFC4519Style.c))
country = val;
}
final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
String altName = null;
if (subjectAlternativeNames != null)
for (final List<?> subjectAlternativeName : subjectAlternativeNames)
if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
altName = (String) subjectAlternativeName.get(1);
try {
final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
if (subjectAlternativeNames != null)
for (final List<?> subjectAlternativeName : subjectAlternativeNames)
if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
altName = (String) subjectAlternativeName.get(1);
} catch (CertificateParsingException e) {
// swallow
}
if (org != null) {
return withLocation ? Joiner.on(", ").skipNulls().join(org, location, country) : org;