Skip to content

Commit

Permalink
Fix userkey typing in background biometrics service
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Jan 13, 2025
1 parent e141a1a commit 0daad18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/browser/src/background/runtime.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export default class RuntimeBackground {
return await this.main.biometricsService.getBiometricsStatus();
}
case BiometricsCommands.UnlockWithBiometricsForUser: {
return await this.main.biometricsService.unlockWithBiometricsForUser(msg.userId);
const userKey = await this.main.biometricsService.unlockWithBiometricsForUser(msg.userId);
return userKey.keyB64;

Check warning on line 199 in apps/browser/src/background/runtime.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/runtime.background.ts#L198-L199

Added lines #L198 - L199 were not covered by tests
}
case BiometricsCommands.GetBiometricsStatusForUser: {
return await this.main.biometricsService.getBiometricsStatusForUser(msg.userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
}
}

async unlockWithBiometricsForUser(userId: UserId): Promise<UserKey | null | undefined> {
async unlockWithBiometricsForUser(userId: UserId): Promise<UserKey | null> {
try {
await this.ensureConnected();

Expand All @@ -96,7 +96,7 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
await this.biometricStateService.setBiometricUnlockEnabled(true);
await this.biometricStateService.setFingerprintValidated(true);
this.keyService.setUserKey(userKey, userId);
return response.userKeyB64;
return userKey;

Check warning on line 99 in apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts#L96-L99

Added lines #L96 - L99 were not covered by tests
}
} else {
return null;
Expand All @@ -107,13 +107,14 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
userId: userId,
});
if (response.response) {
// In case the requesting foreground context dies (popup), the userkey should still be set, so the user is unlocked / the setting should be enabled
const decodedUserkey = Utils.fromB64ToArray(response.userKeyB64);
const userKey = new SymmetricCryptoKey(decodedUserkey) as UserKey;

Check warning on line 112 in apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts#L111-L112

Added lines #L111 - L112 were not covered by tests
if (await this.keyService.validateUserKey(userKey, userId)) {
await this.biometricStateService.setBiometricUnlockEnabled(true);
await this.biometricStateService.setFingerprintValidated(true);
this.keyService.setUserKey(userKey, userId);
return response.userKeyB64;
return userKey;

Check warning on line 117 in apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts#L114-L117

Added lines #L114 - L117 were not covered by tests
}
} else {
return null;
Expand All @@ -123,6 +124,8 @@ export class BackgroundBrowserBiometricsService extends BiometricsService {
this.logService.info("Biometric unlock for user failed", e);
throw new Error("Biometric unlock failed");
}

return null;

Check warning on line 128 in apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/key-management/biometrics/background-browser-biometrics.service.ts#L128

Added line #L128 was not covered by tests
}

async getBiometricsStatusForUser(id: UserId): Promise<BiometricsStatus> {
Expand Down

0 comments on commit 0daad18

Please sign in to comment.