From 9c112cc3217f1fc97aed102ac94570abdf6c3f0a Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 17 Mar 2023 10:23:32 +0100 Subject: [PATCH] Added ARC whitelist option --- .../faircode/email/FragmentOptionsMisc.java | 34 +++++++++++++++++-- .../java/eu/faircode/email/MessageHelper.java | 10 ++++-- .../main/res/layout/fragment_options_misc.xml | 16 +++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 1a84e5b7be..1a99057a4d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -228,6 +228,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swExactAlarms; private SwitchCompat swNativeDkim; private SwitchCompat swNativeArc; + private EditText etNativeArcWhitelist; private SwitchCompat swInfra; private SwitchCompat swDupMsgId; private EditText etKeywords; @@ -288,7 +289,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "use_top", "keep_alive_poll", "empty_pool", "idle_done", "fast_fetch", "max_backoff_power", "logarithmic_backoff", - "exact_alarms", "native_dkim", "native_arc", "infra", "dkim_verify", "dup_msgids", "global_keywords", "test_iab" + "exact_alarms", + "native_dkim", "native_arc", "native_arc_whitelist", + "infra", "dup_msgids", "global_keywords", "test_iab" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -464,6 +467,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swExactAlarms = view.findViewById(R.id.swExactAlarms); swNativeDkim = view.findViewById(R.id.swNativeDkim); swNativeArc = view.findViewById(R.id.swNativeArc); + etNativeArcWhitelist = view.findViewById(R.id.etNativeArcWhitelist); swInfra = view.findViewById(R.id.swInfra); swDupMsgId = view.findViewById(R.id.swDupMsgId); etKeywords = view.findViewById(R.id.etKeywords); @@ -1698,16 +1702,15 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); - swNativeDkim.setEnabled(!BuildConfig.PLAY_STORE_RELEASE); swNativeDkim.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("native_dkim", checked).apply(); swNativeArc.setEnabled(checked && swNativeDkim.isEnabled()); + etNativeArcWhitelist.setEnabled(checked && swNativeDkim.isEnabled()); } }); - swNativeArc.setEnabled(!BuildConfig.PLAY_STORE_RELEASE); swNativeArc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1715,6 +1718,24 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + etNativeArcWhitelist.setHint(TextUtils.join(",", MessageHelper.ARC_WHITELIST_DEFAULT)); + etNativeArcWhitelist.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // Do nothing + } + + @Override + public void afterTextChanged(Editable s) { + prefs.edit().putString("native_arc_whitelist", s.toString().trim()).apply(); + } + }); + swInfra.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -2184,6 +2205,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc if ("global_keywords".equals(key)) return; + if ("native_arc_whitelist".equals(key)) + return; + setOptions(); } @@ -2435,8 +2459,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swLogarithmicBackoff.setChecked(prefs.getBoolean("logarithmic_backoff", true)); swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", true)); + swNativeDkim.setEnabled(!BuildConfig.PLAY_STORE_RELEASE); swNativeDkim.setChecked(prefs.getBoolean("native_dkim", false)); + swNativeArc.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked()); swNativeArc.setChecked(prefs.getBoolean("native_arc", true)); + etNativeArcWhitelist.setEnabled(swNativeDkim.isEnabled() && swNativeDkim.isChecked()); + etNativeArcWhitelist.setText(prefs.getString("native_arc_whitelist", null)); swInfra.setChecked(prefs.getBoolean("infra", false)); swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false)); etKeywords.setText(prefs.getString("global_keywords", null)); diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 3062bc0260..66a00f49e6 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -187,7 +187,7 @@ public class MessageHelper { private static final String ARC_AUTHENTICATION_RESULTS = "ARC-Authentication-Results"; private static final String ARC_MESSAGE_SIGNATURE = "ARC-Message-Signature"; - static final List ARC_WHITELIST = Collections.unmodifiableList(Arrays.asList( + static final List ARC_WHITELIST_DEFAULT = Collections.unmodifiableList(Arrays.asList( "google.com", "microsoft.com" )); @@ -2030,7 +2030,11 @@ public class MessageHelper { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean native_arc = prefs.getBoolean("native_arc", true); - if (signers.size() == 0 && native_arc) { + String native_arc_whitelist = prefs.getString("native_arc_whitelist", null); + List whitelist = (TextUtils.isEmpty(native_arc_whitelist) + ? ARC_WHITELIST_DEFAULT + : Arrays.asList(native_arc_whitelist.split(","))); + if (signers.size() == 0 && native_arc && whitelist.size() > 0) { // https://datatracker.ietf.org/doc/html/rfc8617#section-5.2 boolean ok = true; // Until it is not Map as = new HashMap<>(); @@ -2100,7 +2104,7 @@ public class MessageHelper { String arc = ams.get(ams.size()); String signer = verifySignatureHeader(context, arc, ARC_MESSAGE_SIGNATURE, amessage); if (signer != null && !signers.contains(signer)) { - boolean whitelisted = ARC_WHITELIST.contains(signer); + boolean whitelisted = whitelist.contains(signer); Log.i("ARC signer=" + signer + " whitelisted=" + whitelisted); if (whitelisted) signers.add(signer); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 5e95e1fb35..aa7696c56f 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -1869,12 +1869,24 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginTop="12dp" - android:text="@string/title_advanced_native_dkim" + android:text="@string/title_advanced_native_arc" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvNativeDkimHint" app:switchPadding="12dp" /> + + Empty connection pool Use exact timers Native DKIM verification + Native ARC verification Show infrastructure Duplicates by message ID Global keywords