-
Notifications
You must be signed in to change notification settings - Fork 1k
PM-31118: feat: Add support for SDK pin unlock #7289
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.vault.repository | |
|
|
||
| import com.bitwarden.core.InitUserCryptoMethod | ||
| import com.bitwarden.core.data.manager.dispatcher.DispatcherManager | ||
| import com.bitwarden.core.data.manager.model.FlagKey | ||
| import com.bitwarden.core.data.repository.error.MissingPropertyException | ||
| import com.bitwarden.core.data.repository.model.DataState | ||
| import com.bitwarden.core.data.repository.util.bufferedMutableSharedFlow | ||
|
|
@@ -22,6 +23,7 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource | |
| import com.x8bit.bitwarden.data.auth.repository.util.toSdkParams | ||
| import com.x8bit.bitwarden.data.autofill.util.login | ||
| import com.x8bit.bitwarden.data.platform.error.NoActiveUserException | ||
| import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager | ||
| import com.x8bit.bitwarden.data.platform.util.isActive | ||
| import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource | ||
| import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource | ||
|
|
@@ -70,7 +72,7 @@ import javax.crypto.Cipher | |
| * Default implementation of [VaultRepository]. | ||
| */ | ||
| @Suppress("TooManyFunctions", "LongParameterList") | ||
| class VaultRepositoryImpl( | ||
| internal class VaultRepositoryImpl( | ||
| private val vaultDiskSource: VaultDiskSource, | ||
| private val vaultSdkSource: VaultSdkSource, | ||
| private val authDiskSource: AuthDiskSource, | ||
|
|
@@ -82,6 +84,7 @@ class VaultRepositoryImpl( | |
| private val vaultSyncManager: VaultSyncManager, | ||
| private val credentialExchangeImportManager: CredentialExchangeImportManager, | ||
| private val pinProtectedUserKeyManager: PinProtectedUserKeyManager, | ||
| private val featureFlagManager: FeatureFlagManager, | ||
| dispatcherManager: DispatcherManager, | ||
| ) : VaultRepository, | ||
| CipherManager by cipherManager, | ||
|
|
@@ -371,28 +374,16 @@ class VaultRepositoryImpl( | |
| override suspend fun unlockVaultWithPin( | ||
| pin: String, | ||
| ): VaultUnlockResult { | ||
| val userId = activeUserId | ||
| ?: return VaultUnlockResult.InvalidStateError(error = NoActiveUserException()) | ||
| val userId = activeUserId ?: return VaultUnlockResult.InvalidStateError( | ||
| error = NoActiveUserException(), | ||
| ) | ||
|
|
||
| return authDiskSource.getPinProtectedUserKeyEnvelope(userId = userId) | ||
| ?.let { pinProtectedUserKeyEnvelope -> | ||
| this.unlockVaultForUser( | ||
| userId = userId, | ||
| initUserCryptoMethod = InitUserCryptoMethod.PinEnvelope( | ||
| pin = pin, | ||
| pinProtectedUserKeyEnvelope = pinProtectedUserKeyEnvelope, | ||
| ), | ||
| ) | ||
| } | ||
| ?: run { | ||
| return authDiskSource | ||
| .getPinProtectedUserKey(userId = userId) | ||
| ?.let { pinProtectedUserKey -> | ||
| // This is needed to support unlocking with a legacy pin protected user key. | ||
| // Once the vault is unlocked, the user's pin protected user key is migrated to | ||
| // a pin protected user key envelope. | ||
| val pinProtectedUserKey = authDiskSource.getPinProtectedUserKey(userId = userId) | ||
| ?: return VaultUnlockResult.InvalidStateError( | ||
| error = MissingPropertyException("Pin protected key"), | ||
| ) | ||
|
|
||
| this.unlockVaultForUser( | ||
| userId = userId, | ||
| initUserCryptoMethod = InitUserCryptoMethod.Pin( | ||
|
|
@@ -401,6 +392,29 @@ class VaultRepositoryImpl( | |
| ), | ||
| ) | ||
| } | ||
| ?: run { | ||
|
david-livefront marked this conversation as resolved.
|
||
| if (featureFlagManager.getFeatureFlag(key = FlagKey.SdkPinUnlock)) { | ||
| this.unlockVaultForUser( | ||
| userId = userId, | ||
| initUserCryptoMethod = InitUserCryptoMethod.PinState(pin = pin), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this new init method, the SDK will retrieve the |
||
| ) | ||
| } else { | ||
| authDiskSource | ||
| .getPinProtectedUserKeyEnvelope(userId = userId) | ||
| ?.let { pinProtectedUserKeyEnvelope -> | ||
| this.unlockVaultForUser( | ||
| userId = userId, | ||
| initUserCryptoMethod = InitUserCryptoMethod.PinEnvelope( | ||
| pin = pin, | ||
| pinProtectedUserKeyEnvelope = pinProtectedUserKeyEnvelope, | ||
| ), | ||
| ) | ||
| } | ||
| ?: VaultUnlockResult.InvalidStateError( | ||
| error = MissingPropertyException("Pin protected key envelope"), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override suspend fun generateTotp( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.