Summary
src/tls/openssl/tls.c, tls_set_verify_server():
if (sa_set_str(&sa, host, 0)) { /* sa_set_str returns 0 on SUCCESS, so this branch is
taken ONLY when host is NOT parseable as an address */
SSL_set_hostflags(tc->ssl, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
SSL_set1_host(tc->ssl, host); /* identity check */
SSL_set_tlsext_host_name(tc->ssl, host); /* SNI */
}
SSL_set_verify(tc->ssl, SSL_VERIFY_PEER, tls_verify_handler); /* chain check, always */
There is no else. When host is an IP literal, OpenSSL is given no expected identity of any
kind — neither a DNS name via SSL_set1_host() nor an IP via SSL_set1_ip_asc() /
X509_VERIFY_PARAM_set1_ip(). SSL_VERIFY_PEER still runs, so the chain is checked and the
handshake succeeds; tls_peer_verify() then reports 0, meaning verified.
verify_server defaults to true (tls.c:306), so this is the default path, not an opt-in.
SSL_set1_ip_asc appears zero times in the repository.
Reproduction
A server presents a certificate for real.example (SAN DNS:real.example, no IP SAN), signed
by a lab CA. The client connects to 127.0.0.1 in all four runs. Only the string passed to
tls_set_verify_server() and whether the CA is trusted vary.
/* tlsprobe.c — the whole client, minus error handling */
err = tls_alloc(&tls, TLS_METHOD_SSLV23, NULL, NULL);
if (ca) /* trust the lab CA */
tls_add_cafile(tls, ca);
tls_start_tcp(&sc, tls, tc, 0);
tls_set_verify_server(sc, verify_host); /* <-- the only variable */
tls_conn_connect(sc);
/* on ESTABLISHED: */
printf("peer_verify=%d peer_cn=%s\n", tls_peer_verify(sc), cn);
Result — four runs, same binary, same server, same certificate
RUN A verify_host=127.0.0.1 ca=trusted -> ACCEPTED peer_verify=0 peer_cn=real.example
RUN B verify_host=wrong.example ca=trusted -> REJECTED "hostname mismatch" (err 62)
RUN C verify_host=real.example ca=trusted -> ACCEPTED peer_verify=0 peer_cn=real.example
RUN D verify_host=127.0.0.1 ca=NOT trusted-> REJECTED "unable to get local issuer cert" (err 20)
Run A is the finding: a certificate issued to real.example is accepted by a client that asked
to verify 127.0.0.1, and tls_peer_verify() returns 0 — verified.
The other three are the controls, and each rules out a different way I could have been wrong:
- B — the same build, CA and certificate DO reject a mismatched name when a hostname is passed.
So the identity check works; it simply never runs on the IP path. This is not a broken harness.
- C — the hostname path accepts when the name genuinely matches. The test can say yes.
- D — with the CA untrusted, the IP path rejects. So chain validation is still active; it is the
identity check specifically that is missing.
Affected versions
Introduced by 1041521d (2020-12-01, "tls: extend server verification by host name check (SNI)"),
which added the sa_set_str() gate so that IP connections would stop failing — but removed the
check on that path instead of redirecting it to the IP variant.
first release containing 1041521d : v2.0.0
present at : v4.11.0 (current release) and main
SSL_set1_ip_asc / set1_ip in repo : 0 occurrences
Call sites that reach it with a caller-supplied address:
src/sip/transp.c:875 SIP over TLS (sips:)
src/http/client.c:629 HTTPS — and therefore WSS, which SIP-over-WebSocket uses
src/http/client.c:632
src/rtmp/conn.c:709 RTMPS
IPv6 takes the same path; uri_decode_hostport() strips the brackets before this point.
Why the test suite does not catch it
test/tls.c:260 already exercises exactly this call:
tls_set_verify_server(sc, "127.0.0.1");
...
TEST_EQUALS(0, tls_peer_verify(sc));
It passes — but the fixture certificate has CN = 127.0.0.1 and no extensions, so the assertion
holds whether or not the identity check runs. The suite cannot distinguish the two states. That is
offered as an explanation for how this survived six years, not as a criticism.
Suggested fix
Give OpenSSL the identity in the IP case instead of skipping it:
if (sa_set_str(&sa, host, 0)) {
/* ... existing DNS-name path, unchanged ... */
}
else {
/* host IS an IP literal: verify it against the cert's iPAddress SAN */
if (!SSL_set1_ip_asc(tc->ssl, host)) {
DEBUG_WARNING("SSL_set1_ip_asc error\n");
ERR_clear_error();
return EPROTO;
}
/* deliberately no SNI: RFC 6066 forbids a literal address in SNI */
}
A regression test needs a fixture certificate whose identity does not match the address being
verified — the current one cannot fail.
Publication
If you fix these, I would like the advisory published rather than left private, so downstream
projects using libre can see it. Publication matters more to me than credit; list me or don't,
whichever you prefer.
How this was found
The TLS issue came from diffing v4.11.0 against main for security-shaped commits that had not
shipped — b7b9e383 ("verify WSS server identity against the target host") is unreleased, and
reading why led here. Its commit message attributes the WSS failure to the certificate being
"verified against the IP address and failed"; the handshake tests above show what actually happens
is that SNI is skipped (so an SNI-vhosted server returns its default certificate and the chain
check fails), while the identity check is skipped silently. Both observations are consistent;
that fix addresses one call site and does not change tls_set_verify_server().
I am happy to open a PR with the SSL_set1_ip_asc fix and a regression test — just say so. I do
not open PRs unprompted.
For transparency, I use AI assistance in my research. Every result above comes from a run I can
reproduce.
Summary
src/tls/openssl/tls.c,tls_set_verify_server():There is no
else. Whenhostis an IP literal, OpenSSL is given no expected identity of anykind — neither a DNS name via
SSL_set1_host()nor an IP viaSSL_set1_ip_asc()/X509_VERIFY_PARAM_set1_ip().SSL_VERIFY_PEERstill runs, so the chain is checked and thehandshake succeeds;
tls_peer_verify()then reports0, meaning verified.verify_serverdefaults to true (tls.c:306), so this is the default path, not an opt-in.SSL_set1_ip_ascappears zero times in the repository.Reproduction
A server presents a certificate for
real.example(SANDNS:real.example, no IP SAN), signedby a lab CA. The client connects to
127.0.0.1in all four runs. Only the string passed totls_set_verify_server()and whether the CA is trusted vary.Result — four runs, same binary, same server, same certificate
Run A is the finding: a certificate issued to
real.exampleis accepted by a client that askedto verify
127.0.0.1, andtls_peer_verify()returns 0 — verified.The other three are the controls, and each rules out a different way I could have been wrong:
So the identity check works; it simply never runs on the IP path. This is not a broken harness.
identity check specifically that is missing.
Affected versions
Introduced by
1041521d(2020-12-01, "tls: extend server verification by host name check (SNI)"),which added the
sa_set_str()gate so that IP connections would stop failing — but removed thecheck on that path instead of redirecting it to the IP variant.
Call sites that reach it with a caller-supplied address:
IPv6 takes the same path;
uri_decode_hostport()strips the brackets before this point.Why the test suite does not catch it
test/tls.c:260already exercises exactly this call:It passes — but the fixture certificate has
CN = 127.0.0.1and no extensions, so the assertionholds whether or not the identity check runs. The suite cannot distinguish the two states. That is
offered as an explanation for how this survived six years, not as a criticism.
Suggested fix
Give OpenSSL the identity in the IP case instead of skipping it:
A regression test needs a fixture certificate whose identity does not match the address being
verified — the current one cannot fail.
Publication
If you fix these, I would like the advisory published rather than left private, so downstream
projects using libre can see it. Publication matters more to me than credit; list me or don't,
whichever you prefer.
How this was found
The TLS issue came from diffing
v4.11.0againstmainfor security-shaped commits that had notshipped —
b7b9e383("verify WSS server identity against the target host") is unreleased, andreading why led here. Its commit message attributes the WSS failure to the certificate being
"verified against the IP address and failed"; the handshake tests above show what actually happens
is that SNI is skipped (so an SNI-vhosted server returns its default certificate and the chain
check fails), while the identity check is skipped silently. Both observations are consistent;
that fix addresses one call site and does not change
tls_set_verify_server().I am happy to open a PR with the
SSL_set1_ip_ascfix and a regression test — just say so. I donot open PRs unprompted.
For transparency, I use AI assistance in my research. Every result above comes from a run I can
reproduce.