Documentation
¶
Index ¶
- Variables
- func WithComponents(identifiers ...string) componentsOption
- func WithContentDigestAlgorithmPreferences(prefs ...AlgorithmPreference) contentDigestAlgorithmPreferencesOption
- func WithCreatedTimestamp(flag bool) createdTimestampOption
- func WithExpiresTimestamp(flag bool) expiredTimestampOption
- func WithForbiddenParameters(names ...SignatureParameter) forbiddenParametersOption
- func WithKeyID(keyID string) keyIDOption
- func WithLabel(label string) labelOption
- func WithNonceGetter(ng NonceGetter) nonceGetterOption
- func WithParameter(name SignatureParameter, value any) parameterOption
- func WithRequiredParameters(names ...SignatureParameter) requiredParametersOption
- func WithSignatureAlgorithm(alg SignatureAlgorithm) signatureAlgorithmOption
- func WithTag(tag string) tagOption
- type AcceptSignatureBuildOption
- type AcceptSignatureBuilder
- type AcceptSignatureOption
- type AlgorithmPreference
- type DigestAlgorithm
- type DisplayString
- type Key
- type KeyInfo
- type KeyResolver
- type Message
- type MessageSigner
- type MessageVerifier
- type NoApplicableSignatureError
- type NonceGetter
- type NonceGetterFunc
- type SignOption
- type SignatureAlgorithm
- type SignatureInfo
- type SignatureNegotiationOption
- type SignatureParameter
- type SignatureParameters
- func (p SignatureParameters) Alg() (SignatureAlgorithm, bool)
- func (p SignatureParameters) Created() (int64, bool)
- func (p SignatureParameters) Expires() (int64, bool)
- func (p SignatureParameters) KeyID() (string, bool)
- func (p SignatureParameters) Nonce() (string, bool)
- func (p SignatureParameters) Tag() (string, bool)
- type SignatureRequest
- type Signer
- type SignerOption
- type Token
- type VerificationResult
- type VerifiedSignature
- type Verifier
- type VerifierOption
- func WithMaxAge(age time.Duration) VerifierOption
- func WithRequiredTag(tag string, opts ...VerifierOption) VerifierOption
- func WithSignatureNegotiation(opts ...SignatureNegotiationOption) VerifierOption
- func WithValidateAllSignatures() VerifierOption
- func WithValidityTolerance(tolerance time.Duration) VerifierOption
- func WithoutMaxAge() VerifierOption
- type VerifyOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedKeyType indicates that the supplied key material has an unsupported Go type. ErrUnsupportedKeyType = errors.New("unsupported key type/format") // ErrUnsupportedAlgorithm indicates that the requested signature or digest algorithm is unsupported. ErrUnsupportedAlgorithm = errors.New("unknown/unsupported algorithm") // ErrInvalidKeySize indicates that a key has an incompatible size or curve for its algorithm. ErrInvalidKeySize = errors.New("invalid key size") // ErrNoKeyProvided indicates that required key material was not supplied. ErrNoKeyProvided = errors.New("no key provided") // ErrInvalidSignature indicates that cryptographic signature verification failed. ErrInvalidSignature = errors.New("invalid signature") // ErrVerificationFailed indicates that verifying the selected signatures failed; it wraps the underlying error. ErrVerificationFailed = errors.New("verification failed") // ErrContentDigestMismatch indicates that a covered Content-Digest does not match the message body. ErrContentDigestMismatch = errors.New("content digest mismatch") // ErrMalformedData indicates malformed signature or other structured HTTP message data. ErrMalformedData = errors.New("malformed data") // ErrUnsupportedComponentIdentifier indicates that a covered component identifier is unsupported. ErrUnsupportedComponentIdentifier = errors.New("unsupported component identifier") // ErrInvalidComponentIdentifier indicates a malformed component identifier or invalid component parameters. ErrInvalidComponentIdentifier = errors.New("invalid component identifier") // ErrCanonicalization indicates that a covered HTTP message component could not be canonicalized. ErrCanonicalization = errors.New("failed to canonicalize component") // ErrMalformedSignatureParameter indicates a signature parameter with an invalid type or value. ErrMalformedSignatureParameter = errors.New("malformed signature parameter") // ErrNoApplicableDigestFound indicates that no supported digest could be checked in Content-Digest. ErrNoApplicableDigestFound = errors.New("no applicable digest found") // ErrVerifierCreation indicates that the verifier configuration could not be constructed. ErrVerifierCreation = errors.New("verifier creation failed") // ErrParameter indicates a failed signature parameter check or invalid option. ErrParameter = errors.New("parameter error") // ErrValidity indicates that a signature failed its time validity checks. ErrValidity = errors.New("validity error") // ErrMissingParameter indicates that a required signature parameter or covered component is missing. ErrMissingParameter = errors.New("missing parameter error") // ErrSignatureNegotiationError indicates a failure while preparing signature negotiation. ErrSignatureNegotiationError = errors.New("signature negotiation error") )
Functions ¶
func WithComponents ¶
func WithComponents(identifiers ...string) componentsOption
WithComponents specifies component identifiers to cover when signing, require during verification, or request in Accept-Signature. Each identifier must be a serialized Structured Fields String Item, such as `"@method"` or `"content-digest";req`. For `@query-param`, the `name` component parameter must contain the canonical percent-encoded parameter name. For example, use `"@query-param";name="x%2By"` for a query parameter named `x+y`; a literal `+` in `name` is rejected.
func WithContentDigestAlgorithmPreferences ¶
func WithContentDigestAlgorithmPreferences(prefs ...AlgorithmPreference) contentDigestAlgorithmPreferencesOption
WithContentDigestAlgorithmPreferences specifies the algorithms and preferences to request in Want-Content-Digest.
func WithCreatedTimestamp ¶ added in v0.10.0
func WithCreatedTimestamp(flag bool) createdTimestampOption
WithCreatedTimestamp specifies whether the created parameter is required during verification or requested in Accept-Signature. False makes it optional during verification and omits it from Accept-Signature.
func WithExpiresTimestamp ¶ added in v0.10.0
func WithExpiresTimestamp(flag bool) expiredTimestampOption
WithExpiresTimestamp specifies whether the expires parameter is required during verification or requested in Accept-Signature. False makes it optional during verification and omits it from Accept-Signature.
func WithForbiddenParameters ¶ added in v0.10.0
func WithForbiddenParameters(names ...SignatureParameter) forbiddenParametersOption
WithForbiddenParameters rejects signatures containing any named parameter.
func WithKeyID ¶ added in v0.10.0
func WithKeyID(keyID string) keyIDOption
WithKeyID specifies the keyid parameter for signing or Accept-Signature. An empty value is ignored when signing and omitted from Accept-Signature.
func WithLabel ¶
func WithLabel(label string) labelOption
WithLabel specifies the technical label for a signature or an Accept-Signature request. An empty label leaves the current label unchanged.
func WithNonceGetter ¶ added in v0.10.0
func WithNonceGetter(ng NonceGetter) nonceGetterOption
WithNonceGetter configures a nonce source for Accept-Signature, including verifier-based negotiation. A nil getter leaves the source unchanged.
func WithParameter ¶ added in v0.10.0
func WithParameter(name SignatureParameter, value any) parameterOption
WithParameter specifies an extension parameter for signing, verifying, or requesting a signature, either statically or for a single call. It can also be used in WithSignatureNegotiation. Extension values may be string, Token, DisplayString, time.Time (RFC 9651 Date), bool, int, int64, float64, or []byte. DisplayString must contain valid UTF-8, and Date values are transmitted with second precision. Standard RFC 9421 parameter names are reserved, except for a non-empty string nonce on Verify, Sign, or AcceptSignatureBuilder.Build. Verification requirements are additive; an invocation cannot override static requirements. Duplicate signing or builder parameters are rejected.
func WithRequiredParameters ¶ added in v0.10.0
func WithRequiredParameters(names ...SignatureParameter) requiredParametersOption
WithRequiredParameters requires the named signature parameters to be present. It does not check their application-specific semantics.
func WithSignatureAlgorithm ¶ added in v0.10.0
func WithSignatureAlgorithm(alg SignatureAlgorithm) signatureAlgorithmOption
WithSignatureAlgorithm specifies an alg parameter to request in Accept-Signature. It does not select a signing algorithm.
Types ¶
type AcceptSignatureBuildOption ¶ added in v0.10.0
type AcceptSignatureBuildOption interface {
// contains filtered or unexported methods
}
AcceptSignatureBuildOption configures a single AcceptSignatureBuilder.Build call.
type AcceptSignatureBuilder ¶
type AcceptSignatureBuilder struct {
// contains filtered or unexported fields
}
AcceptSignatureBuilder constructs an Accept-Signature request from the configured parameters and component requirements. Use NewAcceptSignature to create a builder with defaults, then call Build to add headers.
func NewAcceptSignature ¶
func NewAcceptSignature(opts ...AcceptSignatureOption) (*AcceptSignatureBuilder, error)
NewAcceptSignature creates an AcceptSignatureBuilder for requesting a signature from a peer. By default, it uses label "sig", requests created and expires parameters, and does not request a nonce. If Content-Digest is requested, the default digest preferences are SHA-256 and SHA-512.
func (*AcceptSignatureBuilder) Build ¶
func (asb *AcceptSignatureBuilder) Build( ctx context.Context, header http.Header, opts ...AcceptSignatureBuildOption, ) error
Build appends an Accept-Signature header to header using the configured signature requirements. If Content-Digest is requested, it also appends Want-Content-Digest preferences. Additional extension parameters can be supplied with WithParameter. A non-empty nonce may be provided for this call with WithParameter("nonce", value), overriding a configured WithNonceGetter without invoking it. Otherwise, the configured getter is used if present; if neither is provided, no nonce is requested. Options do not modify the builder. The caller must provide a writable, non-nil http.Header.
type AcceptSignatureOption ¶
type AcceptSignatureOption interface {
// contains filtered or unexported methods
}
AcceptSignatureOption configures an AcceptSignatureBuilder.
type AlgorithmPreference ¶
type AlgorithmPreference struct {
// Algorithm is the desired digest algorithm.
Algorithm DigestAlgorithm
// Preference is the preference value serialized alongside the algorithm.
Preference int
}
AlgorithmPreference associates a Content-Digest algorithm with a numeric preference value for the Want-Content-Digest header.
func (AlgorithmPreference) String ¶
func (p AlgorithmPreference) String() string
String formats the preference as "algorithm=preference".
type DigestAlgorithm ¶
type DigestAlgorithm string
DigestAlgorithm identifies a hash algorithm supported for HTTP Content-Digest generation and verification.
const ( // Sha256 selects SHA-256. Sha256 DigestAlgorithm = "sha-256" // Sha512 selects SHA-512. Sha512 DigestAlgorithm = "sha-512" )
type DisplayString ¶ added in v0.12.0
type DisplayString string
DisplayString represents an RFC 9651 Structured Fields Display String. Unlike an ordinary Structured Fields string, it may contain Unicode.
type Key ¶
type Key struct {
// Algorithm is the signature algorithm to use with Material.
// It must be compatible with the supplied key material.
Algorithm SignatureAlgorithm
// Material is the private, public, or symmetric key material used by the
// chosen algorithm. The built-in implementations accept the
// corresponding Go crypto key types or []byte for HMAC. Applications
// may also provide a MessageSigner or MessageVerifier implementation.
Material any
}
Key combines cryptographic key material with the concrete signature algorithm to use. Signing requires private or symmetric key material (or a signer interface); verification requires public or symmetric key material (or a verifier interface).
func (Key) ResolveKey ¶
ResolveKey makes a statically configured Key usable as a KeyResolver.
type KeyInfo ¶ added in v0.10.0
type KeyInfo struct {
// Key is the trusted key and algorithm selected for this signature.
Key Key
// Metadata is application-specific information returned alongside the key.
// It is passed through to VerifiedSignature only on successful verification.
Metadata any
}
KeyInfo is returned by a KeyResolver and contains the accepted verification key and optional application-defined information about its resolution.
type KeyResolver ¶
type KeyResolver interface {
// ResolveKey returns the trusted key and optional metadata for info.
// It is called before cryptographic verification. SignatureInfo and its
// Message contain unverified, sender-controlled data. The implementation
// must not mutate SignatureInfo.Message, Components, Parameters, or their
// mutable contents: these are shared with the verification process and, on
// success, with VerifiedSignature.
ResolveKey(ctx context.Context, info SignatureInfo) (KeyInfo, error)
}
KeyResolver resolves a trusted verification key for a specific HTTP message signature.
type Message ¶
type Message struct {
// Context is passed to key resolution and Accept-Signature nonce generation.
Context context.Context //nolint: containedctx
// Method is the associated HTTP request method.
Method string
// Authority is the authority (host and optional port) of the request.
Authority string
// URL is the associated HTTP request URL.
URL *url.URL
// Header contains the headers of the request or response being processed.
// The signer may update this map with signatures and a Content-Digest.
Header http.Header
// Body opens the body of the request or response being processed.
Body func() (io.ReadCloser, error)
// RequestHeader contains the associated request headers for a response.
RequestHeader http.Header
// RequestBody opens the associated request body for response ;req components.
RequestBody func() (io.ReadCloser, error)
// StatusCode is the HTTP response status code (unused for requests).
StatusCode int
// IsRequest distinguishes requests from responses for canonicalization.
IsRequest bool
// contains filtered or unexported fields
}
Message represents the HTTP request or response data needed to construct and verify an HTTP message signature. For a response, request-related fields supply data used by component identifiers with the ;req parameter. Not every field is necessarily covered by the signature. Message data must remain stable after it is prepared for signing or verification, apart from headers added by signing. A Message must not be copied after its first use.
func MessageForResponse ¶
func MessageForResponse(req *http.Request, respHeader http.Header, body []byte, respCode int) *Message
MessageForResponse creates a Message for signing a response to req. It clones the response and request headers and makes the supplied body available for Content-Digest and other covered components. The request body may be buffered and restored when a ;req component requires it.
func MessageFromRequest ¶
MessageFromRequest creates a Message for signing or verifying an HTTP request. Request headers are cloned. If the body must be read and req.GetBody is unavailable, the original body is buffered and replaced so it remains readable. Callers must enforce size limits for untrusted request bodies.
func MessageFromResponse ¶
MessageFromResponse creates a Message from a received HTTP response and its associated request. Response and request headers are cloned. The response body may be buffered and restored when a covered component needs it. The request body is available for ;req components only when the associated request has a GetBody function.
type MessageSigner ¶ added in v0.11.0
MessageSigner signs the complete HTTP signature base using an application-provided implementation. The implementation is responsible for all cryptographic processing and must return signature bytes in the format required by the selected HTTP Message Signatures algorithm. Context is supplied by the message being signed.
type MessageVerifier ¶ added in v0.11.0
type MessageVerifier interface {
VerifyMessage(ctx context.Context, message, signature []byte) error
}
MessageVerifier verifies the complete HTTP signature base using an application-provided implementation. The signature bytes are passed through unchanged; the implementation is responsible for the algorithm and encoding. Context is supplied by the message being verified.
type NoApplicableSignatureError ¶
type NoApplicableSignatureError struct {
// contains filtered or unexported fields
}
NoApplicableSignatureError indicates that a message does not contain all required signatures or any signature selected by the verifier. If signature negotiation was configured, Negotiate can add the requested headers to a response. It can be recognized with errors.As or errors.Is.
func (*NoApplicableSignatureError) Error ¶
func (e *NoApplicableSignatureError) Error() string
Error returns a description of the missing applicable signature.
func (*NoApplicableSignatureError) Is ¶
func (e *NoApplicableSignatureError) Is(err error) bool
Is matches another NoApplicableSignatureError for use with errors.Is.
func (*NoApplicableSignatureError) Negotiate ¶
func (e *NoApplicableSignatureError) Negotiate(header http.Header)
Negotiate appends any prepared Accept-Signature and related negotiation headers to header. If no negotiation was configured, it adds nothing. The caller must supply a writable, non-nil http.Header.
type NonceGetter ¶
type NonceGetter interface {
// GetNonce returns a nonce or an error for the given context.
GetNonce(ctx context.Context) (string, error)
}
NonceGetter supplies a nonce for an Accept-Signature request. An empty result omits the nonce parameter. Generating and correlating nonce values is the responsibility of the calling application.
type NonceGetterFunc ¶
NonceGetterFunc adapts a function to the NonceGetter interface.
type SignOption ¶ added in v0.10.0
type SignOption interface {
// contains filtered or unexported methods
}
SignOption configures a single Sign call.
type SignatureAlgorithm ¶
type SignatureAlgorithm string
SignatureAlgorithm identifies the concrete cryptographic algorithm used to create or verify an HTTP message signature. The constants below are supported by the built-in implementations. Other algorithms can be used with an application-provided MessageSigner or MessageVerifier. The selected algorithm must be compatible with the supplied Key.Material.
const ( // RsaPkcs1v15Sha256 selects RSA PKCS#1 v1.5 with SHA-256. RsaPkcs1v15Sha256 SignatureAlgorithm = "rsa-v1_5-sha256" // RsaPkcs1v15Sha384 selects RSA PKCS#1 v1.5 with SHA-384. RsaPkcs1v15Sha384 SignatureAlgorithm = "rsa-v1_5-sha384" // RsaPkcs1v15Sha512 selects RSA PKCS#1 v1.5 with SHA-512. RsaPkcs1v15Sha512 SignatureAlgorithm = "rsa-v1_5-sha512" // RsaPssSha256 selects RSA-PSS with SHA-256. RsaPssSha256 SignatureAlgorithm = "rsa-pss-sha256" // RsaPssSha384 selects RSA-PSS with SHA-384. RsaPssSha384 SignatureAlgorithm = "rsa-pss-sha384" // RsaPssSha512 selects RSA-PSS with SHA-512. RsaPssSha512 SignatureAlgorithm = "rsa-pss-sha512" // EcdsaP256Sha256 selects ECDSA using P-256 and SHA-256. EcdsaP256Sha256 SignatureAlgorithm = "ecdsa-p256-sha256" // EcdsaP384Sha384 selects ECDSA using P-384 and SHA-384. EcdsaP384Sha384 SignatureAlgorithm = "ecdsa-p384-sha384" // EcdsaP521Sha512 selects ECDSA using P-521 and SHA-512. EcdsaP521Sha512 SignatureAlgorithm = "ecdsa-p521-sha512" // Ed25519 selects Ed25519 signatures. Ed25519 SignatureAlgorithm = "ed25519" // HmacSha256 selects HMAC with SHA-256. HmacSha256 SignatureAlgorithm = "hmac-sha256" // HmacSha384 selects HMAC with SHA-384. HmacSha384 SignatureAlgorithm = "hmac-sha384" // HmacSha512 selects HMAC with SHA-512. HmacSha512 SignatureAlgorithm = "hmac-sha512" )
type SignatureInfo ¶ added in v0.10.0
type SignatureInfo struct {
// Label is the current Signature-Input dictionary member name. It is not
// signed and can be changed by intermediaries; it is only a technical
// reference.
Label string
// Message is the HTTP message being verified. Not all of its fields are
// necessarily covered by the signature, and it must not be modified.
Message *Message
// Components maps covered component identifiers to the canonicalized
// values used to construct the signature base. Map keys are serialized
// Structured Fields String Items (e.g. `"@method"` or `"content-digest";req`),
// including identifier parameters. It excludes the synthetic
// @signature-params component.
Components map[string]string
// Parameters contains the transmitted, decoded signature parameters.
Parameters SignatureParameters
}
SignatureInfo describes one signature being considered for verification. All its values are unverified and may be sender-controlled. The resolver implementation must treat them as untrusted input when selecting key material. The message and maps are shared with the verification process and must not be modified by the resolver (including mutable values within the maps).
type SignatureNegotiationOption ¶
type SignatureNegotiationOption interface {
// contains filtered or unexported methods
}
SignatureNegotiationOption configures requests additional to the verifier's signature requirements.
type SignatureParameter ¶
type SignatureParameter string
SignatureParameter names an RFC 9421 signature parameter or a profile-specific extension parameter.
const ( // KeyID names the keyid signature parameter. KeyID SignatureParameter = "keyid" // Alg names the alg signature parameter. Alg SignatureParameter = "alg" // Created names the created timestamp parameter. Created SignatureParameter = "created" // Expires names the expires timestamp parameter. Expires SignatureParameter = "expires" // Nonce names the nonce signature parameter. Nonce SignatureParameter = "nonce" // Tag names the tag signature parameter. Tag SignatureParameter = "tag" )
type SignatureParameters ¶ added in v0.10.0
type SignatureParameters map[SignatureParameter]any
SignatureParameters contains all signature parameters transmitted in a Signature-Input entry, including profile-specific extensions. Keys are the parameter names; values are decoded Structured Fields bare items (for example string, Token, DisplayString, time.Time, int64, float64, bool, or []byte).
func (SignatureParameters) Alg ¶ added in v0.10.0
func (p SignatureParameters) Alg() (SignatureAlgorithm, bool)
Alg returns the alg parameter if present and of the expected type.
func (SignatureParameters) Created ¶ added in v0.10.0
func (p SignatureParameters) Created() (int64, bool)
Created returns the created parameter as a Unix timestamp if it has the expected type.
func (SignatureParameters) Expires ¶ added in v0.10.0
func (p SignatureParameters) Expires() (int64, bool)
Expires returns the expires parameter as a Unix timestamp if it has the expected type.
func (SignatureParameters) KeyID ¶ added in v0.10.0
func (p SignatureParameters) KeyID() (string, bool)
KeyID returns the keyid parameter if present and of the expected type.
func (SignatureParameters) Nonce ¶ added in v0.10.0
func (p SignatureParameters) Nonce() (string, bool)
Nonce returns the nonce parameter if present and of the expected type.
func (SignatureParameters) Tag ¶ added in v0.10.0
func (p SignatureParameters) Tag() (string, bool)
Tag returns the tag parameter if present and of the expected type.
type SignatureRequest ¶ added in v0.11.0
type SignatureRequest struct {
// Label is the label of the requested signature.
Label string
// Components lists the requested component identifiers in their requested
// order, serialized as Structured Fields Items. Each identifier can be
// passed to WithComponents.
Components []string
// KeyID is the requested keyid parameter. It is empty if not requested.
KeyID string
// Algorithm is the requested alg parameter. It is empty if not requested.
// It is not checked against the supported signature algorithms.
Algorithm SignatureAlgorithm
// Tag is the requested tag parameter. It is empty if not requested.
Tag string
// Nonce is the requested nonce parameter. It is empty if not requested.
Nonce string
// Created reports whether a created timestamp is requested.
Created bool
// Expires reports whether an expires timestamp is requested.
Expires bool
// Extensions contains the requested parameters not defined by RFC 9421.
// It is nil if there are none. Its values are decoded as described for
// SignatureParameters.
Extensions SignatureParameters
}
SignatureRequest describes a single signature requested by a member of an Accept-Signature field. All its values are controlled by the peer. The application must decide whether a request is acceptable before signing.
func ParseAcceptSignature ¶ added in v0.11.0
func ParseAcceptSignature(header http.Header) ([]SignatureRequest, error)
ParseAcceptSignature parses the Accept-Signature fields in header and returns the signature requests in the order they appear. It returns an empty result if header contains no Accept-Signature field.
If the fields as a whole are not a valid Structured Fields Dictionary, it returns no requests and an error wrapping ErrMalformedData. A member that cannot be used, for example because it is malformed or names an unsupported component, does not affect the other members: the requests of the usable members are returned together with a joined error that has an entry wrapping ErrMalformedData for each unusable member. RFC 9421 permits ignoring requests that cannot be fulfilled, so a non-nil error does not invalidate the returned requests. Applications requiring all requests to be usable must check it.
type Signer ¶
type Signer interface {
// Sign signs msg and returns its updated HTTP headers, including the
// Signature and Signature-Input fields. It also updates msg.Header and
// may update Content-Digest when that component is covered.
// Options apply only to this invocation and do not modify the Signer.
Sign(msg *Message, opts ...SignOption) (http.Header, error)
}
Signer creates HTTP message signatures using a configured key, set of covered components, and signature parameters.
func NewSigner ¶
func NewSigner(key Key, opts ...SignerOption) (Signer, error)
NewSigner creates a Signer using key for cryptographic signing. The key must contain compatible private, symmetric, or application-provided signing material. By default, signatures use label "sig", include created, and expire after 30 seconds. The alg, keyid, tag, and nonce parameters are omitted. When generating Content-Digest, the signer uses both SHA-256 and SHA-512 unless WithContentDigestAlgorithm selects one.
type SignerOption ¶
type SignerOption interface {
// contains filtered or unexported methods
}
SignerOption configures the signing policy of a Signer.
func WithAlg ¶ added in v0.10.0
func WithAlg() SignerOption
WithAlg includes the selected Key.Algorithm as the alg signature parameter. It does not select or change the signing algorithm.
func WithContentDigestAlgorithm ¶
func WithContentDigestAlgorithm(alg DigestAlgorithm) SignerOption
WithContentDigestAlgorithm selects the algorithm for generating a covered Content-Digest. An unsupported algorithm causes ErrUnsupportedAlgorithm.
func WithTTL ¶
func WithTTL(ttl time.Duration) SignerOption
WithTTL specifies the interval between the created and expires signature parameters. A non-positive duration omits expires.
type Token ¶ added in v0.10.0
type Token string
Token represents a Structured Fields token. It is distinct from string so applications can distinguish token values from quoted Structured Fields strings when validating profile-specific signature parameters.
type VerificationResult ¶ added in v0.10.0
type VerificationResult []VerifiedSignature
VerificationResult contains the signatures selected and successfully verified during one call to Verifier.Verify. The order of the signatures is not guaranteed.
type VerifiedSignature ¶ added in v0.10.0
type VerifiedSignature struct {
// Label is the received signature label. It is not cryptographically
// protected and must not be used as an identity or authorization claim.
Label string
// Components contains the canonicalized values of the covered HTTP
// message components, without the synthetic @signature-params component.
// Map keys are serialized Structured Fields String Items (e.g. `"@method"`
// or `"content-digest";req`).
Components map[string]string
// Parameters contains the actual transmitted signature parameters,
// including extensions, without synthetic defaults.
Parameters SignatureParameters
// Metadata is the application-defined metadata provided by the KeyResolver
// for this signature.
Metadata any
}
VerifiedSignature contains the attributes of a successfully verified HTTP message signature and the metadata returned by the KeyResolver.
type Verifier ¶
type Verifier interface {
// Verify returns information about the successfully verified signatures
// or an error. Per-call requirements do not change the Verifier.
Verify(msg *Message, opts ...VerifyOption) (VerificationResult, error)
}
Verifier verifies HTTP message signatures according to its configured requirements. A call succeeds only if all selected signatures pass.
func NewVerifier ¶
func NewVerifier(resolver KeyResolver, opts ...VerifierOption) (Verifier, error)
NewVerifier creates a Verifier instance. Without WithValidateAllSignatures, at least one WithRequiredTag is necessary. By default, created and expires are required and signatures may be at most 30 seconds old. Optional created or expires parameters are still checked when present. Global WithSignatureNegotiation cannot be combined with WithValidateAllSignatures. More specific requirements can be set through opts.
type VerifierOption ¶
type VerifierOption interface {
// contains filtered or unexported methods
}
VerifierOption configures signature selection or verification requirements. It can also be used within WithRequiredTag for per-tag requirements.
func WithMaxAge ¶
func WithMaxAge(age time.Duration) VerifierOption
WithMaxAge specifies the maximum allowed age of a signature with a created timestamp. The duration must be positive.
func WithRequiredTag ¶
func WithRequiredTag(tag string, opts ...VerifierOption) VerifierOption
WithRequiredTag specifies a required application-defined tag and its per-tag verifier options. Each non-empty tag may be configured only once.
func WithSignatureNegotiation ¶
func WithSignatureNegotiation(opts ...SignatureNegotiationOption) VerifierOption
WithSignatureNegotiation enables Accept-Signature negotiation based on the verifier's requirements. Its options specify additional requests that cannot be derived from those requirements.
func WithValidateAllSignatures ¶
func WithValidateAllSignatures() VerifierOption
WithValidateAllSignatures selects all signatures for verification, rather than only those with required tags.
func WithValidityTolerance ¶
func WithValidityTolerance(tolerance time.Duration) VerifierOption
WithValidityTolerance specifies the allowed clock skew for created and expires timestamp checks. The duration must not be negative; zero allows no clock skew.
func WithoutMaxAge ¶ added in v0.11.0
func WithoutMaxAge() VerifierOption
WithoutMaxAge disables the maximum age check for signatures with a created timestamp. Checks for future created timestamps and signature expiration remain active.
type VerifyOption ¶ added in v0.10.0
type VerifyOption interface {
// contains filtered or unexported methods
}
VerifyOption adds requirements for a single Verify call.
Source Files
¶
- accept_signature.go
- asymmetric.go
- canonicalizer.go
- component.go
- component_identifier.go
- httpsig.go
- message.go
- message_digester.go
- message_updater.go
- message_verifier.go
- net.go
- nonce.go
- options.go
- serializer.go
- signature_base.go
- signature_input.go
- signature_requirements.go
- signer.go
- signer_adaptor.go
- symmetric.go
- verification_policy.go
- verifier.go
- verifier_adaptor.go