git.iko.soy/typeable/oauth2-proxy
on 71dc702 help sign in
24 lines 569 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 data, err := ioutil.ReadFile(path)
16 if err != nil {
17 return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err)
18 }
19 if !pool.AppendCertsFromPEM(data) {
20 return nil, fmt.Errorf("loading certificate authority (%s) failed", path)
21 }
22 }
23 return pool, nil