From c08dec2b34ec1c82ea334a9578a66e31171155d5 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 13 Nov 2023 15:00:01 +0100 Subject: [PATCH] DMARC viewer improvements --- app/src/amazon/AndroidManifest.xml | 4 +- app/src/debug/AndroidManifest.xml | 4 +- app/src/fdroid/AndroidManifest.xml | 4 +- app/src/github/AndroidManifest.xml | 4 +- app/src/main/AndroidManifest.xml | 4 +- .../java/eu/faircode/email/ActivityDmarc.java | 41 +++++++++++-------- app/src/play/AndroidManifest.xml | 4 +- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/app/src/amazon/AndroidManifest.xml b/app/src/amazon/AndroidManifest.xml index d462867ae0..9b560becea 100644 --- a/app/src/amazon/AndroidManifest.xml +++ b/app/src/amazon/AndroidManifest.xml @@ -487,10 +487,10 @@ diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml index 59fe4e8a46..f873dbb8ef 100644 --- a/app/src/debug/AndroidManifest.xml +++ b/app/src/debug/AndroidManifest.xml @@ -493,11 +493,11 @@ diff --git a/app/src/fdroid/AndroidManifest.xml b/app/src/fdroid/AndroidManifest.xml index a5a14f5db6..7d9507752a 100644 --- a/app/src/fdroid/AndroidManifest.xml +++ b/app/src/fdroid/AndroidManifest.xml @@ -493,10 +493,10 @@ diff --git a/app/src/github/AndroidManifest.xml b/app/src/github/AndroidManifest.xml index aeb9a08463..5a9df5e35f 100644 --- a/app/src/github/AndroidManifest.xml +++ b/app/src/github/AndroidManifest.xml @@ -492,11 +492,11 @@ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2413c19ea1..595eadd698 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -488,10 +488,10 @@ diff --git a/app/src/main/java/eu/faircode/email/ActivityDmarc.java b/app/src/main/java/eu/faircode/email/ActivityDmarc.java index c95f2ec445..b286039870 100644 --- a/app/src/main/java/eu/faircode/email/ActivityDmarc.java +++ b/app/src/main/java/eu/faircode/email/ActivityDmarc.java @@ -64,7 +64,7 @@ public class ActivityDmarc extends ActivityBase { super.onCreate(savedInstanceState); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setSubtitle("DMARC"); + getSupportActionBar().setSubtitle(R.string.title_advanced_dmarc_viewer); View view = LayoutInflater.from(this).inflate(R.layout.activity_dmarc, null); setContentView(view); @@ -276,14 +276,15 @@ public class ActivityDmarc extends ActivityBase { .append(text).append(' '); if ("source_ip".equals(name)) { try { - boolean valid = false; + Boolean valid = null; String because = null; if (spf != null) for (Pair p : spf) { for (String ip : p.second.response.split("\\s+")) { + boolean allow = true; ip = ip.toLowerCase(Locale.ROOT); if (ip.startsWith("-")) - continue; + allow = false; else if (ip.startsWith("+")) ip = ip.substring(1); @@ -298,9 +299,8 @@ public class ActivityDmarc extends ActivityBase { if (prefix == null) continue; if (ConnectionHelper.inSubnet(text, net[0], prefix)) { - valid = true; + valid = allow; because = ip + " in " + p.first; - break; } } else if ("a".equals(ip) || ip.startsWith("a:")) { String domain = (ip.startsWith("a:") @@ -320,20 +320,18 @@ public class ActivityDmarc extends ActivityBase { for (DnsHelper.DnsRecord a : as) if (prefix == null) { if (text.equals(a.response)) { - valid = true; + valid = allow; because = ip + " in " + domain; break; } } else { if (ConnectionHelper.inSubnet(text, a.response, prefix)) { - valid = true; + valid = allow; because = ip + " in " + domain + "/" + prefix; break; } } - if (valid) - break; - } else if ("mx".equals(ip) || ip.startsWith("mx:")) + } else if ("mx".equals(ip) || ip.startsWith("mx:")) { try { String domain = (ip.startsWith("mx:") ? ip.substring(3) : p.first); @@ -352,33 +350,42 @@ public class ActivityDmarc extends ActivityBase { as.addAll(Arrays.asList(DnsHelper.lookup(context, mx.response, "aaaa"))); } catch (UnknownHostException ignored) { } - for (DnsHelper.DnsRecord a : as) + for (DnsHelper.DnsRecord a : as) { if (prefix == null) { if (text.equals(a.response)) { - valid = true; + valid = allow; because = ip + " in " + domain; break; } } else { if (ConnectionHelper.inSubnet(text, a.response, prefix)) { - valid = true; + valid = allow; because = ip + " in " + domain + "/" + prefix; break; } } - if (valid) + } + if (valid != null) break; } } catch (UnknownHostException ignored) { } + } else if ("ptr".equals(ip) || ip.startsWith("ptr:")) { + valid = false; + because = ip + " ptr not supported"; + } + if (valid != null) + break; } - if (valid) + if (valid != null) break; } int start = ssb.length(); - ssb.append(valid ? "valid (" + because + ")" : "invalid"); - if (!valid) { + ssb.append(Boolean.TRUE.equals(valid) ? "valid" : "invalid"); + if (because != null) + ssb.append(" (").append(because).append(')'); + if (!Boolean.TRUE.equals(valid)) { ssb.setSpan(new StyleSpan(Typeface.BOLD), start, ssb.length(), 0); ssb.setSpan(new ForegroundColorSpan(colorWarning), start, ssb.length(), 0); } diff --git a/app/src/play/AndroidManifest.xml b/app/src/play/AndroidManifest.xml index 01dffe27a6..4ed54b3cba 100644 --- a/app/src/play/AndroidManifest.xml +++ b/app/src/play/AndroidManifest.xml @@ -487,10 +487,10 @@