Skip to content

[PM-22271] Switch to SDK argon2 implementation, and drop other impls #15401

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

Merged
merged 16 commits into from
Jul 15, 2025

Conversation

quexten
Copy link
Contributor

@quexten quexten commented Jun 30, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-22271
bitwarden/sdk-internal#339

📔 Objective

We want to drop our three different argon2 implementations on clients (desktop-native rustcrypto, patched argon2-browser WASM, native C++ module on cli). Each of these have impactful bugs (https://bitwarden.atlassian.net/browse/PM-17450, https://bitwarden.atlassian.net/browse/PM-22217), and tech debt (dependency updates, and the patching scripts for node modules) associated.

For this we switch out the implementation of derive kdf key, and drop the argon2 dependencies and patch scripts / webpack configs.

📸 Screenshots

⏰ 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

@quexten quexten changed the title Switch to SDK argon2 implementation [PM-22271] Switch to SDK argon2 implementation, and drop other impls Jun 30, 2025
Copy link
Contributor

github-actions bot commented Jun 30, 2025

Logo
Checkmarx One – Scan Summary & Details72402d32-c219-40d0-93a5-fb308fc1bf7b

Great job, no security vulnerabilities found in this Pull Request

@dani-garcia
Copy link
Member

dani-garcia commented Jun 30, 2025

Finally, these dependencies have caused so many compile issues in the past.

You should also remove the dependencies from the renovate config:

"@types/argon2-browser",
"aes",
"argon2",
"argon2-browser",

Edit:
Also the CLI package.json:

"../../node_modules/argon2/**/*"
]
},
"dependencies": {
"@koa/multer": "3.1.0",
"@koa/router": "13.1.0",
"argon2": "0.41.1",

quexten added a commit to bitwarden/sdk-internal that referenced this pull request Jul 3, 2025
## 🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-22271
bitwarden/clients#15401

## 📔 Objective

We want to drop our three different argon2 implementations on `clients`
(desktop-native rustcrypto, patched argon2-browser WASM, native C++
module on cli). Each of these have impactful bugs
(https://bitwarden.atlassian.net/browse/PM-17450,
https://bitwarden.atlassian.net/browse/PM-22217), and tech debt
(dependency updates, and the patching scripts for node modules)
associated.

In this case, there is a small amount of tech debt introduced in the SDK
because we introduce a deprecated function on PureCrypto. This small
amount of tech debt introduced is far outweight by the dependencies that
can be dropped on ts. (The clients PR: <img width="128" alt="image"
src="https://github.com/user-attachments/assets/642c6ee8-2df3-406c-aba1-167a1647b65d"
/>)


Specifically, since we want to fix immediate bugs, we do not yet do the
work of porting all higher-level usages (masterpassword-unlock,
masterkeyhash auth, pin unlock/enrollment, send password "key"(hash)
deriving) to the SDK. This is follow-up feature work, and larger in
scope, and involves other teams (auth,tools). Once this follow-up
feature-work is complete, the tech-debt function introduced in this
ticket will be removed, and a tech-debt ticket for this is linked.

The tech debt function is clearly marked as `dangerous_` and
`deprecated` with a note.

## ⏰ 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

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- 👍 (`:+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
@quexten
Copy link
Contributor Author

quexten commented Jul 3, 2025

Blocked by #15408 since the client init had a breaking change in the SDK.

@quexten quexten marked this pull request as ready for review July 8, 2025 12:39
@quexten quexten requested review from a team as code owners July 8, 2025 12:39
@quexten quexten requested review from mzieniukbw and addisonbeck July 8, 2025 12:39
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Project coverage is 37.55%. Comparing base (1b1361f) to head (c099d47).
Report is 5 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...on/src/platform/services/key-generation.service.ts 50.00% 4 Missing ⚠️
apps/desktop/src/main.ts 0.00% 3 Missing ⚠️
apps/desktop/src/app/services/services.module.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15401      +/-   ##
==========================================
- Coverage   37.56%   37.55%   -0.02%     
==========================================
  Files        3301     3299       -2     
  Lines       93914    93817      -97     
  Branches    14139    14130       -9     
==========================================
- Hits        35279    35232      -47     
+ Misses      57175    57125      -50     
  Partials     1460     1460              

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dani-garcia
Copy link
Member

There's still a reference to the argon2 npm package in the cli assets section:

"pkg": {
"assets": [
"./build/**/*",
"../../node_modules/argon2/**/*"

Also the web webpack config:

module: {
noParse: /argon2(-simd)?\.wasm$/,

And while the NAPI code was deleted, the generated TS file wasn't updated:

export function argon2(secret: Buffer, salt: Buffer, iterations: number, memory: number, parallelism: number): Promise<Buffer>

@quexten
Copy link
Contributor Author

quexten commented Jul 8, 2025

Fixed the remaining references.

mzieniukbw
mzieniukbw previously approved these changes Jul 8, 2025
Copy link
Contributor

@mzieniukbw mzieniukbw left a comment

Choose a reason for hiding this comment

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

nice!

@@ -35,7 +35,7 @@ describe("MainBiometricsService", function () {
const windowMain = mock<WindowMain>();
const logService = mock<LogService>();
const biometricStateService = mock<BiometricStateService>();
const cryptoFunctionService = mock<MainCryptoFunctionService>();
const cryptoFunctionService = mock<NodeCryptoFunctionService>();
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ why not just use CryptoFunctionService ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I just grep replaced main-crypto-function-service with node-crypto-function-service after deleting it here. I'll simplify to CryptoFunctionService.

addisonbeck
addisonbeck previously approved these changes Jul 8, 2025
mzieniukbw
mzieniukbw previously approved these changes Jul 8, 2025
@quexten quexten dismissed stale reviews from mzieniukbw and addisonbeck via c099d47 July 14, 2025 17:19
Copy link

@quexten quexten merged commit 8250e40 into main Jul 15, 2025
96 of 97 checks passed
@quexten quexten deleted the km/pm-22271/remove-argon2-impl branch July 15, 2025 09:54
quexten added a commit that referenced this pull request Jul 15, 2025
…15401)

* Switch to SDK argon2 implementation

* Cleanup and update to the latest sdk

* Update package lock

* Remove copy patch

* Fix builds

* Fix test build

* Remove error

* Fix tests

* Fix build

* Run prettier

* Remove argon2 references

* Regenerate index.d.ts for desktop_native napi

* Replace mocked crypto function service type

(cherry picked from commit 8250e40)
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.

Desktop app crash after password insertion Failed to build on macos 15 Bitwarden AppImage crashes, cant get in to my vault
4 participants