Skip to content

Commit 2dc1b9c

Browse files
committed
feat: Use salt from backend
1 parent 5c015e7 commit 2dc1b9c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

libs/auth/src/common/services/login-strategies/login-strategy.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
247247
async makePreloginKey(masterPassword: string, email: string): Promise<MasterKey> {
248248
email = email.trim().toLowerCase();
249249
let kdfConfig: KdfConfig = null;
250+
let salt: string | undefined = undefined;
250251
try {
251252
const preloginResponse = await this.apiService.postPrelogin(new PreloginRequest(email));
252253
if (preloginResponse != null) {
@@ -258,6 +259,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
258259
preloginResponse.kdfMemory,
259260
preloginResponse.kdfParallelism,
260261
);
262+
salt = preloginResponse.salt;
261263
}
262264
} catch (e) {
263265
if (e == null || e.statusCode !== 404) {
@@ -267,7 +269,8 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
267269

268270
kdfConfig.validateKdfConfigForPrelogin();
269271

270-
return await this.keyService.makeMasterKey(masterPassword, email, kdfConfig);
272+
// Cozy customization; used salt from backend
273+
return await this.keyService.makeMasterKey(masterPassword, salt, kdfConfig);
271274
}
272275

273276
private async clearCache(): Promise<void> {

libs/common/src/auth/models/response/prelogin.response.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export class PreloginResponse extends BaseResponse {
66
kdfIterations: number;
77
kdfMemory?: number;
88
kdfParallelism?: number;
9+
salt?: string; // Cozy customization
910

1011
constructor(response: any) {
1112
super(response);
1213
this.kdf = this.getResponseProperty("Kdf");
1314
this.kdfIterations = this.getResponseProperty("KdfIterations");
1415
this.kdfMemory = this.getResponseProperty("KdfMemory");
1516
this.kdfParallelism = this.getResponseProperty("KdfParallelism");
17+
this.salt = this.getResponseProperty("Salt"); // Cozy customization
1618
}
1719
}

0 commit comments

Comments
 (0)