2020-07-03 17:09:17 +02:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/x509"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetCertPool(paths []string) (*x509.CertPool, error) {
|
|
|
|
if len(paths) == 0 {
|
|
|
|
return nil, fmt.Errorf("invalid empty list of Root CAs file paths")
|
|
|
|
}
|
|
|
|
pool := x509.NewCertPool()
|
|
|
|
for _, path := range paths {
|
2020-07-21 03:49:45 +02:00
|
|
|
// Cert paths are a configurable option
|
2020-07-20 07:24:18 +02:00
|
|
|
data, err := ioutil.ReadFile(path) // #nosec G304
|
2020-07-03 17:09:17 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err)
|
|
|
|
}
|
|
|
|
if !pool.AppendCertsFromPEM(data) {
|
|
|
|
return nil, fmt.Errorf("loading certificate authority (%s) failed", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pool, nil
|
|
|
|
}
|