store key source in inbound session

This commit is contained in:
Bruno Windels 2022-01-28 10:00:41 +01:00
parent dd2b41ff95
commit c81dde53e7
4 changed files with 26 additions and 4 deletions

View File

@ -213,6 +213,9 @@ class KeyOperation {
} }
} }
import {KeySource} from "../../../storage/idb/stores/InboundGroupSessionStore";
export function tests() { export function tests() {
let instances = 0; let instances = 0;
@ -237,6 +240,8 @@ export function tests() {
get serializationKey(): string { return `key-${this.sessionId}-${this._firstKnownIndex}`; } get serializationKey(): string { return `key-${this.sessionId}-${this._firstKnownIndex}`; }
get serializationType(): string { return "type"; } get serializationType(): string { return "type"; }
get eventIds(): string[] | undefined { return undefined; } get eventIds(): string[] | undefined { return undefined; }
get keySource(): KeySource { return KeySource.DeviceMessage; }
loadInto(session: Olm.InboundGroupSession) { loadInto(session: Olm.InboundGroupSession) {
const mockSession = session as MockInboundSession; const mockSession = session as MockInboundSession;
mockSession.sessionId = this.sessionId; mockSession.sessionId = this.sessionId;

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {BackupStatus} from "../../../storage/idb/stores/InboundGroupSessionStore"; import {BackupStatus, KeySource} from "../../../storage/idb/stores/InboundGroupSessionStore";
import type {InboundGroupSessionEntry} from "../../../storage/idb/stores/InboundGroupSessionStore"; import type {InboundGroupSessionEntry} from "../../../storage/idb/stores/InboundGroupSessionStore";
import type {Transaction} from "../../../storage/idb/Transaction"; import type {Transaction} from "../../../storage/idb/Transaction";
import type {DecryptionResult} from "../../DecryptionResult"; import type {DecryptionResult} from "../../DecryptionResult";
@ -83,6 +83,7 @@ export abstract class IncomingRoomKey extends RoomKey {
sessionId: this.sessionId, sessionId: this.sessionId,
session: pickledSession, session: pickledSession,
backup: this.backupStatus, backup: this.backupStatus,
source: this.keySource,
claimedKeys: {"ed25519": this.claimedEd25519Key}, claimedKeys: {"ed25519": this.claimedEd25519Key},
}; };
txn.inboundGroupSessions.set(sessionEntry); txn.inboundGroupSessions.set(sessionEntry);
@ -131,6 +132,8 @@ export abstract class IncomingRoomKey extends RoomKey {
protected get backupStatus(): BackupStatus { protected get backupStatus(): BackupStatus {
return BackupStatus.NotBackedUp; return BackupStatus.NotBackedUp;
} }
protected abstract get keySource(): KeySource;
} }
class DeviceMessageRoomKey extends IncomingRoomKey { class DeviceMessageRoomKey extends IncomingRoomKey {
@ -147,10 +150,12 @@ class DeviceMessageRoomKey extends IncomingRoomKey {
get claimedEd25519Key() { return this._decryptionResult.claimedEd25519Key; } get claimedEd25519Key() { return this._decryptionResult.claimedEd25519Key; }
get serializationKey(): string { return this._decryptionResult.event.content?.["session_key"]; } get serializationKey(): string { return this._decryptionResult.event.content?.["session_key"]; }
get serializationType(): string { return "create"; } get serializationType(): string { return "create"; }
protected get keySource(): KeySource { return KeySource.DeviceMessage; }
loadInto(session) { loadInto(session) {
session.create(this.serializationKey); session.create(this.serializationKey);
} }
} }
class BackupRoomKey extends IncomingRoomKey { class BackupRoomKey extends IncomingRoomKey {
@ -164,7 +169,8 @@ class BackupRoomKey extends IncomingRoomKey {
get claimedEd25519Key() { return this._backupInfo["sender_claimed_keys"]?.["ed25519"]; } get claimedEd25519Key() { return this._backupInfo["sender_claimed_keys"]?.["ed25519"]; }
get serializationKey(): string { return this._backupInfo["session_key"]; } get serializationKey(): string { return this._backupInfo["session_key"]; }
get serializationType(): string { return "import_session"; } get serializationType(): string { return "import_session"; }
protected get keySource(): KeySource { return KeySource.Backup; }
loadInto(session) { loadInto(session) {
session.import_session(this.serializationKey); session.import_session(this.serializationKey);
} }

View File

@ -6,7 +6,7 @@ import {addRoomToIdentity} from "../../e2ee/DeviceTracker.js";
import {SESSION_E2EE_KEY_PREFIX} from "../../e2ee/common.js"; import {SESSION_E2EE_KEY_PREFIX} from "../../e2ee/common.js";
import {SummaryData} from "../../room/RoomSummary"; import {SummaryData} from "../../room/RoomSummary";
import {RoomMemberStore, MemberData} from "./stores/RoomMemberStore"; import {RoomMemberStore, MemberData} from "./stores/RoomMemberStore";
import {InboundGroupSessionStore, InboundGroupSessionEntry, BackupStatus} from "./stores/InboundGroupSessionStore"; import {InboundGroupSessionStore, InboundGroupSessionEntry, BackupStatus, KeySource} from "./stores/InboundGroupSessionStore";
import {RoomStateEntry} from "./stores/RoomStateStore"; import {RoomStateEntry} from "./stores/RoomStateStore";
import {SessionStore} from "./stores/SessionStore"; import {SessionStore} from "./stores/SessionStore";
import {Store} from "./Store"; import {Store} from "./Store";
@ -283,6 +283,11 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
const inboundGroupSessions = txn.objectStore("inboundGroupSessions"); const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
await iterateCursor<InboundGroupSessionEntry>(inboundGroupSessions.openCursor(), (value, key, cursor) => { await iterateCursor<InboundGroupSessionEntry>(inboundGroupSessions.openCursor(), (value, key, cursor) => {
value.backup = BackupStatus.NotBackedUp; value.backup = BackupStatus.NotBackedUp;
// we'll also have backup keys in here, we can't tell,
// but the worst thing that can happen is that we try
// to backup keys that were already in backup, which
// the server will ignore
value.source = KeySource.DeviceMessage;
return NOT_DONE; return NOT_DONE;
}); });
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false}); inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});

View File

@ -22,6 +22,11 @@ export enum BackupStatus {
BackedUp = 1 BackedUp = 1
} }
export enum KeySource {
DeviceMessage = 1,
Backup,
}
export interface InboundGroupSessionEntry { export interface InboundGroupSessionEntry {
roomId: string; roomId: string;
senderKey: string; senderKey: string;
@ -29,7 +34,8 @@ export interface InboundGroupSessionEntry {
session?: string; session?: string;
claimedKeys?: { [algorithm : string] : string }; claimedKeys?: { [algorithm : string] : string };
eventIds?: string[]; eventIds?: string[];
backup: BackupStatus backup: BackupStatus,
source: KeySource
} }
type InboundGroupSessionStorageEntry = InboundGroupSessionEntry & { key: string }; type InboundGroupSessionStorageEntry = InboundGroupSessionEntry & { key: string };