use correct device_id in signatures for dehydrating device

completely replace device id for dehydrating device
so we don't have to pass it down the stack
This commit is contained in:
Bruno Windels 2021-10-27 18:08:50 +02:00
parent c89e414bb5
commit e3378d5636
3 changed files with 13 additions and 7 deletions

View File

@ -253,7 +253,7 @@ export class Session {
this._setupEncryption();
}
await this._e2eeAccount.generateOTKsIfNeeded(this._storage, log);
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, undefined, log));
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, false, log));
}
}
@ -570,7 +570,7 @@ export class Session {
if (!isCatchupSync) {
const needsToUploadOTKs = await this._e2eeAccount.generateOTKsIfNeeded(this._storage, log);
if (needsToUploadOTKs) {
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, undefined, log));
await log.wrap("uploadKeys", log => this._e2eeAccount.uploadKeys(this._storage, false, log));
}
}
}

View File

@ -102,7 +102,11 @@ export class Account {
return this._identityKeys;
}
async uploadKeys(storage, dehydratedDeviceId, log) {
setDeviceId(deviceId) {
this._deviceId = deviceId;
}
async uploadKeys(storage, isDehydratedDevice, log) {
const oneTimeKeys = JSON.parse(this._account.one_time_keys());
// only one algorithm supported by olm atm, so hardcode its name
const oneTimeKeysEntries = Object.entries(oneTimeKeys.curve25519);
@ -111,12 +115,13 @@ export class Account {
if (!this._areDeviceKeysUploaded) {
log.set("identity", true);
const identityKeys = JSON.parse(this._account.identity_keys());
payload.device_keys = this._deviceKeysPayload(identityKeys, dehydratedDeviceId || this._deviceId);
payload.device_keys = this._deviceKeysPayload(identityKeys);
}
if (oneTimeKeysEntries.length) {
log.set("otks", true);
payload.one_time_keys = this._oneTimeKeysPayload(oneTimeKeysEntries);
}
const dehydratedDeviceId = isDehydratedDevice ? this._deviceId : undefined;
const response = await this._hsApi.uploadKeys(dehydratedDeviceId, payload, {log}).response();
this._serverOTKCount = response?.one_time_key_counts?.signed_curve25519;
log.set("serverOTKCount", this._serverOTKCount);
@ -241,10 +246,10 @@ export class Account {
}
}
_deviceKeysPayload(identityKeys, deviceId) {
_deviceKeysPayload(identityKeys) {
const obj = {
user_id: this._userId,
device_id: deviceId,
device_id: this._deviceId,
algorithms: [OLM_ALGORITHM, MEGOLM_ALGORITHM],
keys: {}
};

View File

@ -40,7 +40,8 @@ export async function uploadAccountAsDehydratedDevice(account, hsApi, key, devic
initial_device_display_name: deviceDisplayName
}).response();
const deviceId = response.device_id;
await account.uploadKeys(undefined, deviceId, log);
account.setDeviceId(deviceId);
await account.uploadKeys(undefined, true, log);
return deviceId;
}