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

[Cherry-pick 1.4] Fix incorrect base64 encoded caCert usage with Hub Client (#212) #213

Merged
Merged
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
16 changes: 14 additions & 2 deletions client/hub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"net/http"
"os"
"strconv"

"github.com/pkg/errors"

"github.com/vmware-tanzu/tanzu-plugin-runtime/config"
"github.com/vmware-tanzu/tanzu-plugin-runtime/log"
)

const (
Expand Down Expand Up @@ -162,12 +164,22 @@ func (c *hubClient) getTLSConfig() *tls.Config {
// If CACertData is present use it
if certData.CACertData != "" {
var pool *x509.CertPool
var err error

decodedCACertData, err := base64.StdEncoding.DecodeString(certData.CACertData)
if err != nil {
log.Infof("unable to use custom cert for '%s' endpoint. Error: %s", c.tanzuHubEndpoint, err.Error())
return nil
}

pool, err = x509.SystemCertPool()
if err != nil || pool == nil {
pool = x509.NewCertPool()
}
pool.AppendCertsFromPEM([]byte(certData.CACertData))

if ok := pool.AppendCertsFromPEM(decodedCACertData); !ok {
log.Infof("unable to use custom cert for %s endpoint", c.tanzuHubEndpoint)
return nil
}
return &tls.Config{RootCAs: pool, MinVersion: tls.VersionTLS12}
}

Expand Down
Loading