GithubHelp home page GithubHelp logo

rakesh-mohanta / secstore.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jas-/crypt.io

0.0 2.0 0.0 110 KB

Encryption enabled browser storage

License: GNU General Public License v3.0

JavaScript 100.00%

secstore.js's Introduction

#secStore.js

Fork me @ https://www.github.com/jas-/secStore.js

##Description: secStore is simple wrapper to handle client storage mechanisms within the browser.

It is named secStore.js because not only will this plug-in assist you in transparent storage & retrieval of client data, but it will optionally provide a layer of security for said data with the use of the SJCL (Stanford Javascript Crypto Libraries).

##Installation: Three methods are available for setup and use; using bower, cloning & manual

###Bower To setup using bower

%> bower install secstore.js

###Clone To setup using git

%> git clone --recursive https://github.com/jas-/secStore.js.git

###Manual Copy the secStore.min.js and the sjcl libraries to your web project and include them like so.

<script src="/path/to/sjcl.js"></script>
<script src="/path/to/secStore.min.js"></script>

##Requirements:

##Features:

  • HTML5 localStorage support
  • HTML5 sessionStorage support
  • Cookie support
  • AES encryption support
  • Quota support (4K for cookies and 5MB for HTML5 mechanisms)

##Options:

  • encrypt: {Boolean} Provide transparent symmetric encryption of saved data
  • data: {Mixed} Object, string, array or booleans of data to be saved
  • key: {String} Unique identifier used as storage key
  • passphrase: {String} User supplied passphrase
  • storage: {String} Storage engine to use; local, session or cookies

##Support: Found a bug? Want a feature added? General feedback or kudos? Please open an issue so I can address it. Thanks!

##Examples: Here are a few examples of use to get you started.

###Default use Saving data...

var storage = new secStore
  , options = {
    encrypt: true,
    data: {
      key: 'some data that is somewhat private'
    }
  };


storage.set(options, function(error, results){
  if err throw err;
  console.log(results);
});

Retrieving data...

var storage = new secStore
  , options = {
    encrypt: true
  };


storage.get(options, function(error, results){
  if err throw err;
  console.log(results);
});

###Storage option Want to use a different storage engine like the HTML5 sessionStorage feature?

var options = {
  encrypt: true,
  storage: 'session',
  data: {
    key: 'some data that is somewhat private'
  }
};

Or some depreciated cookies? This is the least tested option

var options = {
  encrypt: true,
  storage: 'cookies',
  data: {
    key: 'some data that is somewhat private'
  }
};

###Extra security While providing a transparent method of encryption for objects within the client prevents the need for user interaction, in terms of security in the event of a same-origin, dom rebinding attack coupled with a man- in-the-middle scenario it would be more secure to prompt the user for his/her passphrase. Here is an example of user input for the passphrase.

var pass = window.prompt("Please enter password...", "a custom password");

var options = {
  encrypt: true,
  passphrase: pass,
  data: {
    key: 'some data that is somewhat private'
  }
};

###For the paranoid Here is a robust example of saving & retrieving data implementing a user defined password based on their input while also using key stretching techniques to further enhance the security of the key used as well as using a tempoary storage option such as sessionStorage for the current authenticated session. Of course wrapping this around a TLS/SSL connection is recommended.

Saving data (please keep in mind that a static value for the salt is not recommended)

var pass = window.prompt("Enter password to protect saved data", "");

var options = {
  encrypt: true,
  passphrase: sjcl.misc.pbkdf2(pass, "salt", 1000000, 256),
  data: {
    key: 'some data that is somewhat private'
  }
};

##Warning: I feel it is worth noting that while this plugin makes every attempt at providing a secure transparent method of saving & retieving encrypted data based on unique identifiers retrieved from the client browser, it is by no means a replacement for a user specifying their own passphrase. See the 'Extra security' example for this.

For the reasons behind this notice please research MITM ARP poisoning techniques coupled with use of the BeEF injection framework. This attack vector as well as browser plug-ins & JavaScript scriplets can expose the parameters used to create a unique transparent key used by the browser.

While this technique is possible, it is typically a low threat vector due to the technologies & knowledge necessary to exploit.

secstore.js's People

Contributors

jas- avatar

Watchers

Rakesh mohanta avatar  avatar

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.