From 4dce93e5ef5dcecce31556acdfd3bb4ab417d3cf Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Thu, 2 Mar 2023 17:13:15 +0100 Subject: [PATCH] make sure the key property doesn't leak out of the storage layer as it ends up in the value we're signing and uploading, corrupting the signature --- .../storage/idb/stores/CrossSigningKeyStore.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/matrix/storage/idb/stores/CrossSigningKeyStore.ts b/src/matrix/storage/idb/stores/CrossSigningKeyStore.ts index 32100aca..bbda15c0 100644 --- a/src/matrix/storage/idb/stores/CrossSigningKeyStore.ts +++ b/src/matrix/storage/idb/stores/CrossSigningKeyStore.ts @@ -18,7 +18,8 @@ import {MAX_UNICODE, MIN_UNICODE} from "./common"; import {Store} from "../Store"; import type {CrossSigningKey} from "../../../verification/CrossSigning"; -type CrossSigningKeyEntry = CrossSigningKey & { +type CrossSigningKeyEntry = { + crossSigningKey: CrossSigningKey key: string; // key in storage, not a crypto key } @@ -38,14 +39,15 @@ export class CrossSigningKeyStore { this._store = store; } - get(userId: string, deviceId: string): Promise { - return this._store.get(encodeKey(userId, deviceId)); + async get(userId: string, deviceId: string): Promise { + return (await this._store.get(encodeKey(userId, deviceId)))?.crossSigningKey; } set(crossSigningKey: CrossSigningKey): void { - const deviceIdentityEntry = crossSigningKey as CrossSigningKeyEntry; - deviceIdentityEntry.key = encodeKey(crossSigningKey["user_id"], crossSigningKey.usage[0]); - this._store.put(deviceIdentityEntry); + this._store.put({ + key:encodeKey(crossSigningKey["user_id"], crossSigningKey.usage[0]), + crossSigningKey + }); } remove(userId: string, usage: string): void {