@ -10,7 +10,9 @@ import {
@@ -10,7 +10,9 @@ import {
import { AuditService } from "@bitwarden/common/abstractions/audit.service" ;
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction" ;
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options" ;
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum" ;
import { MasterPasswordServiceAbstraction } from "@bitwarden/common/key-management/master-password/abstractions/master-password.service.abstraction" ;
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service" ;
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service" ;
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service" ;
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service" ;
@ -209,6 +211,7 @@ export class InputPasswordComponent implements OnInit {
@@ -209,6 +211,7 @@ export class InputPasswordComponent implements OnInit {
constructor (
private auditService : AuditService ,
private cipherService : CipherService ,
private configService : ConfigService ,
private dialogService : DialogService ,
private formBuilder : FormBuilder ,
private i18nService : I18nService ,
@ -312,7 +315,7 @@ export class InputPasswordComponent implements OnInit {
@@ -312,7 +315,7 @@ export class InputPasswordComponent implements OnInit {
}
if ( ! this . email ) {
throw new Error ( "Email is required to create master key ." ) ;
throw new Error ( "Email not found ." ) ;
}
// 1. Determine kdfConfig
@ -320,13 +323,13 @@ export class InputPasswordComponent implements OnInit {
@@ -320,13 +323,13 @@ export class InputPasswordComponent implements OnInit {
this . kdfConfig = DEFAULT_KDF_CONFIG ;
} else {
if ( ! this . userId ) {
throw new Error ( "userId not passed down " ) ;
throw new Error ( "userId not found. " ) ;
}
this . kdfConfig = await firstValueFrom ( this . kdfConfigService . getKdfConfig $ ( this . userId ) ) ;
}
if ( this . kdfConfig == null ) {
throw new Error ( "KdfConfig is required to create master key ." ) ;
throw new Error ( "KdfConfig not found ." ) ;
}
const salt =
@ -334,7 +337,7 @@ export class InputPasswordComponent implements OnInit {
@@ -334,7 +337,7 @@ export class InputPasswordComponent implements OnInit {
? await firstValueFrom ( this . masterPasswordService . saltForUser $ ( this . userId ) )
: this . masterPasswordService . emailToSalt ( this . email ) ;
if ( salt == null ) {
throw new Error ( "Salt is required to create master key ." ) ;
throw new Error ( "Salt not found ." ) ;
}
// 2. Verify current password is correct (if necessary)
@ -361,6 +364,26 @@ export class InputPasswordComponent implements OnInit {
@@ -361,6 +364,26 @@ export class InputPasswordComponent implements OnInit {
return ;
}
const newApisFlagEnabled = await this . configService . getFeatureFlag (
FeatureFlag . PM27086_UpdateAuthenticationApisForInputPassword ,
) ;
if ( newApisFlagEnabled ) {
// 4. Build a PasswordInputResult object
const passwordInputResult : PasswordInputResult = {
currentPassword ,
newPassword ,
kdfConfig : this.kdfConfig ,
salt ,
newPasswordHint ,
rotateUserKey : this.formGroup.controls.rotateUserKey?.value ? ? false ,
} ;
// 5. Emit and return PasswordInputResult object
this . onPasswordFormSubmit . emit ( passwordInputResult ) ;
return passwordInputResult ;
}
// 4. Create cryptographic keys and build a PasswordInputResult object
const newMasterKey = await this . keyService . makeMasterKey (
newPassword ,