From 9b6b2c005e7f78f0eaf632c334ea22c61e26d078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Mon, 17 Jul 2023 15:30:15 +0100 Subject: [PATCH] [PM-2297] Add methods to DeviceTrustCryptoService update decryption options model --- src/App/Pages/Accounts/LoginApproveDeviceViewModel.cs | 10 +--------- src/Core/Abstractions/IDeviceTrustCryptoService.cs | 3 ++- src/Core/Models/Domain/AccountDecryptionOptions.cs | 3 +++ src/Core/Services/DeviceTrustCryptoService.cs | 9 +++++++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/App/Pages/Accounts/LoginApproveDeviceViewModel.cs b/src/App/Pages/Accounts/LoginApproveDeviceViewModel.cs index 0cee8f216..74a42e88d 100644 --- a/src/App/Pages/Accounts/LoginApproveDeviceViewModel.cs +++ b/src/App/Pages/Accounts/LoginApproveDeviceViewModel.cs @@ -111,15 +111,7 @@ namespace Bit.App.Pages var decryptOptions = await _stateService.GetAccountDecryptionOptions(); RequestAdminApprovalEnabled = decryptOptions?.TrustedDeviceOption?.HasAdminApproval ?? false; ApproveWithMasterPasswordEnabled = decryptOptions?.HasMasterPassword ?? false; - } - catch (Exception ex) - { - HandleException(ex); - } - - try - { - ApproveWithMyOtherDeviceEnabled = await _apiService.GetDevicesExistenceByTypes(DeviceTypeExtensions.GetDesktopAndMobileTypes().ToArray()); + ApproveWithMyOtherDeviceEnabled = decryptOptions?.TrustedDeviceOption?.HasLoginApprovingDevice ?? false; } catch (Exception ex) { diff --git a/src/Core/Abstractions/IDeviceTrustCryptoService.cs b/src/Core/Abstractions/IDeviceTrustCryptoService.cs index 4335528f6..cd622984b 100644 --- a/src/Core/Abstractions/IDeviceTrustCryptoService.cs +++ b/src/Core/Abstractions/IDeviceTrustCryptoService.cs @@ -10,6 +10,7 @@ namespace Bit.Core.Abstractions Task TrustDeviceIfNeededAsync(); Task GetShouldTrustDeviceAsync(); Task SetShouldTrustDeviceAsync(bool value); - Task DecryptUserKeyWithDeviceKey(string encryptedDevicePrivateKey, string encryptedUserKey); + Task DecryptUserKeyWithDeviceKeyAsync(string encryptedDevicePrivateKey, string encryptedUserKey); + Task IsDeviceTrustedAsync(); } } diff --git a/src/Core/Models/Domain/AccountDecryptionOptions.cs b/src/Core/Models/Domain/AccountDecryptionOptions.cs index 8101bd9f3..9c4208317 100644 --- a/src/Core/Models/Domain/AccountDecryptionOptions.cs +++ b/src/Core/Models/Domain/AccountDecryptionOptions.cs @@ -11,6 +11,9 @@ namespace Bit.Core.Models.Domain public class TrustedDeviceOption { public bool HasAdminApproval { get; set; } + public bool HasLoginApprovingDevice { get; } + public string EncryptedPrivateKey { get; } + public string EncryptedUserKey { get; } } public class KeyConnectorOption diff --git a/src/Core/Services/DeviceTrustCryptoService.cs b/src/Core/Services/DeviceTrustCryptoService.cs index c8e56c06b..d8e5984c4 100644 --- a/src/Core/Services/DeviceTrustCryptoService.cs +++ b/src/Core/Services/DeviceTrustCryptoService.cs @@ -100,8 +100,13 @@ namespace Bit.Core.Services return response; } - // TODO: Add proper types to parameters once we have them coming down from server - public async Task DecryptUserKeyWithDeviceKey(string encryptedDevicePrivateKey, string encryptedUserKey) + public async Task IsDeviceTrustedAsync() + { + var existingDeviceKey = await GetDeviceKeyAsync(); + return existingDeviceKey != null; + } + + public async Task DecryptUserKeyWithDeviceKeyAsync(string encryptedDevicePrivateKey, string encryptedUserKey) { // Get device key var existingDeviceKey = await GetDeviceKeyAsync();