DKIM simplification

pull/212/head
M66B 2 years ago
parent 1076a99c53
commit 796ea88727

@ -3201,13 +3201,10 @@ class Core {
message.tls = helper.getTLS(); message.tls = helper.getTLS();
message.dkim = MessageHelper.getAuthentication("dkim", authentication); message.dkim = MessageHelper.getAuthentication("dkim", authentication);
if (Boolean.TRUE.equals(message.dkim)) { if (Boolean.TRUE.equals(message.dkim) &&
if (native_dkim && !BuildConfig.PLAY_STORE_RELEASE) { native_dkim && !BuildConfig.PLAY_STORE_RELEASE &&
if (TextUtils.isEmpty(message.signedby)) TextUtils.isEmpty(message.signedby))
message.dkim = false; message.dkim = false;
} else
message.dkim = helper.checkDKIMRequirements();
}
message.spf = MessageHelper.getAuthentication("spf", authentication); message.spf = MessageHelper.getAuthentication("spf", authentication);
if (message.spf == null && helper.getSPF()) if (message.spf == null && helper.getSPF())
message.spf = true; message.spf = true;
@ -4305,8 +4302,10 @@ class Core {
message.tls = helper.getTLS(); message.tls = helper.getTLS();
message.dkim = MessageHelper.getAuthentication("dkim", authentication); message.dkim = MessageHelper.getAuthentication("dkim", authentication);
if (Boolean.TRUE.equals(message.dkim)) if (Boolean.TRUE.equals(message.dkim) &&
message.dkim = helper.checkDKIMRequirements(); native_dkim && !BuildConfig.PLAY_STORE_RELEASE &&
TextUtils.isEmpty(message.signedby))
message.dkim = false;
message.spf = MessageHelper.getAuthentication("spf", authentication); message.spf = MessageHelper.getAuthentication("spf", authentication);
if (message.spf == null && helper.getSPF()) if (message.spf == null && helper.getSPF())
message.spf = true; message.spf = true;

@ -2160,41 +2160,6 @@ public class MessageHelper {
return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass")); return (spf.trim().toLowerCase(Locale.ROOT).startsWith("pass"));
} }
boolean checkDKIMRequirements() throws MessagingException {
ensureHeaders();
// https://datatracker.ietf.org/doc/html/rfc6376/
String[] headers = imessage.getHeader("DKIM-Signature");
if (headers == null || headers.length < 1)
return false;
for (String header : headers) {
Map<String, String> kv = getKeyValues(MimeUtility.unfold(header));
// Algorithm
// https://tools.ietf.org/id/draft-ietf-dcrup-dkim-usage-03.html#rfc.section.4.3
String a = kv.get("a");
if ("rsa-sha1".equals(a))
return false;
// 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;
}
}
return true;
}
@NonNull @NonNull
List<String> verifyDKIM(Context context) { List<String> verifyDKIM(Context context) {
List<String> signers = new ArrayList<>(); List<String> signers = new ArrayList<>();

Loading…
Cancel
Save