use of net.java.otr4j.crypto.OtrCryptoException in project Conversations by siacs.
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;
}
use of net.java.otr4j.crypto.OtrCryptoException in project Spark by igniterealtime.
the class MyOtrKeyManager method getLocalFingerprint.
/**
* 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;
}
}
use of net.java.otr4j.crypto.OtrCryptoException in project Zom-Android by zom.
the class OtrAndroidKeyManagerImpl method savePublicKey.
public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
if (sessionID == null)
return;
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(pubKey.getEncoded());
// if (!Address.hasResource(sessionID.getRemoteUserId()))
// return;
String fullUserId = sessionID.getRemoteUserId();
this.store.setProperty(fullUserId + ".publicKey", x509EncodedKeySpec.getEncoded());
// and is useful for transferring rosters to other apps.
try {
String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
String verifiedToken = buildPublicKeyVerifiedId(sessionID.getRemoteUserId(), fingerprintString);
String fingerprintKey = fullUserId + ".fingerprint";
// if a fingerprint for this userid exists, then check if the key is verified
if (this.store.hasProperty(fingerprintKey)) {
if (!this.store.hasProperty(verifiedToken))
this.store.setProperty(verifiedToken, false);
} else {
// if there is no key, then we can "trust on first use"!
this.store.setProperty(fingerprintKey, fingerprintString);
this.store.setProperty(verifiedToken, true);
}
} catch (OtrCryptoException e) {
Log.e(ImApp.LOG_TAG, "otr error: " + e.getMessage(), e);
}
}
use of net.java.otr4j.crypto.OtrCryptoException in project xabber-android by redsolution.
the class OTRManager method sessionStatusChanged.
@Override
public void sessionStatusChanged(SessionID sessionID) {
removeSMRequest(sessionID.getAccountID(), sessionID.getUserID());
removeSMProgress(sessionID.getAccountID(), sessionID.getUserID());
Session session = sessions.get(sessionID.getAccountID(), sessionID.getUserID());
SessionStatus sStatus = session.getSessionStatus();
LogManager.i(this, "session status changed " + sessionID.getUserID() + " status: " + sStatus);
if (sStatus == SessionStatus.ENCRYPTED) {
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
PublicKey remotePublicKey = session.getRemotePublicKey();
String value;
try {
OtrCryptoEngine otrCryptoEngine = new OtrCryptoEngineImpl();
value = otrCryptoEngine.getFingerprint(remotePublicKey);
} catch (OtrCryptoException e) {
LogManager.exception(this, e);
value = null;
}
if (value != null) {
actives.put(sessionID.getAccountID(), sessionID.getUserID(), value);
if (fingerprints.get(sessionID.getAccountID(), sessionID.getUserID(), value) == null) {
fingerprints.put(sessionID.getAccountID(), sessionID.getUserID(), value, false);
requestToWrite(sessionID.getAccountID(), sessionID.getUserID(), value, false);
}
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, isVerified(sessionID.getAccountID(), sessionID.getUserID()) ? ChatAction.otr_verified : ChatAction.otr_encryption);
AbstractChat chat = getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.sendMessages();
}
} else if (sStatus == SessionStatus.PLAINTEXT) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
try {
session.endSession();
} catch (OtrException e) {
LogManager.exception(this, e);
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_plain);
} else if (sStatus == SessionStatus.FINISHED) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.put(sessionID.getAccountID(), sessionID.getUserID(), true);
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_finish);
// if session was finished then clear OTR-resource for this chat
RegularChat chat = (RegularChat) getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.setOTRresource(null);
}
} else {
throw new IllegalStateException();
}
onContactChanged(sessionID);
}
use of net.java.otr4j.crypto.OtrCryptoException in project Conversations by siacs.
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;
}
}
Aggregations