use of net.java.otr4j.crypto.OtrCryptoEngineImpl in project Zom-Android by zom.
the class AuthContextImpl method handleSignatureMessage.
private void handleSignatureMessage(SignatureMessage m) throws OtrException {
Session session = getSession();
SessionID sessionID = session.getSessionID();
logger.finest(sessionID.getLocalUserId() + " received a signature message from " + sessionID.getRemoteUserId() + " throught " + sessionID.getProtocolName() + ".");
if (!session.getSessionPolicy().getAllowV2()) {
logger.finest("Policy does not allow OTRv2, ignoring message.");
return;
}
switch(this.getAuthenticationState()) {
case AWAITING_SIG:
// Verify MAC.
if (!m.verify(this.getM2p())) {
logger.finest("Signature MACs are not equal, ignoring message.");
return;
}
// Decrypt X.
byte[] remoteXDecrypted = m.decrypt(this.getCp());
SignatureX remoteX;
try {
remoteX = SerializationUtils.toMysteriousX(remoteXDecrypted);
} catch (IOException e) {
throw new OtrException(e);
}
// Compute signature.
PublicKey remoteLongTermPublicKey = remoteX.longTermPublicKey;
SignatureM remoteM = new SignatureM(this.getRemoteDHPublicKey(), (DHPublicKey) this.getLocalDHKeyPair().getPublic(), remoteLongTermPublicKey, remoteX.dhKeyID);
OtrCryptoEngine otrCryptoEngine = new OtrCryptoEngineImpl();
// Verify signature.
byte[] signature;
try {
signature = otrCryptoEngine.sha256Hmac(SerializationUtils.toByteArray(remoteM), this.getM1p());
} catch (IOException e) {
throw new OtrException(e);
}
if (!otrCryptoEngine.verify(signature, remoteLongTermPublicKey, remoteX.signature)) {
session.showWarning("Bad signature");
logger.finest("Signature verification failed.");
return;
}
this.setIsSecure(true);
this.setRemoteLongTermPublicKey(remoteLongTermPublicKey);
break;
default:
logger.finest("We were not expecting a signature, ignoring message.");
return;
}
}
use of net.java.otr4j.crypto.OtrCryptoEngineImpl 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;
}
}
use of net.java.otr4j.crypto.OtrCryptoEngineImpl 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);
}
}
use of net.java.otr4j.crypto.OtrCryptoEngineImpl 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;
}
}
Aggregations