Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
extension SetAccountKeysResponseModel {
static func fixture(
accountKeys: PrivateKeysResponseModel? = nil,
key: String? = nil,
privateKey: String? = "PRIVATE_KEY",
publicKey: String? = "PUBLIC_KEY",
) -> SetAccountKeysResponseModel {
self.init(
accountKeys: accountKeys,
key: key,
privateKey: privateKey,
publicKey: publicKey,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ struct SetAccountKeysResponseModel: Equatable, JSONResponse, AccountKeysResponse
/// The user's account keys.
let accountKeys: PrivateKeysResponseModel?

/// The user's key.
let key: String?

/// The user's private key.
@available(*, deprecated, message: "Use accountKeys instead when possible") // TODO: PM-24659 remove
let privateKey: String?
Expand Down
38 changes: 10 additions & 28 deletions BitwardenShared/Core/Auth/Repositories/AuthRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,6 @@ extension DefaultAuthRepository: AuthRepository {
}

func createNewSsoUser(orgIdentifier: String, rememberDevice: Bool) async throws {
// swiftlint:disable:previous function_body_length
let account = try await stateService.getActiveAccount()
let enrollStatus = try await organizationAPIService.getOrganizationAutoEnrollStatus(identifier: orgIdentifier)
let organizationKeys = try await organizationAPIService.getOrganizationKeys(organizationId: enrollStatus.id)
Expand All @@ -696,13 +695,10 @@ extension DefaultAuthRepository: AuthRepository {
),
)

try await stateService.setAccountEncryptionKeys(
AccountEncryptionKeys(
cryptographicState: .create(
accountKeys: setAccountKeysResponse.accountKeys,
privateKey: registrationKeys.privateKey,
),
encryptedUserKey: nil,
try await stateService.setAccountCryptographicState(
.create(
accountKeys: setAccountKeysResponse.accountKeys,
privateKey: registrationKeys.privateKey,
),
)

Expand Down Expand Up @@ -731,12 +727,7 @@ extension DefaultAuthRepository: AuthRepository {
)
let response = try await clientService.auth().registration().postKeysForTdeRegistration(request: request)

try await stateService.setAccountEncryptionKeys(
AccountEncryptionKeys(
cryptographicState: response.accountCryptographicState,
encryptedUserKey: nil,
),
)
try await stateService.setAccountCryptographicState(response.accountCryptographicState)

if rememberDevice {
try await keychainService.setDeviceKey(response.deviceKey, userId: account.profile.userId)
Expand Down Expand Up @@ -939,11 +930,10 @@ extension DefaultAuthRepository: AuthRepository {
// TDE user
if account.profile.userDecryptionOptions?.trustedDeviceOption != nil {
let passwordResult = try await clientService.crypto().makeUpdatePassword(newPassword: password)
let accountKeys = try await stateService.getAccountEncryptionKeys()
requestPasswordHash = passwordResult.passwordHash
requestUserKey = passwordResult.newKey
requestKeys = nil
cryptographicState = accountKeys.cryptographicState
cryptographicState = try await stateService.getAccountCryptographicState()
} else if await configService.getFeatureFlag(.accountEncryptionV2JITPassword) {
// V2 JIT password path: SDK handles all server-side API calls internally.
let organizationKeys = try await organizationAPIService.getOrganizationKeys(
Expand All @@ -962,12 +952,7 @@ extension DefaultAuthRepository: AuthRepository {
let response = try await clientService.auth().registration().postKeysForJitPasswordRegistration(
request: request,
)
try await stateService.setAccountEncryptionKeys(
AccountEncryptionKeys(
cryptographicState: response.accountCryptographicState,
encryptedUserKey: nil,
),
)
try await stateService.setAccountCryptographicState(response.accountCryptographicState)
try await stateService.setAccountMasterPasswordUnlock(
MasterPasswordUnlockResponseModel(unlockData: response.masterPasswordUnlock),
)
Expand Down Expand Up @@ -1011,10 +996,7 @@ extension DefaultAuthRepository: AuthRepository {
masterKeyEncryptedUserKey: requestUserKey,
),
)
try await stateService.setAccountEncryptionKeys(AccountEncryptionKeys(
cryptographicState: cryptographicState,
encryptedUserKey: nil,
))
try await stateService.setAccountCryptographicState(cryptographicState)
try await stateService.setUserHasMasterPassword(true)

// The vault needs to be unlocked before attempting to enroll the user in admin password reset.
Expand Down Expand Up @@ -1284,11 +1266,11 @@ extension DefaultAuthRepository: AuthRepository {
/// or was unlocked using the never lock key.
private func unlockVault(method: InitUserCryptoMethod, hadUserInteraction: Bool = true) async throws {
let account = try await stateService.getActiveAccount()
let encryptionKeys = try await stateService.getAccountEncryptionKeys()
let cryptographicState = try await stateService.getAccountCryptographicState()

try await clientService.crypto().initializeUserCrypto(
account: account,
encryptionKeys: encryptionKeys,
cryptographicState: cryptographicState,
method: method,
)

Expand Down
Loading
Loading