Giter Club home page Giter Club logo

tyk-mashery-auth's Introduction

Mashery Signature Validator

Tyk gRPC plugin written in GoLang to handle Mashery X-Signature validation.

CLI

tyk-mashery-auth --help
Usage of tyk-mashery-auth:
  -debug
        enable debug mode
  -header_auth string
        header location to look for auth token (default "Api-Key")
  -header_signature string
        header location to look for signature (default "X-Signature")
  -listen string
        listen address e.g. :9000 | /tmp/foo.sock (default ":9000")
  -network string
        network mode e.g. tcp | unix (default "tcp")
  -secret string
        shared secret (default "4321knj8fqgm5ffq64tdzifato6fb5p5rkqze933ehivqelctivti8qs0xnzmpq3")
  -skew int
        allowed clock skew in seconds (default 300)
  -token string
        token used for generating debug logs (default "foo")

Download the src & install:

go get -u github.com/asoorm/tyk-mashery-auth

Examples:

# defaults
tyk-mashery-auth

# grpc listen on tcp://0.0.0.0:9001
tyk-mashery-auth --network tcp --listen :9001

# grpc listen on unix socket
tyk-mashery-auth --network unix --listen /tmp/foo.sock

# shared secret `mysharedsecret`
tyk-mashery-auth --secret mysharedsecret

# turn on debug mode
tyk-mashery-auth --debug

# set the allowed clock-skew to +/- 10 minutes
tyk-mashery-auth --skew 600

# override the default authorization header key & auth signature header keys
tyk-mashery-auth --header_auth Api-Key --header_signature X-My-Signature

Configure Tyk API to use the gRPC signature validator as a pre plugin:

Modify the api definition custom_middleware.driver to specify grpc Modify the api definition custom_middleware.pre[] array to include the ValidateSignature hook

{
  "custom_middleware": {
    "post_key_auth": [
      {
        "name": "ValidateSignature"
      }
    ],
    "driver": "grpc"
  }
}

Save the API definition and when you send API requests via the gateway, the gateway will pass responsibility for validating the signature to the tyk-mashery-auth plugin.

curl http://localhost:8080/sha/get \
  -H 'Api-Key: foo' \
  -H 'X-Signature: e08f7ab275ad200f041d5af0ba6bb51525905899b2bdf1825c9ea5d578ca1161'

tyk-mashery-auth's People

Contributors

asoorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tyk-mashery-auth's Issues

perf: js plugin should start from now and work out to max clock skew

  for (var i = now - ALLOWED_CLOCK_SKEW; i <= now + ALLOWED_CLOCK_SKEW; i ++) {

    var raw = token + SHARED_SECRET + i;

    var shaObj = new jsSHA("SHA-256", "TEXT");
    shaObj.update(raw);
    var hash = shaObj.getHash("HEX");

    if (hash === signature) {
      return preBodyToHeaders.ReturnData(req, sess.meta_data);
    }
  }

Current implementation checks from now - ALLOWED_CLOCK_SKEW to now + ALLOWED_CLOCK_SKEW.

More appropriate would be to check from now, and work out to avoid needless hash checking.

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.