Skip to content

Commit

Permalink
Add system CAs for CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Larson <larsond@us.ibm.com>
  • Loading branch information
dlarson04 authored and MaxMcAdam committed Jul 12, 2024
1 parent 9543d04 commit e06b14f
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions cli/cliutils/cliutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,20 +1098,29 @@ func GetIcpCertPath() string {

// TrustIcpCert adds the icp cert file to be trusted in calls made by the given http client
func TrustIcpCert(httpClient *http.Client) error {
icpCertPath := GetIcpCertPath()
if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(icpCert)

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool

}
return nil
icpCertPath := GetIcpCertPath()

var caCertPool *x509.CertPool
var err error

// Trust the system certs like the anax agent code can
caCertPool, err = x509.SystemCertPool()
if err != nil {
// Decided not to fail and return here but just create a new pool
caCertPool = x509.NewCertPool()
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool.AppendCertsFromPEM(icpCert)
}

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool
return nil
}

// Get exchange url from /etc/default/horizon file. if not set, check /etc/horizon/anax.json file
Expand Down

0 comments on commit e06b14f

Please sign in to comment.