From cc52fcc1e6157d48466a936410a9ccf3ca3b320a Mon Sep 17 00:00:00 2001 From: rr-bw <102181210+rr-bw@users.noreply.github.com> Date: Thu, 3 Apr 2025 13:52:35 -0700 Subject: [PATCH] update newMasterKeyEncryptedUserKey creating in legacy performSubmitActions method --- .../change-password.component.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libs/auth/src/angular/change-password/change-password.component.ts b/libs/auth/src/angular/change-password/change-password.component.ts index 04ed4ffc51f..bd9f5a67bcf 100644 --- a/libs/auth/src/angular/change-password/change-password.component.ts +++ b/libs/auth/src/angular/change-password/change-password.component.ts @@ -13,8 +13,10 @@ import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key- import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service"; +import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; import { SyncService } from "@bitwarden/common/platform/sync"; import { UserId } from "@bitwarden/common/types/guid"; +import { UserKey } from "@bitwarden/common/types/key"; import { ToastService } from "@bitwarden/components"; import { KeyService } from "@bitwarden/key-management"; @@ -119,20 +121,19 @@ export class ChangePasswordComponent implements OnInit { const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$)); - const decryptedUserKey = await this.masterPasswordService.decryptUserKeyWithMasterKey( - passwordInputResult.currentMasterKey, - userId, - ); + let newMasterKeyEncryptedUserKey: [UserKey, EncString] = null; - if (decryptedUserKey == null) { - throw new Error("Could not decrypt user key"); + const userKey = await this.keyService.getUserKey(); + if (userKey == null) { + newMasterKeyEncryptedUserKey = await this.keyService.makeUserKey( + passwordInputResult.newMasterKey, + ); + } else { + newMasterKeyEncryptedUserKey = await this.keyService.encryptUserKeyWithMasterKey( + passwordInputResult.newMasterKey, + ); } - const newMasterKeyEncryptedUserKey = await this.keyService.encryptUserKeyWithMasterKey( - passwordInputResult.newMasterKey, - decryptedUserKey, - ); - const request = new PasswordRequest(); request.masterPasswordHash = passwordInputResult.currentServerMasterKeyHash; request.masterPasswordHint = passwordInputResult.newPasswordHint;