Openssl

如何使用 OpenSSL 實用程序從 x509 證書中提取 CRL 位置

  • September 28, 2018

我需要從證書頒發機構提取 crl 位置,以便可以使用它來驗證證書。除了使用該選項並嘗試解析輸出(這似乎容易出現漏洞)之外,這是否可以使用該openssl實用程序?-text

openssl x509有一些開關來控制輸出的格式,並且可以不顯示某些欄位,但似乎無法僅獲取 CRL 位置。

看來您一定會解析輸出。

仍然是一種解析,但至少比 with 更精確x509。它需要改進以更好地考慮列表,對於cut -b21-簡單的 1 元素列表來說,這確實是一種捷徑。

openssl asn1parse -in whatever.crt | grep -A 1 'X509v3 CRL Distribution Points' | tail -1 | cut -d: -f 4 | cut -b21- | perl -ne 's/(..)/print chr(hex($1))/ge; END {print "\n"}'
http://cdp.rapidssl.com/RapidSSLTLSRSACAG1.crl

相比:

openssl x509 -text -in whatever.crt |grep -A4 'CRL Distribution Points'
       X509v3 CRL Distribution Points:

           Full Name:
             URI:http://cdp.rapidssl.com/RapidSSLTLSRSACAG1.crl

或者使用任何一種程式語言,您可能會得到一些接近的東西,具體取決於底層庫為您解碼的程度:

php -r '$cert = file_get_contents("whatever.crt"); $ssl = openssl_x509_parse($cert); print_r($ssl["extensions"]["crlDistributionPoints"]);'

Full Name:
 URI:http://cdp.rapidssl.com/RapidSSLTLSRSACAG1.crl

引用自:https://serverfault.com/questions/405402