From 346c125125821f515973bba66279f47622c50fe7 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 30 Jan 2024 07:57:01 +0100 Subject: [PATCH] DNS improvements --- .../java/eu/faircode/email/DnsHelper.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DnsHelper.java b/app/src/main/java/eu/faircode/email/DnsHelper.java index 27c3de4e17..29b6f6ab02 100644 --- a/app/src/main/java/eu/faircode/email/DnsHelper.java +++ b/app/src/main/java/eu/faircode/email/DnsHelper.java @@ -200,9 +200,20 @@ public class DnsHelper { Log.i("DNS query name=" + type + ":" + name); ResolverResult data = resolver.resolve(name, clazz); - data.throwIfErrorResponse(); + Log.i("DNS resolved name=" + type + ":" + name + + " success=" + data.wasSuccessful() + + " rcode=" + data.getResponseCode()); + + try { + data.throwIfErrorResponse(); + } catch (Throwable ex) { + Log.e("DNS error message=" + ex.getMessage()); + Log.e(ex); + throw ex; + } boolean secure = (data.getUnverifiedReasons() != null); + Log.i("DNS secure=" + secure + " dnssec=" + dnssec); if (secure && dnssec) { DnssecResultNotAuthenticException ex = data.getDnssecResultNotAuthenticException(); if (ex != null) @@ -268,7 +279,12 @@ public class DnsHelper { for (DnsRecord record : result) { record.query = name; record.secure = secure; - record.authentic = data.isAuthenticData(); + try { + record.authentic = data.isAuthenticData(); + } catch (Throwable ex) { + Log.w(ex); + record.authentic = false; + } } if ("mx".equals(type) || "srv".equals(type)) @@ -568,6 +584,7 @@ public class DnsHelper { @Override public void onAnswer(@NonNull byte[] bytes, int rcode) { try { + Log.i("DNS rcode=" + rcode); DnsMessage answer = new DnsMessage(bytes) .asBuilder() .setResponseCode(DnsMessage.RESPONSE_CODE.getResponseCode(rcode))