Skip to content

Go package profile

Generated from current exported declarations and Go doc comments. See the package index.

import "github.com/Sec-CH-Lemon/tls-forge/profile"

Package profile reads and validates JSON for a selected browser build's network behaviour: TLS, HTTP/1.1, HTTP/2, supported HTTP/3 choices and request policy.

A profile is data, not code. Its captured fields and explicit policy can be committed, reviewed and used on another machine with the exact engine major for which it was validated. Historical captures do not automatically establish current browser equivalence on a different platform or path.

Captured ClientHello bytes are one input to a live handshake. The engine regenerates per-connection keys and other dynamic fields according to the selected profile rather than replaying a captured connection.

Constants

Schema

Schema is the version of the profile format this tls-forge writes, and the newest it reads.

A profile that says its schema is read strictly: a field the format does not have is an error, so that a name spelt wrong is found when the profile is read, not on the wire. One with a newer schema is refused rather than read in part. One that says none was written before the format had a version, and is read as it always was: what it holds that the format does not is passed over. Saving writes the schema, so a profile read that way is strict from then on.

Schema 2 added client_hints. A profile of schema 1 is read as strictly, and has none: no tls-forge that wrote 1 knew of them. Schema 3 adds explicit behavior policy; its browser name and user agent are metadata only. Schema 4 adds engine_major, independent of the browser version and schema.

const Schema = 4

Variables

ClientHintOrder

ClientHintOrder is every client hint Chrome 155 sends when a server asks for it with Accept-CH, in the order it sends them, as measured (testdata/chrome155-requests.json): the device's and the network's, some under two names, the user agent's, and the user's preferences. Three of the user agent's, sec-ch-ua, sec-ch-ua-mobile and sec-ch-ua-platform, go with every request, and are a profile's headers; a profile's ClientHints are the values of the rest.

var ClientHintOrder = behavior.Legacy().Strings("headers.client_hint_order")

Default

Default is the registry the package-level functions use.

var Default = NewRegistry()

ErrNoHandshake

ErrNoHandshake reports a profile that names neither a captured ClientHello nor a base profile, and so cannot produce a handshake.

var ErrNoHandshake = fmt.Errorf("profile: neither client_hello, tls_spec nor base is set")

Functions

AskedClientHints()

AskedClientHints are the client hints Chrome sends only to a server that asks for them, in the order it sends them: those a profile's client_hints may say.

func AskedClientHints() []string

DefaultDir()

DefaultDir is where profiles measured on this machine are kept.

Under the user's config directory rather than beside the binary, because a profile is this machine's measurement of this machine's browser: it does not belong to an install that a package manager may replace, and it should survive one.

TLSFORGE_PROFILES moves it, which is how a run in a container or a test says where to look without touching a real one.

func DefaultDir() string

DefaultHintOrder()

DefaultHintOrder is the process-default capture helper's data snapshot. Active clients always use their own Profile.HintOrder, not this cache.

func DefaultHintOrder() []string

DefaultUnaskedHints()

DefaultUnaskedHints are the hints of DefaultHintOrder that go to every server unasked, from the same snapshot.

func DefaultUnaskedHints() []string

FilePath()

FilePath is the directory layout shared by capture and registry lookup. Both components are identifiers; neither can supply a path or traversal.

func FilePath(name, platform string) (string, error)

HostPlatform()

HostPlatform is this machine, spelled the way a profile file is named.

func HostPlatform() string

LegacyBehavior()

LegacyBehavior is for migration and standalone compatibility helpers only.

func LegacyBehavior() behavior.Policy

Major()

Major declares compatibility explicitly when constructing a profile in Go.

func Major(n int) *int

Names()

Names lists the default registry's profiles.

func Names() []string

Register()

Register adds a profile to the default registry.

func Register(p *Profile) error

Ships()

Ships reports a profile tls-forge ships by the name it is filed under, chrome_155_macos: one kept under that name in the directory of profiles answers for it from then on, the directory being read first (Get).

func Ships(name string) bool

Split()

Split separates a name into the version and the platform it names, if it names one. Only a platform this project knows counts: "chrome_151" is a version whose last word happens to be a number, not a platform called 151. The phones' are among them, for a browser measured on one rather than here.

func Split(name string) (version, platform string)

ValidName()

ValidName reports an identifier safe for a profile file, never a path.

func ValidName(name string) bool

Types

CaptureProvenance

