diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-01-16 20:43:06 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-01-16 20:43:06 +0100 |
commit | 4b8c7dc6304db7cd90d23ab80d85c1d534684ef0 (patch) | |
tree | 401f9e79ce91cbd15a35f3ef7796cc6a786a38e6 /src/main/java/de/pixart | |
parent | dbbe76e6a0f5317b97dfa5f0ce31fcd9902463e3 (diff) |
partially improved logging for receiving omemo messages
Diffstat (limited to 'src/main/java/de/pixart')
4 files changed, 28 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java index b889418c1..76302141e 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java @@ -1133,7 +1133,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); diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/CryptoFailedException.java b/src/main/java/de/pixart/messenger/crypto/axolotl/CryptoFailedException.java index da847393b..e6f5e2a65 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/CryptoFailedException.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/CryptoFailedException.java @@ -1,6 +1,11 @@ package de.pixart.messenger.crypto.axolotl; public class CryptoFailedException extends Exception { + + public CryptoFailedException(String msg) { + super(msg); + } + public CryptoFailedException(Exception e) { super(e); } diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java index fa91ee122..a55e741bb 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java @@ -249,16 +249,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 { diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java index 6a314a760..84237d645 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlSession.java @@ -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,20 @@ 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; } |