Documentation ¶
Overview ¶
Package httpsig implements HTTP Signatures according to draft-cavage-http-signatures-08 https://datatracker.ietf.org/doc/draft-cavage-http-signatures/
Index ¶
Constants ¶
const ( DefaultDigestAlgo = digest.SHA256 DefaultHeaderType = SignatureHeader )
These are the default values for TransportOptions
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶ added in v1.1.0
Middleware is an HTTP middleware that will call next only if the request's HTTP signature is valid
func ValidKeyID ¶
ValidKeyID returns true if the keyID doesn't contain any quote (`"`) or comma (`,`) characters
Types ¶
type Algorithm ¶
type Algorithm int
Algorithm represents the type of HTTP signature to use
These are the available Algorithms to use
func ParseAlgorithm ¶
ParseAlgorithm parses a string into an Algorithm
func (Algorithm) Sign ¶
Sign signs the data with the provided key. key is expected to be an rsa.PrivateKey, []byte for HMAC or ecdsa.PrivateKey
func (Algorithm) Transport ¶
func (a Algorithm) Transport(keyID string, key interface{}, opts ...TransportOption) http.RoundTripper
Transport returns an http.RoundTripper that sets HTTP signatures on outgoing requests
type Header ¶
A Header represents the parts of the HTTP signature header
func (*Header) SignatureString ¶
SignatureString returns the string that should be signed for the request. It also populates Header.Headers. If headers has values, only those will be used to produce the string. Otherwise, all headers except Host, User-Agent, Content-Length, Transfer-Encoding and Trailer will be used.
type HeaderType ¶
type HeaderType string
HeaderType dictates which HTTP header to use and the format of the value for generating and verifying HTTP signatures
const ( SignatureHeader HeaderType = "Signature" AuthorizationHeader HeaderType = "Authorization" )
These are the available HeaderTypes to use
func (HeaderType) Parse ¶
func (t HeaderType) Parse(req *http.Request) (*Header, error)
Parse returns a Header populated with the fields extracted from the HTTP signature
func (HeaderType) Set ¶
func (t HeaderType) Set(a Algorithm, keyID string, key interface{}, req *http.Request, digestAlgo digest.Algorithm) error
Set sets the appropriate HTTP header to make an HTTP signature on the request
func (HeaderType) String ¶
func (t HeaderType) String() string
type KeyGetterFunc ¶
The KeyGetterFunc type is an adapter to allow the use of ordinary functions as KeyGetters. If f is a function with the appropriate signature, KeyGetterFunc(f) is a KeyGetter that calls f.
func (KeyGetterFunc) GetKey ¶
func (f KeyGetterFunc) GetKey(keyID string) (key interface{}, err error)
GetKey returns f(keyID)
type TransportOption ¶
type TransportOption func(*transport)
A TransportOption is an option that can be used with Algorithm.Transport
func WithAuthorizationHeader ¶
func WithAuthorizationHeader() TransportOption
WithAuthorizationHeader causes the Transport to use the Authorization header for HTTP signatures instead of the Signature header
func WithDigestAlgorithm ¶
func WithDigestAlgorithm(val digest.Algorithm) TransportOption
WithDigestAlgorithm causes the Transport to use the digest algorithm val when generating HTTP Digest headers
func WithTracer ¶
func WithTracer(tracer opentracing.Tracer) TransportOption
WithTracer sets the tracer to be used by the Transport