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

Add CryptoApi.resetEncryption #4614

Merged
merged 4 commits into from
Jan 22, 2025
Merged

Conversation

florianduros
Copy link
Contributor

@florianduros florianduros commented Jan 14, 2025

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

Task element-hq/element-web#28977
Require #4615
Add CryptoApi.resetEncryption.

The goal of this new api is to give an easy to reset the current encryption state of the user:

  • Disable backing up room keys and delete any existing backup.
  • Remove the default secret storage key from the account data (ie: the recovery key).
  • Reset the cross-signing keys.
  • Re-enable backing up room keys if enabled before.

@florianduros florianduros changed the title Add CryptoApi#resetEncryption Add CryptoApi.resetEncryption Jan 14, 2025
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from f99e069 to 4029eee Compare January 14, 2025 09:35
@florianduros florianduros added T-Feature Request to add a new feature which does not exist right now T-Enhancement and removed T-Feature Request to add a new feature which does not exist right now labels Jan 14, 2025
@florianduros florianduros force-pushed the florianduros/reset-encryption branch 2 times, most recently from 18fb6e6 to b033611 Compare January 15, 2025 14:04
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from b033611 to c1462b7 Compare January 15, 2025 14:36
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from c1462b7 to dbb5c0f Compare January 15, 2025 14:45
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from dbb5c0f to 0420edf Compare January 15, 2025 14:47
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from 0420edf to 6ea0cd1 Compare January 15, 2025 14:48
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from 6ea0cd1 to dbd54dc Compare January 15, 2025 14:54
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from dbd54dc to 9f87c04 Compare January 15, 2025 15:15
@florianduros florianduros force-pushed the florianduros/reset-encryption branch from 9f87c04 to be9f401 Compare January 15, 2025 15:23
Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

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

Looks like it does what it says it does!

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

generally looks good, a few nits, mostly around the tests

src/rust-crypto/rust-crypto.ts Outdated Show resolved Hide resolved
src/crypto-api/index.ts Outdated Show resolved Hide resolved
src/crypto-api/index.ts Outdated Show resolved Hide resolved
spec/unit/rust-crypto/rust-crypto.spec.ts Outdated Show resolved Hide resolved
spec/unit/rust-crypto/rust-crypto.spec.ts Show resolved Hide resolved
spec/unit/rust-crypto/rust-crypto.spec.ts Outdated Show resolved Hide resolved
spec/unit/rust-crypto/rust-crypto.spec.ts Outdated Show resolved Hide resolved
spec/unit/rust-crypto/rust-crypto.spec.ts Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm

@florianduros florianduros added this pull request to the merge queue Jan 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 22, 2025
@florianduros florianduros added this pull request to the merge queue Jan 22, 2025
Merged via the queue into develop with commit 61375ef Jan 22, 2025
30 checks passed
@florianduros florianduros deleted the florianduros/reset-encryption branch January 22, 2025 11:07
authUploadDeviceSigningKeys,
});

// If key backup was enabled, we create a new backup
Copy link
Member

Choose a reason for hiding this comment

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

Why only if backup was enabled?
That means that if there was a backup that was not working (not trusted signed correctly for example), then the resetEncryption flow won't put me back in a working state?

Maybe what we want to check here is if there was a backup server side, or even better do it unless the opt-out flag is set (account data m.org.matrix.custom.backup_disabled)?

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 the rust-sdk is ultimatly looking at the opt-out flag m.org.matrix.custom.backup_disabled, but there is also a local setting to force disable

/~https://github.com/matrix-org/matrix-rust-sdk/blob/a528624274ecd557427835511eb24513f00696d3/crates/matrix-sdk/src/encryption/recovery/mod.rs#L500-L508

So I believe this code is not consistent with rust.
Even if the rust doc is misleading https://docs.rs/matrix-sdk/latest/matrix_sdk/encryption/recovery/struct.Recovery.html#method.reset_identity

Finally, re-enable key backups (only if they were already enabled)

It is unfortunatly not the same enabled meaning

Copy link
Member

Choose a reason for hiding this comment

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

As discussed elsewhere: ugh, yes, this is not what Element X is doing.

I think we should just enable backups here, regardless of whether they were enabled before. If you're resetting, you're going to be looking at the settings dialog, so can see if you're being opted in to keybackup against your will; and I'd rather err on the side of just making it work for everyone.

Comment on lines +1480 to +1497
const backupEnabled = (await this.backupManager.getActiveBackupVersion()) !== null;

// Disable backup, and delete all the backups from the server
await this.backupManager.deleteAllKeyBackupVersions();

// Disable the recovery key and the secret storage
await this.secretStorage.setDefaultKeyId(null);

// Reset the cross-signing keys
await this.crossSigningIdentity.bootstrapCrossSigning({
setupNewCrossSigning: true,
authUploadDeviceSigningKeys,
});

// If key backup was enabled, we create a new backup
if (backupEnabled) {
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.

while we're here: it would be good to add some logging at the start and end of resetEncryption to make it more obvious what's going on in rageshakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants