mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-23 22:18:09 +01:00
26 lines
512 B
Go
26 lines
512 B
Go
package utl
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"os"
|
|
)
|
|
|
|
func LoadTLSConfig(insecureSkipVerify bool, caCertFiles []string) (*tls.Config, error) {
|
|
tlsConfig := &tls.Config{
|
|
InsecureSkipVerify: insecureSkipVerify,
|
|
}
|
|
if len(caCertFiles) > 0 {
|
|
certPool := x509.NewCertPool()
|
|
for _, caCertFile := range caCertFiles {
|
|
caCert, err := os.ReadFile(caCertFile)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
certPool.AppendCertsFromPEM(caCert)
|
|
}
|
|
tlsConfig.RootCAs = certPool
|
|
}
|
|
return tlsConfig, nil
|
|
}
|