Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CLI to trust system certs #4100

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions cli/cliutils/cliutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,20 +1098,28 @@ 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 {
return err
}

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
Loading