mirror of
https://github.com/bitwarden/server
synced 2026-02-26 17:33:40 +00:00
[PM-27281] Support v2 account encryption on JIT master password signups (#6777)
* V2 prep, rename existing SSO JIT MP command to V1 * set initial master password for account registraton V2 * later removel docs * TDE MP onboarding split * revert separate TDE onboarding controller api * Server side hash of the user master password hash * use `ValidationResult` instead for validation errors * unit test coverage * integration test coverage * update sql migration script date * revert validate password change * better requests validation * explicit error message when org sso identifier invalid * more unit test coverage * renamed onboarding to set, hash naming clarifications * update db sql script, formatting * use raw json as request instead of request models for integration test * v1 integration test coverage * change of name
This commit is contained in:
@@ -428,6 +428,55 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
};
|
||||
}
|
||||
|
||||
public UpdateUserData SetMasterPassword(Guid userId, MasterPasswordUnlockData masterPasswordUnlockData,
|
||||
string serverSideHashedMasterPasswordAuthenticationHash, string? masterPasswordHint)
|
||||
{
|
||||
return async (connection, transaction) =>
|
||||
{
|
||||
var timestamp = DateTime.UtcNow;
|
||||
|
||||
await connection!.ExecuteAsync(
|
||||
"[dbo].[User_UpdateMasterPassword]",
|
||||
new
|
||||
{
|
||||
Id = userId,
|
||||
MasterPassword = serverSideHashedMasterPasswordAuthenticationHash,
|
||||
MasterPasswordHint = masterPasswordHint,
|
||||
Key = masterPasswordUnlockData.MasterKeyWrappedUserKey,
|
||||
Kdf = masterPasswordUnlockData.Kdf.KdfType,
|
||||
KdfIterations = masterPasswordUnlockData.Kdf.Iterations,
|
||||
KdfMemory = masterPasswordUnlockData.Kdf.Memory,
|
||||
KdfParallelism = masterPasswordUnlockData.Kdf.Parallelism,
|
||||
RevisionDate = timestamp,
|
||||
AccountRevisionDate = timestamp
|
||||
},
|
||||
transaction: transaction,
|
||||
commandType: CommandType.StoredProcedure);
|
||||
};
|
||||
}
|
||||
|
||||
public async Task UpdateUserDataAsync(IEnumerable<UpdateUserData> updateUserDataActions)
|
||||
{
|
||||
await using var connection = new SqlConnection(ConnectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
await using var transaction = connection.BeginTransaction();
|
||||
try
|
||||
{
|
||||
foreach (var action in updateUserDataActions)
|
||||
{
|
||||
await action(connection, transaction);
|
||||
}
|
||||
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ProtectDataAndSaveAsync(User user, Func<Task> saveTask)
|
||||
{
|
||||
if (user == null)
|
||||
|
||||
Reference in New Issue
Block a user