@@ -1001,7 +1001,8 @@ func addClientCertFromConcatenatedFile(cfg *tls.Config, certKeyFile, keyPassword
1001
1001
// containing file and returns the certificate's subject name.
1002
1002
func addClientCertFromBytes (cfg * tls.Config , data []byte , keyPasswd string ) (string , error ) {
1003
1003
var currentBlock * pem.Block
1004
- var certBlock , certDecodedBlock , keyBlock []byte
1004
+ var certDecodedBlock []byte
1005
+ var certBlocks , keyBlocks [][]byte
1005
1006
1006
1007
remaining := data
1007
1008
start := 0
@@ -1012,7 +1013,8 @@ func addClientCertFromBytes(cfg *tls.Config, data []byte, keyPasswd string) (str
1012
1013
}
1013
1014
1014
1015
if currentBlock .Type == "CERTIFICATE" {
1015
- certBlock = data [start : len (data )- len (remaining )]
1016
+ certBlock := data [start : len (data )- len (remaining )]
1017
+ certBlocks = append (certBlocks , certBlock )
1016
1018
certDecodedBlock = currentBlock .Bytes
1017
1019
start += len (certBlock )
1018
1020
} else if strings .HasSuffix (currentBlock .Type , "PRIVATE KEY" ) {
@@ -1044,22 +1046,24 @@ func addClientCertFromBytes(cfg *tls.Config, data []byte, keyPasswd string) (str
1044
1046
}
1045
1047
var encoded bytes.Buffer
1046
1048
pem .Encode (& encoded , & pem.Block {Type : currentBlock .Type , Bytes : keyBytes })
1047
- keyBlock = encoded .Bytes ()
1049
+ keyBlock := encoded .Bytes ()
1050
+ keyBlocks = append (keyBlocks , keyBlock )
1048
1051
start = len (data ) - len (remaining )
1049
1052
} else {
1050
- keyBlock = data [start : len (data )- len (remaining )]
1053
+ keyBlock := data [start : len (data )- len (remaining )]
1054
+ keyBlocks = append (keyBlocks , keyBlock )
1051
1055
start += len (keyBlock )
1052
1056
}
1053
1057
}
1054
1058
}
1055
- if len (certBlock ) == 0 {
1059
+ if len (certBlocks ) == 0 {
1056
1060
return "" , fmt .Errorf ("failed to find CERTIFICATE" )
1057
1061
}
1058
- if len (keyBlock ) == 0 {
1062
+ if len (keyBlocks ) == 0 {
1059
1063
return "" , fmt .Errorf ("failed to find PRIVATE KEY" )
1060
1064
}
1061
1065
1062
- cert , err := tls .X509KeyPair (certBlock , keyBlock )
1066
+ cert , err := tls .X509KeyPair (bytes . Join ( certBlocks , [] byte ( " \n " )), bytes . Join ( keyBlocks , [] byte ( " \n " )) )
1063
1067
if err != nil {
1064
1068
return "" , err
1065
1069
}
0 commit comments