From 53be4946de4c55c338c950c7043ead120ab0ceeb Mon Sep 17 00:00:00 2001 From: Daniel James Smith <2670567+djsmith85@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:15:28 +0100 Subject: [PATCH] [PM-5717] Fix calling methods on undefined in biometrics service (#7559) * Fix calling init() on undefined in biometrics.service.ts * Add guard on osSupportsBiometric * Create NoopBiometricsService instead of method guards --------- Co-authored-by: Daniel James Smith --- .../main/biometric/biometric.noop.main.ts | 34 +++++++++++++++++++ .../main/biometric/biometrics.service.ts | 8 +++++ 2 files changed, 42 insertions(+) create mode 100644 apps/desktop/src/platform/main/biometric/biometric.noop.main.ts diff --git a/apps/desktop/src/platform/main/biometric/biometric.noop.main.ts b/apps/desktop/src/platform/main/biometric/biometric.noop.main.ts new file mode 100644 index 0000000000..152b5ce32f --- /dev/null +++ b/apps/desktop/src/platform/main/biometric/biometric.noop.main.ts @@ -0,0 +1,34 @@ +import { OsBiometricService } from "./biometrics.service.abstraction"; + +export default class NoopBiometricsService implements OsBiometricService { + constructor() {} + + async init() {} + + async osSupportsBiometric(): Promise { + return false; + } + + async getBiometricKey( + service: string, + storageKey: string, + clientKeyHalfB64: string, + ): Promise { + return null; + } + + async setBiometricKey( + service: string, + storageKey: string, + value: string, + clientKeyPartB64: string | undefined, + ): Promise { + return; + } + + async deleteBiometricKey(service: string, key: string): Promise {} + + async authenticateBiometric(): Promise { + throw new Error("Not supported on this platform"); + } +} diff --git a/apps/desktop/src/platform/main/biometric/biometrics.service.ts b/apps/desktop/src/platform/main/biometric/biometrics.service.ts index ea223c8914..54b8487175 100644 --- a/apps/desktop/src/platform/main/biometric/biometrics.service.ts +++ b/apps/desktop/src/platform/main/biometric/biometrics.service.ts @@ -27,6 +27,8 @@ export class BiometricsService implements BiometricsServiceAbstraction { this.loadWindowsHelloService(); } else if (platform === "darwin") { this.loadMacOSService(); + } else { + this.loadNoopBiometricsService(); } } @@ -47,6 +49,12 @@ export class BiometricsService implements BiometricsServiceAbstraction { this.platformSpecificService = new BiometricDarwinMain(this.i18nService, this.stateService); } + private loadNoopBiometricsService() { + // eslint-disable-next-line + const NoopBiometricsService = require("./biometric.noop.main").default; + this.platformSpecificService = new NoopBiometricsService(); + } + async init() { return await this.platformSpecificService.init(); }