implement storage changes for megolm decryption

This commit is contained in:
Bruno Windels 2020-09-04 15:31:00 +02:00
parent 5a731903da
commit 32a399afec
5 changed files with 50 additions and 0 deletions

View file

@ -27,6 +27,7 @@ export const STORE_NAMES = Object.freeze([
"olmSessions", "olmSessions",
"inboundGroupSessions", "inboundGroupSessions",
"outboundGroupSessions", "outboundGroupSessions",
"groupSessionDecryptions",
]); ]);
export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => {

View file

@ -29,6 +29,7 @@ import {DeviceIdentityStore} from "./stores/DeviceIdentityStore.js";
import {OlmSessionStore} from "./stores/OlmSessionStore.js"; import {OlmSessionStore} from "./stores/OlmSessionStore.js";
import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js";
import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js";
import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js";
export class Transaction { export class Transaction {
constructor(txn, allowedStoreNames) { constructor(txn, allowedStoreNames) {
@ -105,6 +106,11 @@ export class Transaction {
get outboundGroupSessions() { get outboundGroupSessions() {
return this._store("outboundGroupSessions", idbStore => new OutboundGroupSessionStore(idbStore)); return this._store("outboundGroupSessions", idbStore => new OutboundGroupSessionStore(idbStore));
} }
get groupSessionDecryptions() {
return this._store("groupSessionDecryptions", idbStore => new OutboundGroupSessionStore(idbStore));
}
complete() { complete() {
return txnAsPromise(this._txn); return txnAsPromise(this._txn);
} }

View file

@ -13,6 +13,7 @@ export const schema = [
createOlmSessionStore, createOlmSessionStore,
createInboundGroupSessionsStore, createInboundGroupSessionsStore,
createOutboundGroupSessionsStore, createOutboundGroupSessionsStore,
createGroupSessionDecryptions,
]; ];
// TODO: how to deal with git merge conflicts of this array? // TODO: how to deal with git merge conflicts of this array?
@ -89,3 +90,7 @@ function createOutboundGroupSessionsStore(db) {
db.createObjectStore("outboundGroupSessions", {keyPath: "roomId"}); db.createObjectStore("outboundGroupSessions", {keyPath: "roomId"});
} }
//v8
function createGroupSessionDecryptions(db) {
db.createObjectStore("groupSessionDecryptions", {keyPath: "key"});
}

View file

@ -0,0 +1,34 @@
/*
Copyright 2020 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.
*/
function encodeKey(roomId, senderKey, sessionId) {
return `${roomId}|${senderKey}|${sessionId}`;
}
export class GroupSessionDecryptionStore {
constructor(store) {
this._store = store;
}
get(roomId, sessionId, messageIndex) {
return this._store.get(encodeKey(roomId, sessionId, messageIndex));
}
set(decryption) {
decryption.key = encodeKey(decryption.roomId, decryption.sessionId, decryption.messageIndex);
this._store.put(decryption);
}
}

View file

@ -29,6 +29,10 @@ export class InboundGroupSessionStore {
return key === fetchedKey; return key === fetchedKey;
} }
get(roomId, senderKey, sessionId) {
return this._store.get(encodeKey(roomId, senderKey, sessionId));
}
set(session) { set(session) {
session.key = encodeKey(session.roomId, session.senderKey, session.sessionId); session.key = encodeKey(session.roomId, session.senderKey, session.sessionId);
this._store.put(session); this._store.put(session);