From ccd0bf520adbf90534fab2529e29dfbf5948419b Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Thu, 2 Feb 2017 11:26:23 -0800 Subject: [PATCH 1/2] make tls=true do the same thing as tls=. otherwise it's pretty useless. --- dsn.go | 8 +++++++- dsn_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dsn.go b/dsn.go index ac00dcedd..55dd73895 100644 --- a/dsn.go +++ b/dsn.go @@ -493,7 +493,13 @@ func parseDSNParams(cfg *Config, params string) (err error) { if isBool { if boolValue { cfg.TLSConfig = "true" - cfg.tls = &tls.Config{} + + var host string + host, _, err = net.SplitHostPort(cfg.Addr) + if err != nil { + return + } + cfg.tls = &tls.Config{ServerName: host} } else { cfg.TLSConfig = "false" } diff --git a/dsn_test.go b/dsn_test.go index 0693192ad..15dd748fe 100644 --- a/dsn_test.go +++ b/dsn_test.go @@ -161,6 +161,18 @@ func TestDSNWithCustomTLS(t *testing.T) { t.Errorf("did not get the correct ServerName (%s) parsing DSN (%s).", name, tst) } + // tls=true should also pick localhost + tst = baseDSN + "true" + name = "localhost" + tlsCfg.ServerName = "" + cfg, err = ParseDSN(tst) + + if err != nil { + t.Error(err.Error()) + } else if cfg.tls.ServerName != name { + t.Errorf("did not get the correct ServerName (%s) parsing DSN (%s).", name, tst) + } + DeregisterTLSConfig("utils_test") } From 8649abc4b2a7e2d318b3420f3f1d6fd553ea0cbb Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Thu, 2 Feb 2017 11:36:23 -0800 Subject: [PATCH 2/2] update the README.md and AUTHORS --- AUTHORS | 1 + README.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 100370758..1fa976df7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,6 +15,7 @@ Aaron Hopkins Arne Hormann Carlos Nieto Chris Moos +Chris Toshok Daniel Nichter Daniƫl van Eeden DisposaBoy diff --git a/README.md b/README.md index 645203850..7ce2ac5d3 100644 --- a/README.md +++ b/README.md @@ -293,11 +293,11 @@ Default: OS default ``` Type: bool / string -Valid Values: true, false, skip-verify, +Valid Values: true, false, skip-verify, , Default: false ``` -`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig). +Every value other than `false` enables TLS/SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom `` if you've registered it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig). Both `true` and `` will use use the `host` from the address for the expected `ServerName`. ##### `writeTimeout`