From 6ff1a122e20fb9f06297fac7d26044bd60d81ba1 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 6 May 2020 13:02:41 +0200 Subject: [PATCH] Included valid S/MIME public keys for recipients --- .../eu/faircode/email/FragmentCompose.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 582cd8029e..dfc3a720e4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2434,23 +2434,30 @@ public class FragmentCompose extends FragmentBase { certs.add(chain[0]); // Allow sender to decrypt own message for (Address address : addresses) { + boolean found = false; + Throwable cex = null; String email = ((InternetAddress) address).getAddress(); - List acertificates = db.certificate().getCertificateByEmail(email); - if (acertificates == null || acertificates.size() == 0) - throw new IllegalArgumentException( - context.getString(R.string.title_certificate_missing, email), new CertificateException()); - - for (EntityCertificate acertificate : acertificates) { - X509Certificate cert = acertificate.getCertificate(); - try { - cert.checkValidity(); - } catch (CertificateException ex) { - throw new IllegalArgumentException( - context.getString(R.string.title_certificate_invalid, email), ex); + if (acertificates != null) + for (EntityCertificate acertificate : acertificates) { + X509Certificate cert = acertificate.getCertificate(); + try { + cert.checkValidity(); + certs.add(cert); + found = true; + } catch (CertificateException ex) { + Log.w(ex); + cex = ex; + } } - certs.add(cert); - } + + if (!found) + if (cex == null) + throw new IllegalArgumentException( + context.getString(R.string.title_certificate_missing, email)); + else + throw new IllegalArgumentException( + context.getString(R.string.title_certificate_invalid, email), cex); } // Build signature