我有多个证书链,我想根据放在目录中的多个CRL文件来验证它们。
这是我尝试过的示例代码。我对openssl很新,我不确定这段代码是否用CRL验证所有证书(整个链)。
X509_STORE* store = X509_STORE_new();
X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK_ALL);
for each chain
{
STACK_OF(X509*) stack = sk_X509_new_null();
for(int index=0; cert_chain[index] != NULL; index++)
{
if(cert_chain[index]->type == 0)
{
//EE cert
eecert = cert_chain[index]->cert;
}
else
{
sk_X509_push(stack, cert_chain[index]->cert);
//get crl matching issuer
X509_Name* issuer = getIssuer(cert_chain[index]->cert);
X509_CRL* crl = getCRL(issuer);
//Any best way to add multiple crls at once or add location?
X509_STORE_add_crl(store, crl);
}
}
X509_STORE_CTX *store_ctx = X509_STORE_CTX_new();
X509_STORE_CTX_init(store_ctx, store, NULL, NULL);
X509_STORE_CTX_set_chain(ctx, stack);
X509_STORE_CTX_set_cert(store_ctx, eecert);
X509_verify_cert(store_ctx);
}