Coder Social home page Coder Social logo

42loco42 / capka Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 36 KB

Clientside Argon2 Public-Key Authentication

License: GNU Affero General Public License v3.0

Nix 12.44% C 10.57% Go 76.99%
argon2 argon2id caddy-plugin echo-middleware go golang public-key-cryptography

capka's Introduction

Clientside Argon2 Public-Key Authencation

An interesting way of enabling asymmetric cryptography without having to carry around certificate or key files.

The basic protocol (v0)

  1. the client obtains a username & password, e.g. via a login form
  2. from these, it computes a master keypair using the argon2id algorithm:
    // inputs
    username := "alice"
    password := "hunter2"
    domain := "example.org"
    
    // standard values, set by the crypto library
    SEEDBYTES := 32 // required by sign_seed_kp
    SALTBYTES := 16 // required by argon2id
    OPSLIMIT_INTERACTIVE := 2
    MEMLIMIT_INTERACTIVE := 67108864 // 64 MiB
    
    seed := argon2id(
        SEEDBYTES, // output length
        password,
        hash(SALTBYTES, username+domain), // salt
        OPSLIMIT_INTERACTIVE,
        MEMLIMIT_INTERACTIVE,
    )
    kp := sign_seed_kp(seed)
        
  3. server: exposes a /capka/login endpoint
    • client: GETs the endpoint:
    • this returns a “nonce” (can be any random string)
    • server keeps all nones in an “active” cache for a short amount of time (e.g. 5 seconds)
  4. the client POSTs to the same endpoint the following structure:
    {
        "user": "<the given username>",
        "nonce": "<nonce returned by GET /capka/login>",
        "signature": "<nonce signed with the master keypair>"
    }
        
  5. the server then validates both the nonce (is it still in the active cache?) and the signature (user’s public keys are stored in the server DB)

Extension: secure username (v1)

In step 4, the signature is computed on user+nonce instead of just the nonce.

Extension: simple encrypted return (v2)

In step 5, if the server wants to return some kind of session identifier, it encrypts it to the client’s public key instead of sending it in plaintext.

Extension: ephemeral encrypted return (v3)

The previous extension misuses the client’s keypair by assigning it two functions: signature verification and data encryption. Instead, the following changes are made:

  • in step 2, the client also creates a random, ephemeral keypair
  • in step 4, the public key of that keypair is added to the structure (field ephkey) and the signature is now computed over all three values (user, nonce, ephkey)
  • in step 5, the server encrypts the session ID to the ephemeral pubkey instead of the client master pubkey

This version of the protocol should be completely secure even on untrusted (not HTTPS) channels (of course the client can’t trust the server under those circumstances).

Attackers can’t replace any message or component without triggering some kind of validation error on the server. And since nonces don’t carry intrinsic ownership information, even a complete replacement of the nonce with another valid one doesn’t give the attacker any way of injecting their own user or obtaining the session ID.

Implementation goals

capka's People

Contributors

42loco42 avatar

Stargazers

 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.