Skip to content

Fix OpenSSL cert validation when host is an IP address (#581) - #588

Merged
bsergean merged 1 commit into
masterfrom
fix/openssl-ip-cert-validation
Jun 24, 2026
Merged

Fix OpenSSL cert validation when host is an IP address (#581)#588
bsergean merged 1 commit into
masterfrom
fix/openssl-ip-cert-validation

Conversation

@bsergean

Copy link
Copy Markdown
Collaborator

Fixes #581

Problem

When connecting as a TLS client to a host specified as a literal IP address (e.g. wss://127.0.0.1:44300/) with OpenSSL as the TLS provider, x509 certificate verification always fails — even when the server certificate carries a matching iPAddress Subject Alternative Name.

The cause is that SocketOpenSSL::connect unconditionally calls X509_VERIFY_PARAM_set1_host, which only validates against dNSName / CN SAN entries. IP literals must instead be validated against iPAddress SAN entries.

Fix

Detect whether host is an IPv4 or IPv6 literal using the existing ix::inet_pton helper, and in that case validate via X509_VERIFY_PARAM_set1_ip_asc. DNS names keep using X509_VERIFY_PARAM_set1_host as before.

This follows the approach suggested in the issue, made portable (avoids the Windows-only in_addr::S_un union member) and using the library's own inet_pton wrapper.

Testing

  • Builds cleanly with -DUSE_TLS=ON -DUSE_OPEN_SSL=ON (OpenSSL 3.6.1).
  • The reporter validated the same approach against a self-signed CA with a certificate whose SAN was DNS=localhost, IPAddress=127.0.0.1, connecting via both wss://127.0.0.1:44300/ and wss://localhost:44300/.

🤖 Generated with Claude Code

X509_VERIFY_PARAM_set1_host only validates the certificate against
dNSName / CN SAN entries, so connecting to a host given as a literal
IPv4 or IPv6 address (e.g. wss://127.0.0.1/) always failed hostname
verification even when the certificate carried a matching iPAddress SAN.

Detect IP literals with inet_pton and validate them against the
iPAddress SANs via X509_VERIFY_PARAM_set1_ip_asc instead, falling back
to set1_host for DNS names.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@bsergean
bsergean merged commit fb21fa2 into master Jun 24, 2026
7 checks passed
@bsergean bsergean mentioned this pull request Jun 24, 2026
bsergean added a commit that referenced this pull request Jun 25, 2026
Release of accumulated fixes since v12.0.0: DNS lookup crash/offline
resolution (#589), OpenSSL IP-address cert validation (#588),
case-insensitive Upgrade header (#584), server fd double-close (#585),
fragment buffering optimization (#562), and the install include-dir fix (#582).

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

x509 Certificate validation failure when using OpenSSL and host is an IP Address

1 participant