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

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


当前回答

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

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

在Google Chrome中安装证书

在Internet Explorer中安装证书

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

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

其他回答

我的解决方案和解释:

我有一个用IIS资源工具包工具SelfSSL.exe创建的自签名证书。在本地计算机上的证书列表中,我看到这个自签名证书只有一个用途:服务器身份验证。所以我创建了一个新的自签名证书,它有两个目的:服务器身份验证和客户端身份验证。现在Chrome不再抱怨了。

本文展示了许多生成自签名证书的方法。请注意,并非所有选项都允许您指定证书用途。我使用PowerShell的方式:

$cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname company.co.nz

注意:正如kellen Chrome的这个回答所述,它确实允许您设置证书的用途,但是IMO不能为证书添加新的用途,如果创建证书时没有考虑到这一点。

对于使用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上,如果您仍然获得无效证书,则下载证书并添加到密钥链,并使所有证书都可信。

我不得不调整macosx上的Chrome启动程序,并添加了以下脚本。保存如下:;

/应用程序/Google\Chrome.app/Contents/MacOS/Chrome.com命令

#!/bin/sh
RealBin="Google Chrome"
AppDir="$(dirname "$0")"
exec "$AppDir/$RealBin" --ignore-certificate-errors "$@"

当我用这个脚本启动Chrome时,自签名证书可以正常工作。但是,不要使用使用此脚本启动的浏览器浏览网页,您将不会收到有关无效证书的警告!

这是一个不断出现的东西——尤其是在Mac OS X Yosemite上的谷歌Chrome!

谢天谢地,我们的一个开发团队今天向我发送了这个链接,该方法工作可靠,同时仍然允许您控制接受证书的站点。

https://www.reddit.com/r/sysadmin/comments/3ercx4/chrome_shortcut_past_the_your_connection_is_not/cthporl

jersully帖子:

如果您不想麻烦内部证书。。。类型chrome://flags/在地址栏中。滚动到或搜索“记住决策”以在指定的时间长度内继续处理SSL错误。选择“记住三个月”。

在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