-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add support for custom tls.Configs #101
Conversation
"crypto/tls" | ||
) | ||
|
||
type TLSConfig interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this interface for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, as you commented on later.
Ok all the changes are made. I'm not very good at writing documentation, but gave it my best shot. |
@@ -113,7 +114,7 @@ Possible Parameters are: | |||
* `parseTime`: `parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string` | |||
* `strict`: Enable strict mode. MySQL warnings are treated as errors. | |||
* `timeout`: **Driver** side connection timeout. The value must be a string of decimal numbers, each with optional fraction and a unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout). | |||
* `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) | |||
* `tls`: `true` enables TLS / SSL encrypted connection to the server. For other values see [TLS support](#tls-support). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my delayed response.
Please keep it up here. It is not necessary to make a new section for a single parameter. Just note that you can register your own configurations and refer to the godoc.
Ignore the INFILE section, this will be reworked before the next release.
LGTM |
@julienschmidt LGTM; I'd love to have tests for it, though. |
Yes, this is the general case. But I'm more comfortable if another pair of eyes checks this PR to make sure we didn't miss a thing. |
// Use the key as a value in the DSN where tls=value. | ||
// | ||
// rootCertPool := x509.NewCertPool() | ||
// { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this one... the extra scopes are a bit confusing since they are not conventional Go-style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed the note on this line 😉
Please replace the TestTLS function in driver_test.go with the following code: func TestTLS(t *testing.T) {
tlsTest := func(dbt *DBTest) {
if err := dbt.db.Ping(); err != nil {
if err == errNoTLS {
dbt.Skip("Server does not support TLS")
} else {
dbt.Fatalf("Error on Ping: %s", err.Error())
}
}
rows := dbt.mustQuery("SHOW STATUS LIKE 'Ssl_cipher'")
var variable, value *sql.RawBytes
for rows.Next() {
if err := rows.Scan(&variable, &value); err != nil {
dbt.Fatal(err.Error())
}
if value == nil {
dbt.Fatal("No Cipher")
}
}
}
runTests(t, dsn+"&tls=skip-verify", tlsTest)
// Verify that registering / using a custom cfg works
RegisterTLSConfig("custom-skip-verify", &tls.Config{
InsecureSkipVerify: true,
})
runTests(t, dsn+"&tls=custom-skip-verify", tlsTest)
} Also add This adds a simple test, that verifies that registering a custom tls.Config works (regardless of the server supports TLS) |
Ok, I've made the changes. Tests pass. Here is the diff. Anything else before I make the next commit? (Scopes removed in example, test added, tls.Config{} changed to &tls.Config{}) ... |
No, looks good to me now. |
Oh sorry, he already did earlier. Just commit and I merge it |
Thanks a lot! |
Add support for custom tls.Configs
This adds the ability to customize the tls.Config object so you can:
Example of how it would be used: