Hello!
I am trying to access an API served by nginx (with a self-signed SSL cert) that requires client certificate authentication, and while I can successfully auth with curl, I unable to accomplish the same with golang.
Example using curl:
# Will not work
# Works
I found an example from this list that I've tried to adapt:
And another from github:
Despite this, golang gets the same result as the first curl with no client cert.
Am I missing something, or is this a regression in go?
package main
import (
"crypto/tls"
"io/ioutil"
"log"
"net/http"
)
func main() {
certFile := "example_cert.pem"
keyFile := "example_key.pem"
// Load client cert
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
log.Fatal(err)
}
// Setup HTTPS client
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAndVerifyClientCert,
InsecureSkipVerify: true,
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
client := &http.Client{
Transport: transport,
}
// Do GET something
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
// Dump response
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
log.Println(string(data))
}