From a205ae88413312b8d5e7ab57e59d6e0937720b36 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 17 Sep 2020 17:57:12 +0200 Subject: [PATCH] fixes --- src/matrix/Session.js | 19 ++++++++++--------- src/matrix/net/HomeServerApi.js | 7 ++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index b5e0a4b7..934b8e91 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -34,8 +34,8 @@ import { keyFromCredential as ssssKeyFromCredential, readKey as ssssReadKey, writeKey as ssssWriteKey, - SecretStorage -} from "./ssss/index.js" +} from "./ssss/index.js"; +import {SecretStorage} from "./ssss/SecretStorage.js"; const PICKLE_KEY = "DEFAULT_KEY"; @@ -155,8 +155,14 @@ export class Session { if (!this._olm) { throw new Error("olm required"); } - const key = ssssKeyFromCredential(type, credential, this._storage, this._cryptoDriver); - // write the key + const key = await ssssKeyFromCredential(type, credential, this._storage, this._cryptoDriver); + // and create session backup, which needs to read from accountData + txn = await this._storage.readTxn([ + this._storage.storeNames.accountData, + ]); + await this._createSessionBackup(key, txn); + // only after having read a secret, write the key + // as we only find out if it was good if the MAC verification succeeds let txn = await this._storage.readWriteTxn([ this._storage.storeNames.session, ]); @@ -167,11 +173,6 @@ export class Session { throw err; } await txn.complete(); - // and create session backup, which needs to read from accountData - txn = await this._storage.readTxn([ - this._storage.storeNames.accountData, - ]); - await this._createSessionBackup(key, txn); } async _createSessionBackup(ssssKey, txn) { diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index c536ecf7..cfb75e15 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -178,10 +178,11 @@ export class HomeServerApi { } roomKeysVersion(version = null, options = null) { - if (!version) { - version = ""; + let versionPart = ""; + if (version) { + versionPart = `/${encodeURIComponent(version)}`; } - return this._get(`/room_keys/version/${encodeURIComponent(version)}`, null, null, options); + return this._get(`/room_keys/version${versionPart}`, null, null, options); } roomKeyForRoomAndSession(version, roomId, sessionId, options = null) {