Commit 2f0aafba authored by Philipp Hörist's avatar Philipp Hörist
Browse files

[omemo] Dont fail on invalid session

parent 49ad0b1f
......@@ -491,13 +491,17 @@ class LiteAxolotlStore(AxolotlStore):
def isTrusted(self, recipient_id, device_id):
record = self.loadSession(recipient_id, device_id)
identity_key = record.getSessionState().getRemoteIdentityKey()
try:
identity_key = record.getSessionState().getRemoteIdentityKey()
except Exception:
log.exception('Unable to determine trust for %s %s',
recipient_id, device_id)
return False
return self.getTrustForIdentity(
recipient_id, identity_key) == Trust.TRUSTED
def isUntrusted(self, recipient_id, device_id):
record = self.loadSession(recipient_id, device_id)
identity_key = record.getSessionState().getRemoteIdentityKey()
def isUntrustedIdentity(self, recipient_id, identity_key):
return self.getTrustForIdentity(
recipient_id, identity_key) not in (Trust.TRUSTED, Trust.UNDECIDED)
......
......@@ -224,7 +224,8 @@ class OmemoState(DeviceManager):
raise Exception('Received Pre Key Message '
'without PreKey => %s' % jid)
if self._storage.isUntrusted(jid, device):
identity_key = pre_key_message.getIdentityKey()
if self._storage.isUntrustedIdentity(jid, identity_key):
raise SenderNotTrusted
session_cipher = self._get_session_cipher(jid, device)
......@@ -232,7 +233,7 @@ class OmemoState(DeviceManager):
log.info('%s => Process pre key message from %s',
self._account, jid)
key = session_cipher.decryptPkmsg(pre_key_message)
fingerprint = get_fingerprint(pre_key_message.getIdentityKey())
fingerprint = get_fingerprint(identity_key)
self.xmpp_con.set_bundle()
self.add_device(jid, device)
......@@ -242,16 +243,16 @@ class OmemoState(DeviceManager):
message = WhisperMessage(serialized=key)
log.info('%s => Process message from %s', self._account, jid)
session_record = self._storage.loadSession(jid, device)
identity_key = session_record.getSessionState().getRemoteIdentityKey()
fingerprint = get_fingerprint(identity_key)
session_cipher = self._get_session_cipher(jid, device)
key = session_cipher.decryptMsg(message, textMsg=False)
if self._storage.isUntrusted(jid, device):
session_record = self._storage.loadSession(jid, device)
identity_key = session_record.getSessionState().getRemoteIdentityKey()
if self._storage.isUntrustedIdentity(jid, identity_key):
raise SenderNotTrusted
fingerprint = get_fingerprint(identity_key)
self.add_device(jid, device)
return key, fingerprint
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment