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 721ee9849749..b1f0f562c4e9 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 @@ -247,6 +247,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { async makePreloginKey(masterPassword: string, email: string): Promise { email = email.trim().toLowerCase(); let kdfConfig: KdfConfig = null; + let salt: string | undefined = undefined; try { const preloginResponse = await this.apiService.postPrelogin(new PreloginRequest(email)); if (preloginResponse != null) { @@ -258,6 +259,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { preloginResponse.kdfMemory, preloginResponse.kdfParallelism, ); + salt = preloginResponse.salt; } } catch (e) { if (e == null || e.statusCode !== 404) { @@ -267,7 +269,8 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction { kdfConfig.validateKdfConfigForPrelogin(); - return await this.keyService.makeMasterKey(masterPassword, email, kdfConfig); + // Cozy customization; used salt from backend + return await this.keyService.makeMasterKey(masterPassword, salt, kdfConfig); } private async clearCache(): Promise { diff --git a/libs/common/src/auth/models/response/prelogin.response.ts b/libs/common/src/auth/models/response/prelogin.response.ts index c6762e22376c..77028955da76 100644 --- a/libs/common/src/auth/models/response/prelogin.response.ts +++ b/libs/common/src/auth/models/response/prelogin.response.ts @@ -6,6 +6,7 @@ export class PreloginResponse extends BaseResponse { kdfIterations: number; kdfMemory?: number; kdfParallelism?: number; + salt?: string; // Cozy customization constructor(response: any) { super(response); @@ -13,5 +14,6 @@ export class PreloginResponse extends BaseResponse { this.kdfIterations = this.getResponseProperty("KdfIterations"); this.kdfMemory = this.getResponseProperty("KdfMemory"); this.kdfParallelism = this.getResponseProperty("KdfParallelism"); + this.salt = this.getResponseProperty("Salt"); // Cozy customization } }