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 e433459ea19..2961ee006be 100644 --- a/libs/auth/src/angular/change-password/change-password.component.ts +++ b/libs/auth/src/angular/change-password/change-password.component.ts @@ -93,7 +93,7 @@ export class ChangePasswordComponent implements OnInit { await this.syncService.fullSync(true); if (this.activeAccount == null) { - throw new Error("User or userId not found"); + throw new Error("User not found"); } await this.changePasswordService.rotateUserKeyMasterPasswordAndEncryptedData( @@ -103,14 +103,7 @@ export class ChangePasswordComponent implements OnInit { passwordInputResult.newPasswordHint, ); } else { - await this.changePasswordService.changePassword( - passwordInputResult.currentMasterKey, - passwordInputResult.currentServerMasterKeyHash, - passwordInputResult.newPasswordHint, - passwordInputResult.newMasterKey, - passwordInputResult.newServerMasterKeyHash, - this.userId, - ); + await this.changePasswordService.changePassword(passwordInputResult, this.userId); this.toastService.showToast({ variant: "success", @@ -153,8 +146,8 @@ export class ChangePasswordComponent implements OnInit { const request = new PasswordRequest(); request.masterPasswordHash = passwordInputResult.currentServerMasterKeyHash; - request.masterPasswordHint = passwordInputResult.newPasswordHint; request.newMasterPasswordHash = passwordInputResult.newServerMasterKeyHash; + request.masterPasswordHint = passwordInputResult.newPasswordHint; request.key = newMasterKeyEncryptedUserKey[1].encryptedString as string; try { diff --git a/libs/auth/src/common/abstractions/change-password.service.abstraction.ts b/libs/auth/src/common/abstractions/change-password.service.abstraction.ts index b03460cb24d..32aaa5543eb 100644 --- a/libs/auth/src/common/abstractions/change-password.service.abstraction.ts +++ b/libs/auth/src/common/abstractions/change-password.service.abstraction.ts @@ -1,6 +1,6 @@ +import { PasswordInputResult } from "@bitwarden/auth/angular"; import { Account } from "@bitwarden/common/auth/abstractions/account.service"; import { UserId } from "@bitwarden/common/types/guid"; -import { MasterKey } from "@bitwarden/common/types/key"; export abstract class ChangePasswordService { abstract rotateUserKeyMasterPasswordAndEncryptedData( @@ -15,12 +15,5 @@ export abstract class ChangePasswordService { user: Account, ): Promise; - abstract changePassword( - currentMasterKey: MasterKey, - currentServerMasterKeyHash: string, - newPasswordHint: string, - newMasterKey: MasterKey, - newServerMasterKeyHash: string, - userId: UserId, - ): Promise; + abstract changePassword(passwordInputResult: PasswordInputResult, userId: UserId): Promise; } diff --git a/libs/auth/src/common/services/change-password/default-change-password.service.ts b/libs/auth/src/common/services/change-password/default-change-password.service.ts index 934940cd341..605123eb900 100644 --- a/libs/auth/src/common/services/change-password/default-change-password.service.ts +++ b/libs/auth/src/common/services/change-password/default-change-password.service.ts @@ -1,9 +1,9 @@ +import { PasswordInputResult } from "@bitwarden/auth/angular"; import { Account } from "@bitwarden/common/auth/abstractions/account.service"; import { MasterPasswordApiService } from "@bitwarden/common/auth/abstractions/master-password-api.service.abstraction"; import { PasswordRequest } from "@bitwarden/common/auth/models/request/password.request"; import { InternalMasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction"; import { UserId } from "@bitwarden/common/types/guid"; -import { MasterKey } from "@bitwarden/common/types/key"; import { KeyService } from "@bitwarden/key-management"; import { ChangePasswordService } from "../../abstractions"; @@ -31,20 +31,13 @@ export class DefaultChangePasswordService implements ChangePasswordService { return null; // implemented in Web } - async changePassword( - currentMasterKey: MasterKey, - currentServerMasterKeyHash: string, - newPasswordHint: string, - newMasterKey: MasterKey, - newServerMasterKeyHash: string, - userId: UserId, - ) { + async changePassword(passwordInputResult: PasswordInputResult, userId: UserId) { if (!userId) { throw new Error("The change password process requires a userId"); } const decryptedUserKey = await this.masterPasswordService.decryptUserKeyWithMasterKey( - currentMasterKey, + passwordInputResult.currentMasterKey, userId, ); @@ -53,14 +46,14 @@ export class DefaultChangePasswordService implements ChangePasswordService { } const newMasterKeyEncryptedUserKey = await this.keyService.encryptUserKeyWithMasterKey( - newMasterKey, + passwordInputResult.newMasterKey, decryptedUserKey, ); const request = new PasswordRequest(); - request.masterPasswordHash = currentServerMasterKeyHash; - request.masterPasswordHint = newPasswordHint; - request.newMasterPasswordHash = newServerMasterKeyHash; + request.masterPasswordHash = passwordInputResult.currentServerMasterKeyHash; + request.newMasterPasswordHash = passwordInputResult.newServerMasterKeyHash; + request.masterPasswordHint = passwordInputResult.newPasswordHint; request.key = newMasterKeyEncryptedUserKey[1].encryptedString as string; try {