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

Bump keyring-controller and browser-passworder #21878

Merged
merged 22 commits into from
Dec 7, 2023

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Nov 17, 2023

Description

This PR bumps these package versions:

  • @metamask/keyring-controller to ^9.0.0
  • @metamask/browser-passworder to ^4.3.0
  • @metamask/eth-keyring-controller to ^15.1.0

This set of updates brings a change in the way encryption keys are derived from the user password.

To allow encryption with different iteration numbers (e.g. for different use cases), and to easily change these iterations independently in the future, an encryptor factory has been added.

For performance reasons, @metamask/eth-keyring-controller has been fixed to prefer the cached encryption key over the password (it will not derive it again), when it is initialized with cacheEncryptionKey: true and the encryptor supports it (which is the case with @metamask/browser-passworder) - for this reason, this change only impacts the login UX, instead of every user interaction with the keychain.

The encryptor for Snaps has been set lower for now.

Related issues

n/a

Manual testing steps

  1. Unlock an existing vault should work
  2. Locking and unlocking again should still work

Note from DanM: probably a good idea to test this on a lower powered machine to see the performance impact. Test the before and after impact on performance of logging in, going from the unlock screen to the home screen.

These changes might have a UX impact on slower devices, for the following actions:

  • Wallet unlock
  • Actions on KeyringController (or direct keyrings) that end with a call to persistAllKeyrings, which derives the encryption key again and re-encrypt the vault. e.g.:
    • Creating first seed phrase
    • Importing an existing seed phrase
    • Add an account
    • Remove an account
    • Connecting a hardware wallet of any kind
    • Adding a keyring
    • Removing a keyring
    • Importing account
    • (I might be forgetting something)
  • Snaps interactions: some of them call encrypt / decrypt, which also derive the key before/after all the interactions
  • There might be some UX oddities that we never noticed because of the fast derivation time, but that might be noticeable now (see this as an example)

Screenshots/Recordings

n/a

Before

n/a

After

n/a

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@mikesposito mikesposito requested a review from a team as a code owner November 17, 2023 13:19
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@mikesposito mikesposito marked this pull request as draft November 17, 2023 13:19
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Nov 17, 2023
Copy link

socket-security bot commented Nov 17, 2023

New and updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/eth-keyring-controller 15.1.0 None +2 256 kB gudahtt
@metamask/keyring-controller 9.0.0 None +3 402 kB metamaskbot
@metamask/eth-trezor-keyring 2.0.0...3.0.0 None +0/-6 82.3 kB metamaskbot

@mikesposito mikesposito force-pushed the chore/bump-browser-passworder branch 2 times, most recently from f17aac4 to 07faa5f Compare November 20, 2023 11:36
@mikesposito

This comment was marked as outdated.

@metamaskbot metamaskbot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Nov 20, 2023
@metamaskbot

This comment was marked as outdated.

@mikesposito mikesposito marked this pull request as ready for review November 20, 2023 12:08
@mikesposito mikesposito requested review from a team as code owners November 20, 2023 12:08
@mikesposito mikesposito force-pushed the chore/bump-browser-passworder branch 2 times, most recently from 51a9958 to 8c166cf Compare November 20, 2023 14:24
@mikesposito

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

The applied fix has been ported upstream

mcmire
mcmire previously approved these changes Nov 20, 2023
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good!

@mikesposito
Copy link
Member Author

mikesposito commented Nov 21, 2023

Uhm, looks like some of the tests intermittently fail, with a timeout error. Most of them seem to be unrelated (or not directly related at least) to a change in the encryption or the vault - This makes me think that the increased time needed by the key derivation might take up too much of the test case time, which ultimately leads to a timeout in some cases: this would explain a similar test flakiness

@mikesposito
Copy link
Member Author

After some local debugging, I think I have a clearer idea of why this happens.

Some of our test cases open external pages in the browser to test dapp features, and these tests take action on these pages right after the login. Some of them explicitly wait some time (with driver.delay(1000);), some others don't wait at all: this was ok-ish when the key derivation and vault decryption was fast, because the login operation used to end before the external pages were loaded, but now that the decryption is much slower this assumption is wrong because this happens:

  1. The test case inputs the password, then clicks on login
  2. The test case immediately opens an external page
  3. The test case immediately executes an action on the test dapp
  4. The pop-up (any pop-up screen, like the one to sign for example) will open, but instead of showing the expected screen, it will show the login screen to input the password, as the decryption is still happening on the main initial view.
  5. The test fails with a timeout, as the screen expected by the test will never show up

