我想读取证书中的密钥用途字段。在openssl中是否有可用的API?
我想读取证书中的密钥用途字段。在openssl中是否有可用的API?
openssl x509 -in <certificate to check> -purpose -noout -text
这将打印出证书目的列表和证书本身。
这将打印出证书目的列表和证书本身。
openssl
可以使用-ext
标志查询证书扩展。有关可用选项,请参见文档。$> openssl x509 -noout -ext keyUsage < test.crt
X509v3 Key Usage: critical
Digital Signature, Key Encipherment
$> openssl x509 -noout -ext extendedKeyUsage < test.crt
X509v3 Extended Key Usage:
TLS Web Server Authentication, TLS Web Client Authentication
-ext
标志。$> openssl x509 -noout \
-ext keyUsage,extendedKeyUsage < test.crt
之前的解决方案需要在结果文件/输出中查找字符串“Key Usage”。 我有以下解决方案,可以精确地获取X509证书中“Key Usage”字符串。
openssl s_client -showcerts -connect SERVER_HERE:443 </dev/null 2>/dev/null|openssl x509 -text |grep v "$(grep -E -A1 "Key Usage")"
以上命令获取证书,解析为文本并查找字符串“Key Usage”,然后在结果中呈现下一行,该行表示X509上此特定字段的值。
//干杯