Skip to content

Commit

Permalink
Added empty OMEMO message decryption logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Syndace committed Aug 13, 2022
1 parent b4cb371 commit 10ba2e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions omemo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class Content(ABC):
other backend-specific data that is shared between all recipients.
"""

@property
@abstractmethod
def empty(self) -> bool:
"""
Returns:
Whether this instance corresponds to an empty OMEMO message purely used for protocol stability
reasons.
"""


class PlainKeyMaterial(ABC):
"""
Expand Down
7 changes: 4 additions & 3 deletions omemo/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ def is_trusted(device: DeviceInformation) -> bool:

return messages, encryption_errors

async def decrypt(self, message: Message) -> Tuple[bytes, DeviceInformation]:
async def decrypt(self, message: Message) -> Tuple[Optional[bytes], DeviceInformation]:
"""
Decrypt a message.
Expand All @@ -1856,7 +1856,8 @@ async def decrypt(self, message: Message) -> Tuple[bytes, DeviceInformation]:
Returns:
A tuple, where the first entry is the decrypted plaintext and the second entry contains
information about the device that sent the message.
information about the device that sent the message. The plaintext is optional and will be ``None``
in case the message was an empty OMEMO message purely used for protocol stability reasons.
Raises:
UnknownNamespace: if the backend to handle the message is not currently loaded.
Expand Down Expand Up @@ -2064,7 +2065,7 @@ async def handle_key_exchange(
logging.getLogger(SessionManager.LOG_TAG).debug(f"Plain key material: {plain_key_material}")

# Decrypt the message
plaintext = await backend.decrypt_plaintext(
plaintext = None if message.content.empty else await backend.decrypt_plaintext(
message.content,
plain_key_material
)
Expand Down

0 comments on commit 10ba2e3

Please sign in to comment.