Not all tests are affected, as some of them don't use external pages, and some of them wait ~1 sec before taking actions on dapps, but this issue makes the tests completely flaky and dependent on the resources available on the system that runs them.

@mikesposito
Copy link
Member Author

mikesposito commented Nov 21, 2023

The solution can be to use a shared helper login function to be used by all tests. This function would:

  1. Input the password, press on login
  2. Wait for the login to actually end
  3. Resolve, giving the control back to the test

This will ensure that by the time the tests use dapps (or any other operation that needs the login), the wallet will be already unlocked. I will address this issue in a separate PR for ease of review.

EDIT: Issue tracked by #21914 and fixed by #21915

@mikesposito

This comment was marked as outdated.

@metamaskbot

This comment was marked as outdated.

@mikesposito mikesposito force-pushed the chore/bump-browser-passworder branch from aad500d to 9a5edec Compare December 6, 2023 13:38
@mikesposito
Copy link
Member Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policy update failed. You can review the logs or retry the policy update here

@mikesposito mikesposito force-pushed the chore/bump-browser-passworder branch from 668957e to 0780ec6 Compare December 6, 2023 14:19
@metamaskbot
Copy link
Collaborator

Builds ready [0780ec6]
Page Load Metrics (1397 ± 138 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint873771618038
domContentLoaded10195334823
load83818331397287138
domInteractive10195334823
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -129.58 KiB (-3.48%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

legobeat
legobeat previously approved these changes Dec 7, 2023
yarn.lock Outdated Show resolved Hide resolved
@metamaskbot
Copy link
Collaborator

Builds ready [96a1a43]
Page Load Metrics (1335 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint891501162110
domContentLoaded9321563
load91116381335212102
domInteractive9321563
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -129.58 KiB (-3.48%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@legobeat legobeat left a comment

Choose a reason for hiding this comment

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

Have not performed manual testing but changes LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [c33de4f]
Page Load Metrics (1386 ± 135 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint862721514823
domContentLoaded9179374622
load79918121386280135
domInteractive9179374622
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -294.98 KiB (-7.93%)
  • ui: 0 Bytes (0.00%)
  • common: -2 Bytes (-0.00%)

@mikesposito
Copy link
Member Author

Bundle size diffs [🚀 Bundle size reduced!]
background: -294.98 KiB (-7.93%)

‼️

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks great!

@@ -315,6 +315,7 @@ const importSRPOnboardingFlow = async (driver, seedPhrase, password) => {
await driver.fill('[data-testid="create-password-confirm"]', password);
await driver.clickElement('[data-testid="create-password-terms"]');
await driver.clickElement('[data-testid="create-password-import"]');
await driver.waitForElementNotPresent('.loading-overlay');
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could extract this to a function whose name reflects this need in the future if we forget this, but this makes sense for now!

@mikesposito mikesposito merged commit a6b592d into develop Dec 7, 2023
66 of 67 checks passed
@mikesposito mikesposito deleted the chore/bump-browser-passworder branch December 7, 2023 16:40
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
@metamaskbot metamaskbot added the release-11.8.0 Issue or pull request that will be included in release 11.8.0 label Dec 7, 2023
@legobeat
Copy link
Contributor

legobeat commented Dec 7, 2023

Bundle size diffs [🚀 Bundle size reduced!]
background: -294.98 KiB (-7.93%)

‼️

Catching up on and deduping dependencies starting to pay off !

@metamaskbot metamaskbot added release-11.7.4 Issue or pull request that will be included in release 11.7.4 and removed release-11.8.0 Issue or pull request that will be included in release 11.8.0 labels Jan 8, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-11.7.4 on PR. Adding release label release-11.7.4 on PR and removing other release labels(release-11.8.0), as PR was cherry-picked in branch 11.7.4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.7.4 Issue or pull request that will be included in release 11.7.4 team-wallet-framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants