From 1788d04e643608878dc1457eb7b91e98041385d9 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 26 Jul 2020 21:13:18 +0200 Subject: [PATCH] Refactoring --- .../eu/faircode/email/EntityCertificate.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityCertificate.java b/app/src/main/java/eu/faircode/email/EntityCertificate.java index 361b1c768c..e9221ffdbb 100644 --- a/app/src/main/java/eu/faircode/email/EntityCertificate.java +++ b/app/src/main/java/eu/faircode/email/EntityCertificate.java @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Objects; import javax.security.auth.x500.X500Principal; @@ -142,19 +143,22 @@ public class EntityCertificate { try { X500Name name = new JcaX509CertificateHolder(certificate).getSubject(); - List rdns = new ArrayList<>(); - rdns.addAll(Arrays.asList(name.getRDNs(BCStyle.CN))); - rdns.addAll(Arrays.asList(name.getRDNs(BCStyle.EmailAddress))); - for (RDN rdn : rdns) { - for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) { - ASN1Encodable enc = tv.getValue(); - if (enc != null) { - String email = enc.toString(); - if (!result.contains(email) && - Helper.EMAIL_ADDRESS.matcher(email).matches()) - result.add(email); + if (name != null) { + List rdns = new ArrayList<>(); + rdns.addAll(Arrays.asList(name.getRDNs(BCStyle.CN))); + rdns.addAll(Arrays.asList(name.getRDNs(BCStyle.EmailAddress))); + for (RDN rdn : rdns) + for (AttributeTypeAndValue tv : rdn.getTypesAndValues()) { + ASN1Encodable enc = tv.getValue(); + if (enc == null) + continue; + String email = enc.toString().toLowerCase(Locale.ROOT); + if (result.contains(email)) + continue; + if (!Helper.EMAIL_ADDRESS.matcher(email).matches()) + continue; + result.add(email); } - } } } catch (Throwable ex) { Log.e(ex);