我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。

我该怎么做才能让Chrome接受证书并停止抱怨?


当前回答

mkdir CA
openssl genrsa -aes256 -out CA/rootCA.key 4096
openssl req -x509 -new -nodes -key CA/rootCA.key -sha256 -days 1024 -out CA/rootCA.crt

openssl req -new -nodes -keyout example.com.key -out domain.csr -days 3650 -subj "/C=US/L=Some/O=Acme, Inc./CN=example.com"
openssl x509 -req -days 3650 -sha256 -in domain.csr -CA CA/rootCA.crt -CAkey CA/rootCA.key -CAcreateserial -out example.com.crt -extensions v3_ca -extfile <(
cat <<-EOF
[ v3_ca ]
subjectAltName = DNS:example.com
EOF
)

其他回答

要在Windows中创建Chrome v58及更高版本将信任的自签名证书,请使用提升的权限启动Powershell并键入:

New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -Subject "fruity.local" -DnsName "fruity.local", "*.fruity.local" -FriendlyName "FruityCert" -NotAfter (Get-Date).AddYears(10)
#notes: 
#    -subject "*.fruity.local" = Sets the string subject name to the wildcard *.fruity.local
#    -DnsName "fruity.local", "*.fruity.local"
#         ^ Sets the subject alternative name to fruity.local, *.fruity.local. (Required by Chrome v58 and later)
#    -NotAfter (Get-Date).AddYears(10) = make the certificate last 10 years. Note: only works from Windows Server 2016 / Windows 10 onwards!!

完成此操作后,证书将保存到个人\证书存储下的本地计算机证书中。

您要将此证书复制到受信任的根证书颁发机构\证书存储。

一种方法是:单击Windows开始按钮,然后键入certlm.msc。然后按照下面的屏幕截图将新创建的证书拖放到Trusted Root Certification Authority\Certificates存储区。

从Chrome 58+开始,由于缺少SAN,我开始在macOS上获取证书错误。下面是如何再次获得地址栏上的绿色锁。

使用以下命令生成新证书:openssl请求\-新密钥rsa:2048\-2009年5月\-节点\-keyout服务器.key\-新的\-输出服务器.crt\-subj/CN=*.domain.dev\-请求SAN\-扩展SAN\-配置<(cat/System/Library/OpenSSL/OpenSSL.cnf\<(printf'[SAN]\nobjectAltName=DNS:*.domain.dev'))\-沙256\-720天将server.crt导入KeyChain,然后双击证书,展开“信任”,然后选择“始终信任”

刷新页面https://domain.dev在Google Chrome中,绿色锁又回来了。

对于测试环境

在启动chrome时,可以使用--ignore证书错误作为命令行参数(在Ubuntu上使用28.0.1500.52版本)。

这将导致它忽略错误并在没有警告的情况下连接。如果您已经运行了一个版本的chrome,则需要在从命令行重新启动之前关闭它,否则它将打开一个新窗口,但忽略参数。

我将Intellij配置为在进行调试时以这种方式启动chrome,因为测试服务器从来没有有效的证书。

不过,我不建议像这样正常浏览,因为证书检查是一项重要的安全功能,但这可能对某些人有所帮助。

正如有人指出的,你需要重启所有的Chrome,而不仅仅是浏览器窗口。最快的方法是打开一个选项卡。。。

chrome://restart

只需要5个openssl命令,就可以完成这一任务。

(请不要更改浏览器安全设置。)

使用以下代码,您可以(1)成为自己的CA,(2)然后将SSL证书签署为CA。(3)然后将CA证书(而不是服务器上的SSL证书)导入Chrome/Chrum。(是的,即使在Linux上也可以。)

注意:对于Windows,一些报告说openssl必须与winpty一起运行以避免崩溃。

######################
# Become a Certificate Authority
######################

# Generate private key
openssl genrsa -des3 -out myCA.key 2048
# Generate root certificate
openssl req -x509 -new -nodes -key myCA.key -sha256 -days 825 -out myCA.pem

######################
# Create CA-signed certs
######################

NAME=mydomain.example # Use your own domain name
# Generate a private key
openssl genrsa -out $NAME.key 2048
# Create a certificate-signing request
openssl req -new -key $NAME.key -out $NAME.csr
# Create a config file for the extensions
>$NAME.ext cat <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = $NAME # Be sure to include the domain name here because Common Name is not so commonly honoured by itself
DNS.2 = bar.$NAME # Optionally, add additional domains (I've added a subdomain here)
IP.1 = 192.168.0.13 # Optionally, add an IP address (if the connection which you have planned requires it)
EOF
# Create the signed certificate
openssl x509 -req -in $NAME.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial \
-out $NAME.crt -days 825 -sha256 -extfile $NAME.ext

概括如下:

成为CA使用CA cert+密钥签署证书在您的Chrome设置(设置>管理证书>权限>导入)中将myCA.pem作为“权限”(而不是“您的证书”)导入使用服务器中的$NAME.crt和$NAME.key文件

额外步骤(至少适用于Mac):

在“文件>导入文件”中导入CA证书,然后在列表中找到它,右键单击它,展开“>信任”,然后选择“始终”在basicConstraints=CA:FALSE下面添加extendedKeyUsage=serverAuth,clientAuth,并确保在请求设置时将“CommonName”设置为与$NAME相同

您可以检查您的工作以确保正确生成证书:

openssl verify -CAfile myCA.pem -verify_hostname bar.mydomain.example mydomain.example.crt