Skip to content

Instantly share code, notes, and snippets.

@xigang
Created September 29, 2017 01:58
Show Gist options
  • Save xigang/f1bb7279f6802c160b1c49d4b1d0808a to your computer and use it in GitHub Desktop.
Save xigang/f1bb7279f6802c160b1c49d4b1d0808a to your computer and use it in GitHub Desktop.
func createClientConfig(ca, crt, key string) (*tls.Config, error) {
caCertPEM, err := ioutil.ReadFile(ca)
if err != nil {
return nil, err
}
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM(caCertPEM)
if !ok {
panic("failed to parse root certificate")
}
cert, err := tls.LoadX509KeyPair(crt, key)
if err != nil {
return nil, err
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: roots,
InsecureSkipVerify: true,
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment