bitwarden / sdk

Bitwarden SDK.
Other
205 stars 37 forks source link

Make client internally mutable #837

Closed dani-garcia closed 3 weeks ago

dani-garcia commented 3 weeks ago

📔 Objective

We're having some deadlock problems with the Passkey API by calling certain SDK functions on the passkey-rs callbacks. These issues are caused because we're holding a reference to the RwLock during the execution of the Passkey operation and so calling into the SDK from inside that will deadlock.

To solve it we can't just use a lock at the client level, and so we need to move to using interior mutability, I've revived an old PR (#70) where we started doing that.

This PR is split into two commits, for ease of review:

Some notes of what the change entails:

I hate that Mutex and RwLock return a Result in case they are poisoned, that's never our case and it makes their usage so cumbersome 😢

Note: I've tried to change the smallest amount of code to make the change, so the secrets manager APIs (and bitwarden-json) are still mutable. If we're okay with these changes I can go back to update those in a separate PR.

⏰ Reminders before review

🦮 Reviewer guidelines

github-actions[bot] commented 3 weeks ago

Logo Checkmarx One – Scan Summary & Details7e2fdc15-9cf0-41fa-a91e-b844ec2eca82

No New Or Fixed Issues Found

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 47.31458% with 206 lines in your changes missing coverage. Please review.

Project coverage is 60.07%. Comparing base (e5a8dba) to head (46f4b2c).

Files Patch % Lines
crates/bitwarden-uniffi/src/auth/mod.rs 0.00% 18 Missing :warning:
crates/bitwarden-uniffi/src/tool/sends.rs 0.00% 15 Missing :warning:
crates/bitwarden/src/client/client.rs 85.29% 15 Missing :warning:
crates/bitwarden/src/auth/renew.rs 50.00% 12 Missing :warning:
crates/bitwarden-uniffi/src/crypto.rs 0.00% 11 Missing :warning:
crates/bitwarden-uniffi/src/platform/fido2.rs 0.00% 10 Missing :warning:
crates/bitwarden/src/auth/client_auth.rs 25.00% 9 Missing :warning:
crates/bitwarden-uniffi/src/tool/mod.rs 0.00% 8 Missing :warning:
crates/bitwarden-uniffi/src/vault/ciphers.rs 0.00% 8 Missing :warning:
crates/bitwarden-uniffi/src/vault/attachments.rs 0.00% 7 Missing :warning:
... and 35 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #837 +/- ## ========================================== + Coverage 59.22% 60.07% +0.85% ========================================== Files 186 186 Lines 12396 12246 -150 ========================================== + Hits 7341 7357 +16 + Misses 5055 4889 -166 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.