Giter VIP home page Giter VIP logo

buttercup-core's Introduction


Buttercup Core


Buttercup core library

A NodeJS secrets vault.

Buttercup npm npm version node min version security encryption

Tests status

NPM

About

Buttercup is a JavaScript password manager for NodeJS and the browser (though you can also see it used on platforms like React Native). It's based around the concept of a Vault and its secret Entry items (a login, credit card etc.). Entries are then separated into Group containers that make organising vaults a little easier.

Because Buttercup is designed first and foremost to be consumed by users in some application, VaultManager and VaultSource constructs are provided to allow for easy control over several vaults in a somewhat shared environment. A vault manager provides easy-to-use methods to perform dehydration and rehydration (storage in serialised form) of vaults to some secure storage (files, remote datasources etc.).

Buttercup can save and load vaults that are stored locally, in cloud service providers like Dropbox or Google Drive, or in a cloud service's WebDAV-enabled storage. It does this by providing a Datasource construct for each provider.

Because Buttercup can be consumed in some interesting and varied environments, serialisation tools called facades are provided to allow for greater flexibility when working with vault data structures. Facades provide a way to move data around without classes, converting vaults to and from JSON objects. Facades are used when attaching vaults to user interfaces like with the Buttercup UI library.

Features

The core of the system, this Buttercup Core, boasts a few awesome features:

  • Merge-able vault contents
  • History for back-tracking to previous passwords etc.
  • File attachments (encrypted)
  • AES CBC encryption
  • GZip compression
  • NodeJS and Browser support

This library also supports a variety of datasources for loading from and saving to:

Check out the changelog.

Installation

To use Buttercup in a NodeJS environment, you can simply install and require it:

npm install buttercup --save

In a Node environment, for example:

const { Vault } = require("buttercup");

Or for Typescript:

import { Vault } from "buttercup";

In a web environment, use the following:

import { Vault } from "buttercup/web";

Buttercup core is ESM - you must either import it in a project that is also ESM, or use a build tool like Webpack.

Buttercup core supports Node version 14 and up. For older Node versions use v6 and earlier.

Usage

Buttercup uses Vaults, Groups and Entrys to manipulate data in a workspace-like environment. These 3 constructs have no knowledge of encryption or storage, and simply provide interfaces for working with the data structures.

To manage vaults, their storage and their states in a higher-level manner more appropriate for building applications, check out the VaultManager and VaultSource constructs.

To get started, we should create a new Vault:

import { Vault, init } from "buttercup";

// Initialise environment
init();

// Create an empty vault
const vault1 = new Vault();

// Create aa vault with "General" and "Trash" groups
const vault2 = Vault.createWithDefaults();

The init() function call is used to initialise the environment (performs the same function as @buttercup/app-env used to). It is required for Buttercup to work. It can be called more than once without effect.

Entries can't be added directly to a Vault, but can be to Groups. Creating Groups and Entries is trivial:

const vault = Vault.createWithDefaults();
const myGroup = vault.createGroup("My Group");
const myEntry = myGroup.createEntry("My Entry");

Every command on Vaults, Groups and Entries modifies the Vault instance, but does not save it to storage. There is no command or need to commit any data - each instance links back to the original Vault. Vaults are saved and loaded using Datasources:

import { Credentials, FileDatasource, Vault, init } from "buttercup";

init();

const datasourceCredentials = Credentials.fromDatasource({
    path: "./user.bcup"
}, "masterPassword!");
const fileDatasource = new FileDatasource(datasourceCredentials);
const vault = Vault.createWithDefaults();
vault
    .createGroup("Websites")
        .createEntry("My bank")
            .setProperty("username", "user-name")
            .setProperty("password", "s3cureP4$$");

const vaultCredentials = Credentials.fromPassword("masterPassword!");
await fileDatasource.save(vault.format.history, vaultCredentials);

Later:

const datasourceCredentials = Credentials.fromDatasource({
    path: "./user.bcup"
}, "masterPassword!");
const fileDatasource = new FileDatasource(datasourceCredentials);

