1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//! Wire-fingerprint **cluster membership**: the anti-uniqueness self-check
//! (G048–G051).
//!
//! A spoofed TLS/HTTP-2 fingerprint that is *byte-perfect Firefox* still loses
//! if it is the **only** client on the internet emitting that exact shape: a
//! unique fingerprint is itself a stable identifier (it tracks you across
//! sessions even with cookies cleared). The defense is not "look like a
//! browser" but "look like a **populated** browser cluster", collide with the
//! JA4/Akamai that millions of real users share.
//!
//! This module measures exactly that, and **only** that. Given a fingerprint
//! the caller's own stack emits (recovered from a probe such as
//! `tls.peet.ws/api/all`), it reports which known real-browser
//! [`FingerprintTarget`](crate::fingerprint::tls_targets::FingerprintTarget)s
//! that shape collides with. It is a screwdriver: it transforms *the caller's
//! own emitted fingerprint* into a membership verdict. It never inspects a
//! remote target, never claims a vulnerability, and never scores anyone.
//!
//! ## Soundness, what [`ClusterVerdict::Distinguishable`] does and does not mean
//!
//! A `Distinguishable` verdict means "this shape matched **no entry in the
//! bundled catalogue** on the primary axis." That is a fact about *catalogue
//! coverage*, **not** proof the fingerprint is globally unique, the catalogue
//! is a finite snapshot of published targets, and the real cluster a shape
//! belongs to may simply not be bundled yet. So `Distinguishable` lowers the
//! caller's confidence that they blend in; it never raises a claim that the
//! fingerprint is trackable in the wild. Closing the gap is "add the measured
//! target," never "assert uniqueness."
//!
//! ## Why JA4 is the primary axis, Akamai-H2 the corroborator
//!
//! - **JA4** sorts the GREASE-stripped cipher and extension lists before
//! hashing (FoxIO spec; see [`compute_ja4`](crate::fingerprint::ja3::compute_ja4)),
//! so it is *stable across handshakes*, unlike a raw ClientHello capture
//! whose GREASE values and positions vary every connection. A stable surface
//! is the only kind a cluster can be defined over, so JA4 is the **required**
//! axis: membership is asserted only when JA4 matches.
//! - **Akamai HTTP/2** (`SETTINGS|WINDOW_UPDATE|PRIORITY|header-order`) is set
//! by the engine's networking stack, not JavaScript. It *corroborates*: a JA4
//! that matches Firefox while the H2 frame says something else is an
//! incoherent shape, so a **probed** Akamai that contradicts the JA4 match
//! breaks membership rather than being silently ignored. When it contradicts,
//! parse both sides with
//! [`akamai_h2::AkamaiH2Fingerprint`](crate::fingerprint::akamai_h2) and
//! [`diff`](crate::fingerprint::akamai_h2::AkamaiH2Fingerprint::diff) them to
//! localize the divergence to the exact frame field (which SETTINGS value,
//! pseudo-header order, …) (the surface here is a coarse Matched/Mismatched).
//! - **JA3** is order-sensitive and deprecated; **peetprint** is a `peet.ws`
//! composite. Both are recorded and, when probed, may contradict, but neither
//! alone establishes membership.
//!
//! Every surface is tri-state ([`SurfaceMatch`]): `Matched`, `Mismatched`, or
//! `NotProbed`. Collapsing "not probed" into "mismatched" would silently turn an
//! un-probed surface into a false contradiction, so the distinction is kept
//! explicit end to end.
use crate;
/// One surface's comparison outcome. Kept tri-state so "the probe never
/// recovered this surface" is never confused with "this surface disagreed."
/// A fingerprint the caller's own transport emits, as recovered from a wire
/// probe. Every field is optional because a given probe recovers only the
/// surfaces it can see (`tls.peet.ws/api/all` yields all four; a passive TLS
/// sniffer may yield only the JA3 string).
///
/// `ja3` is compared as the full canonical JA3 **string**
/// (`771,ciphers,exts,groups,formats`) to match the catalogue's representation,
/// not the MD5 hash.
/// How one observed fingerprint lines up against one catalogue target, surface
/// by surface.
/// The membership verdict for one observed fingerprint.
/// Compare one observation against one target, surface by surface.
/// Classify an observed fingerprint against the bundled real-browser catalogue.
///
/// Returns [`ClusterVerdict::InCluster`] when the observation is a member of ≥1
/// target (primary axis JA4 matched, nothing probed contradicts), otherwise
/// [`ClusterVerdict::Distinguishable`] with the nearest partial match. See the
/// module soundness note on what `Distinguishable` does and does not assert.
///
/// # Examples
///
/// ```
/// use guise::fingerprint::cluster::{classify_observed, ObservedFingerprint};
/// use guise::fingerprint::tls_targets::lookup;
///
/// // A shape that reproduces a bundled target's JA4 (and a matching Akamai) is
/// // in-cluster.
/// let ff = lookup("firefox-150-linux").unwrap();
/// let observed = ObservedFingerprint {
/// ja4: Some(ff.ja4.to_string()),
/// akamai_h2: Some(ff.akamai_h2.to_string()),
/// ..Default::default()
/// };
/// let verdict = classify_observed(&observed);
/// assert!(verdict.is_in_cluster());
/// assert!(verdict.cluster_labels().contains(&"firefox-150-linux"));
///
/// // A JA4 that exists in no bundled target is distinguishable from the catalogue.
/// let alien = ObservedFingerprint::from_ja4("t13d9999h2_deadbeefcafe_0123456789ab");
/// assert!(!classify_observed(&alien).is_in_cluster());
/// ```
/// [`classify_observed`] against an explicit target set, the testable core, so
/// the catalogue can be substituted in unit tests, or extended with Tier-B
/// targets via [`tls_targets::builtin_with`](crate::fingerprint::tls_targets::builtin_with).
/// The slice need not be `'static` (only each target's string fields are); this
/// lets a caller classify against a runtime-built `Vec<FingerprintTarget>`.