Documentation
¶
Overview ¶
Package requesttransform evaluates a declared request transform: the signing, nonce and body encryption a target's own client applies to every request, written as data (an ordered list of operations) and never as code.
The schema, the checks and the semantics are gimorra's (packages/validators/src/request-transform.ts). Both evaluators read the same conformance vectors (testdata/request-transform.json, a byte-for-byte copy of gimorra's packages/validators/conformance/request-transform.json) in their tests, so one transform answers the same bytes in either.
A transform cannot change where a request goes: no operation writes the URL's scheme, host, port or path, and the header names that route or frame a request (DestinationHeaders) are refused at decode.
Keys are references: hmac-header and encrypt-body name a credential ({"credential": "<name>"}) that Env.Key resolves at evaluation; a transform document never holds a key value.
Index ¶
- Constants
- Variables
- func Activate(s *Set)
- func Decode(data []byte) (*Transform, *Refusal)
- func DecodeWith(data []byte, predefined []string) (*Transform, *Refusal)
- func Evaluate(t *Transform, req Request, env Env) (Request, map[string]string, *Refusal)
- func KeyEnvName(credential string) string
- func Matches(t *Transform, rawURL string) bool
- func PercentEncode(v string) string
- func QueryValue(query, name string) (string, bool)
- type Applies
- type Env
- type KeyRef
- type Op
- type Refusal
- type Request
- type Set
- type Transform
- type URLParts
Constants ¶
const KeyEnvPrefix = "VIGOLIUM_TRANSFORM_KEY_"
KeyEnvPrefix prefixes the environment variable a key reference resolves from first: {"credential": "api-key"} reads VIGOLIUM_TRANSFORM_KEY_API_KEY.
const MaxOps = 32
MaxOps is the most operations one transform may hold.
Variables ¶
var DestinationHeaders = map[string]bool{ "host": true, ":authority": true, ":scheme": true, ":path": true, ":method": true, "forwarded": true, "x-forwarded-host": true, "x-forwarded-proto": true, "x-forwarded-port": true, "x-forwarded-server": true, "x-host": true, "x-original-url": true, "x-rewrite-url": true, "x-original-host": true, "x-http-method-override": true, "x-http-method": true, "x-method-override": true, "content-length": true, "transfer-encoding": true, "connection": true, "te": true, "upgrade": true, "proxy-connection": true, }
DestinationHeaders are the header names that decide where a request goes or how it is framed; a transform never writes one.
var Ops = []string{"timestamp", "nonce", "hash", "truncate", "hmac-header", "set-header", "set-query", "encrypt-body"}
Ops is the closed vocabulary, in the order the refusal message lists it.
Functions ¶
func Activate ¶
func Activate(s *Set)
Activate installs the set every request this process sends is checked against (nil clears it).
func Decode ¶
Decode decodes and checks one transform document, answering the FIRST refusal (the same one gimorra's decodeTransform answers).
func DecodeWith ¶
DecodeWith is Decode with names defined before the first op.
func Evaluate ¶
Evaluate applies a checked transform to one request. The URL that comes back keeps the request's origin byte for byte: no op writes it.
func KeyEnvName ¶
KeyEnvName is the environment variable a credential name resolves from: the prefix plus the name uppercased, every non-alphanumeric byte as `_`.
func Matches ¶
Matches reports whether t applies to rawURL: its host (and port, when the transform names one) and its path prefix.
func PercentEncode ¶
PercentEncode encodes every byte outside RFC 3986's unreserved set as %XX, uppercase.
func QueryValue ¶
QueryValue is one raw query's first value for name, decoded.
Types ¶
type Applies ¶
Applies is where a transform applies: one host (hostname, or hostname:port), optionally a path prefix.
type Env ¶
type Env struct {
// Now is milliseconds since the epoch.
Now func() int64
// Key resolves a credential reference; false when the store holds none.
Key func(credential string) (string, bool)
// Random returns n random bytes; nil uses crypto/rand.
Random func(n int) []byte
// Fixed pins a timestamp or nonce op's value by name.
Fixed map[string]string
// Vars are values defined before the first op.
Vars map[string]string
}
Env is what one evaluation draws on.
type KeyRef ¶
type KeyRef struct {
Credential string
}
KeyRef names a credential of the caller's key store, never its value.
type Op ¶
type Op struct {
Op string
Name string
HasName bool
Unit string
Length int
HasLength bool
Alphabet string
Alg string
Over []string
Join string
Encoding string
From string
Keep string
Header string
Key KeyRef
KeyEncoding string
Prefix string
Value string
Param string
IV string
Layout string
Envelope string
HasEnvelope bool
ContentType string
HasContentType bool
}
Op is one decoded operation; which fields are meaningful depends on Op.
type Refusal ¶
Refusal says why a transform was refused or could not be evaluated. Code is the stable vocabulary both evaluators share (the vectors assert it).
type Request ¶
Request is what a transform reads and writes: the FINAL request, with every header the wire carries (lowercased names) and the body.
type Set ¶
type Set struct {
Transforms []*Transform
// contains filtered or unexported fields
}
Set is the transforms one invocation applies, with the key store their references resolve against.
func Load ¶
Load reads a transform file and, when keysPath is set, its keys file - a JSON object of credential name to value, readable by its owner alone.
func Parse ¶
Parse decodes a transform file: one transform object or an array of them. keys is the parsed keys file (nil for none).
func (*Set) Apply ¶
Apply evaluates the transform that applies to req.URL with the real clock and crypto/rand. It answers req unchanged (and a nil transform) when none applies.
type URLParts ¶
type URLParts struct {
Origin string
Host string
Path string
Query string
HasQuery bool
Fragment string
}
URLParts is a URL split by string slicing - never a URL parser, because two parsers normalise a path differently and a signature over a normalised path signs bytes that never leave.