Go package fingerprint¶
Generated from current exported declarations and Go doc comments. See the package index.
Package fingerprint turns the bytes a TLS client actually put on the wire into the hashes a fingerprinting service would compute from them.
It exists so that "does our handshake match the browser's?" can be answered locally, from the raw ClientHello, instead of by asking a third-party service and trusting its answer. That matters for three reasons: the tests can be hermetic, the comparison keeps working when the service is down or changes its output, and a mismatch can be reported as a structural diff — this extension, that signature algorithm — rather than as two hashes that differ for reasons nobody can see.
Constants¶
ExtServerName, ExtStatusRequest, ExtSupportedGroups, …¶
Extension numbers this package reads by name. The full registry is large and mostly irrelevant here; these are the ones that feed a fingerprint.
const (
ExtServerName uint16 = 0
ExtStatusRequest uint16 = 5
ExtSupportedGroups uint16 = 10
ExtECPointFormats uint16 = 11
ExtSignatureAlgorithms uint16 = 13
ExtALPN uint16 = 16
ExtSCT uint16 = 18
ExtPadding uint16 = 21
ExtExtendedMasterSecret uint16 = 23
ExtCompressCertificate uint16 = 27
ExtSessionTicket uint16 = 35
ExtPreSharedKey uint16 = 41
ExtSupportedVersions uint16 = 43
ExtPSKKeyExchangeModes uint16 = 45
ExtKeyShare uint16 = 51
ExtTrustAnchors uint16 = 51764
ExtEncryptedClientHello uint16 = 65037
ExtRenegotiationInfo uint16 = 65281
// ExtALPS is application_settings, ALPS, under the codepoint BoringSSL
// gives it now, 17613 (0x44cd), which Chrome 155 sends; ExtALPSOld is the
// one it had first, 17513 (0x4469), which older Chrome sends. The names
// are BoringSSL's.
ExtALPS uint16 = 17613
ExtALPSOld uint16 = 17513
// ExtApplicationSettings is 17513, the codepoint BoringSSL calls
// application_settings_old: this name says the other.
//
// Deprecated: use ExtALPSOld, of the same value.
ExtApplicationSettings uint16 = 17513
// ExtApplicationSettingsOld is 17613, the codepoint BoringSSL calls
// application_settings, which Chrome sends now: this name says the other.
//
// Deprecated: use ExtALPS, of the same value.
ExtApplicationSettingsOld uint16 = 17613
)
Variables¶
ErrNoRequest¶
ErrNoRequest reports frames that end before a request's header block does.
ErrNotClientHello¶
ErrNotClientHello reports bytes that are syntactically fine as far as they go but are not the message this package parses — a ServerHello, an alert, or plain HTTP sent to a TLS port.
Functions¶
CipherName()¶
CipherName names a cipher suite.
ExtensionName()¶
ExtensionName names a TLS extension, GREASE included.
GroupName()¶
GroupName names a supported group (named curve).
IsGREASE()¶
IsGREASE reports whether a value is one of the sixteen reserved GREASE values, which all have the form 0xNaNa: both bytes equal, low nibble 0xa.
GREASE is the random noise TLS clients sprinkle through their ClientHello to keep middleboxes honest (RFC 8701). Chrome picks fresh values on every single connection, so anything derived from them differs from the same browser to itself — which is why every fingerprint in this package drops them before hashing. Forgetting to do that is the classic way to produce a "fingerprint" that never matches twice.
SettingName()¶
SettingName names an HTTP/2 setting.
SignatureName()¶
SignatureName names a signature scheme.
VersionName()¶
VersionName names a TLS version.
Types¶
ClientHello¶
ClientHello is a parsed TLS ClientHello, in wire order.
type ClientHello struct {
// Raw is the exact record-layer prefix this hello was parsed from, with
// whatever followed it on the wire trimmed off. A recorder that saved "the
// bytes it happened to have read" would store a different number of bytes
// depending on how the kernel split the stream; this is reproducible, which
// makes it safe to write into a capture file and re-parse later.
Raw []byte
// RecordVersion is the version the record layer was written with, which
// is not the hello's: TLS 1.3 asks for 0x0301 there on a first hello.
// Records is how many records the hello came in, which says where the
// client cut it; a browser's fits in one, however long.
RecordVersion uint16
Records int
LegacyVersion uint16
Random []byte
SessionID []byte
CipherSuites []uint16
CompressionMethods []byte
Extensions []Extension
}
ParseClientHello()¶
ParseClientHello reads a ClientHello out of raw TLS record-layer bytes — the first thing a server reads off an accepted connection.
It takes records rather than a bare handshake message because that is the shape the bytes arrive in, and because a ClientHello may be split across several records. Chrome's is close to 2 KB once the post-quantum key share is in it, which is still one record; other clients fragment, and a parser that assumed one record would report those as malformed.
ClientHello.ALPN()¶
ALPN returns the advertised application protocols, in order.
ClientHello.ApplicationSettings()¶
ApplicationSettings returns the ALPS protocol list. Chrome sends this extension under two different numbers depending on version, and which one it picks is itself a version signal, so both are read, the current one first.
ClientHello.CertCompressionAlgorithms()¶
CertCompressionAlgorithms returns the certificate compression algorithms.
ClientHello.ECPointFormats()¶
ECPointFormats returns the elliptic curve point formats. JA3 hashes them.
ClientHello.EncryptedClientHello()¶
EncryptedClientHello returns the encrypted_client_hello extension of an outer ClientHello, or false for a hello without one, or with one that is an inner hello's or does not parse.
ClientHello.Extension()¶
Extension returns the body of the first extension of the given type.
"First" rather than "only" because a duplicate extension is malformed but not unparseable, and the fingerprint of a malformed hello is still worth having: refusing to describe it would hide exactly the client worth looking at.
ClientHello.ExtensionTypes()¶
ExtensionTypes lists the extension numbers in the order they were sent.
ClientHello.JA3()¶
JA3 returns the JA3 string: version, ciphers, extensions, curves and point formats, decimal, GREASE removed.
A warning that belongs next to the function rather than in a document: JA3 is not usable for Chrome. Chrome shuffles its extension order on every connection, and JA3 hashes that order, so the same browser produces a different JA3 for every request it makes. It is implemented here because plenty of services still log it. A stable JA3 across a finite set of connections is not enough to identify or rule out Chrome; never compare two JA3s and conclude anything from their differing.
Use JA4, which sorts before hashing for exactly this reason.
ClientHello.JA3Hash()¶
JA3Hash returns the MD5 of the JA3 string, which is the form services log.
ClientHello.JA4()¶
JA4 returns the FoxIO JA4 TLS fingerprint, e.g.
Unlike JA3 it sorts the cipher and extension lists before hashing, so it is stable for a browser that shuffles its extension order — which is every modern Chrome. This is the fingerprint to compare.
One property worth knowing before comparing anything: a client's JA4 changes when the connection is RESUMED, because resumption adds pre_shared_key to the extension set. Real Chrome 151 sends t13d1516h2_…_806a8c22fdea cold and t13d1517h2_…_a87ad97598a9 on a resumed connection. Both are that browser. Compare like with like.
ClientHello.JA4Raw()¶
JA4Raw returns the un-hashed form, ja4_r, whose whole point is that a mismatch can be read: two JA4s that differ tell you nothing about why, two JA4Raws differ at a cipher or an extension you can name.
ClientHello.KeyShareGroups()¶
KeyShareGroups returns the groups the client actually sent a key share for, which is a subset of SupportedGroups and a fingerprint in its own right: a client that offers X25519MLKEM768 but only ships an X25519 share is not the browser it claims to be.
ClientHello.KeyShares()¶
KeyShares returns the entries of key_share in the order sent, GREASE included, as far as they parse.
ClientHello.PSKKeyExchangeModes()¶
PSKKeyExchangeModes returns the offered PSK modes.
ClientHello.PreSharedKey()¶
PreSharedKey returns the shape of pre_shared_key, or false for a hello without one, or with one that does not parse.
ClientHello.ServerName()¶
ServerName returns the SNI hostname.
ClientHello.SignatureAlgorithms()¶
SignatureAlgorithms returns the signature schemes, in the order sent.
Order is load-bearing: JA4 hashes this list unsorted, precisely because it is a preference list and clients disagree about the preference.
ClientHello.SupportedGroups()¶
SupportedGroups returns the named groups (curves), GREASE included.
ClientHello.SupportedVersions()¶
SupportedVersions returns the versions from the supported_versions extension, GREASE included, in the order sent.
ClientHello.TrustAnchors()¶
TrustAnchors returns the IDs of trust_anchors in the order sent, each as the relative object identifier it is, dotted (44947.2.1), or in hex when it is not one. Chrome 154 and later send them sorted by their bytes; an older Chrome drew their order once for each process it ran. The IDs say which root store sent them.
Difference¶
Difference is one way in which a candidate handshake failed to be the reference handshake.
It carries both sides and, where a list is involved, which entries are missing and which are extra — because "the JA4 differs" is a fact nobody can act on, while "you are not sending mldsa44" is a fix.
Difference.String()¶
ECH¶
ECH is what a server can read of the encrypted_client_hello extension of a hello to it when it published no ECH configuration, which is every server a browser has not been told about: GREASE, the shape of a real one with random contents, so that servers cannot come to depend on its absence. Its cipher suite, the length of its encapsulated key and the length of its payload.
Extension¶
Extension is one entry of the ClientHello's extension block, kept in the order the client sent it and with its body intact.
The body is kept because the extension TYPE alone is not the whole story: two clients can both send supported_groups and disagree about every group in it. The structural diff reads the bodies.
Field¶
Field is one property a fingerprint is compared on, with the values from one side of the comparison.
The list exists so that the fields are named once. Comparing and displaying want the same set, and a second copy of it in the command line would drift: a field added here would quietly stop being shown, or a field shown there would quietly stop being compared.
type Field struct {
Name string
Values []string
// Set compares membership rather than sequence: where the browser itself
// varies the order, as the extension list, or the trust anchors of a
// Chrome before 154, which drew their order for each process.
Set bool
// Scalar is a single value rather than a list, so a mismatch has no
// meaningful "missing" and "extra".
Scalar bool
// Varies says why a value says nothing of the client, for one shown for
// both sides and never compared: a value the browser draws afresh for
// every connection, such as the length of its ECH payload, where it would
// not match itself, or one the page asked for decides. Empty for a value
// compared. Either side's makes the field one.
Varies string
// Missing is a value the measurement does not hold: one made before it
// was recorded, or one that could not be read. Missing on either side, a
// field is not checked: neither a match nor a difference.
Missing bool
}
HTTP1Fields()¶
HTTP1Fields is everything in an HTTP/1.1 request fingerprint.
Host's position and spelling are fingerprinted, but its value belongs to the destination and differs between two measurements by construction, as does the target of the request line.
HTTP2Fields()¶
HTTP2Fields is everything the connection preamble and first request are compared on.
Header values are included. A profile is a complete browser identity, and a Chrome ClientHello paired with a HeadlessChrome user-agent is exactly the kind of cross-layer contradiction this comparison exists to expose. The values of :path and :authority are not: the two measurements ask for different pages, and a browser opened by hand reaches the server by a name of its own.
TLSFields()¶
TLSFields is everything a ClientHello is compared on, in a fixed order: the manifest of the comparison.
What the browser draws for every connection is not compared as it is, since the browser would not match itself; its shape is, which does not change:
- Extension ORDER. Chrome shuffles it on every connection. The extension SET is compared instead, which is what JA4 hashes, and the order of the trust anchors, drawn once for each browser process, likewise.
- GREASE values (RFC 8701). Where they go, how long they are, what a short body holds and which are one value is compared as grease.
- The random, the session id, the keys, ECH's config id, key and payload, and the tickets and binders of pre_shared_key: their lengths are compared, the bytes are not. Of the keys, what a server can check is compared too: that each is a public key of its kind, and that keys of one kind are each their own (keys).
- The length of the ECH payload, which Chrome draws from four for every connection: shown, not compared itself (Varies); whether it is one of the four is (ech_grease).
- The contents of server_name, which are the site's, and of padding, whose length follows from the rest. Whether server_name holds one host_name, and whether each extension a field reads reads whole, is compared as framing.
A key of a group no rule reads, and an ECH key of a length no KEM has, are reported as not checked when both sides send one.
Other fields in this manifest are compared exactly for the supplied pair of captures. This does not establish that they are invariant across launches, request contexts or connection states. An extension both sides send that none of this describes, with contents that differ, is reported by CompareTLS as not checked.
Field.Matches()¶
Matches reports whether two fields agree, by the rule that field is compared with.
Display has to ask this rather than compare the rendered strings, or a Set field whose order differs would be shown as a difference while the verdict below it said everything matched. The two answers have to come from one rule.
Field.Render()¶
Render is the value as a person reads it.
A Set field renders sorted. Its order is not compared because the browser varies it, so printing the order it happened to arrive in would invite the reader to compare something that is not being compared.
Frame¶
Frame is one HTTP/2 frame as it went: its type, flags, stream and length.
Frame.Ack()¶
Ack reports a SETTINGS or PING frame that acknowledges the server's: when it goes depends on when the server's arrived, not on the client.
Frame.String()¶
String is a frame as a person reads it: its type, its stream, and its flags by name, any the type does not define in hex.
HTTP1¶
HTTP1 is the request line, without its target, and the ordered header block as they appeared on the wire.
HTTP2¶
HTTP2 is everything a server sees a client do on a fresh HTTP/2 connection before the first response is written.
type HTTP2 struct {
Settings []Setting
WindowUpdate uint32
Priorities []Priority
Headers []HeaderField
// HeaderPriority is the priority carried ON the HEADERS frame, which is a
// different thing from a standalone PRIORITY frame and is set by a different
// knob in every library that lets you set it at all. Chrome sends one
// (exclusive, depends on stream 0, weight 255 on the wire); most HTTP
// clients send none.
HeaderPriority *Priority
// Raw is what the client sent from the end of its preface to the end of
// its first request's header block, as it went: ParsePreamble reads it.
// Empty when it was not recorded.
Raw []byte
}
HTTP2.Akamai()¶
Akamai returns the Akamai HTTP/2 fingerprint, e.g.
The four fields are the SETTINGS in order, the connection-level WINDOW_UPDATE increment, the PRIORITY frames, and the order of the pseudo-headers. A PRIORITY frame is stream:exclusive:depends-on:weight, the weight as RFC 9113 counts it, the frame's byte and one, as Akamai's paper and tls.peet.ws write it: Firefox's 200 on the wire is 201 (3:0:0:201). It complements the TLS fingerprint rather than duplicating it: a client can copy a ClientHello byte for byte and still give itself away one layer up by sending :path before :scheme.
HTTP2.Header()¶
Header returns the first value sent for a name, matched case-insensitively.
HTTP2.HeaderOrder()¶
HeaderOrder returns the ordinary header names in the order sent.
This is a fingerprint in its own right and one of the easiest to get wrong, because most HTTP libraries store headers in a map and emit them sorted or at random. A client whose TLS is perfect and whose headers arrive alphabetically has announced itself.
HTTP2.PseudoHeaderOrder()¶
PseudoHeaderOrder returns the pseudo-headers as single letters in the order sent: m, a, s, p for :method, :authority, :scheme, :path.
HeaderBlocks¶
HeaderBlocks reads the header blocks a client wrote on one connection, in the order it wrote them: each against the dynamic table the blocks before it left (RFC 7541, section 2.3.2), which it keeps as the server's decoder does. After a block it cannot read it is out of step with the client's table, and reads no more.
NewHeaderBlocks()¶
NewHeaderBlocks reads the header blocks of a connection whose server let the client's dynamic table be tableSize bytes: the client writes its first against a table of 4096, and may say another size, up to tableSize, at the start of any block.
HeaderBlocks.Next()¶
Next reads the connection's next header block, as Representations reads one: how each field was written, then which field each is.
HeaderField¶
HeaderField is one HPACK-decoded header, in wire order, pseudo-headers included.
KeyShare¶
KeyShare is one entry of key_share: its group, and how long its key is. The key itself is fresh for every connection, and only its length says anything about the client: 1216 bytes for X25519MLKEM768, 32 for X25519, one for a GREASE group's.
PSK¶
PSK is what a server can read of pre_shared_key without its keys: how many identities it offers, and how long each binder is. The identities are tickets the server issued, and the binders are fresh for every hello.
Preamble¶
Preamble is what a client sent from the end of its preface to the end of the header block of its first request.
ParsePreamble()¶
ParsePreamble reads frames up to the end of the first header block. Bytes past it are not read, and are not in Raw.
Priority¶
Priority is a standalone PRIORITY frame. Chrome stopped sending these when it moved to the priority header, so their PRESENCE is a signal in itself.
Report¶
Report is the outcome of comparing a candidate against a reference.
type Report struct {
Differences []Difference
// Unchecked is what both sides have and no rule says how to compare: an
// extension nobody has described, whose contents differ. It is neither a
// match nor a difference, and a report with any is not a match.
Unchecked []Difference `json:",omitempty"`
}
CompareHTTP1()¶
CompareHTTP1 diffs HTTP/1.1 request header order, casing and values.
CompareHTTP2()¶
CompareHTTP2 diffs the connection preamble and the request headers.
CompareTLS()¶
CompareTLS diffs a candidate ClientHello against a reference one, usually a real browser's. TLSFields says what is compared, and what is not.
Report.OK()¶
OK reports a candidate that matches the reference on every field compared, with nothing left that could not be: of the two captures compared alone.
Report.String()¶
Representation¶
Representation is how one field of a header block was written: whole, from a table, or as a literal with or without indexing or never to be indexed, its name from a table or written out; each string written out Huffman-coded or not. A table size update is one too, of no field.
type Representation struct {
// Field is the field's name, decoded; empty for a size update.
Field string
// Kind is "indexed", "with indexing", "without indexing", "never indexed"
// or "size update".
Kind string
// Index is the table index of the field, or of its name, 0 for a name
// written out, or the size a size update sets.
Index uint64
// NameHuffman and ValueHuffman say which strings were Huffman-coded.
NameHuffman, ValueHuffman bool
}
Representations()¶
Representations reads a header block, written for a table of tableSize bytes, field by field: first how each was written, then, decoding the block, which field each is.
Representation.Named()¶
Named is a representation as a person reads it, after its field's name; a size update, of no field, alone.
Representation.String()¶
String is a representation as a person reads it, without its field's name.
Rule¶
Rule is how a comparison holds a client to a browser on one field: what of it is compared, and what is left alone and why. The rules together are the manifest, which a comparison's result carries, so that a match can be read for what it covers.
Manifest()¶
Manifest is the rules a comparison holds a client to, field by field, in the order the fields are compared.
Setting¶
Setting is one entry of an HTTP/2 SETTINGS frame, kept in the order it was sent. Two clients can send the same settings in a different order, and the order is fingerprinted, so a map would throw away the signal.