mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
store key source in inbound session
This commit is contained in:
parent
dd2b41ff95
commit
c81dde53e7
@ -213,6 +213,9 @@ class KeyOperation {
|
||||
}
|
||||
}
|
||||
|
||||
import {KeySource} from "../../../storage/idb/stores/InboundGroupSessionStore";
|
||||
|
||||
|
||||
export function tests() {
|
||||
let instances = 0;
|
||||
|
||||
@ -237,6 +240,8 @@ export function tests() {
|
||||
get serializationKey(): string { return `key-${this.sessionId}-${this._firstKnownIndex}`; }
|
||||
get serializationType(): string { return "type"; }
|
||||
get eventIds(): string[] | undefined { return undefined; }
|
||||
get keySource(): KeySource { return KeySource.DeviceMessage; }
|
||||
|
||||
loadInto(session: Olm.InboundGroupSession) {
|
||||
const mockSession = session as MockInboundSession;
|
||||
mockSession.sessionId = this.sessionId;
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
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 {Transaction} from "../../../storage/idb/Transaction";
|
||||
import type {DecryptionResult} from "../../DecryptionResult";
|
||||
@ -83,6 +83,7 @@ export abstract class IncomingRoomKey extends RoomKey {
|
||||
sessionId: this.sessionId,
|
||||
session: pickledSession,
|
||||
backup: this.backupStatus,
|
||||
source: this.keySource,
|
||||
claimedKeys: {"ed25519": this.claimedEd25519Key},
|
||||
};
|
||||
txn.inboundGroupSessions.set(sessionEntry);
|
||||
@ -131,6 +132,8 @@ export abstract class IncomingRoomKey extends RoomKey {
|
||||
protected get backupStatus(): BackupStatus {
|
||||
return BackupStatus.NotBackedUp;
|
||||
}
|
||||
|
||||
protected abstract get keySource(): KeySource;
|
||||
}
|
||||
|
||||
class DeviceMessageRoomKey extends IncomingRoomKey {
|
||||
@ -147,10 +150,12 @@ class DeviceMessageRoomKey extends IncomingRoomKey {
|
||||
get claimedEd25519Key() { return this._decryptionResult.claimedEd25519Key; }
|
||||
get serializationKey(): string { return this._decryptionResult.event.content?.["session_key"]; }
|
||||
get serializationType(): string { return "create"; }
|
||||
protected get keySource(): KeySource { return KeySource.DeviceMessage; }
|
||||
|
||||
loadInto(session) {
|
||||
session.create(this.serializationKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BackupRoomKey extends IncomingRoomKey {
|
||||
@ -164,7 +169,8 @@ class BackupRoomKey extends IncomingRoomKey {
|
||||
get claimedEd25519Key() { return this._backupInfo["sender_claimed_keys"]?.["ed25519"]; }
|
||||
get serializationKey(): string { return this._backupInfo["session_key"]; }
|
||||
get serializationType(): string { return "import_session"; }
|
||||
|
||||
protected get keySource(): KeySource { return KeySource.Backup; }
|
||||
|
||||
loadInto(session) {
|
||||
session.import_session(this.serializationKey);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import {addRoomToIdentity} from "../../e2ee/DeviceTracker.js";
|
||||
import {SESSION_E2EE_KEY_PREFIX} from "../../e2ee/common.js";
|
||||
import {SummaryData} from "../../room/RoomSummary";
|
||||
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 {SessionStore} from "./stores/SessionStore";
|
||||
import {Store} from "./Store";
|
||||
@ -283,6 +283,11 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
|
||||
const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
|
||||
await iterateCursor<InboundGroupSessionEntry>(inboundGroupSessions.openCursor(), (value, key, cursor) => {
|
||||
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;
|
||||
});
|
||||
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});
|
||||
|
@ -22,6 +22,11 @@ export enum BackupStatus {
|
||||
BackedUp = 1
|
||||
}
|
||||
|
||||
export enum KeySource {
|
||||
DeviceMessage = 1,
|
||||
Backup,
|
||||
}
|
||||
|
||||
export interface InboundGroupSessionEntry {
|
||||
roomId: string;
|
||||
senderKey: string;
|
||||
@ -29,7 +34,8 @@ export interface InboundGroupSessionEntry {
|
||||
session?: string;
|
||||
claimedKeys?: { [algorithm : string] : string };
|
||||
eventIds?: string[];
|
||||
backup: BackupStatus
|
||||
backup: BackupStatus,
|
||||
source: KeySource
|
||||
}
|
||||
|
||||
type InboundGroupSessionStorageEntry = InboundGroupSessionEntry & { key: string };
|
||||
|
Loading…
Reference in New Issue
Block a user