tls-client-python 1.16.0.1__py3-none-macosx_10_9_universal2.whl
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.
- tls_client/__init__.py +81 -0
- tls_client/_client_hints.py +162 -0
- tls_client/_core.py +4738 -0
- tls_client/_default_headers.py +370 -0
- tls_client/_multipart_boundary.py +54 -0
- tls_client/adapters.py +8 -0
- tls_client/auth.py +45 -0
- tls_client/bin/tls-client-darwin-amd64.dylib +0 -0
- tls_client/bin/tls-client-darwin-arm64.dylib +0 -0
- tls_client/context.py +347 -0
- tls_client/cookies.py +189 -0
- tls_client/ech.py +50 -0
- tls_client/exceptions.py +91 -0
- tls_client/hooks.py +30 -0
- tls_client/models.py +6 -0
- tls_client/requests_compat.py +674 -0
- tls_client/status_codes.py +45 -0
- tls_client/structures.py +60 -0
- tls_client_python-1.16.0.1.dist-info/METADATA +620 -0
- tls_client_python-1.16.0.1.dist-info/RECORD +23 -0
- tls_client_python-1.16.0.1.dist-info/WHEEL +5 -0
- tls_client_python-1.16.0.1.dist-info/licenses/LICENSE +27 -0
- tls_client_python-1.16.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Default real-world browser headers for every TLS client identifier.
|
|
3
|
+
|
|
4
|
+
When a Session is created with ``client_identifier="chrome_146"`` and no
|
|
5
|
+
``default_headers`` are provided, the session automatically picks up the
|
|
6
|
+
correct, version-aligned headers for that browser fingerprint.
|
|
7
|
+
|
|
8
|
+
Headers are grouped by browser family with helper factories to ensure
|
|
9
|
+
consistency across versions. Every entry in ``ClientIdentifiers`` has a
|
|
10
|
+
corresponding key below.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import Dict
|
|
14
|
+
|
|
15
|
+
from tls_client._client_hints import full_version_for, high_entropy_hints
|
|
16
|
+
|
|
17
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
18
|
+
# Chrome helpers
|
|
19
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
20
|
+
|
|
21
|
+
def _chrome_ua(version: str) -> str:
|
|
22
|
+
return (
|
|
23
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
24
|
+
f" (KHTML, like Gecko) Chrome/{version}.0.0.0 Safari/537.36"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _chrome_headers(version: str, *, zstd: bool = False) -> Dict[str, str]:
|
|
29
|
+
"""Standard Chrome desktop headers. *zstd* is True for Chrome ≥117."""
|
|
30
|
+
enc = "gzip, deflate, br, zstd" if zstd else "gzip, deflate, br"
|
|
31
|
+
sec_ch_ua = (
|
|
32
|
+
f'"Chromium";v="{version}", "Google Chrome";v="{version}",'
|
|
33
|
+
f' "Not?A_Brand";v="99"'
|
|
34
|
+
)
|
|
35
|
+
headers: Dict[str, str] = {
|
|
36
|
+
"User-Agent": _chrome_ua(version),
|
|
37
|
+
"sec-ch-ua": sec_ch_ua,
|
|
38
|
+
"sec-ch-ua-mobile": "?0",
|
|
39
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
40
|
+
"Accept": (
|
|
41
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,"
|
|
42
|
+
"image/avif,image/webp,image/apng,*/*;q=0.8,"
|
|
43
|
+
"application/signed-exchange;v=b3;q=0.7"
|
|
44
|
+
),
|
|
45
|
+
"Accept-Encoding": enc,
|
|
46
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
47
|
+
}
|
|
48
|
+
headers.update(
|
|
49
|
+
high_entropy_hints("windows", sec_ch_ua, full_version_for(int(version)))
|
|
50
|
+
)
|
|
51
|
+
return headers
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _chrome_psk(version: str, *, zstd: bool = False) -> Dict[str, str]:
|
|
55
|
+
"""Chrome PSK variant — identical desktop headers."""
|
|
56
|
+
return _chrome_headers(version, zstd=zstd)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
60
|
+
# Brave (Chromium fork — prominent "Brave" brand in sec-ch-ua)
|
|
61
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
62
|
+
|
|
63
|
+
def _brave_headers(version: str, *, zstd: bool = True) -> Dict[str, str]:
|
|
64
|
+
enc = "gzip, deflate, br, zstd" if zstd else "gzip, deflate, br"
|
|
65
|
+
sec_ch_ua = (
|
|
66
|
+
f'"Chromium";v="{version}", "Brave";v="{version}",'
|
|
67
|
+
f' "Not?A_Brand";v="99"'
|
|
68
|
+
)
|
|
69
|
+
headers: Dict[str, str] = {
|
|
70
|
+
"User-Agent": _chrome_ua(version),
|
|
71
|
+
"sec-ch-ua": sec_ch_ua,
|
|
72
|
+
"sec-ch-ua-mobile": "?0",
|
|
73
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
74
|
+
"Accept": (
|
|
75
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,"
|
|
76
|
+
"image/avif,image/webp,image/apng,*/*;q=0.8,"
|
|
77
|
+
"application/signed-exchange;v=b3;q=0.7"
|
|
78
|
+
),
|
|
79
|
+
"Accept-Encoding": enc,
|
|
80
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
81
|
+
}
|
|
82
|
+
headers.update(
|
|
83
|
+
high_entropy_hints("windows", sec_ch_ua, full_version_for(int(version)))
|
|
84
|
+
)
|
|
85
|
+
return headers
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
89
|
+
# Opera (Chromium fork — "OPR" in UA, "Opera" in sec-ch-ua)
|
|
90
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
91
|
+
|
|
92
|
+
def _opera_headers(
|
|
93
|
+
opera_ver: str, chromium_ver: str, *, zstd: bool = False
|
|
94
|
+
) -> Dict[str, str]:
|
|
95
|
+
enc = "gzip, deflate, br, zstd" if zstd else "gzip, deflate, br"
|
|
96
|
+
sec_ch_ua = (
|
|
97
|
+
f'"Chromium";v="{chromium_ver}", "Opera";v="{opera_ver}",'
|
|
98
|
+
f' "Not?A_Brand";v="99"'
|
|
99
|
+
)
|
|
100
|
+
headers: Dict[str, str] = {
|
|
101
|
+
"User-Agent": (
|
|
102
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
103
|
+
f" (KHTML, like Gecko) Chrome/{chromium_ver}.0.0.0 Safari/537.36"
|
|
104
|
+
f" OPR/{opera_ver}.0.0.0"
|
|
105
|
+
),
|
|
106
|
+
"sec-ch-ua": sec_ch_ua,
|
|
107
|
+
"sec-ch-ua-mobile": "?0",
|
|
108
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
109
|
+
"Accept": (
|
|
110
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,"
|
|
111
|
+
"image/avif,image/webp,image/apng,*/*;q=0.8,"
|
|
112
|
+
"application/signed-exchange;v=b3;q=0.7"
|
|
113
|
+
),
|
|
114
|
+
"Accept-Encoding": enc,
|
|
115
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
116
|
+
}
|
|
117
|
+
headers.update(
|
|
118
|
+
high_entropy_hints(
|
|
119
|
+
"windows", sec_ch_ua, full_version_for(int(chromium_ver))
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
return headers
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
126
|
+
# Safari (macOS) — NO Client Hints
|
|
127
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
128
|
+
|
|
129
|
+
def _safari_macos(version: str) -> Dict[str, str]:
|
|
130
|
+
return {
|
|
131
|
+
"User-Agent": (
|
|
132
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"
|
|
133
|
+
f" AppleWebKit/605.1.15 (KHTML, like Gecko)"
|
|
134
|
+
f" Version/{version} Safari/605.1.15"
|
|
135
|
+
),
|
|
136
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
137
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
138
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
143
|
+
# Safari (iOS) — NO Client Hints
|
|
144
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
145
|
+
|
|
146
|
+
def _safari_ios(ios_ver: str, safari_ver: str) -> Dict[str, str]:
|
|
147
|
+
return {
|
|
148
|
+
"User-Agent": (
|
|
149
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS"
|
|
150
|
+
f" {ios_ver.replace('.', '_')} like Mac OS X)"
|
|
151
|
+
f" AppleWebKit/605.1.15 (KHTML, like Gecko)"
|
|
152
|
+
f" Version/{safari_ver} Mobile/15E148 Safari/604.1"
|
|
153
|
+
),
|
|
154
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
155
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
156
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
161
|
+
# Safari (iPad) — NO Client Hints
|
|
162
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
163
|
+
|
|
164
|
+
def _safari_ipad(ios_ver: str, safari_ver: str) -> Dict[str, str]:
|
|
165
|
+
return {
|
|
166
|
+
"User-Agent": (
|
|
167
|
+
"Mozilla/5.0 (iPad; CPU OS"
|
|
168
|
+
f" {ios_ver.replace('.', '_')} like Mac OS X)"
|
|
169
|
+
f" AppleWebKit/605.1.15 (KHTML, like Gecko)"
|
|
170
|
+
f" Version/{safari_ver} Mobile/15E148 Safari/604.1"
|
|
171
|
+
),
|
|
172
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
173
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
174
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
179
|
+
# Firefox (desktop) — NO Client Hints; Firefox-specific Accept header
|
|
180
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
181
|
+
|
|
182
|
+
def _firefox_headers(version: str) -> Dict[str, str]:
|
|
183
|
+
return {
|
|
184
|
+
"User-Agent": (
|
|
185
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:"
|
|
186
|
+
f"{version}.0) Gecko/20100101 Firefox/{version}.0"
|
|
187
|
+
),
|
|
188
|
+
"Accept": (
|
|
189
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,"
|
|
190
|
+
"*/*;q=0.8"
|
|
191
|
+
),
|
|
192
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
193
|
+
"Accept-Language": "en-US,en;q=0.5",
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _firefox_psk(version: str) -> Dict[str, str]:
|
|
198
|
+
"""Firefox PSK variant — same desktop headers."""
|
|
199
|
+
return _firefox_headers(version)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
203
|
+
# Native App — OkHttp (Android) — minimal, no browser features
|
|
204
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
205
|
+
|
|
206
|
+
def _okhttp_headers(version: str) -> Dict[str, str]:
|
|
207
|
+
return {
|
|
208
|
+
"User-Agent": f"okhttp/4.{version}.0",
|
|
209
|
+
"Accept-Encoding": "gzip",
|
|
210
|
+
"Connection": "Keep-Alive",
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
215
|
+
# Native App — iOS (CFNetwork / Darwin) — minimal
|
|
216
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
217
|
+
|
|
218
|
+
def _ios_app_headers(app_name: str) -> Dict[str, str]:
|
|
219
|
+
return {
|
|
220
|
+
"User-Agent": (
|
|
221
|
+
f"{app_name}/1.0 (iPhone; iOS 18.0; Scale/3.00)"
|
|
222
|
+
),
|
|
223
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
224
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
229
|
+
# Native App — Android (Dalvik) — minimal
|
|
230
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
231
|
+
|
|
232
|
+
def _android_app_headers(app_name: str) -> Dict[str, str]:
|
|
233
|
+
return {
|
|
234
|
+
"User-Agent": f"{app_name} (Linux; Android 14; en_US)",
|
|
235
|
+
"Accept-Encoding": "gzip",
|
|
236
|
+
"Connection": "Keep-Alive",
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
241
|
+
# Cloudscraper — generic Cloudflare-bypass headers
|
|
242
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
243
|
+
|
|
244
|
+
_CLOUDSCRAPER_HEADERS: Dict[str, str] = {
|
|
245
|
+
"User-Agent": (
|
|
246
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
|
247
|
+
" (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
248
|
+
),
|
|
249
|
+
"Accept": (
|
|
250
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,"
|
|
251
|
+
"image/avif,image/webp,*/*;q=0.8"
|
|
252
|
+
),
|
|
253
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
254
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
259
|
+
# The complete mapping — every ClientIdentifiers literal → default headers
|
|
260
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
261
|
+
|
|
262
|
+
DEFAULT_HEADERS: Dict[str, Dict[str, str]] = {
|
|
263
|
+
# ── Chrome 103 – 112 (pre‑zstd) ──────────────────────────────────────
|
|
264
|
+
"chrome_103": _chrome_headers("103"),
|
|
265
|
+
"chrome_104": _chrome_headers("104"),
|
|
266
|
+
"chrome_105": _chrome_headers("105"),
|
|
267
|
+
"chrome_106": _chrome_headers("106"),
|
|
268
|
+
"chrome_107": _chrome_headers("107"),
|
|
269
|
+
"chrome_108": _chrome_headers("108"),
|
|
270
|
+
"chrome_109": _chrome_headers("109"),
|
|
271
|
+
"chrome_110": _chrome_headers("110"),
|
|
272
|
+
"chrome_111": _chrome_headers("111"),
|
|
273
|
+
"chrome_112": _chrome_headers("112"),
|
|
274
|
+
# ── Chrome 116 (PSK / PSK_PQ) ────────────────────────────────────────
|
|
275
|
+
"chrome_116_PSK": _chrome_psk("116"),
|
|
276
|
+
"chrome_116_PSK_PQ": _chrome_psk("116"),
|
|
277
|
+
# ── Chrome 117+ (zstd in Accept-Encoding) ────────────────────────────
|
|
278
|
+
"chrome_117": _chrome_headers("117", zstd=True),
|
|
279
|
+
"chrome_120": _chrome_headers("120", zstd=True),
|
|
280
|
+
"chrome_124": _chrome_headers("124", zstd=True),
|
|
281
|
+
# ── Chrome 130+ ──────────────────────────────────────────────────────
|
|
282
|
+
"chrome_130_PSK": _chrome_psk("130", zstd=True),
|
|
283
|
+
# ── Chrome 131 ───────────────────────────────────────────────────────
|
|
284
|
+
"chrome_131": _chrome_headers("131", zstd=True),
|
|
285
|
+
"chrome_131_PSK": _chrome_psk("131", zstd=True),
|
|
286
|
+
# ── Chrome 133 ───────────────────────────────────────────────────────
|
|
287
|
+
"chrome_133": _chrome_headers("133", zstd=True),
|
|
288
|
+
"chrome_133_PSK": _chrome_psk("133", zstd=True),
|
|
289
|
+
# ── Chrome 144 ───────────────────────────────────────────────────────
|
|
290
|
+
"chrome_144": _chrome_headers("144", zstd=True),
|
|
291
|
+
"chrome_144_PSK": _chrome_psk("144", zstd=True),
|
|
292
|
+
# ── Chrome 146 ───────────────────────────────────────────────────────
|
|
293
|
+
"chrome_146": _chrome_headers("146", zstd=True),
|
|
294
|
+
"chrome_146_PSK": _chrome_psk("146", zstd=True),
|
|
295
|
+
"chrome_150": _chrome_headers("150", zstd=True),
|
|
296
|
+
"chrome_150_PSK": _chrome_psk("150", zstd=True),
|
|
297
|
+
"chrome_152": _chrome_headers("152", zstd=True),
|
|
298
|
+
"chrome_152_PSK": _chrome_psk("152", zstd=True),
|
|
299
|
+
# ── Brave 146 ────────────────────────────────────────────────────────
|
|
300
|
+
"brave_146": _brave_headers("146"),
|
|
301
|
+
"brave_146_PSK": _brave_headers("146"),
|
|
302
|
+
# ── Safari macOS ──────────────────────────────────────────────────────
|
|
303
|
+
"safari_15_6_1": _safari_macos("15.6.1"),
|
|
304
|
+
"safari_16_0": _safari_macos("16.0"),
|
|
305
|
+
# ── Safari iPad ───────────────────────────────────────────────────────
|
|
306
|
+
"safari_ipad_15_6": _safari_ipad("15.6", "15.6"),
|
|
307
|
+
# ── Safari iOS ────────────────────────────────────────────────────────
|
|
308
|
+
"safari_ios_15_5": _safari_ios("15.5", "15.5"),
|
|
309
|
+
"safari_ios_15_6": _safari_ios("15.6", "15.6"),
|
|
310
|
+
"safari_ios_16_0": _safari_ios("16.0", "16.0"),
|
|
311
|
+
"safari_ios_17_0": _safari_ios("17.0", "17.0"),
|
|
312
|
+
"safari_ios_18_0": _safari_ios("18.0", "18.0"),
|
|
313
|
+
"safari_ios_18_5": _safari_ios("18.5", "18.5"),
|
|
314
|
+
"safari_ios_26_0": _safari_ios("26.0", "26.0"),
|
|
315
|
+
# ── Firefox 102 – 110 ─────────────────────────────────────────────────
|
|
316
|
+
"firefox_102": _firefox_headers("102"),
|
|
317
|
+
"firefox_104": _firefox_headers("104"),
|
|
318
|
+
"firefox_105": _firefox_headers("105"),
|
|
319
|
+
"firefox_106": _firefox_headers("106"),
|
|
320
|
+
"firefox_108": _firefox_headers("108"),
|
|
321
|
+
"firefox_110": _firefox_headers("110"),
|
|
322
|
+
# ── Firefox 117 – 123 ─────────────────────────────────────────────────
|
|
323
|
+
"firefox_117": _firefox_headers("117"),
|
|
324
|
+
"firefox_120": _firefox_headers("120"),
|
|
325
|
+
"firefox_123": _firefox_headers("123"),
|
|
326
|
+
# ── Firefox 132 – 135 ─────────────────────────────────────────────────
|
|
327
|
+
"firefox_132": _firefox_headers("132"),
|
|
328
|
+
"firefox_133": _firefox_headers("133"),
|
|
329
|
+
"firefox_135": _firefox_headers("135"),
|
|
330
|
+
# ── Firefox 146 – 148 ─────────────────────────────────────────────────
|
|
331
|
+
"firefox_146_PSK": _firefox_psk("146"),
|
|
332
|
+
"firefox_147": _firefox_headers("147"),
|
|
333
|
+
"firefox_147_PSK": _firefox_psk("147"),
|
|
334
|
+
"firefox_148": _firefox_headers("148"),
|
|
335
|
+
# ── Opera (Chromium‑based, Opera‑branded sec‑ch‑ua) ──────────────────
|
|
336
|
+
"opera_89": _opera_headers("89", "103"),
|
|
337
|
+
"opera_90": _opera_headers("90", "104"),
|
|
338
|
+
"opera_91": _opera_headers("91", "105"),
|
|
339
|
+
# ── Zalando (native mobile apps) ─────────────────────────────────────
|
|
340
|
+
"zalando_android_mobile": _android_app_headers("Zalando"),
|
|
341
|
+
"zalando_ios_mobile": _ios_app_headers("Zalando"),
|
|
342
|
+
# ── Nike (native mobile apps) ────────────────────────────────────────
|
|
343
|
+
"nike_android_mobile": _android_app_headers("Nike"),
|
|
344
|
+
"nike_ios_mobile": _ios_app_headers("Nike"),
|
|
345
|
+
# ── Cloudscraper ──────────────────────────────────────────────────────
|
|
346
|
+
"cloudscraper": _CLOUDSCRAPER_HEADERS,
|
|
347
|
+
# ── MMS (native iOS apps) ────────────────────────────────────────────
|
|
348
|
+
"mms_ios": _ios_app_headers("MMS"),
|
|
349
|
+
"mms_ios_1": _ios_app_headers("MMS"),
|
|
350
|
+
"mms_ios_2": _ios_app_headers("MMS"),
|
|
351
|
+
"mms_ios_3": _ios_app_headers("MMS"),
|
|
352
|
+
# ── Mesh (native mobile apps) ────────────────────────────────────────
|
|
353
|
+
"mesh_ios": _ios_app_headers("Mesh"),
|
|
354
|
+
"mesh_ios_1": _ios_app_headers("Mesh"),
|
|
355
|
+
"mesh_ios_2": _ios_app_headers("Mesh"),
|
|
356
|
+
"mesh_android": _android_app_headers("Mesh"),
|
|
357
|
+
"mesh_android_1": _android_app_headers("Mesh"),
|
|
358
|
+
"mesh_android_2": _android_app_headers("Mesh"),
|
|
359
|
+
# ── Confirmed (native mobile apps) ───────────────────────────────────
|
|
360
|
+
"confirmed_ios": _ios_app_headers("Confirmed"),
|
|
361
|
+
"confirmed_android": _android_app_headers("Confirmed"),
|
|
362
|
+
# ── OkHttp 4.x (Android networking library) ──────────────────────────
|
|
363
|
+
"okhttp4_android_7": _okhttp_headers("7"),
|
|
364
|
+
"okhttp4_android_8": _okhttp_headers("8"),
|
|
365
|
+
"okhttp4_android_9": _okhttp_headers("9"),
|
|
366
|
+
"okhttp4_android_10": _okhttp_headers("10"),
|
|
367
|
+
"okhttp4_android_11": _okhttp_headers("11"),
|
|
368
|
+
"okhttp4_android_12": _okhttp_headers("12"),
|
|
369
|
+
"okhttp4_android_13": _okhttp_headers("13"),
|
|
370
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Browser-accurate multipart boundary generators.
|
|
2
|
+
|
|
3
|
+
Faithful ports of the boundary algorithms real browsers run, so multipart
|
|
4
|
+
bodies carry the same boundary shape a genuine browser would emit. A
|
|
5
|
+
UUID-hex boundary (``multipart/form-data; boundary=<32 hex chars>``) is an
|
|
6
|
+
immediate automation tell on multipart endpoints.
|
|
7
|
+
|
|
8
|
+
- Chrome / Chromium: Blink ``FormDataEncoder::GenerateUniqueBoundaryString``
|
|
9
|
+
(``----WebKitFormBoundary`` + 16 chars drawn from a 64-slot map where
|
|
10
|
+
'A' and 'B' appear twice, making them twice as likely — verbatim from
|
|
11
|
+
third_party/blink/renderer/platform/network/form_data_encoder.cc).
|
|
12
|
+
- Firefox: Gecko ``HTMLFormSubmission`` (27 dashes + three decimal
|
|
13
|
+
``uint32`` values, gecko-dev dom/html/HTMLFormSubmission.cpp).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import secrets
|
|
17
|
+
|
|
18
|
+
_BLINK_PREFIX = "----WebKitFormBoundary"
|
|
19
|
+
|
|
20
|
+
# The alphanumeric encoding map from Blink. 0x41 ('A') and 0x42 ('B')
|
|
21
|
+
# appear twice on purpose — do not "deduplicate" this table.
|
|
22
|
+
_BLINK_ENCODING_MAP = (
|
|
23
|
+
bytes(range(0x41, 0x5B)) # A-Z
|
|
24
|
+
+ bytes(range(0x61, 0x7B)) # a-z
|
|
25
|
+
+ bytes(range(0x30, 0x3A)) # 0-9
|
|
26
|
+
+ b"AB" # second occurrence of A/B
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
_GECKO_PREFIX = "---------------------------"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def blink_boundary() -> str:
|
|
33
|
+
"""Return a Chrome/Chromium style multipart boundary."""
|
|
34
|
+
randomness = secrets.randbits(128)
|
|
35
|
+
chars = [
|
|
36
|
+
_BLINK_ENCODING_MAP[(randomness >> shift) & 0x3F]
|
|
37
|
+
for shift in range(0, 96, 6)
|
|
38
|
+
]
|
|
39
|
+
return _BLINK_PREFIX + "".join(chr(code) for code in chars)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def gecko_boundary() -> str:
|
|
43
|
+
"""Return a Firefox style multipart boundary."""
|
|
44
|
+
parts = []
|
|
45
|
+
for _ in range(3):
|
|
46
|
+
parts.append(str(secrets.randbits(32)))
|
|
47
|
+
return _GECKO_PREFIX + "".join(parts)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def boundary(browser: str = "chrome") -> str:
|
|
51
|
+
"""Return a browser-accurate boundary for *browser* ("chrome"/"firefox")."""
|
|
52
|
+
if browser == "firefox":
|
|
53
|
+
return gecko_boundary()
|
|
54
|
+
return blink_boundary()
|
tls_client/adapters.py
ADDED
tls_client/auth.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Authentication helpers compatible with the common Requests API."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuthBase(object):
|
|
7
|
+
def __call__(self, request):
|
|
8
|
+
raise NotImplementedError("authentication classes must implement __call__")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class HTTPBasicAuth(AuthBase):
|
|
12
|
+
def __init__(self, username, password):
|
|
13
|
+
self.username = username
|
|
14
|
+
self.password = password
|
|
15
|
+
|
|
16
|
+
def __call__(self, request):
|
|
17
|
+
raw = ("%s:%s" % (self.username, self.password)).encode("latin1")
|
|
18
|
+
request.headers["Authorization"] = "Basic " + base64.b64encode(raw).decode("ascii")
|
|
19
|
+
return request
|
|
20
|
+
|
|
21
|
+
def __eq__(self, other):
|
|
22
|
+
return (
|
|
23
|
+
isinstance(other, HTTPBasicAuth)
|
|
24
|
+
and self.username == other.username
|
|
25
|
+
and self.password == other.password
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class HTTPProxyAuth(HTTPBasicAuth):
|
|
30
|
+
def __call__(self, request):
|
|
31
|
+
raw = ("%s:%s" % (self.username, self.password)).encode("latin1")
|
|
32
|
+
request.headers["Proxy-Authorization"] = (
|
|
33
|
+
"Basic " + base64.b64encode(raw).decode("ascii")
|
|
34
|
+
)
|
|
35
|
+
return request
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class HTTPDigestAuth(AuthBase):
|
|
39
|
+
def __init__(self, username, password):
|
|
40
|
+
self.username = username
|
|
41
|
+
self.password = password
|
|
42
|
+
|
|
43
|
+
def __call__(self, request):
|
|
44
|
+
raise NotImplementedError("HTTP Digest authentication requires challenge replay")
|
|
45
|
+
|
|
Binary file
|
|
Binary file
|