如何阅读X509 V3证书的关键词?

Bal*_*gan 4 openssl digital-certificate x509

我想阅读证书中的密钥用法字段.在openssl中是否有API可用?

小智 11

您可以尝试在openssl中使用以下命令.

openssl x509 -in <certificate to check> -purpose -noout -text
Run Code Online (Sandbox Code Playgroud)

这将打印出证书目的列表和证书本身.


Yan*_*oto 10

7年后...

较新版本openssl允许您使用标志查询证书扩展-ext。请参阅文档了解可用选项。

打印密钥用法

$> openssl x509 -noout -ext keyUsage < test.crt
X509v3 Key Usage: critical
    Digital Signature, Key Encipherment
Run Code Online (Sandbox Code Playgroud)

打印扩展密钥用法

$> openssl x509 -noout -ext extendedKeyUsage < test.crt
X509v3 Extended Key Usage: 
    TLS Web Server Authentication, TLS Web Client Authentication
Run Code Online (Sandbox Code Playgroud)

请注意,如果要一次打印多个扩展名,则需要用逗号分隔,而不是-ext多次使用 flag:

$> openssl x509 -noout \
   -ext keyUsage,extendedKeyUsage < test.crt
Run Code Online (Sandbox Code Playgroud)