Giter VIP home page Giter VIP logo

hardlock's Introduction

HardLock

HardLock is a proof-of-work system to force both malicious users and legitimate users to calculate a piece of information with the property that it is hard to calculate but easy to verify. HardLock uses hash collisions and the generalized birthday problem to provide this property. It takes a hash of a salt and a challenge value supplied by the server plus nonces supplied by the client. The client must find a pair of nonces that results in a hash collision. Hash length is set to an unusually small value in order to make hash collisions possible in the expected time period. Each increase in difficulty factor is substantially more difficult than the previous value. This could be made more fine-grained by looking for hash collision prefixes at the bit level. I was too lazy to bother, but I might pursue it if the technique proves effective as-is. A good difficulty factor for typical usage is 4 or 5. You could increase it to 6 in case of an active attack with some limited impact to legitimate clients on slower hardware.

HardLock is a proof-of-concept and probably should not be used in production. I'm not even sure if it will really prevent the types of attacks it's intended for. I've only tested it on a Nexus 5X and in Chrome and NodeJS on a late 2013 Macbook Pro. For all I know, it'll set older mobile devices on fire... you've been warned.

Obviously, it also requires JavaScript to be enabled on the client, which may or may not be an acceptable trade-off.

Demo

npm install -g serve
serve

Navigate to http://localhost:3000/

NOTE: If you open index.html directly via file://, you will not be able to use Web Workers for background computation and the browser may become unresponsive. It will, however, otherwise work as intended.

Usage

Client-side Work

// The filename is needed to run the compute-heavy algorithm as a web worker.
// This means that the hardlock.min.js must not be concatenated with other JS
// files during any kind of asset pipeline process you may be using.
// You can omit the parameter, but it may result in the browser UI becoming
// unresponsive.
var hl = new HardLock(5, 'testsalt', 'challengevaluegoesherelikecsrf', './dist/hardlock.min.js');
hl.work().then(function (results) {
  // Nonces are encoded into base64.
  document.getElementById('nonces').value = results.encoded;
}).catch(function (error) {
  // WARNING: The user will not be able to successfully submit the form if this
  // happens. You should notify the user as appropriate and probably log this
  // whereever you track client-side errors.
  console.error(error);
})

Server-side Verification

var hl = new HardLock(5, 'testsalt', 'challengevaluegoesherelikecsrf');
var nonces = req.body.nonces;
var verified = hl.verify(nonces);

hardlock's People

Contributors

sporkmonger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.