Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace prepareKeyBackupVersion by resetKeyBackup #3662

Closed
wants to merge 19 commits into from

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented Aug 16, 2023

Fixes https://github.com/vector-im/crypto-internal/issues/107

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

This change is marked as an internal change (Task), so will not be included in the changelog.

@BillCarsonFr BillCarsonFr added the T-Task Tasks for the team like planning label Aug 16, 2023
src/crypto-api.ts Outdated Show resolved Hide resolved
src/crypto/index.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved
src/crypto-api.ts Outdated Show resolved Hide resolved
src/crypto-api.ts Outdated Show resolved Hide resolved
src/crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
src/rust-crypto/rust-crypto.ts Outdated Show resolved Hide resolved
src/rust-crypto/backup.ts Outdated Show resolved Hide resolved
Comment on lines +571 to +573
if (setupNewKeyBackup) {
await this.resetKeyBackup();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be adding new functionality, which doesn't really fit with the title of this PR (which implies we are just replacing the existing implementation). Maybe we should separate the new rust impl from the changes to the existing code? It's hard to review at the moment as it feels like we're doing two quite different things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the main point of the PR? to have boostraping complete now and creating a complete backup?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the main point of the PR? to have boostraping complete now and creating a complete backup?

Yeah, that's probably fair. But then we should rename the PR to reflect what it's actually doing.

The problem is, I'm struggling to come up with a short summary of the PR. "Add new CryptoApi.resetKeyBackup and CryptoApi.deleteKeyBackupVersion APIs, and enable backups in RustCrypto.bootstrapSecretStorage". What a mouthful!

All of which is to say... I feel like this PR is doing lots of things, and we should probably have broken it down. Which may be one of the reasons it has had 119 comments so far, and multiple rounds of review.

It may be too late now, but I think we can learn from this in the future.

src/client.ts Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved
src/crypto-api.ts Outdated Show resolved Hide resolved
src/crypto-api.ts Outdated Show resolved Hide resolved
spec/integ/crypto/crypto.spec.ts Outdated Show resolved Hide resolved
spec/integ/crypto/crypto.spec.ts Outdated Show resolved Hide resolved
expect(activeBackup).toStrictEqual(backupVersion);
});

it("Reset key backup should create a new backup and update 4S", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this isn't part of the tests for bootstrapSecretStorage so should be moved outside the describe block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored.

I don't see any changes here. It's still inside the describe("bootstrapSecretStorage" ... ) block.

});

it("Reset key backup should create a new backup and update 4S", async () => {
// First setup recovery
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// First setup recovery
// First set up recovery

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what is recovery?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recovery is 4S (cross signing and megolm backup)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recovery is 4S (cross signing and megolm backup)

Please could the comment say that then?

spec/integ/crypto/crypto.spec.ts Outdated Show resolved Hide resolved
Comment on lines +546 to +554
/**
* Deletes the given backup.
*
* @param version - The version to delete.
*/
public async deleteKeyBackupVersion(version: string): Promise<void> {
await this.backupManager.deleteKeyBackupVersion(version);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still needs to be moved, please.

Comment on lines +241 to +243
* The decryption key will be saved in Secret Storage (the `SecretStorageCallbacks.getSecretStorageKey` Crypto
* callback will be called)
* and the backup engine will be started.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The decryption key will be saved in Secret Storage (the `SecretStorageCallbacks.getSecretStorageKey` Crypto
* callback will be called)
* and the backup engine will be started.
* The decryption key will be saved in Secret Storage (the {@link SecretStorageCallbacks#getSecretStorageKey}
* callback will be called) and the backup engine will be started.

@@ -56,3 +58,35 @@ export function mockSetupCrossSigningRequests(): void {
{},
);
}

/**
* Mock out requests to `/room_keys/version`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Mock out requests to `/room_keys/version`.
* Mock out requests to `/room_keys/version`.


/**
* Holds information of a created keybackup.
* Useful to get the generated private key material and save it securely somewhere.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Useful to get the generated private key material and save it securely somewhere.
*
* Useful to get the generated private key material and save it securely somewhere.

public async resetKeyBackup(): Promise<void> {
// Delete existing ones
await this.backupManager.deleteKeyBackup();
// There is no use case for having several key backup version live server side.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// There is no use case for having several key backup version live server side.
// There is no use case for having several key backup versions live server side.

Comment on lines +382 to +386
/**
* Prepare the keybackup version data, auth_data not signed at this point
* @returns a {@link PreparedKeyBackupVersion} with all information about the creation.
*/
private async prepareKeyBackupVersion(): Promise<PreparedKeyBackupVersion> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and same naming that legacy code)

this is not necessarily a good thing.

I think my problem is that "prepare" is very vague. We can keep the name of the method if you like but please expand the tsdoc to explain more clearly what it does.

* Returns 404 `M_NOT_FOUND` for GET `/room_keys/version` request until POST `room_keys/version` is called.
* Once the POST is done GET `/room_keys/version` will return the posted backup instead of 404
*
* @param backupVersion The version of the backup to create
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Not as far as I can see?

* Once the POST is done, `GET /room_keys/version` will return the posted backup
* instead of 404.
*
* @param backupVersion - The version of the backup to create
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still needs an update, per #3662 (comment)

// Return the newly created key in the sync response
sendSyncResponse(secretStorageKey);

// Wait for the cross signing keys to be uploaded
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Wait for the cross signing keys to be uploaded
// Wait for the cross signing keys and backup key to be uploaded

expect(activeBackup).toStrictEqual(backupVersion);
});

it("Reset key backup should create a new backup and update 4S", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored.

I don't see any changes here. It's still inside the describe("bootstrapSecretStorage" ... ) block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants