-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
67 lines (59 loc) · 1.7 KB
/
server.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
package main
import (
//"crypto/tls"
"github.com/Hyperledger-TWGC/ccs-gm/tls"
"fmt"
//"github.com/cetcxinlian/cryptogm/tls"
//"crypto/x509"
//"github.com/cetcxinlian/cryptogm/x509"
"github.com/Hyperledger-TWGC/ccs-gm/x509"
"github.com/Hyperledger-TWGC/net-go-gm/http"
"io/ioutil"
)
type myhandler struct {
}
func (h *myhandler) ServeHTTP(w http.ResponseWriter,
r *http.Request) {
fmt.Fprintf(w,
"Hi, This is an example of http service in golang!\n")
}
func main(){
pool := x509.NewCertPool()
//caCart := "./assets/server/tls/ca.crt"
//serverCrt := "./assets/server/tls/server.crt"
//serverKey := "./assets/server/tls/server.key"
//gmssl
//caCart := "./assets/server/gmtls/ca.crt"
//serverCrt := "./assets/server/gmtls/server.crt"
//serverKey := "./assets/server/gmtls/server.key"
//tassl
caCart := "./assets/tasslcerts/CA.crt"
serverCrt := "./assets/tasslcerts/Server.crt"
serverKey := "./assets/tasslcerts/Server.key"
//su
//caCart := "./assets/sudouble-cert/server_ca.crt"
//serverCrt := "./assets/sudouble-cert/server_sign.crt"
//serverKey := "./assets/sudouble-cert/server_sign.key"
//testcryptogen
//caCart := "./assets/testcryptogen/tlspeer0/ca.crt"
//serverCrt := "./assets/testcryptogen/tlspeer0/server.crt"
//serverKey := "./assets/testcryptogen/tlspeer0/server.key"
caCrt ,err := ioutil.ReadFile(caCart)
if err != nil {
fmt.Println("read err", err)
return
}
pool.AppendCertsFromPEM(caCrt)
s := &http.Server{
Addr: "localhost:8081",
Handler: &myhandler{},
TLSConfig: &tls.Config{
ClientCAs: pool,
ClientAuth: tls.RequireAndVerifyClientCert,
},
}
err = s.ListenAndServeTLS(serverCrt, serverKey)
if err != nil {
fmt.Println("ListenAndServeTLS err:", err)
}
}