aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-05-10 20:20:22 +0200
committerChristian Schneppe <christian@pix-art.de>2017-05-10 20:20:22 +0200
commitf78fbcffa5754665ae4744b854b306da749c854a (patch)
treea0f455d5a7bc9f4ccd83fd8557d7c0988a200a43 /src/main/java/de
parent01aca0599d7f7689e7ebdc6f5e8834de93fac391 (diff)
display open pgp key id in account details and allow to delete
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/PgpEngine.java4
-rw-r--r--src/main/java/de/pixart/messenger/entities/Account.java6
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java12
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java58
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java12
6 files changed, 79 insertions, 15 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java
index c906c7514..1979acbb9 100644
--- a/src/main/java/de/pixart/messenger/crypto/PgpEngine.java
+++ b/src/main/java/de/pixart/messenger/crypto/PgpEngine.java
@@ -304,10 +304,6 @@ public class PgpEngine {
}
}
- public PendingIntent getIntentForKey(Contact contact) {
- return getIntentForKey(contact.getPgpKeyId());
- }
-
public PendingIntent getIntentForKey(long pgpKeyId) {
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_GET_KEY);
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java
index e9fb800cc..18e991367 100644
--- a/src/main/java/de/pixart/messenger/entities/Account.java
+++ b/src/main/java/de/pixart/messenger/entities/Account.java
@@ -554,7 +554,11 @@ public class Account extends AbstractEntity {
public boolean setPgpSignId(long pgpID) {
synchronized (this.keys) {
try {
- keys.put(KEY_PGP_ID, pgpID);
+ if (pgpID == 0) {
+ keys.remove(KEY_PGP_ID);
+ } else {
+ keys.put(KEY_PGP_ID, pgpID);
+ }
} catch (JSONException e) {
return false;
}
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index 1c54d2ff3..a38ae7e59 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
-import de.pixart.messenger.crypto.PgpEngine;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.crypto.axolotl.FingerprintStatus;
import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession;
@@ -555,7 +554,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
.findViewById(R.id.button_remove);
removeButton.setVisibility(View.VISIBLE);
key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
- if (otrFingerprint != null && otrFingerprint.equals(messageFingerprint)) {
+ if (otrFingerprint != null && otrFingerprint.equalsIgnoreCase(messageFingerprint)) {
keyType.setText(R.string.otr_fingerprint_selected_message);
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
} else {
@@ -613,14 +612,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
@Override
public void onClick(View v) {
- PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService.getPgpEngine();
- try {
- startIntentSenderForResult(
- pgp.getIntentForKey(contact).getIntentSender(), 0, null, 0,
- 0, 0);
- } catch (Throwable e) {
- Toast.makeText(ContactDetailsActivity.this, R.string.openpgp_error, Toast.LENGTH_SHORT).show();
- }
+ launchOpenKeyChain(contact.getPgpKeyId());
}
};
view.setOnClickListener(openKey);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 4ba88d49a..342e52451 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -516,6 +516,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (message.getEncryption() == Message.ENCRYPTION_PGP
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
+ } else if (message.getEncryption() == Message.ENCRYPTION_OTR) {
+ fingerprint = "otr";
} else {
fingerprint = message.getFingerprint();
}
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index ab1cbc836..320823120 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -36,6 +36,8 @@ import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
+import org.openintents.openpgp.util.OpenPgpUtils;
+
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -93,13 +95,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private TextView mSessionEst;
private TextView mOtrFingerprint;
private TextView mAxolotlFingerprint;
+ private TextView mPgpFingerprint;
private TextView mOwnFingerprintDesc;
+ private TextView mOtrFingerprintDesc;
+ private TextView getmPgpFingerprintDesc;
private TextView mAccountJidLabel;
private ImageView mAvatar;
private RelativeLayout mOtrFingerprintBox;
private RelativeLayout mAxolotlFingerprintBox;
+ private RelativeLayout mPgpFingerprintBox;
private ImageButton mOtrFingerprintToClipboardButton;
private ImageButton mAxolotlFingerprintToClipboardButton;
+ private ImageButton mPgpDeleteFingerprintButton;
private LinearLayout keys;
private LinearLayout keysCard;
private LinearLayout mNamePort;
@@ -512,7 +519,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
this.mPushRow = (TableRow) findViewById(R.id.push_row);
this.mServerInfoPush = (TextView) findViewById(R.id.server_info_push);
+ this.mPgpFingerprintBox = (RelativeLayout) findViewById(R.id.pgp_fingerprint_box);
+ this.mPgpFingerprint = (TextView) findViewById(R.id.pgp_fingerprint);
+ this.getmPgpFingerprintDesc = (TextView) findViewById(R.id.pgp_fingerprint_desc);
+ this.mPgpDeleteFingerprintButton = (ImageButton) findViewById(R.id.action_delete_pgp);
this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
+ this.mOtrFingerprintDesc = (TextView) findViewById(R.id.otr_fingerprint_desc);
this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
@@ -932,8 +944,36 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} else {
this.mServerInfoPush.setText(R.string.server_info_unavailable);
}
+ final long pgpKeyId = this.mAccount.getPgpId();
+ if (pgpKeyId != 0 && Config.supportOpenPgp()) {
+ OnClickListener openPgp = new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ launchOpenKeyChain(pgpKeyId);
+ }
+ };
+ OnClickListener delete = new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ showDeletePgpDialog();
+ }
+ };
+ this.mPgpFingerprintBox.setVisibility(View.VISIBLE);
+ this.mPgpFingerprint.setText(OpenPgpUtils.convertKeyIdToHex(pgpKeyId));
+ this.mPgpFingerprint.setOnClickListener(openPgp);
+ if ("pgp".equals(messageFingerprint)) {
+ this.getmPgpFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent));
+ }
+ this.getmPgpFingerprintDesc.setOnClickListener(openPgp);
+ this.mPgpDeleteFingerprintButton.setOnClickListener(delete);
+ } else {
+ this.mPgpFingerprintBox.setVisibility(View.GONE);
+ }
final String otrFingerprint = this.mAccount.getOtrFingerprint();
if (otrFingerprint != null && Config.supportOtr()) {
+ if ("otr".equals(messageFingerprint)) {
+ this.mOtrFingerprintDesc.setTextColor(ContextCompat.getColor(this, R.color.accent));
+ }
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton
@@ -1022,6 +1062,24 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
}
+ private void showDeletePgpDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.unpublish_pgp);
+ builder.setMessage(R.string.unpublish_pgp_message);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ mAccount.setPgpSignId(0);
+ mAccount.unsetPgpSignature();
+ xmppConnectionService.databaseBackend.updateAccount(mAccount);
+ xmppConnectionService.sendPresence(mAccount);
+ refreshUiReal();
+ }
+ });
+ builder.create().show();
+ }
+
private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
this.mOsOptimizations.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
if (showDataSaverWarning) {
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 0ea105f59..2187a467b 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -69,6 +69,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
+import de.pixart.messenger.crypto.PgpEngine;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
@@ -1074,6 +1075,17 @@ public abstract class XmppActivity extends Activity {
}
}
+ protected void launchOpenKeyChain(long keyId) {
+ PgpEngine pgp = XmppActivity.this.xmppConnectionService.getPgpEngine();
+ try {
+ startIntentSenderForResult(
+ pgp.getIntentForKey(keyId).getIntentSender(), 0, null, 0,
+ 0, 0);
+ } catch (Throwable e) {
+ Toast.makeText(XmppActivity.this, R.string.openpgp_error, Toast.LENGTH_SHORT).show();
+ }
+ }
+
@Override
public void onResume() {
super.onResume();