Skip to content

Commit

Permalink
Add options for status_request and cert_timestamps extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet committed Jun 27, 2024
1 parent 27b008c commit 33b54a8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL := bash

# this is the upstream libcurl-impersonate version
VERSION := 0.7.0b6
VERSION := 0.7.0
CURL_VERSION := curl-8_7_1

$(CURL_VERSION):
Expand Down
2 changes: 2 additions & 0 deletions curl_cffi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ class CurlOpt(IntEnum):
TLS_EXTENSION_ORDER = 10000 + 1012
STREAM_EXCLUSIVE = 0 + 1013
TLS_KEY_USAGE_NO_CHECK = 0 + 1014
TLS_SIGNED_CERT_TIMESTAMPS = 0 + 1015
TLS_STATUS_REQUEST = 0 + 1016

if locals().get("WRITEDATA"):
FILE = locals().get("WRITEDATA")
Expand Down
10 changes: 3 additions & 7 deletions curl_cffi/requests/impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,11 @@ def toggle_extension(curl, extension_id: int, enable: bool):
# status_request
elif extension_id == 5:
if enable:
pass # It's now always enabled
else:
raise NotImplementedError("This extension(5) is always on for now, it will be updated later.")
# signed_certificate_timestamp
curl.setopt(CurlOpt.TLS_STATUS_REQUEST, 1)
# signed_certificate_timestamps
elif extension_id == 18:
if enable:
pass # It's now always enabled
else:
raise NotImplementedError("This extension(18) is always on for now, it will be updated later.")
curl.setopt(CurlOpt.TLS_SIGNED_CERT_TIMESTAMPS, 1)
# session_ticket
elif extension_id == 35:
if enable:
Expand Down
2 changes: 1 addition & 1 deletion curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __init__(
self._closed = False

def _toggle_extensions_by_ids(self, curl, extension_ids):
default_enabled = {0, 51, 13, 43, 5, 18, 65281, 23, 10, 45, 35, 11, 16}
default_enabled = {0, 51, 13, 43, 65281, 23, 10, 45, 35, 11, 16}

to_enable_ids = extension_ids - default_enabled
for ext_id in to_enable_ids:
Expand Down
12 changes: 11 additions & 1 deletion examples/impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[
"771",
"4865-4866-4867-49195-49196-52393-49199-49200-52392-49171-49172-156-157-47-53",
"0-23-65281-10-11-35-16-5-13-51-45-43-18-21", # FIXME: 18 should not be here.
"0-23-65281-10-11-35-16-5-13-51-45-43-21",
"29-23-24",
"0",
]
Expand All @@ -29,6 +29,16 @@
"rsa_pkcs1_sha512",
"rsa_pkcs1_sha1",
]
# other options:
# tls_min_version: int = CurlSslVersion.TLSv1_2
# tls_grease: bool = False
# tls_permute_extensions: bool = False
# tls_cert_compression: Literal["zlib", "brotli"] = "brotli"
# tls_signature_algorithms: Optional[List[str]] = None
# http2_stream_weight: int = 256
# http2_stream_exclusive: int = 1

# See requests/impersonate.py and tests/unittest/test_impersonate.py for more examples
}


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "curl_cffi"
version = "0.7.0b6"
version = "0.7.0b7"
authors = [{ name = "Yifei Kong", email = "kong@yifei.me" }]
description = "libcurl ffi bindings for Python, with impersonation support."
license = { file = "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cffi import FFI

# this is the upstream libcurl-impersonate version
__version__ = "0.7.0b6"
__version__ = "0.7.0"

tmpdir = None

Expand Down
5 changes: 5 additions & 0 deletions tests/unittest/test_impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def test_customized_ja3_extensions():
_, _, extensions, _, _ = r["ja3_text"].split(",")
assert extensions == "65281-0-11-23-5-18-27-16-17513-10-35-43-45-13-51"

ja3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,65281-0-11-23-27-16-17513-10-35-43-45-13-51,25497-29-23-24,0"
r = requests.get(url, ja3=ja3).json()
_, _, extensions, _, _ = r["ja3_text"].split(",")
assert extensions == "65281-0-11-23-27-16-17513-10-35-43-45-13-51"

# removed enable session_ticket()
ja3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,65281-0-11-23-5-18-27-16-17513-10-43-45-13-51,25497-29-23-24,0"
r = requests.get(url, ja3=ja3).json()
Expand Down

0 comments on commit 33b54a8

Please sign in to comment.