我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让Chrome接受证书并停止抱怨?
我已经为localhostCN创建了一个自签名的SSL证书。正如预期的那样,Firefox在最初抱怨后接受了这个证书。然而,Chrome和IE拒绝接受它,即使在将证书添加到Trusted Roots下的系统证书存储之后。尽管当我在Chrome的HTTPS弹出窗口中单击“查看证书信息”时,证书被列为正确安装,但它仍然坚称证书不可信。
我该怎么做才能让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
其他回答
从Chrome 58+开始,由于缺少SAN,我开始在macOS上获取证书错误。下面是如何再次获得地址栏上的绿色锁。
使用以下命令生成新证书:openssl请求\-新密钥rsa:2048\-2009年5月\-节点\-keyout服务器.key\-新的\-输出服务器.crt\-subj/CN=*.domain.dev\-请求SAN\-扩展SAN\-配置<(cat/System/Library/OpenSSL/OpenSSL.cnf\<(printf'[SAN]\nobjectAltName=DNS:*.domain.dev'))\-沙256\-720天将server.crt导入KeyChain,然后双击证书,展开“信任”,然后选择“始终信任”
刷新页面https://domain.dev在Google Chrome中,绿色锁又回来了。
正如有人指出的,你需要重启所有的Chrome,而不仅仅是浏览器窗口。最快的方法是打开一个选项卡。。。
chrome://restart
只需要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
在Mac上,您可以使用Keychain Access实用程序将自签名证书添加到系统密钥链,然后Chrome将接受它。我在这里找到了分步说明:
Google Chrome、Mac OS X和自签名SSL证书
基本上:
双击带有X的锁定图标并将证书图标拖放到桌面,打开此文件(以.cer扩展名结尾);这将打开允许您批准证书的密钥链应用程序。
我也遇到了同样的问题:我已将证书安装到Windows的Trusted Root Authorities存储中,但Chrome仍然拒绝证书,错误为ERR_CERT_COMMON_NAME_INVALID。请注意,当证书未正确安装在存储中时,错误为ERR_CERT_AUTHORITY_INVALID。
正如错误名称、此注释和此问题所暗示的,问题在于证书中声明的域名。当生成证书时提示输入“CommonName”时,我必须输入用于访问站点的域名(在我的情况下是localhost)。我使用重新启动了Chromechrome://restart它终于对这个新证书感到满意。