comment gateway-tls gateway creds

This commit is contained in:
finlab 2021-01-17 22:15:20 +08:00
parent 1a36d08a46
commit c56f6c1c12

View File

@ -54,29 +54,29 @@ func main() {
} }
} }
func gwCreds() credentials.TransportCredentials { // func gwCreds() credentials.TransportCredentials {
cert, err := tls.LoadX509KeyPair("./cert/server.pem", "./cert/server.key") // cert, err := tls.LoadX509KeyPair("./cert/server.pem", "./cert/server.key")
if err != nil { // if err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
certPool := x509.NewCertPool() // certPool := x509.NewCertPool()
ca, err := ioutil.ReadFile("./cert/ca.pem") // ca, err := ioutil.ReadFile("./cert/ca.pem")
if err != nil { // if err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
if ok := certPool.AppendCertsFromPEM(ca); !ok { // if ok := certPool.AppendCertsFromPEM(ca); !ok {
log.Fatal("failed to append certs") // log.Fatal("failed to append certs")
} // }
creds := credentials.NewTLS(&tls.Config{ // creds := credentials.NewTLS(&tls.Config{
Certificates: []tls.Certificate{cert}, // Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAndVerifyClientCert, // NOTE: this is optional! // ClientAuth: tls.RequireAndVerifyClientCert, // NOTE: this is optional!
ClientCAs: certPool, // ClientCAs: certPool,
}) // })
return creds // return creds
} // }
func grpcServerClientCreds() grpc.DialOption { func grpcServerClientCreds() grpc.DialOption {
cert, err := tls.LoadX509KeyPair("./cert/client.pem", "./cert/client.key") cert, err := tls.LoadX509KeyPair("./cert/client.pem", "./cert/client.key")