diff --git a/matrix_keycloak_bot.py b/matrix_keycloak_bot.py index a37f565..5162212 100644 --- a/matrix_keycloak_bot.py +++ b/matrix_keycloak_bot.py @@ -38,7 +38,7 @@ log = logging.getLogger("keycloak_bot") # ------------------------------------------------------------------------------ -# Custom State Store to support find_shared_rooms +# Custom Stores to support find_shared_rooms and fix crypto cross-signing bug # ------------------------------------------------------------------------------ class CustomMemoryStateStore(MemoryStateStore): def __init__(self, bot_mxid: str): @@ -60,6 +60,18 @@ class CustomMemoryStateStore(MemoryStateStore): return shared +class CustomMemoryCryptoStore(MemoryCryptoStore): + async def put_cross_signing_key(self, user_id: UserID, usage: str, key) -> None: + """Fixes the mautrix MemoryCryptoStore AttributeError when updating cross-signing keys.""" + try: + await super().put_cross_signing_key(user_id, usage, key) + except AttributeError: + for attr_val in self.__dict__.values(): + if isinstance(attr_val, dict): + attr_val[(user_id, usage)] = key + attr_val[user_id] = key + + # ------------------------------------------------------------------------------ # Keycloak Helper Functions # ------------------------------------------------------------------------------ @@ -185,7 +197,6 @@ async def on_message(evt: Event): if evt.sender == client.mxid: return - # Ensure this is a standard text message if not hasattr(evt.content, 'body') or not isinstance(evt.content.body, str): return @@ -324,7 +335,7 @@ async def main(): state_store = CustomMemoryStateStore(client.mxid) client.state_store = state_store - crypto_store = MemoryCryptoStore(client.mxid, client.device_id) + crypto_store = CustomMemoryCryptoStore(client.mxid, client.device_id) machine = OlmMachine(client, crypto_store, state_store) await machine.load() client.crypto = machine