wreq 1.3.2.4-aarch64-linux → 1.3.3-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -12
- data/Rakefile +3 -9
- data/crates/wreq-util/README.md +4 -2
- data/lib/wreq_ruby/3.3/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/3.4/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/4.0/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/client.rb +27 -13
- data/lib/wreq_ruby/emulate.rb +3 -28
- data/lib/wreq_ruby/http.rb +9 -2
- data/test/emulation_test.rb +104 -21
- data/test/option_validation_test.rb +13 -4
- data/wreq.gemspec +15 -3
- metadata +3 -8
- data/VERSION +0 -1
- data/crates/README.md +0 -6
- data/crates/serde-magnus/LICENSE +0 -19
- data/crates/serde-magnus/README.md +0 -147
- data/test/emulation_client_hello_test.rb +0 -142
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d2db45f98055ee65b4932ef8032456189713a5a0279aa36f9fbbcb370839304
|
|
4
|
+
data.tar.gz: 6a63533e349eaffab4714609f5231d6d99c05de6b72ad75b06133fc431e44c8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 184dee18a6415b84227e471c59f4972aa8cb3c3ee7a2998d90a10605bcc3ec4f788f02ca8418f2df9505d1d74365d4c9d982219a48e83b683a7829c7545d93e1
|
|
7
|
+
data.tar.gz: b83f842ba969f3aa1bc54500516b1b51165a92bfe2870eb6c2665dfe7439b9ea12552062437d7693be1585ae2374ac76100b5c4fbe878ede6b746133061ad4a6
|
data/README.md
CHANGED
|
@@ -89,21 +89,14 @@ Most browser device models share identical TLS and HTTP/2 configurations, differ
|
|
|
89
89
|
- <details>
|
|
90
90
|
<summary>Available browser emulations</summary>
|
|
91
91
|
|
|
92
|
-
Edge 149–158 provide request-header presets for Windows, macOS, Linux, Android, and iOS.
|
|
93
|
-
Firefox 153–160 provide Android and iPhone presets for `User-Agent` and `Accept-Language`.
|
|
94
|
-
Both use the same TLS and HTTP/2 settings as the corresponding desktop Firefox preset.
|
|
95
|
-
Opera 116–140 provide desktop request-header presets for Windows, macOS, and Linux.
|
|
96
|
-
|
|
97
92
|
| **Browser** | **Versions** |
|
|
98
93
|
| ----------- | ------------ |
|
|
99
|
-
| **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149`, `Chrome150`, `Chrome151`, `Chrome152`, `Chrome153`, `Chrome154`, `Chrome155`, `Chrome156`, `Chrome157
|
|
100
|
-
| **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134
|
|
101
|
-
| **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152
|
|
94
|
+
| **Chrome** | `Chrome100`, `Chrome101`, `Chrome104`, `Chrome105`, `Chrome106`, `Chrome107`, `Chrome108`, `Chrome109`, `Chrome110`, `Chrome114`, `Chrome116`, `Chrome117`, `Chrome118`, `Chrome119`, `Chrome120`, `Chrome123`, `Chrome124`, `Chrome126`, `Chrome127`, `Chrome128`, `Chrome129`, `Chrome130`, `Chrome131`, `Chrome132`, `Chrome133`, `Chrome134`, `Chrome135`, `Chrome136`, `Chrome137`, `Chrome138`, `Chrome139`, `Chrome140`, `Chrome141`, `Chrome142`, `Chrome143`, `Chrome144`, `Chrome145`, `Chrome146`, `Chrome147`, `Chrome148`, `Chrome149`, `Chrome150`, `Chrome151`, `Chrome152`, `Chrome153`, `Chrome154`, `Chrome155`, `Chrome156`, `Chrome157` |
|
|
95
|
+
| **Edge** | `Edge101`, `Edge122`, `Edge127`, `Edge131`, `Edge134`, `Edge135`, `Edge136`, `Edge137`, `Edge138`, `Edge139`, `Edge140`, `Edge141`, `Edge142`, `Edge143`, `Edge144`, `Edge145`, `Edge146`, `Edge147`, `Edge148` |
|
|
96
|
+
| **Firefox** | `Firefox109`, `Firefox117`, `Firefox128`, `Firefox133`, `Firefox135`, `FirefoxPrivate135`, `FirefoxAndroid135`, `Firefox136`, `FirefoxPrivate136`, `Firefox139`, `Firefox142`, `Firefox143`, `Firefox144`, `Firefox145`, `Firefox146`, `Firefox147`, `Firefox148`, `Firefox149`, `Firefox150`, `Firefox151`, `Firefox152` |
|
|
102
97
|
| **Safari** | `Safari15_3`, `Safari15_5`, `Safari15_6_1`, `Safari16`, `Safari16_5`, `Safari17_0`, `Safari17_2_1`, `Safari17_4_1`, `Safari17_5`, `Safari17_6`, `Safari18`, `Safari18_2`, `Safari18_3`, `Safari18_3_1`, `Safari18_5`, `Safari26`, `Safari26_1`, `Safari26_2`, `SafariIos16_5`, `SafariIos17_2`, `SafariIos17_4_1`, `SafariIos18_1_1`, `SafariIos26`, `SafariIos26_2`, `SafariIPad18`, `SafariIPad26`, `SafariIpad26_2` |
|
|
103
|
-
| **OkHttp** | `
|
|
104
|
-
| **Opera** | `Opera116
|
|
105
|
-
|
|
106
|
-
Opera 132–140 use the corresponding Chromium desktop TLS and HTTP/2 defaults with Opera-branded request headers.
|
|
98
|
+
| **OkHttp** | `Opera116`, `Opera117`, `Opera118`, `Opera119`, `Opera120`, `Opera121`, `Opera122`, `Opera123`, `Opera124`, `Opera125`, `Opera126`, `Opera127`, `Opera128`, `Opera129`, `Opera130` |
|
|
99
|
+
| **Opera** | `Opera116`, `Opera117`, `Opera118`, `Opera119` |
|
|
107
100
|
|
|
108
101
|
</details>
|
|
109
102
|
|
data/Rakefile
CHANGED
|
@@ -44,23 +44,17 @@ end
|
|
|
44
44
|
|
|
45
45
|
desc "Run Rust tests"
|
|
46
46
|
task :cargo_test do
|
|
47
|
-
|
|
48
|
-
if RbConfig::CONFIG.fetch("host_os").start_with?("linux")
|
|
49
|
-
# Embedded Ruby tests need the active Ruby's shared library at startup.
|
|
50
|
-
test_env["LD_LIBRARY_PATH"] = [RbConfig::CONFIG.fetch("libdir"), ENV["LD_LIBRARY_PATH"]]
|
|
51
|
-
.compact.reject(&:empty?).join(File::PATH_SEPARATOR)
|
|
52
|
-
end
|
|
53
|
-
sh test_env, "cargo", "test", "--workspace", "--locked"
|
|
47
|
+
sh "cargo test"
|
|
54
48
|
end
|
|
55
49
|
|
|
56
50
|
desc "Format Rust code"
|
|
57
51
|
task :fmt do
|
|
58
|
-
sh "cargo fmt
|
|
52
|
+
sh "cargo fmt"
|
|
59
53
|
end
|
|
60
54
|
|
|
61
55
|
desc "Run Clippy linter"
|
|
62
56
|
task :lint do
|
|
63
|
-
sh "cargo clippy --
|
|
57
|
+
sh "cargo clippy -- -D warnings"
|
|
64
58
|
end
|
|
65
59
|
|
|
66
60
|
desc "Build native gem for platform (e.g., rake 'native[x86_64-linux]')"
|
data/crates/wreq-util/README.md
CHANGED
|
@@ -20,12 +20,14 @@ See the [crate documentation](https://docs.rs/wreq-util/latest/wreq_util) for mo
|
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
|
+
This vendored copy uses the development wreq revision pinned in the [root Cargo.toml](../../Cargo.toml). Building it independently requires the same Git patches.
|
|
24
|
+
|
|
23
25
|
The following example uses the [Tokio](https://tokio.rs) runtime with optional features enabled by adding this to your `Cargo.toml`:
|
|
24
26
|
|
|
25
27
|
```toml
|
|
26
28
|
[dependencies]
|
|
27
29
|
tokio = { version = "1", features = ["full"] }
|
|
28
|
-
wreq = "
|
|
30
|
+
wreq = "0.16.1"
|
|
29
31
|
wreq-util = "3.0.0-rc"
|
|
30
32
|
```
|
|
31
33
|
|
|
@@ -38,7 +40,7 @@ use wreq_util::Emulation;
|
|
|
38
40
|
#[tokio::main]
|
|
39
41
|
async fn main() -> wreq::Result<()> {
|
|
40
42
|
// Build a client
|
|
41
|
-
let client = Client::
|
|
43
|
+
let client = Client::builder_tokio()
|
|
42
44
|
.emulation(Emulation::Chrome147)
|
|
43
45
|
.build()?;
|
|
44
46
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/wreq_ruby/client.rb
CHANGED
|
@@ -5,7 +5,7 @@ unless defined?(Wreq)
|
|
|
5
5
|
# HTTP client with extensive configuration options.
|
|
6
6
|
#
|
|
7
7
|
# This class wraps a native Rust implementation providing high-performance
|
|
8
|
-
# HTTP/1.1 and HTTP/
|
|
8
|
+
# HTTP/1.1, HTTP/2 and HTTP/3 client functionality with support for connection pooling,
|
|
9
9
|
# compression, redirects, proxies, and fine-grained timeout controls.
|
|
10
10
|
#
|
|
11
11
|
# The client is thread-safe and maintains an internal connection pool for
|
|
@@ -110,25 +110,37 @@ unless defined?(Wreq)
|
|
|
110
110
|
# allowing the reuse of local addresses in TIME_WAIT state. Useful for
|
|
111
111
|
# reducing port exhaustion in high-throughput scenarios.
|
|
112
112
|
#
|
|
113
|
-
# @param pool_idle_timeout [Integer, nil]
|
|
114
|
-
#
|
|
115
|
-
#
|
|
113
|
+
# @param pool_idle_timeout [Integer, nil] Idle connection reuse timeout in
|
|
114
|
+
# seconds. Defaults to 90 when omitted or nil. Does not expire a busy
|
|
115
|
+
# HTTP/2 or HTTP/3 connection.
|
|
116
116
|
#
|
|
117
|
-
# @param pool_max_idle_per_host [Integer, nil] Maximum
|
|
118
|
-
# connections
|
|
119
|
-
#
|
|
117
|
+
# @param pool_max_idle_per_host [Integer, nil] Maximum idle HTTP/1
|
|
118
|
+
# connections retained per compatibility group, which includes the host
|
|
119
|
+
# and connection configuration. Defaults to unlimited when omitted or
|
|
120
|
+
# nil; 0 disables connection reuse. Does not limit active connections.
|
|
120
121
|
#
|
|
121
|
-
# @param pool_max_size [Integer, nil]
|
|
122
|
-
#
|
|
123
|
-
#
|
|
122
|
+
# @param pool_max_size [Integer, nil] Maximum compatibility groups retaining
|
|
123
|
+
# idle HTTP/1 or shared HTTP/2 and HTTP/3 connections. Defaults to unlimited
|
|
124
|
+
# when omitted, nil or 0. A full pool evicts the least recently used idle
|
|
125
|
+
# group; it does not make requests wait or limit physical connections.
|
|
124
126
|
#
|
|
125
127
|
# @param http1_only [Boolean, nil] Force the client to use HTTP/1.1 only,
|
|
126
128
|
# even if HTTP/2 is available. Useful for compatibility with servers
|
|
127
|
-
# that have problematic HTTP/2 implementations.
|
|
129
|
+
# that have problematic HTTP/2 implementations. Cannot be combined with
|
|
130
|
+
# http2_only or http3_only. An explicit request version overrides this
|
|
131
|
+
# preference.
|
|
128
132
|
#
|
|
129
133
|
# @param http2_only [Boolean, nil] Force the client to use HTTP/2 only.
|
|
130
134
|
# Requests to servers that don't support HTTP/2 will fail. Cannot be
|
|
131
|
-
# combined with http1_only.
|
|
135
|
+
# combined with http1_only or http3_only. An explicit request version
|
|
136
|
+
# overrides this preference, including HTTP/3 over QUIC.
|
|
137
|
+
#
|
|
138
|
+
# @param http3_only [Boolean, nil] Use HTTP/3 over QUIC without falling back
|
|
139
|
+
# to TCP. Defaults to false when omitted or nil. Requires HTTPS and UDP
|
|
140
|
+
# connectivity. Cannot be combined with http1_only or http2_only. An
|
|
141
|
+
# explicit HTTP/1 or HTTP/2 request version overrides this preference.
|
|
142
|
+
# HTTP/HTTPS proxies, including environment proxies, cannot carry HTTP/3;
|
|
143
|
+
# use no_proxy: true, a SOCKS5 UDP proxy, or a QUIC MASQUE proxy instead.
|
|
132
144
|
#
|
|
133
145
|
# @param https_only [Boolean, nil] Reject plain HTTP connections and
|
|
134
146
|
# only allow HTTPS. Provides an additional layer of security by
|
|
@@ -149,7 +161,9 @@ unless defined?(Wreq)
|
|
|
149
161
|
# environment.
|
|
150
162
|
#
|
|
151
163
|
# @param proxy [String, nil] Proxy server URI to use for all requests.
|
|
152
|
-
# Supports HTTP, HTTPS, and
|
|
164
|
+
# Supports HTTP, HTTPS, SOCKS and QUIC proxies. HTTP/3 can use SOCKS5 UDP
|
|
165
|
+
# ASSOCIATE or a `quic://` MASQUE proxy, but not HTTP CONNECT proxies.
|
|
166
|
+
# Format: "protocol://host:port"
|
|
153
167
|
# Example: "http://proxy.example.com:8080"
|
|
154
168
|
# @param local_address [String, nil] Bind the client's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable.
|
|
155
169
|
# @param interface [String, nil] Bind sockets to a network interface on
|
data/lib/wreq_ruby/emulate.rb
CHANGED
|
@@ -69,7 +69,6 @@ module Wreq
|
|
|
69
69
|
Chrome155 = nil
|
|
70
70
|
Chrome156 = nil
|
|
71
71
|
Chrome157 = nil
|
|
72
|
-
Chrome158 = nil
|
|
73
72
|
|
|
74
73
|
Edge101 = nil
|
|
75
74
|
Edge122 = nil
|
|
@@ -90,16 +89,6 @@ module Wreq
|
|
|
90
89
|
Edge146 = nil
|
|
91
90
|
Edge147 = nil
|
|
92
91
|
Edge148 = nil
|
|
93
|
-
Edge149 = nil
|
|
94
|
-
Edge150 = nil
|
|
95
|
-
Edge151 = nil
|
|
96
|
-
Edge152 = nil
|
|
97
|
-
Edge153 = nil
|
|
98
|
-
Edge154 = nil
|
|
99
|
-
Edge155 = nil
|
|
100
|
-
Edge156 = nil
|
|
101
|
-
Edge157 = nil
|
|
102
|
-
Edge158 = nil
|
|
103
92
|
|
|
104
93
|
Firefox109 = nil
|
|
105
94
|
Firefox117 = nil
|
|
@@ -122,14 +111,6 @@ module Wreq
|
|
|
122
111
|
Firefox150 = nil
|
|
123
112
|
Firefox151 = nil
|
|
124
113
|
Firefox152 = nil
|
|
125
|
-
Firefox153 = nil
|
|
126
|
-
Firefox154 = nil
|
|
127
|
-
Firefox155 = nil
|
|
128
|
-
Firefox156 = nil
|
|
129
|
-
Firefox157 = nil
|
|
130
|
-
Firefox158 = nil
|
|
131
|
-
Firefox159 = nil
|
|
132
|
-
Firefox160 = nil
|
|
133
114
|
|
|
134
115
|
SafariIos17_2 = nil
|
|
135
116
|
SafariIos17_4_1 = nil
|
|
@@ -186,15 +167,6 @@ module Wreq
|
|
|
186
167
|
Opera129 = nil
|
|
187
168
|
Opera130 = nil
|
|
188
169
|
Opera131 = nil
|
|
189
|
-
Opera132 = nil
|
|
190
|
-
Opera133 = nil
|
|
191
|
-
Opera134 = nil
|
|
192
|
-
Opera135 = nil
|
|
193
|
-
Opera136 = nil
|
|
194
|
-
Opera137 = nil
|
|
195
|
-
Opera138 = nil
|
|
196
|
-
Opera139 = nil
|
|
197
|
-
Opera140 = nil
|
|
198
170
|
end
|
|
199
171
|
|
|
200
172
|
unless method_defined?(:to_s)
|
|
@@ -295,6 +267,9 @@ module Wreq
|
|
|
295
267
|
# for HTTP/2 and automatic default headers. The actual implementation is
|
|
296
268
|
# provided by Rust.
|
|
297
269
|
#
|
|
270
|
+
# Profiles configure TLS over TCP, HTTP/2 and request headers. They do not
|
|
271
|
+
# configure HTTP/3 or QUIC fingerprints; HTTP/3 uses the backend defaults.
|
|
272
|
+
#
|
|
298
273
|
# Construction generates the native configuration once. For Chrome 152/153,
|
|
299
274
|
# the TLS trust_anchors extension's ID order is randomized at construction;
|
|
300
275
|
# Chrome 154 and later sort those IDs by their raw bytes instead. Reusing this object
|
data/lib/wreq_ruby/http.rb
CHANGED
|
@@ -42,7 +42,7 @@ module Wreq
|
|
|
42
42
|
|
|
43
43
|
# Value-based equality. Returns true when both represent the same HTTP method.
|
|
44
44
|
# @param other [Object]
|
|
45
|
-
# @return [Boolean]
|
|
45
|
+
# @return [Boolean]
|
|
46
46
|
unless method_defined?(:==)
|
|
47
47
|
def ==(other)
|
|
48
48
|
end
|
|
@@ -77,7 +77,14 @@ module Wreq
|
|
|
77
77
|
HTTP_10 = nil # @return [Wreq::Version] HTTP/1.0
|
|
78
78
|
HTTP_11 = nil # @return [Wreq::Version] HTTP/1.1
|
|
79
79
|
HTTP_2 = nil # @return [Wreq::Version] HTTP/2
|
|
80
|
-
|
|
80
|
+
# Select HTTP/3 over QUIC with `version: Wreq::Version::HTTP_3` on a request.
|
|
81
|
+
# To use it by default, construct a client with `http3_only: true` instead.
|
|
82
|
+
# Requires an HTTPS URL and a reachable UDP endpoint. There is no automatic
|
|
83
|
+
# Alt-Svc discovery or fallback to HTTP/1.1 or HTTP/2.
|
|
84
|
+
# HTTP CONNECT proxies cannot carry these requests; use a direct connection,
|
|
85
|
+
# a SOCKS5 UDP relay or a `quic://` MASQUE proxy.
|
|
86
|
+
# @return [Wreq::Version] HTTP/3
|
|
87
|
+
HTTP_3 = nil
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
# Returns a string representation of the HTTP version.
|
data/test/emulation_test.rb
CHANGED
|
@@ -1,36 +1,119 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "test_helper"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "stringio"
|
|
6
|
+
require "timeout"
|
|
4
7
|
|
|
5
8
|
class EmulationTest < Minitest::Test
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
def test_reused_emulation_retains_trust_anchors_across_clients_and_requests
|
|
10
|
+
[Wreq::Profile::Chrome152, Wreq::Profile::Chrome153, Wreq::Profile::Chrome154, Wreq::Profile::Chrome155, Wreq::Profile::Chrome156, Wreq::Profile::Chrome157].each do |profile|
|
|
11
|
+
emulation = Wreq::Emulation.new(profile: profile)
|
|
12
|
+
client = Wreq::Client.new(emulation: emulation, no_proxy: true)
|
|
13
|
+
expected = capture_trust_anchors { |url| client.get(url, timeout: 5) }
|
|
14
|
+
refute_empty expected, profile.to_s
|
|
15
|
+
|
|
16
|
+
request_client = Wreq::Client.new(no_proxy: true)
|
|
17
|
+
2.times do
|
|
18
|
+
actual = capture_trust_anchors do |url|
|
|
19
|
+
request_client.get(url, emulation: emulation, timeout: 5)
|
|
20
|
+
end
|
|
21
|
+
assert_equal expected, actual, "#{profile}: reusing an object must retain its configuration"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_all_emulation_device_constants_are_non_nil
|
|
27
|
+
Wreq::Profile.constants.each do |name|
|
|
28
|
+
const = Wreq::Profile.const_get(name)
|
|
29
|
+
assert_instance_of Wreq::Profile, const,
|
|
30
|
+
"#{name} should be Profile, got #{const.inspect}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_chrome151_profile_is_available
|
|
35
|
+
profile = Wreq::Profile::Chrome151
|
|
36
|
+
|
|
37
|
+
assert_equal "Chrome151", profile.to_s
|
|
38
|
+
assert_instance_of Wreq::Emulation, Wreq::Emulation.new(profile: profile)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_new_browser_profiles_are_available
|
|
42
|
+
{
|
|
43
|
+
Wreq::Profile::Chrome152 => "Chrome152",
|
|
44
|
+
Wreq::Profile::Chrome153 => "Chrome153",
|
|
45
|
+
Wreq::Profile::Chrome154 => "Chrome154",
|
|
46
|
+
Wreq::Profile::Chrome155 => "Chrome155",
|
|
47
|
+
Wreq::Profile::Chrome156 => "Chrome156",
|
|
48
|
+
Wreq::Profile::Chrome157 => "Chrome157",
|
|
49
|
+
Wreq::Profile::Firefox152 => "Firefox152"
|
|
50
|
+
}.each do |profile, name|
|
|
51
|
+
assert_equal name, profile.to_s
|
|
52
|
+
assert_instance_of Wreq::Emulation, Wreq::Emulation.new(profile: profile)
|
|
15
53
|
end
|
|
16
|
-
|
|
54
|
+
end
|
|
17
55
|
|
|
18
|
-
|
|
19
|
-
|
|
56
|
+
def test_all_emulation_os_constants_are_non_nil
|
|
57
|
+
Wreq::Platform.constants.each do |name|
|
|
58
|
+
const = Wreq::Platform.const_get(name)
|
|
59
|
+
assert_instance_of Wreq::Platform, const,
|
|
60
|
+
"#{name} should be Platform, got #{const.inspect}"
|
|
61
|
+
end
|
|
20
62
|
end
|
|
21
63
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
# Each listener forces a new connection. Stop after ClientHello so this test
|
|
67
|
+
# inspects the extension bytes without depending on certificates or the network.
|
|
68
|
+
def capture_trust_anchors
|
|
69
|
+
server = TCPServer.new("127.0.0.1", 0)
|
|
70
|
+
thread = Thread.new do
|
|
71
|
+
socket = nil
|
|
72
|
+
Timeout.timeout(5) do
|
|
73
|
+
socket = server.accept
|
|
74
|
+
handshake = +"".b
|
|
75
|
+
loop do
|
|
76
|
+
header = read_tls_bytes(socket, 5)
|
|
77
|
+
raise "expected a TLS handshake record" unless header.getbyte(0) == 22
|
|
78
|
+
handshake << read_tls_bytes(socket, header.byteslice(3, 2).unpack1("n"))
|
|
79
|
+
next if handshake.bytesize < 4
|
|
80
|
+
length = handshake.byteslice(1, 3).bytes.reduce(0) { |n, byte| (n << 8) | byte }
|
|
81
|
+
break if handshake.bytesize >= length + 4
|
|
82
|
+
end
|
|
83
|
+
trust_anchors_from_client_hello(handshake)
|
|
84
|
+
end
|
|
85
|
+
ensure
|
|
86
|
+
socket&.close
|
|
28
87
|
end
|
|
88
|
+
thread.report_on_exception = false
|
|
89
|
+
|
|
90
|
+
assert_raises(Wreq::ConnectionError) { yield "https://127.0.0.1:#{server.addr[1]}/" }
|
|
91
|
+
thread.value
|
|
92
|
+
ensure
|
|
93
|
+
server&.close
|
|
94
|
+
thread&.kill if thread&.alive?
|
|
95
|
+
thread&.join
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def read_tls_bytes(io, length)
|
|
99
|
+
bytes = io.read(length)
|
|
100
|
+
raise EOFError, "truncated ClientHello" unless bytes&.bytesize == length
|
|
101
|
+
bytes
|
|
29
102
|
end
|
|
30
103
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
-
|
|
104
|
+
def trust_anchors_from_client_hello(handshake)
|
|
105
|
+
io = StringIO.new(handshake)
|
|
106
|
+
raise "expected ClientHello" unless read_tls_bytes(io, 1).unpack1("C") == 1
|
|
107
|
+
read_tls_bytes(io, 3 + 2 + 32) # Handshake length, legacy version and random.
|
|
108
|
+
read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Session ID.
|
|
109
|
+
read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")) # Cipher suites.
|
|
110
|
+
read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Compression methods.
|
|
111
|
+
extensions = StringIO.new(read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")))
|
|
112
|
+
until extensions.eof?
|
|
113
|
+
type, length = read_tls_bytes(extensions, 4).unpack("nn")
|
|
114
|
+
data = read_tls_bytes(extensions, length)
|
|
115
|
+
return data if type == 51764
|
|
34
116
|
end
|
|
117
|
+
raise "missing trust_anchors extension"
|
|
35
118
|
end
|
|
36
119
|
end
|
|
@@ -227,12 +227,21 @@ class OptionValidationTest < Minitest::Test
|
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
def test_protocol_only_options_are_mutually_exclusive
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
[:http1_only, :http2_only, :http3_only].combination(2) do |first, second|
|
|
231
|
+
error = assert_raises(ArgumentError) do
|
|
232
|
+
Wreq::Client.new(**{first => true, second => true})
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
assert_includes error.message, ":#{first}"
|
|
236
|
+
assert_includes error.message, ":#{second}"
|
|
232
237
|
end
|
|
233
238
|
|
|
234
|
-
|
|
235
|
-
|
|
239
|
+
assert_instance_of Wreq::Client,
|
|
240
|
+
Wreq::Client.new(http3_only: true, http1_only: false, http2_only: nil)
|
|
241
|
+
assert_instance_of Wreq::Client,
|
|
242
|
+
Wreq::Client.new(http1_only: true, http3_only: false)
|
|
243
|
+
assert_instance_of Wreq::Client,
|
|
244
|
+
Wreq::Client.new(http2_only: true, http3_only: nil)
|
|
236
245
|
end
|
|
237
246
|
|
|
238
247
|
def test_validation_reports_the_first_failed_rule
|
data/wreq.gemspec
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
4
6
|
spec.name = "wreq"
|
|
5
7
|
# RubyGems integrates and expects `cargo`.
|
|
6
8
|
# Read more about
|
|
7
9
|
# [Gem::Ext::CargoBuilder](https://github.com/rubygems/rubygems/blob/v3.5.23/lib/rubygems/ext/cargo_builder.rb)
|
|
8
10
|
#
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
+
# wreq relies on "version" in `Cargo.toml` for the release process. You can read this gem spec with:
|
|
12
|
+
# `bundle exec ruby -e 'puts Gem::Specification.load("wreq.gemspec")'`
|
|
13
|
+
#
|
|
14
|
+
# keep in sync the key "wreq-ruby" with `Rakefile`.
|
|
15
|
+
#
|
|
16
|
+
# uses `cargo` to extract the version.
|
|
17
|
+
cargo_output = `cargo metadata --format-version 1`
|
|
18
|
+
cargo_output.force_encoding("UTF-8")
|
|
19
|
+
spec.version = JSON.parse(cargo_output.strip)
|
|
20
|
+
.fetch("packages")
|
|
21
|
+
.find { |p| p["name"] == "wreq-ruby" }
|
|
22
|
+
.fetch("version")
|
|
11
23
|
spec.authors = ["SearchApi"]
|
|
12
24
|
spec.email = ["support@searchapi.io"]
|
|
13
25
|
spec.summary = "Ruby bindings for wreq, an HTTP client with TLS/HTTP2 browser fingerprinting"
|
|
@@ -44,7 +56,7 @@ Gem::Specification.new do |spec|
|
|
|
44
56
|
# Exclude non-Ruby files from RDoc to prevent parsing errors
|
|
45
57
|
spec.rdoc_options = ["--exclude", "Cargo\\..*", "--exclude", "\\.rs$"]
|
|
46
58
|
|
|
47
|
-
spec.requirements = ["Rust >= 1.
|
|
59
|
+
spec.requirements = ["Rust >= 1.98"]
|
|
48
60
|
# use a Ruby version which:
|
|
49
61
|
# - supports Rubygems with the ability of compilation of Rust gem
|
|
50
62
|
# - not end of life
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wreq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.3
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- SearchApi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: An easy and powerful Ruby HTTP client with advanced browser fingerprinting
|
|
14
14
|
that accurately emulates Chrome, Edge, Firefox, Safari, Opera, and OkHttp with precise
|
|
@@ -24,10 +24,6 @@ files:
|
|
|
24
24
|
- LICENSE
|
|
25
25
|
- README.md
|
|
26
26
|
- Rakefile
|
|
27
|
-
- VERSION
|
|
28
|
-
- crates/README.md
|
|
29
|
-
- crates/serde-magnus/LICENSE
|
|
30
|
-
- crates/serde-magnus/README.md
|
|
31
27
|
- crates/wreq-util/.github/FUNDING.yml
|
|
32
28
|
- crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md
|
|
33
29
|
- crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md
|
|
@@ -73,7 +69,6 @@ files:
|
|
|
73
69
|
- test/client_cookie_test.rb
|
|
74
70
|
- test/client_test.rb
|
|
75
71
|
- test/cookie_test.rb
|
|
76
|
-
- test/emulation_client_hello_test.rb
|
|
77
72
|
- test/emulation_test.rb
|
|
78
73
|
- test/error_handling_test.rb
|
|
79
74
|
- test/fork_test.rb
|
|
@@ -126,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
126
121
|
- !ruby/object:Gem::Version
|
|
127
122
|
version: '0'
|
|
128
123
|
requirements:
|
|
129
|
-
- Rust >= 1.
|
|
124
|
+
- Rust >= 1.98
|
|
130
125
|
rubygems_version: 3.5.23
|
|
131
126
|
signing_key:
|
|
132
127
|
specification_version: 4
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.3.2.4
|
data/crates/README.md
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# Local Rust dependencies
|
|
2
|
-
|
|
3
|
-
- [`serde_magnus`](serde-magnus/) is based on OneSignal's `serde_magnus`. The root package uses it as a path dependency and workspace member so it shares the lockfile and runs in `bundle exec rake test`.
|
|
4
|
-
- [`wreq-util`](wreq-util/) is a local copy of [0x676e67/wreq-util](https://github.com/0x676e67/wreq-util). The root [`Cargo.toml`](../Cargo.toml) resolves it from `crates/wreq-util` through `[patch.crates-io]`.
|
|
5
|
-
|
|
6
|
-
When building or testing `wreq-util` on its own, use the Git dependency patches from the root manifest of the same branch. Cargo does not inherit those patches from the parent package.
|
data/crates/serde-magnus/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright 2022 George Claghorn
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights to
|
|
6
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
-
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
-
so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
-
SOFTWARE.
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# `serde_magnus`
|
|
2
|
-
|
|
3
|
-
`serde_magnus` converts between Rust and Ruby data structures using [Serde] and [Magnus].
|
|
4
|
-
|
|
5
|
-
[Serde]: https://github.com/serde-rs/serde
|
|
6
|
-
[Magnus]: https://github.com/matsadler/magnus
|
|
7
|
-
|
|
8
|
-
## Local maintenance
|
|
9
|
-
|
|
10
|
-
This crate is based on [OneSignal's serde_magnus 0.11.0 source][upstream]. It
|
|
11
|
-
uses the same Magnus 0.9 series and Rust 1.98 minimum as `wreq-ruby`.
|
|
12
|
-
|
|
13
|
-
### Local patches
|
|
14
|
-
|
|
15
|
-
- `src/de/` and `src/ser/` preserve arbitrary-size JSON integers in both
|
|
16
|
-
directions and support typed `i128` and `u128`. JSON input validates object keys,
|
|
17
|
-
finite floats, and container depth. The precision tests also cover the
|
|
18
|
-
private number token shared with `serde_json`.
|
|
19
|
-
- `src/options.rs` validates option names before converting values and attaches
|
|
20
|
-
the failing field path to Ruby exceptions.
|
|
21
|
-
- `src/error.rs` carries Serde errors until the conversion entry point can use
|
|
22
|
-
its Ruby handle. The deserializer and map serializer check iteration and map
|
|
23
|
-
state.
|
|
24
|
-
|
|
25
|
-
To sync, diff this directory against the pinned source tree, reapply the local
|
|
26
|
-
changes to the new upstream commit, and update the pin below. Run
|
|
27
|
-
`cargo test --locked -p serde_magnus` and `bundle exec rake test` from the
|
|
28
|
-
repository root. The Ruby tests in `test/json_precision_test.rb` and
|
|
29
|
-
`test/option_validation_test.rb` exercise the request, response, and option
|
|
30
|
-
entry points.
|
|
31
|
-
|
|
32
|
-
[upstream]: https://github.com/OneSignal/serde-magnus/tree/b84e35d03af9f84edf32e29c1fc022b4411ba9b9
|
|
33
|
-
|
|
34
|
-
## Upstream documentation
|
|
35
|
-
|
|
36
|
-
* [API documentation](https://docs.rs/serde_magnus)
|
|
37
|
-
* [Releases/changelog](https://github.com/OneSignal/serde-magnus/releases)
|
|
38
|
-
* [`serde_magnus` on crates.io](https://crates.io/crates/serde_magnus)
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
41
|
-
|
|
42
|
-
The [`serde_magnus::serialize`] function converts from a Rust type implementing the
|
|
43
|
-
[`serde::Serialize`] trait into a Ruby equivalent.
|
|
44
|
-
|
|
45
|
-
```rust
|
|
46
|
-
use serde::{Serialize, Deserialize};
|
|
47
|
-
use magnus::{eval, Ruby, Value};
|
|
48
|
-
use serde_magnus::serialize;
|
|
49
|
-
|
|
50
|
-
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
51
|
-
struct Post {
|
|
52
|
-
title: String,
|
|
53
|
-
content: String,
|
|
54
|
-
author: Author,
|
|
55
|
-
tags: Vec<String>
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
|
59
|
-
struct Author {
|
|
60
|
-
name: String,
|
|
61
|
-
email_address: String
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let post = Post {
|
|
65
|
-
title: "Spring carnival planning update".into(),
|
|
66
|
-
content: "Here's what's new.".into(),
|
|
67
|
-
author: Author {
|
|
68
|
-
name: "Martha".into(),
|
|
69
|
-
email_address: "martha@example.com".into()
|
|
70
|
-
},
|
|
71
|
-
tags: vec![
|
|
72
|
-
"carnival".into(),
|
|
73
|
-
"update".into()
|
|
74
|
-
]
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
let ruby = Ruby::get().unwrap();
|
|
78
|
-
let post: Value = serialize(&ruby, &post)?;
|
|
79
|
-
|
|
80
|
-
assert!(eval!(
|
|
81
|
-
&ruby,
|
|
82
|
-
r#"
|
|
83
|
-
post == {
|
|
84
|
-
title: "Spring carnival planning update",
|
|
85
|
-
content: "Here's what's new.",
|
|
86
|
-
author: {
|
|
87
|
-
name: "Martha",
|
|
88
|
-
email_address: "martha@example.com"
|
|
89
|
-
},
|
|
90
|
-
tags: ["carnival", "update"]
|
|
91
|
-
}
|
|
92
|
-
"#,
|
|
93
|
-
post
|
|
94
|
-
)?);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
[`serde_magnus::deserialize`] converts from a Ruby value to a Rust type implementing
|
|
98
|
-
[`serde::Deserialize`].
|
|
99
|
-
|
|
100
|
-
```rust
|
|
101
|
-
use magnus::{RHash, Ruby};
|
|
102
|
-
use serde_magnus::deserialize;
|
|
103
|
-
|
|
104
|
-
let ruby = Ruby::get().unwrap();
|
|
105
|
-
let post: RHash = eval!(&ruby, r#"
|
|
106
|
-
{
|
|
107
|
-
title: "Spring carnival planning update",
|
|
108
|
-
content: "Here's what's new.",
|
|
109
|
-
author: {
|
|
110
|
-
name: "Martha",
|
|
111
|
-
email_address: "martha@example.com"
|
|
112
|
-
},
|
|
113
|
-
tags: ["carnival", "update"]
|
|
114
|
-
}
|
|
115
|
-
"#)?;
|
|
116
|
-
|
|
117
|
-
let post: Post = deserialize(&ruby, post)?;
|
|
118
|
-
|
|
119
|
-
assert_eq!(
|
|
120
|
-
Post {
|
|
121
|
-
title: "Spring carnival planning update".into(),
|
|
122
|
-
content: "Here's what's new.".into(),
|
|
123
|
-
author: Author {
|
|
124
|
-
name: "Martha".into(),
|
|
125
|
-
email_address: "martha@example.com".into(),
|
|
126
|
-
},
|
|
127
|
-
tags: vec![
|
|
128
|
-
"carnival".into(),
|
|
129
|
-
"update".into()
|
|
130
|
-
]
|
|
131
|
-
},
|
|
132
|
-
post
|
|
133
|
-
);
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
[`serde_magnus::serialize`]: https://docs.rs/serde_magnus/latest/serde_magnus/fn.serialize.html
|
|
137
|
-
[`serde::Serialize`]: https://docs.rs/serde/latest/serde/trait.Serialize.html
|
|
138
|
-
[`serde_magnus::deserialize`]: https://docs.rs/serde_magnus/latest/serde_magnus/fn.deserialize.html
|
|
139
|
-
[`serde::Deserialize`]: https://docs.rs/serde/latest/serde/trait.Deserialize.html
|
|
140
|
-
|
|
141
|
-
## Requirements
|
|
142
|
-
|
|
143
|
-
The local crate shares the Rust and Ruby requirements of `wreq-ruby`.
|
|
144
|
-
|
|
145
|
-
## License
|
|
146
|
-
|
|
147
|
-
`serde_magnus` is released under the terms of the MIT License. See `LICENSE` for details.
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
require "socket"
|
|
5
|
-
require "stringio"
|
|
6
|
-
require "timeout"
|
|
7
|
-
|
|
8
|
-
class EmulationClientHelloTest < Minitest::Test
|
|
9
|
-
SUPPORTED_GROUPS = 10
|
|
10
|
-
SIGNATURE_ALGORITHMS = 13
|
|
11
|
-
KEY_SHARE = 51
|
|
12
|
-
TRUST_ANCHOR_IDS = 51_764
|
|
13
|
-
ENCRYPTED_CLIENT_HELLO = 65_037
|
|
14
|
-
|
|
15
|
-
def test_reusing_chrome_emulation_preserves_trust_anchors
|
|
16
|
-
[Wreq::Profile::Chrome152, Wreq::Profile::Chrome153, Wreq::Profile::Chrome154, Wreq::Profile::Chrome155, Wreq::Profile::Chrome156, Wreq::Profile::Chrome157].each do |profile|
|
|
17
|
-
emulation = Wreq::Emulation.new(profile: profile)
|
|
18
|
-
client = Wreq::Client.new(emulation: emulation, no_proxy: true)
|
|
19
|
-
_, extensions = capture_client_hello { |url| client.get(url, timeout: 5) }
|
|
20
|
-
expected = extensions.fetch(TRUST_ANCHOR_IDS)
|
|
21
|
-
refute_empty expected, profile.to_s
|
|
22
|
-
|
|
23
|
-
request_client = Wreq::Client.new(no_proxy: true)
|
|
24
|
-
2.times do
|
|
25
|
-
_, actual_extensions = capture_client_hello do |url|
|
|
26
|
-
request_client.get(url, emulation: emulation, timeout: 5)
|
|
27
|
-
end
|
|
28
|
-
assert_equal expected, actual_extensions.fetch(TRUST_ANCHOR_IDS), "#{profile}: reusing an object must retain its configuration"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_edge158_sends_signature_grease_without_trust_anchors
|
|
34
|
-
client = Wreq::Client.new(emulation: Wreq::Emulation.new(profile: Wreq::Profile::Edge158), no_proxy: true)
|
|
35
|
-
_, extensions = capture_client_hello { |url| client.get(url, timeout: 5) }
|
|
36
|
-
|
|
37
|
-
_, grease, *signatures = extensions.fetch(SIGNATURE_ALGORITHMS).unpack("n*")
|
|
38
|
-
assert_equal 0x0a0a, grease & 0x0f0f
|
|
39
|
-
assert_equal grease >> 8, grease & 0xff
|
|
40
|
-
assert_equal [0x0904, 0x0905, 0x0906], signatures.first(3) # ML-DSA
|
|
41
|
-
refute extensions.key?(TRUST_ANCHOR_IDS)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_firefox_client_hello_matches_version
|
|
45
|
-
suites_153 = [
|
|
46
|
-
0x1301, 0x1303, 0x1302,
|
|
47
|
-
0xc02b, 0xc02f, 0xcca9, 0xcca8, 0xc02c, 0xc030, 0xc00a, 0xc013, 0xc014, 0x009c, 0x009d, 0x002f, 0x0035
|
|
48
|
-
]
|
|
49
|
-
# Firefox 154 disabled TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.
|
|
50
|
-
suites_154 = suites_153.reject { |suite| suite == 0xc00a }
|
|
51
|
-
|
|
52
|
-
[
|
|
53
|
-
[Wreq::Profile::Firefox153, suites_153, 15, [4588, 29, 23, 24, 25, 256, 257]],
|
|
54
|
-
[Wreq::Profile::Firefox154, suites_154, 15, [4588, 29, 23, 24, 25, 256, 257]],
|
|
55
|
-
[Wreq::Profile::Firefox155, suites_154, 16, [4588, 29, 23, 24, 25, 256, 257]],
|
|
56
|
-
[Wreq::Profile::Firefox156, suites_154, 16, [4588, 29, 23, 24, 25]]
|
|
57
|
-
].each do |profile, expected_suites, padding_remainder, groups|
|
|
58
|
-
client = Wreq::Client.new(emulation: Wreq::Emulation.new(profile: profile), no_proxy: true)
|
|
59
|
-
suites, extensions = capture_client_hello { |url| client.get(url, timeout: 5) }
|
|
60
|
-
assert_equal [4588, 29, 23], key_share_groups(extensions.fetch(KEY_SHARE)), "#{profile}: key share groups"
|
|
61
|
-
assert_equal expected_suites, suites, "#{profile}: cipher suites"
|
|
62
|
-
|
|
63
|
-
assert_equal padding_remainder, ech_payload_size(extensions.fetch(ENCRYPTED_CLIENT_HELLO)) % 32, "#{profile}: ECH GREASE ciphertext"
|
|
64
|
-
assert_equal groups, extensions.fetch(SUPPORTED_GROUPS).unpack("n*").drop(1), "#{profile}: supported groups"
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
# Each listener forces a new connection. Stop after ClientHello so this test
|
|
71
|
-
# inspects the wire bytes without depending on certificates or an external service.
|
|
72
|
-
def capture_client_hello
|
|
73
|
-
server = TCPServer.new("127.0.0.1", 0)
|
|
74
|
-
thread = Thread.new do
|
|
75
|
-
socket = nil
|
|
76
|
-
Timeout.timeout(5) do
|
|
77
|
-
socket = server.accept
|
|
78
|
-
handshake = +"".b
|
|
79
|
-
loop do
|
|
80
|
-
header = read_tls_bytes(socket, 5)
|
|
81
|
-
raise "expected a TLS handshake record" unless header.getbyte(0) == 22
|
|
82
|
-
handshake << read_tls_bytes(socket, header.byteslice(3, 2).unpack1("n"))
|
|
83
|
-
next if handshake.bytesize < 4
|
|
84
|
-
length = handshake.byteslice(1, 3).bytes.reduce(0) { |n, byte| (n << 8) | byte }
|
|
85
|
-
break if handshake.bytesize >= length + 4
|
|
86
|
-
end
|
|
87
|
-
parse_client_hello(handshake)
|
|
88
|
-
end
|
|
89
|
-
ensure
|
|
90
|
-
socket&.close
|
|
91
|
-
end
|
|
92
|
-
thread.report_on_exception = false
|
|
93
|
-
|
|
94
|
-
assert_raises(Wreq::ConnectionError) { yield "https://127.0.0.1:#{server.addr[1]}/" }
|
|
95
|
-
thread.value
|
|
96
|
-
ensure
|
|
97
|
-
server&.close
|
|
98
|
-
thread&.kill if thread&.alive?
|
|
99
|
-
thread&.join
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def read_tls_bytes(io, length)
|
|
103
|
-
bytes = io.read(length)
|
|
104
|
-
raise EOFError, "truncated ClientHello" unless bytes&.bytesize == length
|
|
105
|
-
bytes
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def parse_client_hello(handshake)
|
|
109
|
-
io = StringIO.new(handshake)
|
|
110
|
-
raise "expected ClientHello" unless read_tls_bytes(io, 1).unpack1("C") == 1
|
|
111
|
-
read_tls_bytes(io, 3 + 2 + 32) # Handshake length, legacy version and random.
|
|
112
|
-
read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Session ID.
|
|
113
|
-
suites = read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")).unpack("n*")
|
|
114
|
-
read_tls_bytes(io, read_tls_bytes(io, 1).unpack1("C")) # Compression methods.
|
|
115
|
-
extensions = StringIO.new(read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")))
|
|
116
|
-
parsed = {}
|
|
117
|
-
until extensions.eof?
|
|
118
|
-
type, length = read_tls_bytes(extensions, 4).unpack("nn")
|
|
119
|
-
parsed[type] = read_tls_bytes(extensions, length)
|
|
120
|
-
end
|
|
121
|
-
[suites, parsed]
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def ech_payload_size(extension)
|
|
125
|
-
io = StringIO.new(extension)
|
|
126
|
-
read_tls_bytes(io, 6) # Outer tag, HPKE suite and config ID.
|
|
127
|
-
read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")) # Encapsulated key.
|
|
128
|
-
read_tls_bytes(io, 2).unpack1("n")
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def key_share_groups(extension)
|
|
132
|
-
io = StringIO.new(extension)
|
|
133
|
-
entries = StringIO.new(read_tls_bytes(io, read_tls_bytes(io, 2).unpack1("n")))
|
|
134
|
-
groups = []
|
|
135
|
-
until entries.eof?
|
|
136
|
-
group, length = read_tls_bytes(entries, 4).unpack("nn")
|
|
137
|
-
read_tls_bytes(entries, length) # Key exchange bytes.
|
|
138
|
-
groups << group
|
|
139
|
-
end
|
|
140
|
-
groups
|
|
141
|
-
end
|
|
142
|
-
end
|