Added auto verify signatures

pull/213/head
M66B 2 years ago
parent b53e200afd
commit 71288bd5f3

@ -3319,11 +3319,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean auto_decrypt = prefs.getBoolean("auto_decrypt", false); boolean auto_decrypt = prefs.getBoolean("auto_decrypt", false);
boolean auto_decrypted = properties.getValue("auto_decrypted", message.id); boolean auto_decrypted = properties.getValue("auto_decrypted", message.id);
boolean auto_verify = prefs.getBoolean("auto_verify", false);
boolean auto_verified = properties.getValue("auto_verified", message.id);
if (auto_decrypt && !auto_decrypted && if (auto_decrypt && !auto_decrypted &&
(EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) || (EntityMessage.PGP_SIGNENCRYPT.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt))) { EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt))) {
properties.setValue("auto_decrypted", message.id, true); properties.setValue("auto_decrypted", message.id, true);
onActionDecrypt(message, true); onActionVerifyDecrypt(message, true);
} else if (auto_verify && !auto_verified && !message.verified &&
(EntityMessage.PGP_SIGNONLY.equals(message.encrypt) ||
EntityMessage.SMIME_SIGNONLY.equals(message.encrypt))) {
properties.setValue("auto_verified", message.id, true);
onActionVerifyDecrypt(message, true);
} }
} }
@ -4268,9 +4275,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.setExpanded(message, false, false); properties.setExpanded(message, false, false);
properties.setHeight(message.id, null); properties.setHeight(message.id, null);
} else } else
onActionDecrypt(message, false); onActionVerifyDecrypt(message, false);
} else if (id == R.id.ibVerify) { } else if (id == R.id.ibVerify) {
onActionDecrypt(message, false); onActionVerifyDecrypt(message, false);
} else if (id == R.id.ibUndo) { } else if (id == R.id.ibUndo) {
ActivityCompose.undoSend(message.id, context, owner, parentFragment.getParentFragmentManager()); ActivityCompose.undoSend(message.id, context, owner, parentFragment.getParentFragmentManager());
} else if (id == R.id.ibAnswer) { } else if (id == R.id.ibAnswer) {
@ -5604,13 +5611,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
EntityFolder.JUNK.equals(message.folderType)); EntityFolder.JUNK.equals(message.folderType));
} }
private void onActionDecrypt(TupleMessageEx message, boolean auto) { private void onActionVerifyDecrypt(TupleMessageEx message, boolean auto) {
boolean inline = properties.getValue("inline_encrypted", message.id); boolean inline = properties.getValue("inline_encrypted", message.id);
int encrypt = (message.encrypt == null || inline ? EntityMessage.PGP_SIGNENCRYPT /* Inline */ : message.encrypt); int encrypt = (message.encrypt == null || inline ? EntityMessage.PGP_SIGNENCRYPT /* Inline */ : message.encrypt);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
new Intent(FragmentMessages.ACTION_DECRYPT) new Intent(FragmentMessages.ACTION_VERIFYDECRYPT)
.putExtra("id", message.id) .putExtra("id", message.id)
.putExtra("auto", auto) .putExtra("auto", auto)
.putExtra("type", encrypt)); .putExtra("type", encrypt));

