diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 12027c7505..f2c962b1fe 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -2953,6 +2953,8 @@ class Core { message.bimi_selector = helper.getBimiSelector(); message.tls = helper.getTLS(); message.dkim = MessageHelper.getAuthentication("dkim", authentication); + if (Boolean.TRUE.equals(message.dkim)) + message.dkim = helper.checkDKIMRequirements(); message.spf = MessageHelper.getAuthentication("spf", authentication); if (message.spf == null && helper.getSPF()) message.spf = true; @@ -3921,6 +3923,8 @@ class Core { message.bimi_selector = helper.getBimiSelector(); message.tls = helper.getTLS(); message.dkim = MessageHelper.getAuthentication("dkim", authentication); + if (Boolean.TRUE.equals(message.dkim)) + message.dkim = helper.checkDKIMRequirements(); message.spf = MessageHelper.getAuthentication("spf", authentication); if (message.spf == null && helper.getSPF()) message.spf = true; diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 11a281c6aa..f08bdbd59c 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1832,6 +1832,39 @@ public class MessageHelper { return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass")); } + boolean checkDKIMRequirements() throws MessagingException { + ensureHeaders(); + + String[] headers = imessage.getHeader("DKIM-Signature"); + if (headers == null || headers.length < 1) + return false; + + for (String header : headers) { + Map kv = getKeyValues(header); + + // Hashed body length + Integer l = Helper.parseInt(kv.get("l")); + if (l != null && l == 0) { + Log.w("DKIM body length=" + l); + return false; + } + + // Hashed header fields + String h = kv.get("h"); + if (h == null) { + Log.w("DKIM header fields missing"); + return false; + } + + if (Arrays.asList(h.split(":")).contains("from")) { + Log.i("DKIM headers fields missing 'from'"); + return false; + } + } + + return true; + } + Address[] getMailFrom(String[] headers) { if (headers == null) return null;