mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
support old windows opvault format on 1password importer
This commit is contained in:
parent
e10523cc61
commit
27566c3fd5
@ -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() === '') {
|
||||
|
Loading…
Reference in New Issue
Block a user