1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-02 08:40:08 +01:00

support for encryptr csv importer (#73)

This commit is contained in:
Kyle Spearrin 2020-02-19 14:51:46 -05:00 committed by GitHub
parent 98ae9b0629
commit ab9bee29b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,54 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
import { CardView } from '../models/view/cardView';
import { CipherType } from '../enums/cipherType';
export class EncryptrCsvImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult {
const result = new ImportResult();
const results = this.parseCsv(data, true);
if (results == null) {
result.success = false;
return result;
}
results.forEach((value) => {
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.Label, '--');
cipher.notes = this.getValueOrDefault(value.Notes);
const type = value['Entry Type'];
if (type === 'Password') {
cipher.login.username = this.getValueOrDefault(value.Username);
cipher.login.password = this.getValueOrDefault(value.Password);
cipher.login.uris = this.makeUriArray(value['Site URL']);
} else if (type === 'Credit Card') {
cipher.type = CipherType.Card;
cipher.card = new CardView();
cipher.card.cardholderName = this.getValueOrDefault(value['Name on card']);
cipher.card.number = this.getValueOrDefault(value['Card Number']);
cipher.card.brand = this.getCardBrand(cipher.card.number);
cipher.card.code = this.getValueOrDefault(value.CVV);
const expiry = this.getValueOrDefault(value.Expiry);
if (!this.isNullOrWhitespace(expiry)) {
const expParts = expiry.split('/');
if (expParts.length > 1) {
cipher.card.expMonth = parseInt(expParts[0], null).toString();
cipher.card.expYear = (2000 + parseInt(expParts[1], null)).toString();
}
}
}
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
result.success = true;
return result;
}
}

View File

@ -21,8 +21,10 @@ export class ZohoVaultCsvImporter extends BaseImporter implements Importer {
const cipher = this.initLoginCipher();
cipher.favorite = this.getValueOrDefault(value.Favorite, '0') === '1';
cipher.notes = this.getValueOrDefault(value.Notes);
cipher.name = this.getValueOrDefault(value['Password Name'], this.getValueOrDefault(value['Secret Name'], '--'));
cipher.login.uris = this.makeUriArray(this.getValueOrDefault(value['Password URL'], this.getValueOrDefault(value['Secret URL'])));
cipher.name = this.getValueOrDefault(
value['Password Name'], this.getValueOrDefault(value['Secret Name'], '--'));
cipher.login.uris = this.makeUriArray(
this.getValueOrDefault(value['Password URL'], this.getValueOrDefault(value['Secret URL'])));
this.parseData(cipher, value.SecretData);
this.parseData(cipher, value.CustomData);
this.convertToNoteIfNeeded(cipher);

View File

@ -36,6 +36,7 @@ import { ChromeCsvImporter } from '../importers/chromeCsvImporter';
import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter';
import { CodebookCsvImporter } from '../importers/codebookCsvImporter';
import { DashlaneJsonImporter } from '../importers/dashlaneJsonImporter';
import { EncryptrCsvImporter } from '../importers/encryptrCsvImporter';
import { EnpassCsvImporter } from '../importers/enpassCsvImporter';
import { EnpassJsonImporter } from '../importers/enpassJsonImporter';
import { FirefoxCsvImporter } from '../importers/firefoxCsvImporter';
@ -129,6 +130,7 @@ export class ImportService implements ImportServiceAbstraction {
{ id: 'blackberrycsv', name: 'BlackBerry Password Keeper (csv)' },
{ id: 'buttercupcsv', name: 'Buttercup (csv)' },
{ id: 'codebookcsv', name: 'Codebook (csv)' },
{ id: 'encryptrcsv', name: 'Encryptr (csv)' },
];
constructor(private cipherService: CipherService, private folderService: FolderService,
@ -275,6 +277,8 @@ export class ImportService implements ImportServiceAbstraction {
return new ButtercupCsvImporter();
case 'codebookcsv':
return new CodebookCsvImporter();
case 'encryptrcsv':
return new EncryptrCsvImporter();
default:
return null;
}