2022-04-05 16:54:44 +02:00
|
|
|
import { ipcMain } from "electron";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-07-25 13:24:13 +02:00
|
|
|
import { biometrics } from "@bitwarden/desktop-native";
|
2022-12-02 12:45:09 +01:00
|
|
|
|
|
|
|
import { WindowMain } from "../window.main";
|
2022-04-05 16:54:44 +02:00
|
|
|
|
2022-09-29 16:38:50 +02:00
|
|
|
import { BiometricMain } from "./biometric.main";
|
2022-04-05 16:54:44 +02:00
|
|
|
|
|
|
|
export default class BiometricWindowsMain implements BiometricMain {
|
|
|
|
constructor(
|
|
|
|
private i18nservice: I18nService,
|
|
|
|
private windowMain: WindowMain,
|
|
|
|
private stateService: StateService,
|
|
|
|
private logService: LogService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
async init() {
|
|
|
|
let supportsBiometric = false;
|
|
|
|
try {
|
|
|
|
supportsBiometric = await this.supportsBiometric();
|
2022-07-25 13:24:13 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2022-04-05 16:54:44 +02:00
|
|
|
}
|
|
|
|
await this.stateService.setEnableBiometric(supportsBiometric);
|
|
|
|
await this.stateService.setBiometricText("unlockWithWindowsHello");
|
2022-06-23 09:53:42 +02:00
|
|
|
await this.stateService.setNoAutoPromptBiometricsText("autoPromptWindowsHello");
|
2022-04-05 16:54:44 +02:00
|
|
|
|
2022-07-25 13:24:13 +02:00
|
|
|
ipcMain.handle("biometric", async () => {
|
|
|
|
return await this.authenticateBiometric();
|
2022-04-05 16:54:44 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async supportsBiometric(): Promise<boolean> {
|
|
|
|
try {
|
2022-07-25 13:24:13 +02:00
|
|
|
return await biometrics.available();
|
2022-04-05 16:54:44 +02:00
|
|
|
} catch {
|
2022-07-25 13:24:13 +02:00
|
|
|
return false;
|
2022-04-05 16:54:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 13:24:13 +02:00
|
|
|
async authenticateBiometric(): Promise<boolean> {
|
|
|
|
const hwnd = this.windowMain.win.getNativeWindowHandle();
|
|
|
|
return await biometrics.prompt(hwnd, this.i18nservice.t("windowsHelloConsentMessage"));
|
2022-04-05 16:54:44 +02:00
|
|
|
}
|
|
|
|
}
|