tls-client-python 1.16.0__py3-none-win_amd64.whl → 1.16.0.2__py3-none-win_amd64.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 +19 -2
- tls_client/_client_hints.py +162 -0
- tls_client/_core.py +1025 -83
- tls_client/_default_headers.py +38 -15
- tls_client/_multipart_boundary.py +54 -0
- tls_client/bin/tls-client-windows-amd64.dll +0 -0
- tls_client/context.py +347 -0
- tls_client/ech.py +50 -0
- tls_client/fingerprints/__init__.py +43 -0
- tls_client/fingerprints/chrome.py +158 -0
- tls_client/fingerprints/chrome_full.py +7369 -0
- tls_client/fingerprints/firefox.py +113 -0
- tls_client/fingerprints/registry.py +166 -0
- tls_client/py.typed +0 -0
- tls_client/requests_compat.py +44 -10
- {tls_client_python-1.16.0.dist-info → tls_client_python-1.16.0.2.dist-info}/METADATA +234 -29
- tls_client_python-1.16.0.2.dist-info/RECORD +28 -0
- tls_client_python-1.16.0.dist-info/RECORD +0 -18
- {tls_client_python-1.16.0.dist-info → tls_client_python-1.16.0.2.dist-info}/WHEEL +0 -0
- {tls_client_python-1.16.0.dist-info → tls_client_python-1.16.0.2.dist-info}/licenses/LICENSE +0 -0
- {tls_client_python-1.16.0.dist-info → tls_client_python-1.16.0.2.dist-info}/top_level.txt +0 -0
tls_client/__init__.py
CHANGED
|
@@ -8,7 +8,12 @@ directory. A ``TLS_CLIENT_LIB`` environment variable may be used to
|
|
|
8
8
|
override automatic discovery.
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
-
from tls_client._core import
|
|
11
|
+
from tls_client._core import (
|
|
12
|
+
AsyncSession,
|
|
13
|
+
ClientIdentifiers,
|
|
14
|
+
SUPPORTED_CLIENT_IDENTIFIERS,
|
|
15
|
+
clear_client_pool,
|
|
16
|
+
)
|
|
12
17
|
from tls_client._core import Request as TLSRequest
|
|
13
18
|
from tls_client._core import Response as NativeResponse
|
|
14
19
|
from tls_client._core import Session as NativeSession
|
|
@@ -29,6 +34,10 @@ from tls_client.requests_compat import (
|
|
|
29
34
|
)
|
|
30
35
|
|
|
31
36
|
from tls_client import adapters, auth, cookies, exceptions, models, status_codes, structures
|
|
37
|
+
from tls_client import context as request_context
|
|
38
|
+
from tls_client import ech, fingerprints
|
|
39
|
+
from tls_client._multipart_boundary import blink_boundary, boundary, gecko_boundary
|
|
40
|
+
from tls_client.context import RequestContext
|
|
32
41
|
from tls_client.status_codes import codes
|
|
33
42
|
|
|
34
43
|
__all__ = [
|
|
@@ -42,6 +51,7 @@ __all__ = [
|
|
|
42
51
|
"NativeResponse",
|
|
43
52
|
"TLSRequest",
|
|
44
53
|
"ClientIdentifiers",
|
|
54
|
+
"SUPPORTED_CLIENT_IDENTIFIERS",
|
|
45
55
|
"clear_client_pool",
|
|
46
56
|
"request",
|
|
47
57
|
"get",
|
|
@@ -56,8 +66,15 @@ __all__ = [
|
|
|
56
66
|
"codes",
|
|
57
67
|
"cookies",
|
|
58
68
|
"exceptions",
|
|
69
|
+
"ech",
|
|
70
|
+
"fingerprints",
|
|
59
71
|
"models",
|
|
72
|
+
"request_context",
|
|
73
|
+
"RequestContext",
|
|
74
|
+
"blink_boundary",
|
|
75
|
+
"boundary",
|
|
76
|
+
"gecko_boundary",
|
|
60
77
|
"status_codes",
|
|
61
78
|
"structures",
|
|
62
79
|
]
|
|
63
|
-
__version__ = "1.16.0"
|
|
80
|
+
__version__ = "1.16.0.2"
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""High-entropy Client Hints for Chromium-family browsers.
|
|
2
|
+
|
|
3
|
+
Chrome emits these only after a host advertises ``Accept-CH`` (and the user
|
|
4
|
+
opts in), but impersonation libraries ship them so the header block is
|
|
5
|
+
complete and coherent when the target expects them. Values mirror Chromium
|
|
6
|
+
(verified against httpcloak's captured header logic):
|
|
7
|
+
|
|
8
|
+
- ``sec-ch-ua-full-version-list`` — each brand's exact build for real brands,
|
|
9
|
+
``<major>.0.0.0`` for the GREASE brand;
|
|
10
|
+
- ``sec-ch-ua-platform-version`` / ``-arch`` / ``-bitness`` / ``-model`` /
|
|
11
|
+
``-wow64`` — per-platform defaults.
|
|
12
|
+
|
|
13
|
+
The exact builds come from live handshakes (``tools/_chrome_captures.json``).
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from typing import Dict
|
|
17
|
+
|
|
18
|
+
# Exact Chrome build per major, captured from live handshakes.
|
|
19
|
+
CHROME_FULL_VERSIONS: Dict[int, str] = {
|
|
20
|
+
99: "99.0.4844.84",
|
|
21
|
+
100: "100.0.4896.127",
|
|
22
|
+
101: "101.0.4951.67",
|
|
23
|
+
102: "102.0.5005.115",
|
|
24
|
+
103: "103.0.5060.134",
|
|
25
|
+
104: "104.0.5112.102",
|
|
26
|
+
105: "105.0.5195.127",
|
|
27
|
+
106: "106.0.5249.119",
|
|
28
|
+
107: "107.0.5304.122",
|
|
29
|
+
108: "108.0.5359.125",
|
|
30
|
+
109: "109.0.5414.120",
|
|
31
|
+
110: "110.0.5481.178",
|
|
32
|
+
111: "111.0.5563.147",
|
|
33
|
+
112: "112.0.5615.138",
|
|
34
|
+
113: "113.0.5672.127",
|
|
35
|
+
114: "114.0.5735.199",
|
|
36
|
+
115: "115.0.5790.171",
|
|
37
|
+
116: "116.0.5845.188",
|
|
38
|
+
117: "117.0.5938.150",
|
|
39
|
+
118: "118.0.5993.118",
|
|
40
|
+
119: "119.0.6045.200",
|
|
41
|
+
120: "120.0.6099.225",
|
|
42
|
+
121: "121.0.6167.185",
|
|
43
|
+
122: "122.0.6261.129",
|
|
44
|
+
123: "123.0.6312.123",
|
|
45
|
+
124: "124.0.6367.208",
|
|
46
|
+
125: "125.0.6422.142",
|
|
47
|
+
126: "126.0.6478.183",
|
|
48
|
+
127: "127.0.6533.120",
|
|
49
|
+
128: "128.0.6613.138",
|
|
50
|
+
129: "129.0.6668.101",
|
|
51
|
+
130: "130.0.6723.117",
|
|
52
|
+
131: "131.0.6778.265",
|
|
53
|
+
132: "132.0.6834.160",
|
|
54
|
+
133: "133.0.6943.142",
|
|
55
|
+
134: "134.0.6998.178",
|
|
56
|
+
135: "135.0.7049.115",
|
|
57
|
+
136: "136.0.7103.114",
|
|
58
|
+
137: "137.0.7151.120",
|
|
59
|
+
138: "138.0.7204.184",
|
|
60
|
+
139: "139.0.7258.155",
|
|
61
|
+
140: "140.0.7339.208",
|
|
62
|
+
141: "141.0.7390.123",
|
|
63
|
+
142: "142.0.7444.176",
|
|
64
|
+
143: "143.0.7499.193",
|
|
65
|
+
144: "144.0.7559.133",
|
|
66
|
+
145: "145.0.7632.160",
|
|
67
|
+
146: "146.0.7680.178",
|
|
68
|
+
147: "147.0.7727.138",
|
|
69
|
+
148: "148.0.7778.168",
|
|
70
|
+
149: "149.0.7827.201",
|
|
71
|
+
150: "150.0.7871.187",
|
|
72
|
+
151: "151.0.7922.174",
|
|
73
|
+
152: "152.0.7977.83",
|
|
74
|
+
153: "153.0.8010.37",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# Brands that carry the real build; everything else is the GREASE token.
|
|
78
|
+
_REAL_BRANDS = {"Chromium", "Google Chrome", "Microsoft Edge", "Brave", "Opera"}
|
|
79
|
+
|
|
80
|
+
# Per-platform defaults, mirroring Chromium (httpcloak-verified).
|
|
81
|
+
PLATFORM_VERSION: Dict[str, str] = {
|
|
82
|
+
"windows": '"15.0.0"',
|
|
83
|
+
"macos": '"14.5.0"',
|
|
84
|
+
"linux": '""',
|
|
85
|
+
"android": '"14.0.0"',
|
|
86
|
+
"ios": '""',
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
PLATFORM_ARCH: Dict[str, str] = {
|
|
90
|
+
"windows": '"x86"',
|
|
91
|
+
"macos": '"arm"',
|
|
92
|
+
"linux": '"x86"',
|
|
93
|
+
"android": '""',
|
|
94
|
+
"ios": '""',
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def full_version_for(major: int) -> str:
|
|
99
|
+
"""Return the exact Chrome build for *major*, or a ``<major>.0.0.0`` fallback."""
|
|
100
|
+
return CHROME_FULL_VERSIONS.get(int(major), "%d.0.0.0" % int(major))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def full_version_list(sec_ch_ua: str, full_version: str) -> str:
|
|
104
|
+
"""Expand a low-entropy ``sec-ch-ua`` into ``sec-ch-ua-full-version-list``.
|
|
105
|
+
|
|
106
|
+
Brand names, order and the GREASE token are preserved verbatim. When
|
|
107
|
+
*full_version* is given, real brands get the exact build while the GREASE
|
|
108
|
+
brand keeps its major expanded to ``<major>.0.0.0``; when it is empty,
|
|
109
|
+
every brand is expanded to ``<major>.0.0.0`` (the ``ua_full_version=None``
|
|
110
|
+
fallback of ``context.expand_client_hints``). Example::
|
|
111
|
+
|
|
112
|
+
"Chromium";v="99", "Not?A_Brand";v="24", "Google Chrome";v="99"
|
|
113
|
+
|
|
114
|
+
becomes (with ``full_version="99.0.4844.84"``)::
|
|
115
|
+
|
|
116
|
+
"Chromium";v="99.0.4844.84", "Not?A_Brand";v="24.0.0.0",
|
|
117
|
+
"Google Chrome";v="99.0.4844.84"
|
|
118
|
+
"""
|
|
119
|
+
out = []
|
|
120
|
+
for part in sec_ch_ua.split(","):
|
|
121
|
+
part = part.strip()
|
|
122
|
+
if not part:
|
|
123
|
+
continue
|
|
124
|
+
brand, sep, ver = part.partition(";v=")
|
|
125
|
+
brand = brand.strip().strip('"')
|
|
126
|
+
ver = ver.strip().strip('"')
|
|
127
|
+
if not sep:
|
|
128
|
+
out.append(part)
|
|
129
|
+
elif not ver or "." in ver:
|
|
130
|
+
out.append(part) # empty or already a full version — leave as-is
|
|
131
|
+
elif full_version and brand in _REAL_BRANDS:
|
|
132
|
+
out.append('"%s";v="%s"' % (brand, full_version))
|
|
133
|
+
else:
|
|
134
|
+
out.append('"%s";v="%s.0.0.0"' % (brand, ver))
|
|
135
|
+
return ", ".join(out)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def high_entropy_hints(platform: str, sec_ch_ua: str, full_version: str) -> Dict[str, str]:
|
|
139
|
+
"""Return the six high-entropy Client Hints for a Chromium platform."""
|
|
140
|
+
platform = (platform or "").lower()
|
|
141
|
+
is_mobile = platform in ("android", "ios")
|
|
142
|
+
return {
|
|
143
|
+
"sec-ch-ua-full-version-list": full_version_list(sec_ch_ua, full_version),
|
|
144
|
+
"sec-ch-ua-platform-version": PLATFORM_VERSION.get(platform, '""'),
|
|
145
|
+
"sec-ch-ua-arch": PLATFORM_ARCH.get(platform, '""'),
|
|
146
|
+
"sec-ch-ua-bitness": '""' if is_mobile else '"64"',
|
|
147
|
+
"sec-ch-ua-model": '""',
|
|
148
|
+
"sec-ch-ua-wow64": "?0",
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
# Wire order Chromium uses when it emits the high-entropy block, following the
|
|
153
|
+
# low-entropy trio. Kept here so both the preset generator and the default
|
|
154
|
+
# headers use one canonical order.
|
|
155
|
+
HIGH_ENTROPY_ORDER = [
|
|
156
|
+
"sec-ch-ua-platform-version",
|
|
157
|
+
"sec-ch-ua-arch",
|
|
158
|
+
"sec-ch-ua-bitness",
|
|
159
|
+
"sec-ch-ua-model",
|
|
160
|
+
"sec-ch-ua-full-version-list",
|
|
161
|
+
"sec-ch-ua-wow64",
|
|
162
|
+
]
|