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

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


当前回答

在这里,我的WINDOWS解决方案可能适用于LINUX

Git有openssl

C: \Program Files\Git\usr\bin\openssl.exe。

导航到C:\Program Files\Git\user\bin\,但最好添加到PATH

为证书创建文件夹创建文件req.cnf像我的公司一样改变价值观不要删除subjectAltName=@alt_names[备选名称]DNS.1=本地主机Chrome抱怨

C=CA CA是两个字母国家代码CA=加拿大、美国。。。ST=ON是安大略省

请求cnf

[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = CA
ST = ON
L = Toronto
O = MyCompany
OU = MyDivision
CN = localhost
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost 
DNS.2 = www.mydomainname.com
DNS.3 = mydomainname.com

在CMD中创建证书

 openssl req -x509 -nodes -days 365 -newkey rsa:2048  -keyout server.key -out server.crt -config req.cnf -sha256

 cat server.crt server.key > server.pem

覆盖dev证书

 yourproject\node_modules\webpack-dev-server\ssl   with the **server.pem**

在chrome设置->管理证书

将server.crt导入到受信任的认证授权重新启动chrome

在package.json中

 "scripts": {
    "start": "set HTTPS=true&&react-scripts start",

其他回答

对于MacOS上的Chrome,如果您准备了证书:

退出Chrome(cmd+Q)。启动Keychain Access应用程序并打开“证书”类别。将证书文件拖到Keychain Access窗口上,然后键入证书文件的密码。双击证书并展开“信任”列表。在“使用此证书时”行中,选择“始终信任”关闭此内容并键入密码。启动Chrome并清除所有缓存。检查一切是否正常。

我继续使用bjnord建议的方法,即:Google Chrome、Mac OS X和自签名SSL证书

博客中显示的内容不起作用。

然而,该博客的一条评论是金色的:

sudo安全添加可信证书-d-r trustRoot-k/Library/Keychains/Systemkeychain site.crt

你需要关注博客中关于如何获取cert文件的内容,然后你可以使用上面的命令,应该很好。

您确定站点的地址与证书相同吗?我对Chrome和自签名证书也有同样的问题,但最后我发现它对证书上域名的验证非常挑剔(应该如此)。

Chrome没有自己的证书存储,而是使用Windows自己的证书。然而,Chrome不提供将证书导入商店的方法,因此您应该通过IE添加证书。

在Google Chrome中安装证书

在Internet Explorer中安装证书

还可以看看这两种不同的创建自签名证书的方法(我假设您使用的是您没有提到的IIS)。

如何在IIS 7中创建自签名证书

我自己解决了这个问题,没有更改任何具有适当SSL证书的浏览器上的设置。我使用的是mac,所以需要对我的ssl证书进行密钥链更新。我不得不在ssl认证中添加主题alt名称,以便chrome接受它

我的示例很容易使用命令和配置文件:

添加这些文件,这个示例都在一个根目录中

ssl.conf文件

[ req ]
default_bits       = 4096
distinguished_name = req_distinguished_name
req_extensions     = req_ext

[ req_distinguished_name ]
countryName                 = Country Name (2 letter code)
stateOrProvinceName         = State or Province Name (full name)
localityName                = Locality Name (eg, city)
organizationName            = Organization Name (eg, company)
commonName                  = Common Name (e.g. server FQDN or YOUR name)
commonName_max              = 64

[ req_ext ]
subjectAltName = @alt_names

[alt_names]
DNS.1   = localhost

运行命令以创建证书:

openssl req -newkey rsa:4096 -nodes -keyout key.pem -x509 -days 3650 -out certificate.pem -extensions req_ext -config ssl.conf -subj '/CN=localhost/O=Stackflow/C=US/L=Los Angeles/OU=StackflowTech'

对于仅添加可信证书的Mac(必需):

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./certificate.pem

对于windows,您必须找到如何在本地独立验证我们的ssl证书。我不使用Windows。对不起,窗户的男男女女。

我使用的是带有express.js的node.js服务器,只需要我的密钥和证书,如下所示:

应用程序.js

const https = require('https');
const Express = require('express');
const fs = require('fs');
const app = new Express();
const server = https.createServer({
    key: fs.readFileSync('./key.pem'),
    cert: fs.readFileSync('./certificate.pem'),
}, app);
server.listen(3000);

我可能会在将来为其他后端框架执行此操作,因此我可以在将来为其它框架更新此示例。但这是我在Node.js中解决的问题。清除浏览器缓存并在https上运行应用程序://

下面是一个跑步的例子https://localhost在Mac用户的Node.js服务器上:

https://github.com/laynefaler/Stack-Overflow-running-HTTPS-localhost

快乐编码!

这篇文章已经得到了大量的响应,但我基于其他一些答案创建了一个bash脚本,以便更容易生成在Chrome中有效的自签名TLS证书(在Chrome65.x中测试)。希望它对其他人有用。

自签名tls-bash脚本

安装(并信任)证书后,不要忘记重新启动Chrome(chrome://restart)


另一个值得一看的工具是CloudFlare的cfssl工具包:

cfssl