Revert "Added S/MIME encrypt/decrypt key aliases"

This reverts commit e1adfaee36.
master
M66B 3 months ago
parent e1adfaee36
commit 4b19fe54f7

@ -33,7 +33,6 @@ import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -178,17 +177,9 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
if (identity.sign_key != null)
sb.append(Long.toHexString(identity.sign_key));
if (identity.sign_key_alias != null) {
Pair<String, String> aliases = identity.getAliases();
if (aliases != null && aliases.first != null) {
if (sb.length() != 0)
sb.append(", ");
sb.append(aliases.first);
}
if (aliases != null && aliases.second != null && !aliases.second.equals(aliases.first)) {
if (sb.length() != 0)
sb.append(", ");
sb.append(aliases.second);
}
if (sb.length() != 0)
sb.append(", ");
sb.append(identity.sign_key_alias);
}
tvSignKeyId.setText(context.getString(R.string.title_sign_key, sb.toString()));

@ -22,7 +22,6 @@ package eu.faircode.email;
import static androidx.room.ForeignKey.CASCADE;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
@ -206,38 +205,6 @@ public class EntityIdentity {
return false;
}
Pair<String, String> getAliases() {
if (sign_key_alias == null)
return null;
String encrypt = null;
String decrypt = null;
try {
JSONObject jalias = new JSONObject(sign_key_alias);
if (jalias.has("encrypt"))
encrypt = jalias.getString("encrypt");
if (jalias.has("decrypt"))
decrypt = jalias.getString("decrypt");
} catch (JSONException ex) {
Log.w(ex);
encrypt = sign_key_alias;
decrypt = sign_key_alias;
}
return new Pair<>(encrypt, decrypt);
}
void setAlias(String alias, boolean encrypt) throws JSONException {
Pair<String, String> aliases = getAliases();
JSONObject jaliases = new JSONObject();
if (aliases != null && aliases.first != null)
jaliases.put("encrypt", aliases.first);
if (aliases != null && aliases.second != null)
jaliases.put("decrypt", aliases.second);
jaliases.put(encrypt ? "encrypt" : "decrypt", alias);
sign_key_alias = jaliases.toString();
}
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);

@ -3222,12 +3222,8 @@ public class FragmentCompose extends FragmentBase {
EntityIdentity identity = db.identity().getIdentity(draft.identity);
if (identity != null && identity.sign_key_alias != null)
try {
Pair<String, String> aliases = identity.getAliases();
if (aliases != null && aliases.first != null) {
args.putString("alias", aliases.first);
PrivateKey key = KeyChain.getPrivateKey(context, aliases.first);
args.putBoolean("available", key != null);
}
PrivateKey key = KeyChain.getPrivateKey(context, identity.sign_key_alias);
args.putBoolean("available", key != null);
} catch (Throwable ex) {
Log.w(ex);
}
@ -3242,13 +3238,13 @@ public class FragmentCompose extends FragmentBase {
boolean available = args.getBoolean("available");
if (available) {
args.putString("alias", identity.sign_key_alias);
onSmime(args, action, extras);
return;
}
if (interactive) {
String alias = args.getString("alias");
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), alias, new Helper.IKeyAlias() {
if (interactive)
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), identity.sign_key_alias, new Helper.IKeyAlias() {
@Override
public void onSelected(String alias) {
args.putString("alias", alias);
@ -3273,7 +3269,6 @@ public class FragmentCompose extends FragmentBase {
snackbar.show();
}
});
}
}
@Override
@ -4468,8 +4463,7 @@ public class FragmentCompose extends FragmentBase {
}
// Store selected alias
identity.setAlias(alias, true);
db.identity().setIdentitySignKeyAlias(identity.id, identity.sign_key_alias);
db.identity().setIdentitySignKeyAlias(identity.id, alias);
// Build content
File sinput = new File(tmp, draft.id + ".smime_sign");

@ -9436,8 +9436,7 @@ public class FragmentMessages extends FragmentBase
if (auto && identity == null)
return;
Pair<String, String> aliases = (identity == null ? null : identity.getAliases());
String alias = (aliases == null ? null : aliases.second);
String alias = (identity == null ? null : identity.sign_key_alias);
Helper.selectKeyAlias(getActivity(), getViewLifecycleOwner(), alias, new Helper.IKeyAlias() {
@Override
public void onSelected(String alias) {
@ -10766,17 +10765,10 @@ public class FragmentMessages extends FragmentBase
db.message().setMessageStored(message.id, new Date().getTime());
db.message().setMessageFts(message.id, false);
if (alias != null && !duplicate && message.identity != null) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity != null) {
identity.setAlias(alias, false);
db.identity().setIdentitySignKeyAlias(identity.id, identity.sign_key_alias);
}
}
if (alias != null && !duplicate && message.identity != null)
db.identity().setIdentitySignKeyAlias(message.identity, alias);
db.setTransactionSuccessful();
} catch (JSONException ex) {
Log.e(ex);
} catch (SQLiteConstraintException ex) {
// Message removed
Log.w(ex);

Loading…
Cancel
Save