Skip to content

feat(tls)!: move hostname configuration to tls_stream#323

Merged
sgerbino merged 5 commits into
cppalliance:developfrom
sgerbino:pr/tls-hostname
Jul 22, 2026
Merged

feat(tls)!: move hostname configuration to tls_stream#323
sgerbino merged 5 commits into
cppalliance:developfrom
sgerbino:pr/tls-hostname

Conversation

@sgerbino

Copy link
Copy Markdown
Collaborator

The hostname used for SNI and peer certificate verification is per-connection state, not shared configuration. Remove tls_context::set_hostname and add tls_stream::set_hostname, which takes effect at the next handshake, persists across reset(), and disables SNI and hostname verification when given an empty name. A stream can now be reset and handshaked again against a different hostname. On the OpenSSL backend, reset() now also drops the cached TLS session so a post-reset handshake performs full certificate verification instead of silently resuming.

Resolves #239.

The hostname used for SNI and peer certificate verification is
per-connection state, not shared configuration. Remove
tls_context::set_hostname and add tls_stream::set_hostname, which
takes effect at the next handshake, persists across reset(), and
disables SNI and hostname verification when given an empty name.
A stream can now be reset and handshaked again against a different
hostname. On the OpenSSL backend, reset() now also drops the cached
TLS session so a post-reset handshake performs full certificate
verification instead of silently resuming.
@cppalliance-bot

cppalliance-bot commented Jul 21, 2026

Copy link
Copy Markdown

An automated preview of the documentation is available at https://323.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-07-22 13:09:02 UTC

@cppalliance-bot

cppalliance-bot commented Jul 21, 2026

Copy link
Copy Markdown

GCOVR code coverage report https://323.corosio.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://323.corosio.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://323.corosio.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-07-22 13:26:46 UTC

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.47%. Comparing base (f038041) to head (c65c874).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #323      +/-   ##
===========================================
- Coverage    77.53%   77.47%   -0.06%     
===========================================
  Files           96       96              
  Lines         6899     6869      -30     
  Branches      1663     1652      -11     
===========================================
- Hits          5349     5322      -27     
  Misses        1055     1055              
+ Partials       495      492       -3     
Files with missing lines Coverage Δ
include/boost/corosio/openssl_stream.hpp 55.55% <ø> (ø)
include/boost/corosio/tls_context.hpp 100.00% <ø> (ø)
include/boost/corosio/tls_stream.hpp 75.00% <ø> (ø)
include/boost/corosio/wolfssl_stream.hpp 55.55% <ø> (ø)
src/corosio/src/tls/context.cpp 35.71% <ø> (-2.65%) ⬇️
src/corosio/src/tls/detail/context_impl.hpp 100.00% <ø> (ø)
src/openssl/src/openssl_stream.cpp 55.60% <100.00%> (-1.13%) ⬇️
src/wolfssl/src/wolfssl_stream.cpp 61.88% <ø> (-0.64%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f038041...c65c874. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

sgerbino added 4 commits July 22, 2026 15:00
The scoped tls_role enum moves from tls_context.hpp to tls_stream.hpp,
where its only consumer lives, and handshake() takes it in place of the
nested unscoped handshake_type, which is removed. Backend plumbing that
degraded the role to int (do_handshake, init_ssl_for_role) now carries
tls_role end to end.
set_hostname with an IP literal (IPv4 or IPv6) now matches the
certificate's iPAddress subjectAltName entries instead of its DNS
names, and sends no SNI, which RFC 6066 restricts to DNS names. On
OpenSSL the literal is applied via X509_VERIFY_PARAM_set1_ip_asc,
with the unused host/ip field cleared so a reset stream cannot carry
the previous target's matching rule. On WolfSSL the literal goes
through wolfSSL_check_ip_address; enforcement requires a build with
both OPENSSL_EXTRA and WOLFSSL_IP_ALT_NAME, and on builds lacking
either the call reports success while verification silently checks
nothing, so the handshake fails closed with function_not_supported,
reported by the new wolfssl_supports_ip_alt_name() probe.
A failed handshake attempt now consumes the stream: the next
handshake() behaves as if reset() had been called first, so a
hostname changed after a failure is applied instead of being
silently ignored on a dead session. The hostname now applies to
client handshakes only; a server-role handshake clears any name a
prior client-role handshake left in the verify params, so client
certificates are never hostname-matched. Failures installing the
SNI name or the verify-param host fail the handshake rather than
proceed without the requested check.
wolfSSL_check_ip_address reports success even on builds that compiled
out enforcement, so its return check could never fail closed. Setting
the literal through wolfSSL_get0_param and
wolfSSL_X509_VERIFY_PARAM_set1_ip_asc installs it on the exact path
the certificate check consults, returns a meaningful failure, and
binds symbols exported only by OPENSSL_EXTRA builds — running against
a WolfSSL downgraded below the build-time feature set now fails at
load instead of silently skipping the name check.
@sgerbino
sgerbino merged commit 953f592 into cppalliance:develop Jul 22, 2026
43 checks passed
@sgerbino
sgerbino deleted the pr/tls-hostname branch July 22, 2026 13:29
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Beast2 Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Feature request: tls_stream::set_hostname

2 participants