use of net.java.otr4j.crypto.OtrCryptoEngineImpl 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.OtrCryptoEngineImpl 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.OtrCryptoEngineImpl in project Zom-Android by zom.
the class SignatureMessage method verify.
public boolean verify(byte[] key) throws OtrException {
// Hash the key.
byte[] xbEncrypted;
try {
xbEncrypted = SerializationUtils.writeData(xEncrypted);
} catch (IOException e) {
throw new OtrException(e);
}
byte[] xEncryptedMAC = new OtrCryptoEngineImpl().sha256Hmac160(xbEncrypted, key);
// Verify signature.
return Arrays.equals(this.xEncryptedMAC, xEncryptedMAC);
}
use of net.java.otr4j.crypto.OtrCryptoEngineImpl in project Zom-Android by zom.
the class AuthContextImpl method h2.
private byte[] h2(byte b) throws OtrException {
byte[] secbytes;
try {
secbytes = SerializationUtils.writeMpi(getS());
} catch (IOException e) {
throw new OtrException(e);
}
int len = secbytes.length + 1;
ByteBuffer buff = ByteBuffer.allocate(len);
buff.put(b);
buff.put(secbytes);
byte[] sdata = buff.array();
return new OtrCryptoEngineImpl().sha256Hash(sdata);
}
use of net.java.otr4j.crypto.OtrCryptoEngineImpl 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);
}
Aggregations