diff --git a/src/importers/avastJsonImporter.ts b/src/importers/avastJsonImporter.ts new file mode 100644 index 00000000000..b4981983a6e --- /dev/null +++ b/src/importers/avastJsonImporter.ts @@ -0,0 +1,69 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +import { CipherType } from '../enums/cipherType'; +import { SecureNoteType } from '../enums/secureNoteType'; + +export class AvastJsonImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = JSON.parse(data); + if (results == null) { + result.success = false; + return result; + } + + if (results.logins != null) { + results.logins.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.custName); + cipher.notes = this.getValueOrDefault(value.note); + cipher.login.uris = this.makeUriArray(value.url); + cipher.login.password = this.getValueOrDefault(value.pwd); + cipher.login.username = this.getValueOrDefault(value.loginName); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + if (results.notes != null) { + results.notes.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.type = CipherType.SecureNote; + cipher.secureNote.type = SecureNoteType.Generic; + cipher.name = this.getValueOrDefault(value.label); + cipher.notes = this.getValueOrDefault(value.text); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + } + + if (results.cards != null) { + results.cards.forEach((value: any) => { + const cipher = this.initLoginCipher(); + cipher.type = CipherType.Card; + cipher.name = this.getValueOrDefault(value.custName); + cipher.notes = this.getValueOrDefault(value.note); + cipher.card.cardholderName = this.getValueOrDefault(value.holderName); + cipher.card.number = this.getValueOrDefault(value.cardNumber); + cipher.card.code = this.getValueOrDefault(value.cvv); + cipher.card.brand = this.getCardBrand(cipher.card.number); + if (value.expirationDate != null) { + if (value.expirationDate.month != null) { + cipher.card.expMonth = value.expirationDate.month + ''; + } + if (value.expirationDate.year != null) { + cipher.card.expYear = value.expirationDate.year + ''; + } + } + 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 df6735bd472..8bf4f0a9056 100644 --- a/src/services/import.service.ts +++ b/src/services/import.service.ts @@ -25,6 +25,7 @@ import { CipherView } from '../models/view/cipherView'; import { AscendoCsvImporter } from '../importers/ascendoCsvImporter'; import { AvastCsvImporter } from '../importers/avastCsvImporter'; +import { AvastJsonImporter } from '../importers/avastJsonImporter'; import { AviraCsvImporter } from '../importers/aviraCsvImporter'; import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter'; import { BitwardenJsonImporter } from '../importers/bitwardenJsonImporter'; @@ -117,6 +118,7 @@ export class ImportService implements ImportServiceAbstraction { { id: 'passpackcsv', name: 'Passpack (csv)' }, { id: 'passmanjson', name: 'Passman (json)' }, { id: 'avastcsv', name: 'Avast Passwords (csv)' }, + { id: 'avastjson', name: 'Avast Passwords (json)' }, { id: 'fsecurefsk', name: 'F-Secure KEY (fsk)' }, { id: 'kasperskytxt', name: 'Kaspersky Password Manager (txt)' }, { id: 'remembearcsv', name: 'RememBear (csv)' }, @@ -251,6 +253,8 @@ export class ImportService implements ImportServiceAbstraction { return new PassmanJsonImporter(); case 'avastcsv': return new AvastCsvImporter(); + case 'avastjson': + return new AvastJsonImporter(); case 'fsecurefsk': return new FSecureFskImporter(); case 'kasperskytxt':