-
-
Save pmtabe1/d51b86b41705bc1003324f34562cfcb7 to your computer and use it in GitHub Desktop.
Revisions
-
michaljemala renamed this gist
Jan 28, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
michaljemala revised this gist
May 28, 2014 . 1 changed file with 17 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,16 +2,17 @@ package main import ( "crypto/tls" "crypto/x509" "flag" "io/ioutil" "log" "net/http" ) var ( certFile = flag.String("cert", "someCertFile", "A PEM eoncoded certificate file.") keyFile = flag.String("key", "someKeyFile", "A PEM encoded private key file.") caFile = flag.String("CA", "someCertCAFile", "A PEM eoncoded CA's certificate file.") ) func main() { @@ -23,13 +24,25 @@ func main() { log.Fatal(err) } // Load CA cert caCert, err := ioutil.ReadFile(*caFile) if err != nil { log.Fatal(err) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) // Setup HTTPS client tlsConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, RootCAs: caCertPool, } tlsConfig.BuildNameToCertificate() transport := &http.Transport{TLSClientConfig: tlsConfig} client := &http.Client{Transport: transport} // Do GET something resp, err := client.Get("https://goldportugal.local:8443") if err != nil { log.Fatal(err) } -
michaljemala created this gist
May 26, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ package main import ( "crypto/tls" "flag" "io/ioutil" "log" "net/http" "os" ) var ( certFile = flag.String("cert", "someCertFile", "A PEM eoncoded certificate file.") keyFile = flag.String("key", "someKeyFile", "A PEM encoded private key file.") ) func main() { flag.Parse() // Load client cert cert, err := tls.LoadX509KeyPair(*certFile, *keyFile) if err != nil { log.Fatal(err) } // Setup HTTP client tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true} transport := &http.Transport{TLSClientConfig: tlsConfig} client := &http.Client{Transport: transport} // Do GET something resp, err := client.Get("https://localhost:8443") 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)) }