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

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


当前回答

修复Windows上的Chrome。

首先,您需要导出证书。

在浏览器中找到url。url的“https”段将为用红线划掉,左侧将有一个锁定符号。右键单击划掉的“https”段。您将看到一个包含各种信息的信息窗口单击“详细信息”。导出证书,按照说明接受默认设置。

要导入

转到Chrome设置单击“高级设置”在HTTPS/SSL下单击“管理证书”转到“受信任的根证书颁发机构”单击“导入”将出现一个弹出窗口,询问您是否要安装此证书。单击“是”。

其他回答

Chrome 58+更新(发布于2017-04-19)

从Chrome 58开始,仅使用commonName识别主机的功能被删除。证书现在必须使用subjectAltName来标识其主机。请参阅此处的进一步讨论和此处的bug跟踪器。在过去,subjectAltName仅用于多主机证书,因此一些内部CA工具不包括这些证书。

如果您的自签名证书在过去运行良好,但突然开始在Chrome 58中生成错误,这就是原因。

因此,无论您使用什么方法来生成自签名证书(或由自签名CA签名的证书),请确保服务器的证书包含具有正确DNS和/或IP条目的subjectAltName,即使它仅适用于单个主机。

对于openssl,这意味着您的openssl配置(Ubuntu上的/etc/ssl/openssl.cnf)对于单个主机应该具有类似于以下内容的内容:

[v3_ca]   # and/or [v3_req], if you are generating a CSR
subjectAltName = DNS:example.com

或对于多个主机:

[v3_ca]   # and/or [v3_req], if you are generating a CSR
subjectAltName = DNS:example.com, DNS:host1.example.com, DNS:*.host2.example.com, IP:10.1.2.3

在Chrome的证书查看器(已移动到F12下的“安全”选项卡)中,您应该看到它列在“扩展名”下作为证书主题替代名称:

我也遇到了同样的问题:我已将证书安装到Windows的Trusted Root Authorities存储中,但Chrome仍然拒绝证书,错误为ERR_CERT_COMMON_NAME_INVALID。请注意,当证书未正确安装在存储中时,错误为ERR_CERT_AUTHORITY_INVALID。

正如错误名称、此注释和此问题所暗示的,问题在于证书中声明的域名。当生成证书时提示输入“CommonName”时,我必须输入用于访问站点的域名(在我的情况下是localhost)。我使用重新启动了Chromechrome://restart它终于对这个新证书感到满意。

通过此方法允许不安全的本地主机正常工作chrome://flags/#allow-不安全的本地主机

只需要将开发主机名创建为xxx.localhost。

只需要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
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
)