Chrome浏览器在本地使用自签名证书时出现NET::ERR_CERT_AUTHORITY_INVALID错误

50
我正在尝试在本地电脑上设置开发环境。由于生产网站支持HTTPS(如今谁不支持呢?),我也想在本地主机上使用它。我认为这应该很容易,但事实并非如此。我安装了XAMP,并设置了所有东西以便可以访问网站。但是,每当我在本地访问网站的任何页面时,Google Chrome都会显示警告:NET::ERR_CERT_AUTHORITY_INVALID。我已经按照以下线程尝试解决问题:Getting Chrome to accept self-signed localhost certificate。我还根据此文章创建了正确的主题备用名称(SAN)部分的证书。之后,我生成了CER或P7B文件,并将其导入了Chrome。我重启了Apache和Chrome。我将证书放在可信的根证书颁发机构中,但不知何故,Chrome却将其放在中间根证书颁发机构中... 我使用的是Chrome 61,60版也一样。所以,我无法安装自签名证书,并且一直收到这个警告,这基本上使得在本地主机上进行开发变得不可能...我知道自签名并不是非常值得信赖,但必须有一种离线开发的方式吧?从现在开始在线构建网站这样的做法是没有意义的,有什么想法吗?
9个回答

40

在Chrome浏览器中,我们可以允许使用无效证书进行开发。

这仅适用于本地主机

将以下内容粘贴到Chrome地址栏中:

chrome://flags/#allow-insecure-localhost

然后启用下面标记的文本:允许从本地主机加载的资源使用无效证书

输入图像描述


4
我猜这只能在URL中是https://localhost的情况下才有效,因为它无法与指向localhost / 127.0.0.1的域在/etc/hosts文件中配对。 - Rafa
说实话,如果你正在为一次性场景测试某些东西,这是最好的解决方案。谢谢! - Sujay66
2
不,它无法解决DNS指向“127.0.0.1”的域名的问题。 - Jos
这是答案。***在MS Edge中使用此链接:edge://flags/#allow-insecure-localhost - user3590235

8
以下是使用KeyStore Explorer工具的指令。我之前创建证书时遗漏了以下两点:
  • 添加“授权密钥标识符”(或AKID),选择与创建证书时相同的“CN =<certificate_name>”。
  • 添加“基本约束”选项(不要选择“是CA”)
如果没有这两个步骤,即使您将自签名证书安装到MS-CAPI PKI信任存储中(作为“受信任的根机构”),Chrome也会发出警告/错误。
步骤:
1. Instructions using KSE (KeyStore Explorer)
2. Create a JKS
3. Creating a self-signed certificate
4. Open KeyStore Explorer
5. File | New | JKS | OK
6. Create a Password for your JKS file
7. File | Save as... | enter your password 
8. Enter file name | OK
9. Tools | Generate Key Pair
10. Select Algorithm and Key Size (i.e. 2048) | OK
11. Select validity period (i.e. 5 years) 
12. Select Name (Book icon) | Enter in Name fields | OK: I.e. “CN=localhost…<or SERVER_NAME>”
13. Add Extensions (Very Important), this determines what type of certificate it will be and how it can be used.  This example will be for a standard server certificate with SSL.
14. Add in the Key Usage item
15. Add in the Digital Signature and Key Encipherment options checkbox
16. Add in the EKU (Extended Key Usage) options
17. Select both of these options: "TLS Web Client Authentication" and "TLS Web Server Authentication"
18. Add in the SANs (Subject Alternative Name)
19. Add in all the needed DNS names and IP Addresses (if applicable) for which this server will be used. (repeat for all desired values) (e.g. 127.0.0.1 and localhost (or <SERVER_NAME>)
20. It will look something like this when it's done
21. When it's done you will see all the fields with the OIDs (Object Identifiers) listed | OK | OK
22. Add in the AKID (Authority Key Identifier)
23. Add Extensions "+"
24. Add Extension Type | Authority Key Identifier
25. Select the Authority Cert Issuer of the CN that you created above (.e.g "CN=localhost...") | OK
26. Add in a "Basic Constraints" (do NOT check "Subject is a CA")
27. When you're done you'll see these listed: hit "OK"

/**
 * Note: the Basic Constraints and AKID (Authority Key Identifer) are needed 
 * for the Chrome Browser to validate the self-signed certificate as a 
 * trusted certificate. Otherwise you'll see warning or error messages even 
 * after you have add this certificate, explicitly, to your MS-CAPI Trusted 
 * Root certificates.
 **/

28. Enter in the Alias of the keypair name you want to use
29. Enter in the private keypair password

/**
 * Note: this password MUST be the same as the JKS file keystore password or 
 * Java may fail silently when trying to use this certificate.
 **/
 
30. You should see a message indicating success. | OK 
31. Then, save the File | Save

1
这可能听起来很蠢,但是这个文件应该使用什么文件扩展名,并且在按照这些指示后我应该怎么处理它? - K-Dawg
请按照上面第5步的说明查看JKS文件扩展名。然后,在KeyStore Explorer中右键单击并选择“导出”“公钥”。您可以将其保存为.p7或.cer/.crt扩展名。一旦有了该文件,您就可以将您的.cer文件导入到Chrome和/或FireFox浏览器中,这应该会解决问题。 - atom88
2
如果您计划在 Web 服务器上使用证书,则必须同时导出私钥。右键单击->导出->导出私钥,选择 OpenSSL,取消选中加密,选择文件位置,导出。 - Shawn
2
这个刚刚生效了。创建之后,我下载了证书并将其添加到 Chrome 上。现在不会再出现任何警告了。 - Dominik Mohr
它在Chrome中完美运行。但如何使其在Firefox中工作? - RAGINROSE
2
最终找到了在Firefox中使用它的方法。需要前往about:config并将配置security.enterprise_roots.enabled更改为true。 - RAGINROSE

7

我解决了与相同的问题。

问题似乎出在证书创建的方式上。

以下代码来自上述网站。

#!/usr/bin/env bash
mkdir ~/ssl/
openssl genrsa -des3 -out ~/ssl/rootCA.key 2048
openssl req -x509 -new -nodes -key ~/ssl/rootCA.key -sha256 -days 1024 -out ~/ssl/rootCA.pem


#!/usr/bin/env bash
sudo openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat server.csr.cnf )

