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

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


当前回答

WINDOWS 2017年6月WINDOWS Server 2012

我听从了布拉德·帕克斯的回答。在Windows上,您应该在受信任的根证书颁发机构存储中导入rootCA.pem。

我执行了以下步骤:

openssl genrsa -out rootCA.key 4096
openssl req -x509 -new -nodes -key rootCA.key -newkey rsa:4096 -sha256 -days 1024 -out rootCA.pem
openssl req -new -newkey rsa:4096 -sha256 -nodes -keyout device.key -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 2000 -sha256 -extfile v3.ext

其中v3.ext为:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
IP.1 = 192.168.0.2
IP.2 = 127.0.0.1

然后,在我的例子中,我有一个自托管的web应用程序,所以我需要将证书与IP地址和端口绑定,证书应该在我的存储库中,并带有私钥信息,所以我导出为pfx格式。

openssl pkcs12 -export -out device.pfx -inkey device.key -in device.crt

使用mmc控制台(文件/添加或删除管理单元/证书/添加/计算机帐户/本地计算机/确定),我在个人存储中导入了pfx文件。

后来我使用这个命令绑定证书(您也可以使用HttpConfig工具):

netsh http add sslcert ipport=0.0.0.0:12345 certhash=b02de34cfe609bf14efd5c2b9be72a6cb6d6fe54 appid={BAD76723-BF4D-497F-A8FE-F0E28D3052F4}

certhash=证书Thumprint

appid=GUID(您的选择)

首先,我尝试以不同的方式在受信任的根证书颁发机构上导入证书“device.crt”,但仍然收到相同的错误:

但我意识到我应该导入根权限的证书,而不是域的证书。所以我使用mmc控制台(文件/添加或删除管理单元/证书/添加/计算机帐户/本地计算机/OK),在受信任的根证书颁发机构存储中导入了rootCA.pem。

重新启动Chrome,它就可以工作了。

使用localhost:

或IP地址:

我唯一做不到的是,它有过时的密码(图片上的红色方框)。在这一点上,我们非常感谢帮助。

使用makecert,无法添加SAN信息。使用NewSelfSignedCertificate(Powershell),您可以添加SAN信息,它也可以工作。

其他回答

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

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

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

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

仅适用于本地主机

只需将其粘贴到您的铬中:

chrome://flags/#allow-insecure-localhost

您应该看到突出显示的文本:

允许从本地主机加载的资源的证书无效

单击启用。

其他站点

尝试在窗口的任何位置键入thisisnsafe,浏览器将允许您访问该页面。

-OR-

对于本地自签名证书,可以避免晦涩难懂的命令、专门知识和手动步骤,请尝试从这个答案中选择mkcert。

在这里,我的WINDOWS解决方案可能适用于LINUX

Git有openssl

C: \Program Files\Git\usr\bin\openssl.exe。

导航到C:\Program Files\Git\user\bin\,但最好添加到PATH

为证书创建文件夹创建文件req.cnf像我的公司一样改变价值观不要删除subjectAltName=@alt_names[备选名称]DNS.1=本地主机Chrome抱怨

C=CA CA是两个字母国家代码CA=加拿大、美国。。。ST=ON是安大略省

请求cnf

[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = CA
ST = ON
L = Toronto
O = MyCompany
OU = MyDivision
CN = localhost
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost 
DNS.2 = www.mydomainname.com
DNS.3 = mydomainname.com

在CMD中创建证书

 openssl req -x509 -nodes -days 365 -newkey rsa:2048  -keyout server.key -out server.crt -config req.cnf -sha256

 cat server.crt server.key > server.pem

覆盖dev证书

 yourproject\node_modules\webpack-dev-server\ssl   with the **server.pem**

在chrome设置->管理证书

将server.crt导入到受信任的认证授权重新启动chrome

在package.json中

 "scripts": {
    "start": "set HTTPS=true&&react-scripts start",

只需要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

我刚刚在我的chrome中启用了允许不安全的localhost标志,就这样。

步骤。

类型chrome://flags在您的铬标签中。搜索允许不安全的本地主机标志并启用它。重新启动chrome浏览器。

现在,您将不会看到不安全的警告https://localhost地点。