hmac

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Go

caddy-hmac

This is different than abiosoft/caddy-hmac! This implements a caddy hmac handler.

Installation

xcaddy build v2.0.0 \
    --with github.com/apccurtiss/caddy-hmac

Usage

hmac computes the hash of the input as a {hmac.signature} placeholder for other matchers and handlers.

Caddyfile
hmac [<name>] <algorithm> <secret>
  • name - [optional] if set, names the signature and available as {hmac.name.signature}.
  • algorithm - hash algorithm to use. Can be one of sha1, sha256, md5.
  • plaintext - the plaintext hmac input.
  • secret - the hmac secret key.
Example

Run a command after validating a Github webhook secured with a secret.

@github {
    path /webhook
    header_regexp X-Hub-Signature "([a-z0-9]+)\=([a-z0-9]+)"
}
@hmac {
    expression {hmac.signature} == {http.regexp.2}
}
route @github {
    hmac sha1 {http.regexp.1} {$GITHUB_WEBHOOK_SECRET}
    exec @hmac git pull origin master
}
JSON

hmac can be part of any route as an handler

{
  ...
  "routes": [
    {
      "handle": [
        {
          // required to indicate the handler
          "handler": "hmac",
          // [optional] if set, names the sigurature to be referenced
          // as {hmac.name.signature}.
          "name": "",
          // the algorithm to use. can be sha1, sha256, md5
          "algorithm": "sha1",
          "plaintext": "some_plaintext",
          // hmac secret
          "secret": "some secrets"
        }
      ]
    },
    ...
  ]
  ...
}

License

Apache 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HMAC

type HMAC struct {
	Algorithm string `json:"algorithm,omitempty"`
	Plaintext string `json:"plaintext,omitempty"`
	Secret    string `json:"secret,omitempty"`
	Name      string `json:"name,omitempty"`
	// contains filtered or unexported fields
}

HMAC implements an HTTP handler that validates request body with hmac.

func (HMAC) CaddyModule

func (HMAC) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*HMAC) Provision

func (m *HMAC) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (HMAC) ServeHTTP

func (m HMAC) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*HMAC) UnmarshalCaddyfile

func (m *HMAC) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

hmac [<name>] <algorithm> <secret>

func (HMAC) Validate

func (m HMAC) Validate() error

Validate implements caddy.Validator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL