Skip to content

Commit

Permalink
Basic Foundation for a Keeper Security JSON Importer
Browse files Browse the repository at this point in the history
  • Loading branch information
muddykat-tech committed Apr 16, 2024
1 parent 2004c97 commit 9ab5766
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>buttercup-importer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
101 changes: 101 additions & 0 deletions source/importers/KeeperSecurityImporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const fs = require("fs/promises");
const {
Vault,
Entry,
createEntryFacade,
consumeEntryFacade,
} = require("buttercup");

const DEFAULT_GROUP = "General";

/**
* Importer for Keeper Security vaults
* @memberof module:ButtercupImporter
*/
class KeeperSecurityImporter {
/**
* Create a new Keeper Security importer
* @param {String} data Raw JSON data of a Keeper Security vault export
*/
constructor(data) {
this._data = data;
}

/**
* Export to a Buttercup vault
* @returns {Promise.<Vault>}
* @memberof KeeperSecurityImporter
*/
export() {
const groups = {};
return Promise.resolve().then(() => {
const vault = new Vault();
const ksJson = JSON.parse(this._data); // Parse the new JSON data

// Create the root group
const rootGroup = vault.createGroup(DEFAULT_GROUP);
groups[null] = rootGroup;

ksJson.records.forEach((record) => {
if (record.folders) {
var folderPath = record.folders[0].folder;
var folders = folderPath
.split("\\")
.map((folderName) => folderName.trim());

var currentGroup = rootGroup;

for (
var folderIndex = 0;
folderIndex < folders.length;
folderIndex += 1
) {
if (groups[folders[folderIndex]] != undefined) {
currentGroup = groups[folders[folderIndex]];
} else {
currentGroup = currentGroup.createGroup(
folders[folderIndex]
);

// Section untested due to an odd issue with createEntry not instancing correctly?
const entry = currentGroup.createEntry(
record.title
);
entry.setProperty(
"username",
record.login == null ? "" : record.login
);
entry.setProperty(
"password",
record.password == null ? "" : record.password
);
entry.setProperty(
"URL",
record.login_url == null ? "" : record.login_url
);

groups[folders[folderIndex]] = currentGroup;
}
}
}
});

return vault;
});
}
}

/**
* Load an importer from a file
* @param {String} filename The file to load from
* @returns {Promise.<KeeperSecurityImporter>}
* @static
* @memberof KeeperSecurityImporter
*/
KeeperSecurityImporter.loadFromFile = function (filename) {
return fs
.readFile(filename, "utf8")
.then((data) => new KeeperSecurityImporter(data));
};

module.exports = KeeperSecurityImporter;
2 changes: 2 additions & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const CSVImporter = require("./importers/CSVImporter.js");
const KeePass2XMLImporter = require("./importers/KeePass2XMLImporter.js");
const LastPassImporter = require("./importers/LastPassImporter.js");
const OnePasswordImporter = require("./importers/OnePasswordImporter.js");
const KeeperSecurityImporter = require("./importers/KeeperSecurityImporter.js");

/**
* @module ButtercupImporter
Expand All @@ -18,4 +19,5 @@ module.exports = {
KeePass2XMLImporter,
LastPassImporter,
OnePasswordImporter,
KeeperSecurityImporter,
};

0 comments on commit 9ab5766

Please sign in to comment.