Documentation ¶
Index ¶
- Constants
- Variables
- func GetComponentValue(name string, msg HttpMessage) (string, error)
- func GetQueryParamComponentValue(name string, msg HttpMessage) (string, error)
- type Alg
- type Algorithm
- type Component
- type Created
- type Expires
- type HttpMessage
- type HttpRequest
- func (hr HttpRequest) GetSignature(sigLabel string) (sig SignatureHeaderValue, err error)
- func (hr HttpRequest) GetSignatureInput(sigLabel string) (sigInput SignatureInput, err error)
- func (hr HttpRequest) Header() http.Header
- func (hr HttpRequest) Method() string
- func (hr HttpRequest) SigLabels() []string
- func (hr HttpRequest) Status() int
- func (hr HttpRequest) Url() *url.URL
- type HttpResponse
- type KeyId
- type Nonce
- type SignatureBase
- type SignatureHeaderValue
- type SignatureInput
- type SignatureParameter
- type SignatureParams
- type SignedHttpMessage
- type Tag
Constants ¶
const ( DerivedComponentMethod = "@method" DerivedComponentTargetUri = "@target-uri" DerivedComponentAuthority = "@authority" DerivedComponentScheme = "@scheme" DerivedComponentRequestTarget = "@request-target" DerivedComponentPath = "@path" DerivedComponentQuery = "@query" DerivedComponentQueryParam = "@query-param" DerivedComponentStatus = "@status" ComponentSignatureParams = "@signature-params" )
const ( HeaderContentDigest = "Content-Digest" HeaderSignature = "Signature" HeaderSignatureInput = "Signature-Input" )
const ( SignatureParameterCreated = "created" SignatureParameterExpires = "expired" SignatureParameterNonce = "nonce" SignatureParameterAlg = "alg" SignatureParameterKeyId = "keyid" SignatureParameterTag = "tag" )
Variables ¶
var (
ErrMultipleQueryParamValues = errors.New("multiple query param values")
)
Functions ¶
func GetComponentValue ¶
func GetComponentValue(name string, msg HttpMessage) (string, error)
GetComponentValue returns a component's value. If the name starts with "@" then it is retrieved as a derived component otherwise it is retrieved from the headers.
func GetQueryParamComponentValue ¶
func GetQueryParamComponentValue(name string, msg HttpMessage) (string, error)
GetQueryParamComponentValue returns the value of a "@query-param" derived component. name is expected to have the name of the query parameter, e.g. "@query-param";name="var". TODO: handle url encoded @query-param name
Types ¶
type Algorithm ¶
type Algorithm interface { // The algorithm name which is also the value used // for the alg signature parameter // // https://datatracker.ietf.org/doc/html/rfc9421#name-initial-contents Name() string }
type Created ¶
Created is the created signature parameter which is the unix timestamp in seconds in which the signature was generated. If the value is 0, then the current system time is used as the value.
func CreatedFromString ¶
type Expires ¶
Expires is the expired signature parameter which is the unix timestamp in seconds in which the signature will be expired.
func ExpiredFromString ¶
type HttpMessage ¶
HttpMessage is a wrapper for http.Request or http.Response so we can access common struct fields
type HttpRequest ¶
func (HttpRequest) GetSignature ¶
func (hr HttpRequest) GetSignature(sigLabel string) (sig SignatureHeaderValue, err error)
func (HttpRequest) GetSignatureInput ¶
func (hr HttpRequest) GetSignatureInput(sigLabel string) (sigInput SignatureInput, err error)
func (HttpRequest) Header ¶
func (hr HttpRequest) Header() http.Header
func (HttpRequest) Method ¶
func (hr HttpRequest) Method() string
func (HttpRequest) SigLabels ¶
func (hr HttpRequest) SigLabels() []string
func (HttpRequest) Status ¶
func (hr HttpRequest) Status() int
func (HttpRequest) Url ¶
func (hr HttpRequest) Url() *url.URL
type HttpResponse ¶
func (*HttpResponse) Header ¶
func (hr *HttpResponse) Header() http.Header
func (*HttpResponse) Method ¶
func (hr *HttpResponse) Method() string
func (*HttpResponse) Status ¶
func (hr *HttpResponse) Status() int
func (*HttpResponse) Url ¶
func (hr *HttpResponse) Url() *url.URL
type SignatureBase ¶
type SignatureBase struct { // Keys is a slice of component names // excluding @signature-params. For @query-param, // there can be multiple so the key will have the // query param name // "@query-param";name="var" // "@query-param";name="bar" Keys []string // Lines is a map of component names to // its string value excluding @signature-params Lines map[string]string // SignatureParams is the @signature-params which is always // at the end of the signature base SignatureParams SignatureParams }
func NewSignatureBaseFromRequest ¶
func NewSignatureBaseFromRequest(msg HttpMessage, components []string, sigParams []SignatureParameter) (*SignatureBase, error)
func (*SignatureBase) Marshal ¶
func (sb *SignatureBase) Marshal() (string, error)
type SignatureHeaderValue ¶
type SignatureHeaderValue httpsfv.Dictionary
func NewSignatureHeaderValue ¶
func NewSignatureHeaderValue(sigLabel string, signature []byte) SignatureHeaderValue
func ParseSignatureHeaderValue ¶
func ParseSignatureHeaderValue(s string) (sig SignatureHeaderValue, err error)
func (SignatureHeaderValue) Bytes ¶
func (sig SignatureHeaderValue) Bytes() ([]byte, error)
func (SignatureHeaderValue) Marshal ¶
func (sig SignatureHeaderValue) Marshal() (s string, err error)
type SignatureInput ¶
type SignatureInput httpsfv.Dictionary
signatureInput is a Dictionary Structured Field containing the metadata for one or more message signatures generated from components within the HTTP message.
It is a HTTP header with the key "Signature-Input".
The value is very similar to the value of @signature-params but the component list has a key which is the label for the signature.
Example:
Signature-Input: sig1=("@method" "@target-uri" "@authority" \ "content-digest" "cache-control");\ created=1618884475;keyid="test-key-rsa-pss"
https://datatracker.ietf.org/doc/html/rfc9421#name-the-signature-input-http-fi
func ParseSignatureInput ¶
func ParseSignatureInput(s string) (sigInput SignatureInput, err error)
func SignatureInputFromSignatureParams ¶
func SignatureInputFromSignatureParams(sigLabel string, sp *SignatureParams) *SignatureInput
func (SignatureInput) Components ¶
func (si SignatureInput) Components() []string
func (SignatureInput) Marshal ¶
func (si SignatureInput) Marshal() (string, error)
func (SignatureInput) SigLabel ¶
func (si SignatureInput) SigLabel() string
func (SignatureInput) SignatureParameters ¶
func (si SignatureInput) SignatureParameters() []SignatureParameter
type SignatureParameter ¶
type SignatureParams ¶
@signature-params derived component
https://datatracker.ietf.org/doc/html/rfc9421#name-signature-parameters
func (*SignatureParams) Marshal ¶
func (sp *SignatureParams) Marshal() (string, error)
Marshal serialises the signature params. The result does not include "@signature-params: ".
type SignedHttpMessage ¶
type SignedHttpMessage interface { SigLabels() []string GetSignature(sigLabel string) (SignatureHeaderValue, error) GetSignatureInput(sigLabel string) (SignatureInput, error) }