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

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


当前回答

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

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

其他回答

Windows:生成并自签名证书

这是一个在windows上生成根证书和实际域证书的“单文件”示例。编辑前四个变量,无需CMD进一步输入:

SET ROOT=my-root
SET NAME=demodomain
SET SUBJECT=/C=CH/O=My Demo Company
SET PASSWORD=ptGXHr3sudczSL9Q

:: Generate private key
openssl genrsa -des3 -out %ROOT%.key -passout pass:"%PASSWORD%" 2048
:: Generate root certificate 
openssl req -x509 -new -nodes -key %ROOT%.key -sha256 -days 3650 -out %ROOT%.crt -passin pass:"%PASSWORD%" -subj "%SUBJECT%"


openssl genrsa -out %NAME%.key 2048
openssl req -new -key %NAME%.key -subj "%SUBJECT%/CN=%NAME%" -out %NAME%.csr

(
echo authorityKeyIdentifier=keyid,issuer
echo basicConstraints=CA:FALSE
echo keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
echo subjectAltName = @alt_names
echo [alt_names]
echo DNS = %NAME%)>config.ext

openssl x509 -req -in %NAME%.csr -CA "%ROOT%.crt" -CAkey "%ROOT%.key" -CAcreateserial -out %NAME%.crt -days 1780 -sha256 -extfile config.ext -passin pass:"%PASSWORD%"

:: cleanup files used for certificate generation
del %NAME%.csr
del config.ext

如果您想在一个文件中包含完整的链,请在bat文件中添加以下内容:

:: build chain in certificate-file
echo %ROOT%.crt >> %NAME%.crt
Type "%ROOT%.crt" >> %NAME%.crt

如果要验证证书,请附加以下内容:

openssl verify -CAfile "%ROOT%.crt" -verify_hostname %NAME% %NAME%.crt

打开根证书my-root.crt并将其添加到windows证书存储(选择“受信任的根证书颁发机构”):

Chrome中的最终结果:

我刚刚在我的chrome中启用了允许不安全的localhost标志,就这样。

步骤。

类型chrome://flags在您的铬标签中。搜索允许不安全的本地主机标志并启用它。重新启动chrome浏览器。

现在,您将不会看到不安全的警告https://localhost地点。

单击页面上的任意位置并键入BYPASS_SEQUENCE:

BYPASS_SEQUENCE Chrome Version
thisisunsafe 65 - ?
badidea 62 - 64
danger ? - 61

您不需要查找输入字段,只需键入它即可。这感觉很奇怪,但它有效。我在Mac High Sierra上试过了。

要再次检查他们是否再次更改,请转到最新的Chromium源代码。此时BYPASS_SEQUENCE如下所示:

var BYPASS_SEQUENCE = window.atob('dGhpc2lzdW5zYWZl');

现在他们把它伪装起来了,但要看到真正的BYPASS_SEQUENCE,您可以在浏览器控制台中运行以下行。

console.log(window.atob('dGhpc2lzdW5zYWZl'));

OR

除了键入短语,您还可以在控制台中粘贴代码部分

sendCommand(SecurityInterstitialCommandId.CMD_PROCEED)

我尝试了一切,并尝试了什么:导入时,选择正确的类别,即受信任的根证书颁发机构:

(很抱歉,这是德语,但请按照图片操作)

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