diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 1345e89d5d..1a9d7b2d7e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -133,6 +133,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.LabelVisibilityMode; import com.google.android.material.snackbar.Snackbar; +import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.cert.jcajce.JcaCertStore; import org.bouncycastle.cms.CMSAlgorithm; import org.bouncycastle.cms.CMSEnvelopedData; @@ -3575,7 +3576,25 @@ public class FragmentCompose extends FragmentBase { } CMSTypedData msg = new CMSProcessableFile(einput); - OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC) + // https://datatracker.ietf.org/doc/html/rfc5751#section-2.7 + ASN1ObjectIdentifier encryptionOID; + String encryptAlgorithm = prefs.getString("encrypt_algo_smime", "AES128"); + switch (encryptAlgorithm) { + case "AES128": + encryptionOID = CMSAlgorithm.AES128_CBC; + break; + case "AES192": + encryptionOID = CMSAlgorithm.AES192_CBC; + break; + case "AES256": + encryptionOID = CMSAlgorithm.AES256_CBC; + break; + default: + encryptionOID = CMSAlgorithm.AES128_CBC; + } + Log.i("Encryption algorithm=" + encryptAlgorithm + " OID=" + encryptionOID); + + OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(encryptionOID) .build(); CMSEnvelopedData cmsEnvelopedData = cmsEnvelopedDataGenerator .generate(msg, encryptor); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6b9cc68537..08fbc4a54b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -7277,6 +7277,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. InputStream is = recipientInfo.getContentStream(recipient).getContentStream(); decodeMessage(context, is, message, args); decoded = true; + + String algo; + try { + DefaultAlgorithmNameFinder af = new DefaultAlgorithmNameFinder(); + algo = af.getAlgorithmName(envelopedData.getContentEncryptionAlgorithm()); + } catch (Throwable ex) { + Log.e(ex); + algo = envelopedData.getEncryptionAlgOID(); + } + Log.i("Encryption algo=" + algo); + args.putString("algo", algo); } catch (CMSException ex) { Log.w(ex); } @@ -7460,6 +7471,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Snackbar.make(view, Log.formatThrowable(ex), Snackbar.LENGTH_LONG) .setGestureInsetBottomIgnored(true).show(); } + } else if (EntityMessage.SMIME_SIGNENCRYPT.equals(type)) { + String algo = args.getString("algo"); + if (!TextUtils.isEmpty(algo)) { + Snackbar.make(view, algo, Snackbar.LENGTH_LONG) + .setGestureInsetBottomIgnored(true).show(); + } } } diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java index 4125974a26..2a9ad04118 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsEncryption.java @@ -81,6 +81,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre private SwitchCompat swEncryptSubject; private Spinner spSignAlgoSmime; + private Spinner spEncryptAlgoSmime; private SwitchCompat swCheckCertificate; private Button btnManageCertificates; private Button btnImportKey; @@ -94,7 +95,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre private final static String[] RESET_OPTIONS = new String[]{ "sign_default", "encrypt_default", "auto_decrypt", "auto_undecrypt", "openpgp_provider", "autocrypt", "autocrypt_mutual", "encrypt_subject", - "sign_algo_smime", "check_certificate" + "sign_algo_smime", "encrypt_algo_smime", "check_certificate" }; @Override @@ -121,6 +122,7 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre swEncryptSubject = view.findViewById(R.id.swEncryptSubject); spSignAlgoSmime = view.findViewById(R.id.spSignAlgoSmime); + spEncryptAlgoSmime = view.findViewById(R.id.spEncryptAlgoSmime); swCheckCertificate = view.findViewById(R.id.swCheckCertificate); btnManageCertificates = view.findViewById(R.id.btnManageCertificates); btnImportKey = view.findViewById(R.id.btnImportKey); @@ -268,6 +270,19 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre } }); + spEncryptAlgoSmime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + String[] values = getResources().getStringArray(R.array.smimeEncryptAlgo); + prefs.edit().putString("encrypt_algo_smime", values[position]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("encrypt_algo_smime").apply(); + } + }); + swCheckCertificate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -432,6 +447,14 @@ public class FragmentOptionsEncryption extends FragmentBase implements SharedPre break; } + String encryptAlgorithm = prefs.getString("encrypt_algo_smime", "AES128"); + String[] smimeEncryptAlgo = getResources().getStringArray(R.array.smimeEncryptAlgo); + for (int pos = 0; pos < smimeEncryptAlgo.length; pos++) + if (smimeEncryptAlgo[pos].equals(encryptAlgorithm)) { + spEncryptAlgoSmime.setSelection(pos); + break; + } + swCheckCertificate.setChecked(prefs.getBoolean("check_certificate", true)); } diff --git a/app/src/main/res/layout/fragment_options_encryption.xml b/app/src/main/res/layout/fragment_options_encryption.xml index d1fbdeaf24..2c8be4c0ce 100644 --- a/app/src/main/res/layout/fragment_options_encryption.xml +++ b/app/src/main/res/layout/fragment_options_encryption.xml @@ -286,6 +286,28 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvSignAlgoSmime" /> + + + +