From c101e67900233cc2d3017bfdc118a2b97c6fced1 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 25 Jan 2024 17:51:30 +0100 Subject: [PATCH] DANE: improved error handling --- .../java/eu/faircode/email/DnsHelper.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DnsHelper.java b/app/src/main/java/eu/faircode/email/DnsHelper.java index 0f4b177060..2a7f1f50ad 100644 --- a/app/src/main/java/eu/faircode/email/DnsHelper.java +++ b/app/src/main/java/eu/faircode/email/DnsHelper.java @@ -354,14 +354,22 @@ public class DnsHelper { public void close() throws SecurityException { } }; + String clazz = DaneVerifier.class.getName(); - Logger.getLogger(clazz).addHandler(handler); - Log.w("DANE verify " + server + ":" + port); - boolean verified = new DaneVerifier().verifyCertificateChain(chain, server, port); - Log.w("DANE verified=" + verified + " " + server + ":" + port); - Logger.getLogger(clazz).removeHandler(handler); - if (!verified) - throw new CertificateException("DANE missing or invalid"); + try { + Logger.getLogger(clazz).addHandler(handler); + Log.w("DANE verify " + server + ":" + port); + boolean verified = new DaneVerifier().verifyCertificateChain(chain, server, port); + Log.w("DANE verified=" + verified + " " + server + ":" + port); + if (!verified) + throw new CertificateException("DANE missing or invalid"); + } catch (CertificateException ex) { + throw ex; + } catch (Throwable ex) { + throw new CertificateException("DANE error", ex); + } finally { + Logger.getLogger(clazz).removeHandler(handler); + } } private static List getDnsServers(Context context) {