Search in sources :

Example 6 with OtrCryptoException

use of net.java.otr4j.crypto.OtrCryptoException in project Zom-Android by zom.

the class OtrKeyManagerDefaultImpl method getLocalFingerprint.

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;
    }
}
Also used : KeyPair(java.security.KeyPair) OtrCryptoException(net.java.otr4j.crypto.OtrCryptoException) PublicKey(java.security.PublicKey) OtrCryptoEngineImpl(net.java.otr4j.crypto.OtrCryptoEngineImpl)

Example 7 with OtrCryptoException

use of net.java.otr4j.crypto.OtrCryptoException in project Zom-Android by zom.

the class OtrAndroidKeyManagerImpl method getRemoteFingerprint.

public String getRemoteFingerprint(String fullUserId) {
    String fingerprint = this.store.getProperty(fullUserId + ".fingerprint");
    if (fingerprint != null) {
        // If we have a fingerprint stashed, assume it is correct.
        return fingerprint;
    }
    // if we can't find an exact match, let's show the first one that matches the id sans resource
    for (Object fpKey : store.getKeySet().toArray()) {
        String fpKeyString = (String) fpKey;
        if (fpKeyString.startsWith(fullUserId) && fpKeyString.endsWith(".fingerprint")) {
            fingerprint = store.getProperty(fpKeyString);
            if (fingerprint != null)
                return fingerprint;
        }
    }
    PublicKey remotePublicKey = loadRemotePublicKeyFromStore(fullUserId);
    if (remotePublicKey == null)
        return null;
    try {
        // Store the fingerprint, for posterity.
        String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(remotePublicKey);
        this.store.setProperty(fullUserId + ".fingerprint", fingerprintString);
        return fingerprintString;
    } catch (OtrCryptoException e) {
        throw new RuntimeException("OtrCryptoException getting remote fingerprint", e);
    }
}
Also used : OtrCryptoException(net.java.otr4j.crypto.OtrCryptoException) PublicKey(java.security.PublicKey) OtrCryptoEngineImpl(net.java.otr4j.crypto.OtrCryptoEngineImpl)

Example 8 with OtrCryptoException

use of net.java.otr4j.crypto.OtrCryptoException in project Pix-Art-Messenger by kriztan.

the class Account method getOtrFingerprint.

public String getOtrFingerprint() {
    if (this.otrFingerprint == null) {
        try {
            if (this.mOtrService == null) {
                return null;
            }
            final PublicKey publicKey = this.mOtrService.getPublicKey();
            if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
                return null;
            }
            this.otrFingerprint = new OtrCryptoEngineImpl().getFingerprint(publicKey).toLowerCase(Locale.US);
            return this.otrFingerprint;
        } catch (final OtrCryptoException ignored) {
            return null;
        }
    } else {
        return this.otrFingerprint;
    }
}
Also used : OtrCryptoException(net.java.otr4j.crypto.OtrCryptoException) PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) OtrCryptoEngineImpl(net.java.otr4j.crypto.OtrCryptoEngineImpl) DSAPublicKey(java.security.interfaces.DSAPublicKey)

Example 9 with OtrCryptoException

use of net.java.otr4j.crypto.OtrCryptoException in project Pix-Art-Messenger by kriztan.

the class Conversation method getOtrFingerprint.

public synchronized String getOtrFingerprint() {
    if (this.otrFingerprint == null) {
        try {
            if (getOtrSession() == null || getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) {
                return null;
            }
            DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession().getRemotePublicKey();
            this.otrFingerprint = getAccount().getOtrService().getFingerprint(remotePubKey).toLowerCase(Locale.US);
        } catch (final OtrCryptoException | UnsupportedOperationException ignored) {
            return null;
        }
    }
    return this.otrFingerprint;
}
Also used : OtrCryptoException(net.java.otr4j.crypto.OtrCryptoException) DSAPublicKey(java.security.interfaces.DSAPublicKey)

Aggregations

OtrCryptoException (net.java.otr4j.crypto.OtrCryptoException)9 OtrCryptoEngineImpl (net.java.otr4j.crypto.OtrCryptoEngineImpl)7 PublicKey (java.security.PublicKey)6 DSAPublicKey (java.security.interfaces.DSAPublicKey)4 KeyPair (java.security.KeyPair)2 AbstractChat (com.xabber.android.data.message.AbstractChat)1 RegularChat (com.xabber.android.data.message.RegularChat)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1 OtrException (net.java.otr4j.OtrException)1 OtrCryptoEngine (net.java.otr4j.crypto.OtrCryptoEngine)1 Session (net.java.otr4j.session.Session)1 SessionStatus (net.java.otr4j.session.SessionStatus)1