2016-11-11 45 views
2

我正在使用OpenSSL創建第三方應用程序,爲嵌入式系統創建新的證書撤銷列表。 這裏是我的代碼在OpenSSL中創建新CRL的問題

crl = X509_CRL_new(); 

    X509_CRL_set_version(crl, CRL_VERSION); 

    X509_NAME *id = X509_NAME_new(); 
    X509_NAME_add_entry_by_txt(id, "C", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_COUNTRY, -1, -1, 0); 
    X509_NAME_add_entry_by_txt(id, "ST", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_STATE, -1, -1, 0); 
    X509_NAME_add_entry_by_txt(id, "L", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_COUNTRY, -1, -1, 0); 
    X509_NAME_add_entry_by_txt(id, "O", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_ORGANIZATION, -1, -1, 0); 
    X509_NAME_add_entry_by_txt(id, "OU", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_ORGANIZATIONAL_UNIT, -1, -1, 0); 
    X509_NAME_add_entry_by_txt(id, "CN", MBSTRING_ASC, (const unsigned char*) CRL_ISSUER_COMMON_NAME, -1, -1, 0); 

    X509_CRL_set_issuer_name(crl, id); 

    X509_CRL_set_lastUpdate(crl, tmptm); 

    char filename[50]; 
    strcpy(filename, RW_CRL_LOCATION); 
    strcat(filename, "crl.pem"); 

    fPointer = fopen(filename, "w+"); 
    result = PEM_write_X509_CRL(fPointer, clr); 

當我運行這個它會創建一個CRL文件,當我嘗試閱讀它使用OpenSSL的命令,它無法加載

OpenSSL 1.0.2d 9 Jul 2015 
[email protected]:/vp/test/crl# 
[email protected]:/vp/test/crl# openssl crl -in crl.pem -noout -text 
unable to load CRL 
1995560144:error:0D0C40D8:asn1 encoding routines:c2i_ASN1_OBJECT:invalid object encoding:a_object.c:283: 
1995560144:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:694:Field=algorithm, Type=X509_ALGOR 
1995560144:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:694:Field=sig_alg, Type=X509_CRL_INFO 
1995560144:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:694:Field=crl, Type=X509_CRL 
1995560144:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:pem_oth.c:83: 

但是當我編譯並運行相同在我的32位的Linux PC的代碼,並嘗試打開創建的CRL文件,它的工作原理

OpenSSL 1.0.1f 6 Jan 2014 
[email protected]:~/openssl-testing/code/crl$ openssl crl -in crl.pem -noout -text 
Certificate Revocation List (CRL): 
    Version 3 (0x2) 
Signature Algorithm: itu-t 
    Issuer: /C=SL/L=SL/O=VIVOPAY/OU=PISCES 
    Last Update: Nov 11 05:44:25 2016 GMT 
    Next Update: NONE 
No Revoked Certificates. 
Signature Algorithm: itu-t 

然後複製使用我的電腦到嵌入式文件系統的CRL文件創建,並試圖打開它那裏,它工作得很好。並將嵌入式系統創建的crl複製到PC並試圖打開,失敗。 任何人都可以幫我解決這個問題嗎?

+0

您可能編譯了32位體系結構的代碼。所以在PC上(我猜64位)不起作用。 – LPs

+0

啊好的我會補充,沒有我編譯和測試在這兩個架構 – thilinaur

+1

@ThilinaRathnasooriya - 如果*** _是_ ***真的PEM,然後'文件crl.pem'將返回'ASCII'。如果它返回'binary',那麼它的DER。嘗試將'-inform'選項添加到'openssl crl -in crl.pem -noout -text'。使用PEM或DER:'-inform DER'或'-inform PEM'。另請參閱['openssl crl'手冊頁](https://www.openssl.org/docs/man1.1.0/apps/crl.html)。 – jww

回答

0

遲到了,但我終於明白了:你沒有簽署CRL。簽名填寫兩個算法字段以及實際簽名; 1.0.1解碼中的兩行Signature Algorithm: itu-t是一箇舊的缺陷(或者至少是錯誤的特徵),因爲缺失/空的OID'解碼'爲itu-t,因爲它被分配了頂部弧0. 0,1.2顯然更嚴格並且被捕獲。

致電X509_CRL_signX509_CRL_sign_ctx每個系統上的手冊頁or on the web here