Make CA certificate optional in ClientTLSConfig
This commit is contained in:
parent
2dea5185b3
commit
9747c46e7b
|
@ -72,16 +72,19 @@ func GetCipherName(cipher uint16) (string, error) {
|
||||||
|
|
||||||
func ClientTLSConfig(caCert []byte, clientCert []byte, clientKey []byte) (*tls.Config, error) {
|
func ClientTLSConfig(caCert []byte, clientCert []byte, clientKey []byte) (*tls.Config, error) {
|
||||||
var tlsConfig *tls.Config
|
var tlsConfig *tls.Config
|
||||||
|
var pool *x509.CertPool
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case len(caCert) != 0 && len(clientCert) != 0 && len(clientKey) != 0:
|
case len(clientCert) != 0 && len(clientKey) != 0:
|
||||||
// Valid
|
// Valid
|
||||||
case len(caCert) != 0, len(clientCert) != 0, len(clientKey) != 0:
|
default:
|
||||||
return nil, ErrInvalidCertParams
|
return nil, ErrInvalidCertParams
|
||||||
}
|
}
|
||||||
|
|
||||||
pool := x509.NewCertPool()
|
if len(caCert) != 0 {
|
||||||
|
pool = x509.NewCertPool()
|
||||||
pool.AppendCertsFromPEM(caCert)
|
pool.AppendCertsFromPEM(caCert)
|
||||||
|
}
|
||||||
|
|
||||||
cert, err := tls.X509KeyPair(clientCert, clientKey)
|
cert, err := tls.X509KeyPair(clientCert, clientKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue