Skip to content

Commit

Permalink
feat: add tls config for mTLS
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalvas committed Aug 2, 2023
1 parent 74afd51 commit b2639c7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tlskit/tls_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tlskit

import (
"crypto/tls"
"crypto/x509"
"os"
)

func CreateTLSConfiguration(certFile, keyFile, caFile string, verifyTLS bool) (*tls.Config, error) {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return nil, err
}

caCert, err := os.ReadFile(caFile)
if err != nil {
return nil, err
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

conf := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
InsecureSkipVerify: verifyTLS,
}

return conf, nil
}

0 comments on commit b2639c7

Please sign in to comment.