@@ -752,7 +752,8 @@ func (c *ClientOptions) SetTimeout(d time.Duration) *ClientOptions {
752
752
// "tlsPrivateKeyFile". The "tlsCertificateKeyFile" option specifies a path to the client certificate and private key,
753
753
// which must be concatenated into one file. The "tlsCertificateFile" and "tlsPrivateKey" combination specifies separate
754
754
// paths to the client certificate and private key, respectively. Note that if "tlsCertificateKeyFile" is used, the
755
- // other two options must not be specified.
755
+ // other two options must not be specified. Only the subject name of the first certificate is honored as the username
756
+ // for X509 auth in a file with multiple certs.
756
757
//
757
758
// 3. "tlsCertificateKeyFilePassword" (or "sslClientCertificateKeyPassword"): Specify the password to decrypt the client
758
759
// private key file (e.g. "tlsCertificateKeyFilePassword=password").
@@ -1049,8 +1050,8 @@ func addClientCertFromConcatenatedFile(cfg *tls.Config, certKeyFile, keyPassword
1049
1050
return addClientCertFromBytes (cfg , data , keyPassword )
1050
1051
}
1051
1052
1052
- // addClientCertFromBytes adds a client certificate to the configuration given a path to the
1053
- // containing file and returns the certificate's subject name.
1053
+ // addClientCertFromBytes adds client certificates to the configuration given a path to the
1054
+ // containing file and returns the subject name in the first certificate .
1054
1055
func addClientCertFromBytes (cfg * tls.Config , data []byte , keyPasswd string ) (string , error ) {
1055
1056
var currentBlock * pem.Block
1056
1057
var certDecodedBlock []byte
@@ -1067,7 +1068,11 @@ func addClientCertFromBytes(cfg *tls.Config, data []byte, keyPasswd string) (str
1067
1068
if currentBlock .Type == "CERTIFICATE" {
1068
1069
certBlock := data [start : len (data )- len (remaining )]
1069
1070
certBlocks = append (certBlocks , certBlock )
1070
- certDecodedBlock = currentBlock .Bytes
1071
+ // Assign the certDecodedBlock when it is never set,
1072
+ // so only the first certificate is honored in a file with multiple certs.
1073
+ if certDecodedBlock == nil {
1074
+ certDecodedBlock = currentBlock .Bytes
1075
+ }
1071
1076
start += len (certBlock )
1072
1077
} else if strings .HasSuffix (currentBlock .Type , "PRIVATE KEY" ) {
1073
1078
isEncrypted := x509 .IsEncryptedPEMBlock (currentBlock ) || strings .Contains (currentBlock .Type , "ENCRYPTED PRIVATE KEY" )
0 commit comments