From 27566c3fd5a1040112278c7ad0a50c6b8d45e3e4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 14 Dec 2018 17:19:28 -0500 Subject: [PATCH] support old windows opvault format on 1password importer --- src/importers/onepassword1PifImporter.ts | 97 +++++++++++++++++------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/src/importers/onepassword1PifImporter.ts b/src/importers/onepassword1PifImporter.ts index 798c2cb640..aad0d31d8f 100644 --- a/src/importers/onepassword1PifImporter.ts +++ b/src/importers/onepassword1PifImporter.ts @@ -20,34 +20,11 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer { } const item = JSON.parse(line); const cipher = this.initLoginCipher(); - cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false; - cipher.name = this.getValueOrDefault(item.title, '--'); - if (item.typeName === 'securenotes.SecureNote') { - cipher.type = CipherType.SecureNote; - cipher.secureNote = new SecureNoteView(); - cipher.secureNote.type = SecureNoteType.Generic; - } else if (item.typeName === 'wallet.financial.CreditCard') { - cipher.type = CipherType.Card; - cipher.card = new CardView(); + if (this.isNullOrWhitespace(item.hmac)) { + this.processStandardItem(item, cipher); } else { - cipher.login.uris = this.makeUriArray(item.location); - } - - if (item.secureContents != null) { - if (!this.isNullOrWhitespace(item.secureContents.notesPlain)) { - cipher.notes = item.secureContents.notesPlain.split(this.newLineRegex).join('\n') + '\n'; - } - if (item.secureContents.fields != null) { - this.parseFields(item.secureContents.fields, cipher, 'designation', 'value', 'name'); - } - if (item.secureContents.sections != null) { - item.secureContents.sections.forEach((section: any) => { - if (section.fields != null) { - this.parseFields(section.fields, cipher, 'n', 'v', 't'); - } - }); - } + this.processWinOpVaultItem(item, cipher); } this.convertToNoteIfNeeded(cipher); @@ -59,6 +36,74 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer { return this.result; } + private processWinOpVaultItem(item: any, cipher: CipherView) { + if (item.overview != null) { + cipher.name = this.getValueOrDefault(item.overview.title); + if (item.overview.URLs != null) { + const urls: string[] = []; + item.overview.URLs.forEach((url: any) => { + if (!this.isNullOrWhitespace(url.u)) { + urls.push(url.u); + } + }); + cipher.login.uris = this.makeUriArray(urls); + } + } + + if (item.details != null) { + if (!this.isNullOrWhitespace(item.details.ccnum) || !this.isNullOrWhitespace(item.details.cvv)) { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + } + + if (!this.isNullOrWhitespace(item.details.notesPlain)) { + cipher.notes = item.details.notesPlain.split(this.newLineRegex).join('\n') + '\n'; + } + if (item.details.fields != null) { + this.parseFields(item.details.fields, cipher, 'designation', 'value', 'name'); + } + if (item.details.sections != null) { + item.details.sections.forEach((section: any) => { + if (section.fields != null) { + this.parseFields(section.fields, cipher, 'n', 'v', 't'); + } + }); + } + } + } + + private processStandardItem(item: any, cipher: CipherView) { + cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false; + cipher.name = this.getValueOrDefault(item.title); + + if (item.typeName === 'securenotes.SecureNote') { + cipher.type = CipherType.SecureNote; + cipher.secureNote = new SecureNoteView(); + cipher.secureNote.type = SecureNoteType.Generic; + } else if (item.typeName === 'wallet.financial.CreditCard') { + cipher.type = CipherType.Card; + cipher.card = new CardView(); + } else { + cipher.login.uris = this.makeUriArray(item.location); + } + + if (item.secureContents != null) { + if (!this.isNullOrWhitespace(item.secureContents.notesPlain)) { + cipher.notes = item.secureContents.notesPlain.split(this.newLineRegex).join('\n') + '\n'; + } + if (item.secureContents.fields != null) { + this.parseFields(item.secureContents.fields, cipher, 'designation', 'value', 'name'); + } + if (item.secureContents.sections != null) { + item.secureContents.sections.forEach((section: any) => { + if (section.fields != null) { + this.parseFields(section.fields, cipher, 'n', 'v', 't'); + } + }); + } + } + } + private parseFields(fields: any[], cipher: CipherView, designationKey: string, valueKey: string, nameKey: string) { fields.forEach((field: any) => { if (field[valueKey] == null || field[valueKey].toString().trim() === '') {