@ -433,7 +433,7 @@ public class FragmentMessages extends FragmentBase
static final int REQUEST_CALENDAR = 29; static final int REQUEST_CALENDAR = 29;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT"; static final String ACTION_VERIFYDECRYPT = BuildConfig.APPLICATION_ID + ".VERIFYDECRYPT";
static final String ACTION_KEYWORDS = BuildConfig.APPLICATION_ID + ".KEYWORDS"; static final String ACTION_KEYWORDS = BuildConfig.APPLICATION_ID + ".KEYWORDS";
private static final long REVIEW_ASK_DELAY = 14 * 24 * 3600 * 1000L; // milliseconds private static final long REVIEW_ASK_DELAY = 14 * 24 * 3600 * 1000L; // milliseconds
@ -5049,7 +5049,7 @@ public class FragmentMessages extends FragmentBase
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
IntentFilter iff = new IntentFilter(); IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_STORE_RAW); iff.addAction(ACTION_STORE_RAW);
iff.addAction(ACTION_DECRYPT); iff.addAction(ACTION_VERIFYDECRYPT);
iff.addAction(ACTION_KEYWORDS); iff.addAction(ACTION_KEYWORDS);
lbm.registerReceiver(receiver, iff); lbm.registerReceiver(receiver, iff);
@ -8214,8 +8214,8 @@ public class FragmentMessages extends FragmentBase
String action = intent.getAction(); String action = intent.getAction();
if (ACTION_STORE_RAW.equals(action)) if (ACTION_STORE_RAW.equals(action))
onStoreRaw(intent); onStoreRaw(intent);
else if (ACTION_DECRYPT.equals(action)) else if (ACTION_VERIFYDECRYPT.equals(action))
onDecrypt(intent); onVerifyDecrypt(intent);
else if (ACTION_KEYWORDS.equals(action)) else if (ACTION_KEYWORDS.equals(action))
onKeywords(intent); onKeywords(intent);
} }
@ -8247,7 +8247,7 @@ public class FragmentMessages extends FragmentBase
startActivityForResult(Helper.getChooser(context, create), REQUEST_RAW); startActivityForResult(Helper.getChooser(context, create), REQUEST_RAW);
} }
private void onDecrypt(Intent intent) { private void onVerifyDecrypt(Intent intent) {
long id = intent.getLongExtra("id", -1); long id = intent.getLongExtra("id", -1);
boolean auto = intent.getBooleanExtra("auto", false); boolean auto = intent.getBooleanExtra("auto", false);
int type = intent.getIntExtra("type", EntityMessage.ENCRYPT_NONE); int type = intent.getIntExtra("type", EntityMessage.ENCRYPT_NONE);
@ -8255,6 +8255,7 @@ public class FragmentMessages extends FragmentBase
final Bundle args = new Bundle(); final Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
args.putInt("type", type); args.putInt("type", type);
args.putBoolean("auto", auto);
if (EntityMessage.SMIME_SIGNONLY.equals(type)) if (EntityMessage.SMIME_SIGNONLY.equals(type))
onSmime(args); onSmime(args);
@ -8285,7 +8286,7 @@ public class FragmentMessages extends FragmentBase
@Override @Override
protected void onExecuted(Bundle args, EntityIdentity identity) { protected void onExecuted(Bundle args, EntityIdentity identity) {
Boolean auto = args.getBoolean("auto"); boolean auto = args.getBoolean("auto");
if (auto && identity == null) if (auto && identity == null)
return; return;
@ -9279,6 +9280,7 @@ public class FragmentMessages extends FragmentBase
.setGestureInsetBottomIgnored(true).show(); .setGestureInsetBottomIgnored(true).show();
} else } else
try { try {
boolean auto = args.getBoolean("auto");
String sender = args.getString("sender"); String sender = args.getString("sender");
Date time = (Date) args.getSerializable("time"); Date time = (Date) args.getSerializable("time");
boolean known = args.getBoolean("known"); boolean known = args.getBoolean("known");
@ -9302,7 +9304,7 @@ public class FragmentMessages extends FragmentBase
if (known && !record.isExpired(time) && match && valid) if (known && !record.isExpired(time) && match && valid)
Snackbar.make(view, R.string.title_signature_valid, Snackbar.LENGTH_LONG) Snackbar.make(view, R.string.title_signature_valid, Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show(); .setGestureInsetBottomIgnored(true).show();
else { else if (!auto) {
LayoutInflater inflator = LayoutInflater.from(getContext()); LayoutInflater inflator = LayoutInflater.from(getContext());
View dview = inflator.inflate(R.layout.dialog_certificate, null); View dview = inflator.inflate(R.layout.dialog_certificate, null);
TextView tvCertificateInvalid = dview.findViewById(R.id.tvCertificateInvalid); TextView tvCertificateInvalid = dview.findViewById(R.id.tvCertificateInvalid);

@ -87,6 +87,7 @@ public class FragmentOptionsEncryption extends FragmentBase
private SwitchCompat swSign; private SwitchCompat swSign;
private SwitchCompat swEncrypt; private SwitchCompat swEncrypt;
private SwitchCompat swEncryptAuto; private SwitchCompat swEncryptAuto;
private SwitchCompat swAutoVerify;
private SwitchCompat swAutoDecrypt; private SwitchCompat swAutoDecrypt;
private SwitchCompat swAutoUndoDecrypt; private SwitchCompat swAutoUndoDecrypt;
private Button btnReset; private Button btnReset;
@ -118,7 +119,7 @@ public class FragmentOptionsEncryption extends FragmentBase
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"sign_default", "encrypt_default", "encrypt_auto", "sign_default", "encrypt_default", "encrypt_auto",
"auto_decrypt", "auto_undecrypt", "auto_verify", "auto_decrypt", "auto_undecrypt",
"openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject", "openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject",
"sign_algo_smime", "encrypt_algo_smime", "check_certificate" "sign_algo_smime", "encrypt_algo_smime", "check_certificate"
}; };
@ -139,6 +140,7 @@ public class FragmentOptionsEncryption extends FragmentBase
swSign = view.findViewById(R.id.swSign); swSign = view.findViewById(R.id.swSign);
swEncrypt = view.findViewById(R.id.swEncrypt); swEncrypt = view.findViewById(R.id.swEncrypt);
swEncryptAuto = view.findViewById(R.id.swEncryptAuto); swEncryptAuto = view.findViewById(R.id.swEncryptAuto);
swAutoVerify = view.findViewById(R.id.swAutoVerify);
swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt); swAutoDecrypt = view.findViewById(R.id.swAutoDecrypt);
swAutoUndoDecrypt = view.findViewById(R.id.swAutoUndoDecrypt); swAutoUndoDecrypt = view.findViewById(R.id.swAutoUndoDecrypt);
btnReset = view.findViewById(R.id.btnReset); btnReset = view.findViewById(R.id.btnReset);
@ -225,6 +227,13 @@ public class FragmentOptionsEncryption extends FragmentBase
} }
}); });
swAutoVerify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("auto_verify", checked).apply();
}
});
swAutoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAutoDecrypt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -644,6 +653,7 @@ public class FragmentOptionsEncryption extends FragmentBase
swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false)); swEncrypt.setChecked(prefs.getBoolean("encrypt_default", false));
swSign.setEnabled(!swEncrypt.isChecked()); swSign.setEnabled(!swEncrypt.isChecked());
swEncryptAuto.setChecked(prefs.getBoolean("encrypt_auto", false)); swEncryptAuto.setChecked(prefs.getBoolean("encrypt_auto", false));
swAutoVerify.setChecked(prefs.getBoolean("auto_verify", false));
swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false)); swAutoDecrypt.setChecked(prefs.getBoolean("auto_decrypt", false));
swAutoUndoDecrypt.setChecked(prefs.getBoolean("auto_undecrypt", false)); swAutoUndoDecrypt.setChecked(prefs.getBoolean("auto_undecrypt", false));

