Skip to content

Strip IPv6 URI brackets before rustls ServerName parsing#3

Merged
iainmcgin merged 1 commit intomainfrom
fix/ipv6-sni-brackets
Mar 17, 2026
Merged

Strip IPv6 URI brackets before rustls ServerName parsing#3
iainmcgin merged 1 commit intomainfrom
fix/ipv6-sni-brackets

Conversation

@iainmcgin
Copy link
Collaborator

Fixes #1.

Uri::host() returns [::1] for IPv6 literals; rustls_pki_types::ServerName::try_from rejects the bracketed form as an invalid DNS name. Stripping the brackets lets rustls parse it as ServerName::IpAddress, same as IPv4 literals (which have no brackets).

Two new tests cover IPv4 and IPv6 address inputs.

@iainmcgin iainmcgin requested a review from rpb-ant March 17, 2026 17:07
`Uri::host()` returns IPv6 literals with their URI brackets intact
(`[::1]`), but `rustls_pki_types::ServerName::try_from` expects a bare
address. Bracketed input is rejected as an invalid DNS name, so TLS
connections to IPv6 literals failed outright.

Stripping the brackets lets rustls parse it as `ServerName::IpAddress`,
same as it already does for IPv4 literals (which have no brackets in
URI form).

Fixes #1
@iainmcgin iainmcgin force-pushed the fix/ipv6-sni-brackets branch from 6fc4eff to 6633632 Compare March 17, 2026 17:11
@iainmcgin iainmcgin marked this pull request as ready for review March 17, 2026 17:15
@iainmcgin iainmcgin merged commit 13f6965 into main Mar 17, 2026
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
@iainmcgin iainmcgin deleted the fix/ipv6-sni-brackets branch March 17, 2026 17:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TLS client connections to IPv6 literals fail with "invalid TLS server name"

2 participants