From 88c3537b6869996098da25954985fcb0c6971635 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 16 Nov 2014 00:20:20 +0100 Subject: parse otr-fingerprint in qr codes and nfc. include otr fingerprint in shareable uri where ever possible --- .../eu/siacs/conversations/entities/Account.java | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'src/main/java/eu/siacs/conversations/entities/Account.java') diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 10f2940c..1d0a025f 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -280,10 +280,11 @@ public class Account extends AbstractEntity { return values; } - public OtrEngine getOtrEngine(XmppConnectionService context) { - if (otrEngine == null) { - otrEngine = new OtrEngine(context, this); - } + public void initOtrEngine(XmppConnectionService context) { + this.otrEngine = new OtrEngine(context, this); + } + + public OtrEngine getOtrEngine() { return this.otrEngine; } @@ -298,23 +299,21 @@ public class Account extends AbstractEntity { public String getOtrFingerprint() { if (this.otrFingerprint == null) { try { - DSAPublicKey pubkey = (DSAPublicKey) this.otrEngine - .getPublicKey(); - if (pubkey == null) { + if (this.otrEngine == null) { return null; } - StringBuilder builder = new StringBuilder( - new OtrCryptoEngineImpl().getFingerprint(pubkey)); - builder.insert(8, " "); - builder.insert(17, " "); - builder.insert(26, " "); - builder.insert(35, " "); - this.otrFingerprint = builder.toString(); + DSAPublicKey publicKey = (DSAPublicKey) this.otrEngine.getPublicKey(); + if (publicKey == null) { + return null; + } + this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey); + return this.otrFingerprint; } catch (final OtrCryptoException ignored) { - + return null; } + } else { + return this.otrFingerprint; } - return this.otrFingerprint; } public String getRosterVersion() { @@ -329,11 +328,6 @@ public class Account extends AbstractEntity { this.rosterVersion = version; } - public String getOtrFingerprint(XmppConnectionService service) { - this.getOtrEngine(service); - return this.getOtrFingerprint(); - } - public void updatePresence(String resource, int status) { this.presences.updatePresence(resource, status); } @@ -411,4 +405,13 @@ public class Account extends AbstractEntity { public boolean inGracePeriod() { return SystemClock.elapsedRealtime() < this.mEndGracePeriod; } + + public String getShareableUri() { + String fingerprint = this.getOtrFingerprint(); + if (fingerprint != null) { + return "xmpp:" + this.getJid().toBareJid().toString() + "?otr-fingerprint="+fingerprint; + } else { + return "xmpp:" + this.getJid().toBareJid().toString(); + } + } } -- cgit v1.2.3