fileDatasource
    .load(datasourceCredentials)
    .then(Vault.createFromHistory)
    .then(vault => {
        // ...
    });

Using just a datasource is not recommended as saving and loading is quite low-level and cumbersome. Check the browser extension or desktop application for examples of how to use the VaultManager and other helpful classes.

Development

To develop Buttercup Core, clone the repository on a Linux or Mac OS machine. Ensure that you're running NodeJS version 16/18. Install all dependencies by running npm install in the project directory. Run the tests to ensure everything is functioning correctly: npm test.

Vault Formats

Buttercup currently supports 2 concurrent vault formats, as it is in the process of transitioning from Format A (legacy) to Format B. You can switch the operational format by doing the following:

const { VaultFormatB, init, setDefaultFormat } = require("buttercup");

init();

setDefaultFormat(VaultFormatB);

Buttercup will automatically transition to using Format B as the default in some weeks or months (since v5 was released).

Compatibility

Buttercup's compatibility is defined as the following:

  • NodeJS version 12 and up
  • Current versions of the following browsers:
    • Google Chrome
    • Mozilla Firefox
    • Safari
  • React Native 0.60+

NB: React Native support is not guaranteed under all circumstances as the platform's stability for low-level operations like cryptography is questionable. Use the mobile app as a guideline for implementation.

Browser support is strictly dependent on:

  • Popularity
  • The availability of required crypto libaries such as SubtleCrypto

buttercup-core's People

Contributors

benjspriggs avatar cullub avatar ghostd avatar jameskmonger avatar kylart avatar luislobo avatar perry-mitchell avatar sallar avatar wingysam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

buttercup-core's Issues

Provide error codes

It'd be good to throw some error codes, as well as the message. Identifying the wrong decryption key right now is quite difficult because you need to compare the whole string.

Add archive versions as test-cases

Create an archive auto-generation script which writes an archive at a version to a test directory.

A test should loop over all archives in this directory, attempt to open each one, and check for different properties to ensure they're all handled correctly.

Tests fail on import KDBX archives

Errors like the following occur randomly:

importKDBXTests
✔ containsInHistory - testContainsNotes
✔ containsInHistory - testContainsPassword
✔ containsItems - testContainsRootGroup
✖ containsItems - testContainsSubGroup

Assertion Message: Imported archive should contain sub group
AssertionError: Imported archive should contain sub group
    at Object.ok (/Users/pez/Git/buttercup-core/node_modules/nodeunit/lib/types.js:83:39)
    at Object.module.exports.containsItems.testContainsSubGroup (/Users/pez/Git/buttercup-core/tests/integration/importKDBXTests.js:54:9)
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/lib/core.js:232:20
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:168:13
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:131:25
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:165:17
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:463:34
    at /Users/pez/Git/buttercup-core/tests/integration/importKDBXTests.js:17:9

Move group test issue

A very intermittent test failure:

ManagedGroupTests
✔ delete - testDeletesGroup
✔ delete - testThrowsForTrashGroup
✔ getAttribute - testGetsAttribute
✔ getEntries - testGetsEntries
✔ getID - testGetsID
✔ getTitle - testGetsTitle
✖ moveToGroup - testMovesToAnotherGroup

Assertion Message: Target group should have the new child group
AssertionError: Target group should have the new child group
    at Object.ok (/Users/pez/Git/buttercup-core/node_modules/nodeunit/lib/types.js:83:39)
    at Object.module.exports.moveToGroup.testMovesToAnotherGroup (/Users/pez/Git/buttercup-core/tests/ManagedGroupTests.js:104:9)
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/lib/core.js:232:20
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:168:13
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:131:25
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:165:17
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:463:34
    at Object.module.exports.setUp (/Users/pez/Git/buttercup-core/tests/ManagedGroupTests.js:35:7)
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/lib/core.js:260:35
    at /Users/pez/Git/buttercup-core/node_modules/nodeunit/deps/async.js:458:21

