diff --git a/src/matrix/storage/common.js b/src/matrix/storage/common.js index 473b8eb6..4a4060b2 100644 --- a/src/matrix/storage/common.js +++ b/src/matrix/storage/common.js @@ -27,6 +27,7 @@ export const STORE_NAMES = Object.freeze([ "olmSessions", "inboundGroupSessions", "outboundGroupSessions", + "groupSessionDecryptions", ]); export const STORE_MAP = Object.freeze(STORE_NAMES.reduce((nameMap, name) => { diff --git a/src/matrix/storage/idb/Transaction.js b/src/matrix/storage/idb/Transaction.js index 8b42b0f7..946b06cc 100644 --- a/src/matrix/storage/idb/Transaction.js +++ b/src/matrix/storage/idb/Transaction.js @@ -29,6 +29,7 @@ import {DeviceIdentityStore} from "./stores/DeviceIdentityStore.js"; import {OlmSessionStore} from "./stores/OlmSessionStore.js"; import {InboundGroupSessionStore} from "./stores/InboundGroupSessionStore.js"; import {OutboundGroupSessionStore} from "./stores/OutboundGroupSessionStore.js"; +import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore.js"; export class Transaction { constructor(txn, allowedStoreNames) { @@ -105,6 +106,11 @@ export class Transaction { get outboundGroupSessions() { return this._store("outboundGroupSessions", idbStore => new OutboundGroupSessionStore(idbStore)); } + + get groupSessionDecryptions() { + return this._store("groupSessionDecryptions", idbStore => new OutboundGroupSessionStore(idbStore)); + } + complete() { return txnAsPromise(this._txn); } diff --git a/src/matrix/storage/idb/schema.js b/src/matrix/storage/idb/schema.js index 2060cb39..63458916 100644 --- a/src/matrix/storage/idb/schema.js +++ b/src/matrix/storage/idb/schema.js @@ -13,6 +13,7 @@ export const schema = [ createOlmSessionStore, createInboundGroupSessionsStore, createOutboundGroupSessionsStore, + createGroupSessionDecryptions, ]; // TODO: how to deal with git merge conflicts of this array? @@ -89,3 +90,7 @@ function createOutboundGroupSessionsStore(db) { db.createObjectStore("outboundGroupSessions", {keyPath: "roomId"}); } +//v8 +function createGroupSessionDecryptions(db) { + db.createObjectStore("groupSessionDecryptions", {keyPath: "key"}); +} diff --git a/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js new file mode 100644 index 00000000..299b1520 --- /dev/null +++ b/src/matrix/storage/idb/stores/GroupSessionDecryptionStore.js @@ -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); + } +} diff --git a/src/matrix/storage/idb/stores/InboundGroupSessionStore.js b/src/matrix/storage/idb/stores/InboundGroupSessionStore.js index 3de5a103..d05c67ff 100644 --- a/src/matrix/storage/idb/stores/InboundGroupSessionStore.js +++ b/src/matrix/storage/idb/stores/InboundGroupSessionStore.js @@ -29,6 +29,10 @@ export class InboundGroupSessionStore { return key === fetchedKey; } + get(roomId, senderKey, sessionId) { + return this._store.get(encodeKey(roomId, senderKey, sessionId)); + } + set(session) { session.key = encodeKey(session.roomId, session.senderKey, session.sessionId); this._store.put(session);