CaptureProvenance is separate from the runnable browser profile. Its hashes bind the final profile, the full policy basis and the original capture. Capturing a field does not establish its invariance or browser acceptance.

type CaptureProvenance struct {
    Schema           int                    `json:"provenance_schema"`
    ProfileSHA256    string                 `json:"profile_sha256"`
    CaptureSHA256    string                 `json:"capture_canonical_sha256"`
    BasisName        string                 `json:"basis_name"`
    BasisSHA256      string                 `json:"basis_sha256"`
    Browser          *capture.Navigator     `json:"browser,omitempty"`
    BrowserMode      string                 `json:"browser_mode"`
    Fields           map[string]FieldOrigin `json:"fields"`
    DrawObservations *Drawn                 `json:"draw_observations,omitempty"`
    Acceptance       string                 `json:"acceptance"`
}

ProvenanceForCapture()

ProvenanceForCapture binds a completed candidate after any explicit caller edits. It does not select policy, mutate inputs or mark inherited data measured.

func ProvenanceForCapture(candidate, basis *Profile, c *capture.Capture, mode string) (*CaptureProvenance, error)

Drawn

Drawn is what a browser drew anew for each connection, measured from the hellos of a capture: the measured one and those of the other connections its page opened (echo.WithManual).

type Drawn struct {
    // Hellos is how many it was measured from.
    Hellos int
    // Order says the order of the extensions moved from one hello to
    // another, those both carry compared.
    Order bool
    // ECH are the lengths of the GREASE ECH payloads seen on the wire, each
    // once, ascending; none without one.
    ECH []int
    // Sometimes are the extensions some of them carried and others did not,
    // ascending: what a profile cannot draw.
    Sometimes []uint16
}

DrawnOf()

DrawnOf measures what the browser of a capture drew for each connection, or nil for a capture with too few hellos to tell. GREASE, padding and pre_shared_key are set aside: what is drawn for each, the length of the hello and a ticket decide.

func DrawnOf(c *capture.Capture) (*Drawn, error)

Field

Field is one header. A slice of these rather than a map, because order is fingerprinted and a map has none.

type Field struct {
    Name  string `json:"name"`
    Value string `json:"value"`
}

FieldOrigin

FieldOrigin describes provenance, not executable policy or a browser verdict.

type FieldOrigin struct {
    Class  string `json:"class"`
    Source string `json:"source"`
}

Group

Group is one measured profile and the platforms it was measured on.

A version measured on three platforms is one profile with three spellings rather than three profiles: the handshake is the same on all of them, and only the user-agent and the platform hint differ.

type Group struct {
    // Name is what to ask for to get this machine's platform.
    Name     string
    Variants []Variant
    // Local says this machine has something under this name, which is then the
    // copy that answers.
    Local bool
}

HTTP1

HTTP1 is the part of a request fingerprint HTTP/2 cannot describe. HeaderOrder preserves wire spelling as well as order. Headers contains protocol-only values, or values that differ from the shared Headers block.

type HTTP1 struct {
    HeaderOrder []string `json:"header_order"`
    Headers     []Field  `json:"headers,omitempty"`
}

HTTP2

HTTP2 is the connection preamble a client sends before its first request.

type HTTP2 struct {
    Settings          []Setting  `json:"settings"`
    ConnectionFlow    uint32     `json:"connection_flow"`
    PseudoHeaderOrder []string   `json:"pseudo_header_order"`
    Priorities        []Priority `json:"priorities,omitempty"`
    HeaderPriority    *Priority  `json:"header_priority,omitempty"`
    StreamID          uint32     `json:"stream_id,omitempty"`
}

NetworkHintsPolicy

NetworkHintsPolicy makes literal network persona data distinct from an actual estimator. Estimated mode has no captured production hint values; its policy describes selection, measurement, generation and lifecycle mechanisms.

type NetworkHintsPolicy struct {
    Mode   string                 `json:"mode"`
    Policy *networkquality.Policy `json:"policy,omitempty"`
}

NetworkHintsPolicy.UnmarshalJSON()

UnmarshalJSON rejects missing, duplicate, unknown, case-folded or null choices.

func (p *NetworkHintsPolicy) UnmarshalJSON(raw []byte) error

PerConnection

PerConnection is what a browser's TLS stack draws afresh for every connection, said outright: FromCapture says it of the browser it captures, and a profile written by hand can say it of the browser it describes.

