Skip to content

Strip brackets from IPv6-literal hosts before TLS SNI/ServerName#1171

Merged
algesten merged 3 commits into
mainfrom
fix/ipv6-literal-tls-sni
May 11, 2026
Merged

Strip brackets from IPv6-literal hosts before TLS SNI/ServerName#1171
algesten merged 3 commits into
mainfrom
fix/ipv6-literal-tls-sni

Conversation

@algesten

@algesten algesten commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Authority::host() returns IPv6 literals in their URI-syntax bracketed form (e.g. [::1]), per RFC 3986.
  • rustls' ServerName::try_from rejects the brackets, so HTTPS to an IPv6-literal URL (e.g. https://[::1]/, link-local [fe80::...]) fails the TLS handshake with "invalid dns name". native-tls has the same problem — brackets aren't valid for SNI.
  • Add AuthorityExt::host_bare() in src/util.rs that strips the surrounding [ / ] when present, and use it in both the rustls and native-tls connectors. DNS names and IPv4 literals are unaffected.
  • Once the brackets are gone, rustls recognises the string as an IP and hands it to cert verification as ServerName::IpAddress, which matches the iPAddress SAN — i.e. no extension to rustls is needed.

Fixes #1168.

`Authority::host()` returns IPv6 literals in their URI-syntax
bracketed form (e.g. `[::1]`), but rustls' `ServerName::try_from`
rejects the brackets, so HTTPS against an IPv6-literal URL failed the
TLS handshake. Add `AuthorityExt::host_bare()` to yield the
unbracketed host and use it when passing the name to rustls and
native-tls.

Fixes #1168
@algesten algesten merged commit 187f7ce into main May 11, 2026
74 checks passed
@algesten algesten deleted the fix/ipv6-literal-tls-sni branch May 11, 2026 08:29
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.

IPv6 ServerName vs Authority bracket problem

1 participant