Openssl X509 v3 AuthorityKeyIdentifier实验与逻辑分析

news/2024/10/19 16:37:02/

       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

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

[ req ]
distinguished_name = req_distinguished_name
policy             = policy_match
x509_extensions     = v3_ca# For the CA policy
[ policy_match ]
countryName             = optional
stateOrProvinceName     = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
countryName_default             = IN
countryName_min                 = 2
countryName_max                 = 2
stateOrProvinceName             = State or Province Name (full name) ## Print this message
stateOrProvinceName_default     = KARNATAKA ## This is the default value
localityName                    = Locality Name (eg, city) ## Print this message
localityName_default            = BANGALORE ## This is the default value
0.organizationName              = Organization Name (eg, company) ## Print this message
0.organizationName_default      = GoLinuxCloud ## This is the default value
organizationalUnitName          = Organizational Unit Name (eg, section) ## Print this message
organizationalUnitName_default  = Admin ## This is the default value
commonName                      = Common Name (eg, your name or your server hostname) ## Print this message
commonName_max                  = 64
emailAddress                    = Email Address ## Print this message
emailAddress_max                = 64[ v3_ca ]
#subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = critical,CA:true
nsComment = "OpenSSL Generated Certificate"[ v3_work ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:awlays,issuer:always
basicConstraints = critical,CA:true
nsComment = "OpenSSL Generated Certificate"
openssl genrsa -out private.pem 2048openssl req -new -x509 -days 3650 -config opensslroot.cfg -key private.pem -out cacert.pemopenssl x509 -text -noout -in cacert.pemopenssl genrsa -out workkey.pem 2048openssl req -new -key workkey.pem -config opensslroot.cfg -out certwork.csropenssl req -text -in certwork.csropenssl x509 -req -days 365 -CA cacert.pem -extfile opensslroot.cfg -extensions v3_work -CAcreateserial -CAkey private.pem -in certwork.csr -out certwork.pemopenssl x509 -in certwork.pem -text


http://www.ppmy.cn/news/1218839.html

相关文章

《信息安全原理与实践》(第3版):全面引领信息安全领域新潮流

在当今信息化社会的快速发展中,信息安全问题无疑是最为人们所关注的焦点之一。而《信息安全原理与实践》(第3版)的出版,无疑为解决这一问题提供了强大的理论和实践支持。 首先,这本书经过全面修订和更新,以适应信息安全领域日新月…

将按键放到输入框内:

如何将将Button放到输入框内&#xff1f; 效果图&#xff1a; 步骤如下&#xff1a; button 外围用template 包裹一层 <template #suffix v-if"row.WorkerRole TPM"> <el-inputtype"text"v-model"row.JobNumber"placeholder"…

如何选择工业以太网交换机?

现在市面上有许多品牌的工业以太网交换机&#xff0c;并且类型也相当复杂。在选择交换机的时候&#xff0c;需要考虑多个因素&#xff0c;比如工作环境、是否需要冗余配置、是否需要网管功能、是否需要非网管功能、以及未来的维护和扩展性等。通常情况下&#xff0c;当选择工业…

我记不住的那些命令(不断更新中)

fzf 一种进行模糊查找的命令行工具 主页&#xff1a;https://github.com/junegunn/fzf 我的主机是 Kali&#xff0c;通过apt进行安装fzf&#xff0c;并进行配置。 # apt install fzf # apt show fzf 通过参考/usr/share/doc/fzf/README.Debian来进行快速配置快捷键和自动补…

Poly风格模型的创建与使用_unity基础开发教程

Poly风格模型的创建与使用 安装Poly相关组件Poly模型的创建Poly模型编辑 安装Poly相关组件 打开资源包管理器Package Manager 在弹出的窗口左上角Packages选择Unity Registry 搜索框搜索 Poly 搜索结果点击Polybrush 点击右下角 Install 同时也别忘了导入一下模型示例&#…

电容容量换算电池容量,以及RTC持续时间计算

依据 公式1&#xff1a;QI*t 公式2&#xff1a;QC*U 其中&#xff1a; Q&#xff1a; 电荷量 &#xff08;库仑&#xff09; I&#xff1a; 电流 &#xff08;安培&#xff09; t&#xff1a; 时间 &#xff08;秒&#xff09; C&#xff1a; 电容量 &#xff08;法拉&#xf…

Nginx配置开启HTTPS

获取证书文件 Nginx 开启SSL server {listen 443 default ssl;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;proxy_set_header Host $host;ssl_certificate /usr/local/nginx/cert/server.pem;ssl_certificate_key /usr/local/ngin…

数字化企业各业务模块模型

1.计划 1.1采购计划执行情况 序号 采购计划号 采购订单号 业务员 供应商 物料 数量 金额 计划入库日期 实际入库日期 状态 针对企业执行中或者未关闭的采购计划进行统计与分析&#xff0c;主要目的在于引领企业员工与领导关注长期在途的采购…