LocalHost 上的自签名证书出现 Chrome NET::ERR_CERT_AUTHORITY_INVALID 错误

问题描述 投票:0回答:9

我正在尝试在本地 PC 上设置开发环境。由于生产网站支持 HTTPS(现在谁不支持?),我也希望在本地主机上也支持 HTTPS。我以为这会很容易,但事实并非如此。

我安装了 XAMP,并进行了所有设置,以便我可以访问该网站。但是,每当我在本地访问网站上的任何页面时,我都会收到 chrome 警告:

NET::ERR_CERT_AUTHORITY_INVALID

我确实按照以下线程尝试解决它:

让 Chrome 接受自签名本地主机证书

我还基于此使用正确的主题备用名称 (SAN) 部分创建了证书:

https://deliciousbrains.com/https-locally-without-browser-privacy-errors/

之后,我生成了 CER 或 P7B 文件并将其导入 Chrome。我重新启动了 Apache 和 Chrome。

我将证书放在受信任的根证书颁发机构中。不知何故,Chrome 决定将其放置在中间根证书颁发机构中......

我使用的是 Chrome 61,我在 60 中也有同样的。

因此,我无法安装自签名证书,并不断收到此警告,这基本上使得在本地主机上进行开发变得不可能......

我明白这种自签名并不完全可信,但一定有办法线下发展吧?从现在开始我们必须在线建立网站,这没有意义吗?...

有什么想法吗?

google-chrome ssl ssl-certificate
9个回答
40
投票

我们可以简单地在 Chrome 中允许无效证书用于开发目的。

这只对本地主机有效

将其粘贴到 Chrome 地址栏中:

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

然后启用突出显示的文本:允许从本地主机加载的资源使用无效证书


8
投票

以下是我使用 KeyStore Explorer 工具的说明。 我之前创建证书时缺少的两件事是:

  • 添加
    Authority Key Identifier
    (或
    AKID
    ),选择与创建时使用的相同的
    CN=<certificate_name>
  • 添加
    Basic Constraints
    选项(不要选择“是CA”)

如果没有这两件事,Chrome 将会发出警告/错误 即使您已将自签名证书安装到 MS-CAPI PKI 信任存储中(作为

Trusted Root Authority
)。

步骤:

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

7
投票

我在this之后修复了完全相同的问题。

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

下面的代码来自上述网站。

#!/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

server.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-adminis[email protected]
CN = localhost

v3.ext 文件

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

[alt_names]
DNS.1 = localhost

2
投票

有一个很棒的基于 Java 的 GUI 实用程序,我用它来创建和操作 PKI 的所有内容,称为 KeyStore Explorer。比所有命令行选项简单得多:

http://keystore-explorer.org/


1
投票
  1. 打开 Chrome 浏览器

  2. 将以下链接放入浏览器地址栏中,然后按 Enter。

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

  3. 选择“允许从本地主机加载的资源使用无效证书”。禁用到启用。

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


0
投票

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


0
投票

只需更新您的java(或安装java取决于您的系统架构(32或64位))。

安装完成后重启chrome浏览器即可正常使用。

我已经面对这个问题很长时间了。我刚刚发现这个,它对我有用。


0
投票

尝试禁用所有浏览器扩展并检查问题是否解决。


0
投票

我们之前就遇到过这个问题,问题是前端和API服务器的地址不同。

前端托管在例如

https://wrong.host.badssl.com
加载时会出现此错误。例如:

因此,我们提前前往现场。现在前端加载正常,但 API 调用失败并出现以下错误:浏览器控制台上的

net::ERR_CERT_AUTHORITY_INVALID

原因是前端和API服务器不同,都具有无效的SSL证书。

以下 2 个解决方案中的任何一个都可以:

  1. 前端和 API 服务器使用相同的地址/域/IP 地址
  2. 在新选项卡中打开 API 服务器,然后单击“高级”并继续处理 SSL 警告
© www.soinside.com 2019 - 2024. All rights reserved.