简体   繁体   English

OpenSSL C API:使用CRL进行证书链验证

[英]OpenSSL C API: Certificate chain validation with CRL

I'm trying to perform certificate chain validation for Windows executable files, which also includes check for revoked certificates, using OpenSSL 1.0.2 C API. 我正在尝试使用OpenSSL 1.0.2 C API对Windows可执行文件执行证书链验证,其中还包括检查已撤销的证书。

I have the CRL files stored locally and I want to load them during verification (as opposed to download the CRL via "CRL Distribution Points" URL from certificates which have it). 我将CRL文件存储在本地,我想在验证期间加载它们(而不是通过具有证书的证书通过“ CRL分发点” URL下载CRL)。

Here's my simplified example of loading a single CRL file (omitting any error checking): 这是我加载单个CRL文件的简化示例(省略任何错误检查):

X509_STORE *store = NULL;
X509_STORE_CTX *ctx = NULL;
X509_VERIFY_PARAM *params = NULL;

X509_CRL *crl = d2i_X509_CRL_fp(fc, NULL);  // fc is a file pointer to CRL file
X509_STORE_add_crl(store, crl);
X509_STORE_CTX_init(ctx, store, NULL, NULL);

params = X509_STORE_CTX_get0_param(ctx);
X509_VERIFY_PARAM_set_purpose(params, X509_PURPOSE_ANY);
X509_VERIFY_PARAM_set_flags(params, X509_V_FLAG_CRL_CHECK);  // only want to check end entity
X509_STORE_set1_param(store, params);

// assume p7 is properly initialized PKCS7*
// assume bio is properly initialized BIO*
int ret = PKCS7_verify(p7, p7->d.sign->cert, store, bio, NULL, 0);

Above code will return ret == 0 with error: unable to get certificate CRL , which from my understanding means that OpenSSL is still trying to search CRL from the certificate itself instead of using the one I load locally. 上面的代码将返回ret == 0 ,错误: unable to get certificate CRL ,据我了解,这意味着OpenSSL仍在尝试从证书本身中搜索CRL,而不是使用我在本地加载的证书。

What is the proper way of achieving this task? 完成这项任务的正确方法是什么?

Actually the code above is already correct to achieve my goal in performing CRL check. 实际上,上面的代码已经可以正确实现我执行CRL检查的目标。 One potential pitfall for someone new to X509 certificate structure is that the "CRL Distribution Points" URL for the certificate of interest is contained within that certificate itself, and not on the issuer's certificate . 对于X509证书结构新手来说,一个潜在的陷阱是, 感兴趣的证书的“ CRL分发点” URL包含在该证书本身中,而不在发行方的证书中 This was my mistake which led to the error I mentioned. 这是我的错误,导致了我提到的错误。 I hope this may help people who just get started in understanding the X509 standard. 我希望这可以帮助刚开始了解X509标准的人们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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