-
Notifications
You must be signed in to change notification settings - Fork 927
[PM-23278] Upgrade user KDF settings to minimums #5955
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
Conversation
# Conflicts: # app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt # app/src/main/kotlin/com/x8bit/bitwarden/ui/platform/feature/debugmenu/components/FeatureFlagListItems.kt # app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt # app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/handlers/VaultHandlers.kt # app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt # core/src/main/kotlin/com/bitwarden/core/data/manager/model/FlagKey.kt # network/src/main/kotlin/com/bitwarden/network/service/AccountsService.kt # network/src/main/kotlin/com/bitwarden/network/service/AccountsServiceImpl.kt # network/src/test/kotlin/com/bitwarden/network/service/AccountsServiceTest.kt # ui/src/main/res/values/strings.xml
…esponses, and save to profile.
…minimum # Conflicts: # app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt # core/src/main/kotlin/com/bitwarden/core/data/manager/model/FlagKey.kt
|
New Issues (2)Checkmarx found the following issues in this Pull Request
|
app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt
Dismissed
Show dismissed
Hide dismissed
app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt
Fixed
Show fixed
Hide fixed
app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt
Fixed
Show fixed
Hide fixed
app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt
Fixed
Show fixed
Hide fixed
app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt
Fixed
Show fixed
Hide fixed
| .updateKdfToMinimumsIfNeeded(password = password) | ||
| .also { result -> | ||
| if (result is UpdateKdfMinimumsResult.Error) { | ||
| Timber.e("Failed to silent update KDF settings: ${result.error}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do Timber.e(result.error, "Failed to silently update KDF settings.")?
| ) | ||
| .also { result -> | ||
| if (result is UpdateKdfMinimumsResult.Error) { | ||
| Timber.e("Failed to silent update KDF settings: ${result.error}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do
Timber.e(result.error, "Failed to silently update KDF settings.")
| * @param onDismissRequest called when the user attempts to dismiss the dialog (for example by | ||
| * tapping outside of it). | ||
| */ | ||
| @Suppress("LongMethod") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you double check if this is needed? I removed it and detekt didn't complain. 🤔
| .asText(), | ||
| error = result.error, | ||
| ) | ||
| Timber.e(message = "Failed to update kdf to minimums: ${result.error}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another place we can pass the error as an arg instead.
Timber.e(result.error, "Failed to update kdf to minimums.")
🤔 Is this actually needed since we're logging errors in the data layer?
ui/src/main/res/values/strings.xml
Outdated
| <string name="kdf_update_failed_active_account_not_found">"Kdf update failed, active account not found. Please try again or contact us."</string> | ||
| <string name="an_error_occurred_while_trying_to_update_your_kdf_settings">"An error occurred while trying to update your kdf settings. Please try again or contact us."</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be surrounded by quotes? If so, we should be using the “ and ” chars for opening and closing quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outer quotes like this do not actually appear in the displayed string, I actually just removed a bunch of these. I think they should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch!
SaintPatrck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments. Overall, it's looking good. Great job!
| kdf = Kdf.Pbkdf2(iterations = DEFAULT_PBKDF2_ITERATIONS.toUInt()), | ||
| ) | ||
| .fold( | ||
| onSuccess = { updateKdfOnServer(createUpdateKdfRequest(it)) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| private suspend fun updateKdfOnServer(request: UpdateKdfJsonRequest): UpdateKdfMinimumsResult { | ||
| return accountsService | ||
| .updateKdf(body = request) | ||
| .fold( | ||
| onSuccess = { | ||
| authDiskSource.userState = authDiskSource.userState | ||
| ?.toUserStateJsonKdfUpdatedMinimums() | ||
| UpdateKdfMinimumsResult.Success | ||
| }, | ||
| onFailure = { UpdateKdfMinimumsResult.Error(error = it) }, | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that request creation is extracted, but I think this introduces an unnecessary fold operation. vaultSdkSource.makeUpdateKdf().flatMap will handle mapping a successful result to the result of accountsService.updateKdf(), then you only have to handle failures once, in the final fold().
return vaultSdkSource
.makeUpdateKdf()
.flatMap { response ->
accountsService.updateKdf(
request = createUpdateKdfRequest(response)
)
}
.fold(
onSuccess = {
authDiskSource.userState = authDiskSource.userState
?.toUserStateJsonKdfUpdatedMinimums()
UpdateKdfMinimumsResult.Success
},
onFailure = { UpdateKdsMinimumsResult.Error(error = it) },
)
SaintPatrck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for that. LGTM
# Conflicts: # app/src/main/kotlin/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt # app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt # app/src/test/kotlin/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt
14c4700


Note
Depends on PR: #5944
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-23278
https://bitwarden.atlassian.net/browse/PM-23577
📔 Objective
This pull request introduces functionality to ensure user KDF (Key Derivation Function) settings meet minimum security requirements. It adds logic to check if an account's KDF configuration is outdated and, if so, updates it automatically after password unlock, provided the relevant feature flag is enabled. The changes also include necessary model, service, and dependency updates to support this workflow.
KDF Minimums Enforcement and Update Workflow
AuthRepositoryandAuthRepositoryImplto check if a user's KDF settings are below the minimum and to update them if needed, including integration with a feature flag (ForceUpdateKdfSettings). [1] [2]Model and SDK Support
UpdateKdfMinimumsResultsealed class to model the result of updating KDF settings.makeUpdateKdfmethod toVaultSdkSourceand its implementation to generate updated KDF data using the SDK. [1] [2]toKdfRequestModelto convert SDK KDF objects to network request models.Dependency Injection and Feature Flag Integration
AuthRepositoryModule) to provideFeatureFlagManagertoAuthRepositoryImpl. [1] [2] [3]📸 Screenshots
Screen.Recording.2025-10-02.at.09.24.01.mov
⏰ Reminders before review
🦮 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