mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-25 08:58:55 -05:00
partially improved logging for receiving omemo messages
This commit is contained in:
parent
aa7bfe9fe7
commit
8f39a594ff
@ -1136,7 +1136,12 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
|
||||
XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
|
||||
|
||||
XmppAxolotlSession session = getReceivingSession(message);
|
||||
keyTransportMessage = message.getParameters(session, getOwnDeviceId());
|
||||
try {
|
||||
keyTransportMessage = message.getParameters(session, getOwnDeviceId());
|
||||
} catch (CryptoFailedException e) {
|
||||
Log.d(Config.LOGTAG,"could not decrypt keyTransport message "+e.getMessage());
|
||||
keyTransportMessage = null;
|
||||
}
|
||||
|
||||
if (session.isFresh() && keyTransportMessage != null) {
|
||||
putFreshSession(session);
|
||||
|
@ -1,6 +1,11 @@
|
||||
package eu.siacs.conversations.crypto.axolotl;
|
||||
|
||||
public class CryptoFailedException extends Exception {
|
||||
|
||||
public CryptoFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CryptoFailedException(Exception e){
|
||||
super(e);
|
||||
}
|
||||
|
@ -250,16 +250,16 @@ public class XmppAxolotlMessage {
|
||||
return encryptionElement;
|
||||
}
|
||||
|
||||
private byte[] unpackKey(XmppAxolotlSession session, Integer sourceDeviceId) {
|
||||
private byte[] unpackKey(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||
XmppAxolotlSession.AxolotlKey encryptedKey = keys.get(sourceDeviceId);
|
||||
return (encryptedKey != null) ? session.processReceiving(encryptedKey) : null;
|
||||
if (encryptedKey == null) {
|
||||
throw new CryptoFailedException("Message was not encrypted for this device");
|
||||
}
|
||||
return session.processReceiving(encryptedKey);
|
||||
}
|
||||
|
||||
public XmppAxolotlKeyTransportMessage getParameters(XmppAxolotlSession session, Integer sourceDeviceId) {
|
||||
byte[] key = unpackKey(session, sourceDeviceId);
|
||||
return (key != null)
|
||||
? new XmppAxolotlKeyTransportMessage(session.getFingerprint(), key, getIV())
|
||||
: null;
|
||||
public XmppAxolotlKeyTransportMessage getParameters(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||
return new XmppAxolotlKeyTransportMessage(session.getFingerprint(), unpackKey(session, sourceDeviceId), getIV());
|
||||
}
|
||||
|
||||
public XmppAxolotlPlaintextMessage decrypt(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||
|
@ -82,7 +82,7 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public byte[] processReceiving(AxolotlKey encryptedKey) {
|
||||
public byte[] processReceiving(AxolotlKey encryptedKey) throws CryptoFailedException {
|
||||
byte[] plaintext = null;
|
||||
FingerprintStatus status = getTrust();
|
||||
if (!status.isCompromised()) {
|
||||
@ -90,8 +90,7 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
||||
try {
|
||||
PreKeyWhisperMessage message = new PreKeyWhisperMessage(encryptedKey.key);
|
||||
if (!message.getPreKeyId().isPresent()) {
|
||||
Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "PreKeyWhisperMessage did not contain a PreKeyId");
|
||||
return null;
|
||||
throw new CryptoFailedException("PreKeyWhisperMessage did not contain a PreKeyId");
|
||||
}
|
||||
Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "PreKeyWhisperMessage received, new session ID:" + message.getSignedPreKeyId() + "/" + message.getPreKeyId());
|
||||
IdentityKey msgIdentityKey = message.getIdentityKey();
|
||||
@ -107,19 +106,19 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
||||
WhisperMessage message = new WhisperMessage(encryptedKey.key);
|
||||
plaintext = cipher.decrypt(message);
|
||||
} catch (InvalidKeyException | InvalidKeyIdException | UntrustedIdentityException e) {
|
||||
Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Error decrypting axolotl header, " + e.getClass().getName() + ": " + e.getMessage());
|
||||
throw new CryptoFailedException("Error decrypting axolotl header, \" + e.getClass().getName() + \": \" + e.getMessage()");
|
||||
}
|
||||
} catch (LegacyMessageException | InvalidMessageException | DuplicateMessageException | NoSessionException e) {
|
||||
Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Error decrypting axolotl header, " + e.getClass().getName() + ": " + e.getMessage());
|
||||
throw new CryptoFailedException("Error decrypting axolotl header, \" + e.getClass().getName() + \": \" + e.getMessage()");
|
||||
}
|
||||
|
||||
if (plaintext != null) {
|
||||
if (!status.isActive()) {
|
||||
setTrust(status.toActive());
|
||||
}
|
||||
if (plaintext==null) {
|
||||
throw new CryptoFailedException("plaintext unexpectedly null");
|
||||
}
|
||||
if (!status.isActive()) {
|
||||
setTrust(status.toActive());
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG,account.getJid().toBareJid()+" not encrypting omemo message from fingerprint "+getFingerprint()+" because it was marked as compromised");
|
||||
throw new CryptoFailedException("not encrypting omemo message from fingerprint "+getFingerprint()+" because it was marked as compromised");
|
||||
}
|
||||
return plaintext;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user