首页 > 解决方案 > C++/OpenSSL 将 PEM 加载到 STACK_OF(X509)

问题描述

我正在加载一个PEMBIO从文件或直接从用户输入)。此 PEM 可以包含堆叠的 1 到 N 个证书。

我找不到可以STACK_OF(X509*)从我的简历PEM_read_bio_X509中获得 a 的功能,就像单个X509*.

这样的功能存在吗?如果没有,我可以用另一种方式得到相同的结果吗?

标签: c++openssl

解决方案


以下是@Reinier Torenbeek 提供的链接中的相关部分:

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);

推荐阅读