Skip to content

fix(v2,v3): verify TLS certificate against original host after listener redirect - #766

Open
mfielding wants to merge 2 commits into
sijms:masterfrom
mfielding:keep-original-host-tls-redirect
Open

mfielding wants to merge 2 commits into
sijms:masterfrom
mfielding:keep-original-host-tls-redirect

Conversation

@mfielding

@mfielding mfielding commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a TCPS connection goes through a listener that redirects (the usual case for an Oracle RAC SCAN listener, which hands the client off to a node listener), go-ora verifies the server certificate against the redirect target instead of the host in the original connect descriptor.

SCAN listeners typically redirect to the node VIP IP address. Listener certificates, including the defaults Oracle provisions, are issued for the SCAN host name and have no IP SANs, so verification fails:

x509: cannot validate certificate for 10.0.0.42 because it doesn't contain any IP SANs

The same connect string works with JDBC thin, Instant Client, and python-oracledb (fixed there in 3.0.0, oracle/python-oracledb#415). These clients check the certificate against the host the user asked for, not the address the listener redirected to.

The only workarounds today are SSL VERIFY=false or a listener certificate with IP SANs for every node VIP.

Cause

Session.Connect handles a RedirectPacket by calling UpdateDatabaseInfoForRedirect, which replaces DatabaseInfo.Servers with the addresses from the redirect. Session.negotiate then sets tls.Config.ServerName = host.Addr for the active server, which is now the redirect address.

Change

  • ServerAddr gets a TLSServerName field and a TLSHostName() method that returns TLSServerName if set, otherwise Addr.
  • UpdateDatabaseInfoForRedirect records TLSHostName() of the server that sent the redirect and sets it as TLSServerName on every redirect address. A chain of redirects keeps the original host.
  • negotiate uses host.TLSHostName() for ServerName in both the wallet path and the caller-supplied tls.Config path.

Behaviour without a redirect doesn't change. Verification is not relaxed: the chain and host-name checks still run, against the host the user wrote in the connect string. If that host was an IP address, verification is against that IP, as before.

Tests

  • configurations/database_info_test.go: a redirect keeps the original host; a second redirect still keeps the first host; TLSHostName defaults to Addr.
  • network/session_tls_test.go: TLS handshake through negotiate against a loopback server with a DNS-only certificate, after a redirect from scan.example.com to 10.0.0.42:
    • succeeds, using wallet roots or a caller tls.Config;
    • fails with a host-name error for scan.example.com when the certificate is for a different name.

Without the change, both handshake tests fail with x509: cannot validate certificate for 10.0.0.42 because it doesn't contain any IP SANs.

Applied identically to v2 and v3.

Second commit: don't modify the caller's tls.Config (fixes #757)

negotiate set ServerName directly on the tls.Config passed to WithTLSConfig. That config is shared by every connection the connector makes. Concurrent connections therefore race on ServerName, and a handshake can be verified against another connection's host name. The commit clones the config before setting ServerName.

We observed this against a two-node RAC with 16 concurrent connections built with -race:

  • The race detector reported races at session.go:345.
  • On unpatched master, one connection to a node VIP IP sent no SNI but passed verification. The likely cause is another goroutine setting ServerName to the SCAN name between the ClientHello and the certificate check.

Test: TestNegotiateDoesNotModifyCallerTLSConfig runs four concurrent negotiate calls against one shared config, then checks that ServerName on it is still empty. Without the change, -race reports a race and the check fails.

Fixes #765

After a listener redirect (for example a RAC SCAN listener handing off to a
node listener by VIP IP), negotiate set tls.Config.ServerName to the redirect
address. Certificates issued for the SCAN host name with no IP SANs then fail
verification, while JDBC and the OCI clients accept them.

Record the host of the server that sent the redirect as TLSServerName on each
redirect address and use it as ServerName.
negotiate set ServerName on the tls.Config passed to WithTLSConfig. That
config is shared by every connection made with the connector, so concurrent
connections raced on ServerName, and a handshake could be verified against
the host name of another connection. Clone the config before setting
ServerName.

Fixes sijms#757
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant