Check all certificate names

pull/169/head
M66B 5 years ago
parent 6330e43bfa
commit e12e57bdc9

@ -108,11 +108,14 @@ public class MailService implements AutoCloseable {
boolean trusted = false; boolean trusted = false;
String name = getDnsName(certificate); List<String> names = getDnsNames(certificate);
if (name != null && matches(server, name)) for (String name : names)
trusted = true; if (matches(server, name))
else trusted = true;
Log.e("Certificate mismatch server=" + server + " name=" + name);
if (!trusted)
Log.e("Certificate mismatch" +
" server=" + server + " names=" + TextUtils.join(",", names));
if (getFingerPrint(certificate).equals(trustedFingerprint)) if (getFingerPrint(certificate).equals(trustedFingerprint))
trusted = true; trusted = true;
@ -470,16 +473,18 @@ public class MailService implements AutoCloseable {
} }
} }
private static String getDnsName(X509Certificate certificate) throws CertificateParsingException { private static List<String> getDnsNames(X509Certificate certificate) throws CertificateParsingException {
List<String> result = new ArrayList<>();
Collection<List<?>> altNames = certificate.getSubjectAlternativeNames(); Collection<List<?>> altNames = certificate.getSubjectAlternativeNames();
if (altNames == null) if (altNames == null)
return null; return result;
for (List altName : altNames) for (List altName : altNames)
if (altName.get(0).equals(GeneralName.dNSName)) if (altName.get(0).equals(GeneralName.dNSName))
return (String) altName.get(1); result.add((String) altName.get(1));
return null; return result;
} }
private static String getFingerPrint(X509Certificate certificate) throws CertificateEncodingException, NoSuchAlgorithmException { private static String getFingerPrint(X509Certificate certificate) throws CertificateEncodingException, NoSuchAlgorithmException {

Loading…
Cancel
Save