sudo openssl x509 -req -in server.csr -CA ~/ssl/rootCA.pem -CAkey ~/ssl/rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

服务器的csr.cnf文件

[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn

[dn]
C=US
ST=New York
L=Rochester
O=End Point
OU=Testing Domain
emailAddress=your-administrative-address@your-awesome-existing-domain.com
CN = localhost

v3.ext文件

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost

5
可以添加更多细节吗?你导入了什么到Chrome?我按照相同的步骤操作,但仍然遇到错误。 - Joe Platano
我在创建证书时之前缺少的两个要素是:AKID(授权密钥标识符)- 选择与创建时使用的相同“CN =”。添加“基本约束”选项(不要选择“是CA”) 如果没有这两个要素,即使您已将自签名证书安装到MS-CAPI PKI信任存储中(作为“受信任的根机构”),Chrome也会发出警告/错误。 - atom88
它显示在最后一个命令上: CA证书和CA私钥不匹配 - Asif Mohammad Mollah

2

我使用的一个非常好用的基于Java的GUI实用程序叫做KeyStore Explorer,可以用来创建和操作所有PKI相关事项。比所有命令行选项都容易得多:

http://keystore-explorer.org/


0
我们之前遇到过这个问题,问题是前端和API服务器的地址不同。
前端托管在例如https://wrong.host.badssl.com,加载时会出现此错误。例如:

SSL error Chrome

所以在进一步操作之前,我们先进入网站。现在前端加载得很好,但是 API 调用失败,并在浏览器控制台上显示错误:net::ERR_CERT_AUTHORITY_INVALID

SSL chrome issue

原因是前端和API服务器都有无效的SSL证书。
以下两种解决方案都可行:
1. 使用相同的地址/域名/IP地址来设置前端和API服务器。 2. 在新标签页中打开API服务器,点击高级选项,继续访问SSL警告。

0
我是一名专业的翻译引擎,请将以下内容翻译成中文。请仅返回翻译后的文本,不要进行解释。

我纯属偶然发现了这个方法:如果您已经安装了 Fiddler 并让它在后台运行,那么第一次运行您的应用程序时会弹出一个证书问题的弹窗,如果您点击“是”,它将允许您的请求通过。请参见https://www.telerik.com/forums/fiddler-certificate-error-bypass-question


0
  1. 打开您的Chrome浏览器

  2. 在浏览器地址栏中输入以下链接并按Enter键。

    chrome://flags/#allow-insecure-localhost

  3. 将“允许从本地主机加载的资源使用无效证书”选项从“禁用”更改为“启用”。

希望您的问题得到解决。谢谢。


1
这非常不安全...它将允许所有欺骗网站。 - user1034912
删除浏览器的PKI验证是一个糟糕的主意。出于安全考虑,我不建议这样做。 - undefined

-1

尝试禁用所有浏览器扩展并检查问题是否已解决。在此输入图像描述


-1

只需更新您的Java(或根据您的系统架构(32位或64位)安装Java)。

安装后重新启动Chrome浏览器,然后它就可以正常工作了。

我长时间以来一直面临这个问题。我刚刚发现这个方法,对我很有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接