我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
当前回答
要在Windows中创建Chrome v58及更高版本将信任的自签名证书,请使用提升的权限启动Powershell并键入:
New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -Subject "fruity.local" -DnsName "fruity.local", "*.fruity.local" -FriendlyName "FruityCert" -NotAfter (Get-Date).AddYears(10)
#notes:
# -subject "*.fruity.local" = Sets the string subject name to the wildcard *.fruity.local
# -DnsName "fruity.local", "*.fruity.local"
# ^ Sets the subject alternative name to fruity.local, *.fruity.local. (Required by Chrome v58 and later)
# -NotAfter (Get-Date).AddYears(10) = make the certificate last 10 years. Note: only works from Windows Server 2016 / Windows 10 onwards!!
完成此操作后,证书将保存到个人\证书存储下的本地计算机证书中。
您要将此证书复制到受信任的根证书颁发机构\证书存储。
一种方法是:单击Windows开始按钮,然后键入certlm.msc。然后按照下面的屏幕截图将新创建的证书拖放到Trusted Root Certification Authority\Certificates存储区。
其他回答
修复Windows上的Chrome。
首先,您需要导出证书。
在浏览器中找到url。url的“https”段将为用红线划掉,左侧将有一个锁定符号。右键单击划掉的“https”段。您将看到一个包含各种信息的信息窗口单击“详细信息”。导出证书,按照说明接受默认设置。
要导入
转到Chrome设置单击“高级设置”在HTTPS/SSL下单击“管理证书”转到“受信任的根证书颁发机构”单击“导入”将出现一个弹出窗口,询问您是否要安装此证书。单击“是”。
我自己解决了这个问题,没有更改任何具有适当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
快乐编码!
我继续使用bjnord建议的方法,即:Google Chrome、Mac OS X和自签名SSL证书
博客中显示的内容不起作用。
然而,该博客的一条评论是金色的:
sudo安全添加可信证书-d-r trustRoot-k/Library/Keychains/Systemkeychain site.crt
你需要关注博客中关于如何获取cert文件的内容,然后你可以使用上面的命令,应该很好。
当单击URL旁边的小划掉的锁定图标时,您将看到一个如下所示的框:
单击证书信息链接后,您将看到以下对话框:
它告诉哪个证书存储是正确的,它是受信任的根证书颁发机构存储。
您可以使用其他答案中列出的方法之一将证书添加到该存储,也可以使用:
certutil -addstore -user "ROOT" cert.pem
ROOT是前面提到的证书存储的内部名称。cert.pem是自签名证书的名称。
只需要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