type PerConnection struct {
    // ShufflesExtensions draws the order of the extensions for every
    // connection, as Chromium has since version 110.
    ShufflesExtensions bool `json:"shuffles_extensions,omitempty"`
    // ECHPayloadLengths are the lengths the payload of the GREASE
    // encrypted_client_hello is drawn from, each as likely, before the
    // AEAD's 16-byte tag. None keeps the length the hello was captured with.
    ECHPayloadLengths []uint16 `json:"ech_payload_lengths,omitempty"`
}

Priority

Priority is an HTTP/2 priority, either standalone or carried on HEADERS.

Weight is the value as it appears ON THE WIRE, which is one less than the weight people quote: Chrome's "weight 256" is a 255 here. Storing the wire value keeps the round-trip through a capture exact.

type Priority struct {
    StreamID  uint32 `json:"stream_id"`
    Exclusive bool   `json:"exclusive"`
    DependsOn uint32 `json:"depends_on"`
    Weight    uint8  `json:"weight"`
}

Profile

Profile is a complete browser identity.

type Profile struct {
    // Schema is the version of the format the profile was written in: see
    // the constant. Save writes the current one.
    Schema int `json:"schema,omitempty"`

    // EngineMajor is required for execution and independent of format/browser versions.
    EngineMajor *int `json:"engine_major"`

    // Behavior contains explicit versioned network policies, independent of Name and UserAgent.
    Behavior behavior.Policy `json:"behavior"`

    Name      string `json:"name"`
    UserAgent string `json:"user_agent,omitempty"`

    // ClientHello is a captured ClientHello record, the whole TLS fingerprint.
    // When empty, Base names a stock profile to borrow instead.
    ClientHello []byte `json:"client_hello,omitempty"`

    // TLSSpec describes a handshake without captured bytes. It is exclusive
    // with ClientHello and Base, and always rebuilds live connection state.
    TLSSpec     *TLSSpec     `json:"tls_spec,omitempty"`
    QUICTLSSpec *QUICTLSSpec `json:"quic_tls_spec,omitempty"`

    // Base names a profile from the tls-client catalogue, used when no captured
    // ClientHello is present. It is also what a hand-written profile builds on.
    Base string `json:"base,omitempty"`

    // PerConnection says what the browser draws afresh for every connection.
    // Without it, that is guessed from the profile's name and user agent, as
    // it was before profiles said it.
    PerConnection *PerConnection `json:"per_connection,omitempty"`

    HTTP1   *HTTP1  `json:"http1,omitempty"`
    HTTP2   HTTP2   `json:"http2"`
    Headers []Field `json:"headers,omitempty"`

    // ClientHints are the values of the client hints the browser sends when a
    // server asks for them, by name in lower case, as the browser sends them:
    // the user agent's beyond the three it always sends, and the device's, the
    // network's and the user's preferences where they were measured. A hint
    // the profile has no value for is not sent, asked for or not.
    ClientHints []Field `json:"client_hints,omitempty"`

    // NetworkHints explicitly selects literal persona or a data-owned estimator.
    NetworkHints *NetworkHintsPolicy `json:"network_hints,omitempty"`

    // Notes is free text carried into the JSON so a committed profile can say
    // where it came from — which browser build, measured when, on what OS.
    Notes string `json:"notes,omitempty"`

    // Has unexported fields.
}

CaptureBasis()

CaptureBasis returns the newest shipped full profile for a measured family and platform. Local aliases and Go catalogue presets are not implicit bases. Browser identity selects explicit data here, never runtime engine behavior.

func CaptureBasis(family, platform string) (*Profile, error)

FromCapture()

FromCapture turns a browser measurement into a reusable profile.

Exactly one explicit, executable policy basis is required. Only observed fields replace it; unmeasured generation, protocol and lifecycle policies remain inherited data. Names, User-Agent and brands never select policy here. The variadic signature keeps old callers source-compatible, but omission is an error rather than an implicit legacy/browser preset.

func FromCapture(name string, c *capture.Capture, basis ...*Profile) (*Profile, error)

Get()

Get resolves a name against the default registry.

func Get(name string) (*Profile, error)

Inspect()

Inspect decodes an archived profile for offline inspection. It does not grant permission to execute, nor add or change engine_major. Execution uses Load/New.

func Inspect(data []byte) (*Profile, error)

Load()

Load reads a profile from JSON, as its schema says: see Schema.

func Load(data []byte) (*Profile, error)

Profile.AskedHints()

AskedHints are the hints of HintOrder that go only to a server that asks for them: all but the profile's headers.default_client_hints.

