Skip to content

parseDSNParams manipulates global TLS config #544

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

Closed
x6j8x opened this issue Feb 14, 2017 · 1 comment
Closed

parseDSNParams manipulates global TLS config #544

x6j8x opened this issue Feb 14, 2017 · 1 comment

Comments

@x6j8x
Copy link

x6j8x commented Feb 14, 2017

Issue description

When connecting to multiple databases from the same program using TLS the current logic in parseDSNParams regarding the tlsconfig.ServerName is counterintuitive. It manipulates the global TLSConfig instance from the registry by setting the tlsconfig.ServerName property.

This results in an error like this (when trying to talk to multiple AWS Aurora databases):

x509: certificate is valid for cluster-cfcc3334-[..].eu-west-1.rds.amazonaws.com, cluster-cfcc3334-[..].eu-west-1.rds.amazonaws.com, not cluster-a865301d-[..].eu-west-1.rds.amazonaws.com

The easiest fix would be to take a copy of the global TLSConfig and use this copy for the DB specific parameter (like ServerName). Like this:

dsn.go / starting line 509

	if tlsConfig, ok := tlsConfigRegister[name]; ok {
		localTlsConfig := *tlsConfig
		if len(localTlsConfig.ServerName) == 0 && !localTlsConfig.InsecureSkipVerify {
			host, _, err := net.SplitHostPort(cfg.Addr)
			if err == nil {
				localTlsConfig.ServerName = host
			}
		}

		cfg.TLSConfig = name
		cfg.tls = &localTlsConfig
	} else {
		return errors.New("invalid value / unknown config name: " + name)
	}

Configuration

Driver version (or git SHA): 2e00b5c

Go version: 1.7.5

Server version: AWS Aurora 5.6.10a

@x6j8x
Copy link
Author

x6j8x commented Feb 14, 2017

duplicate to issue #536

@x6j8x x6j8x closed this as completed Feb 14, 2017
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

No branches or pull requests

1 participant