1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

process notes for cards and identity from lastpass

This commit is contained in:
Kyle Spearrin 2017-10-12 17:01:34 -04:00
parent 598c7ea068
commit 49ee41f7d3

View File

@ -1,7 +1,7 @@
angular angular
.module('bit.services') .module('bit.services')
.factory('importService', function (contants) { .factory('importService', function (constants) {
var _service = {}; var _service = {};
_service.import = function (source, file, success, error) { _service.import = function (source, file, success, error) {
@ -270,7 +270,7 @@
favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false, favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false,
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
type: contants.cipherType.login, type: constants.cipherType.login,
login: { login: {
totp: value.totp && value.totp !== '' ? value.totp : null, totp: value.totp && value.totp !== '' ? value.totp : null,
uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null, uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null,
@ -280,7 +280,7 @@
}; };
if (value.fields && value.fields !== '') { if (value.fields && value.fields !== '') {
var fields = value.fields.split('\n'); var fields = value.fields.split(/(?:\r\n|\r|\n)/);
for (i = 0; i < fields.length; i++) { for (i = 0; i < fields.length; i++) {
if (!fields[i] || fields[i] === '') { if (!fields[i] || fields[i] === '') {
continue; continue;
@ -378,7 +378,7 @@
favorite: false, favorite: false,
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
type: contants.cipherType.login, type: constants.cipherType.login,
login: { login: {
totp: value.totp && value.totp !== '' ? value.totp : null, totp: value.totp && value.totp !== '' ? value.totp : null,
uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null, uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null,
@ -388,7 +388,7 @@
}; };
if (value.fields && value.fields !== '') { if (value.fields && value.fields !== '') {
var fields = value.fields.split('\n'); var fields = value.fields.split(/(?:\r\n|\r|\n)/);
for (i = 0; i < fields.length; i++) { for (i = 0; i < fields.length; i++) {
if (!fields[i] || fields[i] === '') { if (!fields[i] || fields[i] === '') {
continue; continue;
@ -481,6 +481,44 @@
}); });
} }
function parseSecureNoteMapping(extraParts, map, skip) {
var obj = {
dataObj: {},
notes: null
};
for (var i = 0; i < extraParts.length; i++) {
var fieldParts = extraParts[i].split(':');
if (fieldParts.length < 1 || fieldParts[0] === 'NoteType' || skip.indexOf(fieldParts[0]) > -1 ||
!fieldParts[1] || fieldParts[1] === '') {
continue;
}
if (fieldParts[0] === 'Notes') {
if (obj.notes) {
obj.notes += ('\n' + fieldParts[1]);
}
else {
obj.notes = fieldParts[1];
}
}
else if (map.hasOwnProperty(fieldParts[0])) {
obj.dataObj[map[fieldParts[0]]] = fieldParts[1];
}
else {
if (obj.notes) {
obj.notes += '\n';
}
else {
obj.notes = '';
}
obj.notes += (fieldParts[0] + ': ' + fieldParts[1]);
}
}
return obj;
}
function parseData(data) { function parseData(data) {
var folders = [], var folders = [],
ciphers = [], ciphers = [],
@ -506,10 +544,10 @@
var cipher = { var cipher = {
favorite: org ? false : value.fav === '1', favorite: org ? false : value.fav === '1',
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
type: value.url === 'http://sn' ? contants.cipherType.secureNote : contants.cipherType.login type: value.url === 'http://sn' ? constants.cipherType.secureNote : constants.cipherType.login
}; };
if (cipher.type === contants.cipherType.login) { if (cipher.type === constants.cipherType.login) {
cipher.login = { cipher.login = {
uri: value.url && value.url !== '' ? trimUri(value.url) : null, uri: value.url && value.url !== '' ? trimUri(value.url) : null,
username: value.username && value.username !== '' ? value.username : null, username: value.username && value.username !== '' ? value.username : null,
@ -518,58 +556,54 @@
cipher.notes = value.extra && value.extra !== '' ? value.extra : null; cipher.notes = value.extra && value.extra !== '' ? value.extra : null;
} }
else if (cipher.type === contants.cipherType.secureNote) { else if (cipher.type === constants.cipherType.secureNote) {
cipher.secureNote = { var extraParts = value.extra.split(/(?:\r\n|\r|\n)/),
type: 0 processedNote = false;
}; if (extraParts.length) {
var typeParts = extraParts[0].split(':');
if (typeParts.length > 1 && typeParts[0] === 'NoteType' &&
(typeParts[1] === 'Credit Card' || typeParts[1] === 'Address')) {
var mappedData = null;
if (typeParts[1] === 'Credit Card') {
mappedData = parseSecureNoteMapping(extraParts, {
'Number': 'number',
'Name on Card': 'cardholderName',
'Security Code': 'code'
}, []);
cipher.type = constants.cipherType.card;
cipher.card = mappedData.dataObj;
}
else if (typeParts[1] === 'Address') {
mappedData = parseSecureNoteMapping(extraParts, {
'Title': 'title',
'First Name': 'firstName',
'Last Name': 'lastName',
'Middle Name': 'middleName',
'Company': 'company',
'Address 1': 'address1',
'Address 2': 'address2',
'Address 3': 'address3',
'City / Town': 'city',
'State': 'state',
'Zip / Postal Code': 'postalCode',
'Country': 'country',
'Email Address': 'email',
'Username': 'username'
}, []);
cipher.type = constants.cipherType.identity;
cipher.identity = mappedData.dataObj;
}
if (value.extra.indexOf('NoteType:') !== 0) { processedNote = true;
// must be a generic note cipher.notes = mappedData.notes;
cipher.notes = value.extra && value.extra !== '' ? value.extra : null; }
} }
else {
var extraParts = value.extra.split(/(?:\r\n|\r|\n)/),
doFields = true;
if (extraParts.length) {
var typeParts = extraParts[0].split(':');
if (typeParts.length > 1 && typeParts[0] === 'NoteType') {
if (typeParts[1] === 'Credit Card') {
doFields = false;
cipher.type = contants.cipherType.card;
cipher.secureNote = null;
// TODO: handle card
cipher.card = {};
}
else if (typeParts[1] === 'Address') {
doFields = false;
cipher.type = contants.cipherType.identity;
cipher.secureNote = null;
// TODO: handle identity
cipher.identity = {};
}
}
}
if (doFields) { if (!processedNote) {
for (i = 0; i < extraParts.length; i++) { cipher.secureNote = {
var fieldParts = extraParts[i].split(':'); type: 0
if (!fieldParts.length) { };
continue; cipher.notes = value.extra && value.extra !== '' ? value.extra : null;
}
var field = {
name: fieldParts[0],
value: fieldParts.length > 1 ? fieldParts[1] : null,
type: constants.fieldType.text
};
if (!cipher.fields) {
cipher.fields = [];
}
cipher.fields.push(field);
}
}
} }
} }
@ -632,7 +666,7 @@
favorite: false, favorite: false,
notes: '', notes: '',
name: card.attr('title'), name: card.attr('title'),
type: contants.cipherType.login, type: constants.cipherType.login,
login: {} login: {}
}; };
@ -741,7 +775,7 @@
var cipher = { var cipher = {
favorite: false, favorite: false,
type: contants.cipherType.login, type: constants.cipherType.login,
notes: null, notes: null,
name: value[0] && value[0] !== '' ? value[0] : '--', name: value[0] && value[0] !== '' ? value[0] : '--',
login: { login: {
@ -840,7 +874,7 @@
favorite: false, favorite: false,
notes: null, notes: null,
name: null, name: null,
type: contants.cipherType.login, type: constants.cipherType.login,
login: { login: {
uri: null, uri: null,
username: null, username: null,
@ -941,7 +975,7 @@
} }
var cipher = { var cipher = {
type: contants.cipherType.login, type: constants.cipherType.login,
favorite: false, favorite: false,
notes: value.Notes && value.Notes !== '' ? value.Notes : null, notes: value.Notes && value.Notes !== '' ? value.Notes : null,
name: value.Title && value.Title !== '' ? value.Title : '--', name: value.Title && value.Title !== '' ? value.Title : '--',
@ -1024,7 +1058,7 @@
var item = JSON.parse(line); var item = JSON.parse(line);
var cipher = { var cipher = {
type: contants.cipherType.login, type: constants.cipherType.login,
favorite: item.openContents && item.openContents.faveIndex ? true : false, favorite: item.openContents && item.openContents.faveIndex ? true : false,
notes: null, notes: null,
name: item.title && item.title !== '' ? item.title : '--', name: item.title && item.title !== '' ? item.title : '--',
@ -1079,7 +1113,7 @@
} }
var cipher = { var cipher = {
type: contants.cipherType.login, type: constants.cipherType.login,
favorite: false, favorite: false,
notes: value.notesPlain && value.notesPlain !== '' ? value.notesPlain : '', notes: value.notesPlain && value.notesPlain !== '' ? value.notesPlain : '',
name: value.title && value.title !== '' ? value.title : '--', name: value.title && value.title !== '' ? value.title : '--',