mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
* Rough draft of Export/Import changes w/ password encryption * fix for encrypted export changes * Create launch.json * Updates to export logic modal user secret prompt * Updates to error handling * renaming the component for checking the user secret to a name that is more clear about what it accomplishes * Fixing lint errors * Adding a comment * Suggested changes from CR * Suggested changes from CR * Making suggested changes * removing unnecessary properties * changes suggested * Fix * Updating error messages * Removing unecessary launch.json file commit * running lint, removing commented code * removing launch.json * Updates to remove the userVerificationPromptService * updates * Removing unused import, running npm prettier/lint * Changes to use Form Fields * Updates * updates requested by Matt * Update apps/web/src/app/tools/import-export/export.component.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Suggested Changes from PR * Fix after merge from Master * changes to styling * Removing unused code and cleanup * Update libs/angular/src/components/user-verification-prompt.component.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Update apps/web/src/locales/en/messages.json Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Changes suggested by Thomas R * Merging master into branch * Revert "Merging master into branch" This reverts commiteb2cdffe49. * Requested changes and improvements * merging master into feature branch * Revert "merging master into feature branch" This reverts commite287715251. * Suggested Changes * changes * requested changes * Requested changes * removing comments, fixing code * reducing copied code * fixing bug * fixing bug * changes * WIP * Thomas's requested changes * adding back missing spaces * change needed after the merge from master into feature branch * prettier + lint * Updating the EncryptedExportType Import * Fixing build errors Co-authored-by: Thomas Rittson <eliykat@users.noreply.github.com> * Move FilePasswordPrompt to ImportExportModule Also remove base class Also remove duplicate service providers * Run prettier * Suggested Changes from Thomas * only require filePassword and confirmFilePassword if it's type is FileEncrypted * Update to only enable the field when submitting a file password encrypted file * Requested changes, moving logic to web * undoing change to bit button * Refactor to process file-encrypted imports in main import.component * Refactor confirm file password check * Remove UserVerificationPromptService * Address CodeScene feedback * Updates to disable the required file password field when needed * Subscribe to reactive form changes to adjust validators * style changes requested by suhkleen * Delete duplicate classes Co-authored-by: CarleyDiaz-Bitwarden <103955722+CarleyDiaz-Bitwarden@users.noreply.github.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Co-authored-by: Thomas Rittson <trittson@bitwarden.com> Co-authored-by: Thomas Rittson <eliykat@users.noreply.github.com>
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import { CryptoService } from "../abstractions/crypto.service";
|
|
import { I18nService } from "../abstractions/i18n.service";
|
|
import { KdfType } from "../enums/kdfType";
|
|
import { EncString } from "../models/domain/encString";
|
|
import { ImportResult } from "../models/domain/importResult";
|
|
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
|
|
|
|
import { BitwardenJsonImporter } from "./bitwardenJsonImporter";
|
|
import { Importer } from "./importer";
|
|
|
|
interface BitwardenPasswordProtectedFileFormat {
|
|
encrypted: boolean;
|
|
passwordProtected: boolean;
|
|
salt: string;
|
|
kdfIterations: number;
|
|
kdfType: number;
|
|
encKeyValidation_DO_NOT_EDIT: string;
|
|
data: string;
|
|
}
|
|
|
|
export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter implements Importer {
|
|
private key: SymmetricCryptoKey;
|
|
|
|
constructor(cryptoService: CryptoService, i18nService: I18nService, private password: string) {
|
|
super(cryptoService, i18nService);
|
|
}
|
|
|
|
async parse(data: string): Promise<ImportResult> {
|
|
const result = new ImportResult();
|
|
const parsedData = JSON.parse(data);
|
|
if (this.cannotParseFile(parsedData)) {
|
|
result.success = false;
|
|
return result;
|
|
}
|
|
|
|
if (!(await this.checkPassword(parsedData))) {
|
|
result.success = false;
|
|
result.errorMessage = this.i18nService.t("invalidFilePassword");
|
|
return result;
|
|
}
|
|
|
|
const encData = new EncString(parsedData.data);
|
|
const clearTextData = await this.cryptoService.decryptToUtf8(encData, this.key);
|
|
return await super.parse(clearTextData);
|
|
}
|
|
|
|
private async checkPassword(jdoc: BitwardenPasswordProtectedFileFormat): Promise<boolean> {
|
|
this.key = await this.cryptoService.makePinKey(
|
|
this.password,
|
|
jdoc.salt,
|
|
KdfType.PBKDF2_SHA256,
|
|
jdoc.kdfIterations
|
|
);
|
|
|
|
const encKeyValidation = new EncString(jdoc.encKeyValidation_DO_NOT_EDIT);
|
|
|
|
const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8(
|
|
encKeyValidation,
|
|
this.key
|
|
);
|
|
if (encKeyValidationDecrypt === null) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private cannotParseFile(jdoc: BitwardenPasswordProtectedFileFormat): boolean {
|
|
return (
|
|
!jdoc ||
|
|
!jdoc.encrypted ||
|
|
!jdoc.passwordProtected ||
|
|
!jdoc.salt ||
|
|
!jdoc.kdfIterations ||
|
|
typeof jdoc.kdfIterations !== "number" ||
|
|
jdoc.kdfType == null ||
|
|
KdfType[jdoc.kdfType] == null ||
|
|
!jdoc.encKeyValidation_DO_NOT_EDIT ||
|
|
!jdoc.data
|
|
);
|
|
}
|
|
}
|