我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
当前回答
对于使用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上,如果您仍然获得无效证书,则下载证书并添加到密钥链,并使所有证书都可信。
其他回答
在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
只需要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
对于使用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上,如果您仍然获得无效证书,则下载证书并添加到密钥链,并使所有证书都可信。
更新11/2017:这个答案可能不适用于大多数较新版本的Chrome。更新02/2016:Mac用户的更好说明可以在这里找到。
在要添加的站点上,右键单击地址栏中的红色锁定图标:单击标记为“连接”的选项卡,然后单击“证书信息”单击“详细信息”选项卡,然后单击“复制到文件…”按钮。。。。这将打开证书导出向导,单击下一步进入导出文件格式屏幕。选择DER编码二进制X.509(.CER),单击“下一步”单击浏览。。。并将文件保存到计算机。给它起个描述性的名字。单击下一步,然后单击完成。打开Chrome设置,滚动到底部,然后单击显示高级设置。。。在HTTPS/SSL下,单击管理证书。。。单击受信任的根证书颁发机构选项卡,然后单击导入。。。按钮这将打开证书导入向导。单击“下一步”进入“要导入的文件”屏幕。单击浏览。。。并选择先前保存的证书文件,然后单击“下一步”。选择将所有证书放置在以下存储中。所选存储应为受信任的根证书颁发机构。如果不是,请单击浏览。。。然后选择它。单击“下一步”并完成单击安全警告上的“是”。重新启动Chrome。
这对我有用。请参见:http://www.robpeck.com/2010/10/google-chrome-mac-os-x-and-self-signed-ssl-certificates/#.Vcy8_ZNVhBc
在地址栏中,单击带有X的小锁。这将显示一个小信息屏幕。单击显示“证书信息”的按钮
单击并将图像拖到桌面。它看起来像一个小证书。
双击它。这将打开Keychain Access实用程序。输入密码以解锁。
确保将证书添加到系统密钥链,而不是登录密钥链。单击“始终信任”,即使这似乎没有任何作用。
添加后,双击它。您可能需要再次进行身份验证。
展开“信任”部分。
“使用此证书时,”设置为“始终信任”