Skip to content

Commit

Permalink
Add hostname override for MSSQL TLS verification
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlesbykumbi committed Apr 15, 2020
1 parent 30c8dfc commit c446521
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 10 additions & 5 deletions internal/plugin/connectors/tcp/mssql/connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ var sslModeToBaseParams = map[string]map[string]string{
}

const (
sslModeDisable = "disable"
sslModeRequire = "require"
sslModeVerifyCA = "verify-ca"
sslModeDisable = "disable"
sslModeRequire = "require"
sslModeVerifyCA = "verify-ca"
sslModeVerifyFull = "verify-full"
)

Expand Down Expand Up @@ -84,12 +84,17 @@ func newSSLParams(credentials map[string][]byte) map[string]string {
return newSSLParams(credentials)
}

if sslMode == sslModeVerifyCA {
if sslMode == sslModeVerifyCA {
params["rawcertificate"] = string(credentials["sslrootcert"])
}

if sslMode == sslModeVerifyFull {
if sslMode == sslModeVerifyFull {
params["rawcertificate"] = string(credentials["sslrootcert"])

// Ability to override hostname for verification
if len(credentials["sslhost"]) > 0 {
params["hostnameincertificate"] = string(credentials["sslhost"])
}
}

return params
Expand Down
17 changes: 17 additions & 0 deletions internal/plugin/connectors/tcp/mssql/connection_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ func TestConnectionDetails_NewSSLOptions(t *testing.T) {
"rawcertificate": "foo",
},
},
{
description: "sslmode:verify-full with sslhost",
args: args{
credentials: map[string][]byte{
"sslmode": []byte("verify-full"),
"sslhost": []byte("foo.bar"),
"sslrootcert": []byte("foo"),
},
},
expected: map[string]string{
"encrypt": "true",
"trustservercertificate": "false",
"disableverifyhostname": "false",
"rawcertificate": "foo",
"hostnameincertificate": "foo.bar",
},
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion third_party/go-mssqldb
Submodule go-mssqldb updated 2 files
+11 −0 conn_str.go
+23 −0 tds.go

0 comments on commit c446521

Please sign in to comment.