diff --git a/libs/auth/src/common/login-strategies/password-login.strategy.ts b/libs/auth/src/common/login-strategies/password-login.strategy.ts index be93d39ebc..427f8178e4 100644 --- a/libs/auth/src/common/login-strategies/password-login.strategy.ts +++ b/libs/auth/src/common/login-strategies/password-login.strategy.ts @@ -63,14 +63,12 @@ export class PasswordLoginStrategyData implements LoginStrategyData { } export class PasswordLoginStrategy extends LoginStrategy { - /** - * The email address of the user attempting to log in. - */ + /** The email address of the user attempting to log in. */ email$: Observable; - /** - * The master key hash of the user attempting to log in. - */ - masterKeyHash$: Observable; + /** The master key hash used for authentication */ + serverMasterKeyHash$: Observable; + /** The local master key hash we store client side */ + localMasterKeyHash$: Observable; protected cache: BehaviorSubject; @@ -107,7 +105,10 @@ export class PasswordLoginStrategy extends LoginStrategy { this.cache = new BehaviorSubject(data); this.email$ = this.cache.pipe(map((state) => state.tokenRequest.email)); - this.masterKeyHash$ = this.cache.pipe(map((state) => state.localMasterKeyHash)); + this.serverMasterKeyHash$ = this.cache.pipe( + map((state) => state.tokenRequest.masterPasswordHash), + ); + this.localMasterKeyHash$ = this.cache.pipe(map((state) => state.localMasterKeyHash)); } override async logIn(credentials: PasswordLoginCredentials) { @@ -123,11 +124,14 @@ export class PasswordLoginStrategy extends LoginStrategy { data.masterKey, HashPurpose.LocalAuthorization, ); - const masterKeyHash = await this.cryptoService.hashMasterKey(masterPassword, data.masterKey); + const serverMasterKeyHash = await this.cryptoService.hashMasterKey( + masterPassword, + data.masterKey, + ); data.tokenRequest = new PasswordTokenRequest( email, - masterKeyHash, + serverMasterKeyHash, captchaToken, await this.buildTwoFactor(twoFactor, email), await this.buildDeviceRequest(), diff --git a/libs/auth/src/common/services/login-strategies/login-strategy.service.ts b/libs/auth/src/common/services/login-strategies/login-strategy.service.ts index 5dbc3397cf..428258308a 100644 --- a/libs/auth/src/common/services/login-strategies/login-strategy.service.ts +++ b/libs/auth/src/common/services/login-strategies/login-strategy.service.ts @@ -137,8 +137,8 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { async getMasterPasswordHash(): Promise { const strategy = await firstValueFrom(this.loginStrategy$); - if ("masterKeyHash$" in strategy) { - return await firstValueFrom(strategy.masterKeyHash$); + if ("serverMasterKeyHash$" in strategy) { + return await firstValueFrom(strategy.serverMasterKeyHash$); } return null; }