如何编辑使用openssl xampp创建的自签名证书?

7

我使用内置于xampp中的openssl创建了自己的自签名证书。然而,我想编辑公共名称,这是否可能?有谁知道如何覆盖证书吗?

1个回答

9
然而,我想编辑通用名称,这是可能的吗?有人知道我如何覆盖证书吗?
本质上不可能。 公共名称(CN)位于签名证书的部分中,因此您不能仅仅删除它而不使签名失效。但是,您可以使用主题备用名称(SAN)中的DNS名称生成新的证书请求或自签名证书(而不在公共名称(CN)中)。
创建带有SAN中DNS名称的自签名证书的技巧是使用自定义配置文件。 您无法仅仅使用命令行生成它,因为SAN中的DNS名称不会被复制。 下面是我使用的自定义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
1
@fondillusions - 是的,您可以覆盖现有的证书。只需确保在XAMPP配置文件中更改证书和私钥即可。无需重新安装XAMPP。这就像在需要换油时购买一辆新车一样。 - jww
太好了,谢谢!我该如何在XAMPP配置文件中更改证书和私钥?抱歉,我有点新手。我正在按照相同的步骤再次创建自签名证书..(这肯定不对吧?)我遇到了一个错误-系统库:fopen:未知错误...... - fondillusions

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接