2020-12-22 16:57:44 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
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';
|
|
|
|
import { UserService } from 'jslib-common/abstractions/user.service';
|
2020-12-22 16:57:44 +01:00
|
|
|
|
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';
|
|
|
|
|
|
|
|
import { ChangePasswordComponent } from 'jslib-angular/components/change-password.component';
|
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;
|
|
|
|
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(i18nService: I18nService, cryptoService: CryptoService,
|
|
|
|
messagingService: MessagingService, userService: UserService,
|
|
|
|
passwordGenerationService: PasswordGenerationService,
|
|
|
|
platformUtilsService: PlatformUtilsService, policyService: PolicyService,
|
2021-10-20 18:30:04 +02:00
|
|
|
private apiService: ApiService, private toasterService: ToasterService, private logService: LogService) {
|
2020-12-22 16:57:44 +01:00
|
|
|
super(i18nService, cryptoService, messagingService, userService, passwordGenerationService,
|
|
|
|
platformUtilsService, policyService);
|
|
|
|
}
|
|
|
|
|
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)));
|
|
|
|
this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(policies);
|
|
|
|
}
|
|
|
|
}
|
2020-12-22 16:57:44 +01:00
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (!await this.strongPassword()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const takeoverResponse = await this.apiService.postEmergencyAccessTakeover(this.emergencyAccessId);
|
|
|
|
|
|
|
|
const oldKeyBuffer = await this.cryptoService.rsaDecrypt(takeoverResponse.keyEncrypted);
|
|
|
|
const oldEncKey = new SymmetricCryptoKey(oldKeyBuffer);
|
|
|
|
|
|
|
|
if (oldEncKey == null) {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), this.i18nService.t('unexpectedError'));
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|