我正在使用 openssl (v.1.0.1k) 编写一个库,以根据颁发者证书和吊销列表验证证书。我的第一步是验证 CLR 来自发行人。我已验证证书和 CLR 已正确生成并使用以下命令行进行验证:
openssl crl -issuer -inform PEM -in root.crl.pem -noout -CAfile master_ca.crt
verify OK ...
然而!我无法使用 X509_CRL_verify() 进行 CRL 验证。它总是报告:“期待:证书”
ERR_get_error() 的输出:
140239350716336:error:0906D06C:lib(9):func(109):reason(108):pem_lib.c:703:Expecting: CERTIFICATE
140239350716336:error:0D0C50A1:lib(13):func(197):reason(161):a_verify.c:200:
我想知道它是否有问题,因为我的证书是“受信任的”证书。我必须使用 PEM_read_bio_x509_AUX() 而不是普通的 PEM_read_bio_x509() 来加载证书。在验证受信任的证书之前,我还需要做些什么吗?
这是验证码:
int verifyCRL( X509_CRL* crl, EVP_PKEY* issuer )
{
int rv = 0;
if ( issuer != NULL )
{
if ( X509_CRL_verify( crl,issuer ) == 1 )
{
log_msg( 5, "CRL verify.. OK" );
rv = 1;
}
else
{
log_msg( 0, "CRL verify.. FAILED" );
print_ssl_errors();
}
}
这是颁发者证书:
-----BEGIN TRUSTED CERTIFICATE-----
MIIDHjCCAoegAwIBAgIJAIEOyY6V3s6CMA0GCSqGSIb3DQEBDQUAMIGfMQswCQYD
VQQGEwJVUzELMAkGA1UECAwCVVQxFzAVBgNVBAcMDlBsZWFzYW50IEdyb3ZlMSUw
IwYDVQQKDBxNYXN0ZXIgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MRIwEAYDVQQLDAlN
YXN0ZXIgQ0ExETAPBgNVBAMMCHRlc3QuY29tMRwwGgYJKoZIhvcNAQkBFg1mcmVk
QHRlc3QuY29tMB4XDTE1MTIxMTIyNTU0MloXDTI1MTIwODIyNTU0MlowgZ8xCzAJ
BgNVBAYTAlVTMQswCQYDVQQIDAJVVDEXMBUGA1UEBwwOUGxlYXNhbnQgR3JvdmUx
JTAjBgNVBAoMHE1hc3RlciBDZXJ0aWZpY2F0ZSBBdXRob3JpdH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UFiB1aW87egynsc
TZycZMgXUjXJhJq2825e274PX77pd00/yUYezom1X6HYuwRHTJj6/25QPm25lrXL
cy84aeLJgJMcKR79oHe0252Bo1y6a2VKgMet3/m58u2opNVOM4pPYh5FSPd2UgWw
//D3L6/+3wwQrDMj8kEbaJZi
-----END X509 CRL-----
哦,是的,我已经初始化了 openssl 堆栈:
SSL_load_error_strings();
SSL_library_init();libraries
OpenSSL_add_all_algorithms();
谢谢!