Documentation
¶
Overview ¶
Package identity is the shared definition of how a scan's requests identify themselves to a target: the User-Agent values a layer may set, and how one value of a rotation list is chosen for a target host.
The platform validates every layer (platform, organization, program) with these functions and the sensor validates the job it receives with the same ones, so a value one side accepts is one the other side sends. The selection is defined once here so the platform can show which User-Agent a host gets in a run and the sensor sends exactly that one.
User-Agent rotation ¶
A layer may give a list of up to MaxUserAgents values instead of one. SelectUserAgent picks one value per (key, host): the key is the scan run (the platform puts the run's id in the job), the host is the target host a request goes to. The choice is sticky: every request of one run to one host carries the same value, so a session never changes its fingerprint half way. Different runs and different hosts spread evenly over the list (HMAC-SHA-256 keyed by the run key, over the canonical host).
Rotation never replaces the identification of a scan: identification headers and the identification query parameter are sent with every value of the list, and a job that requires identification is refused where a tool cannot carry it (see the sensor SDK's tool host).
Index ¶
Constants ¶
const ( // MaxUserAgents is the most values a rotation list may hold. MaxUserAgents = 200 // MaxUserAgentLen is the longest value, in bytes. MaxUserAgentLen = 256 // MaxKeyLen is the longest selection key, in bytes. MaxKeyLen = 128 )
Bounds of the User-Agent values.
Variables ¶
var ErrInvalid = errors.New("invalid identification")
ErrInvalid is wrapped by every validation error of this package.
Functions ¶
func CanonicalHost ¶
CanonicalHost is the host a selection is made for: the host of a URL, a host:port or a bare host, lower-cased, without a port, IPv6 brackets or a trailing dot. "https://WWW.Example.com.:8443/a" and "www.example.com" give the same host, so every port and scheme of a host gets one value.
func CheckKey ¶
CheckKey accepts a selection key of at most MaxKeyLen printable ASCII characters ("" is valid: the selection then depends on the host alone).
func CheckUserAgent ¶
CheckUserAgent accepts a User-Agent of 1 to MaxUserAgentLen printable ASCII characters with no leading or trailing space.
func CheckUserAgents ¶
CheckUserAgents accepts a rotation list: at most MaxUserAgents values, each valid (CheckUserAgent), none twice. An empty list is valid (no rotation).
func SelectIndex ¶
SelectIndex returns the index in a list of n values that (key, host) gets: HMAC-SHA-256 keyed by key over the label and the canonical host, read as a big-endian uint64, modulo n. The bias of the modulo is below n/2^64. -1 when n < 1.
func SelectUserAgent ¶
SelectUserAgent returns the value of list that (key, host) gets (SelectIndex); "" for an empty list.
Types ¶
This section is empty.