import updates

- converted logins to ciphers up to 1password csv
- started secure notes support for lastpasss
This commit is contained in:
Kyle Spearrin 2017-10-12 14:24:08 -04:00
parent cd93d6cc32
commit 106e71fe54
1 changed files with 193 additions and 121 deletions

View File

@ -1,7 +1,7 @@
angular angular
.module('bit.services') .module('bit.services')
.factory('importService', function () { .factory('importService', function (contants) {
var _service = {}; var _service = {};
_service.import = function (source, file, success, error) { _service.import = function (source, file, success, error) {
@ -270,6 +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,
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,
@ -297,7 +298,7 @@
var field = { var field = {
name: fields[i].substr(0, delimPosition), name: fields[i].substr(0, delimPosition),
value: null, value: null,
type: 0 type: constants.fieldType.text
}; };
if (fields[i].length > (delimPosition + 2)) { if (fields[i].length > (delimPosition + 2)) {
@ -377,6 +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,
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,
@ -404,7 +406,7 @@
var field = { var field = {
name: fields[i].substr(0, delimPosition), name: fields[i].substr(0, delimPosition),
value: null, value: null,
type: 0 type: constants.fieldType.text
}; };
if (fields[i].length > (delimPosition + 2)) { if (fields[i].length > (delimPosition + 2)) {
@ -481,17 +483,18 @@
function parseData(data) { function parseData(data) {
var folders = [], var folders = [],
logins = [], ciphers = [],
loginRelationships = []; cipherRelationships = [],
i = 0;
angular.forEach(data, function (value, key) { angular.forEach(data, function (value, key) {
var folderIndex = folders.length, var folderIndex = folders.length,
loginIndex = logins.length, cipherIndex = ciphers.length,
hasFolder = value.grouping && value.grouping !== '' && value.grouping !== '(none)', hasFolder = value.grouping && value.grouping !== '' && value.grouping !== '(none)',
addFolder = hasFolder; addFolder = hasFolder;
if (hasFolder) { if (hasFolder) {
for (var i = 0; i < folders.length; i++) { for (i = 0; i < folders.length; i++) {
if (folders[i].name === value.grouping) { if (folders[i].name === value.grouping) {
addFolder = false; addFolder = false;
folderIndex = i; folderIndex = i;
@ -500,14 +503,71 @@
} }
} }
logins.push({ var cipher = {
favorite: org ? false : value.fav === '1', favorite: org ? false : value.fav === '1',
name: value.name && value.name !== '' ? value.name : '--',
type: value.url === 'http://sn' ? contants.cipherType.secureNote : contants.cipherType.login
};
if (cipher.type === contants.cipherType.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,
password: value.password && value.password !== '' ? value.password : null, password: value.password && value.password !== '' ? value.password : null
notes: value.extra && value.extra !== '' ? value.extra : null, };
name: value.name && value.name !== '' ? value.name : '--',
}); cipher.notes = value.extra && value.extra !== '' ? value.extra : null;
}
else if (cipher.type === contants.cipherType.secureNote) {
if (value.extra.indexOf('NoteType:') === 0) {
// must be a generic note
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;
// TODO: handle card
cipher.card = {};
}
else if (typeParts[1] === 'Address') {
doFields = false;
cipher.type = contants.cipherType.identity;
// TODO: handle identity
cipher.identity = {};
}
}
}
if (doFields) {
for (i = 0; i < extraParts.length; i++) {
var fieldParts = extraParts[i].split(':');
if (!fieldParts.length) {
continue;
}
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);
}
}
}
}
ciphers.push(cipher);
if (addFolder) { if (addFolder) {
folders.push({ folders.push({
@ -517,21 +577,21 @@
if (hasFolder) { if (hasFolder) {
var relationship = { var relationship = {
key: loginIndex, key: cipherIndex,
value: folderIndex value: folderIndex
}; };
loginRelationships.push(relationship); cipherRelationships.push(relationship);
} }
}); });
success(folders, logins, loginRelationships); success(folders, ciphers, cipherRelationships);
} }
} }
function importSafeInCloudXml(file, success, error) { function importSafeInCloudXml(file, success, error) {
var folders = [], var folders = [],
logins = [], ciphers = [],
loginRelationships = [], cipherRelationships = [],
foldersIndex = [], foldersIndex = [],
i = 0, i = 0,
j = 0; j = 0;
@ -562,13 +622,12 @@
continue; continue;
} }
var login = { var cipher = {
favorite: false, favorite: false,
uri: null,
username: null,
password: null,
notes: '', notes: '',
name: card.attr('title'), name: card.attr('title'),
type: contants.cipherType.login,
login: {}
}; };
var fields = card.find('> field'); var fields = card.find('> field');
@ -581,16 +640,16 @@
if (text && text !== '') { if (text && text !== '') {
if (type === 'login') { if (type === 'login') {
login.username = text; cipher.login.username = text;
} }
else if (type === 'password') { else if (type === 'password') {
login.password = text; cipher.login.password = text;
} }
else if (type === 'notes') { else if (type === 'notes') {
login.notes += (text + '\n'); login.notes += (text + '\n');
} }
else if (type === 'weblogin' || type === 'website') { else if (type === 'weblogin' || type === 'website') {
login.uri = trimUri(text); cipher.login.uri = trimUri(text);
} }
else { else {
login.notes += (name + ': ' + text + '\n'); login.notes += (name + ': ' + text + '\n');
@ -600,22 +659,22 @@
var notes = card.find('> notes'); var notes = card.find('> notes');
for (j = 0; j < notes.length; j++) { for (j = 0; j < notes.length; j++) {
login.notes += ($(notes[j]).text() + '\n'); cipher.notes += ($(notes[j]).text() + '\n');
} }
if (login.notes === '') { if (cipher.notes === '') {
login.notes = null; cipher.notes = null;
} }
logins.push(login); ciphers.push(cipher);
labels = card.find('> label_id'); labels = card.find('> label_id');
if (labels.length) { if (labels.length) {
var labelId = $(labels[0]).text(); var labelId = $(labels[0]).text();
var folderIndex = foldersIndex[labelId]; var folderIndex = foldersIndex[labelId];
if (labelId !== null && labelId !== '' && folderIndex !== null) { if (labelId !== null && labelId !== '' && folderIndex !== null) {
loginRelationships.push({ cipherRelationships.push({
key: logins.length - 1, key: ciphers.length - 1,
value: folderIndex value: folderIndex
}); });
} }
@ -623,7 +682,7 @@
} }
} }
success(folders, logins, loginRelationships); success(folders, ciphers, cipherRelationships);
} }
else { else {
error(); error();
@ -638,7 +697,7 @@
parseCsvErrors(results); parseCsvErrors(results);
var folders = [], var folders = [],
logins = [], ciphers = [],
folderRelationships = []; folderRelationships = [];
var customFieldHeaders = []; var customFieldHeaders = [];
@ -660,7 +719,7 @@
} }
var folderIndex = folders.length, var folderIndex = folders.length,
loginIndex = logins.length, cipherIndex = ciphers.length,
hasFolder = value[1] && value[1] !== '', hasFolder = value[1] && value[1] !== '',
addFolder = hasFolder; addFolder = hasFolder;
@ -674,13 +733,16 @@
} }
} }
var login = { var cipher = {
favorite: false, favorite: false,
uri: null, type: contants.cipherType.login,
username: value[2] && value[2] !== '' ? value[2] : null,
password: value[3] && value[3] !== '' ? value[3] : null,
notes: null, notes: null,
name: value[0] && value[0] !== '' ? value[0] : '--', name: value[0] && value[0] !== '' ? value[0] : '--',
login: {
uri: null,
username: value[2] && value[2] !== '' ? value[2] : null,
password: value[3] && value[3] !== '' ? value[3] : null
}
}; };
if (customFieldHeaders.length) { if (customFieldHeaders.length) {
@ -692,19 +754,19 @@
var cfHeader = customFieldHeaders[j - 4]; var cfHeader = customFieldHeaders[j - 4];
if (cfHeader.toLowerCase() === 'url' || cfHeader.toLowerCase() === 'uri') { if (cfHeader.toLowerCase() === 'url' || cfHeader.toLowerCase() === 'uri') {
login.uri = trimUri(cf); cipher.login.uri = trimUri(cf);
} }
else { else {
if (login.notes === null) { if (cipher.notes === null) {
login.notes = ''; cipher.notes = '';
} }
login.notes += cfHeader + ': ' + cf + '\n'; cipher.notes += cfHeader + ': ' + cf + '\n';
} }
} }
} }
logins.push(login); ciphers.push(cipher);
if (addFolder) { if (addFolder) {
folders.push({ folders.push({
@ -714,21 +776,21 @@
if (hasFolder) { if (hasFolder) {
folderRelationships.push({ folderRelationships.push({
key: loginIndex, key: cipherIndex,
value: folderIndex value: folderIndex
}); });
} }
} }
success(folders, logins, folderRelationships); success(folders, ciphers, folderRelationships);
} }
}); });
} }
function importKeePass2Xml(file, success, error) { function importKeePass2Xml(file, success, error) {
var folders = [], var folders = [],
logins = [], ciphers = [],
loginRelationships = []; folderRelationships = [];
getXmlFileContents(file, parse, error); getXmlFileContents(file, parse, error);
@ -740,7 +802,7 @@
var group = root.find('> Group'); var group = root.find('> Group');
if (group.length) { if (group.length) {
traverse($(group[0]), true, ''); traverse($(group[0]), true, '');
success(folders, logins, loginRelationships); success(folders, ciphers, folderRelationships);
} }
} }
else { else {
@ -767,14 +829,17 @@
if (entries.length) { if (entries.length) {
for (var i = 0; i < entries.length; i++) { for (var i = 0; i < entries.length; i++) {
var entry = $(entries[i]); var entry = $(entries[i]);
var loginIndex = logins.length; var cipherIndex = ciphers.length;
var login = { var cipher = {
favorite: false, favorite: false,
notes: null,
name: null,
type: contants.cipherType.login,
login: {
uri: null, uri: null,
username: null, username: null,
password: null, password: null
notes: null, }
name: null
}; };
var entryStrings = entry.find('> String'); var entryStrings = entry.find('> String');
@ -789,37 +854,37 @@
switch (key) { switch (key) {
case 'URL': case 'URL':
login.uri = trimUri(value); cipher.login.uri = trimUri(value);
break; break;
case 'UserName': case 'UserName':
login.username = value; cipher.login.username = value;
break; break;
case 'Password': case 'Password':
login.password = value; cipher.login.password = value;
break; break;
case 'Title': case 'Title':
login.name = value; cipher.name = value;
break; break;
case 'Notes': case 'Notes':
login.notes = login.notes === null ? value + '\n' : login.notes + value + '\n'; cipher.notes = cipher.notes === null ? value + '\n' : cipher.notes + value + '\n';
break; break;
default: default:
// other custom fields // other custom fields
login.notes = login.notes === null ? key + ': ' + value + '\n' cipher.notes = cipher.notes === null ? key + ': ' + value + '\n'
: login.notes + key + ': ' + value + '\n'; : cipher.notes + key + ': ' + value + '\n';
break; break;
} }
} }
if (login.name === null) { if (cipher.name === null) {
login.name = '--'; cipher.name = '--';
} }
logins.push(login); ciphers.push(cipher);
if (!isRootNode) { if (!isRootNode) {
loginRelationships.push({ folderRelationships.push({
key: loginIndex, key: cipherIndex,
value: folderIndex value: folderIndex
}); });
} }
@ -843,7 +908,7 @@
parseCsvErrors(results); parseCsvErrors(results);
var folders = [], var folders = [],
logins = [], ciphers = [],
folderRelationships = []; folderRelationships = [];
angular.forEach(results.data, function (value, key) { angular.forEach(results.data, function (value, key) {
@ -854,7 +919,7 @@
value.Group.split('/').join(' > ') : null; value.Group.split('/').join(' > ') : null;
var folderIndex = folders.length, var folderIndex = folders.length,
loginIndex = logins.length, cipherIndex = ciphers.length,
hasFolder = groupName !== null, hasFolder = groupName !== null,
addFolder = hasFolder, addFolder = hasFolder,
i = 0; i = 0;
@ -869,17 +934,20 @@
} }
} }
var login = { var cipher = {
type: contants.cipherType.login,
favorite: false, favorite: false,
uri: value.URL && value.URL !== '' ? fixUri(value.URL) : null,
username: value.Username && value.Username !== '' ? value.Username : null,
password: value.Password && value.Password !== '' ? value.Password : null,
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 : '--',
login: {
uri: value.URL && value.URL !== '' ? fixUri(value.URL) : null,
username: value.Username && value.Username !== '' ? value.Username : null,
password: value.Password && value.Password !== '' ? value.Password : null
}
}; };
if (value.Title) { if (value.Title) {
logins.push(login); ciphers.push(cipher);
} }
if (addFolder) { if (addFolder) {
@ -890,49 +958,48 @@
if (hasFolder) { if (hasFolder) {
var relationship = { var relationship = {
key: loginIndex, key: cipherIndex,
value: folderIndex value: folderIndex
}; };
folderRelationships.push(relationship); folderRelationships.push(relationship);
} }
}); });
success(folders, logins, folderRelationships); success(folders, ciphers, folderRelationships);
} }
}); });
} }
function import1Password1Pif(file, success, error) { function import1Password1Pif(file, success, error) {
var folders = [], var folders = [],
logins = [], ciphers = [],
loginRelationships = [],
i = 0; i = 0;
function parseFields(fields, login, designationKey, valueKey, nameKey) { function parseFields(fields, cipher, designationKey, valueKey, nameKey) {
for (var j = 0; j < fields.length; j++) { for (var j = 0; j < fields.length; j++) {
var field = fields[j]; var field = fields[j];
if (!field[valueKey] || field[valueKey] === '') { if (!field[valueKey] || field[valueKey] === '') {
continue; continue;
} }
if (!login.username && field[designationKey] && field[designationKey] === 'username') { if (!cipher.login.username && field[designationKey] && field[designationKey] === 'username') {
login.username = field[valueKey]; cipher.login.username = field[valueKey];
} }
else if (!login.password && field[designationKey] && field[designationKey] === 'password') { else if (!cipher.login.password && field[designationKey] && field[designationKey] === 'password') {
login.password = field[valueKey]; cipher.login.password = field[valueKey];
} }
else if (!login.totp && field[designationKey] && field[designationKey].startsWith("TOTP_")) { else if (!cipher.login.totp && field[designationKey] && field[designationKey].startsWith("TOTP_")) {
login.totp = field[valueKey]; cipher.login.totp = field[valueKey];
} }
else if (field[valueKey]) { else if (field[valueKey]) {
if (login.notes === null) { if (cipher.notes === null) {
login.notes = ''; cipher.notes = '';
} }
else { else {
login.notes += '\n'; cipher.notes += '\n';
} }
login.notes += ((field[nameKey] || 'no_name') + ': ' + cipher.notes += ((field[nameKey] || 'no_name') + ': ' +
field[valueKey].toString().split('\\r\\n').join('\n').split('\\n').join('\n')); field[valueKey].toString().split('\\r\\n').join('\n').split('\\n').join('\n'));
} }
} }
@ -950,46 +1017,48 @@
} }
var item = JSON.parse(line); var item = JSON.parse(line);
var login = { var cipher = {
type: contants.cipherType.login,
favorite: item.openContents && item.openContents.faveIndex ? true : false, favorite: item.openContents && item.openContents.faveIndex ? true : false,
notes: null,
name: item.title && item.title !== '' ? item.title : '--',
login: {
uri: item.location && item.location !== '' ? fixUri(item.location) : null, uri: item.location && item.location !== '' ? fixUri(item.location) : null,
username: null, username: null,
password: null, password: null,
notes: null,
name: item.title && item.title !== '' ? item.title : '--',
totp: null totp: null
}
}; };
if (item.secureContents) { if (item.secureContents) {
if (item.secureContents.notesPlain && item.secureContents.notesPlain !== '') { if (item.secureContents.notesPlain && item.secureContents.notesPlain !== '') {
login.notes = item.secureContents.notesPlain cipher.notes = item.secureContents.notesPlain
.split('\\r\\n').join('\n').split('\\n').join('\n'); .split('\\r\\n').join('\n').split('\\n').join('\n');
} }
if (item.secureContents.fields) { if (item.secureContents.fields) {
parseFields(item.secureContents.fields, login, 'designation', 'value', 'name'); parseFields(item.secureContents.fields, cipher, 'designation', 'value', 'name');
} }
if (item.secureContents.sections) { if (item.secureContents.sections) {
for (var j = 0; j < item.secureContents.sections.length; j++) { for (var j = 0; j < item.secureContents.sections.length; j++) {
if (item.secureContents.sections[j].fields) { if (item.secureContents.sections[j].fields) {
parseFields(item.secureContents.sections[j].fields, login, 'n', 'v', 't'); parseFields(item.secureContents.sections[j].fields, cipher, 'n', 'v', 't');
} }
} }
} }
} }
logins.push(login); ciphers.push(cipher);
} }
success(folders, logins, loginRelationships); success(folders, ciphers, []);
} }
} }
function import1Password6WinCsv(file, success, error) { function import1Password6WinCsv(file, success, error) {
var folders = [], var folders = [],
logins = [], ciphers = [];
loginRelationships = [];
Papa.parse(file, { Papa.parse(file, {
encoding: 'UTF-8', encoding: 'UTF-8',
@ -1003,13 +1072,16 @@
continue; continue;
} }
var login = { var cipher = {
type: contants.cipherType.login,
favorite: false, favorite: false,
notes: value.notesPlain && value.notesPlain !== '' ? value.notesPlain : '',
name: value.title && value.title !== '' ? value.title : '--',
login: {
uri: null, uri: null,
username: null, username: null,
password: null, password: null
notes: value.notesPlain && value.notesPlain !== '' ? value.notesPlain : '', }
name: value.title && value.title !== '' ? value.title : '--'
}; };
for (var property in value) { for (var property in value) {
@ -1018,45 +1090,45 @@
continue; continue;
} }
if (!login.password && property === 'password') { if (!cipher.login.password && property === 'password') {
login.password = value[property]; cipher.login.password = value[property];
} }
else if (!login.username && property === 'username') { else if (!cipher.login.username && property === 'username') {
login.username = value[property]; cipher.login.username = value[property];
} }
else if (!login.uri && property === 'urls') { else if (!cipher.login.uri && property === 'urls') {
var urls = value[property].split(/(?:\r\n|\r|\n)/); var urls = value[property].split(/(?:\r\n|\r|\n)/);
login.uri = fixUri(urls[0]); cipher.login.uri = fixUri(urls[0]);
for (var j = 1; j < urls.length; j++) { for (var j = 1; j < urls.length; j++) {
if (login.notes !== '') { if (cipher.notes !== '') {
login.notes += '\n'; cipher.notes += '\n';
} }
login.notes += ('url ' + (j + 1) + ': ' + urls[j]); cipher.notes += ('url ' + (j + 1) + ': ' + urls[j]);
} }
} }
else if (property !== 'ainfo' && property !== 'autosubmit' && property !== 'notesPlain' && else if (property !== 'ainfo' && property !== 'autosubmit' && property !== 'notesPlain' &&
property !== 'ps' && property !== 'scope' && property !== 'tags' && property !== 'title' && property !== 'ps' && property !== 'scope' && property !== 'tags' && property !== 'title' &&
property !== 'uuid' && !property.startsWith('section:')) { property !== 'uuid' && !property.startsWith('section:')) {
if (login.notes !== '') { if (cipher.notes !== '') {
login.notes += '\n'; cipher.notes += '\n';
} }
login.notes += (property + ': ' + value[property]); cipher.notes += (property + ': ' + value[property]);
} }
} }
} }
if (login.notes === '') { if (cipher.notes === '') {
login.notes = null; cipher.notes = null;
} }
logins.push(login); ciphers.push(cipher);
} }
success(folders, logins, loginRelationships); success(folders, ciphers, []);
} }
}); });
} }