From 819aabb33020b9d7039554ebe64b4620ee932cc2 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Fri, 25 Aug 2023 09:47:37 -0400 Subject: [PATCH] don't clear key needed for bio/auto migration in pin migration (#2721) --- src/Core/Services/CryptoService.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Core/Services/CryptoService.cs b/src/Core/Services/CryptoService.cs index 856f0f777..89dce3e36 100644 --- a/src/Core/Services/CryptoService.cs +++ b/src/Core/Services/CryptoService.cs @@ -1011,6 +1011,10 @@ namespace Bit.Core.Services // Decrypt var masterKey = new MasterKey(Convert.FromBase64String(oldKey)); var encryptedUserKey = await _stateService.GetEncKeyEncryptedAsync(userId); + if (encryptedUserKey == null) + { + return; + } var userKey = await DecryptUserKeyWithMasterKeyAsync( masterKey, new EncString(encryptedUserKey), @@ -1070,8 +1074,11 @@ namespace Bit.Core.Services var encPin = await EncryptAsync(pin, userKey); await _stateService.SetProtectedPinAsync(encPin.EncryptedString); } - // Clear old key - await _stateService.SetEncKeyEncryptedAsync(null); + // Clear old key only if not needed for bio/auto migration + if (await _stateService.GetKeyEncryptedAsync() != null) + { + await _stateService.SetEncKeyEncryptedAsync(null); + } return userKey; }