Using the client SSL certificate

If a remote HTTPS server has strict authentication and requires a trusted client certificate, you can specify the certificate file by setting the TLSClientConfig variable in the http.Transport object that is used by http.Client to make the GET request.

This example makes a HTTP GET request similar to the previous example, but it does not use the default HTTP client provided by the net/http package. It creates a custom http.Client and configures it to use TLS with the client certificate. If you need a certificate or private key, refer to Chapter 6, Cryptography, for examples of generating keys and self-signed certificates:

package mainimport (   "crypto/tls"   "log"   "net/http")func main() {   // Load cert cert, err ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.