60 lines
999 B
Go
60 lines
999 B
Go
package main
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
fmt.Printf("Usage: %s URL\n", filepath.Base(os.Args[0]))
|
|
return
|
|
}
|
|
URL := os.Args[1]
|
|
|
|
caCert, err := ioutil.ReadFile("server.crt")
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
caCertPool := x509.NewCertPool()
|
|
caCertPool.AppendCertsFromPEM(caCert)
|
|
cert, err := tls.LoadX509KeyPair("client.crt", "client.key")
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
client := &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: &tls.Config{
|
|
RootCAs: caCertPool,
|
|
InsecureSkipVerify: true,
|
|
Certificates: []tls.Certificate{cert},
|
|
},
|
|
},
|
|
}
|
|
|
|
resp, err := client.Get(URL)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
htmlData, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
fmt.Printf("%v\n", resp.Status)
|
|
fmt.Printf(string(htmlData))
|
|
}
|