小编典典

让 Chrome 接受自签名的本地主机证书

javascript

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

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


阅读 643

收藏
2022-02-22

共2个答案

小编典典

localhost只为

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

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

您应该会看到突出显示的文本: Allow invalid certificate for resources loaded from localhost

单击Enable

-要么-

尝试在窗口的任何位置输入: thisisunsafe ,浏览器*应该*让您访问该页面。[关联]

-要么-

对于避免神秘命令、专业知识和手动步骤的本地自签名证书,请尝试mkcert

2022-02-22
小编典典

只需5 个*命令, openssl*您就可以完成此操作。

请不要更改您的浏览器安全设置。

使用以下代码,您可以 (1) 成为您自己的 CA,(2) 然后将您的 SSL 证书签署为 CA。(3) 然后将 CA 证书(不是 SSL 证书,它进入您的服务器)导入 Chrome/Chromium。(是的,这甚至适用于 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.com # 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

回顾一下:

  1. 成为 CA
  2. 使用您的 CA 证书+密钥签署您的证书
  3. 在 Chrome 设置(设置 > 管理证书 > 权限 >导入)中myCA.pem作为“权限”(而不是“您的证书”)导入
  4. 使用服务器中的$NAME.crt$NAME.key文件

额外步骤(至少对于 Mac):

  1. 在“文件 > 导入文件”中导入 CA 证书,然后在列表中找到它,右键单击它,展开“>信任”,然后选择“始终”
  2. extendedKeyUsage=serverAuth,clientAuth在下面添加basicConstraints=CA:FALSE,并确保将“CommonName”设置为与$NAME要求设置时相同

您可以检查您的工作以确保正确构建证书:

openssl verify -CAfile myCA.pem -verify_hostname bar.mydomain.com mydomain.com.crt
2022-02-22