I have issue with client authentication via certificate in GoLang. From trace I see that server is requesting certificate but certificate is not send in client response.
Here is my Go code:
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
xml := `
<Packet>
<Header>
<ID>1231232132132354234</ID>
</Header>
<Body>
<Item>
<Content>SMS</Content>
<Phone_no>+123123213</Phone_no>
<Content>test</Content>
<OriginAddress>Posiljatelj</OriginAddress>
</Item>
</Body>
</Packet>
`
// Load client cert
cert, err := tls.LoadX509KeyPair("../cert/certNEW.pem", "../cert/serverNEW.key")
if err != nil {
log.Fatal(err)
}
// Load CA cert
caCert, err := ioutil.ReadFile("../cert/cacerts.cer")
if err != nil {
log.Fatal(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
// Setup HTTPS client
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
InsecureSkipVerify: true,
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}
resp, err := client.Post("https://api.url", "text/xml", bytes.NewBuffer([]byte(xml)))
if err != nil {
fmt.Println(err)
}
contents, err := ioutil.ReadAll(resp.Body)
fmt.Printf("%s
", string(contents))
}
I got pfx certificate from client, what i did is that I extraceted public client certificate, private certificate and rootRA public part and I assrted in Go code.