aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/OmemoActivity.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-11-29 21:39:50 +0100
committerChristian Schneppe <christian@pix-art.de>2016-11-29 21:39:50 +0100
commitbdda426ad4223773b5873ee20db22a22dff0e49b (patch)
tree0f958c1e14690a9731429ba5f1d801c5c94fb96b /src/main/java/de/pixart/messenger/OmemoActivity.java
parent9671783d5bf7e2b8cf543b03b13fd292c2183614 (diff)
allow fingerprint verification via context menu
Diffstat (limited to 'src/main/java/de/pixart/messenger/OmemoActivity.java')
-rw-r--r--src/main/java/de/pixart/messenger/OmemoActivity.java48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/OmemoActivity.java b/src/main/java/de/pixart/messenger/OmemoActivity.java
index 85e0498a7..5359e8a28 100644
--- a/src/main/java/de/pixart/messenger/OmemoActivity.java
+++ b/src/main/java/de/pixart/messenger/OmemoActivity.java
@@ -3,6 +3,7 @@ package de.pixart.messenger;
import android.app.AlertDialog;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
@@ -13,28 +14,51 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
+import com.google.zxing.integration.android.IntentIntegrator;
+import com.google.zxing.integration.android.IntentResult;
+
import java.security.cert.X509Certificate;
+import java.util.Arrays;
import de.pixart.messenger.crypto.axolotl.FingerprintStatus;
import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession;
import de.pixart.messenger.entities.Account;
+import de.pixart.messenger.ui.TrustKeysActivity;
import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.ui.widget.Switch;
import de.pixart.messenger.utils.CryptoHelper;
+import de.pixart.messenger.utils.XmppUri;
public abstract class OmemoActivity extends XmppActivity {
private Account mSelectedAccount;
private String mSelectedFingerprint;
+ protected XmppUri mPendingFingerprintVerificationUri = null;
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
Object account = v.getTag(R.id.TAG_ACCOUNT);
Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
- if (account != null && fingerprint != null && account instanceof Account && fingerprint instanceof String) {
+ Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
+ if (account != null
+ && fingerprint != null
+ && account instanceof Account
+ && fingerprintStatus != null
+ && fingerprint instanceof String
+ && fingerprintStatus instanceof FingerprintStatus) {
getMenuInflater().inflate(R.menu.omemo_key_context, menu);
- this.mSelectedAccount = (Account) account;
+ MenuItem purgeItem = menu.findItem(R.id.purge_omemo_key);
+ MenuItem verifyScan = menu.findItem(R.id.verify_scan);
+ if (this instanceof TrustKeysActivity) {
+ purgeItem.setVisible(false);
+ verifyScan.setVisible(false);
+ } else {
+ FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
+ if (!status.isActive() || status.isVerified()) {
+ verifyScan.setVisible(false);
+ }
+ } this.mSelectedAccount = (Account) account;
this.mSelectedFingerprint = (String) fingerprint;
}
}
@@ -48,10 +72,29 @@ public abstract class OmemoActivity extends XmppActivity {
case R.id.copy_omemo_key:
copyOmemoFingerprint(mSelectedFingerprint);
break;
+ case R.id.verify_scan:
+ new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC","QR_CODE"));
+ break;
}
return true;
}
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+ IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
+ if (scanResult != null && scanResult.getFormatName() != null) {
+ String data = scanResult.getContents();
+ XmppUri uri = new XmppUri(data);
+ if (xmppConnectionServiceBound) {
+ processFingerprintVerification(uri);
+ } else {
+ this.mPendingFingerprintVerificationUri =uri;
+ }
+ }
+ }
+
+ protected abstract void processFingerprintVerification(XmppUri uri);
+
protected void copyOmemoFingerprint(String fingerprint) {
if (copyTextToClipboard(CryptoHelper.prettifyFingerprint(fingerprint.substring(2)), R.string.omemo_fingerprint)) {
Toast.makeText(
@@ -107,6 +150,7 @@ public abstract class OmemoActivity extends XmppActivity {
registerForContextMenu(view);
view.setTag(R.id.TAG_ACCOUNT, account);
view.setTag(R.id.TAG_FINGERPRINT, fingerprint);
+ view.setTag(R.id.TAG_FINGERPRINT_STATUS, status);
boolean x509 = Config.X509_VERIFICATION && status.getTrust() == FingerprintStatus.Trust.VERIFIED_X509;
final View.OnClickListener toast;
trustToggle.setChecked(status.isTrusted(), false);