2021-11-29 01:14:04 +01:00
|
|
|
import { Component, NgZone } from "@angular/core";
|
2018-04-05 04:59:42 +02:00
|
|
|
import { Router } from "@angular/router";
|
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/auth/components/lock.component";
|
2023-05-02 18:46:03 +02:00
|
|
|
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.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 { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
|
|
|
import { KeyConnectorService } from "@bitwarden/common/auth/abstractions/key-connector.service";
|
|
|
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
|
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
2023-06-13 23:22:25 +02:00
|
|
|
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
|
2018-04-05 04:59:42 +02:00
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
import { BiometricErrors, BiometricErrorTypes } from "../../models/biometricErrors";
|
|
|
|
|
2018-04-05 04:59:42 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-lock",
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: "lock.component.html",
|
2018-04-05 04:59:42 +02:00
|
|
|
})
|
2019-01-08 05:29:50 +01:00
|
|
|
export class LockComponent extends BaseLockComponent {
|
2021-09-17 10:22:46 +02:00
|
|
|
private isInitialLockScreen: boolean;
|
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
biometricError: string;
|
|
|
|
pendingBiometric = false;
|
|
|
|
|
2018-10-03 06:21:22 +02:00
|
|
|
constructor(
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
2018-04-05 04:59:42 +02:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
messagingService: MessagingService,
|
2019-02-13 05:53:04 +01:00
|
|
|
cryptoService: CryptoService,
|
2020-04-06 17:40:16 +02:00
|
|
|
vaultTimeoutService: VaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService: VaultTimeoutSettingsService,
|
2020-07-29 23:01:05 +02:00
|
|
|
environmentService: EnvironmentService,
|
|
|
|
stateService: StateService,
|
2021-11-29 01:14:04 +01:00
|
|
|
apiService: ApiService,
|
|
|
|
logService: LogService,
|
|
|
|
keyConnectorService: KeyConnectorService,
|
2022-05-01 23:57:40 +02:00
|
|
|
ngZone: NgZone,
|
2023-04-17 16:35:37 +02:00
|
|
|
policyApiService: PolicyApiServiceAbstraction,
|
|
|
|
policyService: InternalPolicyService,
|
2023-06-13 23:22:25 +02:00
|
|
|
passwordStrengthService: PasswordStrengthServiceAbstraction,
|
2023-05-02 18:46:03 +02:00
|
|
|
private authService: AuthService,
|
|
|
|
dialogService: DialogServiceAbstraction
|
2021-11-29 01:14:04 +01:00
|
|
|
) {
|
2019-02-13 05:53:04 +01:00
|
|
|
super(
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
platformUtilsService,
|
|
|
|
messagingService,
|
|
|
|
cryptoService,
|
2021-11-09 18:59:51 +01:00
|
|
|
vaultTimeoutService,
|
2022-08-30 22:30:43 +02:00
|
|
|
vaultTimeoutSettingsService,
|
2021-11-09 18:59:51 +01:00
|
|
|
environmentService,
|
|
|
|
stateService,
|
|
|
|
apiService,
|
|
|
|
logService,
|
2021-11-29 01:14:04 +01:00
|
|
|
keyConnectorService,
|
2023-04-17 16:35:37 +02:00
|
|
|
ngZone,
|
|
|
|
policyApiService,
|
|
|
|
policyService,
|
2023-06-13 23:22:25 +02:00
|
|
|
passwordStrengthService,
|
2023-05-02 18:46:03 +02:00
|
|
|
dialogService
|
2021-11-29 01:14:04 +01:00
|
|
|
);
|
2022-10-04 20:43:51 +02:00
|
|
|
this.successRoute = "/tabs/current";
|
2021-09-17 10:22:46 +02:00
|
|
|
this.isInitialLockScreen = (window as any).previousPopupUrl == null;
|
2018-04-05 04:59:42 +02:00
|
|
|
}
|
2021-09-17 10:22:46 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2019-02-13 05:53:04 +01:00
|
|
|
await super.ngOnInit();
|
2021-09-17 10:22:46 +02:00
|
|
|
const disableAutoBiometricsPrompt =
|
2022-01-27 22:22:51 +01:00
|
|
|
(await this.stateService.getDisableAutoBiometricsPrompt()) ?? true;
|
2020-10-11 20:42:09 +02:00
|
|
|
|
2021-09-28 16:37:18 +02:00
|
|
|
window.setTimeout(async () => {
|
|
|
|
document.getElementById(this.pinLock ? "pin" : "masterPassword").focus();
|
2022-05-01 23:57:40 +02:00
|
|
|
if (
|
|
|
|
this.biometricLock &&
|
|
|
|
!disableAutoBiometricsPrompt &&
|
|
|
|
this.isInitialLockScreen &&
|
|
|
|
(await this.authService.getAuthStatus()) === AuthenticationStatus.Locked
|
|
|
|
) {
|
|
|
|
await this.unlockBiometric();
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
2020-10-11 20:42:09 +02:00
|
|
|
|
|
|
|
async unlockBiometric(): Promise<boolean> {
|
|
|
|
if (!this.biometricLock) {
|
|
|
|
return;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-10-11 20:42:09 +02:00
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
this.pendingBiometric = true;
|
|
|
|
this.biometricError = null;
|
2020-10-11 20:42:09 +02:00
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
let success;
|
|
|
|
try {
|
|
|
|
success = await super.unlockBiometric();
|
|
|
|
} catch (e) {
|
|
|
|
const error = BiometricErrors[e as BiometricErrorTypes];
|
2020-10-11 20:42:09 +02:00
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
if (error == null) {
|
|
|
|
this.logService.error("Unknown error: " + e);
|
|
|
|
}
|
2021-09-28 16:37:18 +02:00
|
|
|
|
2022-03-15 13:13:39 +01:00
|
|
|
this.biometricError = this.i18nService.t(error.description);
|
2020-10-11 20:42:09 +02:00
|
|
|
}
|
2022-03-15 13:13:39 +01:00
|
|
|
this.pendingBiometric = false;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
2018-04-05 04:59:42 +02:00
|
|
|
}
|