@@ -169,32 +169,34 @@ func (c *clientImpl) initAuth(saramaConfig *sarama.Config) error {
169169 return nil
170170}
171171
172- // convertTLSConfig convert tls config
173- func convertTLSConfig (tlsConfig auth.TLS ) (* tls.Config , error ) {
174- if ! tlsConfig .Enabled {
172+ // convertTLSConfig converts tls config
173+ func convertTLSConfig (authConfig auth.TLS ) (* tls.Config , error ) {
174+ if ! authConfig .Enabled {
175175 return nil , nil
176176 }
177177
178- if tlsConfig .CertFile != "" && tlsConfig .CaFile != "" && tlsConfig .KeyFile != "" {
179- cert , err := tls .LoadX509KeyPair (tlsConfig .CertFile , tlsConfig .KeyFile )
178+ tlsConfig := & tls.Config {
179+ InsecureSkipVerify : ! authConfig .EnableHostVerification ,
180+ }
181+
182+ if authConfig .CaFile != "" {
183+ caCertPool := x509 .NewCertPool ()
184+ pemData , err := ioutil .ReadFile (authConfig .CaFile )
180185 if err != nil {
181186 return nil , err
182187 }
183- caCertPool := x509 .NewCertPool ()
184- pemData , err := ioutil .ReadFile (tlsConfig .CaFile )
188+ caCertPool .AppendCertsFromPEM (pemData )
189+
190+ tlsConfig .RootCAs = caCertPool
191+ }
192+
193+ if authConfig .CertFile != "" && authConfig .KeyFile != "" {
194+ cert , err := tls .LoadX509KeyPair (authConfig .CertFile , authConfig .KeyFile )
185195 if err != nil {
186196 return nil , err
187197 }
188- caCertPool .AppendCertsFromPEM (pemData )
189198
190- return & tls.Config {
191- Certificates : []tls.Certificate {cert },
192- RootCAs : caCertPool ,
193- InsecureSkipVerify : ! tlsConfig .EnableHostVerification ,
194- }, nil
195- } else {
196- return & tls.Config {
197- InsecureSkipVerify : ! tlsConfig .EnableHostVerification ,
198- }, nil
199+ tlsConfig .Certificates = []tls.Certificate {cert }
199200 }
201+ return tlsConfig , nil
200202}
0 commit comments