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

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


当前回答

通过此方法允许不安全的本地主机正常工作chrome://flags/#allow-不安全的本地主机

只需要将开发主机名创建为xxx.localhost。

其他回答

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
)

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

您应该使用以下项创建PKI:;

自签名根CA。子/中间证书[由根CA签署]。正常/最终实体证书[由根CA或子CA签名]commonName或subjectAltName(SAN)作为“localhost”。还包括https://localhost/作为SAN中的URI。将该根CA作为“受信任的根证书颁发机构”导入/安装到Windows操作系统中。因为你提到了IE:Google Chrome在寻找证书链时使用了相同的资源。将该最终实体证书安装为您的web服务器证书,它将停止抱怨该错误消息。

希望这有帮助。

好的,假设你已经创建了一个“有效”的自签名证书。它正确安装在chrome ver 94上。但是当您访问该站点时,您不会得到ssl锁,并且会出现“无效的证书颁发机构”错误。事实上,它是一个有效的证书。但是如果你没有正确浏览网站,你会收到这个错误。我的证书的DNS是DNS1:TFDM,DNS2:TFDM.local,DNS3:172.31.42.251,DNS4:192.168.20.50。

我正在浏览192.168.20.50,它不安全(锁定)。问题是,证书是针对DNS1:TFDM的。因此,我必须输入/etc/hosts文件(centos7)192.168.20.50 TFDM进行解析,然后浏览https://TFDM.问题已解决。您必须正确浏览网站。我以为它会在服务器端解决,但必须在客户端解决。这很容易被忽视,如果其他一切都正确,这可能是你的问题。覆盖安全性和ssl功能会带来麻烦,我认为没有合适的解决方案。如果应用正确,并且遵循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

在这里,我的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",