Skip to content

[PM-24051] MasterPasswordUnlockData model with response mapping and adds it to identity success response model #376

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

mzieniukbw
Copy link
Contributor

@mzieniukbw mzieniukbw commented Aug 5, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-24051

📔 Objective

Adds MasterPasswordUnlockData model with MasterPasswordUnlockResponseModel mapping. This wi
Adds UserDecryptionOptionsResponseModel into the identity success token response. This model includes the master password unlock field.
The /sync response model is autogenerated by OpenApi and already includes user decryption option and the master password unlock fields.
Includes Uniffi and WASM bindings for MasterPasswordUnlock.

In further PR's we plan to use the MasterPasswordUnlock in InitUserCryptoMethod enum - this is still in discussion.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Aug 5, 2025

Logo
Checkmarx One – Scan Summary & Details2655eb53-8e8e-4df0-9bcd-e467613a40ae

Great job! No new security vulnerabilities introduced in this pull request

Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 90.13453% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.35%. Comparing base (bceb681) to head (2591773).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...twarden-core/src/key_management/user_decryption.rs 0.00% 19 Missing ⚠️
...twarden-core/src/key_management/master_password.rs 98.52% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #376      +/-   ##
==========================================
+ Coverage   74.19%   74.35%   +0.16%     
==========================================
  Files         253      255       +2     
  Lines       21897    22120     +223     
==========================================
+ Hits        16247    16448     +201     
- Misses       5650     5672      +22     

☔ 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.

@mzieniukbw mzieniukbw requested review from a team and quexten and removed request for a team August 5, 2025 11:08
@mzieniukbw mzieniukbw marked this pull request as ready for review August 5, 2025 14:51
@mzieniukbw mzieniukbw requested a review from a team as a code owner August 5, 2025 14:51
@mzieniukbw mzieniukbw requested a review from justindbaur August 5, 2025 14:51
Copy link
Contributor

@quexten quexten left a comment

Choose a reason for hiding this comment

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

Some initial comments, some of these are required, some are idiomatic (but probably required since the quality bar for SDK seems to be set much higher).

I'd like a review from someone with more rust experience such as @Hinton or @dani-garcia too. I believe specifically the request parsing is something that has not existed in the SDK so far, and there may be a better way to do this that we're unaware of.

@mzieniukbw mzieniukbw requested a review from quexten August 8, 2025 09:42
Copy link
Contributor

@quexten quexten left a comment

Choose a reason for hiding this comment

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

Looking pretty nice now! Some more smaller items that improve usability by teams unfamiliar with the code (docs / error names)

@Hinton
Copy link
Member

Hinton commented Aug 11, 2025

This tightly couples consumers of the SDK to the server generated bindings which is somewhat dangerous. We've previously addressed this by wrapping requests/responses in a manner that more accurately represents the action from the SDK's perspective. There be dragons here and we should consider this a bit.

Do we expect to do similar things to other request/responses? If not I think we should simply wrap the logic with our own struct, while it's a few lines of boilerplate it reduces the complexity.

Includes Uniffi and WASM support.

There is no UniFFI support here.

@mzieniukbw mzieniukbw marked this pull request as draft August 13, 2025 17:17
@mzieniukbw mzieniukbw marked this pull request as ready for review August 13, 2025 20:02
@mzieniukbw mzieniukbw requested review from Hinton and quexten August 13, 2025 20:02
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

issue: The PR title mentions sync response, there is nothing touching sync here.

We should be careful about introducing public objects that are not consumed. Once something is public it's technically a breaking change to flip the visibility and if you don't know fully what needs to be public it's easy to accidentally leave public remnants that should be private.

In these case just making items private and going back later and flipping the visibility where necessary can be useful. Which can also assist with documentation since documentation should be written from the consumers standpoint which is hard when you don't have the interfaces making it public.

Comment on lines +60 to +71
memory: kdf_parse_nonzero_u32(
response
.kdf
.memory
.ok_or(MasterPasswordError::KdfMalformed)?,
)?,
parallelism: kdf_parse_nonzero_u32(
response
.kdf
.parallelism
.ok_or(MasterPasswordError::KdfMalformed)?,
)?,
Copy link
Member

Choose a reason for hiding this comment

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

question: Is there a reason for not just using require!?

Suggested change
memory: kdf_parse_nonzero_u32(
response
.kdf
.memory
.ok_or(MasterPasswordError::KdfMalformed)?,
)?,
parallelism: kdf_parse_nonzero_u32(
response
.kdf
.parallelism
.ok_or(MasterPasswordError::KdfMalformed)?,
)?,
memory: kdf_parse_nonzero_u32(require!(response.kdf.memory))?,
parallelism: kdf_parse_nonzero_u32(require!(response.kdf.parallelism))?,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@quexten pointed out, that it might be better to consolidate all KDF related verification into the KdfMalformed error. Using require! would provide non-KDF specific error.

@mzieniukbw mzieniukbw changed the title [PM-24051] In identity and sync response & decryption options, add MasterPasswordUnlockDataResponse in response model [PM-24051] MasterPasswordUnlockData model with response mapping and adds it to identity success response model Aug 15, 2025
@mzieniukbw mzieniukbw requested a review from Hinton August 15, 2025 13:12
Copy link

Copy link
Contributor

@quexten quexten 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 from my side.

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

Successfully merging this pull request may close these issues.

3 participants