Ensure that uploaded keys are dicts

This commit is contained in:
Till Faelligen 2024-11-22 09:25:11 +01:00
parent 9c2d8fd6dd
commit 938536186c
No known key found for this signature in database
GPG key ID: ACCDC9606D472758

View file

@ -58,7 +58,6 @@ if TYPE_CHECKING:
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
ONE_TIME_KEY_UPLOAD = "one_time_key_upload_lock" ONE_TIME_KEY_UPLOAD = "one_time_key_upload_lock"
@ -821,15 +820,29 @@ class E2eKeysHandler:
# TODO: Validate the JSON to make sure it has the right keys. # TODO: Validate the JSON to make sure it has the right keys.
device_keys = keys.get("device_keys", None) device_keys = keys.get("device_keys", None)
if device_keys: if device_keys and isinstance(device_keys, dict):
await self.device_key_uploader( # Validate that user_id and device_id match the requesting user
user_id=user_id, if (
device_id=device_id, device_keys["user_id"] == user_id
keys={"device_keys": device_keys}, and device_keys["device_id"] == device_id
) ):
await self.device_key_uploader(
user_id=user_id,
device_id=device_id,
keys={"device_keys": device_keys},
)
else:
log_kv(
{
"message": "Not updating device_keys for user, user_id or device_id mismatch",
"user_id": user_id,
}
)
else:
log_kv({"message": "Did not update device_keys", "reason": "not a dict"})
one_time_keys = keys.get("one_time_keys", None) one_time_keys = keys.get("one_time_keys", None)
if one_time_keys: if one_time_keys and isinstance(one_time_keys, dict):
log_kv( log_kv(
{ {
"message": "Updating one_time_keys for device.", "message": "Updating one_time_keys for device.",
@ -840,6 +853,8 @@ class E2eKeysHandler:
await self._upload_one_time_keys_for_user( await self._upload_one_time_keys_for_user(
user_id, device_id, time_now, one_time_keys user_id, device_id, time_now, one_time_keys
) )
elif one_time_keys:
log_kv({"message": "Did not update device_keys", "reason": "not a dict"})
else: else:
log_kv( log_kv(
{"message": "Did not update one_time_keys", "reason": "no keys given"} {"message": "Did not update one_time_keys", "reason": "no keys given"}