简体   繁体   中英

C++/OpenSSL load PEM into STACK_OF(X509)

I'm loading a PEM in a BIO (from a file OR from user input directly). This PEM can contain 1 to N certificates stacked.

I can't find a function that give me a STACK_OF(X509*) from my bio, like PEM_read_bio_X509 does for a single X509* .

Does such a function exist ? If it doesn't , could i get the same result in another way ?

Here is the relevant part from the link @Reinier Torenbeek provided:

STACK_OF(X509_INFO) *certstack;
const char ca_filestr[] = "./cabundle.pem";

stackbio = BIO_new(BIO_s_file());
outbio   = BIO_new_fp(stdout, BIO_NOCLOSE);

/* ---------------------------------------------------------- *
 * Load the file with the list of certificates in PEM format  *
 * ---------------------------------------------------------- */
if (BIO_read_filename(stackbio, ca_filestr) <= 0) {
    BIO_printf(outbio, "Error loading cert bundle into memory\n");
    exit(-1);
}

certstack = PEM_X509_INFO_read_bio(stackbio, NULL, NULL, NULL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM