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";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { LockComponent as BaseLockComponent } from "@bitwarden/angular/components/lock.component";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { AuthService } from "@bitwarden/common/abstractions/auth.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 { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.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-29 20:14:59 +02:00
|
|
|
import { SyncService } from "@bitwarden/common/abstractions/sync/sync.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service";
|
|
|
|
import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus";
|
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;
|
2022-08-05 17:01:47 +02:00
|
|
|
authenicatedUrl = "/tabs/current";
|
|
|
|
unAuthenicatedUrl = "/update-temp-password";
|
2022-03-15 13:13:39 +01:00
|
|
|
|
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,
|
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,
|
2022-08-05 17:01:47 +02:00
|
|
|
private authService: AuthService,
|
|
|
|
private syncService: SyncService
|
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,
|
|
|
|
environmentService,
|
|
|
|
stateService,
|
|
|
|
apiService,
|
|
|
|
logService,
|
2021-11-29 01:14:04 +01:00
|
|
|
keyConnectorService,
|
|
|
|
ngZone
|
|
|
|
);
|
2022-08-05 17:01:47 +02:00
|
|
|
|
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();
|
2022-08-05 17:01:47 +02:00
|
|
|
await this.syncService.fullSync(true);
|
|
|
|
|
|
|
|
const forcePasswordReset = await this.stateService.getForcePasswordReset();
|
|
|
|
this.successRoute = forcePasswordReset === true ? this.unAuthenicatedUrl : this.authenicatedUrl;
|
|
|
|
|
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
|
|
|
}
|