• Openssl X509 v3 AuthorityKeyIdentifier实验与逻辑分析


           Openssl是X509的事实标准,目前主流OS或个别安全性要求较高的设计场景,对X509的证书链验证已经不在停留在只从数字签名校验了,也就是仅仅从公钥验签的角度,在这些场景中,往往还会校验AuthorityKeyIdentifier和SubjectKeyIdentifier的一致性,也即下级证书的AuthorityKeyIdentifier应该与上级证书的SubjectKeyIdentifier一致,这两个参数是X509 v3  extensions的范围。

            但是X509对SubjectKeyIdentifier与AuthorityKeyIdentifier本身以及它们之前的一致性校验逻辑,都没有严格的规定,因此我们只能follow Openssl的逻辑。

            Openssl的SubjectKeyIdentifier可以为hash,此时是公钥的160bit sha-1散列,或者是一个hex字符串,此时是人为预设的SubjectKeyIdentifier。

            Openssl的AuthorityKeyIdentifier是follow X509定义的,AuthorityKeyIdentifier实际上是一个组,有三个组成员,keyid,dirname,serialnum,keyid就是上级证书的SubjectKeyIdentifier。你可以提供authoritykeyidentifier=keyid,issuer,作为openssl参数,它会尽量把以上三个组成员给填满,为什么说尽量呢,因为上级证书可能压根就没有SubjectKeyIdentifier这个v3 extension属性。

            Openssl的证书链校验,如果提供了issuer_checks参数也是可以校验以上一致性的。

            openssl配置subjectKeyIdentifier = hash,此时openssl在签发证书时,会加入subjectKeyIdentifier参数,如果subjectKeyIdentifier这个参数没有的话,缺省是不会有任何subjectKeyIdentifier被加入的。

            此时如果authorityKeyIdentifier = keyid,issuer,那么只有issuer有效,也即会加入上级证书的dirname,serialnum。

            当subjectKeyIdentifier = hash;authorityKeyIdentifier = keyid,issuer时,产生的下级证书如下图。

            当没有subjectKeyIdentifier = hash;authorityKeyIdentifier = keyid,issuer:always时,产生的下级证书如下图。其中issuer:always强制加入dirname,serialnum两项。

            当没有subjectKeyIdentifier配置;仅有authorityKeyIdentifier = keyid,issuer时,产生的下级证书如下图。可以看到CA证书没有 subjectKeyIdentifier,下级证书没办法复制到subjectKeyIdentifier因此authorityKeyIdentifier 仅有其他两项。

            以上各种情况,均可以通过以下命令验证通过。

            openssl verify -CAfile cacert.pem --issuer_checks certwork.pem

    以下为用到的配置文件与测试命令。

    1. [ req ]
    2. distinguished_name = req_distinguished_name
    3. policy = policy_match
    4. x509_extensions = v3_ca
    5. # For the CA policy
    6. [ policy_match ]
    7. countryName = optional
    8. stateOrProvinceName = optional
    9. organizationName = optional
    10. organizationalUnitName = optional
    11. commonName = supplied
    12. emailAddress = optional
    13. [ req_distinguished_name ]
    14. countryName = Country Name (2 letter code)
    15. countryName_default = IN
    16. countryName_min = 2
    17. countryName_max = 2
    18. stateOrProvinceName = State or Province Name (full name) ## Print this message
    19. stateOrProvinceName_default = KARNATAKA ## This is the default value
    20. localityName = Locality Name (eg, city) ## Print this message
    21. localityName_default = BANGALORE ## This is the default value
    22. 0.organizationName = Organization Name (eg, company) ## Print this message
    23. 0.organizationName_default = GoLinuxCloud ## This is the default value
    24. organizationalUnitName = Organizational Unit Name (eg, section) ## Print this message
    25. organizationalUnitName_default = Admin ## This is the default value
    26. commonName = Common Name (eg, your name or your server hostname) ## Print this message
    27. commonName_max = 64
    28. emailAddress = Email Address ## Print this message
    29. emailAddress_max = 64
    30. [ v3_ca ]
    31. #subjectKeyIdentifier = hash
    32. authorityKeyIdentifier = keyid,issuer
    33. basicConstraints = critical,CA:true
    34. nsComment = "OpenSSL Generated Certificate"
    35. [ v3_work ]
    36. subjectKeyIdentifier = hash
    37. authorityKeyIdentifier = keyid:awlays,issuer:always
    38. basicConstraints = critical,CA:true
    39. nsComment = "OpenSSL Generated Certificate"
    1. openssl genrsa -out private.pem 2048
    2. openssl req -new -x509 -days 3650 -config opensslroot.cfg -key private.pem -out cacert.pem
    3. openssl x509 -text -noout -in cacert.pem
    4. openssl genrsa -out workkey.pem 2048
    5. openssl req -new -key workkey.pem -config opensslroot.cfg -out certwork.csr
    6. openssl req -text -in certwork.csr
    7. openssl x509 -req -days 365 -CA cacert.pem -extfile opensslroot.cfg -extensions v3_work -CAcreateserial -CAkey private.pem -in certwork.csr -out certwork.pem
    8. openssl x509 -in certwork.pem -text

  • 相关阅读:
    地磁查询网站
    ModelScope-agent体验
    springboot 注入配置文件中的集合 List
    js中let和var的区别
    zk常用命令ls、ls2、get、stat,参数意思(重补早期学习记录)
    Figure 02 机器人发布:未来AI的巅峰还是泡沫中的救命稻草?
    优雅而高效——立即执行函数表达式()();
    【Redis】原理篇:Redis过期删除与内存淘汰
    Ubuntu systemd.service服务单元配置详解
    WPF知识小结(2)
  • 原文地址:https://blog.csdn.net/HeavenMonkey/article/details/134418250