Skip to main content

http_quik/profile/
mod.rs

1//! Data-only definitions for Chrome transport identity profiles.
2//!
3//! This module defines the configuration schemas used by the `tls` and `http2`
4//! modules to construct browser-identical network handshakes. No protocol
5//! logic resides here; these structures serve as the single source of truth
6//! for all fingerprint-sensitive parameters.
7//!
8//! Each [`ChromeProfile`] encodes a complete, multi-layer network identity
9//! spanning TLS (Layer 4), HTTP/2 (Layer 5), and HTTP metadata (Layer 7).
10
11use boring::ssl::SslVersion;
12
13pub mod chrome_134;
14
15/// Alias for BoringSSL's internal version type.
16pub type TlsVersion = SslVersion;
17
18/// Target operating system and CPU architecture.
19///
20/// The platform determines OS-specific protocol parameters (ALPS payload
21/// length, User-Agent string, Client Hint values) and is used by
22/// [`chrome_134::profile_auto`] to align the network persona with the
23/// host kernel's TCP/IP characteristics.
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum Platform {
26    /// macOS on Apple Silicon (M1/M2/M3/M4).
27    MacOsArm,
28    /// macOS on Intel x86-64.
29    MacOsX86,
30    /// Windows 10/11 on x86-64.
31    WindowsX64,
32    /// Linux (Ubuntu, Debian, etc.) on x86-64.
33    LinuxX64,
34}
35
36/// Configuration for the TLS 1.2/1.3 handshake layer.
37///
38/// This structure defines the Layer 4 identity of the client. Small changes
39/// here (such as the order of cipher suites) will change the JA3/JA4
40/// fingerprint and can lead to immediate detection.
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub struct TlsProfile {
43    /// Minimum allowed TLS version (typically TLS 1.2).
44    pub min_version: TlsVersion,
45    /// Maximum allowed TLS version (typically TLS 1.3).
46    pub max_version: TlsVersion,
47    /// Colon-separated list of cipher suites in OpenSSL format.
48    ///
49    /// Precision in the order of this list is critical as it directly
50    /// impacts the JA3/JA4 fingerprint.
51    pub cipher_list: &'static str,
52    /// Numeric IDs for supported elliptic curve groups.
53    pub curves: &'static [u16],
54    /// Whether to enable TLS GREASE (RFC 8701) to simulate randomized extensions.
55    pub grease_enabled: bool,
56    /// Whether to permute (shuffle) TLS extensions per connection.
57    pub permute_extensions: bool,
58    /// Whether to send a dummy ECH (Encrypted Client Hello) extension for GREASE.
59    pub enable_ech_grease: bool,
60    /// Whether to enable ALPS (Application-Layer Protocol Settings).
61    pub alps_enabled: bool,
62    /// Whether to use the draft-01 or final ALPS codepoint.
63    pub alps_use_new_codepoint: bool,
64    /// Additional H2 SETTINGS IDs to append in the ALPS payload.
65    ///
66    /// Windows and Linux Chrome include an extra setting (ID 31386) in the
67    /// ALPS handshake data that macOS omits. Each tuple is `(id, value)`.
68    pub alps_extra_settings: &'static [(u16, u32)],
69    /// Whether to support RFC 8879 certificate compression (Brotli).
70    pub compress_certificate: bool,
71    /// Whether to enable stateless session tickets for fast reconnection.
72    pub session_ticket_enabled: bool,
73    /// Ordered list of ALPN protocol identifiers.
74    pub alpn_protocols: &'static [&'static [u8]],
75    /// Ordered list of signature algorithm IDs (used for JA4_r).
76    pub sigalgs: &'static [u16],
77}
78
79/// Initial HTTP/2 SETTINGS frame parameters.
80///
81/// The values and the *order* in which they are sent are used by Akamai
82/// and other WAFs to identify the client implementation.
83#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub struct SettingsFrame {
85    /// SETTINGS_HEADER_TABLE_SIZE (ID 0x1).
86    pub header_table_size: u32,
87    /// SETTINGS_ENABLE_PUSH (ID 0x2).
88    pub enable_push: bool,
89    /// SETTINGS_INITIAL_WINDOW_SIZE (ID 0x4).
90    pub initial_window_size: u32,
91    /// SETTINGS_MAX_HEADER_LIST_SIZE (ID 0x6).
92    pub max_header_list_size: u32,
93}
94
95/// Configuration for the HTTP/2 protocol layer.
96///
97/// Defines the Layer 5 identity, focusing on behavioral markers like
98/// pseudo-header ordering and stream priority.
99#[derive(Debug, Clone, Copy, PartialEq, Eq)]
100pub struct Http2Profile {
101    /// Initial SETTINGS frame values and order.
102    pub settings: SettingsFrame,
103    /// Total connection-level window size (default + delta).
104    ///
105    /// This value determines the initial `WINDOW_UPDATE` frame increment
106    /// sent immediately after the handshake. Chrome uses a specific non-standard
107    /// increment that acts as a strong identity signal.
108    pub initial_connection_window_size: u32,
109    /// Ordering of pseudo-headers (e.g., :method, :authority, :scheme, :path).
110    pub pseudo_order: [PseudoOrder; 4],
111    /// Priority parameters for the initial HEADERS frame.
112    pub headers_priority: HeadersPriority,
113}
114
115/// Stream priority parameters embedded in the HEADERS frame.
116#[derive(Debug, Clone, Copy, PartialEq, Eq)]
117pub struct HeadersPriority {
118    /// Stream ID that this request depends on (typically 0).
119    pub dep: u32,
120    /// Priority weight (0-255).
121    pub weight: u8,
122    /// Whether this dependency is exclusive.
123    pub exclusive: bool,
124}
125
126/// Canonical HTTP/2 pseudo-header identifiers.
127#[derive(Debug, Clone, Copy, PartialEq, Eq)]
128pub enum PseudoOrder {
129    /// `:method`
130    Method,
131    /// `:authority`
132    Authority,
133    /// `:scheme`
134    Scheme,
135    /// `:path`
136    Path,
137}
138
139/// Chrome-specific HTTP header values and Client Hint metadata.
140///
141/// These values are injected into every outbound request and must match
142/// the declared platform. WAFs cross-check `sec-ch-ua-platform` against
143/// the TLS handshake and TCP stack to detect spoofed identities.
144#[derive(Debug, Clone, PartialEq, Eq)]
145pub struct HeaderProfile {
146    /// Full `User-Agent` header value.
147    pub user_agent: String,
148    /// `sec-ch-ua` Client Hint brand list.
149    pub sec_ch_ua: String,
150    /// `sec-ch-ua-platform` Client Hint (e.g., `"macOS"`, `"Windows"`, `"Linux"`).
151    pub sec_ch_ua_platform: String,
152    /// `sec-ch-ua-platform-version` Client Hint.
153    ///
154    /// Must match the host OS: Windows 11 reports `"13.0.0"`,
155    /// macOS Sequoia reports `"15.0.0"`, Linux reports `"0.0.0"`.
156    pub sec_ch_ua_platform_version: String,
157    /// Whether to include the RFC 9218 `priority` header (e.g., `u=0, i`).
158    pub include_priority_header: bool,
159    /// Whether to advertise `zstd` in the `accept-encoding` header.
160    pub zstd_encoding: bool,
161}
162
163/// A complete, multi-layer identity profile for a Chrome instance.
164///
165/// Combines TLS, HTTP/2, and HTTP metadata into a single configuration
166/// that, when applied, makes the transport layer indistinguishable from
167/// the specified Chrome version and platform.
168#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct ChromeProfile {
170    /// Major Chrome version (e.g., `134`).
171    pub version: u32,
172    /// Target operating system and architecture.
173    pub platform: Platform,
174    /// TLS handshake configuration (JA3/JA4 fingerprint source).
175    pub tls: TlsProfile,
176    /// HTTP/2 handshake configuration (Akamai fingerprint source).
177    pub h2: Http2Profile,
178    /// HTTP-level metadata and Client Hints.
179    pub headers: HeaderProfile,
180}