public void savePublicKey(SessionID sessionID, PublicKey pubKey) { if (sessionID == null) return; X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(pubKey.getEncoded()); // if (!Address.hasResource(fullUserId)) // return; this.store.setProperty( sessionID.getRemoteUserId() + ".publicKey", x509EncodedKeySpec.getEncoded()); // Stash the associated fingerprint. This saves calculating it in the future // and is useful for transferring rosters to other apps. try { String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey); String verifiedToken = buildPublicKeyVerifiedId(sessionID.getRemoteUserId(), fingerprintString.toLowerCase()); if (!this.store.hasProperty(verifiedToken)) this.store.setProperty(verifiedToken, false); this.store.setPropertyHex( sessionID.getRemoteUserId() + ".fingerprint", Hex.decode(fingerprintString)); store.save(); } catch (OtrCryptoException e) { e.printStackTrace(); } }
/** * Return remote finger print for specified sessionID. * * @return finger print for remote contact */ public String getRemoteFingerprint(SessionID sessionID) { PublicKey remotePublicKey = loadRemotePublicKey(sessionID); if (remotePublicKey == null) return null; try { return new OtrCryptoEngineImpl().getFingerprint(remotePublicKey); } catch (OtrCryptoException e) { e.printStackTrace(); return null; } }
/** * Returns the local finger print for specified session. If there is no finger print you might * generate one. * * @return the local finger print for this sessionID */ public String getLocalFingerprint(SessionID sessionID) { KeyPair keyPair = loadLocalKeyPair(sessionID); if (keyPair == null) return null; PublicKey pubKey = keyPair.getPublic(); try { return new OtrCryptoEngineImpl().getFingerprint(pubKey); } catch (OtrCryptoException e) { e.printStackTrace(); return null; } }
private void storeLocalPublicKey(String fullUserId, PublicKey pubKey) { String userId = Address.stripResource(fullUserId); X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(pubKey.getEncoded()); this.store.setProperty(userId + ".publicKey", x509EncodedKeySpec.getEncoded()); // Stash fingerprint for consistency. try { String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey); this.store.setPropertyHex(userId + ".fingerprint", Hex.decode(fingerprintString)); } catch (OtrCryptoException e) { e.printStackTrace(); } store.save(); }
public String getLocalFingerprint(String fullUserId) { String userId = Address.stripResource(fullUserId); KeyPair keyPair = loadLocalKeyPair(userId); if (keyPair == null) return null; PublicKey pubKey = keyPair.getPublic(); try { String fingerprint = cryptoEngine.getFingerprint(pubKey); OtrDebugLogger.log("got fingerprint for: " + userId + "=" + fingerprint); return fingerprint; } catch (OtrCryptoException e) { e.printStackTrace(); return null; } }