Code Monkey home page Code Monkey logo

authentication-server's Introduction

authentication-server

Build Status codecov Greenkeeper badge

JWT Authentication server using email, password, captcha and Google Authenticator

Main Features:

Build, test and run

yarn

Generate a keypair:

openssl ecparam -genkey -name secp521r1 -noout -out ec512.prv.pem
openssl ec -in ec512.prv.pem -pubout > ec512.pub.pem

Run tests & lint:

yarn test & yarn lint

Start server:

yarn start

How to use

You can find a client-side library here: authentication-client

Specification

Database Schema

Column Type Description
uuid text UuidV4
email text Email
newEmail text New unconfirmed email
emailToken text Email confirmation token
created timestamp Creation time
updated timestamp Last update time
lastUsed timestamp Last usage time)
kdfSalt blob Key derivation function salt
srpSalt blob SRP salt
srpVerifier blob SRP verifier
totpSecret boob Time bases one time passsword secret (2FA)

Parameters

scrypt

N 16384
r 8
p 1
dkLen 32

The result taken in raw binary form. 256 bit random salt.

SRP-6a

4096-bit Group parameters (RFC5054 §A.5). 256 bit random salts and nonces.

Sign-up

Note: Captcha prevents this from automated detecting user existence

  1. User: generates random 32 byte kdfSalt
  2. User: generates random 32 byte srpSalt
  3. User: key = scrypt(password, kdfSalt)
  4. User: verifier = SRP6A_verifier(email, key, srpSalt)
  5. User calls /api/signup with:
    • email
    • kdfSalt
    • srpSalt
    • verifier
    • captcha
  6. Server validates recaptcha
  7. Server generates totpSecret
  8. Server creates new user with submitted data
  9. Server returns totpSecret

Log-in

  1. User calls /api/login-data with:
    • email
  2. Server responds with:
    • kdfSalt
    • srpSalt
    • serverPublicKey
    • encrypted and authenticated:
      • serverPrivateKey
  3. User calls /api/login with:
    • clientProof
    • clientPublicKey
    • email
    • timeBasedOneTimeToken
    • encrypted and authenticated:
      • serverPrivateKey
  4. Server verifies all the data and checks:
    • the client proof
    • integrity of encrypted part
    • 2FA token
  5. Server issues the JSON Web Token
  6. Server returns:
    • token
    • serverProof
  7. Client verifies server proof

FAQ

Why are passwords so difficult?

  • Because they often have low entropy (like the codes on a suitcase, you can try all options in a few days).

  • Because people use the same password in many places, so even if your site is not important—the same password may access the users bank account.

What's wrong with sending plain password over https?

CA's are unreliable, TLS is too complex/buggy.

What's wrong with sending hash(salt, pwd)?

Does not protect against password brute forcing. An attacker who has the salt and hash can rapidly try combinations.

Why not just Scrypt?

It's a lot better, but an attacker that has the salt and hash can still try passwords without being detected. Just much more slowly.

Why not just SRP-6a?

SRP protects against eavesdroppers, nothing send over the wire will help an attacker.

But now the server stores something that is roughly similar to a salted hash: if an attacker obtains the user database, (s)he can quickly do an brute force.

By using both we make it impossible to attack the password when the TLS leaks and very hard when the user database is leaked.

Why not SMS Verification?

SMS is not secure

Why generate the salt client side

It is in the clients interest to protect itself.

authentication-server's People

Contributors

logvinovleon avatar recmo avatar greenkeeper[bot] avatar

Watchers

 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.