Initial commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user