1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

Increase error checking on imported Login items (#369)

* Increase error checking on imported Login items

* Check encKey when importing encrypted JSON

* Fix style, use GUID as random string for test

* Revert "Increase error checking on imported Login items"

This reverts commit 17294527863cc53b84ed218f94ffbc21f4e96260.

* fix linting

* Fix tests
This commit is contained in:
Thomas Rittson
2021-05-13 10:58:59 +10:00
committed by GitHub
parent ba1a40af4e
commit 306aef73d4
4 changed files with 42 additions and 6 deletions

View File

@@ -1,16 +1,24 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { EncString } from '../models/domain/encString';
import { ImportResult } from '../models/domain/importResult';
import { CipherWithIds } from '../models/export/cipherWithIds';
import { CollectionWithId } from '../models/export/collectionWithId';
import { FolderWithId } from '../models/export/folderWithId';
import { CryptoService } from '../abstractions/crypto.service';
import { I18nService } from '../abstractions/i18n.service';
export class BitwardenJsonImporter extends BaseImporter implements Importer {
private results: any;
private result: ImportResult;
constructor(private cryptoService: CryptoService, private i18nService: I18nService) {
super();
}
async parse(data: string): Promise<ImportResult> {
this.result = new ImportResult();
this.results = JSON.parse(data);
@@ -25,11 +33,20 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
this.parseDecrypted();
}
this.result.success = true;
return this.result;
}
private async parseEncrypted() {
if (this.results.encKeyValidation_DO_NOT_EDIT != null) {
const encKeyValidation = new EncString(this.results.encKeyValidation_DO_NOT_EDIT);
const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8(encKeyValidation);
if (encKeyValidationDecrypt === null) {
this.result.success = false;
this.result.errorMessage = this.i18nService.t('importEncKeyError');
return;
}
}
const groupingsMap = new Map<string, number>();
if (this.organization && this.results.collections != null) {
@@ -82,6 +99,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
this.cleanupCipher(view);
this.result.ciphers.push(view);
}
this.result.success = true;
}
private parseDecrypted() {
@@ -133,5 +152,7 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
this.cleanupCipher(cipher);
this.result.ciphers.push(cipher);
});
this.result.success = true;
}
}