-
-
Notifications
You must be signed in to change notification settings - Fork 254
refactor!: KeyringController always derives encryption key
#7128
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
base: main
Are you sure you want to change the base?
refactor!: KeyringController always derives encryption key
#7128
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
8f04566 to
ad1ae0d
Compare
| state.encryptionSalt = updatedState.encryptionSalt; | ||
| } | ||
| state.encryptionKey = encryptionKey; | ||
| state.encryptionSalt = parsedEncryptedVault.salt; |
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.
I think there is a potential bug here:
Above you set
this.#setEncryptionKey(
credentials.encryptionKey,
credentials.encryptionSalt || parsedEncryptedVault.salt,
);but here you set
state.encryptionSalt = parsedEncryptedVault.salt;Shouldn't this be:
state.encryptionSalt = this.#encryptionKey.salt;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.
As we are decrypting the vault here, the existing vault salt and this.#encryptionKey.salt should always be the same, even when the salt is undefined, right?
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.
Yeah, we have a check to ensure they are the same in #setEncryptionKey. See where we throw the KeyringControllerError.ExpiredCredentials error.
Though... it is a bit confusing that the guarantee about these being the same is in a different function 🤔. Perhaps it would be simplest to use this.#encryptionKey.salt; just so the reader doesn't need to understand where it was validated?
Potentially a slight readability improvement here, but I don't think it's a bug
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.
That makes sense. I was being conservative on what was there before, but I agree that using this.#encryptionKey.salt is clearer, and should be equivalent. Done in c59a9c1
5f8200d to
54baecf
Compare
the package was also updated to ^6.0.0
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Explanation
This PR extracts the second and final set of changes from #5963, which refactors the
KeyringControllerto always derive the encryption key from the password, rather than storing it in memory.This change allows to simplify
#unlockKeyringsand#updateVaultmethods, after the removeal of all the logic and tests related tocacheEncryptionKey. This also allows to removethis.#password, that has been replaced bythis.#encryptionKey.The
this.#encryptionKeyassignment logic has been moved to two new internal methods with these specific responsibilities:#deriveEncryptionKey(string): Derives the encryption key from the password, to be used during password login and password change.#useEncryptionKey(string, string): Uses an existing encryption key to be used directly, to be used bysubmitEncryptionKeymainly.Package previews from this branch are tested on clients with these PRs:
@metamask/{keyring,seedless-onboarding}-controllermetamask-extension#37454@metamask/keyring-controllermetamask-mobile#22240References
Checklist
Note
Refactors vault encryption in KeyringController to derive/use a serialized encryption key (not password), adds required encryptor methods, updates tests, and bumps browser-passworder to v6.
encryptionKeywithsalt; remove password caching and related logic.#deriveAndSetEncryptionKeyand#setEncryptionKey; reworksubmitPassword,submitEncryptionKey,changePassword,#updateVault, and#unlockKeyringsto use imported/exported keys.WrongEncryptionKeyTypeerror; persistencryptionKey/encryptionSaltconsistently; remove use of old cached-key upgrade path.Encryptorinterface to requireexportKey,keyFromPassword, andgenerateSalt.jest.config.js.exportKey,keyFromPassword,generateSalt; adapt tests accordingly.@metamask/browser-passworderto^6.0.0in affected packages.yarn.lockaccordingly.Written by Cursor Bugbot for commit 7b3eef0. This will update automatically on new commits. Configure here.