Skip to content

Commit

Permalink
Fix incorrect base64 encoded caCert usage with Hub Client
Browse files Browse the repository at this point in the history
Signed-off-by: Anuj Chaudhari <[email protected]>
  • Loading branch information
anujc25 committed Aug 30, 2024
1 parent f5842d0 commit 8f4d43a
Showing 1 changed file with 14 additions and 2 deletions.
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 when taking to '%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 when taking to %s endpoint", c.tanzuHubEndpoint)
return nil
}
return &tls.Config{RootCAs: pool, MinVersion: tls.VersionTLS12}
}

Expand Down

0 comments on commit 8f4d43a

Please sign in to comment.