Documentation ¶
Index ¶
- Variables
- func BuildSignatureData(req *http.Request, headers []string, created, expires time.Time) ([]byte, error)
- func BuildSignatureString(req *http.Request, headers []string, created, expires time.Time) (string, error)
- func Ed25519Sign(key interface{}, message []byte) ([]byte, error)
- func Ed25519Verify(key interface{}, message, sig []byte) error
- func HMACSign(key []byte, hash crypto.Hash, data []byte) ([]byte, error)
- func HMACVerify(key []byte, hash crypto.Hash, data, sig []byte) error
- func KeyIDFromContext(ctx context.Context) string
- func RSASign(key *rsa.PrivateKey, hash crypto.Hash, data []byte) (signature []byte, err error)
- func RSAVerify(key *rsa.PublicKey, hash crypto.Hash, data, sig []byte) (err error)
- func RequireSignature(h http.Handler, v *Verifier, realm string) (out http.Handler)
- func WithKeyID(ctx context.Context, id string) context.Context
- type Algorithm
- type KeyGetter
- type KeyGetterFunc
- type MemoryKeyStore
- type Params
- type Signer
- func NewEd25519Signer(id string, key crypto.PrivateKey, headers []string) *Signer
- func NewHMACSHA256Signer(id string, key []byte, headers []string) (signer *Signer)
- func NewRSASHA1Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
- func NewRSASHA256Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
- func NewSigner(id string, key interface{}, algo Algorithm, headers []string) (signer *Signer)
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ( // Rand is a hookable reader used as a random byte source. Rand io.Reader = rand.Reader )
Functions ¶
func BuildSignatureData ¶
func BuildSignatureData(req *http.Request, headers []string, created, expires time.Time) ([]byte, error)
BuildSignatureData is a convenience wrapper around BuildSignatureString that returns []byte instead of a string.
func BuildSignatureString ¶
func BuildSignatureString(req *http.Request, headers []string, created, expires time.Time) (string, error)
BuildSignatureString constructs a signature string following section 2.3
func Ed25519Sign ¶
Ed25519Sign signs the message with privateKey and returns a signature.
func Ed25519Verify ¶
Ed25519Verify reports whether sig is a valid signature of message by publicKey.
func HMACVerify ¶
HMACVerify verifies a signed digest of the data hashed using the provided hash and key.
func KeyIDFromContext ¶
KeyIDFromContext returns the request ID from the context. A zero ID is returned if there are no identifers in the current context.
func RequireSignature ¶
RequireSignature is a http middleware that ensure the incoming request have the required signature using verifier v
Types ¶
type Algorithm ¶
type Algorithm interface { Name() string Sign(key interface{}, data []byte) (sig []byte, err error) Verify(key interface{}, data, sig []byte) error }
Algorithm provides methods used to sign/verify signatures.
var Ed25519 Algorithm = ed25519{}
Ed25519 implements Ed25519 Algorithm
var HMACSHA256 Algorithm = hmacSha256{}
HMACSHA256 implements keyed HMAC over SHA256 digests
var RSASHA1 Algorithm = rsaSha1{}
RSASHA1 implements RSA PKCS1v15 signatures over a SHA1 digest
var RSASHA256 Algorithm = rsaSha256{}
RSASHA256 implements RSA PKCS1v15 signatures over a SHA256 digest
type KeyGetter ¶
KeyGetter is an interface used by the verifier to retrieve a key stored by key id.
The following types are supported for the specified algorithms: []byte - HMAC signatures *rsa.PublicKey - RSA signatures *rsa.PrivateKey - RSA signatures
Other types will treated as if no key was returned.
type KeyGetterFunc ¶
KeyGetterFunc is a convenience type for implementing a KeyGetter with a regular function
func (KeyGetterFunc) GetKey ¶
func (fn KeyGetterFunc) GetKey(id string) (interface{}, error)
GetKey calls fn(id)
type MemoryKeyStore ¶
type MemoryKeyStore struct {
// contains filtered or unexported fields
}
MemoryKeyStore is a simple in memory key store that implement the KeyGetter interface
func NewMemoryKeyStore ¶
func NewMemoryKeyStore() *MemoryKeyStore
NewMemoryKeyStore creates a new MemoryKeyStore
func (*MemoryKeyStore) GetKey ¶
func (m *MemoryKeyStore) GetKey(id string) (interface{}, error)
GetKey implements KeyGetter interface
func (*MemoryKeyStore) SetKey ¶
func (m *MemoryKeyStore) SetKey(id string, key interface{})
SetKey link id to a key
type Params ¶
type Params struct { KeyID string Algorithm string Headers []string Signature []byte Created time.Time Expires time.Time }
Params holds the field requires to build the signature string
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer is the type used by HTTP clients to sign their request
func NewEd25519Signer ¶
func NewEd25519Signer(id string, key crypto.PrivateKey, headers []string) *Signer
NewEd25519Signer contructs a signer with the specified key id, Ed25519 key, and headers to sign.
func NewHMACSHA256Signer ¶
NewHMACSHA256Signer contructs a signer with the specified key id, hmac key, and headers to sign.
func NewRSASHA1Signer ¶
func NewRSASHA1Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
NewRSASHA1Signer contructs a signer with the specified key id, rsa private key and headers to sign.
func NewRSASHA256Signer ¶
func NewRSASHA256Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
NewRSASHA256Signer contructs a signer with the specified key id, rsa private key and headers to sign.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier is used by by the HTTP server to verify the incoming HTTP requests
func NewVerifier ¶
NewVerifier creates a new Verifier using kg to get the key mapped to the ID received in the requests
func (*Verifier) RequiredHeaders ¶
RequiredHeaders returns the required header the client have to include in the signature
func (*Verifier) SetRequiredHeaders ¶
SetRequiredHeaders set the list of headers to be included by the client to generate the signature