mirror of
https://github.com/bitwarden/android.git
synced 2024-11-22 01:16:02 +03:00
Update to the latest Bitwarden SDK (#3779)
This commit is contained in:
parent
82fd7f01f8
commit
9e372c29d1
8 changed files with 118 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.x8bit.bitwarden.data.auth.datasource.sdk
|
package com.x8bit.bitwarden.data.auth.datasource.sdk
|
||||||
|
|
||||||
import com.bitwarden.core.AuthRequestResponse
|
import com.bitwarden.core.AuthRequestResponse
|
||||||
|
import com.bitwarden.core.KeyConnectorResponse
|
||||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||||
|
@ -37,6 +38,11 @@ interface AuthSdkSource {
|
||||||
purpose: HashPurpose,
|
purpose: HashPurpose,
|
||||||
): Result<String>
|
): Result<String>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a set of encryption key information for use with a key connector.
|
||||||
|
*/
|
||||||
|
suspend fun makeKeyConnectorKeys(): Result<KeyConnectorResponse>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a set of encryption key information for registration.
|
* Creates a set of encryption key information for registration.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.auth.datasource.sdk
|
||||||
|
|
||||||
import com.bitwarden.core.AuthRequestResponse
|
import com.bitwarden.core.AuthRequestResponse
|
||||||
import com.bitwarden.core.FingerprintRequest
|
import com.bitwarden.core.FingerprintRequest
|
||||||
|
import com.bitwarden.core.KeyConnectorResponse
|
||||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||||
|
@ -63,6 +64,13 @@ class AuthSdkSourceImpl(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun makeKeyConnectorKeys(): Result<KeyConnectorResponse> =
|
||||||
|
runCatchingWithLogs {
|
||||||
|
getClient()
|
||||||
|
.auth()
|
||||||
|
.makeKeyConnectorKeys()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun makeRegisterKeys(
|
override suspend fun makeRegisterKeys(
|
||||||
email: String,
|
email: String,
|
||||||
password: String,
|
password: String,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoMethod
|
import com.bitwarden.core.InitUserCryptoMethod
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
|
import com.bitwarden.crypto.Kdf
|
||||||
import com.bitwarden.crypto.TrustDeviceResponse
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.bitwarden.exporters.ExportFormat
|
import com.bitwarden.exporters.ExportFormat
|
||||||
import com.bitwarden.fido.Fido2CredentialAutofillView
|
import com.bitwarden.fido.Fido2CredentialAutofillView
|
||||||
|
@ -52,6 +53,22 @@ interface VaultSdkSource {
|
||||||
*/
|
*/
|
||||||
suspend fun getTrustDevice(userId: String): Result<TrustDeviceResponse>
|
suspend fun getTrustDevice(userId: String): Result<TrustDeviceResponse>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derives a "key connector" key from the given information for the given `userId. This can be
|
||||||
|
* used to later unlock their vault via a call to [initializeCrypto] with
|
||||||
|
* [InitUserCryptoMethod.KeyConnector].
|
||||||
|
*
|
||||||
|
* This should only be called after a successful call to [initializeCrypto] for the associated
|
||||||
|
* user.
|
||||||
|
*/
|
||||||
|
suspend fun deriveKeyConnector(
|
||||||
|
userId: String,
|
||||||
|
userKeyEncrypted: String,
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
|
kdf: Kdf,
|
||||||
|
): Result<String>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derives a "pin key" from the given [pin] for the given [userId]. This can be used to later
|
* Derives a "pin key" from the given [pin] for the given [userId]. This can be used to later
|
||||||
* unlock their vault via a call to [initializeCrypto] with [InitUserCryptoMethod.Pin].
|
* unlock their vault via a call to [initializeCrypto] with [InitUserCryptoMethod.Pin].
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.x8bit.bitwarden.data.vault.datasource.sdk
|
package com.x8bit.bitwarden.data.vault.datasource.sdk
|
||||||
|
|
||||||
import com.bitwarden.core.DateTime
|
import com.bitwarden.core.DateTime
|
||||||
|
import com.bitwarden.core.DeriveKeyConnectorRequest
|
||||||
import com.bitwarden.core.DerivePinKeyResponse
|
import com.bitwarden.core.DerivePinKeyResponse
|
||||||
import com.bitwarden.core.InitOrgCryptoRequest
|
import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
|
import com.bitwarden.crypto.Kdf
|
||||||
import com.bitwarden.crypto.TrustDeviceResponse
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.bitwarden.exporters.ExportFormat
|
import com.bitwarden.exporters.ExportFormat
|
||||||
import com.bitwarden.fido.Fido2CredentialAutofillView
|
import com.bitwarden.fido.Fido2CredentialAutofillView
|
||||||
|
@ -67,6 +69,26 @@ class VaultSdkSourceImpl(
|
||||||
.trustDevice()
|
.trustDevice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun deriveKeyConnector(
|
||||||
|
userId: String,
|
||||||
|
userKeyEncrypted: String,
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
|
kdf: Kdf,
|
||||||
|
): Result<String> =
|
||||||
|
runCatchingWithLogs {
|
||||||
|
getClient(userId = userId)
|
||||||
|
.crypto()
|
||||||
|
.deriveKeyConnector(
|
||||||
|
request = DeriveKeyConnectorRequest(
|
||||||
|
userKeyEncrypted = userKeyEncrypted,
|
||||||
|
password = password,
|
||||||
|
kdf = kdf,
|
||||||
|
email = email,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun derivePinKey(
|
override suspend fun derivePinKey(
|
||||||
userId: String,
|
userId: String,
|
||||||
pin: String,
|
pin: String,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.auth.datasource.sdk
|
||||||
|
|
||||||
import com.bitwarden.core.AuthRequestResponse
|
import com.bitwarden.core.AuthRequestResponse
|
||||||
import com.bitwarden.core.FingerprintRequest
|
import com.bitwarden.core.FingerprintRequest
|
||||||
|
import com.bitwarden.core.KeyConnectorResponse
|
||||||
import com.bitwarden.core.MasterPasswordPolicyOptions
|
import com.bitwarden.core.MasterPasswordPolicyOptions
|
||||||
import com.bitwarden.core.RegisterKeyResponse
|
import com.bitwarden.core.RegisterKeyResponse
|
||||||
import com.bitwarden.core.RegisterTdeKeyResponse
|
import com.bitwarden.core.RegisterTdeKeyResponse
|
||||||
|
@ -124,6 +125,20 @@ class AuthSdkSourceTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `makeKeyConnectorKeys should call SDK and return a Result with the correct data`() =
|
||||||
|
runBlocking {
|
||||||
|
val expectedResult = mockk<KeyConnectorResponse>()
|
||||||
|
coEvery { clientAuth.makeKeyConnectorKeys() } returns expectedResult
|
||||||
|
|
||||||
|
val result = authSkdSource.makeKeyConnectorKeys()
|
||||||
|
|
||||||
|
assertEquals(expectedResult.asSuccess(), result)
|
||||||
|
coVerify(exactly = 1) {
|
||||||
|
clientAuth.makeKeyConnectorKeys()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `makeRegisterKeys should call SDK and return a Result with the correct data`() =
|
fun `makeRegisterKeys should call SDK and return a Result with the correct data`() =
|
||||||
runBlocking {
|
runBlocking {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.x8bit.bitwarden.data.vault.datasource.sdk
|
package com.x8bit.bitwarden.data.vault.datasource.sdk
|
||||||
|
|
||||||
import com.bitwarden.core.DateTime
|
import com.bitwarden.core.DateTime
|
||||||
|
import com.bitwarden.core.DeriveKeyConnectorRequest
|
||||||
import com.bitwarden.core.DerivePinKeyResponse
|
import com.bitwarden.core.DerivePinKeyResponse
|
||||||
import com.bitwarden.core.InitOrgCryptoRequest
|
import com.bitwarden.core.InitOrgCryptoRequest
|
||||||
import com.bitwarden.core.InitUserCryptoRequest
|
import com.bitwarden.core.InitUserCryptoRequest
|
||||||
import com.bitwarden.core.UpdatePasswordResponse
|
import com.bitwarden.core.UpdatePasswordResponse
|
||||||
|
import com.bitwarden.crypto.Kdf
|
||||||
import com.bitwarden.crypto.TrustDeviceResponse
|
import com.bitwarden.crypto.TrustDeviceResponse
|
||||||
import com.bitwarden.exporters.ExportFormat
|
import com.bitwarden.exporters.ExportFormat
|
||||||
import com.bitwarden.fido.ClientData
|
import com.bitwarden.fido.ClientData
|
||||||
|
@ -145,6 +147,46 @@ class VaultSdkSourceTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `deriveKeyConnector should call SDK and return a Result with the correct data`() =
|
||||||
|
runBlocking {
|
||||||
|
val userId = "userId"
|
||||||
|
val userKeyEncrypted = "userKeyEncrypted"
|
||||||
|
val email = "email"
|
||||||
|
val password = "password"
|
||||||
|
val expectedResult = "expectedResult"
|
||||||
|
val kdf = mockk<Kdf>()
|
||||||
|
coEvery {
|
||||||
|
clientCrypto.deriveKeyConnector(
|
||||||
|
request = DeriveKeyConnectorRequest(
|
||||||
|
userKeyEncrypted = userKeyEncrypted,
|
||||||
|
email = email,
|
||||||
|
password = password,
|
||||||
|
kdf = kdf,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} returns expectedResult
|
||||||
|
val result = vaultSdkSource.deriveKeyConnector(
|
||||||
|
userId = userId,
|
||||||
|
userKeyEncrypted = userKeyEncrypted,
|
||||||
|
email = email,
|
||||||
|
password = password,
|
||||||
|
kdf = kdf,
|
||||||
|
)
|
||||||
|
assertEquals(expectedResult.asSuccess(), result)
|
||||||
|
coVerify(exactly = 1) {
|
||||||
|
sdkClientManager.getOrCreateClient(userId = userId)
|
||||||
|
clientCrypto.deriveKeyConnector(
|
||||||
|
request = DeriveKeyConnectorRequest(
|
||||||
|
userKeyEncrypted = userKeyEncrypted,
|
||||||
|
email = email,
|
||||||
|
password = password,
|
||||||
|
kdf = kdf,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `derivePinKey should call SDK and return a Result with the correct data`() = runBlocking {
|
fun `derivePinKey should call SDK and return a Result with the correct data`() = runBlocking {
|
||||||
val userId = "userId"
|
val userId = "userId"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.x8bit.bitwarden.data.vault.datasource.sdk.model
|
package com.x8bit.bitwarden.data.vault.datasource.sdk.model
|
||||||
|
|
||||||
import com.bitwarden.vault.CipherListView
|
import com.bitwarden.vault.CipherListView
|
||||||
|
import com.bitwarden.vault.CipherListViewType
|
||||||
import com.bitwarden.vault.CipherRepromptType
|
import com.bitwarden.vault.CipherRepromptType
|
||||||
import com.bitwarden.vault.CipherType
|
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,10 @@ fun createMockCipherListView(number: Int): CipherListView =
|
||||||
folderId = "mockFolderId-$number",
|
folderId = "mockFolderId-$number",
|
||||||
collectionIds = listOf("mockCollectionId-$number"),
|
collectionIds = listOf("mockCollectionId-$number"),
|
||||||
name = "mockName-$number",
|
name = "mockName-$number",
|
||||||
type = CipherType.LOGIN,
|
type = CipherListViewType.Login(
|
||||||
|
hasFido2 = false,
|
||||||
|
totp = null,
|
||||||
|
),
|
||||||
creationDate = ZonedDateTime
|
creationDate = ZonedDateTime
|
||||||
.parse("2023-10-27T12:00:00Z")
|
.parse("2023-10-27T12:00:00Z")
|
||||||
.toInstant(),
|
.toInstant(),
|
||||||
|
@ -30,5 +33,6 @@ fun createMockCipherListView(number: Int): CipherListView =
|
||||||
reprompt = CipherRepromptType.NONE,
|
reprompt = CipherRepromptType.NONE,
|
||||||
edit = false,
|
edit = false,
|
||||||
viewPassword = false,
|
viewPassword = false,
|
||||||
subTitle = "",
|
subTitle = "mockSubTitle-$number",
|
||||||
|
key = "mockKey-$number",
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ androidxSplash = "1.1.0-rc01"
|
||||||
androidXAppCompat = "1.7.0"
|
androidXAppCompat = "1.7.0"
|
||||||
androdixAutofill = "1.1.0"
|
androdixAutofill = "1.1.0"
|
||||||
androidxWork = "2.9.1"
|
androidxWork = "2.9.1"
|
||||||
bitwardenSdk = "0.5.0-20240716.152920-144"
|
bitwardenSdk = "0.5.0-20240819.160739-177"
|
||||||
crashlytics = "3.0.2"
|
crashlytics = "3.0.2"
|
||||||
detekt = "1.23.6"
|
detekt = "1.23.6"
|
||||||
firebaseBom = "33.1.2"
|
firebaseBom = "33.1.2"
|
||||||
|
|
Loading…
Reference in a new issue