diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-11-28 15:11:44 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-11-28 15:11:44 +0100 |
commit | 84a2fa0041c6d30658ba29b3b5f5db2604c35c90 (patch) | |
tree | fe9508196323d120b4c57e30831b8636637f1ed8 /src/main/java | |
parent | bbe01c9a6afd2bf312c1ad38c482c53be743949c (diff) |
allow fingerprint verification via context menu
Diffstat (limited to 'src/main/java')
4 files changed, 94 insertions, 20 deletions
diff --git a/src/main/java/eu/siacs/conversations/OmemoActivity.java b/src/main/java/eu/siacs/conversations/OmemoActivity.java index 5cda7e5f..c0c7b298 100644 --- a/src/main/java/eu/siacs/conversations/OmemoActivity.java +++ b/src/main/java/eu/siacs/conversations/OmemoActivity.java @@ -2,6 +2,7 @@ package eu.siacs.conversations; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; import android.view.ContextMenu; import android.view.MenuItem; @@ -12,14 +13,20 @@ 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 eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.ui.TrustKeysActivity; import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.widget.Switch; import eu.siacs.conversations.utils.CryptoHelper; +import eu.siacs.conversations.utils.XmppUri; public abstract class OmemoActivity extends XmppActivity { @@ -27,13 +34,32 @@ 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); + 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 +74,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( @@ -106,6 +151,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/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index b8313d9e..296a10c2 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -49,6 +49,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.XmppConnection; @@ -528,13 +529,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(); } } @@ -543,4 +547,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/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 14e3d929..008c563b 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -53,6 +53,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.XmppConnection; @@ -376,13 +377,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(); @@ -664,6 +676,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/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 45800854..1f7951e4 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -73,7 +73,6 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat finish(); } }; - private XmppUri mPendingFingerprintVerificationUri = null; private Toast mUseCameraHintToast = null; @Override @@ -138,21 +137,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() @@ -162,13 +155,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() { @@ -288,9 +284,10 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat if (this.mPendingFingerprintVerificationUri != null) { processFingerprintVerification(this.mPendingFingerprintVerificationUri); this.mPendingFingerprintVerificationUri = null; + } else { + reloadFingerprints(); + populateView(); } - reloadFingerprints(); - populateView(); } } |