我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
当前回答
这对我有用。请参见:http://www.robpeck.com/2010/10/google-chrome-mac-os-x-and-self-signed-ssl-certificates/#.Vcy8_ZNVhBc
在地址栏中,单击带有X的小锁。这将显示一个小信息屏幕。单击显示“证书信息”的按钮
单击并将图像拖到桌面。它看起来像一个小证书。
双击它。这将打开Keychain Access实用程序。输入密码以解锁。
确保将证书添加到系统密钥链,而不是登录密钥链。单击“始终信任”,即使这似乎没有任何作用。
添加后,双击它。您可能需要再次进行身份验证。
展开“信任”部分。
“使用此证书时,”设置为“始终信任”
其他回答
对于使用NX的带有Angular Micro前端的mac
步骤1:创建自签名根证书
openssl req -x509 -nodes -new -sha256 -days 390 -newkey rsa:2048 -keyout "RootCA.key" -out "RootCA.pem" -subj "/C=de/CN=localhost.local"
openssl x509 -outform pem -in "RootCA.pem" -out "RootCA.crt"
步骤2:定义应包含在证书中的域和子域
为此,只需创建一个名为vhosts_domains.ext的文本文件并插入以下内容:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = *.mixable.blog.local
DNS.3 = mixable.blog.local
此示例包括域mixeble.blog.local的本地开发环境的子域以及所有子域,如www.mixable.blog.loal或apps.mixeble.blog.local。
步骤3:创建证书
openssl req -new -nodes -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/C=de/ST=State/L=City/O=Organization/CN=localhost.local"
openssl x509 -req -sha256 -days 1024 -in localhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile vhosts_domains.ext -out localhost.crt
步骤4:使证书可用于Angular应用程序
nx serve host --open --devRemotes=<app names> --ssl --ssl-key <folder_location>/localhost.key --ssl-cert <folder_location>/localhost.crt
步骤5:将证书从导入添加到macOS密钥链
在chrome上,如果您仍然获得无效证书,则下载证书并添加到密钥链,并使所有证书都可信。
我自己解决了这个问题,没有更改任何具有适当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
快乐编码!
在Mac上,您可以通过执行以下操作创建一个在系统级别完全受Chrome和Safari信任的证书:
# create a root authority cert
./create_root_cert_and_key.sh
# create a wildcard cert for mysite.com
./create_certificate_for_domain.sh mysite.com
# or create a cert for www.mysite.com, no wildcards
./create_certificate_for_domain.sh www.mysite.com www.mysite.com
上面使用了以下脚本和支持文件v3.ext,以避免主题替代名称丢失错误
如果您想使用自己的根权限创建一个完全受信任的新的自签名证书,可以使用这些脚本。
创建root_cert_and_key.sh
#!/usr/bin/env bash
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
为域.sh创建证书
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "Please supply a subdomain to create a certificate for";
echo "e.g. www.mysite.com"
exit;
fi
if [ ! -f rootCA.pem ]; then
echo 'Please run "create_root_cert_and_key.sh" first, and try again!'
exit;
fi
if [ ! -f v3.ext ]; then
echo 'Please download the "v3.ext" file and try again!'
exit;
fi
# Create a new private key if one doesnt exist, or use the xeisting one if it does
if [ -f device.key ]; then
KEY_OPT="-key"
else
KEY_OPT="-keyout"
fi
DOMAIN=$1
COMMON_NAME=${2:-*.$1}
SUBJECT="/C=CA/ST=None/L=NB/O=None/CN=$COMMON_NAME"
NUM_OF_DAYS=825
openssl req -new -newkey rsa:2048 -sha256 -nodes $KEY_OPT device.key -subj "$SUBJECT" -out device.csr
cat v3.ext | sed s/%%DOMAIN%%/"$COMMON_NAME"/g > /tmp/__v3.ext
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days $NUM_OF_DAYS -sha256 -extfile /tmp/__v3.ext
# move output files to final filenames
mv device.csr "$DOMAIN.csr"
cp device.crt "$DOMAIN.crt"
# remove temp file
rm -f device.crt;
echo
echo "###########################################################################"
echo Done!
echo "###########################################################################"
echo "To use these files on your server, simply copy both $DOMAIN.csr and"
echo "device.key to your webserver, and use like so (if Apache, for example)"
echo
echo " SSLCertificateFile /path_to_your_files/$DOMAIN.crt"
echo " SSLCertificateKeyFile /path_to_your_files/device.key"
v3.ext版本
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = %%DOMAIN%%
另一步-如何在Chrome/Safari中完全信任自签名证书
若要在Chrome和Safari中完全信任自签名证书,您需要将新的证书颁发机构导入Mac。要做到这一点,请遵循以下说明或mitmproxy网站上有关此一般流程的更详细说明:
您可以在命令行使用以下两种方法之一执行此操作,该命令将提示您输入密码:
$ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
或使用Keychain Access应用程序:
打开钥匙链访问在“钥匙链”列表中选择“系统”在“类别”列表中选择“证书”选择“文件|导入项目…”浏览到上面创建的文件“rootCA.pem”,选择它,然后单击“打开”在“证书”列表中选择新导入的证书。单击“i”按钮,或右键单击证书,然后选择“获取信息”展开“信任”选项将“使用此证书时”更改为“始终信任”关闭对话框,系统将提示您输入密码。关闭并重新打开使用目标域的所有选项卡,它将被安全加载!
另外,如果您需要java客户端信任证书,可以通过将证书导入到java密钥库来实现。注意,如果证书已经存在,这将从密钥库中删除证书,因为它需要在情况发生变化时更新它。当然,它只对正在导入的证书执行此操作。
import_certs_in_current_folder_into_java_keystore.sh
KEYSTORE="$(/usr/libexec/java_home)/jre/lib/security/cacerts";
function running_as_root()
{
if [ "$EUID" -ne 0 ]
then echo "NO"
exit
fi
echo "YES"
}
function import_certs_to_java_keystore
{
for crt in *.crt; do
echo prepping $crt
keytool -delete -storepass changeit -alias alias__${crt} -keystore $KEYSTORE;
keytool -import -file $crt -storepass changeit -noprompt --alias alias__${crt} -keystore $KEYSTORE
echo
done
}
if [ "$(running_as_root)" == "YES" ]
then
import_certs_to_java_keystore
else
echo "This script needs to be run as root!"
fi
修复Windows上的Chrome。
首先,您需要导出证书。
在浏览器中找到url。url的“https”段将为用红线划掉,左侧将有一个锁定符号。右键单击划掉的“https”段。您将看到一个包含各种信息的信息窗口单击“详细信息”。导出证书,按照说明接受默认设置。
要导入
转到Chrome设置单击“高级设置”在HTTPS/SSL下单击“管理证书”转到“受信任的根证书颁发机构”单击“导入”将出现一个弹出窗口,询问您是否要安装此证书。单击“是”。
这篇文章已经得到了大量的响应,但我基于其他一些答案创建了一个bash脚本,以便更容易生成在Chrome中有效的自签名TLS证书(在Chrome65.x中测试)。希望它对其他人有用。
自签名tls-bash脚本
安装(并信任)证书后,不要忘记重新启动Chrome(chrome://restart)
另一个值得一看的工具是CloudFlare的cfssl工具包:
cfssl