Skip to content

server: add rustls_server_config_builder_set_send_tls13_tickets#653

Merged
cpu merged 1 commit into
rustls:mainfrom
mattrobenolt:set-num-tickets
Jul 13, 2026
Merged

server: add rustls_server_config_builder_set_send_tls13_tickets#653
cpu merged 1 commit into
rustls:mainfrom
mattrobenolt:set-num-tickets

Conversation

@mattrobenolt

@mattrobenolt mattrobenolt commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Closes #652.

Note

This PR was AI generated using GLM 5.2.

What

Adds rustls_server_config_builder_set_num_tickets(builder, n) to expose ServerConfig::send_tls13_tickets through the C API. Mirrors the existing rustls_server_config_builder_set_ignore_client_order pattern: a new Option<usize> field on ServerConfigBuilder, a setter, and application at build() time. Defaults to None (rustls's own default of 2 applies), so this is a strictly additive, no-behavior-change-by-default feature.

Why

For TLS-library performance comparison benchmarks, NewSessionTicket issuance after a full handshake is a measurable distortion. rustls upstream established this in PR #2187 ("server: default send_tls13_tickets 4 -> 2"):

the extra 2 tickets cost us 8%/6% (client/server) of a normal resumption, or ~0%/2% of a full handshake. This also manifests when comparing default configurations between TLS libraries due to the high cost of creating new tickets ... It also avoids folks repeatedly tripping into this during benchmarking.

Both peer libraries expose a knob to suppress this:

  • OpenSSL: SSL_CTX_set_num_tickets(ctx, 0)
  • rustls (Rust API): server.send_tls13_tickets = 0

rustls-ffi was the one path that couldn't, so a C/Zig/Python benchmark driving rustls through the FFI could not get a handshake measurement equivalent to its peers — the rustls-ffi handshake row measured "handshake + 2 NewSessionTicket issuance" while peers measured "handshake only." The workaround of building a fresh config per connection prevents resumption (client offering PSK) but not ticket issuance (server still generates and sends the tickets).

Changes

  • librustls/src/server.rs: send_tls13_tickets: Option<usize> field on ServerConfigBuilder (init None in both _new and _new_custom), rustls_server_config_builder_set_num_tickets setter, applied in rustls_server_config_builder_build. Test test_server_config_builder_set_num_tickets covering both 0 and a non-zero value.
  • librustls/src/rustls.h: vendored header declaration.

Verification

  • cargo test --no-default-features --features ring --locked — 35 passed (incl. new test)
  • cargo fmt --check — clean
  • cargo clippy --no-default-features --features ring --all-targets -- -D warnings -A unknown-lints — no warnings in changed code

(No cargo-c/capi build run locally; the C examples need cmake which isn't in my env. The header change is a straightforward declaration mirroring set_ignore_client_order.)

Notes

Comment thread librustls/src/server.rs Outdated
Comment thread librustls/src/server.rs Outdated

@cpu cpu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you squash your commits as well? Thanks

Comment thread librustls/src/server.rs Outdated
@mattrobenolt

Copy link
Copy Markdown
Contributor Author

Thanks @djc @cpu. Pushed an update addressing all the feedback:

  • Removed the docstring on the send_tls13_tickets struct field (it is pub(crate), not publicly exposed, so no doccomment per the RFC 1574 guidelines).
  • Trimmed the setter doc comment to a short summary + the "Setting this to 0 disables session ticket issuance entirely" behavior, matching the style of rustls_server_config_builder_set_ignore_client_order. Dropped the OpenSSL SSL_CTX_set_num_tickets citation and the benchmarking rationale from the API docs.
  • Regenerated/aligned the vendored rustls.h declaration to match cbindgen output.
  • Squashed into a single commit (e0a4c3d).

Comment thread librustls/src/server.rs
Comment thread librustls/src/server.rs Outdated
Expose ServerConfig::send_tls13_tickets via the C API so callers can
control how many TLS 1.3 NewSessionTicket messages the server sends after
a full handshake (rustls default is 2). Setting 0 disables ticket
issuance.

This lets benchmark harnesses driving rustls through the FFI measure a
clean full handshake without NewSessionTicket issuance cost, making the
handshake row equivalent to OpenSSL/rustls-Rust-API peers. rustls upstream
established the ticket-issuance cost is a measurable benchmarking hazard
(PR #2187: ~2% of a full handshake server-side at the default of 2), and
both OpenSSL and the rustls Rust API expose a knob to suppress it —
rustls-ffi was the one path that couldn't.

Closes rustls#652
@mattrobenolt

Copy link
Copy Markdown
Contributor Author

Pushed another update (831186e) addressing the latest feedback:

  • @djc: the setter doc summary is now a single line, per RFC 1574 §"Summary sentence".
  • @cpu: renamed to rustls_server_config_builder_set_send_tls13_tickets to match the upstream ServerConfig::send_tls13_tickets field name, consistent with how set_ignore_client_order mirrors ignore_client_order. Updated the header and regenerated api.json.
  • @cpu: added the missing assert!(!config.is_null()); to the second build in the test.

Also renamed the test function to match and confirmed the header still regenerates cleanly with cbindgen.

@cpu cpu changed the title server: add rustls_server_config_builder_set_num_tickets server: add rustls_server_config_builder_set_send_tls13_tickets Jul 13, 2026

@cpu cpu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@cpu
cpu enabled auto-merge (rebase) July 13, 2026 18:05
@cpu
cpu merged commit cc46e55 into rustls:main Jul 13, 2026
46 checks passed
@mattrobenolt
mattrobenolt deleted the set-num-tickets branch July 13, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose a way to set ServerConfig::send_tls13_tickets (disable TLS 1.3 session ticket issuance)

3 participants