Skip to content

Commit

Permalink
fix: Only append root CAs on TLS config when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsaintroch committed Dec 3, 2024
1 parent 50c4eeb commit 31a7954
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ func (cfg *ConfigTLS) ToStandardTLS() (*tls.Config, []errorstack.Validation) {
})
}

tlsConfig := &tls.Config{
ServerName: cfg.ServerName,
InsecureSkipVerify: cfg.InsecureSkipVerify,
Certificates: []tls.Certificate{cert},
}

if len(cfg.RootCAFiles) == 0 {
return tlsConfig, nil
}

caCertPool := x509.NewCertPool()
for _, ca := range cfg.RootCAFiles {
caCert, err := os.ReadFile(ca)
Expand All @@ -112,7 +122,7 @@ func (cfg *ConfigTLS) ToStandardTLS() (*tls.Config, []errorstack.Validation) {
ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok {
validations = append(validations, errorstack.Validation{
Message: err.Error(),
Message: "failed to append root certificate from pem",
})
}
}
Expand All @@ -121,12 +131,6 @@ func (cfg *ConfigTLS) ToStandardTLS() (*tls.Config, []errorstack.Validation) {
return nil, validations
}

tlsConfig := &tls.Config{
ServerName: cfg.ServerName,
InsecureSkipVerify: cfg.InsecureSkipVerify,
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
}

tlsConfig.RootCAs = caCertPool
return tlsConfig, nil
}

0 comments on commit 31a7954

Please sign in to comment.