@@ -253,39 +253,41 @@ func (c *criService) updateImage(ctx context.Context, r string) error {
253253// getTLSConfig returns a TLSConfig configured with a CA/Cert/Key specified by registryTLSConfig
254254func (c * criService ) getTLSConfig (registryTLSConfig criconfig.TLSConfig ) (* tls.Config , error ) {
255255 var (
256- cert tls.Certificate
257- err error
256+ tlsConfig = & tls.Config {}
257+ cert tls.Certificate
258+ err error
258259 )
259- if registryTLSConfig .CertFile != "" && registryTLSConfig .KeyFile != "" {
260- cert , err = tls .LoadX509KeyPair (registryTLSConfig .CertFile , registryTLSConfig .KeyFile )
261- if err != nil {
262- return nil , errors .Wrap (err , "failed to load cert file" )
263- }
264- }
265260 if registryTLSConfig .CertFile != "" && registryTLSConfig .KeyFile == "" {
266261 return nil , errors .Errorf ("cert file %q was specified, but no corresponding key file was specified" , registryTLSConfig .CertFile )
267262 }
268263 if registryTLSConfig .CertFile == "" && registryTLSConfig .KeyFile != "" {
269264 return nil , errors .Errorf ("key file %q was specified, but no corresponding cert file was specified" , registryTLSConfig .KeyFile )
270265 }
271-
272- caCertPool , err := x509 .SystemCertPool ()
273- if err != nil {
274- return nil , errors .Wrap (err , "failed to get system cert pool" )
275- }
276- caCert , err := ioutil .ReadFile (registryTLSConfig .CAFile )
277- if err != nil {
278- return nil , errors .Wrap (err , "failed to load CA file" )
266+ if registryTLSConfig .CertFile != "" && registryTLSConfig .KeyFile != "" {
267+ cert , err = tls .LoadX509KeyPair (registryTLSConfig .CertFile , registryTLSConfig .KeyFile )
268+ if err != nil {
269+ return nil , errors .Wrap (err , "failed to load cert file" )
270+ }
271+ if len (cert .Certificate ) != 0 {
272+ tlsConfig .Certificates = []tls.Certificate {cert }
273+ }
274+ tlsConfig .BuildNameToCertificate ()
279275 }
280- caCertPool .AppendCertsFromPEM (caCert )
281276
282- tlsConfig := & tls.Config {
283- RootCAs : caCertPool ,
284- }
285- if len (cert .Certificate ) != 0 {
286- tlsConfig .Certificates = []tls.Certificate {cert }
277+ if registryTLSConfig .CAFile != "" {
278+ caCertPool , err := x509 .SystemCertPool ()
279+ if err != nil {
280+ return nil , errors .Wrap (err , "failed to get system cert pool" )
281+ }
282+ caCert , err := ioutil .ReadFile (registryTLSConfig .CAFile )
283+ if err != nil {
284+ return nil , errors .Wrap (err , "failed to load CA file" )
285+ }
286+ caCertPool .AppendCertsFromPEM (caCert )
287+ tlsConfig .RootCAs = caCertPool
287288 }
288- tlsConfig .BuildNameToCertificate ()
289+
290+ tlsConfig .InsecureSkipVerify = registryTLSConfig .InsecureSkipVerify
289291 return tlsConfig , nil
290292}
291293
0 commit comments