Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable SNI #953

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions driver/pgdriver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func parseDSN(dsn string) ([]Option, error) {
case "require":
if sslRootCert == "" {
tlsConfig.InsecureSkipVerify = true
tlsConfig.ServerName = u.Host
if host, _, err := net.SplitHostPort(u.Host); err == nil {
tlsConfig.ServerName = host
}
break
}
// For backwards compatibility reasons, in the presence of `sslrootcert`,
Expand All @@ -283,6 +287,10 @@ func parseDSN(dsn string) ([]Option, error) {
// (verify chain, but skip server name).
// See https://github.com/golang/go/issues/21971 .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comment and explain why this is required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is still correct. InsecureSkipVerify = true will not verify either the certificate chain nor verify the server name. The ServerName field only adds the server name to the TLS ClientHello but doesn't impact the verification if insecure is set.

Copy link
Member

@vmihailenco vmihailenco Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks.

tlsConfig.InsecureSkipVerify = true
tlsConfig.ServerName = u.Host
if host, _, err := net.SplitHostPort(u.Host); err == nil {
tlsConfig.ServerName = host
}
tlsConfig.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
certs := make([]*x509.Certificate, 0, len(rawCerts))
for _, rawCert := range rawCerts {
Expand Down
Loading