func (p *Profile) AskedHints() []string

Profile.BareBase()

BareBase reports a profile that only names a base of the transport's catalogue, and is that base: no handshake and no HTTP/2 settings of its own.

func (p *Profile) BareBase() bool

Profile.Catalogue()

Catalogue reports that this object was read from the embedded export/import catalogue. It describes provenance, never selects transport behavior. File Load does not invent that origin; Clone preserves it.

func (p *Profile) Catalogue() bool

Profile.Chromium()

Chromium reports a profile of a Chromium browser: Chrome, Chromium, Edge, Brave, Opera and the like, on any platform but iOS, where every browser is Safari underneath. What tls-forge has measured of how a browser sends each kind of request, it measured on Chrome, and applies to these alone.

func (p *Profile) Chromium() bool

Profile.ClientProfile()

ClientProfile converts to the form the transport consumes, the order of the TLS extensions drawn for every connection when the browser draws one (ShufflesExtensions).

func (p *Profile) ClientProfile() (profiles.ClientProfile, error)

Profile.ClientProfileShuffled()

ClientProfileShuffled is ClientProfile with the order of the extensions of every connection's ClientHello drawn for it when shuffle is true, every order of those that move as likely as any other, as Chromium draws one (shuffleExtensions), and the declared order when false. A bare base resolves the same materialized JSON descriptor as an ordinary catalogue lookup.

func (p *Profile) ClientProfileShuffled(shuffle bool) (profiles.ClientProfile, error)

Profile.Clone()

Clone returns an independent copy of the profile.

func (p *Profile) Clone() *Profile

Profile.Header()

Header returns a default header's value.

func (p *Profile) Header(name string) (string, bool)

Profile.HeaderOrder()

HeaderOrder is the header names in profile order, which is what the transport needs to reproduce the browser's ordering.

func (p *Profile) HeaderOrder() []string

Profile.HintOrder()

HintOrder is the order the profile sends its client hints in, as its behavior's headers.client_hint_order says.

func (p *Profile) HintOrder() []string

Profile.Migrate()

Migrate explicitly creates a separately identified current-engine candidate. It preserves the source and capture provenance. The caller must perform the relevant browser/wire acceptance; this operation is not an equivalence claim.

func (p *Profile) Migrate(name string) (*Profile, error)

Profile.RuntimeBehavior()

RuntimeBehavior is the explicit data consumed by all network layers. Schema 0-2 compatibility is materialized on load/save, never for schema 3.

func (p *Profile) RuntimeBehavior() behavior.Policy

Profile.Save()

Save writes a profile as indented JSON, the form meant to be committed and reviewed. Indented and newline-terminated so a profile update shows up in a diff as the fields that changed rather than as one very long line. It is written in the current schema, whichever it was read in.

func (p *Profile) Save() ([]byte, error)

Profile.ShufflesExtensions()

ShufflesExtensions reports whether this browser randomises the TLS extension order on each connection, as PerConnection says. A profile that does not say is guessed at by its family: Chromium browsers do; Firefox and Safari do not; the user agent is a fallback for custom captured profile names.

Nothing on an iPhone or an iPad does, whatever it is called: every browser there connects through Apple's own stack, so Chrome on iOS sends Safari's handshake, in Safari's order.

func (p *Profile) ShufflesExtensions() bool

Profile.Source()

Source is the file this profile was read from, or empty for one that ships inside the binary or came from the catalogue.

func (p *Profile) Source() string

Profile.Spec()

Spec builds a fresh ClientHelloSpec.

Fresh on every call, deliberately. utls extensions are pointers with mutable state, and a spec shared between connections is a spec whose key share is reused — which is both a bug and a fingerprint, since no browser reuses one.

func (p *Profile) Spec() (tls.ClientHelloSpec, error)

Profile.Validate()

Validate accepts an executable identity before any request-related I/O. Inspect and Save preserve representable archives without this permission. Engine compatibility remains an independent, mandatory first gate.

func (p *Profile) Validate() error

Profile.ValidateEngine()

ValidateEngine checks the actual compiled execution contract, not Schema or Name.

func (p *Profile) ValidateEngine() error

QUICTLSSpec

QUICTLSSpec independently describes QUIC TLS. CipherSuites in Hello is the fixed vector or the hardware-AES branch; neither branch is a browser constant.

type QUICTLSSpec struct {
    Hello                  *TLSSpec `json:"hello"`
    CipherOrder            string   `json:"cipher_order"`
    CipherSuitesWithoutAES []uint16 `json:"cipher_suites_without_aes"`
}

