Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross signing/observe 4s #1096

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/matrix/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class Session {
this._megolmDecryption = null;
this._getSyncToken = () => this.syncToken;
this._olmWorker = olmWorker;
this._secretStorage = undefined;
this._keyBackup = new ObservableValue(undefined);
this._crossSigning = new ObservableValue(undefined);
this._observedRoomStatus = new Map();
Expand Down Expand Up @@ -332,13 +333,14 @@ export class Session {
const isValid = await secretStorage.hasValidKeyForAnyAccountData();
log.set("isValid", isValid);
if (isValid) {
await this._loadSecretStorageServices(secretStorage, log);
this._secretStorage = secretStorage;
await this._loadSecretStorageService(log);
}
return isValid;
});
}

async _loadSecretStorageServices(secretStorage, log) {
async _loadSecretStorageServices(log) {
try {
await log.wrap("enable key backup", async log => {
const keyBackup = new KeyBackup(
Expand All @@ -348,7 +350,7 @@ export class Session {
this._storage,
this._platform,
);
if (await keyBackup.load(secretStorage, log)) {
if (await keyBackup.load(this._secretStorage, log)) {
for (const room of this._rooms.values()) {
if (room.isEncrypted) {
room.enableKeyBackup(keyBackup);
Expand All @@ -364,7 +366,7 @@ export class Session {
await log.wrap("enable cross-signing", async log => {
const crossSigning = new CrossSigning({
storage: this._storage,
secretStorage,
secretStorage: this._secretStorage,
platform: this._platform,
olm: this._olm,
olmUtil: this._olmUtil,
Expand Down Expand Up @@ -534,12 +536,12 @@ export class Session {
}
}
if (this._olm && this._e2eeAccount) {
// try set up session backup and cross-signing if we stored the ssss key
const ssssKey = await ssssReadKey(txn);
if (ssssKey) {
// this will close the txn above, so we do it last
await this._tryLoadSecretStorage(ssssKey, log);
}
this._secretStorage = new SecretStorage({
platform: this._platform,
storage: this._storage,
olm: this._olm
});
await this._secretStorage.load(txn);
}
}

Expand Down Expand Up @@ -775,19 +777,25 @@ export class Session {
txn.accountData.set(event);
}
}
if (this._secretStorage) {
changes.secretStorageChanges = await this._secretStorage.writeSync(accountData.events, txn, log);
}
}
return changes;
}

/** @internal */
afterSync({syncInfo, e2eeAccountChanges}) {
afterSync({syncInfo, e2eeAccountChanges, secretStorageChanges}) {
if (syncInfo) {
// sync transaction succeeded, modify object state now
this._syncInfo = syncInfo;
}
if (this._e2eeAccount) {
this._e2eeAccount.afterSync(e2eeAccountChanges);
}
if (secretStorageChanges && this._secretStorage) {
this._secretStorage.afterSync(secretStorageChanges);
}
}

/** @internal */
Expand Down
Loading