谷歌浏览器中的“导入证书时私钥丢失或无效”

Mac*_*zyk 45 linux google-chrome certificate ssl

我想在 https localhost 上测试我的网络应用程序。不幸的是,似乎不可能从 chrome 中删除证书警告。首先,我生成了这样的证书:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/localhost-selfsigned.key -out /etc/ssl/certs/localhost-selfsigned.crt
Run Code Online (Sandbox Code Playgroud)

然后我想将它添加到 Chrome,设置 > 高级 > 管理证书 - > 导入。我尝试导入之前生成的 .crt 文件,我得到的只是:

证书导入错误:此客户端证书的私钥丢失或无效。

我用谷歌搜索它,但我发现没有任何帮助。

我还尝试启用 allow-insecure-localhost 标志并打开 chrome with--ignore-certificate-errors但它仍然显示警告和损坏的 https

还有其他方法还是我在证书上做错了什么?

Eri*_*rik 63

我认为您可能想要做的是将其添加到错误的证书存储中。如果您尝试将其添加到“您的证书”下,那您会过得很不愉快。该选项卡用于添加身份证书;您的浏览器向服务器提供的内容以建立浏览器的身份。

根据您的描述,我认为您想要做的是您希望您的浏览器信任将在您的服务器端的自签名证书。如果是这种情况,您需要将其添加到“权限”选项卡中。

  • 这适用于 Chrome v64。正如@Erik 指出的那样,您在“权限”选项卡下导入 .crt。注意:FireFox 不会给你这个麻烦 (5认同)
  • chrome 中的“权威”标签在哪里?看不到任何导入证书或 .pem 的方法。谢谢, (3认同)
  • 权限选项卡用于 CA 证书。非 CA 证书应该在服务器选项卡上。尽管您 [不能](https://bbs.archlinux.org/viewtopic.php?pid=1776753#p1776753),例如,在 Chromium 65.0.3325.162 中手动添加非 CA 证书。 (2认同)
  • 通过“权限”选项卡导入解决了我的问题。 (2认同)

omu*_*apa 6

对我有用的是

  • 设立CA
  • 使用此 CA 签署我自己的证书,然后
  • 将 CA 密钥导入 Chrome(权威机构)。

我从这个答案中得到了程序。

由于我的具体问题是为了满足多级子域的需求,因此我将从这个角度来看待它。

子域:

  • bar.fooz.mydomain.com
  • foo.fooz.mydomain.com
  1. 成为证书颁发机构
export CA=myca
# you probably want to have this in its own directory
mdkir /etc/ssl/$CA && cd /etc/ssl/$CA

# generate private key
openssl genrsa -des3 -out $CA.key 2048

# generate root certificate
openssl req -x509 -new -nodes -key $CA.key -sha256 -days 825 -out $CA.pem
Run Code Online (Sandbox Code Playgroud)
  1. 创建 CA 签名的证书
export NAME=fooz.mydomain.com
# if CA files were in a separate directory
cd .. && mkdir /etc/ssl/$NAME && cd /etc/ssl/$NAME

# generate private key
openssl genrsa -out $NAME.key 2048

# Create a certificate-signing request
# Once prompted, set FQDN to the value of $NAME
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
# Optionally, add additional domains (I've added a subdomain here)
DNS.2 = foo.$NAME
DNS.3 = bar.$NAME
IP.1 = 192.168.0.13 # (Optional, but probably important), 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 $CA.pem -CAkey $CA.key -CAcreateserial -out $NAME.crt -days 825 -sha256 -extfile $NAME.ext
Run Code Online (Sandbox Code Playgroud)
  1. 下载$CA.pem文件并在浏览器中以权威身份导入:
    1. Chrome settings (Settings > Privacy and Security > Security > Manage certificates > Authorities > Import). Check Trust this certificate for identifying websites
    2. Firefox: Preferences > Privacy and Security > Certificates > View Certificates > Authorities > import. Check Trust this CA to identify websites
Run Code Online (Sandbox Code Playgroud)
  1. 重新启动浏览器(Firefox 无需重新启动即可工作)