Skip to content

[PM-35395] MasterPasswordService Key Management Integration#7637

Open
enmande wants to merge 11 commits into
auth/pm-35393/master-password-service-auth-integrationfrom
auth/pm-35395/master-password-service-km-integration
Open

[PM-35395] MasterPasswordService Key Management Integration#7637
enmande wants to merge 11 commits into
auth/pm-35393/master-password-service-auth-integrationfrom
auth/pm-35395/master-password-service-km-integration

Conversation

@enmande
Copy link
Copy Markdown
Contributor

@enmande enmande commented May 14, 2026

🎟️ Tracking

PM-35395

📔 Objective

Refactors the Change-KDF flow to use the new MasterPasswordService, routing through SaveUpdateKdfConfigurationAsync (source).

📓 Note the name change from the base branch of invoked method to SaveUpdateKdfConfigurationAsync.
At implementation time, it was decided SaveUpdateMasterPasswordAndKdfAsync was not an ideal name for this method. It is used for KDF-affecting flows (only); the fact that the hash of a master password will change as a result of key derivation is a side effect, and naming it in the method directly invites misunderstanding. Tests and comments were updated throughout to reflect this.

Part of the PM-33011 story-of-stories to route all password set/change/rotate flows through MasterPasswordService. Depends on PM-35393.

📸 Screenshots

KDF Configuration change

zed is a user with a Master Password.

zed changes their KDF configuration: PBKDF2 -> Argon2id with default settings.

  • Stored hash-of-hash for Master Password is updated
  • LastKdfChangeDate is updated as expected
  • LastMasterPasswordChangeDate is not updated as expected
  • Appropriate KDF configurations are updated
PM-39395_kdf-change.mov

enmande added 8 commits May 14, 2026 11:06
Master Password hash will be updated as a necessary side-effect of KDF
configuration change, but should not be represented in the method naming
to prevent confusion. This is for KDF-update flows only.
Mismatched salt should fail fast at the command level (existing).
A defense-in-depth check also resides at ValidateDataForUser inside the
MasterPasswordService.
@enmande enmande added needs-qa ai-review Request a Claude code review labels May 14, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Refactors ChangeKdfCommand to route through IMasterPasswordService.SaveUpdateExistingKdfConfigurationAsync, consolidating user mutation and persistence in a single service call. Includes a rename from *MasterPasswordAndKdf to *KdfConfiguration to better reflect that this flow updates KDF parameters and re-derives the authentication hash without changing the user's password. Removes the now-unnecessary LastPasswordChangeDate update on KDF rotation and migrates command tests to mock IMasterPasswordService. No new findings; prior threads on LastPasswordChangeDate semantics and redundant salt validation have been addressed by the author.

Code Review Details

No new findings.

// LastPasswordChangeDate is intentionally not set: KDF rotation re-derives the authentication
// hash from the same password using new KDF parameters — the user's password has not changed.
var now = _timeProvider.GetUtcNow().UtcDateTime;
user.LastPasswordChangeDate = now;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This method incorrectly indexed on a change of hash to warrant an update to the LastPasswordChangeDate. KDF- and Master Password-change operations are separate, and LastPasswordChangeDate is intended to capture the user action/intent to change the Master Password.

LastKdfChangeDate is provided to separate these concerns.

Comment thread test/Core.Test/KeyManagement/Kdf/ChangeKdfCommandTests.cs Outdated
// Prevent a de-synced salt value from creating an un-decryptable unlock method
// Prevent a de-synced salt value from creating an un-decryptable unlock method.
// Also checked in the MasterPasswordService via UpdateExistingKdfConfigurationData.ValidateDataForUser.
authenticationData.ValidateSaltUnchangedForUser(user);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

MasterPasswordService will perform salt-unchanged validation for authentication and unlock data requests consistently. That makes this check (now) an additional check of the same.

I have elected not to remove it from the command at this time, considering that up to Key Management's discretion.

@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.86%. Comparing base (eeb3dd5) to head (848f6d7).

Additional details and impacted files
@@                                    Coverage Diff                                     @@
##           auth/pm-35393/master-password-service-auth-integration    #7637      +/-   ##
==========================================================================================
- Coverage                                                   59.87%   59.86%   -0.02%     
==========================================================================================
  Files                                                        2124     2124              
  Lines                                                       93469    93463       -6     
  Branches                                                     8307     8307              
==========================================================================================
- Hits                                                        55965    55950      -15     
- Misses                                                      35527    35534       +7     
- Partials                                                     1977     1979       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@enmande enmande marked this pull request as ready for review May 14, 2026 19:16
@enmande enmande requested review from a team as code owners May 14, 2026 19:16
@enmande enmande requested review from JaredSnider-Bitwarden, ike-kottlowski and mzieniukbw and removed request for a team and JaredSnider-Bitwarden May 14, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review needs-qa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant