mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-26 09:19:07 -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;
|
XmppAxolotlMessage.XmppAxolotlKeyTransportMessage keyTransportMessage;
|
||||||
|
|
||||||
XmppAxolotlSession session = getReceivingSession(message);
|
XmppAxolotlSession session = getReceivingSession(message);
|
||||||
|
try {
|
||||||
keyTransportMessage = message.getParameters(session, getOwnDeviceId());
|
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) {
|
if (session.isFresh() && keyTransportMessage != null) {
|
||||||
putFreshSession(session);
|
putFreshSession(session);
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package eu.siacs.conversations.crypto.axolotl;
|
package eu.siacs.conversations.crypto.axolotl;
|
||||||
|
|
||||||
public class CryptoFailedException extends Exception {
|
public class CryptoFailedException extends Exception {
|
||||||
|
|
||||||
|
public CryptoFailedException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public CryptoFailedException(Exception e){
|
public CryptoFailedException(Exception e){
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
@ -250,16 +250,16 @@ public class XmppAxolotlMessage {
|
|||||||
return encryptionElement;
|
return encryptionElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] unpackKey(XmppAxolotlSession session, Integer sourceDeviceId) {
|
private byte[] unpackKey(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||||
XmppAxolotlSession.AxolotlKey encryptedKey = keys.get(sourceDeviceId);
|
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) {
|
public XmppAxolotlKeyTransportMessage getParameters(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||||
byte[] key = unpackKey(session, sourceDeviceId);
|
return new XmppAxolotlKeyTransportMessage(session.getFingerprint(), unpackKey(session, sourceDeviceId), getIV());
|
||||||
return (key != null)
|
|
||||||
? new XmppAxolotlKeyTransportMessage(session.getFingerprint(), key, getIV())
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmppAxolotlPlaintextMessage decrypt(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
public XmppAxolotlPlaintextMessage decrypt(XmppAxolotlSession session, Integer sourceDeviceId) throws CryptoFailedException {
|
||||||
|
@ -82,7 +82,7 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public byte[] processReceiving(AxolotlKey encryptedKey) {
|
public byte[] processReceiving(AxolotlKey encryptedKey) throws CryptoFailedException {
|
||||||
byte[] plaintext = null;
|
byte[] plaintext = null;
|
||||||
FingerprintStatus status = getTrust();
|
FingerprintStatus status = getTrust();
|
||||||
if (!status.isCompromised()) {
|
if (!status.isCompromised()) {
|
||||||
@ -90,8 +90,7 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
|||||||
try {
|
try {
|
||||||
PreKeyWhisperMessage message = new PreKeyWhisperMessage(encryptedKey.key);
|
PreKeyWhisperMessage message = new PreKeyWhisperMessage(encryptedKey.key);
|
||||||
if (!message.getPreKeyId().isPresent()) {
|
if (!message.getPreKeyId().isPresent()) {
|
||||||
Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "PreKeyWhisperMessage did not contain a PreKeyId");
|
throw new CryptoFailedException("PreKeyWhisperMessage did not contain a PreKeyId");
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "PreKeyWhisperMessage received, new session ID:" + message.getSignedPreKeyId() + "/" + message.getPreKeyId());
|
Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "PreKeyWhisperMessage received, new session ID:" + message.getSignedPreKeyId() + "/" + message.getPreKeyId());
|
||||||
IdentityKey msgIdentityKey = message.getIdentityKey();
|
IdentityKey msgIdentityKey = message.getIdentityKey();
|
||||||
@ -107,19 +106,19 @@ public class XmppAxolotlSession implements Comparable<XmppAxolotlSession> {
|
|||||||
WhisperMessage message = new WhisperMessage(encryptedKey.key);
|
WhisperMessage message = new WhisperMessage(encryptedKey.key);
|
||||||
plaintext = cipher.decrypt(message);
|
plaintext = cipher.decrypt(message);
|
||||||
} catch (InvalidKeyException | InvalidKeyIdException | UntrustedIdentityException e) {
|
} 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) {
|
} 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) {
|
||||||
|
throw new CryptoFailedException("plaintext unexpectedly null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plaintext != null) {
|
|
||||||
if (!status.isActive()) {
|
if (!status.isActive()) {
|
||||||
setTrust(status.toActive());
|
setTrust(status.toActive());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} 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;
|
return plaintext;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user