Skip to content

Commit

Permalink
Merge pull request #1308 from matrix-org/jryans/backup-key-cache-format
Browse files Browse the repository at this point in the history
Store key backup key in cache as Uint8Array
  • Loading branch information
jryans committed Apr 8, 2020
2 parents 4d26252 + 2ed6e9b commit 84637c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/crypto/CrossSigning.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ export function createCryptoStoreCacheCallbacks(store) {
});
},
storeCrossSigningKeyCache: function(type, key) {
if (!(key instanceof Uint8Array)) {
throw new Error(
`storeCrossSigningKeyCache expects Uint8Array, got ${key}`,
);
}
return store.doTxn(
'readwrite',
[IndexedDBCryptoStore.STORE_ACCOUNT],
Expand Down
6 changes: 5 additions & 1 deletion src/crypto/index.js
Original file line number Diff line number Diff line change
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 Expand Up @@ -822,6 +823,9 @@ Crypto.prototype.getSessionBackupPrivateKey = async function() {
* @returns {Promise} so you can catch failures
*/
Crypto.prototype.storeSessionBackupPrivateKey = async function(key) {
if (!(key instanceof Uint8Array)) {
throw new Error(`storeSessionBackupPrivateKey expects Uint8Array, got ${key}`);
}
return this._cryptoStore.doTxn(
'readwrite',
[IndexedDBCryptoStore.STORE_ACCOUNT],
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/recoverykey.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function decodeRecoveryKey(recoverykey) {
throw new Error("Incorrect length");
}

return result.slice(
return Uint8Array.from(result.slice(
OLM_RECOVERY_KEY_PREFIX.length,
OLM_RECOVERY_KEY_PREFIX.length + global.Olm.PRIVATE_KEY_LENGTH,
);
));
}

0 comments on commit 84637c6

Please sign in to comment.