clients
clients copied to clipboard
Auth/PM-5268 - DeviceTrustCryptoService state provider migration
Type of change
- [ ] Bug fix
- [X] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
Objective
Resolve PM-5268 and migrate all owned state in the DeviceTrustCryptoService to the new State Provider framework.
Code changes
DeviceTrustCryptoService changes
- libs/common/src/platform/state/state-definitions.ts: Add new
DEVICE_TRUST_DISKto state definitions for disk & local web storage. - libs/common/src/auth/services/device-trust-crypto.service.implementation.ts: Update
DeviceTrustCryptoServiceto state provider framework. - apps/cli/src/bw.ts: Add
stateProviderdependency - apps/browser/src/background/main.background.ts: Add
stateProviderdependency - libs/angular/src/services/jslib-services.module.ts: Add
stateProviderdependency - apps/browser/src/auth/background/service-factories/device-trust-crypto-service.factory.ts: Add
stateProviderdependency - libs/common/src/auth/services/device-trust-crypto.service.spec.ts: Update tests
Data migration
- libs/common/src/state-migrations/migrations/22-migrate-device-trust-crypto-svc-to-state-providers.ts: Add data migration for
DeviceTrustCryptoService.deviceKeyandDeviceTrustCryptoService.shouldTrustDevice - libs/common/src/state-migrations/migrations/22-migrate-device-trust-crypto-svc-to-state-providers.spec.ts: Test migration
- libs/common/src/state-migrations/migrate.ts: Register
DeviceTrustCryptoServiceStateProviderMigratoras latest migration
State Cleanup
- libs/auth/src/common/login-strategies/login.strategy.ts: We no longer need to manually persist the device key on login as the state provider framework does this for us.
- libs/auth/src/common/login-strategies/login.strategy.spec.ts: - Remove no longer necessary test.
- libs/common/src/platform/abstractions/state.service.ts: Remove
getDeviceKey,setDeviceKey,getShouldTrustDevice, andsetShouldTrustDevicemethods - libs/common/src/platform/services/state.service.ts: Remove
getDeviceKey,setDeviceKey,getShouldTrustDevice, andsetShouldTrustDevicemethods - libs/common/src/platform/models/domain/account.ts: Remove
trustDeviceChoiceForDecryptionanddeviceKeyprops from account - libs/common/src/platform/models/domain/account-keys.spec.ts: Remove now unnecessary tests
- apps/desktop/src/platform/services/electron-state.service.ts: Remove device key logic
Screenshots
Data migration working
https://github.com/bitwarden/clients/assets/116684653/00f7640f-1733-4959-a805-807ecf2f96c4
Post migration, device trust is maintained
https://github.com/bitwarden/clients/assets/116684653/0c1b2547-187c-408f-8dfb-471e86aabb94
Post migration, establishing trust on a new device works
https://github.com/bitwarden/clients/assets/116684653/b08b45f3-05fd-4c95-be7c-594c5b6a4333
Before you submit
- Please add unit tests where it makes sense to do so (encouraged but not required)
- If this change requires a documentation update - notify the documentation team
- If this change has particular deployment requirements - notify the DevOps team
- Ensure that all UI additions follow WCAG AA requirements
Checkmarx One – Scan Summary & Details – b9877c67-f902-4361-881a-0e93afe4cd19
No New Or Fixed Issues Found
Codecov Report
Attention: Patch coverage is 73.27586% with 31 lines in your changes are missing coverage. Please review.
Project coverage is 26.90%. Comparing base (
94843bd) to head (8a39b4d).
Additional details and impacted files
@@ Coverage Diff @@
## main #7882 +/- ##
==========================================
+ Coverage 26.83% 26.90% +0.06%
==========================================
Files 2310 2311 +1
Lines 67392 67442 +50
Branches 12627 12641 +14
==========================================
+ Hits 18082 18142 +60
+ Misses 47920 47907 -13
- Partials 1390 1393 +3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Notes for reviewers: Per a discussion between Auth and Platform regarding service design, I refactored all of DeviceTrustCryptoService to accept user id as a required parameter for all methods.