Added ARC whitelist option

pull/212/head
M66B 2 years ago
parent 115a98b6fe
commit 9c112cc321

@ -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));

@ -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<String> ARC_WHITELIST = Collections.unmodifiableList(Arrays.asList(
static final List<String> 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<String> 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<Integer, String> 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);

@ -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" />
<EditText
android:id="@+id/etNativeArcWhitelist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:inputType="textNoSuggestions"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNativeArc" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swInfra"
android:layout_width="0dp"
@ -1883,7 +1895,7 @@
android:text="@string/title_advanced_infra"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNativeArc"
app:layout_constraintTop_toBottomOf="@id/etNativeArcWhitelist"
app:switchPadding="12dp" />
<androidx.constraintlayout.helper.widget.Flow

@ -869,6 +869,7 @@
<string name="title_advanced_empty_pool" translatable="false">Empty connection pool</string>
<string name="title_advanced_exact_alarms" translatable="false">Use exact timers</string>
<string name="title_advanced_native_dkim" translatable="false">Native DKIM verification</string>
<string name="title_advanced_native_arc" translatable="false">Native ARC verification</string>
<string name="title_advanced_infra" translatable="false">Show infrastructure</string>
<string name="title_advanced_dup_msgid" translatable="false">Duplicates by message ID</string>
<string name="title_advanced_global_keywords" translatable="false">Global keywords</string>

Loading…
Cancel
Save