如何为多个子域创建 SSL 证书?

如何为多个子域创建 SSL 证书?

我正在运行服务器“myserver.net”,它有子域“a.myserver.net”和“b.myserver.net”。

创建(自签名)SSL 证书时,我必须为每个子域创建一个包含 FQDN 的证书,即使这些子域只是虚拟主机。

OpenSSL 仅允许一个“通用名称”,即相关域。是否有可能创建对域的所有子域都有效的证书?

答案1

是的,使用 *.myserver.net 作为通用名称。

这被称为通配符证书,有大量的操作指南都可以用这个关键字来查找。

以下是其中之一:https://web.archive.org/web/20140228063914/http://www.justinsamuel.com/2006/03/11/howto-create-a-self-signed-wildcard-ssl-certificate

更新:如果您希望证书也与根域 (myserver.net) 匹配,则应使用主题备用名称扩展。使用 openssh 生成证书时,输入“*.myserver.net/CN=myserver.net”作为通用名称。

兼容是够好了,除非你使用的浏览器很老旧。

答案2

仅供参考,还有另一种证书,称为统一通信证书。通配符只能颁发给,*.domain.com但 UCC 证书允许您在任何域下列出最多 100 个完全限定域名 (FQDN)。获取其中一种证书的主要原因是 Microsoft 不太热衷于 MS 域控制器、Exchange 等的通配符。

https://www.godaddy.com/help/what-is-a-multiple-domain-ucc-ssl-certificate-3908

统一通信证书 (UCC) 是一种 SSL 证书,可保护多个域名以及域名内的多个主机名。UCC 可让您在单个证书中保护主域名和最多 99 个其他主题备用名称 (SAN)。UCC 非常适合 Microsoft® Exchange Server 2007、Exchange Server 2010 和 Microsoft Live® Communications Server。

UCC 与共享主机兼容。但是,站点印章和证书“颁发给”信息将仅列出主域名。请注意,任何辅助主机帐户也将列在证书中,因此如果您不希望站点看起来彼此“连接”,则不应使用此类证书。

UCC 的主要缺点是您必须预先列出所有域名(通配符不需要这样做)。如果列表发生变化,您将必须获得新的证书。顺便说一句,Namecheap(我知道的唯一一家这样做的公司)提供了一个扩展验证 UCC(您按域名付费,这意味着 100 个域名的证书非常昂贵),这是为多个域名获得 EV 证书的唯一方法,因为没有人提供 EV 通配符。

答案3

我无法发表评论,所以我添加了一个单独的答案。我尝试为 NGINX 创建自签名证书,这很容易,但是当我想将其添加到 Chrome 白名单时,我遇到了问题。我的解决方案是创建一个根证书并用它来签署一个子证书。

一步一步来。创建文件配置SSL证书 注意,配置文件有一个选项基本约束=CA:true这意味着该证书应该是根证书。

这是一个很好的做法,因为您只需创建一次就可以重复使用。

[ req ]
default_bits = 2048

prompt = no
distinguished_name=req_distinguished_name
req_extensions = v3_req

[ req_distinguished_name ]
countryName=UA
stateOrProvinceName=root region
localityName=root city
organizationName=Market(localhost)
organizationalUnitName=roote department
commonName=market.localhost
[email protected]

[ alternate_names ]
DNS.1        = market.localhost
DNS.2        = www.market.localhost
DNS.3        = mail.market.localhost
DNS.4        = ftp.market.localhost
DNS.5        = *.market.localhost

[ v3_req ]
keyUsage=digitalSignature
basicConstraints=CA:true
subjectKeyIdentifier = hash
subjectAltName = @alternate_names

您的子证书的下一个配置文件将被调用配置SSL配置文件

[ req ]
default_bits = 2048

prompt = no
distinguished_name=req_distinguished_name
req_extensions = v3_req

[ req_distinguished_name ]
countryName=UA
stateOrProvinceName=Kyiv region
localityName=Kyiv
organizationName=market place
organizationalUnitName=market place department
commonName=market.localhost
[email protected]

