Creating a *.local ssl certificate

Jon*_*son 4 ssl openssl certificates apache-virtualhost

I am trying to set up a single SSL certificate that will make any *.local website work over https. I have all .local domains pointing back to my local machine. I use these when developing websites. A lot of new features (geo location, service workers etc.) require an SSL.

I believe that for recent versions of Chrome/Firefox, an old school self-signed certificate no longer works.

Below are the steps I have taken after following a combination of these guides: https://deliciousbrains.com/https-locally-without-browser-privacy-errors/

https://codeghar.wordpress.com/2008/03/17/create-a-certificate-authority-and-certificates-with-openssl/

/sf/ask/1910621261/

Here is my config file:

#..................................
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = /home/*****/Sites/root-ca
serial = $dir/serial
database = $dir/index.txt
new_certs_dir = $dir/certs
certificate = $dir/certs/cacert.pem
private_key = $dir/private/cakey.pem
default_days = 3000
default_md = sha256
preserve = no
email_in_dn = no
nameopt = default_ca
certopt = default_ca
policy = policy_match
copy_extensions = copyall
[ policy_match ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req ]
default_bits = 2048 # Size of keys
default_keyfile = key.pem # name of generated keys
default_md = md5 # message digest algorithm
string_mask = nombstr # permitted characters
distinguished_name = req_distinguished_name
req_extensions = v3_req
[ req_distinguished_name ]
# Variable name Prompt string
#------------------------- ----------------------------------
0.organizationName = Organization Name (company)
organizationalUnitName = Organizational Unit Name (department, division)
emailAddress = Email Address
emailAddress_max = 40
localityName = Locality Name (city, district)
stateOrProvinceName = State or Province Name (full name)
countryName = Country Name (2 letter code)
countryName_min = 2
countryName_max = 2
commonName = Common Name (hostname, IP, or your name)
commonName_max = 64
# Default values for the above, for consistency and less typing.
# Variable name Value
#------------------------ ------------------------------
0.organizationName_default = *****
localityName_default = *****
stateOrProvinceName_default = *****
countryName_default = *****
emailAddress_default = *****
[ v3_ca ]
basicConstraints = CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
subjectAltName       = @alternate_names
[ v3_req ]
subjectKeyIdentifier = hash
basicConstraints     = CA:FALSE
keyUsage             = digitalSignature, keyEncipherment
subjectAltName       = @alternate_names
nsComment            = "OpenSSL Generated Certificate"

[ alternate_names ]

DNS.1       = *.local
Run Code Online (Sandbox Code Playgroud)

I first create a new certificate authority:

openssl req -new -x509 -extensions v3_ca -keyout private/cakey.pem -out certs/cacert.pem -days 3000 -config conf/caconfig.cnf
Run Code Online (Sandbox Code Playgroud)

I have given the Common name here as my name

Common Name (hostname, IP, or your name) []:Jonathan Hodgson
Run Code Online (Sandbox Code Playgroud)

The file certs/cacert.pem I then import into chromium's authorities which works without a problem.

I then create a certificate request:

openssl req -extensions v3_req -new -nodes -out local.req.pem -keyout private/local.key.pem -config conf/caconfig.cnf
Run Code Online (Sandbox Code Playgroud)

I have given the Common name here as *.local

Common Name (hostname, IP, or your name) []:*.local
Run Code Online (Sandbox Code Playgroud)

I then sign the request:

openssl ca -out certs/local.cert.pem  -config conf/caconfig.cnf -infiles local.req.pem
Run Code Online (Sandbox Code Playgroud)

我将文件添加到我的 http 配置中:

<VirtualHost *:80>
    ServerName test.local
    ServerAlias *.local
    VirtualDocumentRoot /home/jonathan/Sites/%-2/public_html
    CustomLog /home/jonathan/Sites/access.log vhost_combined
    ErrorLog /home/jonathan/Sites/error.log
</VirtualHost>

<VirtualHost *:443>
    ServerName test.local
    ServerAlias *.local
    VirtualDocumentRoot /home/jonathan/Sites/%-2/public_html
    CustomLog /home/jonathan/Sites/access.log vhost_combined
    ErrorLog /home/jonathan/Sites/error.log
    SSLEngine On
    SSLCertificateFile /home/jonathan/Sites/root-ca/certs/local.cert.pem
    SSLCertificateKeyFile /home/jonathan/Sites/root-ca/private/local.key.pem
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我已经重新启动了 apache 但我仍然得到 NET::ERR_CERT_COMMON_NAME_INVALID

