Search code examples
c++sslopenssldigital-certificate

PEM_read_X509 not reading entire certifcate


I am using PEM_read_X509 API to read a certificate. The certificate file contains 2 set of certificate contents,

-----BEGIN CERTIFICATE-----
****<certificate content>****
 -----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
*****<certificate content>****
 -----END CERTIFICATE-----

The issue is PEM_read_X509 read only first cert and not reading the second certificate. I think the API will stop reading the certificate when it encounters -----END CERTIFICATE-----

Can anyone help on this...?


Solution

  •  X509* x;
     while(x = PEM_read_X509(file, NULL, NULL, NULL))
            X509_print_fp(stdout, x);