From 0e450904c5dbbf90147970f7ca394303319b687d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Tue, 18 Jul 2023 18:01:42 +0100 Subject: [PATCH] [PM-2297] fix TrustedDeviceOption and DeviceResponse model. Change StateService device key get set to have default user id --- src/Core/Models/Domain/AccountDecryptionOptions.cs | 8 ++++---- src/Core/Models/Response/DeviceResponse.cs | 2 +- src/Core/Services/StateService.cs | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Core/Models/Domain/AccountDecryptionOptions.cs b/src/Core/Models/Domain/AccountDecryptionOptions.cs index b989f4a87..2b485e26b 100644 --- a/src/Core/Models/Domain/AccountDecryptionOptions.cs +++ b/src/Core/Models/Domain/AccountDecryptionOptions.cs @@ -11,10 +11,10 @@ namespace Bit.Core.Models.Domain public class TrustedDeviceOption { public bool HasAdminApproval { get; set; } - public bool HasLoginApprovingDevice { get; } - public bool HasManageResetPasswordPermission { get; } - public string EncryptedPrivateKey { get; } - public string EncryptedUserKey { get; } + public bool HasLoginApprovingDevice { get; set; } + public bool HasManageResetPasswordPermission { get; set; } + public string EncryptedPrivateKey { get; set; } + public string EncryptedUserKey { get; set; } } public class KeyConnectorOption diff --git a/src/Core/Models/Response/DeviceResponse.cs b/src/Core/Models/Response/DeviceResponse.cs index 331d0562a..9cd3fb9e0 100644 --- a/src/Core/Models/Response/DeviceResponse.cs +++ b/src/Core/Models/Response/DeviceResponse.cs @@ -3,7 +3,7 @@ public class DeviceResponse { public string Id { get; set; } - public int Name { get; set; } + public string Name { get; set; } public string Identifier { get; set; } public DeviceType Type { get; set; } public string CreationDate { get; set; } diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index a952c2c4f..9340cd827 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -484,13 +484,17 @@ namespace Bit.Core.Services public async Task GetDeviceKeyAsync(string userId = null) { - var deviceKeyB64 = await _storageMediatorService.GetAsync(Constants.DeviceKeyKey(userId), true); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + var deviceKeyB64 = await _storageMediatorService.GetAsync(Constants.DeviceKeyKey(reconciledOptions.UserId), true); return new SymmetricCryptoKey(Convert.FromBase64String(deviceKeyB64)); } public async Task SetDeviceKeyAsync(SymmetricCryptoKey value, string userId = null) { - await _storageMediatorService.SaveAsync(Constants.DeviceKeyKey(userId), value.KeyB64, true); + var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, + await GetDefaultStorageOptionsAsync()); + await _storageMediatorService.SaveAsync(Constants.DeviceKeyKey(reconciledOptions.UserId), value.KeyB64, true); } public async Task> GetAutofillBlacklistedUrisAsync(string userId = null)