我的印象是,这是因为我需要将 subjectAltName 添加到我已经完成的配置文件中。

请让我知道我应该怎么做。

在此先感谢您的帮助

编辑

我认为问题与通配符有关。如果我将alternate_names 设置为example.local 并将请求的通用名称设置为example.local,则example.local 在Chrome 和Firefox 中都显示为安全。

我尝试将 DNS.1 设置为local并将 DNS.2设置为*.local,然后我就进入ERR_SSL_SERVER_CERT_BAD_FORMAT了 chrome 和SEC_ERROR_REUSED_ISSUER_AND_SERIALFirefox。在生成证书之前,我肯定会重置我的串行文件和索引文件。

dav*_*085 5

您将 SAN 添加到CSR,但您没有告诉ca在证书中包含来自 CSR 的扩展。见 https://security.stackexchange.com/questions/150078/missing-x509-extensions-with-an-openssl-generated-certificate或手册页ca 也是在网络上copy_extensions

编辑:您需要x509_extensionsca配置中指定,或等效但不太方便的 commandline option -extensions,在任何一种情况下都指向存在但如果您不想要任何 CA 要求的扩展的部分可以为空。因为我从来没有试过从CSR的扩展的情况下,我并没有在第一次注意到这个,而不是配置,这是不现实的大多数CA。如果您指定copy_extensions以外none(并且 CSR 有一些)但未指定,x509_extensionsca 确实会将扩展放入证书中,但在存在扩展时不会按照标准(如 rfc5280)的要求将证书版本设置为 v3。

如果这是一个错误,这是有争议的;手册页说x509_extensions/extensions控制 v3 设置,并没有说任何类似的事情copy_extensions暗示没有,但恕我直言,这肯定是一个非常次优的功能。编辑:这是一个错误,将被修复,但在此之前使用解决方法,请参阅https://unix.stackexchange.com/a/394465/59699

但是:在我的测试中,这实际上并没有解决您的问题。即使证书*.local在 SANCN 中并且(现在)在其他方面有效,我的 Firefox (53.0.2) 和 Chrome (59.0.3071.109) 仍然分别使用 SSL_ERROR_CERT_DOMAIN_ERROR 和 ERR_CERT_COMMON_NAME_INVALID 拒绝它。我猜他们可能不会local从正常的 2+ 级逻辑中排除并尝试*.example.local:Chrome 确实接受这一点,但 Firefox 不接受。我也尝试过*.example.orgChrome 和 IE11 都这样但仍然不是 Firefox(当然,在真正的 TLD 中.org为自己分配名称并不是 DNS 应该工作的方式)。

这让我卡住了。通过一些工作,可以使 OpenSSL 生成包含几乎所有您想要的任何内容的证书,但我不知道Firefox 和 Chrome 会接受什么。如果我发现任何东西,我会尝试调查并更新。


我希望你的意思是*.local只为服务器 CSR 而不是 CA(自签名)证书提供 CommonName。如果 CA 和叶证书的主题名称相同,则无法可靠地工作。编辑:您编辑的 Q 确认它们正确不同。尽管它没有提到根据ca您使用的策略的要求还指定国家、州和组织。

注意“自签名”是一个艺术术语,意味着用相同的密钥签名。您的 CA 证书是自签名的。您的服务器证书是由您自己使用自己的密钥签名的,但它不是自签名的。尝试将自签名证书的说明应用于非自签名证书是您的问题的一部分。

而Gilles 点关于md5 的签名算法也是正确的。

编辑:设置的“重置”序列(和索引)openssl ca是一个坏主意,除非您永久丢弃它们用于的 CA 证书和名称。标准说一个给定的 CA 不能在证书中发布多个具有相同序列值的证书,并且序列文件是方式openssl ca(也x509 -req) 实现这一点。“真实”(公共)CA 现在不再使用简单的计数器,而是包括熵来阻止对 PKI 的碰撞攻击——google hashclash——但这对于像你这样的个人 CA 来说不是问题。如果浏览器(或其他依赖者)看到多个具有相同序列号和 CA 名称的证书,我可以很容易地相信它会不高兴,尽管我不希望浏览器持续存储叶证书——从而看到旧的和新的在一个过程中,除非长期运行——除非您将其导入适用的商店,包括在 Firefox 中,如果您将其设为永久“例外”。