From b945962edec63170e9f343e96df5387f3d544740 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 24 Nov 2016 20:54:03 +0100 Subject: offer verification directly from the trust keys screen --- .../messenger/services/XmppConnectionService.java | 8 ++- .../de/pixart/messenger/ui/TrustKeysActivity.java | 73 +++++++++++++++++++++ .../drawable-hdpi/ic_barcode_scan_white_24dp.png | Bin 0 -> 272 bytes .../drawable-mdpi/ic_barcode_scan_white_24dp.png | Bin 0 -> 238 bytes .../drawable-xhdpi/ic_barcode_scan_white_24dp.png | Bin 0 -> 320 bytes .../drawable-xxhdpi/ic_barcode_scan_white_24dp.png | Bin 0 -> 470 bytes .../ic_barcode_scan_white_24dp.png | Bin 0 -> 600 bytes src/main/res/menu/trust_keys.xml | 9 +++ src/main/res/values-v21/themes.xml | 1 + src/main/res/values/attrs.xml | 1 + src/main/res/values/strings.xml | 4 ++ src/main/res/values/themes.xml | 2 +- 12 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_barcode_scan_white_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_barcode_scan_white_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_barcode_scan_white_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_barcode_scan_white_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_barcode_scan_white_24dp.png create mode 100644 src/main/res/menu/trust_keys.xml (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 50701c8bc..f2eacda56 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3771,17 +3771,20 @@ public class XmppConnectionService extends Service { }); } - public void verifyFingerprints(Contact contact, List fingerprints) { + public boolean verifyFingerprints(Contact contact, List fingerprints) { boolean needsRosterWrite = false; + boolean performedVerification = false; final AxolotlService axolotlService = contact.getAccount().getAxolotlService(); for (XmppUri.Fingerprint fp : fingerprints) { if (fp.type == XmppUri.FingerprintType.OTR) { - needsRosterWrite |= contact.addOtrFingerprint(fp.fingerprint); + performedVerification |= contact.addOtrFingerprint(fp.fingerprint); + needsRosterWrite |= performedVerification; } else if (fp.type == XmppUri.FingerprintType.OMEMO) { String fingerprint = "05" + fp.fingerprint.replaceAll("\\s", ""); FingerprintStatus fingerprintStatus = axolotlService.getFingerprintTrust(fingerprint); if (fingerprintStatus != null) { if (!fingerprintStatus.isVerified()) { + performedVerification = true; axolotlService.setFingerprintTrust(fingerprint, fingerprintStatus.toVerified()); } } else { @@ -3792,6 +3795,7 @@ public class XmppConnectionService extends Service { if (needsRosterWrite) { syncRosterToDisk(contact.getAccount()); } + return performedVerification; } public boolean verifyFingerprints(Account account, List fingerprints) { diff --git a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java index 893317970..fd3e9f421 100644 --- a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java +++ b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java @@ -1,7 +1,12 @@ package de.pixart.messenger.ui; +import android.app.ActionBar; import android.content.Intent; import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -10,6 +15,9 @@ 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 org.whispersystems.libaxolotl.IdentityKey; import java.util.ArrayList; @@ -25,6 +33,7 @@ import de.pixart.messenger.crypto.axolotl.AxolotlService; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; @@ -64,6 +73,8 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } }; + private XmppUri mPendingFingerprintVerificationUri = null; + @Override protected void refreshUiReal() { invalidateOptionsMenu(); @@ -101,6 +112,64 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.trust_keys, menu); + Toast toast = Toast.makeText(this,R.string.use_camera_icon_to_scan_barcode,Toast.LENGTH_LONG); + ActionBar actionBar = getActionBar(); + toast.setGravity(Gravity.TOP | Gravity.END, 0 ,actionBar == null ? 0 : actionBar.getHeight()); + toast.show(); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_scan_qr_code: + if (hasPendingKeyFetches()) { + Toast.makeText(this, R.string.please_wait_for_keys_to_be_fetched, Toast.LENGTH_SHORT).show(); + } else { + new IntentIntegrator(this).initiateScan(); + return true; + } + } + return super.onOptionsItemSelected(item); + } + + @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; + } + } + } + + private void processFingerprintVerification(XmppUri uri) { + if (mConversation != null + && mAccount != null + && uri.hasFingerprints() + && mAccount.getAxolotlService().getCryptoTargets(mConversation).contains(uri.getJid())) { + boolean performedVerification = xmppConnectionService.verifyFingerprints(mAccount.getRoster().getContact(uri.getJid()),uri.getFingerprints()); + boolean keys = reloadFingerprints(); + if (performedVerification && !keys && !hasNoOtherTrustedKeys() && !hasPendingKeyFetches()) { + Toast.makeText(this,R.string.all_omemo_keys_have_been_verified, Toast.LENGTH_SHORT).show(); + finishOk(); + } else if (performedVerification) { + Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); + } + } else { + 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(); + } + } + private void populateView() { setTitle(getString(R.string.trust_omemo_fingerprints)); ownKeys.removeAllViews(); @@ -215,6 +284,10 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat if (this.mAccount != null && intent != null) { String uuid = intent.getStringExtra("conversation"); this.mConversation = xmppConnectionService.findConversationByUuid(uuid); + if (this.mPendingFingerprintVerificationUri != null) { + processFingerprintVerification(this.mPendingFingerprintVerificationUri); + this.mPendingFingerprintVerificationUri = null; + } reloadFingerprints(); populateView(); } diff --git a/src/main/res/drawable-hdpi/ic_barcode_scan_white_24dp.png b/src/main/res/drawable-hdpi/ic_barcode_scan_white_24dp.png new file mode 100644 index 000000000..705f40296 Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_barcode_scan_white_24dp.png differ diff --git a/src/main/res/drawable-mdpi/ic_barcode_scan_white_24dp.png b/src/main/res/drawable-mdpi/ic_barcode_scan_white_24dp.png new file mode 100644 index 000000000..b952be675 Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_barcode_scan_white_24dp.png differ diff --git a/src/main/res/drawable-xhdpi/ic_barcode_scan_white_24dp.png b/src/main/res/drawable-xhdpi/ic_barcode_scan_white_24dp.png new file mode 100644 index 000000000..f0d2b0e59 Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_barcode_scan_white_24dp.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_barcode_scan_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_barcode_scan_white_24dp.png new file mode 100644 index 000000000..cd8375f5b Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_barcode_scan_white_24dp.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_barcode_scan_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_barcode_scan_white_24dp.png new file mode 100644 index 000000000..f8b6f3f3b Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_barcode_scan_white_24dp.png differ diff --git a/src/main/res/menu/trust_keys.xml b/src/main/res/menu/trust_keys.xml new file mode 100644 index 000000000..7c63bd7fe --- /dev/null +++ b/src/main/res/menu/trust_keys.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/src/main/res/values-v21/themes.xml b/src/main/res/values-v21/themes.xml index b686c5f6d..80e140f0c 100644 --- a/src/main/res/values-v21/themes.xml +++ b/src/main/res/values-v21/themes.xml @@ -37,6 +37,7 @@ @drawable/ic_settings_grey600_24dp @drawable/ic_import_export_white_24dp @drawable/ic_share_white_24dp + @drawable/ic_barcode_scan_white_24dp diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index 309c1fb30..da88d1f44 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -26,6 +26,7 @@ + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6415acaab..1d33ecffd 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -711,4 +711,8 @@ This device has been verified Copy fingerprint All OMEMO keys have been verified + Barcode does not contain fingerprints for this conversation. + Verified fingerprints + Use the camera to scan a contacts barcode + Please wait for keys to be fetched diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 071d26d3c..61a2d2bb1 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -32,7 +32,7 @@ @drawable/ic_settings_grey600_24dp @drawable/ic_import_export_white_24dp @drawable/ic_share_white_24dp - + @drawable/ic_barcode_scan_white_24dp 16dp 16dp -- cgit v1.2.3