Skip to content

Commit

Permalink
Merge pull request #95 from brownds14/tls-connection
Browse files Browse the repository at this point in the history
Allow TLS connection without client authentication
  • Loading branch information
birdayz authored Feb 7, 2020
2 parents dd3750f + 49f4948 commit 9d3fda9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cmd/kaf/kaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ func getConfig() (saramaConfig *sarama.Config) {
tlsConfig.RootCAs = caCertPool
}

clientCert, err := ioutil.ReadFile(cluster.TLS.Clientfile)
if err != nil {
errorExit("Unable to read Clientfile :%v\n", err)
}
clientKey, err := ioutil.ReadFile(cluster.TLS.Clientkeyfile)
if err != nil {
errorExit("Unable to read Clientkeyfile :%v\n", err)
}
if cluster.TLS.Clientfile != "" && cluster.TLS.Clientkeyfile != "" {
clientCert, err := ioutil.ReadFile(cluster.TLS.Clientfile)
if err != nil {
errorExit("Unable to read Clientfile :%v\n", err)
}
clientKey, err := ioutil.ReadFile(cluster.TLS.Clientkeyfile)
if err != nil {
errorExit("Unable to read Clientkeyfile :%v\n", err)
}

cert, err := tls.X509KeyPair([]byte(clientCert), []byte(clientKey))
if err != nil {
errorExit("Unable to creatre KeyPair: %v\n", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
cert, err := tls.X509KeyPair([]byte(clientCert), []byte(clientKey))
if err != nil {
errorExit("Unable to creatre KeyPair: %v\n", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}

tlsConfig.BuildNameToCertificate()
tlsConfig.BuildNameToCertificate()
}
saramaConfig.Net.TLS.Config = tlsConfig
}
if cluster.SecurityProtocol == "SASL_SSL" {
Expand Down

0 comments on commit 9d3fda9

Please sign in to comment.