@@ -169,32 +169,34 @@ func (c *clientImpl) initAuth(saramaConfig *sarama.Config) error {
169
169
return nil
170
170
}
171
171
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 {
175
175
return nil , nil
176
176
}
177
177
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 )
180
185
if err != nil {
181
186
return nil , err
182
187
}
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 )
185
195
if err != nil {
186
196
return nil , err
187
197
}
188
- caCertPool .AppendCertsFromPEM (pemData )
189
198
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 }
199
200
}
201
+ return tlsConfig , nil
200
202
}
0 commit comments