Skip to content

Commit

Permalink
CAFile is now optional, in that case the default RootCAs are used
Browse files Browse the repository at this point in the history
  • Loading branch information
bonifaido committed Jun 22, 2017
1 parent 42ede7f commit 5f96fb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/getter/httpgetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (g *httpGetter) Get(href string) (*bytes.Buffer, error) {
// newHTTPGetter constructs a valid http/https client as Getter
func newHTTPGetter(URL, CertFile, KeyFile, CAFile string) (Getter, error) {
var client httpGetter
if CertFile != "" && KeyFile != "" && CAFile != "" {
if CertFile != "" && KeyFile != "" {
tlsConf, err := tlsutil.NewClientTLS(CertFile, KeyFile, CAFile)
if err != nil {
return nil, fmt.Errorf("can't create TLS config for client: %s", err.Error())
Expand Down
17 changes: 10 additions & 7 deletions pkg/tlsutil/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ func NewClientTLS(certFile, keyFile, caFile string) (*tls.Config, error) {
if err != nil {
return nil, err
}
cp, err := CertPoolFromFile(caFile)
if err != nil {
return nil, err
}
return &tls.Config{
config := tls.Config{
Certificates: []tls.Certificate{*cert},
RootCAs: cp,
}, nil
}
if caFile != "" {
cp, err := CertPoolFromFile(caFile)
if err != nil {
return nil, err
}
config.RootCAs = cp
}
return &config, nil
}

// CertPoolFromFile returns an x509.CertPool containing the certificates
Expand Down

0 comments on commit 5f96fb8

Please sign in to comment.