From ab9bee29b8ebf0b2812fcc5e5a8e7c36a3868ebd Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 19 Feb 2020 14:51:46 -0500 Subject: [PATCH] support for encryptr csv importer (#73) --- src/importers/encryptrCsvImporter.ts | 54 +++++++++++++++++++++++++++ src/importers/zohoVaultCsvImporter.ts | 6 ++- src/services/import.service.ts | 4 ++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/importers/encryptrCsvImporter.ts diff --git a/src/importers/encryptrCsvImporter.ts b/src/importers/encryptrCsvImporter.ts new file mode 100644 index 0000000000..edd2a41a89 --- /dev/null +++ b/src/importers/encryptrCsvImporter.ts @@ -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; + } +} diff --git a/src/importers/zohoVaultCsvImporter.ts b/src/importers/zohoVaultCsvImporter.ts index 3c86d4fa87..cf2403e552 100644 --- a/src/importers/zohoVaultCsvImporter.ts +++ b/src/importers/zohoVaultCsvImporter.ts @@ -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); diff --git a/src/services/import.service.ts b/src/services/import.service.ts index 8bf4f0a905..e7b58550ca 100644 --- a/src/services/import.service.ts +++ b/src/services/import.service.ts @@ -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; }