2020-12-22 16:57:44 +01:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2022-02-24 12:10:07 +01:00
|
|
|
import { ChangePasswordComponent } from "jslib-angular/components/change-password.component";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { MessagingService } from "jslib-common/abstractions/messaging.service";
|
|
|
|
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { PolicyService } from "jslib-common/abstractions/policy.service";
|
2021-12-14 17:10:26 +01:00
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2021-06-07 20:13:58 +02:00
|
|
|
import { KdfType } from "jslib-common/enums/kdfType";
|
|
|
|
import { PolicyData } from "jslib-common/models/data/policyData";
|
|
|
|
import { Policy } from "jslib-common/models/domain/policy";
|
|
|
|
import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey";
|
|
|
|
import { EmergencyAccessPasswordRequest } from "jslib-common/models/request/emergencyAccessPasswordRequest";
|
|
|
|
import { PolicyResponse } from "jslib-common/models/response/policyResponse";
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2020-12-22 16:57:44 +01:00
|
|
|
@Component({
|
|
|
|
selector: "emergency-access-takeover",
|
|
|
|
templateUrl: "emergency-access-takeover.component.html",
|
|
|
|
})
|
|
|
|
export class EmergencyAccessTakeoverComponent extends ChangePasswordComponent implements OnInit {
|
|
|
|
@Output() onDone = new EventEmitter();
|
|
|
|
@Input() emergencyAccessId: string;
|
|
|
|
@Input() name: string;
|
|
|
|
@Input() email: string;
|
|
|
|
@Input() kdf: KdfType;
|
|
|
|
@Input() kdfIterations: number;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2020-12-22 16:57:44 +01:00
|
|
|
formPromise: Promise<any>;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
i18nService: I18nService,
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
messagingService: MessagingService,
|
|
|
|
stateService: StateService,
|
2020-12-22 16:57:44 +01:00
|
|
|
passwordGenerationService: PasswordGenerationService,
|
2021-12-14 17:10:26 +01:00
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
policyService: PolicyService,
|
|
|
|
private apiService: ApiService,
|
|
|
|
private logService: LogService
|
|
|
|
) {
|
|
|
|
super(
|
|
|
|
i18nService,
|
|
|
|
cryptoService,
|
|
|
|
messagingService,
|
|
|
|
passwordGenerationService,
|
|
|
|
platformUtilsService,
|
|
|
|
policyService,
|
|
|
|
stateService
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-12 00:58:22 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
const response = await this.apiService.getEmergencyGrantorPolicies(this.emergencyAccessId);
|
|
|
|
if (response.data != null && response.data.length > 0) {
|
|
|
|
const policies = response.data.map(
|
|
|
|
(policyResponse: PolicyResponse) => new Policy(new PolicyData(policyResponse))
|
2021-12-17 15:57:11 +01:00
|
|
|
);
|
2021-02-12 00:58:22 +01:00
|
|
|
this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(
|
2021-12-17 15:57:11 +01:00
|
|
|
policies
|
2021-12-14 17:10:26 +01:00
|
|
|
);
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
2021-02-12 00:58:22 +01:00
|
|
|
async submit() {
|
|
|
|
if (!(await this.strongPassword())) {
|
|
|
|
return;
|
2021-12-14 17:10:26 +01:00
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
|
|
|
const takeoverResponse = await this.apiService.postEmergencyAccessTakeover(
|
|
|
|
this.emergencyAccessId
|
|
|
|
);
|
|
|
|
|
|
|
|
const oldKeyBuffer = await this.cryptoService.rsaDecrypt(takeoverResponse.keyEncrypted);
|
|
|
|
const oldEncKey = new SymmetricCryptoKey(oldKeyBuffer);
|
|
|
|
|
|
|
|
if (oldEncKey == null) {
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("errorOccurred"),
|
|
|
|
this.i18nService.t("unexpectedError")
|
|
|
|
);
|
2020-12-22 16:57:44 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const key = await this.cryptoService.makeKey(
|
|
|
|
this.masterPassword,
|
|
|
|
this.email,
|
|
|
|
takeoverResponse.kdf,
|
|
|
|
takeoverResponse.kdfIterations
|
|
|
|
);
|
|
|
|
const masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, key);
|
|
|
|
|
|
|
|
const encKey = await this.cryptoService.remakeEncKey(key, oldEncKey);
|
|
|
|
|
|
|
|
const request = new EmergencyAccessPasswordRequest();
|
|
|
|
request.newMasterPasswordHash = masterPasswordHash;
|
|
|
|
request.key = encKey[1].encryptedString;
|
|
|
|
|
|
|
|
this.apiService.postEmergencyAccessPassword(this.emergencyAccessId, request);
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.onDone.emit();
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
}
|