git.iko.soy/typeable/oauth2-proxy
on ea261ca help sign in
25 lines 626 B history raw
1package util
3import (
4 "crypto/x509"
5 "fmt"
6 "io/ioutil"
7)
9func GetCertPool(paths []string) (*x509.CertPool, error) {
10 if len(paths) == 0 {
11 return nil, fmt.Errorf("invalid empty list of Root CAs file paths")
12 }
13 pool := x509.NewCertPool()
14 for _, path := range paths {
15 // Cert paths are a configurable option
16 data, err := ioutil.ReadFile(path) // #nosec G304
17 if err != nil {
18 return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err)
19 }
20 if !pool.AppendCertsFromPEM(data) {
21 return nil, fmt.Errorf("loading certificate authority (%s) failed", path)
22 }
23 }
24 return pool, nil