This commit is contained in:
Bruno Windels 2020-09-17 17:57:12 +02:00
parent 5752cca69c
commit a205ae8841
2 changed files with 14 additions and 12 deletions

View File

@ -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) {

View File

@ -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) {