如何编辑使用 openssl xampp 创建的自签名证书?
Posted
技术标签:
【中文标题】如何编辑使用 openssl xampp 创建的自签名证书?【英文标题】:How do I edit a self signed certificate created using openssl xampp? 【发布时间】:2014-11-19 03:03:09 【问题描述】:我使用 xampp 中内置的 openssl 创建了自己的自签名证书。但是,我想编辑通用名称,这可能吗?有谁知道我可以如何覆盖证书?
【问题讨论】:
【参考方案1】:但是,我想编辑公用名,这可能吗?有谁知道我可以如何覆盖证书?
这是不可能的本身。公用名 (CN) 位于已签名的证书部分,因此您不能简单地删除它而不使签名失效。
但是,您可以使用主题备用名称 (SAN)(而不是通用名称 (CN))中的 DNS 名称生成新的证书请求或自签名证书。
在 SAN 中使用 DNS 名称创建自签名证书的技巧是您需要使用自定义配置文件。您无法仅使用命令行生成一个,因为 SAN 中的 DNS 名称没有复制。下面是我使用的自定义 CONF 文件(称为 example-com.conf
)。
example-com.conf:
# Self Signed (note the addition of -x509):
# openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Signing Request (note the lack of -x509):
# openssl req -config example-com.conf -new -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.req.pem
# Print it:
# openssl x509 -in example-com.cert.pem -text -noout
# openssl req -in example-com.req.pem -text -noout
[ req ]
default_bits = 2048
default_keyfile = server-key.pem
distinguished_name = subject
req_extensions = req_ext
x509_extensions = x509_ext
string_mask = utf8only
# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description).
# Its sort of a mashup. For example, RFC 4514 does not provide emailAddress.
[ subject ]
countryName = Country Name (2 letter code)
countryName_default = US
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = NY
localityName = Locality Name (eg, city)
localityName_default = New York
organizationName = Organization Name (eg, company)
organizationName_default = Example, LLC
# Use a friendly name here because its presented to the user. The server's DNS
# names are placed in Subject Alternate Names. Plus, DNS names here is deprecated
# by both IETF and CA/Browser Forums. If you place a DNS name here, then you
# must include the DNS name in the SAN too (otherwise, Chrome and others that
# strictly follow the CA/Browser Baseline Requirements will fail).
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = Example Company
emailAddress = Email Address
emailAddress_default = test@example.com
# Section x509_ext is used when generating a self-signed certificate. I.e., openssl req -x509 ...
[ x509_ext ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"
# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage = serverAuth, clientAuth
# Section req_ext is used when generating a certificate signing request. I.e., openssl req ...
[ req_ext ]
subjectKeyIdentifier = hash
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"
# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage = serverAuth, clientAuth
[ alternate_names ]
DNS.1 = example.com
DNS.2 = www.example.com
DNS.3 = mail.example.com
DNS.4 = ftp.example.com
# Add these if you need them. But usually you don't want them or
# need them in production. You may need them for development.
# DNS.5 = localhost
# DNS.6 = localhost.localdomain
# DNS.7 = 127.0.0.1
# IPv6 localhost
# DNS.8 = ::1
【讨论】:
对不起,我的意思是“编辑”/更改证书的通用名称。不能创建一个新的来覆盖现有的吗?我想知道重新安装 xampp 然后再次创建证书是否会更容易..? @fondillusions - 是的,您可以覆盖现有证书。只需确保更改 XAMPP 配置文件中的证书和私钥即可。无需重新安装 XAMPP。这就像在需要更换机油时购买新车一样。 太好了,谢谢!如何更改 XAMPP 配置文件中的证书和私钥?对不起,有点新手。我再次按照相同的步骤创建自签名证书..(肯定不对?)我收到一个错误 - 系统库:fopen:未知错误...... @fondillusions - 请参阅How do I use https (SSL) in XAMPP while using virtual hosts、Setting up SSL on a local xampp/apache server 和其他相关问题。以上是关于如何编辑使用 openssl xampp 创建的自签名证书?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 OpenSSL 生成带有 SubjectAltName 的自签名证书? [关闭]
Openssl从CSR创建证书(无私钥 - 存储在另一个系统中)
XAMPP PHP OPENSSL openssl_pkey_get_details() 崩溃网页