From 3238b819268d2155376a22b963887f59a3eeb7ca Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 28 Jun 2019 23:17:13 -0400 Subject: [PATCH] myki importer --- src/importers/mykiCsvImporter.ts | 76 ++++++++++++++++++++++++++++++++ src/services/import.service.ts | 4 ++ 2 files changed, 80 insertions(+) create mode 100644 src/importers/mykiCsvImporter.ts diff --git a/src/importers/mykiCsvImporter.ts b/src/importers/mykiCsvImporter.ts new file mode 100644 index 0000000000..47988cc797 --- /dev/null +++ b/src/importers/mykiCsvImporter.ts @@ -0,0 +1,76 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { CipherType } from '../enums/cipherType'; +import { SecureNoteType } from '../enums/secureNoteType'; + +import { CardView } from '../models/view/cardView'; +import { IdentityView } from '../models/view/identityView'; +import { SecureNoteView } from '../models/view/secureNoteView'; + +import { ImportResult } from '../models/domain/importResult'; + +export class MykiCsvImporter 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.nickname, '--'); + cipher.notes = this.getValueOrDefault(value.additionalInfo); + + if (value.url !== undefined) { + // Accounts + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.totp = this.getValueOrDefault(value.twoFactAuthToken); + } else if (value.cardNumber !== undefined) { + // Cards + cipher.card = new CardView(); + cipher.type = CipherType.Card; + cipher.card.cardholderName = this.getValueOrDefault(value.cardName); + cipher.card.number = this.getValueOrDefault(value.cardNumber); + cipher.card.brand = this.getCardBrand(cipher.card.number); + cipher.card.expMonth = this.getValueOrDefault(value.exp_month); + cipher.card.expYear = this.getValueOrDefault(value.exp_year); + cipher.card.code = this.getValueOrDefault(value.cvv); + } else if (value.firstName !== undefined) { + // Identities + cipher.identity = new IdentityView(); + cipher.type = CipherType.Identity; + cipher.identity.title = this.getValueOrDefault(value.title); + cipher.identity.firstName = this.getValueOrDefault(value.firstName); + cipher.identity.middleName = this.getValueOrDefault(value.middleName); + cipher.identity.lastName = this.getValueOrDefault(value.lastName); + cipher.identity.phone = this.getValueOrDefault(value.number); + cipher.identity.email = this.getValueOrDefault(value.email); + cipher.identity.address1 = this.getValueOrDefault(value.firstAddressLine); + cipher.identity.address2 = this.getValueOrDefault(value.secondAddressLine); + cipher.identity.city = this.getValueOrDefault(value.city); + cipher.identity.country = this.getValueOrDefault(value.country); + cipher.identity.postalCode = this.getValueOrDefault(value.zipCode); + } else if (value.content !== undefined) { + // Notes + cipher.secureNote = new SecureNoteView(); + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + cipher.name = this.getValueOrDefault(value.title, '--'); + cipher.notes = this.getValueOrDefault(value.content); + } else { + return; + } + + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +} diff --git a/src/services/import.service.ts b/src/services/import.service.ts index 5d69fde20a..bb8baae8d7 100644 --- a/src/services/import.service.ts +++ b/src/services/import.service.ts @@ -45,6 +45,7 @@ import { KeeperCsvImporter } from '../importers/keeperCsvImporter'; import { LastPassCsvImporter } from '../importers/lastpassCsvImporter'; import { MeldiumCsvImporter } from '../importers/meldiumCsvImporter'; import { MSecureCsvImporter } from '../importers/msecureCsvImporter'; +import { MykiCsvImporter } from '../importers/mykiCsvImporter'; import { OnePassword1PifImporter } from '../importers/onepassword1PifImporter'; import { OnePasswordWinCsvImporter } from '../importers/onepasswordWinCsvImporter'; import { PadlockCsvImporter } from '../importers/padlockCsvImporter'; @@ -115,6 +116,7 @@ export class ImportService implements ImportServiceAbstraction { { id: 'kasperskytxt', name: 'Kaspersky Password Manager (txt)' }, { id: 'remembearcsv', name: 'RememBear (csv)' }, { id: 'passwordwallettxt', name: 'PasswordWallet (txt)' }, + { id: 'mykicsv', name: 'Myki (csv)' }, ]; constructor(private cipherService: CipherService, private folderService: FolderService, @@ -247,6 +249,8 @@ export class ImportService implements ImportServiceAbstraction { return new RememBearCsvImporter(); case 'passwordwallettxt': return new PasswordWalletTxtImporter(); + case 'mykicsv': + return new MykiCsvImporter(); default: return null; }