1
0
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:
Kyle Spearrin 2018-12-14 17:19:28 -05:00
parent e10523cc61
commit 27566c3fd5

View File

@ -20,8 +20,61 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
}
const item = JSON.parse(line);
const cipher = this.initLoginCipher();
if (this.isNullOrWhitespace(item.hmac)) {
this.processStandardItem(item, cipher);
} else {
this.processWinOpVaultItem(item, cipher);
}
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
this.result.ciphers.push(cipher);
});
this.result.success = true;
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, '--');
cipher.name = this.getValueOrDefault(item.title);
if (item.typeName === 'securenotes.SecureNote') {
cipher.type = CipherType.SecureNote;
@ -49,14 +102,6 @@ export class OnePassword1PifImporter extends BaseImporter implements Importer {
});
}
}
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
this.result.ciphers.push(cipher);
});
this.result.success = true;
return this.result;
}
private parseFields(fields: any[], cipher: CipherView, designationKey: string, valueKey: string, nameKey: string) {