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

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


当前回答

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

这对我有用:

使用Chrome,通过HTTPS点击服务器上的一个页面,然后继续浏览红色警告页面(假设你还没有这样做)。打开Chrome设置>显示高级设置>HTTPS/SSL>管理证书。单击“颁发机构”选项卡,然后向下滚动以在您为证书提供的“组织名称”下查找您的证书。选择它,单击“编辑”(注意:在最新版本的Chrome中,该按钮现在是“高级”而不是“编辑”),选中所有框并单击“确定”。您可能需要重新启动Chrome。

你现在应该在你的页面上获得漂亮的绿色锁。

编辑:我在新计算机上再次尝试了此操作,但仅从红色的不受信任证书页面继续,证书就没有显示在“管理证书”窗口中。我必须做到以下几点:

在具有不受信任证书的页面(https://用红色划掉)上,单击锁>证书信息。注意:在较新版本的chrome上,您必须打开“开发人员工具”>“安全”,然后选择“查看证书”。单击“详细信息”选项卡>“导出”。选择PKCS#7,单一证书作为文件格式。然后按照我的原始说明进入“管理证书”页面。单击“权限”选项卡>“导入”,然后选择将证书导出到的文件,并确保选择PKCS#7,单一证书作为文件类型。如果提示证书存储,请选择受信任的根证书颁发机构选中所有复选框并单击“确定”。重新启动Chrome。

mkdir CA
openssl genrsa -aes256 -out CA/rootCA.key 4096
openssl req -x509 -new -nodes -key CA/rootCA.key -sha256 -days 1024 -out CA/rootCA.crt

openssl req -new -nodes -keyout example.com.key -out domain.csr -days 3650 -subj "/C=US/L=Some/O=Acme, Inc./CN=example.com"
openssl x509 -req -days 3650 -sha256 -in domain.csr -CA CA/rootCA.crt -CAkey CA/rootCA.key -CAcreateserial -out example.com.crt -extensions v3_ca -extfile <(
cat <<-EOF
[ v3_ca ]
subjectAltName = DNS:example.com
EOF
)

Linux系统

如果您使用的是Linux,也可以关注以下官方wiki页面:

在Linux上配置SSL证书。NSS共享数据库和LINUXNSS共享数据库如何

基本上:

单击带有X的锁定图标,选择证书信息转到“详细信息”选项卡单击导出。。。(另存为文件)

现在,以下命令将添加证书(其中YOUR_FILE是导出的文件):

certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n YOUR_FILE -i YOUR_FILE

要列出所有证书,请运行以下命令:

certutil -d sql:$HOME/.pki/nssdb -L

如果它仍然不起作用,您可能会受到此错误的影响:问题55050:Ubuntu SSL错误8179

另外,在使用上述命令之前,请确保您拥有libnss3工具。

如果没有,请通过以下方式安装:

sudo apt-get install libnss3-tools # on Ubuntu
sudo yum install nss-tools # on Fedora, Red Hat, etc.

另外,您可以使用以下方便的脚本:

$ cat add_cert.sh
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n $1 -i $1
$ cat list_cert.sh
certutil -d sql:$HOME/.pki/nssdb -L # add '-h all' to see all built-in certs
$ cat download_cert.sh
echo QUIT | openssl s_client -connect $1:443 | sed -ne '/BEGIN CERT/,/END CERT/p'

用法:

add_cert.sh [FILE]
list_cert.sh
download_cert.sh [DOMAIN]

故障排除

使用--auto-ssl客户端身份验证参数运行Chromegoogle chrome--自动ssl客户端身份验证

这是一个不断出现的东西——尤其是在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错误。选择“记住三个月”。