Skip to content
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

Set tls ServerName to fix issue: either ServerName or InsecureSkipVerify must be specified in the tls.Config #1692

Merged
merged 2 commits into from May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions broker.go
Expand Up @@ -165,6 +165,17 @@ func (b *Broker) Open(conf *Config) error {

if conf.Net.TLS.Enable {
Logger.Printf("Using tls")

// If no ServerName is set, infer the ServerName
// from the hostname we're connecting to.
if conf.Net.TLS.Config.ServerName == "" {
d1egoaz marked this conversation as resolved.
Show resolved Hide resolved
colonPos := strings.LastIndex(b.addr, ":")
if colonPos == -1 {
colonPos = len(b.addr)
}
hostname := b.addr[:colonPos]
conf.Net.TLS.Config.ServerName = hostname
}
b.conn = tls.Client(b.conn, conf.Net.TLS.Config)
}

Expand Down
3 changes: 1 addition & 2 deletions client_tls_test.go
Expand Up @@ -158,8 +158,7 @@ func TestTLS(t *testing.T) {
Succeed: true,
Server: serverTLSConfig,
Client: &tls.Config{
RootCAs: pool,
ServerName: "127.0.0.1",
RootCAs: pool,
Certificates: []tls.Certificate{{
Certificate: [][]byte{clientDer},
PrivateKey: clientkey,
Expand Down