From e2841e8d8968d4dd0288d20c51032132f29cceec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Mon, 24 Jul 2023 10:47:37 +0100 Subject: [PATCH 1/3] [PM-2297] remove unnecessary using --- src/iOS.Autofill/CredentialProviderViewController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/iOS.Autofill/CredentialProviderViewController.cs b/src/iOS.Autofill/CredentialProviderViewController.cs index ab77da33f..ed0ae3ec4 100644 --- a/src/iOS.Autofill/CredentialProviderViewController.cs +++ b/src/iOS.Autofill/CredentialProviderViewController.cs @@ -17,7 +17,6 @@ using CoreFoundation; using CoreNFC; using Foundation; using UIKit; -using Xamarin.Essentials; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; From eceee581c95b20a9aca823a067863787d3724202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Mon, 24 Jul 2023 22:23:17 +0100 Subject: [PATCH 2/3] [PM-2297] Refactor auth service key connector code --- src/Core/Services/AuthService.cs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Core/Services/AuthService.cs b/src/Core/Services/AuthService.cs index d05c081a7..d11009d2d 100644 --- a/src/Core/Services/AuthService.cs +++ b/src/Core/Services/AuthService.cs @@ -482,14 +482,9 @@ namespace Bit.Core.Services if (code == null || tokenResponse.Key != null) { - if (tokenResponse.KeyConnectorUrl != null) - { - await _keyConnectorService.GetAndSetKey(tokenResponse.KeyConnectorUrl); - } - + var decryptOptions = await _stateService.GetAccountDecryptionOptions(); await _cryptoService.SetMasterKeyEncryptedUserKeyAsync(tokenResponse.Key); - var decryptOptions = await _stateService.GetAccountDecryptionOptions(); if (decryptOptions?.TrustedDeviceOption != null) { var key = await _deviceTrustCryptoService.DecryptUserKeyWithDeviceKeyAsync(decryptOptions?.TrustedDeviceOption.EncryptedPrivateKey, decryptOptions?.TrustedDeviceOption.EncryptedUserKey); @@ -498,12 +493,16 @@ namespace Bit.Core.Services await _cryptoService.SetUserKeyAsync(key); } } - else if (masterKey != null && - (!string.IsNullOrEmpty(tokenResponse.KeyConnectorUrl) || !string.IsNullOrEmpty(decryptOptions?.KeyConnectorOption?.KeyConnectorUrl))) + else if (!string.IsNullOrEmpty(tokenResponse.KeyConnectorUrl) || !string.IsNullOrEmpty(decryptOptions?.KeyConnectorOption?.KeyConnectorUrl)) { - await _cryptoService.SetMasterKeyAsync(masterKey); - var userKey = await _cryptoService.DecryptUserKeyWithMasterKeyAsync(masterKey); - await _cryptoService.SetUserKeyAsync(userKey); + + await _cryptoService.SetMasterKeyEncryptedUserKeyAsync(tokenResponse.Key); + if (masterKey != null) + { + await _cryptoService.SetMasterKeyAsync(masterKey); + var userKey = await _cryptoService.DecryptUserKeyWithMasterKeyAsync(masterKey); + await _cryptoService.SetUserKeyAsync(userKey); + } } // User doesn't have a key pair yet (old account), let's generate one for them. From 52aabe823745f6a7ade5194ef4e935a7450e7a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Bispo?= Date: Mon, 24 Jul 2023 22:52:25 +0100 Subject: [PATCH 3/3] [PM-2297] Remove reconciledOptions for deviceKey in state service --- src/Core/Services/DeviceTrustCryptoService.cs | 6 ++++-- src/Core/Services/StateService.cs | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Core/Services/DeviceTrustCryptoService.cs b/src/Core/Services/DeviceTrustCryptoService.cs index 93ccb905e..0d9b81aa9 100644 --- a/src/Core/Services/DeviceTrustCryptoService.cs +++ b/src/Core/Services/DeviceTrustCryptoService.cs @@ -33,12 +33,14 @@ namespace Bit.Core.Services public async Task GetDeviceKeyAsync() { - return await _stateService.GetDeviceKeyAsync(); + var activeUserId = await _stateService.GetActiveUserIdAsync(); + return await _stateService.GetDeviceKeyAsync(activeUserId); } private async Task SetDeviceKeyAsync(SymmetricCryptoKey deviceKey) { - await _stateService.SetDeviceKeyAsync(deviceKey); + var activeUserId = await _stateService.GetActiveUserIdAsync(); + await _stateService.SetDeviceKeyAsync(deviceKey, activeUserId); } public async Task TrustDeviceAsync() diff --git a/src/Core/Services/StateService.cs b/src/Core/Services/StateService.cs index 480bacaaa..49a069ddf 100644 --- a/src/Core/Services/StateService.cs +++ b/src/Core/Services/StateService.cs @@ -515,9 +515,7 @@ namespace Bit.Core.Services public async Task GetDeviceKeyAsync(string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, - await GetDefaultStorageOptionsAsync()); - var deviceKeyB64 = await _storageMediatorService.GetAsync(Constants.DeviceKeyKey(reconciledOptions.UserId), true); + var deviceKeyB64 = await _storageMediatorService.GetAsync(Constants.DeviceKeyKey(userId), true); if (string.IsNullOrEmpty(deviceKeyB64)) { return null; @@ -527,9 +525,7 @@ namespace Bit.Core.Services public async Task SetDeviceKeyAsync(SymmetricCryptoKey value, string userId = null) { - var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, - await GetDefaultStorageOptionsAsync()); - await _storageMediatorService.SaveAsync(Constants.DeviceKeyKey(reconciledOptions.UserId), value.KeyB64, true); + await _storageMediatorService.SaveAsync(Constants.DeviceKeyKey(userId), value.KeyB64, true); } public async Task> GetAutofillBlacklistedUrisAsync(string userId = null)