|
5 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | | -from typing import Any, Awaitable, Callable, TypedDict |
| 8 | +from typing import Awaitable, Callable |
9 | 9 | import asyncio |
10 | | -import functools |
11 | | -import json |
12 | | - |
13 | | -import olm |
14 | 10 |
|
15 | 11 | from mautrix.errors import MForbidden, MNotFound |
16 | 12 | from mautrix.types import ( |
17 | | - DeviceID, |
18 | | - EncryptionKeyAlgorithm, |
19 | 13 | EventType, |
20 | 14 | IdentityKey, |
21 | | - KeyID, |
22 | 15 | RequestedKeyInfo, |
23 | 16 | RoomEncryptionStateEventContent, |
24 | 17 | RoomID, |
25 | 18 | RoomKeyEventContent, |
26 | 19 | SessionID, |
27 | | - SigningKey, |
28 | 20 | TrustState, |
29 | 21 | UserID, |
30 | 22 | ) |
|
34 | 26 | from .ssss import Machine as SSSSMachine |
35 | 27 |
|
36 | 28 |
|
37 | | -class SignedObject(TypedDict): |
38 | | - signatures: dict[UserID, dict[str, str]] |
39 | | - unsigned: Any |
40 | | - |
41 | | - |
42 | 29 | class BaseOlmMachine: |
43 | 30 | client: cli.Client |
44 | 31 | ssss: SSSSMachine |
@@ -118,27 +105,3 @@ async def _fill_encryption_info(self, evt: RoomKeyEventContent) -> None: |
118 | 105 | evt.beeper_max_age_ms = encryption_info.rotation_period_ms |
119 | 106 | if not evt.beeper_max_messages: |
120 | 107 | evt.beeper_max_messages = encryption_info.rotation_period_msgs |
121 | | - |
122 | | - |
123 | | -canonical_json = functools.partial( |
124 | | - json.dumps, ensure_ascii=False, separators=(",", ":"), sort_keys=True |
125 | | -) |
126 | | - |
127 | | - |
128 | | -def verify_signature_json( |
129 | | - data: "SignedObject", user_id: UserID, key_name: DeviceID | str, key: SigningKey |
130 | | -) -> bool: |
131 | | - data_copy = {**data} |
132 | | - data_copy.pop("unsigned", None) |
133 | | - signatures = data_copy.pop("signatures") |
134 | | - key_id = str(KeyID(EncryptionKeyAlgorithm.ED25519, key_name)) |
135 | | - try: |
136 | | - signature = signatures[user_id][key_id] |
137 | | - except KeyError: |
138 | | - return False |
139 | | - signed_data = canonical_json(data_copy) |
140 | | - try: |
141 | | - olm.ed25519_verify(key, signed_data, signature) |
142 | | - return True |
143 | | - except olm.OlmVerifyError: |
144 | | - return False |
0 commit comments