QUICTLSSpec.UnmarshalJSON()

UnmarshalJSON requires an exact, complete declarative QUIC TLS descriptor.

func (q *QUICTLSSpec) UnmarshalJSON(data []byte) error

Registry

Registry resolves a profile name.

Four sources, in order: profiles registered at runtime, profiles kept in this machine's own directory, profiles measured and committed here, and the tls-client catalogue. The order matters: someone who captures their own Chrome and keeps it under "chrome_151" should get theirs, not the one that shipped, because theirs is the browser a server will be comparing against.

type Registry struct {
    // Has unexported fields.
}

NewRegistry()

NewRegistry returns a registry over the built-in sources and this machine's own profile directory.

func NewRegistry() *Registry

Registry.Dir()

Dir is where this registry looks for profiles kept on this machine.

func (r *Registry) Dir() string

Registry.Get()

Get resolves a name to a profile.

func (r *Registry) Get(name string) (*Profile, error)

Registry.HasHandshake()

HasHandshake reports whether a name resolves to a profile built from a real captured ClientHello rather than to a catalogue entry. It is what lets a caller tell "this is my browser" from "this is close to some browser".

func (r *Registry) HasHandshake(name string) bool

Registry.KeptHere()

KeptHere lists the profiles in this machine's own directory, which are the ones that win over anything shipped.

func (r *Registry) KeptHere() []string

Registry.Measured()

Measured lists the profiles taken from a real browser, grouped by version.

Both sources at once, not one instead of the other: a machine that has measured Chrome 151 on its own platform still resolves the shipped profile for the others, and a listing that showed only the local one would be saying less than is true.

func (r *Registry) Measured() []Group

Registry.Names()

Names lists every profile that can be resolved, measured ones first.

func (r *Registry) Names() []string

Registry.Register()

Register adds or replaces a profile.

func (r *Registry) Register(p *Profile) error

Registry.SetDir()

SetDir points the registry at another directory.

func (r *Registry) SetDir(dir string)

Resumption

Resumption is how the browser of a capture resumed a session, against the hello it sent cold: tls-forge resumes as Chrome does, with the cold hello and pre_shared_key last, one ticket offered (withResumption).

type Resumption struct {
    // Measured says the capture has a resumed hello.
    Measured bool
    // Added are the extensions the resumed hello carries and the cold one
    // does not, pre_shared_key aside; Missing those it lacks. Ascending.
    Added, Missing []uint16
    // NotLast says pre_shared_key was not its last extension.
    NotLast bool
    // Identities is how many tickets it offered.
    Identities int
}

ResumptionOf()

ResumptionOf is how the browser of a capture resumed a session, against its cold hello; not Measured for a capture with no resumed hello.

func ResumptionOf(c *capture.Capture) (Resumption, error)

Resumption.AsTLSForge()

AsTLSForge says the browser resumed as tls-forge resumes.

func (r Resumption) AsTLSForge() bool

Setting

Setting is one HTTP/2 setting. Order matters, so this is a list.

type Setting struct {
    ID    uint16 `json:"id"`
    Value uint32 `json:"value"`
}

TLSExtension

TLSExtension selects a supported protocol primitive and its data. Parameters are strictly typed by that primitive, including for programmatic profiles.

type TLSExtension struct {
    Type       string          `json:"type"`
    Parameters json.RawMessage `json:"parameters"`
}

TLSSpec

TLSSpec is declarative input, not a recorded handshake. Generated and session values have named sources; a profile cannot supply keys, randoms or binders.

type TLSSpec struct {
    MinVersion         uint16         `json:"min_version"`
    MaxVersion         uint16         `json:"max_version"`
    CipherSuites       []uint16       `json:"cipher_suites"`
    CompressionMethods []uint8        `json:"compression_methods"`
    SessionID          string         `json:"session_id"`
    GREASE             string         `json:"grease"`
    ExtensionOrder     string         `json:"extension_order"`
    Extensions         []TLSExtension `json:"extensions"`
}

TLSSpec.UnmarshalJSON()

UnmarshalJSON requires the complete, unambiguous declarative representation.

func (s *TLSSpec) UnmarshalJSON(data []byte) error

Variant

Variant is one platform a version was measured on.

type Variant struct {
    Platform string
    // Local says this one came from this machine's directory, which is the copy
    // that will be used.
    Local bool
}