-
-
Notifications
You must be signed in to change notification settings - Fork 255
chore: call revoke token in background #6184
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -654,16 +654,27 @@ export class SeedlessOnboardingController<EncryptionKey> extends BaseController< | |
| revokeToken, | ||
| } = await this.#unlockVaultAndGetVaultData(password); | ||
| this.#setUnlocked(); | ||
|
|
||
| await this.#createNewVaultWithAuthData({ | ||
| password, | ||
| rawToprfEncryptionKey: toprfEncryptionKey, | ||
| rawToprfPwEncryptionKey: toprfPwEncryptionKey, | ||
| rawToprfAuthKeyPair: toprfAuthKeyPair, | ||
| }); | ||
| if (revokeToken) { | ||
| await this.#revokeRefreshTokenAndUpdateState(revokeToken); | ||
| // re-creating vault to persist the new revoke token | ||
| await this.#createNewVaultWithAuthData({ | ||
| password, | ||
| rawToprfEncryptionKey: toprfEncryptionKey, | ||
| rawToprfPwEncryptionKey: toprfPwEncryptionKey, | ||
| rawToprfAuthKeyPair: toprfAuthKeyPair, | ||
| }); | ||
| // this call is not critical for unlocking, so we can do it in the background without await. | ||
| this.#revokeRefreshTokenAndUpdateState(revokeToken) | ||
| .then(() => { | ||
| // re-creating vault to persist the new revoke token | ||
| return this.#createNewVaultWithAuthData({ | ||
| password, | ||
| rawToprfEncryptionKey: toprfEncryptionKey, | ||
| rawToprfPwEncryptionKey: toprfPwEncryptionKey, | ||
| rawToprfAuthKeyPair: toprfAuthKeyPair, | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| log('Error revoking refresh token', error); | ||
| }); | ||
|
Comment on lines
+665
to
+677
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. writing the vault asynchronously like this is dangerous as it can lead to vault corruption. |
||
| } | ||
| }); | ||
| } | ||
|
|
@@ -759,18 +770,30 @@ export class SeedlessOnboardingController<EncryptionKey> extends BaseController< | |
| vaultKey, | ||
| ); | ||
| this.#setUnlocked(); | ||
|
|
||
| if (revokeToken) { | ||
| // revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token | ||
| await this.#revokeRefreshTokenAndUpdateState(revokeToken); | ||
| } | ||
| // re-creating vault to persist the new revoke token | ||
| await this.#createNewVaultWithAuthData({ | ||
| password: globalPassword, | ||
| rawToprfEncryptionKey: latestEncKey, | ||
| rawToprfPwEncryptionKey: latestPwEncKey, | ||
| rawToprfAuthKeyPair: latestAuthKeyPair, | ||
| }); | ||
| if (revokeToken) { | ||
| // // revoke and recyle refresh token after unlock to keep refresh token fresh, avoid malicious use of leaked refresh token | ||
| // // this call is not critical for unlocking, so we can do it in the background without await. | ||
| this.#revokeRefreshTokenAndUpdateState(revokeToken) | ||
| .then(() => { | ||
| // re-creating vault to persist the new revoke token. | ||
| // TODO: Optimize this function such that updates to vault wont require re-creating the vault. | ||
| return this.#createNewVaultWithAuthData({ | ||
| password: globalPassword, | ||
| rawToprfEncryptionKey: latestEncKey, | ||
| rawToprfPwEncryptionKey: latestPwEncKey, | ||
| rawToprfAuthKeyPair: latestAuthKeyPair, | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| log('Error revoking refresh token', error); | ||
| }); | ||
|
Comment on lines
+782
to
+795
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see comment above, we can't do this |
||
| } | ||
|
|
||
| // restore the current keyring encryption key with the new global password | ||
| await this.storeKeyringEncryptionKey(keyringEncryptionKey); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that
#createNewVaultWithAuthDatais potentially an expensive operation.it runs
encryptWithDetail(pw, vaultData), which involves the intentionally slow pbkdf2 key derivation step.as you are increasing the usage of vault encryption, you are driving up cpu usage.