Documentation ¶
Overview ¶
Package httpsign provides tools for signing and authenticating HTTP requests between web services. See README.md for more details.
Index ¶
Constants ¶
const ( XMailgunSignature = "X-Mailgun-Signature" XMailgunSignatureVersion = "X-Mailgun-Signature-Version" XMailgunNonce = "X-Mailgun-Nonce" XMailgunTimestamp = "X-Mailgun-Timestamp" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // KeyPath is a path to a file that contains the key to sign requests. If // it is an empty string then the key should be provided in `KeyBytes`. KeyPath string // KeyBytes is a key that is used by lemma to sign requests. Ignored if // `KeyPath` is not an empty string. KeyBytes []byte HeadersToSign []string // list of headers to sign SignVerbAndURI bool // include the http verb and uri in request NonceCacheCapacity int // capacity of the nonce cache NonceCacheTimeout int // nonce cache timeout EmitStats bool // toggle emitting metrics or not StatsdHost string // hostname of statsd server StatsdPort int // port of statsd server StatsdPrefix string // prefix to prepend to metrics NonceHeaderName string // default: X-Mailgun-Nonce TimestampHeaderName string // default: X-Mailgun-Timestamp SignatureHeaderName string // default: X-Mailgun-Signature SignatureVersionHeaderName string // default: X-Mailgun-Signature-Version }
Modify NonceCacheCapacity and NonceCacheTimeout if your service needs to authenticate more than 5,000 requests per second. For example, if you need to handle 10,000 requests per second and timeout after one minute, you may want to set NonceCacheTimeout to 60 and NonceCacheCapacity to 10000 * cacheTimeout = 600000.
type SeededRNG ¶
type SeededRNG struct { Seed int64 // contains filtered or unexported fields }
SeededRNG returns bytes generated in a predictable sequence by package math/rand. Not cryptographically secure, not thread safe. Changes to Seed after the first call to Bytes or HexDigest will have no effect. The zero value of SeededRNG is ready to use, and will use a seed of 0.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Represents an entity that can be used to sign and authenticate requests.
func New ¶
Return a new Signer. Config can not be nil. If you need control over setting time and random providers, use NewWithProviders.
func (*Signer) SignRequest ¶
Signs a given HTTP request with signature, nonce, and timestamp.
func (*Signer) SignRequestWithKey ¶
Signs a given HTTP request with signature, nonce, and timestamp. Signs the message with the passed in key not the one initialized with.
func (*Signer) VerifyRequest ¶
VerifyRequest checks that an HTTP request was sent by an authorized sender.