在OpenSSL中的证书验证期间无法执行CRL检查

时间:2014-06-20 06:42:14

标签: ssl openssl certificate x509certificate x509

我正在尝试使用带有CRL检查的OpenSSL执行证书验证。

我可以使用命令提示符同时使用下面提到的命令 -

1. openssl verify -crl_check  -CAfile CA_crl.pem recipient_cert.pem

2. openssl verify -crl_check -CRLfile crls.pem -CAfile CA.pem mycert.pem

在第一个命令中,CA_crl.pem包含CA证书和CRL内容。 在第二个命令中,CA和CRL在不同的文件中提到。

现在我想使用C代码执行相同的操作。我参考了以下链接,但我一直从X509_verify_cert获得返回值0,没有错误代码给出任何提示。

http://etutorials.org/Programming/secure+programming/Chapter+10.+Public+Key+Infrastructure/10.5+Performing+X.509+Certificate+Verification+with+OpenSSL/

指出我的错误?

更新1:

我正在尝试不同的方法。这是我的代码。现在我从X509_verify_cert获得了返回值1但我应该收到CRL has expired错误的错误代码12。

这是我现在的代码 -

void printError() {
    __android_log_print(ANDROID_LOG_DEBUG, "OpenSSLJni", "\nPrinting Errors");
    long err = ERR_get_error();
    while (err != 0 ) {
        char buf[130];
        char* ptr = ERR_error_string(err, buf);
        __android_log_print(ANDROID_LOG_DEBUG, "OpenSSLJni", "\nError from buffer: %s", buf);
        err = ERR_get_error();
    }
}

//验证码开始。

X509* x509 = initialised;
STACK_OF(X509) *certs = initialised;
char* CAfile = initialised;

X509_STORE *cert_ctx=X509_STORE_new();
    if (cert_ctx == NULL) {
        return 0;
    }
    X509_STORE_set_verify_cb(cert_ctx,cb);

    X509_LOOKUP *lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());

    if (CAfile) {
        i=X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM);
        if(!i) {
            __android_log_print(ANDROID_LOG_DEBUG, "OpenSSLJni", "\nError loading file %s\n", CAfile);
            //BIO_printf(bio_err, "Error loading file %s\n", CAfile);
            //ERR_print_errors(bio_err);
            //goto end;
        }
    } else {
        X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);

    }

    X509_STORE_CTX *csc = X509_STORE_CTX_new();
    if (csc != NULL) {
        X509_STORE_set_flags(cert_ctx, X509_V_FLAG_CRL_CHECK);
        if(X509_STORE_CTX_init(csc, cert_ctx, x509, certs)) {
            X509_STORE_CTX_set_flags(csc, X509_V_FLAG_CRL_CHECK);
            __android_log_print(ANDROID_LOG_DEBUG, "OpenSSLJni", "\nCalling X509_verify_cert");
            int i = X509_verify_cert(csc);
            int ret = 0;
            if (i > 0)
            {
                ret=1;
            }

            __android_log_print(ANDROID_LOG_DEBUG, "OpenSSLJni", "\nReturn Value: %d", i);
            printError();

            return(ret);
        }
    }

0 个答案:

没有答案
相关问题