| 23 | } |
| 24 | |
| 25 | func LoadClientPool(cert string) (*x509.CertPool, error) { |
| 26 | pemServerCA, err := os.ReadFile(cert) |
| 27 | if err != nil { |
| 28 | return nil, fmt.Errorf("failed to read server certificate: %v", err) |
| 29 | } |
| 30 | |
| 31 | certPool, err := x509.SystemCertPool() |
| 32 | if err != nil { |
| 33 | certPool = x509.NewCertPool() |
| 34 | } |
| 35 | if !certPool.AppendCertsFromPEM(pemServerCA) { |
| 36 | return nil, fmt.Errorf("failed to add server CA's certificate") |
| 37 | } |
| 38 | |
| 39 | return certPool, nil |
| 40 | } |
| 41 | |
| 42 | func CreateHTTPClient(certPool *x509.CertPool, hostname string) *http.Client { |
| 43 | tlsConfig := &tls.Config{RootCAs: certPool, ServerName: hostname} |