@@ -89,20 +89,34 @@ func NewTLSConfig(ctx context.Context, config *Config, tlsType TLSType) (*tls.Co
89
89
90
90
tlsConfig .RootCAs = rootCAs
91
91
92
+ var configuredCert * tls.Certificate
92
93
// For mTLS we need both the cert and key
93
94
if config .CertFile != "" && config .KeyFile != "" {
94
95
// Read the key pair to create certificate
95
96
cert , err := tls .LoadX509KeyPair (config .CertFile , config .KeyFile )
96
97
if err != nil {
97
98
return nil , i18n .WrapError (ctx , err , i18n .MsgInvalidKeyPairFiles )
98
99
}
99
- tlsConfig . Certificates = []tls. Certificate { cert }
100
+ configuredCert = & cert
100
101
} else if config .Cert != "" && config .Key != "" {
101
102
cert , err := tls .X509KeyPair ([]byte (config .Cert ), []byte (config .Key ))
102
103
if err != nil {
103
104
return nil , i18n .WrapError (ctx , err , i18n .MsgInvalidKeyPairFiles )
104
105
}
105
- tlsConfig .Certificates = []tls.Certificate {cert }
106
+ configuredCert = & cert
107
+ }
108
+
109
+ if configuredCert != nil {
110
+ // Rather than letting Golang pick a certificate it thinks matches from the list of one,
111
+ // we directly supply it the one we have in all cases.
112
+ tlsConfig .GetClientCertificate = func (_ * tls.CertificateRequestInfo ) (* tls.Certificate , error ) {
113
+ log .L (ctx ).Debugf ("Supplying client certificate" )
114
+ return configuredCert , nil
115
+ }
116
+ tlsConfig .GetCertificate = func (_ * tls.ClientHelloInfo ) (* tls.Certificate , error ) {
117
+ log .L (ctx ).Debugf ("Supplying server certificate" )
118
+ return configuredCert , nil
119
+ }
106
120
}
107
121
108
122
if tlsType == ServerType {
0 commit comments