Implement store for shared secret

This commit is contained in:
RMidhunSuresh 2023-06-05 11:51:07 +05:30
parent c0928c75f8
commit e6a9e39c7d
5 changed files with 59 additions and 4 deletions

View File

@ -34,7 +34,8 @@ export enum StoreNames {
operations = "operations",
accountData = "accountData",
calls = "calls",
crossSigningKeys = "crossSigningKeys"
crossSigningKeys = "crossSigningKeys",
sharedSecrets = "sharedSecrets",
}
export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);

View File

@ -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<void> {
try {
await txnAsPromise(this._txn);

View File

@ -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"});
}

View File

@ -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<SharedSecret>;
constructor(store: Store<SharedSecret>) {
this._store = store;
}
get(name: string): Promise<SharedSecret | undefined> {
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);
}
}

View File

@ -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(() => {