【问题标题】:How to add custom field to certificate using openssl如何使用 openssl 将自定义字段添加到证书
【发布时间】:2016-06-30 16:18:09
【问题描述】:

我正在尝试创建供内部使用的证书。我是 CA,我希望在我的客户端证书中添加一个字段,这样当我为客户端生成证书时,它将在该字段中保存一些特定数据。

我阅读了以下 articleanother article 并了解我可以通过为每个字段生成一个 oid 来使用 x509 v3 格式执行此操作,然后在创建公钥时将其与 -extfile 参数一起使用 所以我使用了默认的 /etc/ssl/openssl.cnf 配置文件并取消注释提到的字段之一:

[ new_oids ]
testoid1 = 1.2.3.4

然后我通过以下方式生成所有证书:

openssl genrsa -aes256 -out ca-key.pem 4096
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem -config openssl.cnf 
openssl genrsa -out key.pem 4096
openssl req -subj '/CN=client' -new -key key.pem -out client.csr
openssl x509 -req -days 365 -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem  -CAcreateserial -out cert.pem -extfile extfile.cnf

extfile.cnf 内容在哪里:

1.2.3.4 = Something

我明白了:

Error Loading extension section default
140218200073872:error:22097082:X509 V3 routines:DO_EXT_NCONF:unknown extension name:v3_conf.c:125:
140218200073872:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:v3_conf.c:95:name=1.2.3.4, value=Something
unable to write 'random state'

缺少该主题的文档。有人可以指导我并解释它是如何完成的吗?

【问题讨论】:

  • 一篇不错的博客,详细介绍了在 x509 证书 here 中添加扩展字段的基础知识。

标签: ssl openssl x509


【解决方案1】:

为了添加自定义字段,首先创建一个配置文件:

[req]
req_extensions = v3_req

[v3_req]
1.2.3.4.5.6.7.8=ASN1:UTF8String:Something

然后,创建 CSR:

openssl req [params] -out mycsr.csr -config myconfig.cnf

然后,创建证书:

openssl x509 -req -sha256 -in mycsr.csr [params] -out mycert.pem -extfile myconfig.cnf -extensions v3_req

【讨论】:

  • 我遇到了同样的问题,我尝试了这里的建议,但我收到了这个错误:无法在配置中找到“distinguished_name”。我的配置文件是否必须只有上面写的内容或其他内容?
  • @Sandra 迟到总比没有好:superuser.com/questions/947061/…(基本上,在您现有的/etc/ssl/openssl.cnf 中找到上述两个部分,如果缺少这两行,请添加)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
  • 2018-08-11
  • 2015-05-30
  • 1970-01-01
相关资源
最近更新 更多