diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt index 3bc1dff1b64..bd8df3cc04f 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt @@ -59,7 +59,7 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.model.ForcePasswordResetRea import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus import com.x8bit.bitwarden.data.auth.datasource.network.model.DeviceDataModel import com.x8bit.bitwarden.data.auth.datasource.sdk.AuthSdkSource -import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toKdfTypeJson +import com.x8bit.bitwarden.data.auth.datasource.sdk.util.toKdfRequestModel import com.x8bit.bitwarden.data.auth.manager.AuthRequestManager import com.x8bit.bitwarden.data.auth.manager.AuthStateManager import com.x8bit.bitwarden.data.auth.manager.KdfManager @@ -866,16 +866,16 @@ internal class AuthRepositoryImpl( identityService.registerFinish( body = RegisterFinishRequestJson( email = email, - masterPasswordHash = registerKeyResponse.masterPasswordHash, - masterPasswordHint = masterPasswordHint, emailVerificationToken = emailVerificationToken, - userSymmetricKey = registerKeyResponse.encryptedUserKey, + masterPasswordHint = masterPasswordHint, userAsymmetricKeys = KeysJson( publicKey = registerKeyResponse.keys.public, encryptedPrivateKey = registerKeyResponse.keys.private, ), - kdfType = kdf.toKdfTypeJson(), - kdfIterations = kdf.iterations, + kdf = kdf.toKdfRequestModel(), + salt = email, + masterPasswordAuthenticationHash = registerKeyResponse.masterPasswordHash, + masterKeyWrappedUserKey = registerKeyResponse.encryptedUserKey, ), ) } diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt index a28ffabc805..96054964d2f 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt @@ -4851,16 +4851,21 @@ class AuthRepositoryTest { identityService.registerFinish( body = RegisterFinishRequestJson( email = EMAIL, - masterPasswordHash = PASSWORD_HASH, - masterPasswordHint = null, emailVerificationToken = EMAIL_VERIFICATION_TOKEN, - userSymmetricKey = ENCRYPTED_USER_KEY, + masterPasswordHint = null, userAsymmetricKeys = KeysJson( publicKey = PUBLIC_KEY, encryptedPrivateKey = PRIVATE_KEY, ), - kdfType = KdfTypeJson.PBKDF2_SHA256, - kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(), + kdf = KdfJson( + kdfType = KdfTypeJson.PBKDF2_SHA256, + iterations = DEFAULT_KDF_ITERATIONS, + memory = null, + parallelism = null, + ), + salt = EMAIL, + masterPasswordAuthenticationHash = PASSWORD_HASH, + masterKeyWrappedUserKey = ENCRYPTED_USER_KEY, ), ) } returns RegisterResponseJson.Success.asSuccess() diff --git a/network/src/main/kotlin/com/bitwarden/network/model/RegisterFinishRequestJson.kt b/network/src/main/kotlin/com/bitwarden/network/model/RegisterFinishRequestJson.kt index a0f0660ef4d..d4d5946ecb9 100644 --- a/network/src/main/kotlin/com/bitwarden/network/model/RegisterFinishRequestJson.kt +++ b/network/src/main/kotlin/com/bitwarden/network/model/RegisterFinishRequestJson.kt @@ -6,14 +6,12 @@ import kotlinx.serialization.Serializable /** * Request body for register. * - * @param email the email to be registered. - * @param emailVerificationToken token used to finish the registration process. - * @param masterPasswordHash the master password (encrypted). - * @param masterPasswordHint the hint for the master password (nullable). - * @param userSymmetricKey the user key for the request (encrypted). - * @param userAsymmetricKeys a [KeysJson] object containing public and private keys. - * @param kdfType the kdf type represented as an [Int]. - * @param kdfIterations the number of kdf iterations. + * @property email the email to be registered. + * @property emailVerificationToken token used to finish the registration process. + * @property masterPasswordHint the hint for the master password (nullable). + * @property userAsymmetricKeys a [KeysJson] object containing public and private keys. + * @property authenticationData The data to authenticate with a master password. + * @property unlockData The data to unlock with a master password. */ @Serializable data class RegisterFinishRequestJson( @@ -23,21 +21,42 @@ data class RegisterFinishRequestJson( @SerialName("emailVerificationToken") val emailVerificationToken: String, - @SerialName("masterPasswordHash") - val masterPasswordHash: String, - @SerialName("masterPasswordHint") val masterPasswordHint: String?, - @SerialName("userSymmetricKey") - val userSymmetricKey: String, - @SerialName("userAsymmetricKeys") val userAsymmetricKeys: KeysJson, - @SerialName("kdf") - val kdfType: KdfTypeJson, - - @SerialName("kdfIterations") - val kdfIterations: UInt, -) + @SerialName("MasterPasswordAuthentication") + val authenticationData: MasterPasswordAuthenticationDataJson, + + @SerialName("MasterPasswordUnlock") + val unlockData: MasterPasswordUnlockDataJson, +) { + constructor( + email: String, + emailVerificationToken: String, + masterPasswordHint: String?, + userAsymmetricKeys: KeysJson, + kdf: KdfJson, + salt: String, + masterPasswordAuthenticationHash: String, + masterKeyWrappedUserKey: String, + ) : this( + email = email, + emailVerificationToken = emailVerificationToken, + masterPasswordHint = masterPasswordHint, + userAsymmetricKeys = userAsymmetricKeys, + authenticationData = MasterPasswordAuthenticationDataJson( + kdf = kdf, + salt = salt, + masterPasswordAuthenticationHash = masterPasswordAuthenticationHash, + ), + unlockData = MasterPasswordUnlockDataJson( + kdf = kdf, + salt = salt, + masterKeyWrappedUserKey = masterKeyWrappedUserKey, + containedKeyId = null, + ), + ) +} diff --git a/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt b/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt index a63c81081dd..8845d645ee2 100644 --- a/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt +++ b/network/src/test/kotlin/com/bitwarden/network/service/IdentityServiceTest.kt @@ -5,6 +5,7 @@ import com.bitwarden.network.api.UnauthenticatedIdentityApi import com.bitwarden.network.base.BaseServiceTest import com.bitwarden.network.model.GetTokenResponseJson import com.bitwarden.network.model.IdentityTokenAuthModel +import com.bitwarden.network.model.KdfJson import com.bitwarden.network.model.KdfTypeJson import com.bitwarden.network.model.KeyConnectorUserDecryptionOptionsJson import com.bitwarden.network.model.KeysJson @@ -410,16 +411,21 @@ class IdentityServiceTest : BaseServiceTest() { private const val PASSWORD_HASH = "passwordHash" private val registerFinishRequestBody = RegisterFinishRequestJson( email = EMAIL, - masterPasswordHash = "mockk_masterPasswordHash", - masterPasswordHint = "mockk_masterPasswordHint", emailVerificationToken = "mock_emailVerificationToken", - userSymmetricKey = "mockk_key", + masterPasswordHint = "mockk_masterPasswordHint", userAsymmetricKeys = KeysJson( publicKey = "mockk_publicKey", encryptedPrivateKey = "mockk_encryptedPrivateKey", ), - kdfType = KdfTypeJson.PBKDF2_SHA256, - kdfIterations = 600000U, + kdf = KdfJson( + kdfType = KdfTypeJson.PBKDF2_SHA256, + iterations = 600000, + memory = null, + parallelism = null, + ), + salt = EMAIL, + masterPasswordAuthenticationHash = "mockk_masterPasswordHash", + masterKeyWrappedUserKey = "mockk_key", ) } }