@ -119,6 +119,17 @@
app:layout_constraintTop_toBottomOf="@id/swEncrypt" app:layout_constraintTop_toBottomOf="@id/swEncrypt"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoVerify"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_auto_verify"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEncryptAuto"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoDecrypt" android:id="@+id/swAutoDecrypt"
android:layout_width="0dp" android:layout_width="0dp"
@ -127,7 +138,7 @@
android:text="@string/title_advanced_auto_decrypt" android:text="@string/title_advanced_auto_decrypt"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swEncryptAuto" app:layout_constraintTop_toBottomOf="@id/swAutoVerify"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -767,6 +767,7 @@
<string name="title_advanced_sign_default">Sign by default</string> <string name="title_advanced_sign_default">Sign by default</string>
<string name="title_advanced_encrypt_default">Encrypt by default</string> <string name="title_advanced_encrypt_default">Encrypt by default</string>
<string name="title_advanced_encrypt_auto">Automatically encrypt when all recipients\' keys are available</string> <string name="title_advanced_encrypt_auto">Automatically encrypt when all recipients\' keys are available</string>
<string name="title_advanced_auto_verify">Automatically verify signed messages</string>
<string name="title_advanced_auto_decrypt">Automatically decrypt messages</string> <string name="title_advanced_auto_decrypt">Automatically decrypt messages</string>
<string name="title_advanced_auto_undo_decrypt">Undo decryption on closing conversation</string> <string name="title_advanced_auto_undo_decrypt">Undo decryption on closing conversation</string>

Loading…
Cancel
Save