From bdda426ad4223773b5873ee20db22a22dff0e49b Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 29 Nov 2016 21:39:50 +0100 Subject: allow fingerprint verification via context menu --- .../java/de/pixart/messenger/OmemoActivity.java | 48 +++++++++++++++++++++- .../messenger/ui/ContactDetailsActivity.java | 24 ++++++++--- .../pixart/messenger/ui/EditAccountActivity.java | 18 +++++++- .../de/pixart/messenger/ui/TrustKeysActivity.java | 27 ++++++------ src/main/res/menu/omemo_key_context.xml | 4 ++ src/main/res/values/ids.xml | 5 ++- src/main/res/values/strings.xml | 1 + 7 files changed, 102 insertions(+), 25 deletions(-) (limited to 'src/main') 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); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index e974fb0a0..a97ffc321 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -27,6 +27,7 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.QuickContactBadge; import android.widget.TextView; +import android.widget.Toast; import com.wefika.flowlayout.FlowLayout; @@ -42,12 +43,12 @@ import de.pixart.messenger.crypto.axolotl.AxolotlService; import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; -import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.ListItem; import de.pixart.messenger.services.XmppConnectionService.OnAccountUpdate; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.UIHelper; +import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; @@ -57,7 +58,6 @@ import de.pixart.messenger.xmpp.jid.Jid; public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated { public static final String ACTION_VIEW_CONTACT = "view_contact"; - private Conversation mConversation; private Contact contact; private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() { @@ -541,13 +541,16 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } public void onBackendConnected() { - if ((accountJid != null) && (contactJid != null)) { - Account account = xmppConnectionService - .findAccountByJid(accountJid); + if (accountJid != null && contactJid != null) { + Account account = xmppConnectionService.findAccountByJid(accountJid); if (account == null) { return; } this.contact = account.getRoster().getContact(contactJid); + if (mPendingFingerprintVerificationUri != null) { + processFingerprintVerification(mPendingFingerprintVerificationUri); + mPendingFingerprintVerificationUri = null; + } populateView(); } } @@ -556,4 +559,15 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp public void onKeyStatusUpdated(AxolotlService.FetchStatus report) { refreshUi(); } + + @Override + protected void processFingerprintVerification(XmppUri uri) { + if (contact != null && contact.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { + if (xmppConnectionService.verifyFingerprints(contact,uri.getFingerprints())) { + Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show(); + } + } } diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 7e3417a6e..2617fd94c 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -53,6 +53,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnCaptchaRequested; import de.pixart.messenger.ui.adapter.KnownHostsAdapter; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.UIHelper; +import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xml.Element; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.XmppConnection; @@ -383,13 +384,24 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { + public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_BATTERY_OP || requestCode == REQUEST_DATA_SAVER) { updateAccountInformation(mAccount == null); } } + @Override + protected void processFingerprintVerification(XmppUri uri) { + if (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { + if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) { + Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show(); + } + } + protected void updateSaveButton() { boolean accountInfoEdited = accountInfoEdited(); @@ -671,6 +683,10 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mPassword.requestFocus(); } } + if (mPendingFingerprintVerificationUri != null) { + processFingerprintVerification(mPendingFingerprintVerificationUri); + mPendingFingerprintVerificationUri = null; + } updateAccountInformation(init); } diff --git a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java index 3564f7fc1..69e33fde9 100644 --- a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java +++ b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java @@ -16,7 +16,6 @@ import android.widget.TextView; import android.widget.Toast; import com.google.zxing.integration.android.IntentIntegrator; -import com.google.zxing.integration.android.IntentResult; import org.whispersystems.libaxolotl.IdentityKey; @@ -139,21 +138,15 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } @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); - populateView(); - } else { - this.mPendingFingerprintVerificationUri =uri; - } + protected void onStop() { + super.onStop(); + if (mUseCameraHintToast != null) { + mUseCameraHintToast.cancel(); } } - private void processFingerprintVerification(XmppUri uri) { + @Override + protected void processFingerprintVerification(XmppUri uri) { if (mConversation != null && mAccount != null && uri.hasFingerprints() @@ -163,13 +156,16 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat if (performedVerification && !keys && !hasNoOtherTrustedKeys() && !hasPendingKeyFetches()) { Toast.makeText(this,R.string.all_omemo_keys_have_been_verified, Toast.LENGTH_SHORT).show(); finishOk(); + return; } else if (performedVerification) { Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); } } else { + reloadFingerprints(); Log.d(Config.LOGTAG,"xmpp uri was: "+uri.getJid()+" has Fingerprints: "+Boolean.toString(uri.hasFingerprints())); Toast.makeText(this,R.string.barcode_does_not_contain_fingerprints_for_this_conversation,Toast.LENGTH_SHORT).show(); } + populateView(); } private void populateView() { @@ -289,9 +285,10 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat if (this.mPendingFingerprintVerificationUri != null) { processFingerprintVerification(this.mPendingFingerprintVerificationUri); this.mPendingFingerprintVerificationUri = null; + } else { + reloadFingerprints(); + populateView(); } - reloadFingerprints(); - populateView(); } } diff --git a/src/main/res/menu/omemo_key_context.xml b/src/main/res/menu/omemo_key_context.xml index f63a3439b..19f7d75e4 100644 --- a/src/main/res/menu/omemo_key_context.xml +++ b/src/main/res/menu/omemo_key_context.xml @@ -1,5 +1,9 @@ + diff --git a/src/main/res/values/ids.xml b/src/main/res/values/ids.xml index 78ccb5596..d1fd477b5 100644 --- a/src/main/res/values/ids.xml +++ b/src/main/res/values/ids.xml @@ -4,6 +4,7 @@ - - + + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 01f0dd1c2..7a1110b8f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -722,4 +722,5 @@ Blind Trust Before Verification Automatically trust all new devices from contacts that haven\'t been verified before. Untrusted + Invalid barcode -- cgit v1.2.3