Skip to content

Commit

Permalink
Get key backup restoring working in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Jan 10, 2024
1 parent 713de5e commit f94ff81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
15 changes: 8 additions & 7 deletions internal/api/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,15 @@ func (c *JSClient) MustBackupKeys(t *testing.T) (recoveryKey string) {

func (c *JSClient) MustLoadBackup(t *testing.T, recoveryKey string) {
chrome.MustAwaitExecute(t, c.ctx, fmt.Sprintf(`(async () => {
// add the recovery key to secret storage
const recoveryKeyInfo = await window.__client.secretStorage.addKey("m.secret_storage.v1.aes-hmac-sha2", {
// we assume the recovery key is the private key for the default key id so
// figure out what that key id is.
const keyId = await window.__client.secretStorage.getDefaultKeyId();
// now add this to the in-memory cache. We don't actually ever return key info so we just pass in {} here.
window._secretStorageKeys[keyId] = {
keyInfo: {},
key: window.decodeRecoveryKey("%s"),
});
console.log("setting default key ID to " + recoveryKeyInfo.keyId);
// FIXME: this needs the client to be syncing already as this promise won't resolve until it comes down /sync, wedging forever
await window.__client.secretStorage.setDefaultKeyId(recoveryKeyInfo.keyId);
console.log("done!");
}
console.log("will return recovery key for default key id " + keyId);
const keyBackupCheck = await window.__client.getCrypto().checkKeyBackupAndEnable();
console.log("key backup: ", JSON.stringify(keyBackupCheck));
// FIXME: this just doesn't seem to work, causing 'Error: getSecretStorageKey callback returned invalid data' because the key ID
Expand Down
5 changes: 1 addition & 4 deletions tests/key_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import (
// Test that backups can be restored using secret storage and the recovery key.
func TestCanBackupKeys(t *testing.T) {
ClientTypeMatrix(t, func(t *testing.T, clientTypeA, clientTypeB api.ClientType) {
if clientTypeB.Lang == api.ClientTypeJS {
t.Skipf("key backup restoring is unsupported (js)")
return
}
if clientTypeA.HS != clientTypeB.HS {
t.Skipf("client A and B must be on the same HS as this is testing key backups so A=backup creator B=backup restorer")
return
}
t.Logf("backup creator = %s backup restorer = %s", clientTypeA.Lang, clientTypeB.Lang)
deployment := Deploy(t)
csapiAlice := deployment.Register(t, clientTypeA.HS, helpers.RegistrationOpts{
LocalpartSuffix: "alice",
Expand Down

0 comments on commit f94ff81

Please sign in to comment.