Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions python/wreq/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ExtensionType(Enum):
NEXT_PROTO_NEG = auto()
CHANNEL_ID = auto()
RECORD_SIZE_LIMIT = auto()
TRUST_ANCHORS = auto()


@final
Expand Down Expand Up @@ -420,6 +421,16 @@ class Params(TypedDict):
Overrides the random AES hardware acceleration.
"""

grease_sigalgs_enabled: NotRequired[bool]
"""
Whether the `signature_algorithms` extension includes a GREASE value.
"""

trust_anchors: NotRequired[bytes]
"""
Encoded Trust Anchor IDs sent in a TLS 1.3 ClientHello.
"""


@final
class TlsOptions:
Expand Down
14 changes: 14 additions & 0 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ define_enum!(
NEXT_PROTO_NEG,
CHANNEL_ID,
RECORD_SIZE_LIMIT,
TRUST_ANCHORS,
);

/// A builder for [`TlsOptions`].
Expand Down Expand Up @@ -215,6 +216,12 @@ struct Builder {

/// Overrides the random AES hardware acceleration.
random_aes_hw_override: Option<bool>,

/// Whether the `signature_algorithms` extension includes a GREASE value.
grease_sigalgs_enabled: Option<bool>,

/// Encoded Trust Anchor IDs sent in a TLS 1.3 ClientHello.
trust_anchors: Option<Vec<u8>>,
}

/// TLS connection configuration options.
Expand Down Expand Up @@ -382,6 +389,13 @@ impl TlsOptions {
params.random_aes_hw_override,
random_aes_hw_override
);
apply_option!(
set_if_some,
builder,
params.grease_sigalgs_enabled,
grease_sigalgs_enabled
);
apply_option!(set_if_some, builder, params.trust_anchors, trust_anchors);
}

Self(builder.build())
Expand Down
12 changes: 11 additions & 1 deletion tests/tls_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import wreq
from wreq.emulation import Emulation
from wreq.tls import CertStore
from wreq.tls import CertStore, ExtensionType, TlsOptions


@pytest.mark.asyncio
Expand Down Expand Up @@ -49,3 +49,13 @@ async def test_alps_new_endpoint():
async with resp:
text = await resp.text()
assert text is not None


def test_tls_options_trust_anchors_and_grease_sigalgs():
opts = TlsOptions(grease_sigalgs_enabled=True, trust_anchors=b"")
assert opts is not None


def test_extension_type_trust_anchors():
opts = TlsOptions(extension_permutation=[ExtensionType.TRUST_ANCHORS])
assert opts is not None
Loading