diff --git a/Cargo.lock b/Cargo.lock index 3d0932ee7..bb87702a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,6 +93,7 @@ dependencies = [ "libc", "openssl-macros", "rusty-hook", + "zstd", ] [[package]] @@ -139,6 +140,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex 2.0.1", ] @@ -395,6 +398,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + [[package]] name = "glob" version = "0.3.4" @@ -579,6 +593,16 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom", + "libc", +] + [[package]] name = "libc" version = "0.2.191" @@ -740,6 +764,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + [[package]] name = "proc-macro2" version = "1.0.107" @@ -758,6 +788,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "redox_syscall" version = "0.5.18" @@ -952,6 +988,7 @@ dependencies = [ "futures", "linked_hash_set", "tokio", + "zstd", ] [[package]] @@ -1104,3 +1141,31 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] + +[[package]] +name = "zstd" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad5020ab8f27bfc0024ad0a07aed6bf022a16208f479686fbed4fdd0c85eb0b3" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "8.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9ea9cc2576c2fcc104e9cec04f46e3ede564f4fbc206831e4ef7e859a4140d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.1.3+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f729a06d0257428fd9d997ac8db7e1407bd0262ab016b085b36bc52957c0052d" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 35f61a0e2..1dd9a21d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ bindgen = { version = "0.72.0", default-features = false, features = ["runtime"] bitflags = "2.9" brotli = "9.0" flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] } +zstd = { version = "0.14.4", default-features = false } bytes = "1" cmake = "0.1.54" fs_extra = "1.3.0" diff --git a/boring-sys/patches/client-fingerprint.patch b/boring-sys/patches/client-fingerprint.patch index 2351e0dda..99597d54b 100644 --- a/boring-sys/patches/client-fingerprint.patch +++ b/boring-sys/patches/client-fingerprint.patch @@ -1,25 +1,27 @@ diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h +index 67b6537..8272cde 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h -@@ -5688,6 +5688,14 @@ - // SSL_set_permute_extensions configures whether sockets on `ssl` should +@@ -5689,6 +5689,14 @@ OPENSSL_EXPORT void SSL_CTX_set_permute_extensions(SSL_CTX *ctx, int enabled); // permute extensions. For now, this is only implemented for the ClientHello. OPENSSL_EXPORT void SSL_set_permute_extensions(SSL *ssl, int enabled); -+ + +// Opt-in named profile encoding from this fork. Only built-in, implemented -+// profile IDs are accepted (1 = Chrome120, 2 = Chrome133, 3 = Firefox120, -+// 4 = Safari16, 5 = iOS14, 6 = Android11, 7 = Edge85, -+// 8 = 360 7.5, 9 = QQ 11.1). ++// profile IDs are accepted (1 = Chrome120, 5 = iOS14, 6 = Android11, ++// 7 = Edge85, 8 = 360 7.5, 9 = QQ 11.1, 10 = Chrome155, ++// 11 = Firefox148, 12 = Safari26.3). IDs 2 through 4 are retired. +// Trust, versions, ALPN and sessions remain caller-owned. +// Fresh stream clients only; no raw ClientHello API. +OPENSSL_EXPORT int SSL_set_client_fingerprint(SSL *ssl, unsigned profile); - ++ // SSL_max_seal_overhead returns the maximum overhead, in bytes, of sealing a // record with `ssl`. + OPENSSL_EXPORT size_t SSL_max_seal_overhead(const SSL *ssl); diff --git a/ssl/encrypted_client_hello.cc b/ssl/encrypted_client_hello.cc +index a8bec51..3698205 100644 --- a/ssl/encrypted_client_hello.cc +++ b/ssl/encrypted_client_hello.cc -@@ -741,9 +741,13 @@ +@@ -741,9 +741,13 @@ static bool setup_ech_grease(SSL_HANDSHAKE *hs) { } const uint16_t kdf_id = EVP_HPKE_HKDF_SHA256; @@ -27,51 +29,52 @@ diff --git a/ssl/encrypted_client_hello.cc b/ssl/encrypted_client_hello.cc - ? EVP_hpke_aes_128_gcm() - : EVP_hpke_chacha20_poly1305(); + // Chrome's GREASE shape is fixed by its template, not the local CPU. -+ const bool has_aes_hw = hs->config->client_fingerprint == 3 -+ ? random_size(0, 1) != 0 -+ : hs->config->client_fingerprint != 0 || -+ EVP_has_aes_hardware(); ++ const uint8_t profile = hs->config->client_fingerprint; ++ const bool firefox = profile == kFirefox148Fingerprint; ++ const bool use_aes = firefox ? random_size(0, 1) != 0 ++ : profile != 0 || EVP_has_aes_hardware(); + const EVP_HPKE_AEAD *aead = -+ has_aes_hw ? EVP_hpke_aes_128_gcm() : EVP_hpke_chacha20_poly1305(); ++ use_aes ? EVP_hpke_aes_128_gcm() : EVP_hpke_chacha20_poly1305(); static_assert(ssl_grease_ech_config_id < sizeof(hs->grease_seed), "hs->grease_seed is too small"); uint8_t config_id = hs->grease_seed[ssl_grease_ech_config_id]; -@@ -768,7 +772,8 @@ +@@ -768,7 +772,8 @@ static bool setup_ech_grease(SSL_HANDSHAKE *hs) { // estimate maximum_name_length to be between 32 and 100 bytes. Then round up // to a multiple of 32, to match RFC 9849, section 6.1.3. const size_t payload_len = - 32 * random_size(128 / 32, 224 / 32) + aead_overhead(aead); -+ (hs->config->client_fingerprint == 3 -+ ? 223 : 32 * random_size(128 / 32, 224 / 32)) + aead_overhead(aead); ++ (firefox ? 223 : 32 * random_size(128 / 32, 224 / 32)) + ++ aead_overhead(aead); bssl::ScopedCBB cbb; CBB enc_cbb, payload_cbb; uint8_t *payload; diff --git a/ssl/extensions.cc b/ssl/extensions.cc +index 2df6fbc..b62b20e 100644 --- a/ssl/extensions.cc +++ b/ssl/extensions.cc -@@ -364,6 +364,13 @@ - continue; - } +@@ -366,6 +366,13 @@ bool tls12_add_verify_sigalgs(const SSL_HANDSHAKE *hs, CBB *out) { if (!CBB_add_u16(out, sigalg)) { -+ return false; -+ } -+ // Safari repeats this signature scheme. Keep real verification preferences -+ // unique and preserve the duplicate only in the final transcript encoding. -+ if ((hs->config->client_fingerprint == 4 || -+ hs->config->client_fingerprint == 5) && sigalg == 0x0805 && -+ !CBB_add_u16(out, sigalg)) { return false; } ++ // The Safari and iOS templates repeat this scheme. Keep native ++ // verification preferences unique and repeat only in the transcript. ++ const uint8_t profile = hs->config->client_fingerprint; ++ if ((profile == 5 || profile == kSafari263Fingerprint) && ++ sigalg == SSL_SIGN_RSA_PSS_RSAE_SHA384 && !CBB_add_u16(out, sigalg)) { ++ return false; ++ } } -@@ -966,6 +973,15 @@ + return true; + } +@@ -966,6 +973,15 @@ static bool ext_ticket_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, SSL_get_options(ssl) & SSL_OP_NO_TICKET) { return true; } -+ // Safari, iOS and Android cold templates omit this extension. A caller's -+ // actual TLS1.2 ticket may still be offered; warm policy is caller-owned. -+ if ((hs->config->client_fingerprint == 4 || -+ hs->config->client_fingerprint == 5 || -+ hs->config->client_fingerprint == 6) && ++ // These cold templates omit this extension. A caller's actual TLS 1.2 ++ // ticket may still be offered. ++ const uint8_t profile = hs->config->client_fingerprint; ++ if ((profile == 5 || profile == 6 || ++ profile == kFirefox148Fingerprint || profile == kSafari263Fingerprint) && + (ssl->session == nullptr || + ssl_session_get_type(ssl->session.get()) != SSLSessionType::kTicket)) { + return true; @@ -79,35 +82,85 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc // Renegotiation does not participate in session resumption. However, still // advertise the extension to avoid potentially breaking servers which carry -@@ -1052,7 +1068,9 @@ +@@ -1052,7 +1068,10 @@ static bool ext_sigalgs_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, return false; } // Add a fake signature algorithm. See RFC 8701. - if (hs->ssl->ctx->grease_enabled && -+ // Fixed profiles retain their declared signature list; the unconfigured -+ // path continues to use the native signature-algorithm GREASE extension. -+ if (hs->config->client_fingerprint == 0 && hs->ssl->ctx->grease_enabled && ++ // Chrome 155 and the unconfigured path include signature-algorithm GREASE. ++ const uint8_t profile = hs->config->client_fingerprint; ++ if ((profile == 0 || profile == kChrome155Fingerprint) && ++ hs->ssl->ctx->grease_enabled && !CBB_add_u16(&sigalgs_cbb, ssl_get_grease_value(hs, ssl_grease_signature_algorithm))) { return false; -@@ -2779,6 +2797,12 @@ +@@ -2268,9 +2287,11 @@ static bool ext_psk_key_exchange_modes_add_clienthello( + if (hs->max_version < TLS1_3_VERSION) { + return true; + } +- // We do not support resumption with PAKEs, so do not offer any PSK key +- // exchange modes, to signal the server not to send a ticket. +- if (hs->pake_prover != nullptr) { ++ // Firefox 148 omits PSK modes in its cold template. Preserve the native ++ // modes and binder when a caller supplies an eligible TLS 1.3 PSK. ++ if (hs->pake_prover != nullptr || ++ (hs->config->client_fingerprint == kFirefox148Fingerprint && ++ !should_offer_psk(hs, type))) { + return true; + } + +@@ -2503,13 +2524,28 @@ bool ssl_setup_key_shares(SSL_HANDSHAKE *hs, uint16_t override_group_id) { + } + } + ++ const bool shared_x25519 = override_group_id == 0 && ++ hs->config->client_fingerprint == kFirefox148Fingerprint; ++ const SSLKeyShare *hybrid = nullptr; + CBB key_exchange; + for (const uint16_t group_id : *selected_key_shares) { +- UniquePtr key_share = SSLKeyShare::Create(group_id); +- if (key_share == nullptr || // +- !CBB_add_u16(cbb.get(), group_id) || // +- !CBB_add_u16_length_prefixed(cbb.get(), &key_exchange) || // +- !key_share->Generate(&key_exchange) || // ++ if (!CBB_add_u16(cbb.get(), group_id) || ++ !CBB_add_u16_length_prefixed(cbb.get(), &key_exchange)) { ++ return false; ++ } ++ UniquePtr key_share; ++ if (group_id == SSL_GROUP_X25519 && hybrid != nullptr) { ++ key_share = SSLKeyShare::CreateFirefox148Companion(&key_exchange, *hybrid); ++ } else { ++ key_share = SSLKeyShare::Create(group_id); ++ if (key_share != nullptr && !key_share->Generate(&key_exchange)) { ++ return false; ++ } ++ } ++ if (shared_x25519 && group_id == SSL_GROUP_X25519_MLKEM768) { ++ hybrid = key_share.get(); ++ } ++ if (key_share == nullptr || + !hs->key_shares.TryPushBack(std::move(key_share))) { + return false; + } +@@ -2779,6 +2815,12 @@ static bool ext_supported_groups_add_clienthello(const SSL_HANDSHAKE *hs, } } + // uTLS Firefox declares FFDHE but does not implement it. Do not put these + // IDs in the real supported-group/key-share list: selection must fail closed. -+ if (hs->config->client_fingerprint == 3 && ++ if (hs->config->client_fingerprint == kFirefox148Fingerprint && + (!CBB_add_u16(&groups_bytes, 256) || !CBB_add_u16(&groups_bytes, 257))) { + return false; + } return CBB_flush(out_compressible); } -@@ -3315,6 +3339,12 @@ +@@ -3315,6 +3357,12 @@ static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs, static bool ext_delegated_credential_add_clienthello( const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type) { -+ if (hs->config->client_fingerprint == 3) { ++ if (hs->config->client_fingerprint == kFirefox148Fingerprint) { + // Fixed template-only declaration, not delegated credential verification. + static const uint8_t kDeclaration[] = { + 0, 34, 0, 10, 0, 8, 4, 3, 5, 3, 6, 3, 2, 3}; @@ -116,14 +169,14 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc return true; } -@@ -4114,8 +4144,27 @@ +@@ -4114,8 +4162,27 @@ static bool ext_server_cert_type_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) { return true; } +static bool ext_profile_record_limit_add_clienthello( + const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, + ssl_client_hello_type_t type) { -+ if (hs->config->client_fingerprint != 3) { ++ if (hs->config->client_fingerprint != kFirefox148Fingerprint) { + return true; + } + // uTLS's FakeRecordSizeLimitExtension. A response is explicitly rejected; @@ -144,15 +197,17 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc { TLSEXT_TYPE_server_name, ext_sni_add_clienthello, -@@ -4355,6 +4404,63 @@ +@@ -4355,6 +4422,65 @@ static_assert(kNumExtensions <= "too many extensions for received bitset"); bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs) { -+ if (hs->config->client_fingerprint >= 3 && -+ hs->config->client_fingerprint <= 9) { -+ static const uint16_t kFirefox[] = { -+ 0, 23, 65281, 10, 11, 35, 16, 5, 34, 51, 43, 13, 45, 28, 65037}; -+ static const uint16_t kSafari[] = { ++ const uint8_t profile = hs->config->client_fingerprint; ++ if ((profile >= 5 && profile <= 9) || profile == kFirefox148Fingerprint || ++ profile == kSafari263Fingerprint) { ++ static const uint16_t kFirefox148[] = { ++ 0, 23, 65281, 10, 11, 16, 5, 34, 18, 51, 43, 13, 28, 27, 65037, ++ 35, 45}; ++ static const uint16_t kSafari263[] = { + 0, 23, 65281, 10, 11, 16, 5, 13, 18, 51, 45, 43, 27}; + static const uint16_t kIos[] = { + 0, 23, 65281, 10, 11, 16, 5, 13, 18, 51, 45, 43}; @@ -171,9 +226,9 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc + bool used[kNumExtensions] = {}; + size_t at = 0; + Span order; -+ switch (hs->config->client_fingerprint) { -+ case 3: order = kFirefox; break; -+ case 4: order = kSafari; break; ++ switch (profile) { ++ case kFirefox148Fingerprint: order = kFirefox148; break; ++ case kSafari263Fingerprint: order = kSafari263; break; + case 5: order = kIos; break; + case 6: order = kAndroid; break; + case 7: order = kEdge; break; @@ -208,7 +263,7 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc if (!hs->config->permute_extensions) { return true; } -@@ -4510,6 +4616,22 @@ +@@ -4510,6 +4636,22 @@ static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out, return true; } @@ -231,7 +286,7 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded, ssl_client_hello_type_t type) { // `out` must contain the start of a ClientHello, which means it must begin -@@ -4521,6 +4643,7 @@ +@@ -4521,6 +4663,7 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded, return ssl_add_clienthello_tlsext_inner(hs, out, out_encoded); } @@ -239,7 +294,7 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc assert(out_encoded == nullptr); // Only ClientHelloInner needs two outputs. SSLImpl *const ssl = hs->ssl; CBB extensions; -@@ -4575,8 +4698,33 @@ +@@ -4575,8 +4718,34 @@ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded, // intolerant to the last extension being zero-length. See // https://crbug.com/363583. bool offering_psk = should_offer_psk(hs, type); @@ -247,8 +302,9 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc - !SSL_is_quic(ssl) && !ssl->s3->used_hello_retry_request) { + const uint8_t profile = hs->config->client_fingerprint; + if (profile != 0) { -+ // Chrome133, Firefox, Android and 360 do not use conditional padding. -+ if (profile != 2 && profile != 3 && profile != 6 && profile != 8 && ++ // Some fixed templates omit the padding extension. ++ if (profile != 6 && profile != 8 && profile != kChrome155Fingerprint && ++ profile != kFirefox148Fingerprint && profile != kSafari263Fingerprint && + !SSL_is_dtls(ssl) && !SSL_is_quic(ssl) && + !ssl->s3->used_hello_retry_request) { + const size_t psk_len = profile_pre_shared_key_clienthello_length(hs, type); @@ -276,9 +332,10 @@ diff --git a/ssl/extensions.cc b/ssl/extensions.cc return false; } diff --git a/ssl/handshake_client.cc b/ssl/handshake_client.cc +index 3d57f34..db08229 100644 --- a/ssl/handshake_client.cc +++ b/ssl/handshake_client.cc -@@ -122,6 +122,25 @@ +@@ -122,6 +122,26 @@ static bool ssl_write_client_cipher_list(const SSL_HANDSHAKE *hs, CBB *out, continue; } any_enabled = true; @@ -294,8 +351,9 @@ diff --git a/ssl/handshake_client.cc b/ssl/handshake_client.cc + } + } + // Safari/iOS declare ECDHE-ECDSA-3DES without implementing it. -+ if ((hs->config->client_fingerprint == 4 || -+ hs->config->client_fingerprint == 5) && id == 0xc012) { ++ const uint8_t profile = hs->config->client_fingerprint; ++ if ((profile == 5 || profile == kSafari263Fingerprint) && ++ id == 0xc012) { + declaration = 0xc008; + } + if (declaration != 0 && !CBB_add_u16(&child, declaration)) { @@ -305,9 +363,34 @@ diff --git a/ssl/handshake_client.cc b/ssl/handshake_client.cc return false; } diff --git a/ssl/internal.h b/ssl/internal.h +index 0872532..b916a34 100644 --- a/ssl/internal.h +++ b/ssl/internal.h -@@ -3417,6 +3417,9 @@ +@@ -893,6 +893,11 @@ bool ssl_public_key_verify(SSLImpl *ssl, Span signature, + Span in); + + ++// Additive native IDs for the newer fixed ClientHello profiles. ++constexpr uint8_t kChrome155Fingerprint = 10; ++constexpr uint8_t kFirefox148Fingerprint = 11; ++constexpr uint8_t kSafari263Fingerprint = 12; ++ + // Key shares. + + // SSLKeyShare abstracts over KEM-like constructions, for use with TLS 1.2 ECDHE +@@ -913,6 +918,11 @@ class SSLKeyShare { + // nullptr on error. + static UniquePtr Create(uint16_t group_id); + ++ // CreateFirefox148Companion emits a standalone X25519 share with the ++ // classical component of this handshake's already generated hybrid share. ++ static UniquePtr CreateFirefox148Companion( ++ CBB *out_public_key, const SSLKeyShare &hybrid); ++ + // GroupID returns the group ID. + virtual uint16_t GroupID() const = 0; + +@@ -3417,6 +3427,9 @@ struct SSL_CONFIG { X509_VERIFY_PARAM *param = nullptr; @@ -318,9 +401,10 @@ diff --git a/ssl/internal.h b/ssl/internal.h UniquePtr cipher_list; // for TLS 1.2 ciphers. diff --git a/ssl/ssl_cipher.cc b/ssl/ssl_cipher.cc +index 973a7bb..b9e3c71 100644 --- a/ssl/ssl_cipher.cc +++ b/ssl/ssl_cipher.cc -@@ -77,6 +77,19 @@ +@@ -77,6 +77,19 @@ static constexpr SSL_CIPHER kCiphers[] = { SSL_HANDSHAKE_MAC_DEFAULT, }, @@ -340,14 +424,10 @@ diff --git a/ssl/ssl_cipher.cc b/ssl/ssl_cipher.cc // PSK cipher suites. // Cipher 8C -@@ -187,6 +200,19 @@ - SSL_kECDHE, - SSL_aECDSA, - SSL_AES256, -+ SSL_SHA1, -+ SSL_HANDSHAKE_MAC_DEFAULT, -+ }, -+ +@@ -191,6 +204,19 @@ static constexpr SSL_CIPHER kCiphers[] = { + SSL_HANDSHAKE_MAC_DEFAULT, + }, + + // Opt-in profile patch: reuse native ECDHE/RSA and 3DES primitives for + // Safari's real, selectable legacy suite. Deprecated/default-off as 3DES. + { @@ -357,10 +437,14 @@ diff --git a/ssl/ssl_cipher.cc b/ssl/ssl_cipher.cc + SSL_kECDHE, + SSL_aRSA_SIGN, + SSL_3DES, - SSL_SHA1, - SSL_HANDSHAKE_MAC_DEFAULT, - }, -@@ -782,6 +808,7 @@ ++ SSL_SHA1, ++ SSL_HANDSHAKE_MAC_DEFAULT, ++ }, ++ + // Cipher C013 + { + TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA, +@@ -782,6 +808,7 @@ bool ssl_cipher_is_deprecated(const SSL_CIPHER *cipher) { return cipher->protocol_id == SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 || cipher->protocol_id == SSL_CIPHER_ECDHE_RSA_WITH_AES_128_CBC_SHA256 || @@ -368,7 +452,7 @@ diff --git a/ssl/ssl_cipher.cc b/ssl/ssl_cipher.cc cipher->algorithm_enc == SSL_3DES; } -@@ -1172,10 +1199,12 @@ +@@ -1172,10 +1199,12 @@ bool ssl_create_cipher_list(UniquePtr *out_cipher_list, SSL_CIPHER_RSA_WITH_AES_128_GCM_SHA256, SSL_CIPHER_RSA_WITH_AES_256_GCM_SHA384, SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA, @@ -381,19 +465,85 @@ diff --git a/ssl/ssl_cipher.cc b/ssl/ssl_cipher.cc }; // Set up a linked list of ciphers. +diff --git a/ssl/ssl_key_share.cc b/ssl/ssl_key_share.cc +index 2f006e9..3ad9eb5 100644 +--- a/ssl/ssl_key_share.cc ++++ b/ssl/ssl_key_share.cc +@@ -189,10 +189,27 @@ class X25519KeyShare : public SSLKeyShare { + return true; + } + +- private: ++ protected: + uint8_t private_key_[32]; + }; + ++class Firefox148X25519KeyShare final : public X25519KeyShare { ++ public: ++ ~Firefox148X25519KeyShare() override { ++ OPENSSL_cleanse(private_key_, sizeof(private_key_)); ++ } ++ ++ bool GenerateFrom(CBB *out, const uint8_t private_key[32]) { ++ uint8_t public_key[X25519_PUBLIC_VALUE_LEN]; ++ X25519_public_from_private(public_key, private_key); ++ if (!CBB_add_bytes(out, public_key, sizeof(public_key))) { ++ return false; ++ } ++ OPENSSL_memcpy(private_key_, private_key, sizeof(private_key_)); ++ return true; ++ } ++}; ++ + // Kyber768 (round-3, "draft00") is implemented on top of ML-KEM-768. See + // https://words.filippo.io/mlkem768/#bonus-track-using-a-ml-kem-implementation-as-kyber-v3 + constexpr size_t kKyber768PublicKeyBytes = MLKEM768_PUBLIC_KEY_BYTES; +@@ -529,6 +546,7 @@ class X25519MLKEM768KeyShare : public SSLKeyShare { + } + + private: ++ friend class bssl::SSLKeyShare; + uint8_t x25519_private_key_[32]; + MLKEM768_private_key mlkem_private_key_; + }; +@@ -647,6 +665,21 @@ UniquePtr SSLKeyShare::Create(uint16_t group_id) { + } + } + ++UniquePtr SSLKeyShare::CreateFirefox148Companion( ++ CBB *out_public_key, const SSLKeyShare &hybrid) { ++ if (hybrid.GroupID() != SSL_GROUP_X25519_MLKEM768) { ++ return nullptr; ++ } ++ const auto &hybrid_share = static_cast(hybrid); ++ auto classic_share = MakeUnique(); ++ if (classic_share == nullptr || ++ !classic_share->GenerateFrom(out_public_key, ++ hybrid_share.x25519_private_key_)) { ++ return nullptr; ++ } ++ return classic_share; ++} ++ + bool ssl_nid_to_group_id(uint16_t *out_group_id, int nid) { + for (const auto &group : kNamedGroups) { + if (group.nid == nid) { diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc +index 78b8778..562a904 100644 --- a/ssl/ssl_lib.cc +++ b/ssl/ssl_lib.cc -@@ -3324,6 +3324,46 @@ +@@ -3324,6 +3324,55 @@ void SSL_set_permute_extensions(SSL *ssl, int enabled) { ssl_impl->config->permute_extensions = !!enabled; } +int SSL_set_client_fingerprint(SSL *ssl, unsigned profile) { ++ const bool supported_profile = ++ profile == 1 || (profile >= 5 && profile <= kSafari263Fingerprint); + auto *ssl_impl = FromOpaque(ssl); + if (!ssl || !ssl_impl->config || ssl_impl->server || SSL_is_dtls(ssl) || + SSL_is_quic(ssl) || ssl_impl->s3->initial_handshake_complete || + (ssl_impl->s3->hs != nullptr && ssl_impl->s3->hs->max_version != 0) || -+ ssl_impl->config->client_fingerprint != 0 || profile < 1 || profile > 9) { ++ ssl_impl->config->client_fingerprint != 0 || !supported_profile) { + OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return 0; + } @@ -408,11 +558,18 @@ diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc + static const uint16_t kCnsa[] = { + SSL_CIPHER_AES_256_GCM_SHA384, SSL_CIPHER_AES_128_GCM_SHA256, + SSL_CIPHER_CHACHA20_POLY1305_SHA256}; -+ const Span order = -+ profile == 3 ? Span(kFirefox) -+ : ssl_impl->config->compliance_policy == ssl_compliance_policy_cnsa_202407 -+ ? Span(kCnsa) -+ : Span(kChrome); ++ static const uint16_t kSafari263[] = { ++ SSL_CIPHER_AES_256_GCM_SHA384, SSL_CIPHER_CHACHA20_POLY1305_SHA256, ++ SSL_CIPHER_AES_128_GCM_SHA256}; ++ Span order = Span(kChrome); ++ if (profile == kFirefox148Fingerprint) { ++ order = Span(kFirefox); ++ } else if (ssl_impl->config->compliance_policy == ++ ssl_compliance_policy_cnsa_202407) { ++ order = Span(kCnsa); ++ } else if (profile == kSafari263Fingerprint) { ++ order = Span(kSafari263); ++ } + uint16_t ciphers[3]; + size_t num_ciphers = 0; + for (uint16_t cipher : order) { diff --git a/boring/Cargo.toml b/boring/Cargo.toml index 0f7648462..aa2dc7a15 100644 --- a/boring/Cargo.toml +++ b/boring/Cargo.toml @@ -21,7 +21,7 @@ default = [] reality = ["boring-sys/reality"] shadow-tls-v3 = ["reality", "boring-sys/shadow-tls-v3"] jls = ["shadow-tls-v3", "boring-sys/jls"] -client-fingerprint = ["dep:brotli", "dep:flate2", "boring-sys/client-fingerprint"] +client-fingerprint = ["dep:brotli", "dep:flate2", "dep:zstd", "boring-sys/client-fingerprint"] # Use a FIPS-validated version of BoringSSL. fips = ["boring-sys/fips"] @@ -69,6 +69,7 @@ fips-precompiled = ["fips"] [dependencies] brotli = { workspace = true, optional = true } flate2 = { workspace = true, optional = true } +zstd = { workspace = true, optional = true } bitflags = { workspace = true } foreign-types = { workspace = true } openssl-macros = { workspace = true } diff --git a/boring/examples/jls.rs b/boring/examples/jls.rs index 1672d4342..81ad85cda 100644 --- a/boring/examples/jls.rs +++ b/boring/examples/jls.rs @@ -125,9 +125,9 @@ mod probe { let profile = match fields[4] { "none" => None, "chrome120" => Some(ClientFingerprint::Chrome120), - "chrome133" => Some(ClientFingerprint::Chrome133), - "firefox120" => Some(ClientFingerprint::Firefox120), - "safari16" => Some(ClientFingerprint::Safari16), + "chrome155" => Some(ClientFingerprint::Chrome155), + "firefox148" => Some(ClientFingerprint::Firefox148), + "safari263" => Some(ClientFingerprint::Safari263), _ => return Err("input"), }; let mut builder = SslConnector::builder(SslMethod::tls()).map_err(|_| "config")?; diff --git a/boring/examples/reality_hybrid.rs b/boring/examples/reality_hybrid.rs index 948075aac..4737a591c 100644 --- a/boring/examples/reality_hybrid.rs +++ b/boring/examples/reality_hybrid.rs @@ -71,7 +71,7 @@ fn probe() -> Result<(), &'static str> { // Prove that permissive external trust cannot bypass REALITY authentication. builder.set_custom_verify_callback(SslVerifyMode::NONE, |_| Ok(())); let mut configuration = match fields[5] { - "chrome" => FingerprintConnector::new(builder, ClientFingerprint::Chrome133) + "chrome" => FingerprintConnector::new(builder, ClientFingerprint::Chrome155) .map_err(|_| "config")? .configure(b"\x08http/1.1") .map_err(|_| "config")?, diff --git a/boring/examples/shadow_tls_v3.rs b/boring/examples/shadow_tls_v3.rs index cd873d47f..c8e554df9 100644 --- a/boring/examples/shadow_tls_v3.rs +++ b/boring/examples/shadow_tls_v3.rs @@ -306,9 +306,9 @@ mod probe { let profile = match fields[3] { "none" => None, "chrome120" => Some(ClientFingerprint::Chrome120), - "chrome133" => Some(ClientFingerprint::Chrome133), - "firefox120" => Some(ClientFingerprint::Firefox120), - "safari16" => Some(ClientFingerprint::Safari16), + "chrome155" => Some(ClientFingerprint::Chrome155), + "firefox148" => Some(ClientFingerprint::Firefox148), + "safari263" => Some(ClientFingerprint::Safari263), _ => return Err("input"), }; let mut config = if let Some(profile) = profile { diff --git a/boring/src/ssl/fingerprint.rs b/boring/src/ssl/fingerprint.rs index ea7eeb266..b3743644e 100644 --- a/boring/src/ssl/fingerprint.rs +++ b/boring/src/ssl/fingerprint.rs @@ -15,13 +15,6 @@ pub enum ClientFingerprint { /// Chrome 120's classic X25519 profile. Transport ALPN remains caller-owned. /// This does not emulate HTTP/2 settings, QUIC, actual ECH or browser runtime. Chrome120, - /// Chrome 133 with native X25519MLKEM768 + X25519 shares and new h2 ALPS. - /// REALITY requires a separate explicit config; this does not shape QUIC. - Chrome133, - /// Firefox 120, with X25519/P-256 shares and its fixed extension order. - Firefox120, - /// Safari 16.0's stream profile. The caller still owns the TLS version floor. - Safari16, /// iOS 14 stream profile, with CBC-SHA256 offers and no certificate compression. Ios14, /// Android 11 OkHttp's TLS 1.2 profile, without GREASE or compression. @@ -32,6 +25,12 @@ pub enum ClientFingerprint { ThreeSixty75, /// QQ 11.1, including its old-codepoint h2 ALPS declaration. Qq111, + /// Chrome 155.0.8059.40 on macOS, with ML-DSA and advertised trust anchor IDs. + Chrome155, + /// Firefox 148 with a shared X25519 key across its hybrid and classic shares. + Firefox148, + /// Safari 26.3 with native X25519MLKEM768 and X25519 shares and Zlib. + Safari263, } // A closed, bounded catalog, not user-supplied extension/cipher data. The native @@ -48,28 +47,30 @@ struct Profile { sct: bool, ech_grease: bool, alps_new_codepoint: Option, - compression: Compression, + compression: &'static [Compression], + requested_trust_anchors: &'static [u8], + tls12_floor: bool, tls12_only: bool, } enum Compression { - None, Brotli, Zlib, + Zstd, } impl ClientFingerprint { fn profile(self) -> &'static Profile { match self { Self::Chrome120 => &CHROME120, - Self::Chrome133 => &CHROME133, - Self::Firefox120 => &FIREFOX120, - Self::Safari16 => &SAFARI16, Self::Ios14 => &IOS14, Self::Android11 => &ANDROID11, Self::Edge85 => &EDGE85, Self::ThreeSixty75 => &THREE_SIXTY75, Self::Qq111 => &QQ111, + Self::Chrome155 => &CHROME155, + Self::Firefox148 => &FIREFOX148, + Self::Safari263 => &SAFARI263, } } } @@ -95,53 +96,22 @@ const CHROME120: Profile = Profile { sct: true, ech_grease: true, alps_new_codepoint: Some(false), - compression: Compression::Brotli, + compression: &[Compression::Brotli], + requested_trust_anchors: &[], + tls12_floor: false, tls12_only: false, }; -const CHROME133: Profile = Profile { - native_id: 2, - groups: &[4588, 29, 23, 24], - key_shares: &[4588, 29], - alps_new_codepoint: Some(true), - ..CHROME120 -}; - -const FIREFOX120: Profile = Profile { - native_id: 3, - ciphers: concat!( - "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:", - "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:", - "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:", - "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", - "ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:", - "AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA" - ), - groups: &[29, 23, 24, 25], - key_shares: &[29, 23], - signatures: concat!( - "ecdsa_secp256r1_sha256:ecdsa_secp384r1_sha384:ecdsa_secp521r1_sha512:", - "rsa_pss_rsae_sha256:rsa_pss_rsae_sha384:rsa_pss_rsae_sha512:", - "rsa_pkcs1_sha256:rsa_pkcs1_sha384:rsa_pkcs1_sha512:ecdsa_sha1:rsa_pkcs1_sha1" - ), - grease: false, - shuffle: false, - sct: false, - ech_grease: true, - alps_new_codepoint: None, - compression: Compression::None, - tls12_only: false, -}; - -const SAFARI16: Profile = Profile { - native_id: 4, +// Independently implemented from observed uTLS v1.8.8 HelloIOS_14 wire fields. +const IOS14: Profile = Profile { + native_id: 5, ciphers: concat!( "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:", "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:", "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:", - "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", - "ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:", - "AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA:AES128-SHA:", + "ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", + "ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:", + "AES256-GCM-SHA384:AES128-GCM-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:", "ECDHE-RSA-DES-CBC3-SHA:DES-CBC3-SHA" ), groups: &[29, 23, 24, 25], @@ -156,28 +126,12 @@ const SAFARI16: Profile = Profile { sct: true, ech_grease: false, alps_new_codepoint: None, - compression: Compression::Zlib, + compression: &[], + requested_trust_anchors: &[], + tls12_floor: false, tls12_only: false, }; -// Independently implemented from observed uTLS v1.8.8 HelloIOS_14 wire fields. -// It has its own cipher/compression policy; sharing immutable group/signature -// values does not select Safari's native profile or compression extension. -const IOS14: Profile = Profile { - native_id: 5, - ciphers: concat!( - "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:", - "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:", - "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:", - "ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", - "ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:", - "AES256-GCM-SHA384:AES128-GCM-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:", - "ECDHE-RSA-DES-CBC3-SHA:DES-CBC3-SHA" - ), - compression: Compression::None, - ..SAFARI16 -}; - // Fixed upstream profiles: MetaCubeX/utls HelloAndroid_11_OkHttp, // HelloEdge_85, Hello360_7_5 and HelloQQ_11_1. Only implemented negotiation // capabilities are enabled; fake DHE/DSA, RC4 and disabled CBC-SHA256 suites @@ -201,7 +155,7 @@ const ANDROID11: Profile = Profile { sct: false, ech_grease: false, alps_new_codepoint: None, - compression: Compression::None, + compression: &[], tls12_only: true, ..CHROME120 }; @@ -235,6 +189,112 @@ const QQ111: Profile = Profile { ..EDGE85 }; +// The public IDs in the captured Chrome 155 trust_anchors extension. The +// native API takes the one-byte-length-prefixed IDs and encodes the list length. +// https://github.com/refraction-networking/utls/blob/360383f893fbe954ff12a701b87295406abbc156/testdata/chrome155_clienthello.hex +const CHROME155_TRUST_ANCHORS: &[u8] = b"\ + \x05\x82\xdf\x13\x02\x01\ + \x05\x82\xdf\x13\x02\x06\ + \x05\x82\xdf\x13\x02\x0d\ + \x05\x82\xdf\x13\x02\x0e\ + \x05\x82\xdf\x13\x02\x0f\ + \x05\x82\xdf\x13\x02\x12\ + \x05\x82\xdf\x13\x02\x13\ + \x05\x82\xdf\x13\x02\x14\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x07\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x08\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x09\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x0a\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x0b\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x0c\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x0d\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x12\ + \x08\x83\x9a\x64\x8c\x9b\x2d\x01\x13\ + \x04\xd6\x79\x09\x01\ + \x04\xd6\x79\x09\x04\ + \x04\xd6\x79\x09\x05\ + \x04\xd6\x79\x09\x06\ + \x04\xd6\x79\x09\x07\ + \x04\xd6\x79\x09\x08\ + \x04\xd6\x79\x09\x0a\ + \x04\xd6\x79\x09\x0b\ + \x04\xd6\x79\x09\x0c\ + \x04\xd6\x79\x09\x0d\ + \x04\xd6\x79\x09\x0f"; + +const CHROME155: Profile = Profile { + native_id: 10, + groups: &[4588, 29, 23, 24], + key_shares: &[4588, 29], + signatures: concat!( + "mldsa44:mldsa65:mldsa87:", + "ecdsa_secp256r1_sha256:rsa_pss_rsae_sha256:rsa_pkcs1_sha256:", + "ecdsa_secp384r1_sha384:rsa_pss_rsae_sha384:rsa_pkcs1_sha384:", + "rsa_pss_rsae_sha512:rsa_pkcs1_sha512" + ), + alps_new_codepoint: Some(true), + requested_trust_anchors: CHROME155_TRUST_ANCHORS, + tls12_floor: true, + ..CHROME120 +}; + +const FIREFOX148: Profile = Profile { + native_id: 11, + ciphers: concat!( + "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:", + "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:", + "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:", + "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", + "ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:", + "AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA" + ), + groups: &[4588, 29, 23, 24, 25], + key_shares: &[4588, 29, 23], + signatures: concat!( + "ecdsa_secp256r1_sha256:ecdsa_secp384r1_sha384:ecdsa_secp521r1_sha512:", + "rsa_pss_rsae_sha256:rsa_pss_rsae_sha384:rsa_pss_rsae_sha512:", + "rsa_pkcs1_sha256:rsa_pkcs1_sha384:rsa_pkcs1_sha512:ecdsa_sha1:rsa_pkcs1_sha1" + ), + grease: false, + shuffle: false, + sct: true, + ech_grease: true, + alps_new_codepoint: None, + compression: &[Compression::Zlib, Compression::Brotli, Compression::Zstd], + requested_trust_anchors: &[], + tls12_floor: true, + tls12_only: false, +}; + +const SAFARI263: Profile = Profile { + native_id: 12, + ciphers: concat!( + "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:", + "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:", + "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:", + "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:", + "ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:", + "AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA:AES128-SHA:", + "ECDHE-RSA-DES-CBC3-SHA:DES-CBC3-SHA" + ), + groups: &[4588, 29, 23, 24, 25], + key_shares: &[4588, 29], + signatures: concat!( + "ecdsa_secp256r1_sha256:rsa_pss_rsae_sha256:rsa_pkcs1_sha256:", + "ecdsa_secp384r1_sha384:rsa_pss_rsae_sha384:rsa_pkcs1_sha384:", + "rsa_pss_rsae_sha512:rsa_pkcs1_sha512:rsa_pkcs1_sha1" + ), + grease: true, + shuffle: false, + sct: true, + ech_grease: false, + alps_new_codepoint: None, + compression: &[Compression::Zlib], + requested_trust_anchors: &[], + tls12_floor: true, + tls12_only: false, +}; + /// Immutable profile plus caller-configured TLS trust, versions and identity. /// Each connection supplies its transport ALPN; no profile can override it. #[derive(Debug, Clone)] @@ -252,6 +312,13 @@ impl FingerprintConnector { profile: ClientFingerprint, ) -> Result { let spec = profile.profile(); + if spec.tls12_floor + && builder + .min_proto_version() + .is_none_or(|minimum| minimum.0 < SslVersion::TLS1_2.0) + { + builder.set_min_proto_version(Some(SslVersion::TLS1_2))?; + } if spec.tls12_only && builder .max_proto_version() @@ -269,10 +336,12 @@ impl FingerprintConnector { builder.enable_signed_cert_timestamps(); } builder.enable_ocsp_stapling(); - match spec.compression { - Compression::None => {} - Compression::Brotli => builder.add_certificate_compression_algorithm(Brotli)?, - Compression::Zlib => builder.add_certificate_compression_algorithm(Zlib)?, + for algorithm in spec.compression { + match algorithm { + Compression::Brotli => builder.add_certificate_compression_algorithm(Brotli)?, + Compression::Zlib => builder.add_certificate_compression_algorithm(Zlib)?, + Compression::Zstd => builder.add_certificate_compression_algorithm(Zstd)?, + } } // These setters copy bounded static values; native code validates IDs. unsafe { @@ -320,6 +389,13 @@ impl FingerprintConnector { spec.key_shares.as_ptr(), spec.key_shares.len(), ))?; + if !spec.requested_trust_anchors.is_empty() { + cvt(ffi::SSL_set1_requested_trust_anchors( + config.as_ptr(), + spec.requested_trust_anchors.as_ptr(), + spec.requested_trust_anchors.len(), + ))?; + } } config.set_alpn_protos(alpn)?; config.set_enable_ech_grease(spec.ech_grease); @@ -430,3 +506,97 @@ impl CertificateCompressor for Brotli { } } } + +struct Zstd; +impl CertificateCompressor for Zstd { + const ALGORITHM: CertificateCompressionAlgorithm = CertificateCompressionAlgorithm::ZSTD; + const CAN_COMPRESS: bool = false; + const CAN_DECOMPRESS: bool = true; + + fn decompress(&self, input: &[u8], output: &mut W) -> io::Result<()> { + if input.len() > MAX_CERTIFICATE_BYTES { + return Err(io::Error::other("compressed certificate limit")); + } + if !input.starts_with(&[0x28, 0xb5, 0x2f, 0xfd]) { + return Err(io::Error::other("invalid Zstandard certificate frame")); + } + // Using the slice directly preserves any input after the first frame. + let mut decoder = zstd::stream::read::Decoder::with_buffer(input)?.single_frame(); + decoder.window_log_max(MAX_CERTIFICATE_BYTES.ilog2())?; + io::copy( + &mut decoder.by_ref().take(MAX_CERTIFICATE_BYTES as u64), + output, + )?; + // At the output limit one more read completes the frame or detects overflow. + if decoder.read(&mut [0])? != 0 || !decoder.into_inner().is_empty() { + return Err(io::Error::other( + "invalid or oversized certificate compression", + )); + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::{CertificateCompressor, Zstd, MAX_CERTIFICATE_BYTES}; + use std::io::{self, Write}; + + #[test] + fn zstd_decoder_accepts_a_single_checked_frame_at_the_certificate_limit() { + let expected = vec![0xa5; MAX_CERTIFICATE_BYTES]; + let compressed = zstd::bulk::compress(&expected, 0).unwrap(); + let mut output = Vec::new(); + Zstd.decompress(&compressed, &mut output).unwrap(); + assert_eq!(output, expected); + + let mut encoder = zstd::stream::write::Encoder::new(Vec::new(), 0).unwrap(); + encoder.include_checksum(true).unwrap(); + encoder.window_log(MAX_CERTIFICATE_BYTES.ilog2()).unwrap(); + encoder.write_all(b"certificate").unwrap(); + let mut checksummed = encoder.finish().unwrap(); + output.clear(); + Zstd.decompress(&checksummed, &mut output).unwrap(); + assert_eq!(output, b"certificate"); + *checksummed.last_mut().unwrap() ^= 1; + assert!(Zstd.decompress(&checksummed, &mut io::sink()).is_err()); + } + + #[test] + fn zstd_decoder_rejects_truncation_extra_frames_and_excessive_sizes() { + let compressed = zstd::bulk::compress(b"certificate", 0).unwrap(); + let mut trailing = compressed.clone(); + trailing.push(0); + let concatenated = [compressed.as_slice(), compressed.as_slice()].concat(); + // A full-size raw block produces exactly the allowed output. Its + // framing makes the input exceed the limit. + let mut over_input = b"\x28\xb5\x2f\xfd\x00\x38\x01\x00\x10".to_vec(); + over_input.resize(over_input.len() + MAX_CERTIFICATE_BYTES, 0); + assert_eq!( + zstd::bulk::decompress(&over_input, MAX_CERTIFICATE_BYTES) + .unwrap() + .len(), + MAX_CERTIFICATE_BYTES + ); + let mut encoder = zstd::stream::write::Encoder::new(Vec::new(), 0).unwrap(); + encoder.window_log(MAX_CERTIFICATE_BYTES.ilog2()).unwrap(); + encoder + .write_all(&vec![0; MAX_CERTIFICATE_BYTES + 1]) + .unwrap(); + let over_output = encoder.finish().unwrap(); + // A one-byte raw block framed with a 256 KiB decoder window. + let over_window = b"\x28\xb5\x2f\xfd\x00\x40\x09\x00\x00a"; + assert_eq!(zstd::bulk::decompress(over_window, 1).unwrap(), b"a"); + for invalid in [ + &compressed[..compressed.len() - 1], + &trailing, + &concatenated, + &over_input, + &over_output, + over_window, + b"\x50\x2a\x4d\x18\x00\x00\x00\x00", // skippable frame + ] { + assert!(Zstd.decompress(invalid, &mut io::sink()).is_err()); + } + } +} diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index 18f4b62fb..eb8b2fbdc 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -858,6 +858,9 @@ impl CertificateCompressionAlgorithm { pub const ZLIB: Self = Self(ffi::TLSEXT_cert_compression_zlib as u16); pub const BROTLI: Self = Self(ffi::TLSEXT_cert_compression_brotli as u16); + + /// Zstandard's certificate compression identifier from RFC 8879. + pub const ZSTD: Self = Self(3); } /// A standard implementation of protocol selection for Application Layer Protocol Negotiation diff --git a/boring/src/ssl/reality.rs b/boring/src/ssl/reality.rs index 9356dd256..d109a6d05 100644 --- a/boring/src/ssl/reality.rs +++ b/boring/src/ssl/reality.rs @@ -56,7 +56,7 @@ impl RealityClientConfig { /// Requires an actual X25519MLKEM768 key share and negotiation. /// /// Classic X25519 remains the default. Configure a compatible group/share - /// list (for example Chrome133) before setting this config on a fresh SSL. + /// list (for example Chrome155) before setting this config on a fresh SSL. /// Missing hybrid shares and a peer selecting a classic group fail closed; /// this does not silently replace the selected ClientHello profile. #[must_use] diff --git a/boring/tests/jls.rs b/boring/tests/jls.rs index 2ee0e6397..f4476eefe 100644 --- a/boring/tests/jls.rs +++ b/boring/tests/jls.rs @@ -187,9 +187,9 @@ fn all_named_profiles_authenticate_the_final_hello() { use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Chrome133, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, ] { let builder = SslConnector::builder(SslMethod::tls()).unwrap(); let connector = FingerprintConnector::new(builder, profile).unwrap(); diff --git a/boring/tests/reality.rs b/boring/tests/reality.rs index 2e0ced42c..3cc297cd3 100644 --- a/boring/tests/reality.rs +++ b/boring/tests/reality.rs @@ -241,8 +241,6 @@ fn allowed_hybrid_preserves_classic_profiles_without_inventing_hybrid_shares() { use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, ClientFingerprint::Ios14, ClientFingerprint::Edge85, ClientFingerprint::Qq111, @@ -296,12 +294,12 @@ fn hybrid_only_reality_authenticates_with_its_own_ecdh_component() { #[cfg(feature = "client-fingerprint")] #[test] -fn explicit_hybrid_reality_preserves_chrome133_shares_and_authentication() { +fn explicit_hybrid_reality_preserves_chrome155_shares_and_authentication() { use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; let (server, config) = parameters(); let connector = FingerprintConnector::new( SslConnector::builder(SslMethod::tls()).unwrap(), - ClientFingerprint::Chrome133, + ClientFingerprint::Chrome155, ) .unwrap(); let mut connection = connector.configure(b"\x02h2").unwrap(); @@ -322,9 +320,9 @@ fn named_profile_preserves_reality_wire_authentication() { let (server, config) = parameters(); for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Chrome133, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, ] { let connector = FingerprintConnector::new(SslConnector::builder(SslMethod::tls()).unwrap(), profile) @@ -346,7 +344,7 @@ fn named_profile_preserves_reality_wire_authentication() { authenticate_hello(&server, &msg); let (groups, shares) = hello_groups(&msg); assert!(!groups.contains(&4588)); - let expected = if profile == ClientFingerprint::Firefox120 { + let expected = if profile == ClientFingerprint::Firefox148 { vec![(29, 32), (23, 65)] } else { vec![(29, 32)] @@ -357,6 +355,50 @@ fn named_profile_preserves_reality_wire_authentication() { } } +#[cfg(feature = "client-fingerprint")] +#[test] +fn new_named_profiles_authenticate_when_either_x25519_group_is_selected() { + use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; + + for profile in [ + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, + ] { + let connector = + FingerprintConnector::new(SslConnector::builder(SslMethod::tls()).unwrap(), profile) + .unwrap(); + let make_client = |config: &RealityClientConfig| { + let mut connection = connector + .configure_with_application_settings(b"\x02h2", false) + .unwrap(); + connection + .set_reality_client(&config.clone().allow_x25519mlkem768()) + .unwrap(); + connection.into_ssl("reality.test").unwrap() + }; + + let (server, config) = parameters(); + let mut stream = capture(make_client(&config)); + assert_eq!(stream.connect().unwrap_err().code(), ErrorCode::WANT_READ); + let message = hello(&stream.get_ref().wire); + let mut expected = vec![(4588, 1216), (29, 32)]; + if profile == ClientFingerprint::Firefox148 { + expected.push((23, 65)); + } + assert_eq!(hello_groups(&message).1, expected, "{profile:?}"); + authenticate_hello(&server, &message); + + for (group, expected) in [("X25519", 29), ("X25519MLKEM768", 4588)] { + assert_eq!( + memory_handshake_with_group(make_client, group, false, false, false, false) + .unwrap_or_else(|error| panic!("{profile:?} with {group}: {error}")), + expected + ); + } + } +} + fn hello_groups(msg: &[u8]) -> (Vec, Vec<(u16, usize)>) { let mut cursor = 71; cursor += 2 + u16_at(msg, cursor); @@ -699,7 +741,7 @@ fn required_hybrid_reality_negotiates_hybrid_and_rejects_classic_selection() { use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; let connector = FingerprintConnector::new( SslConnector::builder(SslMethod::tls()).unwrap(), - ClientFingerprint::Chrome133, + ClientFingerprint::Chrome155, ) .unwrap(); let make_client = |config: &RealityClientConfig| { @@ -761,8 +803,8 @@ fn incompatible_profiles_or_later_share_changes_cannot_disable_hybrid_requiremen let (_, config) = parameters(); for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, + ClientFingerprint::Ios14, + ClientFingerprint::Edge85, ] { let connector = FingerprintConnector::new(SslConnector::builder(SslMethod::tls()).unwrap(), profile) @@ -837,9 +879,9 @@ fn each_profile_requires_temporary_certificate_hmac_and_native_proof() { use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector}; for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Chrome133, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, ] { let connector = FingerprintConnector::new(SslConnector::builder(SslMethod::tls()).unwrap(), profile) diff --git a/boring/tests/selected_fingerprint.rs b/boring/tests/selected_fingerprint.rs index 52b059d5b..ec7ca4e2d 100644 --- a/boring/tests/selected_fingerprint.rs +++ b/boring/tests/selected_fingerprint.rs @@ -1,6 +1,7 @@ #![cfg(feature = "client-fingerprint")] //! Closed-template wire observations through the production connector. No sockets. use boring::ssl::{ClientFingerprint, FingerprintConnector, SslConnector, SslMethod, SslVersion}; +use foreign_types::ForeignTypeRef; use std::io::{self, Read, Write}; #[derive(Debug, Default)] @@ -41,217 +42,16 @@ fn grease(id: u16) -> bool { id & 0x0f0f == 0x0a0a && id >> 8 == id & 0xff } -fn configuration( - connector: &FingerprintConnector, - reality: bool, -) -> boring::ssl::ConnectConfiguration { - let config = connector.configure(b"\x02h2\x08http/1.1").unwrap(); - #[cfg(feature = "reality")] - let config = { - let mut config = config; - if reality { - use boring::{ - pkey::{Id, PKey}, - ssl::RealityClientConfig, - }; - let peer = PKey::generate(Id::X25519).unwrap(); - let mut public = [0; 32]; - peer.raw_public_key(&mut public).unwrap(); - config - .set_reality_client(&RealityClientConfig::new(public, &[], [1, 8, 0]).unwrap()) - .unwrap(); - } - config - }; - #[cfg(not(feature = "reality"))] - assert!(!reality); - config -} - -fn check_firefox(reality: bool) { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder - .set_min_proto_version(Some(SslVersion::TLS1_2)) - .unwrap(); - let connector = FingerprintConnector::new(builder, ClientFingerprint::Firefox120).unwrap(); - for _ in 0..8 { - let error = configuration(&connector, reality) - .connect("fingerprint.test", Capture::default()) - .unwrap_err(); - let boring::ssl::HandshakeError::WouldBlock(stream) = error else { - panic!("expected hello"); - }; - let mut record = stream.get_ref().0.as_slice(); - assert_eq!(take(&mut record, 3), &[22, 3, 1]); - let mut hello = vector(&mut record, 2); - assert!(record.is_empty()); - assert_eq!(take(&mut hello, 1), &[1]); - let mut body = vector(&mut hello, 3); - assert!(hello.is_empty()); - assert_eq!(take(&mut body, 2), &[3, 3]); - take(&mut body, 32); - assert_eq!(vector(&mut body, 1).len(), 32); - assert_eq!( - codes(vector(&mut body, 2)), - [ - 0x1301, 0x1303, 0x1302, 0xc02b, 0xc02f, 0xcca9, 0xcca8, 0xc02c, 0xc030, 0xc00a, - 0xc009, 0xc013, 0xc014, 0x009c, 0x009d, 0x002f, 0x0035 - ] - ); - assert_eq!(vector(&mut body, 1), &[0]); - let mut ext = vector(&mut body, 2); - assert!(body.is_empty()); - let mut rows = vec![]; - while !ext.is_empty() { - let kind = codes(take(&mut ext, 2))[0]; - rows.push((kind, vector(&mut ext, 2))); - } - // Exact, not sorted: official Firefox120 vector includes template-only - // FFDHE, delegated_credentials and record_size_limit declarations. - assert_eq!( - rows.iter().map(|r| r.0).collect::>(), - [0, 23, 65281, 10, 11, 35, 16, 5, 34, 51, 43, 13, 45, 28, 65037] - ); - let value = |id| rows.iter().find(|r| r.0 == id).unwrap().1; - assert_eq!(&value(0)[5..], b"fingerprint.test"); - assert_eq!(value(16), b"\0\x0c\x02h2\x08http/1.1"); - assert_eq!(codes(&value(10)[2..]), [29, 23, 24, 25, 256, 257]); - assert_eq!(codes(&value(34)[2..]), [0x0403, 0x0503, 0x0603, 0x0203]); - assert_eq!( - codes(&value(13)[2..]), - [ - 0x0403, 0x0503, 0x0603, 0x0804, 0x0805, 0x0806, 0x0401, 0x0501, 0x0601, 0x0203, - 0x0201 - ] - ); - assert_eq!(value(43), &[4, 3, 4, 3, 3]); - for (id, expected) in [ - (23, &[][..]), - (65281, &[0]), - (11, &[1, 0]), - (35, &[]), - (5, &[1, 0, 0, 0, 0]), - (45, &[1, 1]), - (28, &[0x40, 1]), - ] { - assert_eq!(value(id), expected); - } - let mut shares = &value(51)[2..]; - for (id, size) in [(29, 32), (23, 65)] { - assert_eq!(codes(take(&mut shares, 2)), [id]); - let key = vector(&mut shares, 2); - assert_eq!(key.len(), size); - if id == 23 { - assert_eq!(key[0], 4); - } - } - assert!(shares.is_empty()); - let ech = value(65037); - assert_eq!(ech.len(), 281); - assert_eq!(&ech[..3], &[0, 0, 1]); - assert!([1, 3].contains(&codes(&ech[3..5])[0])); - assert_eq!(&ech[6..8], &[0, 32]); - assert_eq!(&ech[40..42], &[0, 239]); - } -} - -fn check_safari(reality: bool) { - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder - .set_min_proto_version(Some(SslVersion::TLS1_2)) - .unwrap(); - let connector = FingerprintConnector::new(builder, ClientFingerprint::Safari16).unwrap(); - for _ in 0..8 { - let error = configuration(&connector, reality) - .connect("fingerprint.test", Capture::default()) - .unwrap_err(); - let boring::ssl::HandshakeError::WouldBlock(stream) = error else { - panic!("expected hello"); - }; - let mut record = stream.get_ref().0.as_slice(); - assert_eq!(take(&mut record, 3), &[22, 3, 1]); - let mut hello = vector(&mut record, 2); - assert!(record.is_empty()); - assert_eq!(take(&mut hello, 1), &[1]); - let mut body = vector(&mut hello, 3); - assert!(hello.is_empty()); - assert_eq!(take(&mut body, 2), &[3, 3]); - take(&mut body, 32); - assert_eq!(vector(&mut body, 1).len(), 32); - let ciphers = codes(vector(&mut body, 2)); - assert!(grease(ciphers[0])); - assert_eq!( - &ciphers[1..], - &[ - 0x1301, 0x1302, 0x1303, 0xc02c, 0xc02b, 0xcca9, 0xc030, 0xc02f, 0xcca8, 0xc00a, - 0xc009, 0xc014, 0xc013, 0x009d, 0x009c, 0x0035, 0x002f, 0xc008, 0xc012, 0x000a - ] - ); - assert_eq!(vector(&mut body, 1), &[0]); - let mut ext = vector(&mut body, 2); - assert!(body.is_empty()); - let mut rows = vec![]; - while !ext.is_empty() { - let kind = codes(take(&mut ext, 2))[0]; - rows.push((kind, vector(&mut ext, 2))); - } - assert!(grease(rows[0].0)); - assert!(rows[0].1.is_empty()); - let last = rows.len() - 1 - usize::from(rows.last().unwrap().0 == 21); - assert!(grease(rows[last].0)); - assert_eq!(rows[last].1, &[0]); - assert_eq!( - rows[1..last].iter().map(|r| r.0).collect::>(), - [0, 23, 65281, 10, 11, 16, 5, 13, 18, 51, 45, 43, 27] - ); - let value = |id| rows.iter().find(|r| r.0 == id).unwrap().1; - assert_eq!(&value(0)[5..], b"fingerprint.test"); - assert_eq!(value(16), b"\0\x0c\x02h2\x08http/1.1"); - assert_eq!(value(27), &[2, 0, 1]); // Zlib, not Brotli. - assert_eq!( - codes(&value(13)[2..]), - [ - 0x0403, 0x0804, 0x0401, 0x0503, 0x0203, 0x0805, 0x0805, 0x0501, 0x0806, 0x0601, - 0x0201 - ] - ); - assert_eq!(&value(43)[3..], &[3, 4, 3, 3]); // Approved TLS1.2 floor. - let groups = codes(&value(10)[2..]); - assert!(grease(groups[0])); - assert_eq!(&groups[1..], &[29, 23, 24, 25]); - let mut shares = &value(51)[2..]; - for (id, size) in [(groups[0], 1), (29, 32)] { - assert_eq!(codes(take(&mut shares, 2)), [id]); - assert_eq!(vector(&mut shares, 2).len(), size); - } - assert!(shares.is_empty()); - for (id, expected) in [ - (23, &[][..]), - (65281, &[0]), - (11, &[1, 0]), - (5, &[1, 0, 0, 0, 0]), - (18, &[]), - (45, &[1, 1]), - ] { - assert_eq!(value(id), expected); - } - let padding = value(21); - let unpadded = stream.get_ref().0.len() - 5 - padding.len() - 4; - assert!((256..512).contains(&unpadded)); - assert_eq!(padding.len(), 512 - unpadded - 4); - assert!(padding.iter().all(|b| *b == 0)); - } -} - -// Expected wire constants: independently checked against fixed uTLS v1.8.8 iOS14. -fn check_ios(reality: bool) { +fn check_ios() { let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); builder .set_min_proto_version(Some(SslVersion::TLS1_2)) .unwrap(); let connector = FingerprintConnector::new(builder, ClientFingerprint::Ios14).unwrap(); for _ in 0..8 { - let error = configuration(&connector, reality) + let error = connector + .configure(b"\x02h2\x08http/1.1") + .unwrap() .connect("fingerprint.test", Capture::default()) .unwrap_err(); let boring::ssl::HandshakeError::WouldBlock(stream) = error else { @@ -333,149 +133,9 @@ fn check_ios(reality: bool) { } } -fn check_chrome133(reality: bool) { - // Independent expected fields: CF0 official Mihomo v1.19.31 / uTLS v1.8.7 - // Chrome133, not data loaded from the implementation's profile table. - let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder - .set_min_proto_version(Some(SslVersion::TLS1_2)) - .unwrap(); - let connector = FingerprintConnector::new(builder, ClientFingerprint::Chrome133).unwrap(); - for sni in [ - "fingerprint.test".to_owned(), - format!("{}.fingerprint.test", "f".repeat(63)), - ] { - for _ in 0..8 { - let error = configuration(&connector, reality) - .connect(&sni, Capture::default()) - .unwrap_err(); - let boring::ssl::HandshakeError::WouldBlock(stream) = error else { - panic!("expected captured ClientHello"); - }; - let mut record = stream.get_ref().0.as_slice(); - assert_eq!(take(&mut record, 3), &[22, 3, 1]); - let mut hello = vector(&mut record, 2); - assert!(record.is_empty()); - assert_eq!(take(&mut hello, 1), &[1]); - let mut body = vector(&mut hello, 3); - assert!(hello.is_empty()); - assert_eq!(take(&mut body, 2), &[3, 3]); - take(&mut body, 32); - assert_eq!(vector(&mut body, 1).len(), 32); - let ciphers = codes(vector(&mut body, 2)); - assert!(grease(ciphers[0])); - assert_eq!( - &ciphers[1..], - &[ - 0x1301, 0x1302, 0x1303, 0xc02b, 0xc02f, 0xc02c, 0xc030, 0xcca9, 0xcca8, 0xc013, - 0xc014, 0x009c, 0x009d, 0x002f, 0x0035 - ] - ); - assert_eq!(vector(&mut body, 1), &[0]); - let mut ext = vector(&mut body, 2); - assert!(body.is_empty()); - let mut rows = vec![]; - while !ext.is_empty() { - let kind = codes(take(&mut ext, 2))[0]; - rows.push((kind, vector(&mut ext, 2))); - } - assert!(grease(rows[0].0)); - assert!(rows[0].1.is_empty()); - assert!(grease(rows.last().unwrap().0)); - assert_eq!(rows.last().unwrap().1, &[0]); - let mut kinds: Vec<_> = rows[1..rows.len() - 1].iter().map(|r| r.0).collect(); - kinds.sort_unstable(); - assert_eq!( - kinds, - [0, 5, 10, 11, 13, 16, 18, 23, 27, 35, 43, 45, 51, 17613, 65037, 65281] - ); - let value = |id| rows.iter().find(|r| r.0 == id).unwrap().1; - assert_eq!(value(17613), b"\0\x03\x02h2"); - assert_eq!(value(16), b"\0\x0c\x02h2\x08http/1.1"); - assert_eq!(&value(0)[5..], sni.as_bytes()); - assert_eq!(value(27), &[2, 0, 2]); - assert_eq!( - value(13), - &[0, 16, 4, 3, 8, 4, 4, 1, 5, 3, 8, 5, 5, 1, 8, 6, 6, 1] - ); - for (id, expected) in [ - (5, &[1, 0, 0, 0, 0][..]), - (11, &[1, 0]), - (18, &[]), - (23, &[]), - (35, &[]), - (45, &[1, 1]), - (65281, &[0]), - ] { - assert_eq!(value(id), expected); - } - let groups = codes(&value(10)[2..]); - assert!(grease(groups[0])); - assert_eq!( - &groups[1..], - if reality { - &[29, 23, 24][..] - } else { - &[4588, 29, 23, 24][..] - } - ); - let mut encoded_shares = value(51); - let mut shares = vector(&mut encoded_shares, 2); - assert!(encoded_shares.is_empty()); - for (id, size) in [(groups[0], 1), (4588, 1216), (29, 32)] { - if reality && id == 4588 { - continue; - } - assert_eq!(codes(take(&mut shares, 2)), [id]); - let key = vector(&mut shares, 2); - assert_eq!(key.len(), size); - if grease(id) { - assert_eq!(key, &[0]); - } else { - assert!(key.iter().any(|b| *b != 0)); - } - } - assert!(shares.is_empty()); - let versions = value(43); - assert_eq!(versions[0], 6); - assert!(grease(codes(&versions[1..3])[0])); - assert_eq!(&versions[3..], &[3, 4, 3, 3]); - let ech = value(65037); - assert_eq!(&ech[..5], &[0, 0, 1, 0, 1]); - assert_eq!(&ech[6..8], &[0, 32]); - let size = usize::from(codes(&ech[40..42])[0]); - assert!([144, 176, 208, 240].contains(&size)); - assert_eq!(ech.len(), 42 + size); - } - } -} - -#[test] -fn firefox120_has_independent_fixed_order_and_two_classic_shares() { - check_firefox(false); -} - -#[test] -fn safari16_preserves_fixed_cipher_signature_and_extension_vectors() { - check_safari(false); -} - -#[test] -fn chrome133_has_real_mlkem_shares_new_alps_and_no_padding() { - check_chrome133(false); -} - -#[cfg(feature = "reality")] -#[test] -fn classic_reality_preserves_each_new_profile_except_required_mlkem_removal() { - check_chrome133(true); - check_firefox(true); - check_safari(true); -} - #[test] fn ios14_preserves_its_independent_cipher_and_extension_vectors() { - check_ios(false); + check_ios(); } #[test] @@ -499,17 +159,16 @@ fn ios_rsa_sha256_cipher_is_excluded_from_the_default_offer() { } fn profile_fields(profile: ClientFingerprint) -> (Vec, Vec<(u16, Vec)>) { - profile_fields_with_settings(profile, true) + profile_fields_with_settings(profile, true, SslVersion::TLS1_2) } fn profile_fields_with_settings( profile: ClientFingerprint, application_settings: bool, + min_version: SslVersion, ) -> (Vec, Vec<(u16, Vec)>) { let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); - builder - .set_min_proto_version(Some(SslVersion::TLS1_2)) - .unwrap(); + builder.set_min_proto_version(Some(min_version)).unwrap(); let connector = FingerprintConnector::new(builder, profile).unwrap(); let error = connector .configure_with_application_settings(b"\x02h2\x08http/1.1", application_settings) @@ -536,6 +195,183 @@ fn profile_fields_with_settings( (ciphers, rows) } +fn key_shares(mut extension: &[u8]) -> Vec<(u16, &[u8])> { + let mut encoded = vector(&mut extension, 2); + assert!(extension.is_empty()); + let mut shares = Vec::new(); + while !encoded.is_empty() { + let group = codes(take(&mut encoded, 2))[0]; + shares.push((group, vector(&mut encoded, 2))); + } + shares +} + +#[test] +fn chrome155_advertises_native_signatures_and_the_captured_trust_anchor_list() { + let (ciphers, extensions) = profile_fields(ClientFingerprint::Chrome155); + assert!(grease(ciphers[0])); + assert_eq!( + ciphers[1..], + [ + 0x1301, 0x1302, 0x1303, 0xc02b, 0xc02f, 0xc02c, 0xc030, 0xcca9, 0xcca8, 0xc013, 0xc014, + 0x009c, 0x009d, 0x002f, 0x0035 + ] + ); + let mut kinds: Vec<_> = extensions + .iter() + .map(|(kind, _)| *kind) + .filter(|kind| !grease(*kind)) + .collect(); + kinds.sort_unstable(); + assert_eq!( + kinds, + [0, 5, 10, 11, 13, 16, 18, 23, 27, 35, 43, 45, 51, 17613, 0xca34, 65037, 65281] + ); + let value = |id| { + extensions + .iter() + .find(|(kind, _)| *kind == id) + .unwrap() + .1 + .as_slice() + }; + assert_eq!(value(17613), b"\0\x03\x02h2"); + let signatures = codes(&value(13)[2..]); + assert!(grease(signatures[0])); + assert_eq!( + signatures[1..], + [0x0904, 0x0905, 0x0906, 0x0403, 0x0804, 0x0401, 0x0503, 0x0805, 0x0501, 0x0806, 0x0601] + ); + let anchors = value(0xca34); + assert_eq!(anchors.len(), 186); + // SHA-256 of the extension body in the independent Chrome 155 capture. + assert_eq!( + hex::encode(boring::sha::sha256(anchors)), + "734236b257e52e7d202b222a0694fedf187c12b11a4fcc733dd00f3331b7f16c" + ); + let shares = key_shares(value(51)); + assert!(grease(shares[0].0)); + assert_eq!(shares[0].1, &[0]); + assert_eq!((shares[1].0, shares[1].1.len()), (4588, 1216)); + assert_eq!((shares[2].0, shares[2].1.len()), (29, 32)); + assert_ne!(&shares[1].1[1184..], shares[2].1); + assert_eq!(shares.len(), 3); +} + +#[test] +fn firefox148_reuses_the_x25519_key_and_offers_ordered_certificate_compression() { + let (ciphers, extensions) = profile_fields(ClientFingerprint::Firefox148); + assert_eq!( + ciphers, + [ + 0x1301, 0x1303, 0x1302, 0xc02b, 0xc02f, 0xcca9, 0xcca8, 0xc02c, 0xc030, 0xc00a, 0xc009, + 0xc013, 0xc014, 0x009c, 0x009d, 0x002f, 0x0035 + ] + ); + assert_eq!( + extensions.iter().map(|(kind, _)| *kind).collect::>(), + [0, 23, 65281, 10, 11, 16, 5, 34, 18, 51, 43, 13, 28, 27, 65037] + ); + let value = |id| { + extensions + .iter() + .find(|(kind, _)| *kind == id) + .unwrap() + .1 + .as_slice() + }; + assert_eq!(value(27), &[6, 0, 1, 0, 2, 0, 3]); + assert_eq!(codes(&value(10)[2..]), [4588, 29, 23, 24, 25, 256, 257]); + let shares = key_shares(value(51)); + assert_eq!( + shares + .iter() + .map(|(group, bytes)| (*group, bytes.len())) + .collect::>(), + [(4588, 1216), (29, 32), (23, 65)] + ); + assert_eq!(&shares[0].1[1184..], shares[1].1); +} + +#[test] +fn safari263_preserves_its_fixed_order_and_independent_hybrid_share() { + let (ciphers, extensions) = profile_fields(ClientFingerprint::Safari263); + assert!(grease(ciphers[0])); + assert_eq!( + ciphers[1..], + [ + 0x1302, 0x1303, 0x1301, 0xc02c, 0xc02b, 0xcca9, 0xc030, 0xc02f, 0xcca8, 0xc00a, 0xc009, + 0xc014, 0xc013, 0x009d, 0x009c, 0x0035, 0x002f, 0xc008, 0xc012, 0x000a + ] + ); + let kinds: Vec<_> = extensions.iter().map(|(kind, _)| *kind).collect(); + assert!(grease(kinds[0])); + assert!(grease(*kinds.last().unwrap())); + assert_eq!( + kinds[1..kinds.len() - 1], + [0, 23, 65281, 10, 11, 16, 5, 13, 18, 51, 45, 43, 27] + ); + let value = |id| { + extensions + .iter() + .find(|(kind, _)| *kind == id) + .unwrap() + .1 + .as_slice() + }; + assert_eq!(value(27), &[2, 0, 1]); + assert_eq!( + codes(&value(13)[2..]), + [0x0403, 0x0804, 0x0401, 0x0503, 0x0805, 0x0805, 0x0501, 0x0806, 0x0601, 0x0201] + ); + let shares = key_shares(value(51)); + assert!(grease(shares[0].0)); + assert_eq!(shares[0].1, &[0]); + assert_eq!((shares[1].0, shares[1].1.len()), (4588, 1216)); + assert_eq!((shares[2].0, shares[2].1.len()), (29, 32)); + assert_ne!(&shares[1].1[1184..], shares[2].1); + assert_eq!(shares.len(), 3); +} + +#[test] +fn recent_profiles_require_tls12_and_keep_the_callers_tls13_floor() { + for profile in [ + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, + ] { + for (requested, expected) in [ + (SslVersion::TLS1_1, &[0x0304, 0x0303][..]), + (SslVersion::TLS1_3, &[0x0304][..]), + ] { + let (_, extensions) = profile_fields_with_settings(profile, true, requested); + let versions = &extensions.iter().find(|(kind, _)| *kind == 43).unwrap().1; + assert_eq!( + codes(&versions[1..]) + .into_iter() + .filter(|id| !grease(*id)) + .collect::>(), + expected, + "{profile:?} with {requested:?}" + ); + } + } +} + +#[test] +fn removed_native_profile_ids_are_rejected_on_fresh_clients() { + let connector = SslConnector::builder(SslMethod::tls()).unwrap().build(); + for id in [2, 3, 4] { + let config = connector.configure().unwrap(); + assert_eq!( + unsafe { boring_sys::SSL_set_client_fingerprint(config.as_ptr(), id) }, + 0, + "obsolete native profile ID {id}" + ); + assert!(!boring::error::ErrorStack::get().errors().is_empty()); + } +} + #[test] fn android11_keeps_okhttp_order_without_adding_tls13_or_browser_extensions() { let (ciphers, extensions) = profile_fields(ClientFingerprint::Android11); @@ -673,10 +509,10 @@ fn three_sixty75_keeps_tls12_groups_without_enabling_fake_or_disabled_algorithms fn callers_without_alps_consumers_keep_h2_without_advertising_either_codepoint() { for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Chrome133, + ClientFingerprint::Chrome155, ClientFingerprint::Qq111, ] { - let (_, extensions) = profile_fields_with_settings(profile, false); + let (_, extensions) = profile_fields_with_settings(profile, false, SslVersion::TLS1_2); assert!(!extensions .iter() .any(|(kind, _)| matches!(kind, 17513 | 17613))); diff --git a/docs/client-fingerprint.md b/docs/client-fingerprint.md index 5d8aae6dc..82edd4460 100644 --- a/docs/client-fingerprint.md +++ b/docs/client-fingerprint.md @@ -5,17 +5,20 @@ The fork follows boring 5.5.1 and the official BoringSSL 0.20261020.0 baseline build patches; the checked-out BoringSSL submodule contains upstream source. Enable `boring/client-fingerprint` or `tokio-boring/client-fingerprint` on this -fork. The implemented fixed profiles are `ClientFingerprint::Chrome120` (classic -X25519), `Chrome133` (ordinary TLS with native X25519MLKEM768 and X25519 shares, -new ALPS and no padding), `Firefox120` (X25519/P-256 shares and fixed order) and -`Safari16` (Safari 16.0, fixed order and Zlib) and `Ios14` (iOS 14, fixed order, -CBC-SHA256 offers and no certificate compression), `Android11` (Android 11 -OkHttp), `Edge85`, `ThreeSixty75` (360 Browser 7.5) and `Qq111` (QQ 11.1). -Android11 and ThreeSixty75 cap negotiation at TLS 1.2; a caller's higher minimum -is still enforced rather than lowered. They are not aliases following a -browser release automatically. Unknown profile names -must be rejected by applications; this library does not silently map them to a -different browser. +fork. Each `ClientFingerprint` variant selects a fixed profile. + +| Family | Variants | +| --- | --- | +| Chrome | `Chrome120`, `Chrome155` | +| Firefox | `Firefox148` | +| Safari | `Safari263` (26.3) | +| iOS and Android | `Ios14`, `Android11` (OkHttp) | +| Edge, 360 Browser and QQ | `Edge85`, `ThreeSixty75` (7.5), `Qq111` (11.1) | + +Applications select a versioned variant explicitly. The retired Chrome 133, +Firefox 120 and Safari 16.0 profiles are unavailable. `Android11` and +`ThreeSixty75` cap negotiation at TLS 1.2 and retain any stricter caller floor. +`Chrome120` offers a classic X25519 share. ## Interface @@ -51,12 +54,14 @@ discard already-negotiated settings. `configure(alpn)` remains equivalent to `configure_with_application_settings(alpn, true)`, preserving existing behavior. The profile configures ciphers, supported groups, signature algorithms, GREASE, -extension permutation, SCT/OCSP, ECH GREASE and template-specific h2 ALPS. Certificate -compression uses real Brotli for Chrome and Zlib for Safari; Firefox and iOS do not -advertise it. This is not an advertised-only extension. The -native certificate-message allocation and decoder output are bounded to 128 KiB. -The profile does not disable certificate verification, weaken handshake signature -verification, enable early data or create a resumption policy. +extension permutation, SCT/OCSP, ECH GREASE and template-specific h2 ALPS. +Chrome uses Brotli certificate decompression and Safari uses Zlib. +`Firefox148` offers actual Zlib, Brotli and Zstd decoders in that order. +`Ios14` omits certificate compression. The native certificate +message allocation and decoder output are bounded to 128 KiB. The Zstd decoder +also limits its window to 128 KiB and requires a single complete frame. +Certificate and handshake signature verification stay active. The caller still +controls early data and owns session storage. Edge85 and Qq111 preserve their fixed reference ordering; QQ declares old-codepoint h2 ALPS when enabled, while Edge does not. Android11 and ThreeSixty75 do not add @@ -75,6 +80,27 @@ wire identity. only transports these bytes; the application remains responsible for interpreting them and enforcing its required ALPN before using or caching the connection. +## Recent profiles + +- `Chrome155` offers native X25519MLKEM768 and X25519 shares, GREASE followed + by native TLS 1.3 ML-DSA-44/65/87 signature schemes, and the newer h2 ALPS + codepoint when ALPS is enabled. The per-connection `trust_anchors` extension + requests the 28 identifiers recorded in the Chrome 155 reference. The IDs + can influence the peer's certificate chain choice. The caller's trust store + and certificate verifier still determine acceptance. The profile does not + initiate an anchor-discovery retry. + [Chrome 155 reference](https://github.com/refraction-networking/utls/blob/360383f893fbe954ff12a701b87295406abbc156/testdata/chrome155_clienthello.md) +- `Firefox148` generates X25519MLKEM768, X25519 and P-256 shares in that order. + The hybrid and standalone X25519 entries use one ephemeral X25519 key within + each ClientHello. A cold connection omits the TLS 1.2 ticket extension and + TLS 1.3 PSK modes. The native handshake can send a real TLS 1.2 ticket or + TLS 1.3 PSK and its required modes when an eligible session is available. + A cold peer may decline to issue a TLS 1.3 ticket. +- `Safari263` offers independently generated X25519MLKEM768 and X25519 shares, + uses a fixed extension order and TLS 1.3 cipher order, and omits padding. + `Chrome155`, `Firefox148`, and `Safari263` require at least TLS 1.2 and + retain a stricter caller floor. + ## REALITY With both features enabled, use the same connector and set @@ -84,24 +110,20 @@ exception and native CertificateVerify checks remain in the native handshake. The full connection-local invariants and deliberately unsupported combinations are documented in [REALITY](reality-client.md). -The [CF4 fork-local checks](client-fingerprint-cf4-fork.md) cover the four originally accepted -profiles' classic REALITY shape and authentication binding. Classic mode removes -Chrome133's ML-KEM group/share and preserves Firefox's additional P-256 share. -Independent VCore/Mihomo data paths still require application integration and -fresh container acceptance; ordinary-TLS ML-KEM is not PQ REALITY. - -For explicit hybrid REALITY, only Chrome133 among this fixed catalog has the -required group/share. Configure `RealityClientConfig::require_x25519mlkem768` -separately; classic remains the default. The other fixed profiles fail rather -than changing their wire identities. Both actual hybrid negotiation and native -REALITY authentication are required. See the independent [hybrid fork gate](reality-hybrid.md); -its checks do not establish VCore's production/download-leg support. - -`RealityClientConfig::allow_x25519mlkem768` instead preserves the profile's actual -shares and allows either classic or hybrid selection within the same authenticated -handshake. A classic profile remains classic; this does not invent a hybrid share -or retry a rejected connection. Classic mode remains the default, and required -hybrid mode keeps its existing requirement. +Classic mode remains the default. It removes X25519MLKEM768 from both the +advertised groups and the actual key shares of hybrid-capable profiles while +preserving the remaining shares, including Firefox's P-256. +The [CF4 fork-local checks](client-fingerprint-cf4-fork.md) preserve the original +profile coverage. + +`Chrome155`, `Firefox148` and `Safari263` offer the native group +and share needed by `RealityClientConfig::require_x25519mlkem768`. This mode +requires actual hybrid negotiation and native REALITY authentication. The other +fixed profiles fail when hybrid is required. `allow_x25519mlkem768` preserves +the selected profile's existing shares and accepts either supported choice +within the same authenticated handshake. Rejected handshakes terminate without +a retry. REALITY identity remains bound to X25519 and its native verification. +See the [hybrid fork gate](reality-hybrid.md) for the original independent checks. ## Scope and verification @@ -126,12 +148,10 @@ and is deprecated/default-off outside explicit cipher configuration. No RC4 was restored. Safari's repeated signature scheme is a wire encoding detail; real signature verification preferences remain unique. -Applications must set their TLS version floor (VCore uses TLS1.2), which trims -Safari's reference TLS1.0/1.1 advertisement. Safari omits the cold session-ticket -extension. Actual caller-supplied TLS1.2 tickets can still use it; warm connections -are not claimed as identical to the reference cold template. Zlib rejects +`Safari263` omits the cold session-ticket extension. An eligible TLS 1.2 ticket +can still be offered on a warm connection. Zlib rejects truncation, corrupt checksums, trailing bytes and oversized output before passing -the certificate to the unchanged verifier. +the certificate to the verifier. TLS1.3 cipher order and Chrome ECH GREASE AEAD are fixed by the named template, not CPU AES acceleration. Real native cipher filtering, key generation, @@ -142,20 +162,20 @@ Targeted checks create only memory streams, including real native TLS peers: ```sh cargo test -p boring --features reality,client-fingerprint --test client_fingerprint --test selected_fingerprint --test reality --test hkdf +cargo test -p boring --features client-fingerprint --lib zstd_decoder_ cargo test -p tokio-boring --features reality,client-fingerprint --test client_fingerprint --test selected_fingerprint cargo clippy -p boring -p tokio-boring --features reality,client-fingerprint --lib -- -D warnings cargo fmt --all -- --check ``` -The earlier isolated Mihomo, ordinary-TLS, Vision and handshake experiments are -selection/integration evidence, not reasons to repeat general backend feasibility -work. The tests above exercise the new named interface. Application wiring, -portable pinned Git dependency resolution, device behavior and release review are -separate gates; passing these library tests does not complete those gates. +These checks cover the library's wire encoding, certificate decompression and +native handshakes. Application wiring, locked Git dependency resolution, +interoperability with external peers, device behavior and release review require +separate validation. ### Historical initial-interface result — 2026-09-25 -On macOS ARM64, the current named interface passed one wire-profile test, eight +On macOS ARM64, the initial named interface passed one wire-profile test, eight REALITY tests (including the named-profile authentication case), nine existing HKDF tests and two Tokio memory-handshake tests: 20 total. The Tokio tests cover absent/empty/nonempty peer ALPS and actual Brotli certificate decoding with both diff --git a/docs/reality-client.md b/docs/reality-client.md index 630c2a2f3..1003b7ce4 100644 --- a/docs/reality-client.md +++ b/docs/reality-client.md @@ -44,12 +44,11 @@ The opt-in [named ClientHello profile](client-fingerprint.md) can be combined with this interface. Authentication still owns the same native key share and final ClientHello bytes; the profile cannot bypass the REALITY verifier. -With the selected-v1 templates, classic mode removes X25519MLKEM768 from both +With named templates, classic mode removes X25519MLKEM768 from both advertised groups and actual shares, matching Mihomo's default classic behavior. -It preserves other classic shares (including Firefox120's P-256) in order and -binds authentication to the actual X25519 object, even if it is not first. Without -explicit share configuration it selects X25519 alone. It creates no second -identity key or global secret mapping; ordinary Chrome133 TLS still uses ML-KEM. +It preserves the order of classic shares, including Firefox148's P-256, and +authenticates with the actual X25519 object. Without explicit share configuration +it selects X25519 alone. Ordinary TLS can still negotiate ML-KEM. ### Explicit required hybrid mode @@ -58,16 +57,16 @@ identity key or global secret mapping; ordinary Chrome133 TLS still uses ML-KEM. ```rust,ignore let reality = RealityClientConfig::new(server_public_key, &short_id, [1, 8, 0])? .require_x25519mlkem768(); -// Select Chrome133 or a native group/share list including X25519MLKEM768 first. +// Select Chrome155 or a native group/share list including X25519MLKEM768 first. ssl.set_reality_client(&reality)?; ``` This requires both a real native X25519MLKEM768 ClientHello share and that group in the negotiated connection. A classic ServerHello fails before key-share decapsulation. HRR remains unsupported; there is no silent classic retry. The -mode preserves an explicit compatible list; without explicit shares it selects -the hybrid group alone. Chrome120, Firefox120 and Safari16 are incompatible with -this mode, not templates to silently upgrade or rename. +mode preserves an explicit compatible list and selects the hybrid group alone +when no explicit shares are configured. Required hybrid mode rejects classic-only +profiles such as Chrome120 and Ios14. Authentication uses the standalone X25519 share when present, otherwise the X25519 component of the actual hybrid share, matching Mihomo's server-side diff --git a/docs/reality-hybrid.md b/docs/reality-hybrid.md index 3265926e4..26d720ab6 100644 --- a/docs/reality-hybrid.md +++ b/docs/reality-hybrid.md @@ -156,6 +156,8 @@ The host probe is client-only, not a VCore runtime or protected socket path. The fork harness explicitly receives a VCore checkout for its existing isolated lab and official downloader; it does not discover an implicit sibling directory. The tested lab source baseline is `def0e19cb0945614397c884388a9ee561818a19a`. +The current probe selects Chrome155 for its `chrome` cases. The tables above +record the earlier Chrome133 runs. Use a fresh direct child under that checkout's ignored `target/interop/runs`: ```sh diff --git a/tests/interop/jls.py b/tests/interop/jls.py index a9ed4e564..de105212b 100644 --- a/tests/interop/jls.py +++ b/tests/interop/jls.py @@ -276,7 +276,7 @@ def probe( if not passed: raise RuntimeError(f"case failed: {label}") - for profile in ("none", "chrome120", "chrome133", "firefox120", "safari16"): + for profile in ("none", "chrome120", "chrome155", "firefox148", "safari263"): for v6 in (False, True): probe(f"{profile}-v{6 if v6 else 4}", profile=profile, v6=v6) probe( diff --git a/tests/interop/shadow_tls_v3.py b/tests/interop/shadow_tls_v3.py index c954a70dc..9a433998f 100644 --- a/tests/interop/shadow_tls_v3.py +++ b/tests/interop/shadow_tls_v3.py @@ -267,7 +267,7 @@ def probe( if not passed: raise RuntimeError(f"case failed: {label}") - for profile in ("none", "chrome120", "chrome133", "firefox120", "safari16"): + for profile in ("none", "chrome120", "chrome155", "firefox148", "safari263"): for v6 in (False, True): for version, port in (("TLS1.3", 23001), ("TLS1.2", 23002)): probe( @@ -277,7 +277,7 @@ def probe( port=port, v6=v6, ) - probe("chrome133-hrr", profile="chrome133", port=23003, hrr=True) + probe("chrome155-hrr", profile="chrome155", port=23003, hrr=True) probe( "wrong-password", supplied_password="synthetic-wrong-password", diff --git a/tokio-boring/Cargo.toml b/tokio-boring/Cargo.toml index 5e20cc0c1..b3fcd2506 100644 --- a/tokio-boring/Cargo.toml +++ b/tokio-boring/Cargo.toml @@ -48,6 +48,7 @@ tokio = { workspace = true, features = ["time"] } [dev-dependencies] brotli = { workspace = true } flate2 = { workspace = true } +zstd = { workspace = true } foreign-types = { workspace = true } futures = { workspace = true } tokio = { workspace = true, features = [ "full" ] } diff --git a/tokio-boring/tests/selected_fingerprint.rs b/tokio-boring/tests/selected_fingerprint.rs index 4d9e75a35..2f62b4c92 100644 --- a/tokio-boring/tests/selected_fingerprint.rs +++ b/tokio-boring/tests/selected_fingerprint.rs @@ -9,10 +9,13 @@ use boring::{ }, x509::X509, }; -use foreign_types::ForeignTypeRef; +use foreign_types::{ForeignType, ForeignTypeRef}; use std::{ pin::Pin, - sync::{Arc, Mutex}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, + }, task::{Context, Poll}, }; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf}; @@ -65,15 +68,23 @@ fn server(version: SslVersion, group: &str) -> SslAcceptorBuilder { fn ecdsa_certificate(server: &mut SslAcceptorBuilder) { use boring::{ - asn1::Asn1Time, - bn::BigNum, ec::{EcGroup, EcKey}, hash::MessageDigest, nid::Nid, - x509::X509Name, }; let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap(); let key = PKey::from_ec_key(EcKey::generate(&group).unwrap()).unwrap(); + let mut cert = certificate_builder(&key); + cert.sign(&key, MessageDigest::sha256()).unwrap(); + server.set_certificate(&cert.build()).unwrap(); + server.set_private_key(&key).unwrap(); +} + +fn certificate_builder( + key: &boring::pkey::PKeyRef, +) -> boring::x509::X509Builder { + use boring::{asn1::Asn1Time, bn::BigNum, x509::X509Name}; + let mut name = X509Name::builder().unwrap(); name.append_entry_by_text("CN", "profile.test").unwrap(); let name = name.build(); @@ -87,10 +98,60 @@ fn ecdsa_certificate(server: &mut SslAcceptorBuilder) { .unwrap(); cert.set_not_after(&Asn1Time::days_from_now(1).unwrap()) .unwrap(); - cert.set_pubkey(&key).unwrap(); - cert.sign(&key, MessageDigest::sha256()).unwrap(); - server.set_certificate(&cert.build()).unwrap(); - server.set_private_key(&key).unwrap(); + cert.set_pubkey(key).unwrap(); + cert +} + +#[tokio::test] +async fn chrome155_negotiates_each_mldsa_signature_with_native_verification() { + use boring::{pkey::Id, ssl::SslSignatureAlgorithm}; + + tokio::time::timeout(std::time::Duration::from_secs(5), async { + for (key_id, signature) in [ + ( + boring_sys::EVP_PKEY_ML_DSA_44, + SslSignatureAlgorithm::ML_DSA_44, + ), + ( + boring_sys::EVP_PKEY_ML_DSA_65, + SslSignatureAlgorithm::ML_DSA_65, + ), + ( + boring_sys::EVP_PKEY_ML_DSA_87, + SslSignatureAlgorithm::ML_DSA_87, + ), + ] { + let key = PKey::generate(Id::from_raw(key_id)).unwrap(); + let certificate = certificate_builder(&key).build(); + // SAFETY: The certificate and key are live and exclusively owned. + // Pure ML-DSA signs the message directly with no EVP digest. + let signature_len = unsafe { + boring_sys::X509_sign(certificate.as_ptr(), key.as_ptr(), std::ptr::null()) + }; + assert!(signature_len > 0, "{}", boring::error::ErrorStack::get()); + let mut acceptor = server(SslVersion::TLS1_3, "X25519"); + acceptor.set_certificate(&certificate).unwrap(); + acceptor.set_private_key(&key).unwrap(); + let acceptor = acceptor.build(); + + let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); + builder.cert_store_mut().add_cert(certificate).unwrap(); + let connector = + FingerprintConnector::new(builder, ClientFingerprint::Chrome155).unwrap(); + let (io, peer) = tokio::io::duplex(16 * 1024); + let (client, server) = tokio::join!( + tokio_boring::connect(connector.configure(b"\x02h2").unwrap(), "profile.test", io), + tokio_boring::accept(&acceptor, peer) + ); + server.unwrap(); + assert_eq!( + client.unwrap().ssl().peer_signature_algorithm(), + Some(signature) + ); + } + }) + .await + .unwrap(); } #[tokio::test] @@ -193,7 +254,7 @@ async fn classic_profile_suites(profile: ClientFingerprint) { ] { exchange_profile(profile, SslVersion::TLS1_2, "X25519", Some(cipher)).await; } - if profile == ClientFingerprint::Safari16 { + if profile == ClientFingerprint::Safari263 { for cipher in ["ECDHE-RSA-DES-CBC3-SHA", "DES-CBC3-SHA"] { exchange_profile(profile, SslVersion::TLS1_2, "X25519", Some(cipher)).await; } @@ -204,19 +265,19 @@ async fn classic_profile_suites(profile: ClientFingerprint) { } #[tokio::test] -async fn firefox120_negotiates_declared_classic_groups_and_ciphers() { - classic_profile_suites(ClientFingerprint::Firefox120).await; +async fn firefox148_negotiates_declared_classic_groups_and_ciphers() { + classic_profile_suites(ClientFingerprint::Firefox148).await; } #[tokio::test] -async fn safari16_negotiates_declared_classic_groups_and_real_legacy_ciphers() { - classic_profile_suites(ClientFingerprint::Safari16).await; +async fn safari263_negotiates_declared_classic_groups_and_real_legacy_ciphers() { + classic_profile_suites(ClientFingerprint::Safari263).await; } #[tokio::test] async fn firefox_and_safari_keep_the_callers_tls12_floor() { tokio::time::timeout(std::time::Duration::from_secs(10), async { - for profile in [ClientFingerprint::Firefox120, ClientFingerprint::Safari16] { + for profile in [ClientFingerprint::Firefox148, ClientFingerprint::Safari263] { for version in [SslVersion::TLS1, SslVersion::TLS1_1] { let (io, remote) = tokio::io::duplex(4096); let task = tokio::spawn(async move { @@ -280,7 +341,7 @@ impl boring::ssl::CertificateCompressor for BrotliCertificate { #[tokio::test] async fn chrome_profiles_retain_bounded_brotli_and_reject_wrong_payload_algorithm() { tokio::time::timeout(std::time::Duration::from_secs(10), async { - for profile in [ClientFingerprint::Chrome120, ClientFingerprint::Chrome133] { + for profile in [ClientFingerprint::Chrome120, ClientFingerprint::Chrome155] { for mode in 0..5 { let mut acceptor = server(SslVersion::TLS1_3, "X25519"); acceptor @@ -360,7 +421,7 @@ impl boring::ssl::CertificateCompressor for ZlibCertificate { } #[tokio::test] -async fn safari16_real_zlib_rejects_truncation_corruption_trailing_and_oversize() { +async fn safari263_real_zlib_rejects_truncation_corruption_trailing_and_oversize() { tokio::time::timeout(std::time::Duration::from_secs(10), async { for mode in 0..8 { let mut acceptor = server(SslVersion::TLS1_3, "X25519"); @@ -391,7 +452,7 @@ async fn safari16_real_zlib_rejects_truncation_corruption_trailing_and_oversize( Ok(()) } }); - let connector = FingerprintConnector::new(b, ClientFingerprint::Safari16).unwrap(); + let connector = FingerprintConnector::new(b, ClientFingerprint::Safari263).unwrap(); let mut config = connector.configure(b"\x02h2").unwrap(); config.set_verify_hostname(false); let result = tokio_boring::connect(config, "profile.test", io).await; @@ -421,8 +482,64 @@ async fn safari16_real_zlib_rejects_truncation_corruption_trailing_and_oversize( .unwrap(); } +struct ZstdCertificate(Arc); +impl boring::ssl::CertificateCompressor for ZstdCertificate { + const ALGORITHM: boring::ssl::CertificateCompressionAlgorithm = + boring::ssl::CertificateCompressionAlgorithm::ZSTD; + const CAN_COMPRESS: bool = true; + const CAN_DECOMPRESS: bool = false; + + fn compress(&self, input: &[u8], output: &mut W) -> std::io::Result<()> { + output.write_all(&zstd::bulk::compress(input, 0)?)?; + self.0.store(true, Ordering::Relaxed); + Ok(()) + } +} + +#[tokio::test] +async fn firefox148_negotiates_p256_without_retry_and_decodes_a_zstd_certificate() { + tokio::time::timeout(std::time::Duration::from_secs(10), async { + let compressed = Arc::new(AtomicBool::new(false)); + let mut acceptor = server(SslVersion::TLS1_3, "P-256"); + acceptor + .add_certificate_compression_algorithm(ZstdCertificate(compressed.clone())) + .unwrap(); + let acceptor = acceptor.build(); + let (io, remote) = tokio::io::duplex(4096); + let task = tokio::spawn(async move { + let mut tls = tokio_boring::accept(&acceptor, remote).await.unwrap(); + let mut request = [0; 4]; + tls.read_exact(&mut request).await.unwrap(); + assert_eq!(&request, b"ping"); + tls.write_all(b"pong").await.unwrap(); + }); + + let mut builder = SslConnector::builder(SslMethod::tls()).unwrap(); + builder.set_custom_verify_callback(SslVerifyMode::PEER, |_| Ok(())); + let connector = FingerprintConnector::new(builder, ClientFingerprint::Firefox148).unwrap(); + let mut tls = + tokio_boring::connect(connector.configure(b"\x02h2").unwrap(), "localhost", io) + .await + .unwrap(); + assert_eq!(tls.ssl().version2(), Some(SslVersion::TLS1_3)); + assert!(!tls.ssl().used_hello_retry_request()); + assert_eq!( + unsafe { boring_sys::SSL_get_group_id(tls.ssl().as_ptr()) }, + 23 + ); + assert!(compressed.load(Ordering::Relaxed)); + tls.write_all(b"ping").await.unwrap(); + let mut response = [0; 4]; + tls.read_exact(&mut response).await.unwrap(); + assert_eq!(&response, b"pong"); + task.await.unwrap(); + }) + .await + .unwrap(); +} + #[tokio::test] -async fn chrome133_negotiates_mlkem_x25519_hrr_and_tls12_with_data() { +async fn chrome155_negotiates_mlkem_x25519_hrr_and_tls12_with_data() { tokio::time::timeout(std::time::Duration::from_secs(10), async { for (version, group, expected_id, hrr) in [ (SslVersion::TLS1_3, "X25519MLKEM768", 4588, false), @@ -446,7 +563,7 @@ async fn chrome133_negotiates_mlkem_x25519_hrr_and_tls12_with_data() { let mut b = SslConnector::builder(SslMethod::tls()).unwrap(); b.set_min_proto_version(Some(SslVersion::TLS1_2)).unwrap(); b.set_custom_verify_callback(SslVerifyMode::PEER, |_| Ok(())); - let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome133).unwrap(); + let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome155).unwrap(); let mut config = connector.configure(b"\x02h2").unwrap(); config.set_verify_hostname(false); let mut tls = tokio_boring::connect(config, "profile.test", io) @@ -470,7 +587,7 @@ async fn chrome133_negotiates_mlkem_x25519_hrr_and_tls12_with_data() { } #[tokio::test] -async fn chrome133_negotiates_only_new_alps_with_absent_empty_and_nonempty_results() { +async fn chrome155_negotiates_only_new_alps_with_absent_empty_and_nonempty_results() { tokio::time::timeout(std::time::Duration::from_secs(10), async { for (new_codepoint, settings) in [ (false, Some(&b"old"[..])), @@ -508,7 +625,7 @@ async fn chrome133_negotiates_only_new_alps_with_absent_empty_and_nonempty_resul }); let mut b = SslConnector::builder(SslMethod::tls()).unwrap(); b.set_custom_verify_callback(SslVerifyMode::PEER, |_| Ok(())); - let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome133).unwrap(); + let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome155).unwrap(); let mut config = connector.configure(b"\x02h2").unwrap(); config.set_verify_hostname(false); let mut tls = tokio_boring::connect(config, "profile.test", io) @@ -529,8 +646,8 @@ async fn chrome133_negotiates_only_new_alps_with_absent_empty_and_nonempty_resul } #[tokio::test] -async fn chrome133_real_ticket_resumption_and_rejected_ticket_full_handshake() { - profile_ticket_resumption(ClientFingerprint::Chrome133, "X25519MLKEM768").await; +async fn chrome155_real_ticket_resumption_and_rejected_ticket_full_handshake() { + profile_ticket_resumption(ClientFingerprint::Chrome155, "X25519MLKEM768").await; } #[tokio::test] @@ -721,7 +838,7 @@ async fn profile_ticket_resumption(profile: ClientFingerprint, group: &'static s } #[tokio::test] -async fn chrome133_rejects_bad_certificate_and_forged_handshake_signature() { +async fn chrome155_rejects_bad_certificate_and_forged_handshake_signature() { tokio::time::timeout(std::time::Duration::from_secs(10), async { for bad_signature in [false, true] { let mut acceptor = server(SslVersion::TLS1_3, "X25519MLKEM768"); @@ -744,7 +861,7 @@ async fn chrome133_rejects_bad_certificate_and_forged_handshake_signature() { )) } }); - let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome133).unwrap(); + let connector = FingerprintConnector::new(b, ClientFingerprint::Chrome155).unwrap(); let mut config = connector.configure(b"\x02h2").unwrap(); config.set_verify_hostname(false); let error = tokio_boring::connect(config, "profile.test", io) @@ -779,9 +896,9 @@ async fn all_classic_reality_profiles_reject_hrr_and_tls12() { tokio::time::timeout(std::time::Duration::from_secs(15), async { for profile in [ ClientFingerprint::Chrome120, - ClientFingerprint::Chrome133, - ClientFingerprint::Firefox120, - ClientFingerprint::Safari16, + ClientFingerprint::Chrome155, + ClientFingerprint::Firefox148, + ClientFingerprint::Safari263, ] { for (version, group, expected) in [ (SslVersion::TLS1_2, "X25519", "UNSUPPORTED_PROTOCOL"), @@ -921,9 +1038,9 @@ async fn reject_server_hello( } #[tokio::test] -async fn chrome133_rejects_malformed_server_key_share() { +async fn chrome155_rejects_malformed_server_key_share() { reject_server_hello( - ClientFingerprint::Chrome133, + ClientFingerprint::Chrome155, SslVersion::TLS1_3, ServerHelloFault::ShareLength, "DECODE_ERROR", @@ -932,10 +1049,10 @@ async fn chrome133_rejects_malformed_server_key_share() { } #[tokio::test] -async fn firefox120_rejects_template_only_selections() { +async fn firefox148_rejects_template_only_selections() { for kind in [28, 34] { reject_server_hello( - ClientFingerprint::Firefox120, + ClientFingerprint::Firefox148, SslVersion::TLS1_2, ServerHelloFault::Extension(kind), "UNEXPECTED_EXTENSION", @@ -943,7 +1060,7 @@ async fn firefox120_rejects_template_only_selections() { .await; } reject_server_hello( - ClientFingerprint::Firefox120, + ClientFingerprint::Firefox148, SslVersion::TLS1_3, ServerHelloFault::FfdheSelection, "WRONG_CURVE", @@ -952,9 +1069,9 @@ async fn firefox120_rejects_template_only_selections() { } #[tokio::test] -async fn safari16_rejects_utls_fake_cipher_selection() { +async fn safari263_rejects_utls_fake_cipher_selection() { reject_server_hello( - ClientFingerprint::Safari16, + ClientFingerprint::Safari263, SslVersion::TLS1_2, ServerHelloFault::FakeCipher, "WRONG_CIPHER_RETURNED", diff --git a/tokio-boring/tests/shadow_tls.rs b/tokio-boring/tests/shadow_tls.rs index e957d4b5f..fca8dd3bf 100644 --- a/tokio-boring/tests/shadow_tls.rs +++ b/tokio-boring/tests/shadow_tls.rs @@ -144,9 +144,9 @@ async fn native_tls_transcript_and_all_profiles_complete_without_wire_rewriting( for profile in [ None, Some(ClientFingerprint::Chrome120), - Some(ClientFingerprint::Chrome133), - Some(ClientFingerprint::Firefox120), - Some(ClientFingerprint::Safari16), + Some(ClientFingerprint::Chrome155), + Some(ClientFingerprint::Firefox148), + Some(ClientFingerprint::Safari263), ] { exchange(version, profile, "X25519", None, true).await; } @@ -155,7 +155,7 @@ async fn native_tls_transcript_and_all_profiles_complete_without_wire_rewriting( // Server P-384 forces a real TLS 1.3 HRR for Chrome's first shares. exchange( SslVersion::TLS1_3, - Some(ClientFingerprint::Chrome133), + Some(ClientFingerprint::Chrome155), "P-384", None, true, @@ -192,7 +192,7 @@ async fn cancelled_handshakes_drop_io_and_do_not_reuse_authentication_state() { let mut config = if round % 2 == 0 { builder.build().configure().unwrap() } else { - FingerprintConnector::new(builder, ClientFingerprint::Chrome133) + FingerprintConnector::new(builder, ClientFingerprint::Chrome155) .unwrap() .configure(&[]) .unwrap()