Archive should extend Group

The Archive class should extend Group for obvious reasons. This would make for better interfaces when dealing with archives in a group-like manner. Archives are a Group in many ways and should reflect this.

Add coverage around 963377a

I noticed that the fix for the occasionally failing tests (963377a) didn't have any tests added to check that the behaviour is now correct. It'd probably be good to get a test in there just for some robustness around the fix.

Allow searching archives for groups

Either through publicising the searching tool, or adding functions to the Archive prototype, I think there should be more options to reliably search archives for groups, for example based on their title.

To get a group with the title 'bob' in another project, I had to do this:

let groups = archive.getGroups();
let group = groups.filter((g) => g._remoteObject.title === 'bob')[0];

This clearly isn't a reliable or clean way to do it. I would much rather be able to do:

let group = Buttercup.tools.searching.findGroupByTitle(archive.getGroups(), 'bob');

Or, better yet:

let group = archive.findGroupByTitle('bob');

Use webdav-fs

Include webdav-fs instead of hardcoded webdav support.

Remove cmm command

I can't see any use of the cmm command at the moment, would it not make sense to remove it?

npm test command failing to run

When running npm test, I get the following error which prevents the tests from running at all:

> [email protected] test:nodeunit /home/james/Development/buttercup-core
> node node_modules/nodeunit/bin/nodeunit tests tests/integration tests/commands

module.js:339
    throw err;
    ^

Error: Cannot find module '__buttercup/classes/Archive.js'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /home/james/Development/buttercup-core/source/module.js:7:18
    at Object.<anonymous> (/home/james/Development/buttercup-core/source/module.js:37:3)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)

npm ERR! Linux 3.19.0-51-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test:nodeunit"
npm ERR! node v5.0.0
npm ERR! npm  v3.7.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test:nodeunit: `node node_modules/nodeunit/bin/nodeunit tests tests/integration tests/commands`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test:nodeunit script 'node node_modules/nodeunit/bin/nodeunit tests tests/integration tests/commands'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the buttercup package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node node_modules/nodeunit/bin/nodeunit tests tests/integration tests/commands
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs buttercup
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls buttercup
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/james/Development/buttercup-core/npm-debug.log
npm ERR! Test failed.  See above for more details.

Flattening support

Add ability to flatten file history without data loss.

Only flatten when archive is at 1000 lines. Flatten across 500 lines (from start).

Remove images from core library

From what I can tell, this library (buttercup-core) is intended to be the backbone of the Buttercup application. Therefore, I'm not entirely sure if the images in the /resources/ folder actually belong in this library. The folder is almost 70kb in total, which would be quite a considerable amount to take off the size of the library.

Key file support

Add support for key files for locking/unlocking archives as well as loading/saving.

How to set an ID for a group ?

@perry-mitchell @sallar
Hi, I need to know the process of setting an ID for the group in an archive.

I tried using managedGroup.getID() , but didn't get any output for it, also tried using archive.getGroupByID() and entered the groupname as the parameter, but only got 'null' as the output.

So can you please help me with this ?

npm install ERR!

This error occurred on webpack-react branch. I don't have any idea the JSON file which logged, where or what is it? :)

npm ERR! registry error parsing json
npm ERR! Darwin 15.5.0
npm ERR! argv "/Users/naser/.nvm/versions/node/v6.4.0/bin/node" "/Users/naser/.nvm/versions/node/v6.4.0/bin/npm" "install"
npm ERR! node v6.4.0
npm ERR! npm  v3.10.3

npm ERR! Unexpected token < in JSON at position 0
npm ERR! <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><title>MN8-4
npm ERR! </title></head><body><iframe src="http://10.10.34.34?type=Invalid Keyword&policy=MainPolicy " style="width: 100%; height: 100%" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"></iframe></body></html>
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/naser/workspace/lab/sandbox/electron/buttercup/npm-debug.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.