Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cloudflare/boring still vendors BoringSSL e2a57cfb4, which predates
# SSL_CTX_set_grease_sigalgs_enabled (Chrome 152 GREASE in signature_algorithms).
# Point boring-sys at a newer upstream checkout and skip cloudflare's PQ
# patch — current BoringSSL already has ML-KEM/ML-DSA natively.
[env]
BORING_BSSL_SOURCE_PATH = { value = "vendor/boringssl", relative = true }
BORING_BSSL_ASSUME_PATCHED = "1"
27 changes: 26 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: '3.12'
Expand Down Expand Up @@ -55,6 +57,8 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}
Expand Down Expand Up @@ -95,6 +99,8 @@ jobs:
needs: test
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: '3.x'
Expand Down Expand Up @@ -148,6 +154,8 @@ jobs:
- { target: armv7l, manylinux: musllinux_1_1 }
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}
Expand Down Expand Up @@ -261,6 +269,8 @@ jobs:
python_version: [ '3.10', '3.13t', '3.14t' ]
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
if: matrix.target != 'aarch64'
with:
Expand Down Expand Up @@ -311,6 +321,8 @@ jobs:
python_version: [ '3.10', '3.13t', '3.14t' ]
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version == '3.13t' && '3.13' || matrix.python_version == '3.14t' && '3.14' || matrix.python_version }}
Expand Down Expand Up @@ -343,6 +355,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
Expand All @@ -362,6 +376,8 @@ jobs:
hashes: ${{ steps.compute.outputs.hashes }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
with:
submodules: recursive
- uses: actions/setup-python@v6
with:
python-version: '3.12'
Expand Down Expand Up @@ -415,8 +431,17 @@ jobs:
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
gh release upload ${{ github.ref_name }} dist/* --repo ${{ github.repository }}
if ! gh release view "${{ github.ref_name }}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
gh release create "${{ github.ref_name }}" \
--title "${{ github.ref_name }}" \
--generate-notes \
--repo "${{ github.repository }}"
fi
gh release upload "${{ github.ref_name }}" dist/* --repo "${{ github.repository }}" --clobber
# Upstream (jawah/utls) publishes to PyPI. Forks attach wheels to the
# GitHub Release only — the package name `utls` is already taken.
- name: Publish to PyPI
if: github.repository == 'jawah/utls'
uses: "pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e"
with:
attestations: true
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/boringssl"]
path = vendor/boringssl
url = https://github.com/google/boringssl.git
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Release History
===============

2026.9.3
--------

- Added `chrome:152` profile and moved `chrome:stable` to it. Chrome 152
is the first stable major to send the `trust_anchors` extension
(`0xCA34`, draft-ietf-tls-trust-anchor-ids) with the Chrome Root Store
ID list. Cipher suites, groups, and ML-DSA signature algorithms are
unchanged from `chrome:150`; the extra extension changes the JA4 from
`t13d1516h2_…` to `t13d1517h2_8daaf6152771_cb7bf5808d99`.
- `trust_anchors` is now a first-class Fingerprint field, applied via
BoringSSL's `SSL_set1_requested_trust_anchors`.
- Chrome 152 also prepends a per-connection GREASE value to
`signature_algorithms` (visible in PeetPrint, stripped from JA4).
Wired via `SSL_CTX_set_grease_sigalgs_enabled`. Builds compile
BoringSSL from `vendor/boringssl` because `cloudflare/boring`'s
vendored snapshot still predates this API.

2026.7.8
--------

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ members = [
]

[workspace.package]
version = "2026.7.8"
version = "2026.9.3"
edition = "2021"
rust-version = "1.75"
license = "MIT"
repository = "https://github.com/jawah/utls"
homepage = "https://github.com/jawah/utls"
repository = "https://github.com/xiaoweigege/utls"
homepage = "https://github.com/xiaoweigege/utls"
authors = ["Ahmed TAHRI"]

[workspace.dependencies]
# Pinned to a cloudflare/boring master commit for ML-DSA
# cloudflare/boring FFI. The C library itself is compiled from
# vendor/boringssl (see .cargo/config.toml) so we pick up
# SSL_CTX_set_grease_sigalgs_enabled, which this crate's vendored
# snapshot (e2a57cfb4) does not yet contain.
boring-sys = { git = "https://github.com/cloudflare/boring", rev = "931385ed41df448c82d150219f69af56e3c8399f" }
libc = "0.2"
thiserror = "1"
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ BoringSSL-backed TLS for CPython, with Chrome impersonation
-----------------------------------------------------------

Drop-in replacement for the `ssl` stdlib with a `Fingerprint` API for Chrome
impersonation. Built on stock BoringSSL through `boring-sys` - no vendored
patches, no curl-impersonate, no Go runtime at import time. Use it with any
known Python http client you like or used to.
impersonation. Built on stock BoringSSL through `boring-sys` - no
curl-impersonate, no Go runtime at import time. Use it with any known
Python http client you like or used to.

Supports CPython 3.7 onward, including freethreaded builds.

Expand Down Expand Up @@ -37,10 +37,23 @@ are read and merged.

### Getting Started

Install from PyPI (pre-built wheels for Linux, macOS, and Windows):
Install a pre-built wheel from GitHub Releases (Linux, macOS, Windows):

```
pip install utls
# copy the wheel URL for your platform from
# https://github.com/xiaoweigege/utls/releases
pip install https://github.com/xiaoweigege/utls/releases/download/2026.9.3/utls-2026.9.3-cp37-abi3-macosx_11_0_arm64.whl
```

Upstream PyPI (`pip install utls`) is the original `jawah/utls` package and
does not include these Chrome 152 changes.

From source, initialize the BoringSSL checkout first (Chrome 152 GREASE
in `signature_algorithms` needs a snapshot newer than the one bundled
with `cloudflare/boring`):

```
git submodule update --init --recursive
```

Then swap `ssl` for `utls` anywhere in your code:
Expand Down Expand Up @@ -103,7 +116,7 @@ The bundled profile registry can be inspected at runtime:
from utls import Fingerprint, presets

print(presets())
# ['chrome:131', 'chrome:142', 'chrome:146', 'chrome:148', 'chrome:150', 'chrome:stable']
# ['chrome:131', 'chrome:142', 'chrome:146', 'chrome:148', 'chrome:150', 'chrome:152', 'chrome:stable']

fp = Fingerprint.from_preset("chrome:stable")
print(fp.ja3_hash, fp.ja4_hash)
Expand Down Expand Up @@ -159,10 +172,10 @@ For HTTP/1.1, prepend `Host` at position 0 to preserve Chrome's wire order.

- `chrome:stable` always tracks the newest Chrome major shipped in a utls
release. Use this if you want to drift with Chrome without code changes.
- `chrome:148`, `chrome:146`, `chrome:142`, `chrome:131` pin to specific
Chrome majors. Use these when reproducibility matters - e.g. a long-
running scraper that should not silently change shape when utls is
upgraded.
- `chrome:152`, `chrome:150`, `chrome:148`, `chrome:146`, `chrome:142`,
`chrome:131` pin to specific Chrome majors. Use these when
reproducibility matters - e.g. a long-running scraper that should not
silently change shape when utls is upgraded.

The JA4 hash is the fingerprint identity that bot-detection vendors and
TLS observatories actually index on. `chrome:142` / `chrome:146` /
Expand All @@ -171,7 +184,8 @@ ClientHello (the deltas are HTTP-layer); `chrome:131` differs because it
uses the legacy ALPS codepoint (`0x4469` vs `0x44cd`). `chrome:150` also
differs: it is the first stable major to advertise post-quantum ML-DSA
(FIPS 204) signature algorithms, which changes the `signature_algorithms`
bytes and therefore the JA4.
bytes and therefore the JA4. `chrome:152` adds the `trust_anchors`
extension (`0xCA34`), taking the JA4 extension count from 16 to 17.

#### Why JA3 varies but JA4 stays put

Expand Down
34 changes: 32 additions & 2 deletions crates/utls-core/src/fingerprint/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
//! * `alpn` - `SSL_set_alpn_protos`.
//! * `alps` - `SSL_add_application_settings`.
//! * `grease` - `SSL_CTX_set_grease_enabled`.
//! * `grease_sigalgs` - `SSL_CTX_set_grease_sigalgs_enabled` (Chrome 152+).
//! * `compress_certificate` - `SSL_CTX_add_cert_compression_alg`.
//! * `extension order permutation` - `SSL_set_permute_extensions`
//! (matches Chrome 110+ random-per-handshake behaviour).
//! * `status_request` / `signed_certificate_timestamp` - `SSL_enable_*`.
//! * `trust_anchors` (`0xCA34`) - `SSL_set1_requested_trust_anchors`.
//!
//! ## What we deliberately do **not** do
//!
Expand All @@ -35,7 +37,7 @@
use std::ffi::CString;
use std::os::raw::c_int;

use super::spec::{EchPolicy, Fingerprint};
use super::spec::{EchPolicy, Fingerprint, TRUST_ANCHORS_EXTENSION};
use crate::error::{Error, Result};

/// Apply `fp` to `ssl`.
Expand Down Expand Up @@ -75,6 +77,7 @@ pub unsafe fn apply(
apply_record_size_limit(fp, ssl)?;
apply_ech(fp, ssl)?;
apply_padding(fp, ssl)?;
apply_trust_anchors(fp, ssl)?;
}
Ok(())
}
Expand Down Expand Up @@ -384,7 +387,8 @@ unsafe fn apply_grease(fp: &Fingerprint, ssl: *mut boring_sys::SSL) -> Result<()
// extensions (one prepended, one appended to the extension permutation
// built by `ssl_setup_extension_permutation`) plus the GREASE entries
// sprinkled into the cipher list, supported_groups, supported_versions,
// and key_share.
// and key_share. GREASE inside `signature_algorithms` is a *separate*
// knob (`SSL_CTX_set_grease_sigalgs_enabled`); Chrome 152+ turns it on.
//
// The toggle is per-CTX, not per-SSL. Because utls's fingerprint lives
// on the context (one fingerprint per Context, applied to every SSL
Expand All @@ -399,6 +403,10 @@ unsafe fn apply_grease(fp: &Fingerprint, ssl: *mut boring_sys::SSL) -> Result<()
}
let enabled = if fp.grease { 1 } else { 0 };
unsafe { boring_sys::SSL_CTX_set_grease_enabled(ctx, enabled) };
// Chrome 152+: prepend a per-connection GREASE value to signature_algorithms.
// Independent of `grease_enabled` until BoringSSL folds the two together.
let sigalgs_enabled = if fp.grease && fp.grease_sigalgs { 1 } else { 0 };
unsafe { boring_sys::SSL_CTX_set_grease_sigalgs_enabled(ctx, sigalgs_enabled) };
Ok(())
}

Expand Down Expand Up @@ -536,3 +544,25 @@ unsafe fn apply_padding(_fp: &Fingerprint, _ssl: *mut boring_sys::SSL) -> Result
// patch (tracked: `0005-clienthello-padding-target.patch`).
Ok(())
}

/// Emit the `trust_anchors` (0xCA34) extension.
///
/// Driven primarily by `fp.trust_anchors`. If that is `None` but
/// `extensions_order` lists 0xCA34, we still send an empty list so the
/// codepoint appears on the wire (JA4 counts it; an empty list is a
/// valid "retry-flow only" advertisement).
unsafe fn apply_trust_anchors(fp: &Fingerprint, ssl: *mut boring_sys::SSL) -> Result<()> {
let ids: &[u8] = match &fp.trust_anchors {
Some(v) => v.as_slice(),
None if fp.extensions_order.contains(&TRUST_ANCHORS_EXTENSION) => &[],
None => return Ok(()),
};
// SAFETY: `ssl` is a valid pre-handshake *mut SSL; BoringSSL copies
// `(ids, ids_len)` internally. An empty slice is documented to still
// emit the extension.
let rc = unsafe { boring_sys::SSL_set1_requested_trust_anchors(ssl, ids.as_ptr(), ids.len()) };
if rc != 1 {
return Err(Error::from_boring_queue("SSL_set1_requested_trust_anchors"));
}
Ok(())
}
22 changes: 21 additions & 1 deletion crates/utls-core/src/fingerprint/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
//! All slicing is bounds-checked. Malformed input returns
//! [`Error::Usage`] with a clear message; it never panics.

use super::spec::{CertCompressAlg, EchPolicy, Fingerprint, GREASE_EXTENSION};
use super::spec::{
CertCompressAlg, EchPolicy, Fingerprint, GREASE_EXTENSION, TRUST_ANCHORS_EXTENSION,
};
use crate::error::{Error, Result};

const TLS_HANDSHAKE_RECORD: u8 = 0x16;
Expand Down Expand Up @@ -199,6 +201,11 @@ fn parse_extension(ext_type: u16, body: &[u8], fp: &mut Fingerprint) -> Result<(
21 => {
fp.padding = Some(body.len());
}
// trust_anchors (0xCA34): TLS body is 2-byte length + 8-bit
// length-prefixed IDs. BoringSSL wants the inner ID list.
x if x == TRUST_ANCHORS_EXTENSION => {
fp.trust_anchors = Some(parse_trust_anchor_ids(body));
}
_ => {
// Unknown / not modeled - extension is preserved in
// `extensions_order` so the shape is reproduced.
Expand All @@ -207,6 +214,19 @@ fn parse_extension(ext_type: u16, body: &[u8], fp: &mut Fingerprint) -> Result<(
Ok(())
}

/// Strip the TLS extension's outer 2-byte length prefix. A truncated or
/// empty body becomes an empty ID list (still means "send the extension").
fn parse_trust_anchor_ids(body: &[u8]) -> Vec<u8> {
if body.len() < 2 {
return Vec::new();
}
let declared = u16::from_be_bytes([body[0], body[1]]) as usize;
let rest = &body[2..];
rest.get(..declared.min(rest.len()))
.unwrap_or(rest)
.to_vec()
}

#[inline]
fn is_grease(v: u16) -> bool {
// GREASE values per RFC 8701 - both bytes equal and high nibble == 0xA.
Expand Down
Loading