Skip to content

Commit 1aca068

Browse files
committed
Reference commit - Custom TLS config
This was just so I could test something locally. I hardcoded the CA cert and domain I needed in and then had a custom TLS config which used the CA cert and domain only. The `make([]byte, 0)` are effectively Nils and a way to set the cert/key pair to Nil. Ideally what I'd like to do is finish this off properly, but I don't actually need this change. The basic TLS changes are all I need.
1 parent d865626 commit 1aca068

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

driver/driver.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
type driver struct {
1919
}
2020

21+
// Testing custom tls by hard-coding something in
22+
var CaPem = []byte(`-----BEGIN CERTIFICATE-----
23+
MYCACERT
24+
-----END CERTIFICATE-----`)
25+
2126
// Open: DSN user:password@addr[?db]
2227
func (d driver) Open(dsn string) (sqldriver.Conn, error) {
2328
lastIndex := strings.LastIndex(dsn, "@")
@@ -70,6 +75,8 @@ func (d driver) Open(dsn string) (sqldriver.Conn, error) {
7075
return nil, errors.Errorf("invalid dsn, must user:password@addr[[?db[&param=X]]")
7176
}
7277

78+
custom := client.NewClientTLSConfig(CaPem, make([]byte, 0), make([]byte, 0), false, "custom.host.name")
79+
7380
tlsConfigName, tls := params["ssl"]
7481
if tls {
7582
if tlsConfigName == "true" {
@@ -82,8 +89,8 @@ func (d driver) Open(dsn string) (sqldriver.Conn, error) {
8289
// `tlsConfigName` which is a string type and using that to point at the actual
8390
// `tlsConfig` which is a `NewClientTLSConfig` type. Can probably draw
8491
// inspiration from go-sql-driver/mysql
85-
//c, err := client.Connect(addr, user, password, db, func(c *Conn) {c.SetTLSConfig(tlsConfig)})
86-
return nil, errors.Errorf("Custom TLS configuration support not implemented yet")
92+
c, err = client.Connect(addr, user, password, db, func(c *client.Conn) {c.SetTLSConfig(custom)})
93+
//return nil, errors.Errorf("Custom TLS configuration support not implemented yet")
8794
}
8895
} else {
8996
c, err = client.Connect(addr, user, password, db)

0 commit comments

Comments
 (0)