2023-04-17 17:03:40 +02:00
|
|
|
import * as os from "os";
|
|
|
|
|
2022-08-09 21:11:51 +02:00
|
|
|
import { Component, NgZone } from "@angular/core";
|
2020-07-23 23:24:35 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2021-05-06 20:19:48 +02:00
|
|
|
import { ipcRenderer } from "electron";
|
2018-02-10 04:47:53 +01:00
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2022-08-30 16:11:19 +02:00
|
|
|
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
|
2022-08-30 22:30:43 +02:00
|
|
|
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeoutSettings.service";
|
2023-04-17 16:35:37 +02:00
|
|
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/policy/policy-api.service.abstraction";
|
|
|
|
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
2023-04-17 16:35:37 +02:00
|
|
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
|
2018-02-10 04:47:53 +01:00
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
const BroadcasterSubscriptionId = "LockComponent";
|
|
|
|
|
2018-02-10 04:47:53 +01:00
|
|
|
@Component({
|
|
|
|
selector: "app-lock",
|
2018-04-06 18:25:22 +02:00
|
|
|
templateUrl: "lock.component.html",
|
2018-02-10 04:47:53 +01:00
|
|
|
})
|
2022-08-09 21:11:51 +02:00
|
|
|
export class LockComponent extends BaseLockComponent {
|
2021-07-05 00:06:24 +02:00
|
|
|
private deferFocus: boolean = null;
|
2023-04-17 17:03:40 +02:00
|
|
|
protected oldOs = false;
|
|
|
|
protected deprecated = false;
|
2021-07-05 00:06:24 +02:00
|
|
|
|
2018-10-03 15:42:11 +02:00
|
|
|
constructor(
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
2018-04-05 05:01:40 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
messagingService: MessagingService,
|
2021-12-15 23:32:00 +01:00
|
|
|
cryptoService: CryptoService,
|
|
|
|
vaultTimeoutService: VaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
2020-07-23 23:24:35 +02:00
|
|
|
environmentService: EnvironmentService,
|
|
|
|
stateService: StateService,
|
2020-11-04 18:09:21 +01:00
|
|
|
apiService: ApiService,
|
|
|
|
private route: ActivatedRoute,
|
2021-11-29 01:21:48 +01:00
|
|
|
private broadcasterService: BroadcasterService,
|
|
|
|
ngZone: NgZone,
|
2023-04-17 16:35:37 +02:00
|
|
|
policyApiService: PolicyApiServiceAbstraction,
|
|
|
|
policyService: InternalPolicyService,
|
|
|
|
passwordGenerationService: PasswordGenerationServiceAbstraction,
|
2021-11-09 19:00:01 +01:00
|
|
|
logService: LogService,
|
2022-10-04 20:43:51 +02:00
|
|
|
keyConnectorService: KeyConnectorService
|
2021-11-09 19:00:01 +01:00
|
|
|
) {
|
2021-12-15 23:32:00 +01:00
|
|
|
super(
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
messagingService,
|
|
|
|
cryptoService,
|
|
|
|
vaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService,
|
2021-12-15 23:32:00 +01:00
|
|
|
environmentService,
|
|
|
|
stateService,
|
|
|
|
apiService,
|
|
|
|
logService,
|
2021-11-29 01:21:48 +01:00
|
|
|
keyConnectorService,
|
2023-04-17 16:35:37 +02:00
|
|
|
ngZone,
|
|
|
|
policyApiService,
|
|
|
|
policyService,
|
|
|
|
passwordGenerationService
|
2021-11-29 01:21:48 +01:00
|
|
|
);
|
2023-04-17 17:03:40 +02:00
|
|
|
|
|
|
|
if (process.platform === "win32") {
|
|
|
|
try {
|
|
|
|
const release = os.release();
|
|
|
|
const majorVersion = parseInt(release.split(".")[0], 10);
|
|
|
|
|
|
|
|
this.oldOs = majorVersion < 10;
|
|
|
|
if (new Date() > new Date("2023-05-31")) {
|
|
|
|
this.deprecated = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 19:48:55 +01:00
|
|
|
}
|
2020-07-23 23:24:35 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
2021-12-15 23:32:00 +01:00
|
|
|
const autoPromptBiometric = !(await this.stateService.getNoAutoPromptBiometrics());
|
2021-05-06 20:19:48 +02:00
|
|
|
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-02-03 19:21:22 +01:00
|
|
|
this.route.queryParams.subscribe((params) => {
|
2022-10-27 12:49:59 +02:00
|
|
|
setTimeout(async () => {
|
|
|
|
if (!params.promptBiometric || !this.supportsBiometric || !autoPromptBiometric) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (await ipcRenderer.invoke("windowVisible")) {
|
|
|
|
this.unlockBiometric();
|
|
|
|
}
|
|
|
|
}, 1000);
|
2021-12-20 15:47:17 +01:00
|
|
|
});
|
2020-11-04 18:09:21 +01:00
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
|
|
|
this.ngZone.run(() => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "windowHidden":
|
|
|
|
this.onWindowHidden();
|
2021-12-20 15:47:17 +01:00
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
case "windowIsFocused":
|
|
|
|
if (this.deferFocus === null) {
|
|
|
|
this.deferFocus = !message.windowIsFocused;
|
|
|
|
if (!this.deferFocus) {
|
|
|
|
this.focusInput();
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
} else if (this.deferFocus && message.windowIsFocused) {
|
|
|
|
this.focusInput();
|
|
|
|
this.deferFocus = false;
|
2020-07-23 23:24:35 +02:00
|
|
|
}
|
2020-11-04 18:09:21 +01:00
|
|
|
break;
|
2021-07-05 00:06:24 +02:00
|
|
|
default:
|
2021-12-20 15:47:17 +01:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
});
|
2020-11-04 18:09:21 +01:00
|
|
|
});
|
2021-07-05 00:06:24 +02:00
|
|
|
this.messagingService.send("getWindowIsFocused");
|
2020-11-04 18:09:21 +01:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:00:44 +01:00
|
|
|
ngOnDestroy() {
|
2022-08-09 21:11:51 +02:00
|
|
|
super.ngOnDestroy();
|
2020-11-04 20:00:44 +01:00
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
|
|
|
|
2020-11-04 18:09:21 +01:00
|
|
|
onWindowHidden() {
|
|
|
|
this.showPassword = false;
|
2020-07-23 23:24:35 +02:00
|
|
|
}
|
2021-07-05 00:06:24 +02:00
|
|
|
|
|
|
|
private focusInput() {
|
|
|
|
document.getElementById(this.pinLock ? "pin" : "masterPassword").focus();
|
|
|
|
}
|
2018-02-10 04:47:53 +01:00
|
|
|
}
|