30 lines
557 B
Go
30 lines
557 B
Go
package tlsutil
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"io/ioutil"
|
|
)
|
|
|
|
func GRPCTLSConfig() (*tls.Config, error) {
|
|
cert, err := tls.LoadX509KeyPair("certs/server.crt", "certs/server.key")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
caPEM, err := ioutil.ReadFile("certs/ca.crt")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
caPool := x509.NewCertPool()
|
|
caPool.AppendCertsFromPEM(caPEM)
|
|
|
|
return &tls.Config{
|
|
Certificates: []tls.Certificate{cert},
|
|
ClientCAs: caPool,
|
|
ClientAuth: tls.RequireAndVerifyClientCert,
|
|
MinVersion: tls.VersionTLS12,
|
|
}, nil
|
|
}
|