wreq 1.3.2.4 → 1.3.3
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/Cargo.lock +470 -50
- data/Cargo.toml +19 -16
- data/README.md +5 -12
- data/Rakefile +3 -9
- data/crates/wreq-util/Cargo.toml +1 -1
- data/crates/wreq-util/README.md +4 -2
- data/crates/wreq-util/examples/emulate.rs +7 -3
- data/crates/wreq-util/examples/tower_delay.rs +4 -4
- data/crates/wreq-util/src/emulate/macros.rs +197 -32
- data/crates/wreq-util/src/emulate/profile/chrome/header.rs +116 -0
- data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
- data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +268 -0
- data/crates/wreq-util/src/emulate/profile/chrome.rs +2269 -0
- data/crates/wreq-util/src/emulate/profile/firefox/header.rs +54 -48
- data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +102 -92
- data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +146 -155
- data/crates/wreq-util/src/emulate/profile/firefox.rs +440 -312
- data/crates/wreq-util/src/emulate/profile/okhttp.rs +2 -3
- data/crates/wreq-util/src/emulate/profile/opera/header.rs +29 -0
- data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
- data/crates/wreq-util/src/emulate/profile/opera/tls.rs +103 -0
- data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
- data/crates/wreq-util/src/emulate/profile.rs +10 -10
- data/crates/wreq-util/src/emulate.rs +1 -34
- data/crates/wreq-util/src/tower/delay/layer.rs +5 -5
- data/crates/wreq-util/src/tower/delay.rs +4 -4
- data/crates/wreq-util/tests/client.rs +50 -187
- data/crates/wreq-util/tests/emulate_chrome.rs +0 -17
- data/crates/wreq-util/tests/emulate_firefox.rs +26 -36
- data/crates/wreq-util/tests/emulate_opera.rs +0 -24
- data/crates/wreq-util/tests/support/mod.rs +1 -1
- 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/src/client/body/json.rs +1 -2
- data/src/client/resp.rs +1 -1
- data/src/client.rs +8 -4
- data/src/emulate.rs +5 -28
- data/src/error.rs +23 -3
- data/src/lib.rs +3 -2
- data/src/options.rs +17 -19
- data/{crates/serde-magnus/src → src/serde}/de/array_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/array_enumerator.rs +1 -1
- data/{crates/serde-magnus/src → src/serde}/de/deserializer.rs +31 -25
- data/{crates/serde-magnus/src → src/serde}/de/enum_deserializer.rs +3 -3
- data/{crates/serde-magnus/src → src/serde}/de/hash_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/number_deserializer.rs +2 -2
- data/{crates/serde-magnus/src → src/serde}/de/variant_deserializer.rs +20 -11
- data/src/serde/de.rs +33 -0
- data/src/serde/error.rs +146 -0
- data/src/serde/ser/enums.rs +14 -0
- data/{crates/serde-magnus/src → src/serde}/ser/map_serializer.rs +2 -2
- data/src/serde/ser/seq_serializer.rs +71 -0
- data/src/serde/ser/serializer.rs +194 -0
- data/{crates/serde-magnus/src → src/serde}/ser/struct_serializer.rs +4 -4
- data/src/serde/ser/struct_variant_serializer.rs +44 -0
- data/src/serde/ser/tuple_variant_serializer.rs +41 -0
- data/src/serde/ser.rs +18 -0
- data/{crates/serde-magnus/src → src/serde}/tests.rs +68 -19
- data/src/serde.rs +202 -0
- data/test/emulation_test.rb +104 -21
- data/test/option_validation_test.rb +13 -4
- data/wreq.gemspec +15 -3
- metadata +29 -35
- data/VERSION +0 -1
- data/crates/README.md +0 -6
- data/crates/serde-magnus/Cargo.toml +0 -29
- data/crates/serde-magnus/LICENSE +0 -19
- data/crates/serde-magnus/README.md +0 -147
- data/crates/serde-magnus/src/de/mod.rs +0 -554
- data/crates/serde-magnus/src/error.rs +0 -84
- data/crates/serde-magnus/src/lib.rs +0 -137
- data/crates/serde-magnus/src/options.rs +0 -151
- data/crates/serde-magnus/src/ser/enums.rs +0 -11
- data/crates/serde-magnus/src/ser/mod.rs +0 -428
- data/crates/serde-magnus/src/ser/seq_serializer.rs +0 -68
- data/crates/serde-magnus/src/ser/serializer.rs +0 -220
- data/crates/serde-magnus/src/ser/struct_variant_serializer.rs +0 -45
- data/crates/serde-magnus/src/ser/tuple_variant_serializer.rs +0 -38
- data/crates/wreq-util/src/emulate/profile/chromium/chrome.rs +0 -731
- data/crates/wreq-util/src/emulate/profile/chromium/edge.rs +0 -418
- data/crates/wreq-util/src/emulate/profile/chromium/header.rs +0 -74
- data/crates/wreq-util/src/emulate/profile/chromium/http2.rs +0 -59
- data/crates/wreq-util/src/emulate/profile/chromium/opera.rs +0 -312
- data/crates/wreq-util/src/emulate/profile/chromium/tls.rs +0 -310
- data/crates/wreq-util/src/emulate/profile/chromium.rs +0 -9
- data/test/emulation_client_hello_test.rb +0 -142
|
@@ -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
|