Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions requests_go/tls_config/convert_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import wraps

from .config import TLSConfig

# X.509证书数字签名算法英文形式标识符
Expand Down Expand Up @@ -55,11 +57,24 @@ def to_tls_config(config: dict) -> TLSConfig:
return tls_config


def fix_exception(func):
@wraps(func)
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except: # noqa
return None

return inner


@fix_exception
def get_ja3_string(config):
ja3_string = config["tls"]["ja3"]
return ja3_string


@fix_exception
def get_header_order(config):
headers = {}
headers_list = []
Expand All @@ -78,13 +93,15 @@ def get_header_order(config):
return list(headers.keys())


@fix_exception
def get_force_http1(config):
force_http1 = False
if config["http_version"] != "h2":
force_http1 = True
return force_http1


@fix_exception
def get_pseudo_header_order(config):
headers = {}
headers_list = []
Expand All @@ -102,6 +119,7 @@ def get_pseudo_header_order(config):
return list(headers.keys())


@fix_exception
def get_supported_signature_algorithms(config):
supported_signature_algorithms = []
extensions = config["tls"]["extensions"]
Expand All @@ -115,6 +133,7 @@ def get_supported_signature_algorithms(config):
return None


@fix_exception
def get_cert_compression_algo(config):
cert_compression_algo = None
extensions = config["tls"]["extensions"]
Expand All @@ -127,6 +146,7 @@ def get_cert_compression_algo(config):
return cert_compression_algo


@fix_exception
def get_record_size_limit(config):
record_size_limit = None
extensions = config["tls"]["extensions"]
Expand All @@ -136,6 +156,7 @@ def get_record_size_limit(config):
return record_size_limit


@fix_exception
def get_supported_delegated_credentials_algorithms(config):
supported_delegated_credentials_algorithms = []
extensions = config["tls"]["extensions"]
Expand All @@ -149,6 +170,7 @@ def get_supported_delegated_credentials_algorithms(config):
return None


@fix_exception
def get_supported_versions(config):
supported_versions = []
extensions = config["tls"]["extensions"]
Expand All @@ -169,6 +191,7 @@ def get_supported_versions(config):
return None


@fix_exception
def get_psk_key_exchange_modes(config):
psk_key_exchange_modes = None
extensions = config["tls"]["extensions"]
Expand All @@ -189,6 +212,7 @@ def get_signature_algorithms_cert(config):
pass


@fix_exception
def get_key_share_curves(config):
key_share_curves = []
extensions = config["tls"]["extensions"]
Expand All @@ -214,13 +238,15 @@ def get_key_share_curves(config):
return None


@fix_exception
def get_not_used_grease(config):
not_used_grease = False
if "TLS_GREASE" not in config["tls"]["extensions"][0]["name"]:
not_used_grease = True
return not_used_grease


@fix_exception
def get_h2_settings(config):
settings = {}
setting_list = []
Expand All @@ -238,11 +264,13 @@ def get_h2_settings(config):
return None


@fix_exception
def get_h2_settings_order(config):
settings = get_h2_settings(config)
return list(settings.keys())


@fix_exception
def get_connection_flow(config):
connection_flow = None
sent_frames = config["http2"]["sent_frames"]
Expand All @@ -253,6 +281,7 @@ def get_connection_flow(config):
return connection_flow


@fix_exception
def get_header_priority(config):
header_priority = None
sent_frames = config["http2"]["sent_frames"]
Expand All @@ -269,6 +298,7 @@ def get_header_priority(config):
return header_priority


@fix_exception
def get_priority_frames(config):
priority_frames = []
sent_frames = config["http2"]["sent_frames"]
Expand Down