[ alternate_names ]
DNS.1        = market.localhost
DNS.2        = www.market.localhost
DNS.3        = mail.market.localhost
DNS.4        = ftp.market.localhost
DNS.5        = *.market.localhost

[ v3_req ]
keyUsage=digitalSignature
basicConstraints=CA:false
subjectAltName = @alternate_names
subjectKeyIdentifier = hash

第一步-创建Root key和证书

openssl genrsa -out ca.key 2048
openssl req -new -x509 -key ca.key -out ca.crt -days 365 -config config_ssl_ca.cnf

第二步创建子密钥并提交 CSR(证书签名请求)。因为这个想法是通过 root 签署子证书并获取正确的证书

openssl genrsa -out market.key 2048
openssl req -new -sha256 -key market.key -config config_ssl.cnf -out market.csr

打开Linux终端并执行此命令

echo 00 > ca.srl
touch index.txt

ca.srl包含下一个要使用的十六进制序列号的文本文件。必需。此文件必须存在且包含有效序列号。

最后一步,再创建一个配置文件并调用它配置ca.cnf

# we use 'ca' as the default section because we're usign the ca command
[ ca ]
default_ca = my_ca

[ my_ca ]
#  a text file containing the next serial number to use in hex. Mandatory.
#  This file must be present and contain a valid serial number.
serial = ./ca.srl

# the text database file to use. Mandatory. This file must be present though
# initially it will be empty.
database = ./index.txt

# specifies the directory where new certificates will be placed. Mandatory.
new_certs_dir = ./

# the file containing the CA certificate. Mandatory
certificate = ./ca.crt

# the file contaning the CA private key. Mandatory
private_key = ./ca.key

# the message digest algorithm. Remember to not use MD5
default_md = sha256

# for how many days will the signed certificate be valid
default_days = 365

# a section with a set of variables corresponding to DN fields
policy = my_policy

# MOST IMPORTANT PART OF THIS CONFIG
copy_extensions = copy

[ my_policy ]
# if the value is "match" then the field value must match the same field in the
# CA certificate. If the value is "supplied" then it must be present.
# Optional means it may be present. Any fields not mentioned are silently
# deleted.
countryName = match
stateOrProvinceName = supplied
organizationName = supplied
commonName = market.localhost
organizationalUnitName = optional
commonName = supplied

您可能会问,为什么这么难,为什么我们必须再创建一个配置才能通过 root 签署子证书。答案很简单,因为子证书必须有一个 SAN 块 - 主题备用名称。如果我们通过“openssl x509”实用程序签署子证书,根证书将删除子证书中的 SAN 字段。因此,我们使用“openssl ca”而不是“openssl x509”来避免删除 SAN 字段。我们创建一个新的配置文件并告诉它复制所有扩展字段copy_extensions = 复制

openssl ca -config config_ca.cnf -out market.crt -in market.csr

该程序会问您两个问题:

  1. 签署证书?请回答“是”
  2. 1 个证书请求中 1 个已认证,同意吗?请回答“是”

在终端中,您可以看到一个带有“数据库”字样的句子,它表示您通过命令“touch”创建的文件 index.txt。它将包含您通过“openssl ca”实用程序创建的所有证书的所有信息。要检查证书是否有效,请使用:

openssl rsa -in market.key -check

如果你想看看 CRT 里面有什么:

openssl x509 -in market.crt -text -noout

如果你想看看 CSR 里面有什么:

openssl req -in market.csr -noout -text 

答案4

这个问题很合理。不幸的是,据我所知,协议从未打算让域名所有者只为子域名签署证书。

您要么是任何事物的 CA,要么什么都不是。一旦您成为 CA,范围就没有限制了。

很蠢,但事实就是如此。只需为您拥有的每个域名购买单独的证书 $$$,没错,每个域名,所以不要费心尝试保护您销售的嵌入式设备。

相关内容