【问题标题】:how to read the keyusage of a X509 V3 certificate?如何读取 X509 V3 证书的密钥用法?
【发布时间】:2012-04-16 23:34:18
【问题描述】:

我想读取证书中的密钥用法字段。openssl 中有可用的 API 吗?

【问题讨论】:

标签: openssl x509 digital-certificate


【解决方案1】:

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

openssl x509 -in <certificate to check> -purpose -noout -text

这将打印出证书用途列表和证书本身。

【讨论】:

  • 我需要在 c 代码中得到它.. 谢谢你的评论。我会检查这个命令的源代码
【解决方案2】:

7 年后...

较新版本的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

【讨论】:

    【解决方案3】:

    您需要在结果文件中找到之前的解决方案/输出字符串“Key Usage”。 我得到了以下解决方案,它在 Key Usage X509 证书中准确地引入了字符串。

    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 上此特定字段的值。

    //干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      相关资源
      最近更新 更多