Skip to content

Commit

Permalink
Merge pull request #1 from EverTrust/fix/ca-bundle
Browse files Browse the repository at this point in the history
Fixed CA bundle checking & TLS verification
  • Loading branch information
antoninguyot authored Jul 5, 2022
2 parents 0bbc1b9 + 46c2c52 commit 44cdae9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,22 @@ func (c *Client) Init(baseUrl url.URL, apiId string, apiKey string) {
c.baseUrl = baseUrl
c.apiId = apiId
c.apiKey = apiKey
c.Transport.TLSClientConfig = &tls.Config{}
c.baseClient.Transport = &c.Transport
}

// SetCaBundle sets the client certificate than can be used for authentication.
func (c *Client) SetCaBundle(caBundle string) {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM([]byte(caBundle))
c.Transport.TLSClientConfig = &tls.Config{
RootCAs: caCertPool,
caCertPool, _ := x509.SystemCertPool()
if caCertPool == nil {
caCertPool = x509.NewCertPool()
}
caCertPool.AppendCertsFromPEM([]byte(caBundle))
c.Transport.TLSClientConfig.RootCAs = caCertPool
}

func (c *Client) SkipTLSVerify() {
c.Transport.TLSClientConfig.InsecureSkipVerify = true
}

func (c *Client) SetProxy(proxyUrl url.URL) {
Expand Down

0 comments on commit 44cdae9

Please sign in to comment.