AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1834911
Accepted
FireEmerald
FireEmerald
Asked: 2024-03-13 16:58:12 +0800 CST2024-03-13 16:58:12 +0800 CST 2024-03-13 16:58:12 +0800 CST

如何获取 X509 主题字段中使用的编码类型?

  • 772

RFC 5280中写道,例如X520OrganizationName可以使用以下编码之一:

X520OrganizationName ::= CHOICE {
      teletexString     TeletexString
                          (SIZE (1..ub-organization-name)),
      printableString   PrintableString
                          (SIZE (1..ub-organization-name)),
      universalString   UniversalString
                          (SIZE (1..ub-organization-name)),
      utf8String        UTF8String
                          (SIZE (1..ub-organization-name)),
      bmpString         BMPString
                          (SIZE (1..ub-organization-name))  }

如何查找给定 X509 证书中使用的编码?有没有openssl命令或者类似的软件?

certificate
  • 2 2 个回答
  • 196 Views

2 个回答

  • Voted
  1. Best Answer
    u1686_grawity
    2024-03-13T17:17:37+08:002024-03-13T17:17:37+08:00

    使用ASN.1 DER解码器软件:

    • OpenSSL:openssl asn1parse -i -in Foo.crt

      (asn1parse 需要 Base64“PEM”格式,就像大多数其他 openssl 子命令一样,但您可以使用-inform DER它来为其提供二进制格式的证书。)

    • P.Gutmann 的 dumpasn1:dumpasn1 Foo.der

      (dumpasn1 需要二进制(非 Base64)格式。使用openssl x509 -in Foo.crt -out Foo.der -outform DER甚至使用将证书转换为二进制 DER base64 -d。)

    • asn1.js(在线): https: //lapo.it/asn1js/

      (另一个类似的版本位于https://pkitools.net/pages/ca/asn1.html)

    主题 DN 是证书中的第一个字段(前 在两个时间戳之后– 发行者 DN 是后在时间戳之前);它被表示为一个“序列”,每个 RDN 都是一个“集合”(通常有一个元素,但格式允许多个,例如CN=this+UID=that,OU=etc,O=etc)。

    例如:

    $ openssl x509 -outform DER -in Telia_Root_CA_v2.pem -out /tmp/telia.crt
    $ dumpasn1 /tmp/telia.crt
      第01396章
      4 860:序列{
      8 3: [0] {                          ← 版本 (X.509 v3)
     10 1:整数 2
            : }                            ↙ 序列号
     13 15:整数 01 67 5F 27 D6 FE 7A E3 E4 AC BE 09 5B 05 9E
     30 13:序列 {                     ← 算法
     32 9:对象标识符 sha256WithRSA 加密 (1 2 840 113549 1 1 11)
     43 0:空
            : }
     45 68:序列 {                     ←主题发行人 DN 从此处开始
     47 11:设置{
     49 9:序列{
     51 3:对象标识符国家/地区名称 (2 5 4 6)
     56 2:可打印字符串“FI”
            : }
            : }
     60 26:        SET {                        ← 'O=...' RDN 
     62 24:          SEQUENCE {                 ← RDN 的 'O=...' 元素
     64 3:           对象标识符 组织名称 (2 5 4 0) 
     69 17:            UTF8String ' Telia 芬兰 Oyj' 
            :            } 
            :          }
     88 25:设置{
     90 23:序列{
     92 3:对象标识符通用名称 (2 5 4 3)
     97 16:UTF8String 'Telia 根 CA v2'
            : }
            : }
            : }
    115 30:序列{
    117 13: UTC 时间 2018 年 11 月 29 日 11:55:54 GMT
    
    • 4
  2. dave_thompson_085
    2024-03-14T11:21:43+08:002024-03-14T11:21:43+08:00

    使用 OpenSSL 的更具体且更易于阅读的方法:

    openssl x509 {<file | -in file} -noout -subject -nameopt oneline,show_type
    # change -subject to -issuer (or use both!) if applicable 
    # if DN is long or complex enough that single-line is hard to read 
    # change oneline to multiline 
    
    # for the cert currently used by www.example.com:
    
    $ openssl x509 <temp -noout -subject # default does not show types
    subject=C = US, ST = California, L = Los Angeles, O = Internet\C2\A0Corporation\C2\A0for\C2\A0Assigned\C2\A0Names\C2\A0and\C2\A0Numbers, CN = www.example.org
    
    $ openssl x509 <temp -noout -subject -nameopt oneline,show_type
    subject=C = PRINTABLESTRING:US, ST = PRINTABLESTRING:California, L = PRINTABLESTRING:Los Angeles, O = UTF8STRING:Internet\C2\A0Corporation\C2\A0for\C2\A0Assigned\C2\A0Names\C2\A0and\C2\A0Numbers, CN = PRINTABLESTRING:www.example.org
    
    $ openssl x509 <temp -noout -subject -nameopt multiline,show_type
    subject=
        countryName               = PRINTABLESTRING:US
        stateOrProvinceName       = PRINTABLESTRING:California
        localityName              = PRINTABLESTRING:Los Angeles
        organizationName          = UTF8STRING:Internet\A0Corporation\A0for\A0Assigned\A0Names\A0and\A0Numbers
        commonName                = PRINTABLESTRING:www.example.org
    $
    

    在旧版本的 OpenSSL 中,默认格式是 PEM,如果适用,您必须指定-inform DER(或缩写)。-inform d然而,在 3.0.0 及以上版本(现在是唯一支持上游的版本)中,大多数命令包括x509自动接受 PEM 或 DER 形式的输入。(asn1parse不会,因为与其他命令不同,它不查看甚至不需要 PEM 标签行;它的“PEM”格式实际上接受任何base64,除非您指定新选项-strictpem。有时这很有用,有时没有。)

    • 1

相关问题

  • Mac OS X 钥匙串证书“成员:VERY_LONG_GUID”

  • 让我们加密更新失败

  • 如何将自签名 SSL 证书添加到 Linux (Ubuntu/Alpine) 信任库?

  • 无法根据自签名 openssl 证书验证 openssl 证书?

  • 如何设置 DNS、AWS S3、AWS Cloudfront 和 AWS Certificate Manager 以保护多个站点

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve