I have to connect with https url and I am provided with .crt, .key and .csr file. I am trying using code:
caCert, err := ioutil.ReadFile("file1.crt")
if err != nil {
fmt.Println("error in read crt")
fmt.Println(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
cer, err := tls.LoadX509KeyPair("file1.crt", "file2.key")
if err != nil {
fmt.Println("cert load error")
fmt.Println(err.Error())
}
proxyUrl, _ := url.Parse("http://xxx.xxx.xxx.xx:yy")
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
ServerName: "abc.com",
RootCAs: caCertPool,
Certificates: []tls.Certificate{cer},
},
Proxy: http.ProxyURL(proxyUrl),
}}
req, err := http.NewRequest("POST", url, nil)
if err != nil {
fmt.Println(err)
}
req.Header.Set("id", id)
resp, err := client.Do(req)
I am behind proxy and corporate firewall. When I try to connect using above code I am getting error:
x509: certificate signed by unknown authority
Why I am getting this error. Is code correct or I am doing something wrong.