wreq.tls
TLS/SSL configuration including certificates, key logging, and fingerprinting.
wreq.tls
TLS Utilities and Types
This module provides types and utilities for configuring TLS (Transport Layer Security) in HTTP clients.
TlsVersion
AlpnProtocol
AlpsProtocol
KeyShare
Bases: Enum
Key exchange groups (elliptic curves) for TLS 1.3.
Source code in python/wreq/tls.py
CertificateCompressionAlgorithm
Bases: Enum
IANA assigned identifier of compression algorithm. See https://www.rfc-editor.org/rfc/rfc8879.html#name-compression-algorithms
Source code in python/wreq/tls.py
ExtensionType
Bases: Enum
A TLS extension type.
Source code in python/wreq/tls.py
Identity
Represents a private key and X509 cert as a client certificate.
Source code in python/wreq/tls.py
from_pkcs12_der
staticmethod
Parses a DER-formatted PKCS #12 archive, using the specified password to decrypt the key.
The archive should contain a leaf certificate and its private key, as well any intermediate certificates that allow clients to build a chain to a trusted root. The chain certificates should be in order from the leaf certificate towards the root.
PKCS #12 archives typically have the file extension .p12 or .pfx, and can be created
with the OpenSSL pkcs12 tool:
openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem -certfile chain_certs.pem
Source code in python/wreq/tls.py
from_pkcs8_pem
staticmethod
Parses a chain of PEM encoded X509 certificates, with the leaf certificate first.
key is a PEM encoded PKCS #8 formatted private key for the leaf certificate.
The certificate chain should contain any intermediate certificates that should be sent to clients to allow them to build a chain to a trusted root.
A certificate chain here means a series of PEM encoded certificates concatenated together.
Source code in python/wreq/tls.py
CertStore
Represents a certificate store for verifying TLS connections.
Source code in python/wreq/tls.py
__init__
Creates a new CertStore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
der_certs
|
Sequence[bytes] | None
|
Optional list of DER-encoded certificates (as bytes). |
None
|
pem_certs
|
Sequence[str] | None
|
Optional list of PEM-encoded certificates (as str). |
None
|
default_paths
|
bool | None
|
If True, use system default certificate paths. |
None
|
Source code in python/wreq/tls.py
from_der_certs
staticmethod
Creates a CertStore from a collection of DER-encoded certificates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
certs
|
Sequence[bytes]
|
List of DER-encoded certificates (as bytes). |
required |
from_pem_certs
staticmethod
Creates a CertStore from a collection of PEM-encoded certificates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
certs
|
Sequence[str]
|
List of PEM-encoded certificates (as str). |
required |
from_pem_stack
staticmethod
Creates a CertStore from a PEM-encoded certificate stack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
certs
|
bytes
|
PEM-encoded certificate stack (as bytes). |
required |
KeyLog
Specifies the intent for a (TLS) keylogger to be used in a client or server configuration.
This type allows you to control how TLS session keys are logged for debugging or analysis. You can either use the default environment variable (SSLKEYLOGFILE) or specify a file path directly. This is useful for tools like Wireshark that can decrypt TLS traffic if provided with the correct session keys.
Static Methods: environment() -> KeyLog Use the SSLKEYLOGFILE environment variable for key logging. file(path: Path) -> KeyLog Log keys to the specified file path.
Source code in python/wreq/tls.py
environment
staticmethod
file
staticmethod
Log keys to the specified file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file path to log TLS keys to. |
required |
Params
typed-dict
Bases: TypedDict
All parameters for TLS connections.
Source code in python/wreq/tls.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
__init__
__init__(*, alpn_protocols=..., alps_protocols=..., alps_use_new_codepoint=..., session_ticket=..., min_tls_version=..., max_tls_version=..., pre_shared_key=..., enable_ech_grease=..., permute_extensions=..., grease_enabled=..., enable_ocsp_stapling=..., enable_signed_cert_timestamps=..., record_size_limit=..., psk_skip_session_ticket=..., key_shares=..., psk_dhe_ke=..., renegotiation=..., delegated_credentials=..., curves_list=..., sigalgs_list=..., cipher_list=..., preserve_tls13_cipher_list=..., certificate_compression_algorithms=..., extension_permutation=..., aes_hw_override=..., random_aes_hw_override=...)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpn_protocols
|
Sequence[AlpnProtocol]
|
Application-Layer Protocol Negotiation (RFC 7301). Specifies which application protocols (e.g., HTTP/2, HTTP/1.1) may be negotiated over a single TLS connection. |
...
|
alps_protocols
|
Sequence[AlpsProtocol]
|
Application-Layer Protocol Settings (ALPS). Enables exchanging application-layer settings during the handshake for protocols negotiated via ALPN. |
...
|
alps_use_new_codepoint
|
bool
|
Whether to use an alternative ALPS codepoint for compatibility. Useful when larger ALPS payloads are required. |
...
|
session_ticket
|
bool
|
Enables TLS Session Tickets (RFC 5077). Allows session resumption without requiring server-side state. |
...
|
min_tls_version
|
TlsVersion
|
Minimum TLS version allowed for the connection. |
...
|
max_tls_version
|
TlsVersion
|
Maximum TLS version allowed for the connection. |
...
|
pre_shared_key
|
bool
|
Enables Pre-Shared Key (PSK) cipher suites (RFC 4279). Authentication relies on out-of-band pre-shared keys instead of certificates. |
...
|
enable_ech_grease
|
bool
|
Controls whether to send a GREASE Encrypted ClientHello (ECH) extension when no supported ECH configuration is available. GREASE prevents protocol ossification by sending unknown extensions. |
...
|
permute_extensions
|
bool
|
Controls whether ClientHello extensions should be permuted. |
...
|
grease_enabled
|
bool
|
Controls whether GREASE extensions (RFC 8701) are enabled in general. |
...
|
enable_ocsp_stapling
|
bool
|
Enables OCSP stapling for the connection. |
...
|
enable_signed_cert_timestamps
|
bool
|
Enables Signed Certificate Timestamps (SCT). |
...
|
record_size_limit
|
int
|
Sets the maximum TLS record size. |
...
|
psk_skip_session_ticket
|
bool
|
Whether to skip session tickets when using PSK. |
...
|
key_shares
|
Sequence[KeyShare]
|
Whether to set specific key shares for TLS 1.3 handshakes. |
...
|
psk_dhe_ke
|
bool
|
Enables PSK with (EC)DHE key establishment ( |
...
|
renegotiation
|
bool
|
Enables TLS renegotiation by sending the |
...
|
delegated_credentials
|
str
|
Delegated Credentials (RFC 9345). Allows TLS 1.3 endpoints to use temporary delegated credentials for authentication with reduced long-term key exposure. |
...
|
curves_list
|
str
|
List of supported elliptic curves. |
...
|
sigalgs_list
|
str
|
List of supported signature algorithms. |
...
|
cipher_list
|
str
|
Cipher suite configuration string. Uses BoringSSL's mini-language to select, enable, and prioritize ciphers. |
...
|
preserve_tls13_cipher_list
|
bool
|
Sets whether to preserve the TLS 1.3 cipher list as configured by cipher_list. By default, BoringSSL does not preserve the TLS 1.3 cipher list. When this option is disabled (the default), BoringSSL uses its internal default TLS 1.3 cipher suites in its default order, regardless of what is set via cipher_list. When enabled, this option ensures that the TLS 1.3 cipher suites explicitly set via cipher_list are retained in their original order, without being reordered or modified by BoringSSL's internal logic. This is useful for maintaining specific cipher suite priorities for TLS 1.3. Note that if cipher_list does not include any TLS 1.3 cipher suites, BoringSSL will still fall back to its default TLS 1.3 cipher suites and order. |
...
|
certificate_compression_algorithms
|
Sequence[CertificateCompressionAlgorithm]
|
Supported certificate compression algorithms (RFC 8879). |
...
|
extension_permutation
|
Sequence[ExtensionType]
|
Supported TLS extensions, used for extension ordering/permutation. |
...
|
aes_hw_override
|
bool
|
Overrides AES hardware acceleration. |
...
|
random_aes_hw_override
|
bool
|
Overrides the random AES hardware acceleration. |
...
|
TlsOptions
TLS connection configuration options.
This struct provides fine-grained control over the behavior of TLS connections, including: - Protocol negotiation (ALPN, ALPS, TLS versions) - Session management (tickets, PSK, key shares) - Security & privacy (OCSP, GREASE, ECH, delegated credentials) - Performance tuning (record size, cipher preferences, hardware overrides)
All fields are optional or have defaults. See each field for details.
Source code in python/wreq/tls.py
__init__
__init__(*, alpn_protocols=..., alps_protocols=..., alps_use_new_codepoint=..., session_ticket=..., min_tls_version=..., max_tls_version=..., pre_shared_key=..., enable_ech_grease=..., permute_extensions=..., grease_enabled=..., enable_ocsp_stapling=..., enable_signed_cert_timestamps=..., record_size_limit=..., psk_skip_session_ticket=..., key_shares=..., psk_dhe_ke=..., renegotiation=..., delegated_credentials=..., curves_list=..., sigalgs_list=..., cipher_list=..., preserve_tls13_cipher_list=..., certificate_compression_algorithms=..., extension_permutation=..., aes_hw_override=..., random_aes_hw_override=...)
Creates a new TlsOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpn_protocols
|
Sequence[AlpnProtocol]
|
Application-Layer Protocol Negotiation (RFC 7301). Specifies which application protocols (e.g., HTTP/2, HTTP/1.1) may be negotiated over a single TLS connection. |
...
|
alps_protocols
|
Sequence[AlpsProtocol]
|
Application-Layer Protocol Settings (ALPS). Enables exchanging application-layer settings during the handshake for protocols negotiated via ALPN. |
...
|
alps_use_new_codepoint
|
bool
|
Whether to use an alternative ALPS codepoint for compatibility. Useful when larger ALPS payloads are required. |
...
|
session_ticket
|
bool
|
Enables TLS Session Tickets (RFC 5077). Allows session resumption without requiring server-side state. |
...
|
min_tls_version
|
TlsVersion
|
Minimum TLS version allowed for the connection. |
...
|
max_tls_version
|
TlsVersion
|
Maximum TLS version allowed for the connection. |
...
|
pre_shared_key
|
bool
|
Enables Pre-Shared Key (PSK) cipher suites (RFC 4279). Authentication relies on out-of-band pre-shared keys instead of certificates. |
...
|
enable_ech_grease
|
bool
|
Controls whether to send a GREASE Encrypted ClientHello (ECH) extension when no supported ECH configuration is available. GREASE prevents protocol ossification by sending unknown extensions. |
...
|
permute_extensions
|
bool
|
Controls whether ClientHello extensions should be permuted. |
...
|
grease_enabled
|
bool
|
Controls whether GREASE extensions (RFC 8701) are enabled in general. |
...
|
enable_ocsp_stapling
|
bool
|
Enables OCSP stapling for the connection. |
...
|
enable_signed_cert_timestamps
|
bool
|
Enables Signed Certificate Timestamps (SCT). |
...
|
record_size_limit
|
int
|
Sets the maximum TLS record size. |
...
|
psk_skip_session_ticket
|
bool
|
Whether to skip session tickets when using PSK. |
...
|
key_shares
|
Sequence[KeyShare]
|
Whether to set specific key shares for TLS 1.3 handshakes. |
...
|
psk_dhe_ke
|
bool
|
Enables PSK with (EC)DHE key establishment ( |
...
|
renegotiation
|
bool
|
Enables TLS renegotiation by sending the |
...
|
delegated_credentials
|
str
|
Delegated Credentials (RFC 9345). Allows TLS 1.3 endpoints to use temporary delegated credentials for authentication with reduced long-term key exposure. |
...
|
curves_list
|
str
|
List of supported elliptic curves. |
...
|
sigalgs_list
|
str
|
List of supported signature algorithms. |
...
|
cipher_list
|
str
|
Cipher suite configuration string. Uses BoringSSL's mini-language to select, enable, and prioritize ciphers. |
...
|
preserve_tls13_cipher_list
|
bool
|
Sets whether to preserve the TLS 1.3 cipher list as configured by cipher_list. By default, BoringSSL does not preserve the TLS 1.3 cipher list. When this option is disabled (the default), BoringSSL uses its internal default TLS 1.3 cipher suites in its default order, regardless of what is set via cipher_list. When enabled, this option ensures that the TLS 1.3 cipher suites explicitly set via cipher_list are retained in their original order, without being reordered or modified by BoringSSL's internal logic. This is useful for maintaining specific cipher suite priorities for TLS 1.3. Note that if cipher_list does not include any TLS 1.3 cipher suites, BoringSSL will still fall back to its default TLS 1.3 cipher suites and order. |
...
|
certificate_compression_algorithms
|
Sequence[CertificateCompressionAlgorithm]
|
Supported certificate compression algorithms (RFC 8879). |
...
|
extension_permutation
|
Sequence[ExtensionType]
|
Supported TLS extensions, used for extension ordering/permutation. |
...
|
aes_hw_override
|
bool
|
Overrides AES hardware acceleration. |
...
|
random_aes_hw_override
|
bool
|
Overrides the random AES hardware acceleration. |
...
|
TlsInfo
Information about the established TLS connection.