Skip to content

Commit

Permalink
Store key backup key in cache as Uint8Array
Browse files Browse the repository at this point in the history
Bootstrap was incorrectly storing the key backup key as base64 encoded, when
instead it should be a uint8Array.

Fixes element-hq/element-web#13057
  • Loading branch information
jryans committed Apr 7, 2020
1 parent dc56f05 commit 0efac7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/crypto/index.js
Expand Up @@ -711,7 +711,8 @@ Crypto.prototype.bootstrapSecretStorage = async function({
const sessionBackupKey = await this.getSecret('m.megolm_backup.v1');
if (sessionBackupKey) {
logger.info("Got session backup key from secret storage: caching");
await this.storeSessionBackupPrivateKey(sessionBackupKey);
const decoded = olmlib.decodeBase64(sessionBackupKey);
await this.storeSessionBackupPrivateKey(decoded);
}
} finally {
// Restore the original callbacks. NB. we must do this by manipulating
Expand Down
7 changes: 2 additions & 5 deletions src/crypto/verification/Base.js
Expand Up @@ -221,8 +221,7 @@ export class VerificationBase extends EventEmitter {
`m.cross_signing.${type}`, [this.deviceId],
);
const result = await promise;
const decoded = decodeBase64(result);
return Uint8Array.from(decoded);
return decodeBase64(result);
} },
original._cacheCallbacks,
);
Expand Down Expand Up @@ -252,9 +251,7 @@ export class VerificationBase extends EventEmitter {
logger.info("Got key backup key, decoding...");
const decodedKey = decodeBase64(base64Key);
logger.info("Decoded backup key, storing...");
client._crypto.storeSessionBackupPrivateKey(
Uint8Array.from(decodedKey),
);
client._crypto.storeSessionBackupPrivateKey(decodedKey);
logger.info("Backup key stored. Starting backup restore...");
const backupInfo = await client.getKeyBackupVersion();
// no need to await for this - just let it go in the bg
Expand Down

0 comments on commit 0efac7e

Please sign in to comment.