2023-03-10 05:54:11 +01:00
|
|
|
import { DIALOG_DATA } from "@angular/cdk/dialog";
|
|
|
|
import { Component, Inject } from "@angular/core";
|
|
|
|
import { FormGroup, FormControl, Validators } from "@angular/forms";
|
2018-08-28 04:40:03 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.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";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { KdfConfig } from "@bitwarden/common/auth/models/domain/kdf-config";
|
[AC-1266] Enums filename conventions (#5140)
* refactor: update clientType enum
* refactor: update deviceType filename
* refactor: update encryptedExportType filename
* refactor: update encryptionType filename
* refactor: update eventType filename
* refactor: update fieldType filename
* refactor: update fileUploadType filename
* refactor: update hashPurpose filename
* refactor: update htmlStorageLocation filename
* refactor: update kdfType filename
* refactor: update keySuffixOptions filename
* refactor: update linkedIdType filename
* refactor: update logLevelType filename
* refactor: update nativeMessagingVersion filename
* refactor: update notificationType filename
* refactor: update productType filename
* refactor: update secureNoteType filename
* refactor: update stateVersion filename
* refactor: update storageLocation filename
* refactor: update themeType filename
* refactor: update uriMatchType filename
* fix: update kdfType classes missed in initial pass, refs AC-1266
* fix: missing import update for device-type
* refactor: add barrel file for enums and update pathed import statements, refs AC-1266
* fix: incorrect import statements for web, refs AC-1266
* fix: missed import statement updates (browser), refs AC-1266
* fix: missed import statement changes (cli), refs AC-1266
* fix: missed import statement changes (desktop), refs AC-1266
* fix: prettier, refs AC-1266
* refactor: (libs) update relative paths to use barrel file, refs AC-1266
* fix: missed find/replace import statements for SecureNoteType, refs AC-1266
* refactor: apply .enum suffix to enums folder and modify leftover relative paths, refs AC-1266
* fix: find/replace errors for native-messaging-version, refs AC-1266
2023-04-05 05:42:21 +02:00
|
|
|
import { KdfType } from "@bitwarden/common/enums";
|
2022-10-18 19:01:42 +02:00
|
|
|
import { KdfRequest } from "@bitwarden/common/models/request/kdf.request";
|
2018-08-28 04:40:03 +02:00
|
|
|
|
|
|
|
@Component({
|
2023-03-10 05:54:11 +01:00
|
|
|
selector: "app-change-kdf-confirmation",
|
|
|
|
templateUrl: "change-kdf-confirmation.component.html",
|
2018-08-28 04:40:03 +02:00
|
|
|
})
|
2023-03-10 05:54:11 +01:00
|
|
|
export class ChangeKdfConfirmationComponent {
|
|
|
|
kdf: KdfType;
|
|
|
|
kdfConfig: KdfConfig;
|
|
|
|
|
|
|
|
form = new FormGroup({
|
|
|
|
masterPassword: new FormControl(null, Validators.required),
|
|
|
|
});
|
|
|
|
showPassword = false;
|
2018-08-28 04:40:03 +02:00
|
|
|
masterPassword: string;
|
|
|
|
formPromise: Promise<any>;
|
2023-03-10 05:54:11 +01:00
|
|
|
loading = false;
|
2018-08-28 04:40:03 +02:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
private apiService: ApiService,
|
|
|
|
private i18nService: I18nService,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private cryptoService: CryptoService,
|
|
|
|
private messagingService: MessagingService,
|
2023-03-10 05:54:11 +01:00
|
|
|
private stateService: StateService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private logService: LogService,
|
2023-03-10 05:54:11 +01:00
|
|
|
@Inject(DIALOG_DATA) params: { kdf: KdfType; kdfConfig: KdfConfig }
|
2021-12-14 17:10:26 +01:00
|
|
|
) {
|
2023-03-10 05:54:11 +01:00
|
|
|
this.kdf = params.kdf;
|
|
|
|
this.kdfConfig = params.kdfConfig;
|
|
|
|
this.masterPassword = null;
|
2018-08-28 04:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
2023-03-10 05:54:11 +01:00
|
|
|
this.loading = true;
|
2018-08-28 04:40:03 +02:00
|
|
|
const hasEncKey = await this.cryptoService.hasEncKey();
|
|
|
|
if (!hasEncKey) {
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast("error", null, this.i18nService.t("updateKey"));
|
2018-08-28 04:40:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-30 15:07:51 +01:00
|
|
|
try {
|
|
|
|
this.formPromise = this.makeKeyAndSaveAsync();
|
|
|
|
await this.formPromise;
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"success",
|
|
|
|
this.i18nService.t("encKeySettingsChanged"),
|
|
|
|
this.i18nService.t("logBackIn")
|
|
|
|
);
|
|
|
|
this.messagingService.send("logout");
|
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2023-03-10 05:54:11 +01:00
|
|
|
} finally {
|
|
|
|
this.loading = false;
|
2023-01-30 15:07:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async makeKeyAndSaveAsync() {
|
2023-03-10 05:54:11 +01:00
|
|
|
const masterPassword = this.form.value.masterPassword;
|
2018-08-28 04:40:03 +02:00
|
|
|
const request = new KdfRequest();
|
|
|
|
request.kdf = this.kdf;
|
2023-01-30 15:07:51 +01:00
|
|
|
request.kdfIterations = this.kdfConfig.iterations;
|
|
|
|
request.kdfMemory = this.kdfConfig.memory;
|
|
|
|
request.kdfParallelism = this.kdfConfig.parallelism;
|
2023-03-10 05:54:11 +01:00
|
|
|
request.masterPasswordHash = await this.cryptoService.hashPassword(masterPassword, null);
|
2021-12-14 17:10:26 +01:00
|
|
|
const email = await this.stateService.getEmail();
|
2018-08-28 04:40:03 +02:00
|
|
|
const newKey = await this.cryptoService.makeKey(
|
2023-03-10 05:54:11 +01:00
|
|
|
masterPassword,
|
2018-08-28 04:40:03 +02:00
|
|
|
email,
|
|
|
|
this.kdf,
|
2023-01-30 15:07:51 +01:00
|
|
|
this.kdfConfig
|
2018-08-28 04:40:03 +02:00
|
|
|
);
|
2023-03-10 05:54:11 +01:00
|
|
|
request.newMasterPasswordHash = await this.cryptoService.hashPassword(masterPassword, newKey);
|
2018-08-28 04:40:03 +02:00
|
|
|
const newEncKey = await this.cryptoService.remakeEncKey(newKey);
|
|
|
|
request.key = newEncKey[1].encryptedString;
|
2023-01-30 15:07:51 +01:00
|
|
|
|
|
|
|
await this.apiService.postAccountKdf(request);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-08-28 04:40:03 +02:00
|
|
|
}
|