From d76b0a3104f0bf259472c54d253fc214c3238765 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 22 Nov 2016 12:03:21 +0100 Subject: [PATCH] offer verification directly from the trust keys screen --- .../services/XmppConnectionService.java | 8 +- .../conversations/ui/TrustKeysActivity.java | 73 +++++++++++++++++- .../res/drawable-hdpi/ic_action_camera.png | Bin 0 -> 601 bytes .../ic_camera_alt_white_24dp.png | Bin 0 -> 364 bytes .../res/drawable-mdpi/ic_action_camera.png | Bin 0 -> 420 bytes .../ic_camera_alt_white_24dp.png | Bin 0 -> 240 bytes .../res/drawable-xhdpi/ic_action_camera.png | Bin 0 -> 760 bytes .../ic_camera_alt_white_24dp.png | Bin 0 -> 446 bytes .../res/drawable-xxhdpi/ic_action_camera.png | Bin 0 -> 1015 bytes .../ic_camera_alt_white_24dp.png | Bin 0 -> 666 bytes .../ic_camera_alt_white_24dp.png | Bin 0 -> 894 bytes src/main/res/menu/trust_keys.xml | 9 +++ src/main/res/values-v21/themes.xml | 2 + src/main/res/values/attrs.xml | 1 + src/main/res/values/strings.xml | 4 + src/main/res/values/themes.xml | 2 + 16 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_action_camera.png create mode 100644 src/main/res/drawable-hdpi/ic_camera_alt_white_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_action_camera.png create mode 100644 src/main/res/drawable-mdpi/ic_camera_alt_white_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_action_camera.png create mode 100644 src/main/res/drawable-xhdpi/ic_camera_alt_white_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_action_camera.png create mode 100644 src/main/res/drawable-xxhdpi/ic_camera_alt_white_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_camera_alt_white_24dp.png create mode 100644 src/main/res/menu/trust_keys.xml diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index c8a19019..c69dd2db 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3617,17 +3617,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 { @@ -3638,6 +3641,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/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 26836395..9af0d075 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -1,7 +1,12 @@ package eu.siacs.conversations.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; @@ -23,9 +31,9 @@ import eu.siacs.conversations.OmemoActivity; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; -import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; @@ -64,6 +72,7 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat finish(); } }; + private XmppUri mPendingFingerprintVerificationUri = null; @Override protected void refreshUiReal() { @@ -102,6 +111,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(); @@ -216,6 +283,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_action_camera.png b/src/main/res/drawable-hdpi/ic_action_camera.png new file mode 100644 index 0000000000000000000000000000000000000000..60f9f100b211e645299a232aab2ec85eecf0e39a GIT binary patch literal 601 zcmV-f0;c_mP)c74A2aa0jOP>%0eMc=#%4a7 zxXcBB01yBIKmZ7UDa*B~gYrCI!mwz#{OCB&&maJ*3V!VLZ{~wSw;f%;UXyqG%w9o37c+1clz1 z@!OiqigR09`@h#FfP~dFj}0%qTfEt6Z(~&8l<>ime?=T+lnwr-rbqEkju(2=D0Oa%oSF>rrE%8oQtMYbH`Mq5 zaIqsZSx$%808u4cWw=jGQfTU-CL>U8{xeo4c$9LLjh?ve<@Wk&Bm1JzD8CCuGm(Bp nKCcS^0U!VbfB=}Z{0cAtSoN!DR&gMq00000NkvXXu0mjfZr%f2 literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-hdpi/ic_camera_alt_white_24dp.png b/src/main/res/drawable-hdpi/ic_camera_alt_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..497c88ca82b139d8523f62d272569b97777cdec7 GIT binary patch literal 364 zcmV-y0h9iTP)S{uX;NkkS)#&21u+#OWT?<*8xnfup2(UyYu`|TWayHRle3^B=LUseC>Hz3 z2?03L6F2Y)Y1vJelVK0EWmn2Ql$Ly?Q}HYJ&`ey8O(uTi9vWT@jom{_aSLoF;#2pK zl4W-|8up!*EPLl3g1*=uhfkRYaWVLWw$#P9nUaw)p(W=g$}a?K8bsDKc?-L=1LM-h zsPJb*v0}uSlpQ7f(8IPT6#ZR~|J)2!gMLSvx$!&t+WdOxKlA~ZoD~H=l;~Ih0000< KMNUMnLSTYiKb+YB literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_action_camera.png b/src/main/res/drawable-mdpi/ic_action_camera.png new file mode 100644 index 0000000000000000000000000000000000000000..75d6b8c20e1bffb7a2ed39575868b3ee788e910d GIT binary patch literal 420 zcmV;V0bBlwP)jlX11>@}q@{x%UTwi*ad+Uhl|=PlTJRgFe`x!@f8x)0EvnjklGX^+d5E6&J##!u9jP{ zCAiZHkAXPXi!ebT=lL4K1x)6Wg_MY91 zzt7rrmFO;X_oUmq$FIPH+E8b!7Su|rTTt3JU}I)<+1$1SJPXOxL=vhYuo3Q@z)==< z{b1(CNz*~H=m#TH*Ja}&F!>pnOOBdeCCh%W6|%$U`K_?;2UJ3mWl4Bp2(Ys-zHDi) q+wWiFtfaRVtkebP_bn*je*_=o)*|^)1w=Uj0000j*L%^~Of_*a@57-uZPy5pn1PX;h zp-?Ck3WY+Ucs|rz|G?pJXu+jd@byitR!dy2uW==r5H9A#?GzTf&-uOyV_0x~F^u~W z05FEpKC{?&-&~+x(mc5H8y{mp!;$L@7ZLrKE z4m;fz#AERpvkVqiA1>pLO9A#kVwMw3hve%<+{@xal-2(zoNE#44t;(i2x12Lq=1^| z+lKCa(z8dGpt(|?1o+~oI3hH?FsR`(Qz1e^LDUNYQodL+`%!^;M)dAcR2Np@LV%qJ zdc%V0%<$TS=G^%pz?SX4v1o<_6fCc3t z&-bAygUg(|?SlohN)}*$V(z;Ype<6@*5)iBQmPjgAk$uCF;^r~YR3lwj3{H#gy#k3 znTtO~ob(4=Wq}dxSSG^yN)hI~qsy8k-W-Mu9ex5K!r-5nfcFMD?d(P1s5|7cAJB!J zoAI6ixx<8ZG-N?7rv5=*<75`NX}MR@5$XYf7c%KoWQX`%ZBHUCT#~P<670fQ@xXXN z!Gq7PT$8WD0%Vf|`vMzg@(Jr1WG>MQD(D7REdUoHYk4E_$2$u={b9&ATS3bFt5nS?tU*5U+ zuRv$a3fXL!qPq!nmZ-`S-6wEv!Im}!G@?dn#;*=rm4ZHT$3Hy5 zK#ky=d(UOmFsQV^o<2gJx=}eIwnA3W7xau83lN!8vECcV2)4w<^v@2~67MD11sAjh ztGUt}LA${P1=0J3E1eNGc`3L+Gf5t=WKEt5E{OV^X;qWQ4p$&rl*20-lc(iB^4yia zijQ0lF6anWaiv8;dol|xA!y6No&?ck78<-*{Fa&B9E#TSq3mYYuttQ*QZ*_=*n0M$ zV!JjJ9`z`_U5gAzIwsc`sys4xbSaS{W>lIoJ$6TM=qna%_I>f1qB5iXUVh&=cfY<* oSSx7G$evyZ)YnOH5*(G_7e~OF#v^w+0000007*qoM6N<$g3E)#tN;K2 literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_action_camera.png b/src/main/res/drawable-xxhdpi/ic_action_camera.png new file mode 100644 index 0000000000000000000000000000000000000000..e7b9910235d905d19e0493589df65e19e6991785 GIT binary patch literal 1015 zcmV+`7}iUPHE@& zR50n7OgepA5`zVp`|2irEk&%zh>4Bzv7F;sQe_Bmg`Z#8u9)&0A*u2LE~wo2lk?7; zAp>K#(kr+XKIVAoSdJrfEPtFqfbT5I3@AoVq-Px&_F)m9`$jUnC&wMBsFFgc$HqNnDk5_BMCs^(@3j&S5H_yh8wbN=uBtRF4hL z^RY{l2$G%#ExOzw;c?C&S0 zDUEW?+NUl0GAm+C207?zGV{a?%Gl8Wn@`f%gE2#}B4PRi!wN7VwWRbrGK?W?d9PgkS?7?<{}Vm}$|v7@!ludTJ==T>E5v9|g!o znDUZR8&yg^hb&K>dU&s1uMc29zmX}1>stp+3Uf(^9^YdlR>Y|7T5p)002ovPDHLkV1oLPx-$R( literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_camera_alt_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_camera_alt_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..c8e69dcebb98d43695027fcc7e39a339c84dda51 GIT binary patch literal 666 zcmV;L0%iS)P)y zDuP#FBS9M!QcYr?x(Xj5^OKhEOrZ0;%Xt?M^PS1$oUvkJVg?bG2*VOq|FP&lUkJx< zKARBwK%20%c&{z=j$iacgSVPOZ>ZBRKY6Vs^pYxn!v)X(MaU+{KDTId#}NxSK|*6x zFv$sHenK`COmmFwEtDe)3f@BdM8ToA&@EBW@D_@SSjd>rJ=jul4hPAn$ZYd zQ(^?GM-r@1H!ZY@i{+CPWphGpzG8()mbM9@HXpGBsG>9Ms~`YLf6Qp{EBmWamEC4dDr!XN=Tg=UR*LRnyXqu_l$^Po#V$T zj`&?_>IiL%W{Dt*qP?plloe0b6+u)P>h$wELg`L#hA>QZ`WYP|H+WzkLrdxi*`3}7 zVOSR<9(Dx^Vxd?l7V1BL0REY1s|}3R@&Et;07*qoM6N<$f_%9k Avj6}9 literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/ic_camera_alt_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_camera_alt_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..777658e95515ca47c9852d00621e2e6d45abc5c7 GIT binary patch literal 894 zcmV-^1A+XBP)zI9LJx5Cecy~F=}h8lwKtS@9n)MRxm2`AkqpItJs@p>)C(tu-V-#=CId=UD(s^ z#Zy@d`v;fOn~Tzu?OJHHNtIePI-lk`KN@Bx3G-g)`+Uz|m=FBkykXu`7K_DVu`~_~ z1Z4r$j3}CsFA0vr7p4ddb45K=_{;=>kNJmsIpZVU0%^)LLWz`4fe-nOMmgjIT>|g$ zGtFS1ZXE(|^ApYDN8W0_z#v8Txj;7;?6E~Um_R#sF$;$xalZoX{D6r(A?{D$E~c{O zM_>?haY%a$6fv1Q-U9oW%qwq!3ryzRTflV87q9|W;F{;GFv0){qSYiAAj>K*xHezl zfJJ&yHS#`7{A#YiA58NG$|F%`I5JV-9to7sbaLM;flIzZ1Lw!X3#^Fu{wYByi=R|$;R}qoTB8JI$kiVUUtqx1 zx=B!Su6`5*yii_yR9b4GhtSXus6)G54OU*Fzb<9Fuf)`*nQG!IEfB;+M}w za~X69{6e&@G0KTnj6*#FFeADVZuofoh-l4&E`cLDWuFO3wP#-rPc_|?^a;Rylnh;L z@)wd48zfOOJOnKQa*Rac43Xn8&v?osa%9ANUyhGPfeM+%FRSSkfU`OkhV}j2l~kBT z1bVSYwP7Nn+I` zNiohkFLCTaw-vAgjq*RZ@U(}??0O4qVKTS91=2W}ibKjn!0?Ng1(Y9wI8QK + + + + \ 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 d6612552..aa5e825b 100644 --- a/src/main/res/values-v21/themes.xml +++ b/src/main/res/values-v21/themes.xml @@ -60,6 +60,7 @@ @drawable/ic_settings_black_24dp @drawable/ic_import_export_white_24dp @drawable/ic_share_white_24dp + @drawable/ic_camera_alt_white_24dp @drawable/ic_notifications_black54_24dp @drawable/ic_notifications_off_black54_24dp @@ -126,6 +127,7 @@ @drawable/ic_settings_white_24dp @drawable/ic_import_export_white_24dp @drawable/ic_share_white_24dp + @drawable/ic_camera_alt_white_24dp @drawable/ic_notifications_white_24dp @drawable/ic_notifications_off_white_24dp diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index 82f9db89..7b7d2c5a 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -47,6 +47,7 @@ + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 416ee252..591d3dbc 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -703,4 +703,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 f15822c9..69d4d39f 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -57,6 +57,7 @@ @drawable/ic_action_settings @drawable/ic_stat_communication_import_export @drawable/ic_action_share + @drawable/ic_action_camera @drawable/ic_notifications_black54_24dp @drawable/ic_notifications_off_black54_24dp @@ -120,6 +121,7 @@ @drawable/ic_action_settings_white @drawable/ic_stat_communication_import_export @drawable/ic_action_share + @drawable/ic_action_camera @drawable/ic_notifications_white80 @drawable/ic_notifications_off_white80