Skip to content

Commit b344be6

Browse files
committed
Fix incorrect base64 encoded caCert usage with Hub Client (#212)
Signed-off-by: Anuj Chaudhari <anuj.chaudhari@broadcom.com>
1 parent f9d2132 commit b344be6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

client/hub/client.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88
"context"
99
"crypto/tls"
1010
"crypto/x509"
11+
"encoding/base64"
1112
"net/http"
1213
"os"
1314
"strconv"
1415

1516
"github.com/pkg/errors"
1617

1718
"github.com/vmware-tanzu/tanzu-plugin-runtime/config"
19+
"github.com/vmware-tanzu/tanzu-plugin-runtime/log"
1820
)
1921

2022
const (
@@ -162,12 +164,22 @@ func (c *hubClient) getTLSConfig() *tls.Config {
162164
// If CACertData is present use it
163165
if certData.CACertData != "" {
164166
var pool *x509.CertPool
165-
var err error
167+
168+
decodedCACertData, err := base64.StdEncoding.DecodeString(certData.CACertData)
169+
if err != nil {
170+
log.Infof("unable to use custom cert for '%s' endpoint. Error: %s", c.tanzuHubEndpoint, err.Error())
171+
return nil
172+
}
173+
166174
pool, err = x509.SystemCertPool()
167175
if err != nil || pool == nil {
168176
pool = x509.NewCertPool()
169177
}
170-
pool.AppendCertsFromPEM([]byte(certData.CACertData))
178+
179+
if ok := pool.AppendCertsFromPEM(decodedCACertData); !ok {
180+
log.Infof("unable to use custom cert for %s endpoint", c.tanzuHubEndpoint)
181+
return nil
182+
}
171183
return &tls.Config{RootCAs: pool, MinVersion: tls.VersionTLS12}
172184
}
173185

0 commit comments

Comments
 (0)