Documentation ¶
Overview ¶
Package httpsign provides tools for signing and authenticating HTTP requests between web services. See README.md for more details.
Index ¶
Constants ¶
const CacheCapacity = 5000 * CacheTimeout // 5,000 msg/sec * 100 sec = 500,000 elements
const CacheTimeout = 100 // 100 sec
const MaxSkewSec = 5 // 5 sec
const XMailgunNonce = "X-Mailgun-Nonce"
const XMailgunSignature = "X-Mailgun-Signature"
const XMailgunSignatureVersion = "X-Mailgun-Signature-Version"
const 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 NonceCache ¶
func NewNonceCache ¶
func NewNonceCache(capacity int, cacheTTL int, timeProvider timetools.TimeProvider) (*NonceCache, error)
Return a new NonceCache. Allows you to control cache capacity, ttl, as well as the TimeProvider.
func (*NonceCache) InCache ¶
func (n *NonceCache) InCache(nonce string) bool
InCache checks if a nonce is in the cache. If not, it adds it to the cache and returns false. Otherwise it returns true.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Represents a service that can be used to sign and authenticate requests.
func New ¶
Return a new Service. Config can not be nil. If you need control over setting time and random providers, use NewWithProviders.
func NewWithProviders ¶
func NewWithProviders(config *Config, timeProvider timetools.TimeProvider, randomProvider random.RandomProvider) (*Service, error)
Returns a new Service. Provides control over time and random providers.
func (*Service) AuthenticateRequest ¶
Authenticates HTTP request to ensure it was sent by an authorized sender.
func (*Service) AuthenticateRequestWithKey ¶
Authenticates HTTP request to ensure it was sent by an authorized sender. Checks message signature with the passed in key, not the one initialized with.
func (*Service) SignRequest ¶
Signs a given HTTP request with signature, nonce, and timestamp.