1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00

support old windows opvault format on 1password importer

This commit is contained in:
Kyle Spearrin 2018-12-14 17:19:28 -05:00
parent e10523cc61
commit 27566c3fd5

View File

@ -20,34 +20,11 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
} }
const item = JSON.parse(line); const item = JSON.parse(line);
const cipher = this.initLoginCipher(); const cipher = this.initLoginCipher();
cipher.favorite = item.openContents && item.openContents.faveIndex ? true : false;
cipher.name = this.getValueOrDefault(item.title, '--');
if (item.typeName === 'securenotes.SecureNote') { if (this.isNullOrWhitespace(item.hmac)) {
cipher.type = CipherType.SecureNote; this.processStandardItem(item, cipher);
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 { } else {
cipher.login.uris = this.makeUriArray(item.location); this.processWinOpVaultItem(item, cipher);
}
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.convertToNoteIfNeeded(cipher); this.convertToNoteIfNeeded(cipher);
@ -59,6 +36,74 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
return this.result; 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) { private parseFields(fields: any[], cipher: CipherView, designationKey: string, valueKey: string, nameKey: string) {
fields.forEach((field: any) => { fields.forEach((field: any) => {
if (field[valueKey] == null || field[valueKey].toString().trim() === '') { if (field[valueKey] == null || field[valueKey].toString().trim() === '') {