python icon indicating copy to clipboard operation
python copied to clipboard

Decryption fails (TypeError) when attached to conduit homeserver

Open jblachly opened this issue 1 year ago • 0 comments

This is a copy of https://github.com/maubot/maubot/issues/184 , because the core issue is in the mautrix-python library, not maubot (where the error manifests).

Maubot (docker :latest, git d574f84079c2469b71e6c09c4b804e8bf6156153) cannot decrypt messages posted in encrypted room when logged in to a Conduit homeserver.

This is because conduit does not return fields failures and user_signing_keys. However, these are not required by the specification: https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3keysquery

Problem is here:

https://github.com/mautrix/python/blob/735d0c139e48777cbd2385ed15fdb549113914c4/mautrix/types/util/serializable_attrs.py#L211-L221

ANd ultimately looking thru the traceback, none of the callers in the chain supply a default (third param to _dict_to_attrs) containing the missing fields. ~~If this issue should be instead in https://github.com/mautrix/python let me know (or move it if there is shared control)~~

[2022-09-03 18:46:09] [[email protected].@github:matrix.blachly.net] req #4840: POST https://matrix.blachly.net/_matrix/client/v3/keys/query {"timeout": 10000, "device_keys": { ... keys ... } into QueryKeysResponse
[2022-09-03 18:46:09] [[email protected].@github:matrix.blachly.net] Failed to run handler
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/mautrix/types/util/serializable_attrs.py", line 212, in _dict_to_attrs
    obj = attrs_type(**new_items)
TypeError: __init__() missing 2 required positional arguments: 'failures' and 'user_signing_keys'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/mautrix/client/syncer.py", line 229, in _catch_errors
    await handler(data)
  File "/usr/lib/python3.9/site-packages/mautrix/client/encryption_manager.py", line 182, in handle
    decrypted = await self.client.crypto.decrypt_megolm_event(evt)
  File "/usr/lib/python3.9/site-packages/mautrix/crypto/decrypt_megolm.py", line 70, in decrypt_megolm_event
    device = await self.get_or_fetch_device_by_key(evt.sender, session.sender_key)
  File "/usr/lib/python3.9/site-packages/mautrix/crypto/device_lists.py", line 230, in get_or_fetch_device_by_key
    devices = await self._fetch_keys([user_id], include_untracked=True)
  File "/usr/lib/python3.9/site-packages/mautrix/crypto/device_lists.py", line 40, in _fetch_keys
    resp = await self.client.query_keys(users, token=since)
  File "/usr/lib/python3.9/site-packages/mautrix/client/api/modules/crypto.py", line 151, in query_keys
    return QueryKeysResponse.deserialize(resp)
  File "/usr/lib/python3.9/site-packages/mautrix/types/util/serializable_attrs.py", line 375, in deserialize
    return _dict_to_attrs(cls, data)
  File "/usr/lib/python3.9/site-packages/mautrix/types/util/serializable_attrs.py", line 218, in _dict_to_attrs
    raise SerializerError(
mautrix.types.util.serializable.SerializerError: Missing value for required key failures in QueryKeysResponse

jblachly avatar Oct 14 '22 22:10 jblachly