-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
68 lines (61 loc) · 1.79 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
//"crypto/tls"
//"github.com/cetcxinlian/cryptogm/tls"
//"crypto/x509"
//"github.com/cetcxinlian/cryptogm/x509"
"github.com/Hyperledger-TWGC/ccs-gm/tls"
"github.com/Hyperledger-TWGC/ccs-gm/x509"
"fmt"
"io/ioutil"
"github.com/Hyperledger-TWGC/net-go-gm/http"
)
func main() {
pool := x509.NewCertPool()
//caCertPath := "./assets/client/tls/ca.crt"
//clientCrt := "./assets/client/tls/client.crt"
//clientKey := "./assets/client/tls/client.key"
//gmssl
//caCertPath := "./assets/client/gmtls/ca.crt"
//clientCrt := "./assets/client/gmtls/client.crt"
//clientKey := "./assets/client/gmtls/client.key"
//tassl
caCertPath := "./assets/tasslcerts/CA.crt"
clientCrt := "./assets/tasslcerts/Client.crt"
clientKey := "./assets/tasslcerts/Client.key"
//su
//caCertPath := "./assets/sudouble-cert/client_ca.crt"
//clientCrt := "./assets/sudouble-cert/client_sign.crt"
//clientKey := "./assets/sudouble-cert/client_sign.key"
//testcryptogen
//caCertPath := "./assets/testcryptogen/tlsuser/ca.crt"
//clientCrt := "./assets/testcryptogen/tlsuser/client.crt"
//clientKey := "./assets/testcryptogen/tlsuser/client.key"
caCrt, err := ioutil.ReadFile(caCertPath)
if err != nil {
fmt.Println("Readfile Err", err)
return
}
pool.AppendCertsFromPEM(caCrt)
cliCrt, err := tls.LoadX509KeyPair(clientCrt, clientKey)
if err != nil {
fmt.Println("Loadx509keypair err", err)
return
}
tr := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: pool,
Certificates: []tls.Certificate{cliCrt},
GMSupport: &tls.GMSupport{},
},
}
client := &http.Client{Transport: tr}
resp, err := client.Get("https://localhost:8081")
if err != nil {
fmt.Println("error", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}