@@ -246,16 +246,26 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
246
246
if err != nil {
247
247
return nil , err
248
248
}
249
- block , _ := pem .Decode (certDataPEM )
250
- if block == nil || block .Type != "CERTIFICATE" {
251
- return nil , h .Errf ("no CERTIFICATE pem block found in %s" , h .Val ())
249
+ // while block is not nil, we have more certificates in the file
250
+ for block , rest := pem .Decode (certDataPEM ); block != nil ; block , rest = pem .Decode (rest ) {
251
+ if block .Type != "CERTIFICATE" {
252
+ return nil , h .Errf ("no CERTIFICATE pem block found in %s" , filename )
253
+ }
254
+ if subdir == "trusted_ca_cert_file" {
255
+ cp .ClientAuthentication .TrustedCACerts = append (
256
+ cp .ClientAuthentication .TrustedCACerts ,
257
+ base64 .StdEncoding .EncodeToString (block .Bytes ),
258
+ )
259
+ } else {
260
+ cp .ClientAuthentication .TrustedLeafCerts = append (
261
+ cp .ClientAuthentication .TrustedLeafCerts ,
262
+ base64 .StdEncoding .EncodeToString (block .Bytes ),
263
+ )
264
+ }
252
265
}
253
- if subdir == "trusted_ca_cert_file" {
254
- cp .ClientAuthentication .TrustedCACerts = append (cp .ClientAuthentication .TrustedCACerts ,
255
- base64 .StdEncoding .EncodeToString (block .Bytes ))
256
- } else {
257
- cp .ClientAuthentication .TrustedLeafCerts = append (cp .ClientAuthentication .TrustedLeafCerts ,
258
- base64 .StdEncoding .EncodeToString (block .Bytes ))
266
+ // if we decoded nothing, return an error
267
+ if len (cp .ClientAuthentication .TrustedCACerts ) == 0 && len (cp .ClientAuthentication .TrustedLeafCerts ) == 0 {
268
+ return nil , h .Errf ("no CERTIFICATE pem block found in %s" , filename )
259
269
}
260
270
261
271
default :
0 commit comments