diff --git a/src/App/Pages/Accounts/RegisterPageViewModel.cs b/src/App/Pages/Accounts/RegisterPageViewModel.cs index 52cca400c..f69453bad 100644 --- a/src/App/Pages/Accounts/RegisterPageViewModel.cs +++ b/src/App/Pages/Accounts/RegisterPageViewModel.cs @@ -178,10 +178,7 @@ namespace Bit.App.Pages Email = Email.Trim().ToLower(); var kdfConfig = new KdfConfig(KdfType.PBKDF2_SHA256, Constants.Pbkdf2Iterations, null, null); var newMasterKey = await _cryptoService.MakeMasterKeyAsync(MasterPassword, Email, kdfConfig); - var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync( - newMasterKey, - await _cryptoService.MakeUserKeyAsync() - ); + var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync(newMasterKey); var hashedPassword = await _cryptoService.HashMasterKeyAsync(MasterPassword, newMasterKey); var (newPublicKey, newProtectedPrivateKey) = await _cryptoService.MakeKeyPairAsync(newUserKey); var request = new RegisterRequest diff --git a/src/App/Pages/Accounts/SetPasswordPageViewModel.cs b/src/App/Pages/Accounts/SetPasswordPageViewModel.cs index dd121c0a2..a933988a9 100644 --- a/src/App/Pages/Accounts/SetPasswordPageViewModel.cs +++ b/src/App/Pages/Accounts/SetPasswordPageViewModel.cs @@ -169,8 +169,7 @@ namespace Bit.App.Pages var masterPasswordHash = await _cryptoService.HashMasterKeyAsync(MasterPassword, newMasterKey, HashPurpose.ServerAuthorization); var localMasterPasswordHash = await _cryptoService.HashMasterKeyAsync(MasterPassword, newMasterKey, HashPurpose.LocalAuthorization); - var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync(newMasterKey, - await _cryptoService.GetUserKeyAsync() ?? await _cryptoService.MakeUserKeyAsync()); + var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync(newMasterKey); var (newPublicKey, newProtectedPrivateKey) = await _cryptoService.MakeKeyPairAsync(newUserKey); var request = new SetPasswordRequest diff --git a/src/Core/Abstractions/ICryptoService.cs b/src/Core/Abstractions/ICryptoService.cs index 777ff65f4..106c43426 100644 --- a/src/Core/Abstractions/ICryptoService.cs +++ b/src/Core/Abstractions/ICryptoService.cs @@ -23,7 +23,7 @@ namespace Bit.Core.Abstractions Task GetMasterKeyAsync(string userId = null); Task MakeMasterKeyAsync(string password, string email, KdfConfig kdfConfig); Task ClearMasterKeyAsync(string userId = null); - Task> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey, UserKey userKey = null); + Task> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey); Task DecryptUserKeyWithMasterKeyAsync(MasterKey masterKey, EncString encUserKey = null, string userId = null); Task> MakeDataEncKeyAsync(UserKey key); Task> MakeDataEncKeyAsync(OrgKey key); diff --git a/src/Core/Services/AuthService.cs b/src/Core/Services/AuthService.cs index 8b15475aa..e6a8e9517 100644 --- a/src/Core/Services/AuthService.cs +++ b/src/Core/Services/AuthService.cs @@ -514,13 +514,15 @@ namespace Bit.Core.Services { // SSO Key Connector Onboarding var password = await _cryptoFunctionService.RandomBytesAsync(64); - var newMasterKey = await _cryptoService.MakeMasterKeyAsync(Convert.ToBase64String(password), _tokenService.GetEmail(), tokenResponse.KdfConfig); + var newMasterKey = await _cryptoService.MakeMasterKeyAsync( + Convert.ToBase64String(password), + _tokenService.GetEmail(), + tokenResponse.KdfConfig); + var keyConnectorRequest = new KeyConnectorUserKeyRequest(newMasterKey.EncKeyB64); await _cryptoService.SetMasterKeyAsync(newMasterKey); - var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync( - newMasterKey, - await _cryptoService.MakeUserKeyAsync()); + var (newUserKey, newProtectedUserKey) = await _cryptoService.EncryptUserKeyWithMasterKeyAsync(newMasterKey); await _cryptoService.SetUserKeyAsync(newUserKey); var (newPublicKey, newProtectedPrivateKey) = await _cryptoService.MakeKeyPairAsync(); diff --git a/src/Core/Services/CryptoService.cs b/src/Core/Services/CryptoService.cs index a49bd808a..6993eca2c 100644 --- a/src/Core/Services/CryptoService.cs +++ b/src/Core/Services/CryptoService.cs @@ -143,9 +143,9 @@ namespace Bit.Core.Services return _stateService.SetMasterKeyAsync(null, userId); } - public async Task> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey, UserKey userKey = null) + public async Task> EncryptUserKeyWithMasterKeyAsync(MasterKey masterKey) { - userKey ??= await GetUserKeyAsync(); + var userKey = await GetUserKeyAsync() ?? await MakeUserKeyAsync(); return await BuildProtectedSymmetricKey(masterKey, userKey.Key, keyBytes => new UserKey(keyBytes)); }