@@ -10,11 +10,20 @@ import com.bitwarden.crypto.HashPurpose
10
10
import com.bitwarden.crypto.Kdf
11
11
import com.bitwarden.data.datasource.disk.ConfigDiskSource
12
12
import com.bitwarden.data.manager.DispatcherManager
13
+ import com.bitwarden.network.model.GetTokenResponseJson
14
+ import com.bitwarden.network.model.PrevalidateSsoResponseJson
15
+ import com.bitwarden.network.model.RefreshTokenResponseJson
16
+ import com.bitwarden.network.model.RegisterFinishRequestJson
13
17
import com.bitwarden.network.model.RegisterRequestJson
18
+ import com.bitwarden.network.model.RegisterResponseJson
14
19
import com.bitwarden.network.model.ResendEmailRequestJson
15
20
import com.bitwarden.network.model.ResendNewDeviceOtpRequestJson
16
21
import com.bitwarden.network.model.ResetPasswordRequestJson
22
+ import com.bitwarden.network.model.SendVerificationEmailRequestJson
17
23
import com.bitwarden.network.model.SetPasswordRequestJson
24
+ import com.bitwarden.network.model.TrustedDeviceUserDecryptionOptionsJson
25
+ import com.bitwarden.network.model.TwoFactorAuthMethod
26
+ import com.bitwarden.network.model.VerifyEmailTokenRequestJson
18
27
import com.bitwarden.network.util.isSslHandShakeError
19
28
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
20
29
import com.x8bit.bitwarden.data.auth.datasource.disk.model.AccountJson
@@ -24,19 +33,10 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
24
33
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
25
34
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeleteAccountResponseJson
26
35
import com.x8bit.bitwarden.data.auth.datasource.network.model.DeviceDataModel
27
- import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
28
36
import com.x8bit.bitwarden.data.auth.datasource.network.model.IdentityTokenAuthModel
29
37
import com.x8bit.bitwarden.data.auth.datasource.network.model.PasswordHintResponseJson
30
- import com.x8bit.bitwarden.data.auth.datasource.network.model.PrevalidateSsoResponseJson
31
- import com.x8bit.bitwarden.data.auth.datasource.network.model.RefreshTokenResponseJson
32
- import com.x8bit.bitwarden.data.auth.datasource.network.model.RegisterFinishRequestJson
33
- import com.x8bit.bitwarden.data.auth.datasource.network.model.RegisterResponseJson
34
- import com.x8bit.bitwarden.data.auth.datasource.network.model.SendVerificationEmailRequestJson
35
38
import com.x8bit.bitwarden.data.auth.datasource.network.model.SendVerificationEmailResponseJson
36
- import com.x8bit.bitwarden.data.auth.datasource.network.model.TrustedDeviceUserDecryptionOptionsJson
37
- import com.x8bit.bitwarden.data.auth.datasource.network.model.TwoFactorAuthMethod
38
39
import com.x8bit.bitwarden.data.auth.datasource.network.model.TwoFactorDataModel
39
- import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifyEmailTokenRequestJson
40
40
import com.x8bit.bitwarden.data.auth.datasource.network.model.VerifyEmailTokenResponseJson
41
41
import com.x8bit.bitwarden.data.auth.datasource.network.service.AccountsService
42
42
import com.x8bit.bitwarden.data.auth.datasource.network.service.DevicesService
@@ -1209,18 +1209,19 @@ class AuthRepositoryImpl(
1209
1209
organizationIdentifier = organizationIdentifier,
1210
1210
)
1211
1211
.fold(
1212
- onSuccess = {
1213
- when (it ) {
1212
+ onSuccess = { response ->
1213
+ when (response ) {
1214
1214
is PrevalidateSsoResponseJson .Error -> {
1215
- PrevalidateSsoResult .Failure (message = it .message, error = null )
1215
+ PrevalidateSsoResult .Failure (message = response .message, error = null )
1216
1216
}
1217
1217
1218
1218
is PrevalidateSsoResponseJson .Success -> {
1219
- if (it.token.isNullOrBlank()) {
1220
- PrevalidateSsoResult .Failure (error = MissingPropertyException (" Token" ))
1221
- } else {
1222
- PrevalidateSsoResult .Success (token = it.token)
1223
- }
1219
+ response.token
1220
+ ?.takeUnless { it.isBlank() }
1221
+ ?.let { PrevalidateSsoResult .Success (token = it) }
1222
+ ? : PrevalidateSsoResult .Failure (
1223
+ error = MissingPropertyException (" Token" ),
1224
+ )
1224
1225
}
1225
1226
}
1226
1227
},
@@ -1790,17 +1791,20 @@ class AuthRepositoryImpl(
1790
1791
/* *
1791
1792
* Attempt to unlock the current user's vault with key connector data.
1792
1793
*/
1794
+ @Suppress(" LongMethod" )
1793
1795
private suspend fun unlockVaultWithKeyConnectorOnLoginSuccess (
1794
1796
profile : AccountJson .Profile ,
1795
1797
keyConnectorUrl : String ,
1796
1798
orgIdentifier : String ,
1797
1799
loginResponse : GetTokenResponseJson .Success ,
1798
- ): VaultUnlockResult ? =
1799
- if (loginResponse.userDecryptionOptions?.hasMasterPassword != false ) {
1800
+ ): VaultUnlockResult ? {
1801
+ val key = loginResponse.key
1802
+ val privateKey = loginResponse.privateKey
1803
+ return if (loginResponse.userDecryptionOptions?.hasMasterPassword != false ) {
1800
1804
// This user has a master password, so we skip the key-connector logic as it is not
1801
1805
// setup yet. The user can still unlock the vault with their master password.
1802
1806
null
1803
- } else if (loginResponse. key != null && loginResponse. privateKey != null ) {
1807
+ } else if (key != null && privateKey != null ) {
1804
1808
// This is a returning user who should already have the key connector setup
1805
1809
keyConnectorManager
1806
1810
.getMasterKeyFromKeyConnector(
@@ -1810,10 +1814,10 @@ class AuthRepositoryImpl(
1810
1814
.map {
1811
1815
unlockVault(
1812
1816
accountProfile = profile,
1813
- privateKey = loginResponse. privateKey,
1817
+ privateKey = privateKey,
1814
1818
initUserCryptoMethod = InitUserCryptoMethod .KeyConnector (
1815
1819
masterKey = it.masterKey,
1816
- userKey = loginResponse. key,
1820
+ userKey = key,
1817
1821
),
1818
1822
)
1819
1823
}
@@ -1863,6 +1867,7 @@ class AuthRepositoryImpl(
1863
1867
onSuccess = { it },
1864
1868
)
1865
1869
}
1870
+ }
1866
1871
1867
1872
/* *
1868
1873
* Attempt to unlock the current user's vault with password data.
@@ -1896,19 +1901,21 @@ class AuthRepositoryImpl(
1896
1901
): VaultUnlockResult ? {
1897
1902
// Attempt to unlock the vault with auth request if possible.
1898
1903
// These values will only be null during the Just-in-Time provisioning flow.
1899
- if (loginResponse.privateKey != null && loginResponse.key != null ) {
1904
+ val privateKey = loginResponse.privateKey
1905
+ val key = loginResponse.key
1906
+ if (privateKey != null && key != null ) {
1900
1907
deviceData?.let { model ->
1901
1908
return unlockVault(
1902
1909
accountProfile = profile,
1903
- privateKey = loginResponse. privateKey,
1910
+ privateKey = privateKey,
1904
1911
initUserCryptoMethod = InitUserCryptoMethod .AuthRequest (
1905
1912
requestPrivateKey = model.privateKey,
1906
1913
method = model
1907
1914
.masterPasswordHash
1908
1915
?.let {
1909
1916
AuthRequestMethod .MasterKey (
1910
1917
protectedMasterKey = model.asymmetricalKey,
1911
- authRequestKey = loginResponse. key,
1918
+ authRequestKey = key,
1912
1919
)
1913
1920
}
1914
1921
? : AuthRequestMethod .UserKey (protectedUserKey = model.asymmetricalKey),
0 commit comments