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.
@@ -66,12 +66,16 @@ public class X509Utils {
else if (type.equals(RFC4519Style.c))
country = val;
}
- final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
String altName = null;
+ 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;
