diff --git a/src/matrix/storage/common.ts b/src/matrix/storage/common.ts index bf9ce39b..ce85056d 100644 --- a/src/matrix/storage/common.ts +++ b/src/matrix/storage/common.ts @@ -34,7 +34,8 @@ export enum StoreNames { operations = "operations", accountData = "accountData", calls = "calls", - crossSigningKeys = "crossSigningKeys" + crossSigningKeys = "crossSigningKeys", + sharedSecrets = "sharedSecrets", } export const STORE_NAMES: Readonly = Object.values(StoreNames); diff --git a/src/matrix/storage/idb/Transaction.ts b/src/matrix/storage/idb/Transaction.ts index 4c76608c..2070eaae 100644 --- a/src/matrix/storage/idb/Transaction.ts +++ b/src/matrix/storage/idb/Transaction.ts @@ -38,6 +38,7 @@ import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore" import {OperationStore} from "./stores/OperationStore"; import {AccountDataStore} from "./stores/AccountDataStore"; import {CallStore} from "./stores/CallStore"; +import {SharedSecretStore} from "./stores/SharedSecretStore"; import type {ILogger, ILogItem} from "../../../logging/types"; export type IDBKey = IDBValidKey | IDBKeyRange; @@ -178,6 +179,10 @@ export class Transaction { return this._store(StoreNames.calls, idbStore => new CallStore(idbStore)); } + get sharedSecrets(): SharedSecretStore { + return this._store(StoreNames.sharedSecrets, idbStore => new SharedSecretStore(idbStore)); + } + async complete(log?: ILogItem): Promise { try { await txnAsPromise(this._txn); diff --git a/src/matrix/storage/idb/schema.ts b/src/matrix/storage/idb/schema.ts index 9b4d5547..ce3c89c4 100644 --- a/src/matrix/storage/idb/schema.ts +++ b/src/matrix/storage/idb/schema.ts @@ -37,7 +37,8 @@ export const schema: MigrationFunc[] = [ addInboundSessionBackupIndex, migrateBackupStatus, createCallStore, - applyCrossSigningChanges + applyCrossSigningChanges, + createSharedSecretStore, ]; // TODO: how to deal with git merge conflicts of this array? @@ -299,3 +300,8 @@ async function applyCrossSigningChanges(db: IDBDatabase, txn: IDBTransaction, lo }); log.set("marked_outdated", counter); } + +//v19 create shared secrets store +function createSharedSecretStore(db: IDBDatabase) : void { + db.createObjectStore("sharedSecrets", {keyPath: "key"}); +} diff --git a/src/matrix/storage/idb/stores/SharedSecretStore.ts b/src/matrix/storage/idb/stores/SharedSecretStore.ts new file mode 100644 index 00000000..79f9f625 --- /dev/null +++ b/src/matrix/storage/idb/stores/SharedSecretStore.ts @@ -0,0 +1,39 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +import {Store} from "../Store"; + +type SharedSecret = any; + +export class SharedSecretStore { + private _store: Store; + + constructor(store: Store) { + this._store = store; + } + + get(name: string): Promise { + return this._store.get(name); + } + + set(name: string, secret: SharedSecret): void { + secret.key = name; + this._store.put(secret); + } + + remove(name: string): void { + this._store.delete(name); + } +} diff --git a/src/matrix/verification/SAS/channel/Channel.ts b/src/matrix/verification/SAS/channel/Channel.ts index 10adbd7f..2860ea48 100644 --- a/src/matrix/verification/SAS/channel/Channel.ts +++ b/src/matrix/verification/SAS/channel/Channel.ts @@ -98,8 +98,12 @@ export class ToDeviceChannel extends Disposables implements IChannel { this.track( this.deviceMessageHandler.disposableOn( "message", - async ({ unencrypted }) => - await this.handleDeviceMessage(unencrypted) + async ({ unencrypted }) => { + if (!unencrypted) { + return; + } + await this.handleDeviceMessage(unencrypted); + } ) ); this.track(() => {