@@ -11,20 +11,24 @@ import (
1111 "github.com/segmentio/kafka-go/sasl/scram"
1212)
1313
14- func NewTLSConfig (sasl kafka.SASLConfig ) * tls.Config {
15- rootCA , err := os .ReadFile (sasl .RootCAPath )
14+ func NewTLSConfig (cfg * kafka.Config ) * tls.Config {
15+ rootCA , err := os .ReadFile (cfg . SASL .RootCAPath )
1616 if err != nil {
17- panic ("Error while reading Root CA file: " + sasl .RootCAPath + " error: " + err .Error ())
17+ panic ("Error while reading Root CA file: " + cfg . SASL .RootCAPath + " error: " + err .Error ())
1818 }
1919
20- interCA , err := os . ReadFile ( sasl . IntermediateCAPath )
21- if err != nil {
22- panic ("Error while reading Intermediate CA file: " + sasl . IntermediateCAPath + " error : " + err . Error () )
20+ caCertPool := x509 . NewCertPool ( )
21+ if ok := caCertPool . AppendCertsFromPEM ( rootCA ); ! ok {
22+ panic ("failed to append Root CA certificates from file : " + cfg . SASL . RootCAPath )
2323 }
2424
25- caCertPool := x509 .NewCertPool ()
26- caCertPool .AppendCertsFromPEM (rootCA )
27- caCertPool .AppendCertsFromPEM (interCA )
25+ interCA , err := os .ReadFile (cfg .SASL .IntermediateCAPath )
26+ if err != nil {
27+ cfg .Logger .Warnf ("Unable to read Intermediate CA file: %s, error: %v" , cfg .SASL .IntermediateCAPath , err )
28+ cfg .Logger .Info ("Intermediate CA will be skipped." )
29+ } else if ok := caCertPool .AppendCertsFromPEM (interCA ); ! ok {
30+ cfg .Logger .Warnf ("Failed to append Intermediate CA certificates from file: %s" , cfg .SASL .IntermediateCAPath )
31+ }
2832
2933 return & tls.Config {
3034 RootCAs : caCertPool ,
0 commit comments