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

Rust-crypto: fix bootstrapCrossSigning on second call #3912

Merged
merged 3 commits into from
Dec 1, 2023

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Nov 28, 2023

Currently, bootstrapCrossSigning raises an exception if it is called a second time before secret storage is set up. It is easily fixed by checking that 4S is set up before trying to export to 4S.

Also a few logging fixes while we're in the area.

Fixes element-hq/element-web#26393


Here's what your changelog entry will look like:

🐛 Bug Fixes

@@ -66,18 +66,25 @@ export class CrossSigningIdentity {
});

if (olmDeviceHasKeys) {
if (!privateKeysInSecretStorage) {
if (!(await this.secretStorage.hasKey())) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the real fix in this PR: we need to check that secretStorage is set up before we try to export to it.

Comment on lines -151 to 178
this.secretStorage.store("m.cross_signing.master", exported.masterKey);
await this.secretStorage.store("m.cross_signing.master", exported.masterKey);
} else {
logger.error(`Cannot export MSK to secret storage, private key unknown`);
}
if (exported?.self_signing_key) {
this.secretStorage.store("m.cross_signing.self_signing", exported.self_signing_key);
await this.secretStorage.store("m.cross_signing.self_signing", exported.self_signing_key);
} else {
logger.error(`Cannot export SSK to secret storage, private key unknown`);
}
if (exported?.userSigningKey) {
this.secretStorage.store("m.cross_signing.user_signing", exported.userSigningKey);
await this.secretStorage.store("m.cross_signing.user_signing", exported.userSigningKey);
} else {
logger.error(`Cannot export USK to secret storage, private key unknown`);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

these things were missing their await keywords, which meant that when they failed they were shouting into the void.

Currently, `bootstrapCrossSigning` raises an exception if it is called a second
time before secret storage is set up. It is easily fixed by checking that 4S is
set up before trying to export to 4S.

Also a few logging fixes while we're in the area.
@richvdh
Copy link
Member Author

richvdh commented Nov 28, 2023

will add some more tests

Copy link
Member

@BillCarsonFr BillCarsonFr left a comment

Choose a reason for hiding this comment

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

Good catch

const authDict = { type: "test" };
await bootstrapCrossSigning(authDict);

// a second call should do nothing except GET requests
Copy link
Member

Choose a reason for hiding this comment

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

What get requests?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does GET /user/:user/account_data/:type requests, because this test is running before the initialsync completes (so it has not cached any account data in memory).

Would you find this useful to include in the comment?

Copy link
Member

Choose a reason for hiding this comment

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

No maybe not. Was trying to remember why it would do requests.
Looks like it's checking if it's in 4S or not to eventually update 4S or import. There are some comments about it in bootstrapCrossSigning. I guess the naming is not perfect, maybe it's ensureCrossSigning but also fix it :/

@richvdh richvdh added this pull request to the merge queue Nov 29, 2023
@robintown robintown removed their request for review November 29, 2023 17:44
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 29, 2023
@richvdh
Copy link
Member Author

richvdh commented Nov 30, 2023

Test flake filed as element-hq/element-web#26679

@richvdh richvdh added this pull request to the merge queue Nov 30, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 30, 2023
@richvdh richvdh added this pull request to the merge queue Dec 1, 2023
Merged via the queue into develop with commit b515cdb Dec 1, 2023
24 checks passed
@richvdh richvdh deleted the rav/element-r/fix_bootstrap_cross_signing branch December 1, 2023 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Element-R: Exceptions when setting up backup/cross-signing/etc on existing account with no 4S
3 participants