我是 ASP.NET 新手。
环境:
乌班图18.04
视觉工作室代码
.NET SDK 2.2.105
我在运行某些命令时遇到麻烦。
我正在阅读教程
并运行这个命令:
dotnet dev-certs https --trust
我预计https://本地主机应该值得信赖。
但我发现了错误信息;
$ Specify --help for a list of available options and commands.
似乎命令“dotnet dev-certs https”没有 --trust 选项。
如何解决这个问题?
在 Ubuntu 上standard机制是:
-
dotnet dev-certs https -v
生成自签名证书
- 使用以下命令将 ~/.dotnet/corefx/cryptography/x509stores/my 中生成的证书从 pfx 转换为 pem
openssl pkcs12 -in <certname>.pfx -nokeys -out localhost.crt -nodes
- copy
localhost.crt
to /usr/local/share/ca-certificates
- 使用信任证书
sudo update-ca-certificates
- 验证证书是否已复制到
/etc/ssl/certs/localhost.pem
(扩展名更改)
- 使用验证它是否可信
openssl verify localhost.crt
不幸的是,这不起作用:
-
dotnet dev-certs https
生成受上述问题影响的证书https://github.com/openssl/openssl/issues/1418 and https://github.com/dotnet/aspnetcore/issues/7246:
$ openssl verify localhost.crt
CN = localhost
error 20 at 0 depth lookup: unable to get local issuer certificate
error localhost.crt: verification failed
解决方法:(在 Openssl 1.1.1c 上测试)
- 手动生成自签名证书
- 信任这个证书
- 强制您的应用程序使用此证书
详细地:
-
手动生成自签名证书:
- 创建包含以下内容的 localhost.conf 文件:
[req]
default_bits = 2048
default_keyfile = localhost.key
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_ca
[req_distinguished_name]
commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = localhost
commonName_max = 64
[req_ext]
subjectAltName = @alt_names
[v3_ca]
subjectAltName = @alt_names
basicConstraints = critical, CA:false
keyUsage = keyCertSign, cRLSign, digitalSignature,keyEncipherment
[alt_names]
DNS.1 = localhost
DNS.2 = 127.0.0.1
- 使用生成证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -config localhost.conf
- 使用将 cert 转换为 pfx
openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crt
- (可选)使用验证证书
openssl verify -CAfile localhost.crt localhost.crt
这应该产生localhost.crt: OK
- 因为它尚未被信任使用
openssl verify localhost.crt
应该失败
CN = localhost
error 18 at 0 depth lookup: self signed certificate
error localhost.crt: verification failed
-
信任这个证书:
- 将 localhost.crt 复制到
/usr/local/share/ca-certificates
- 使用信任证书
sudo update-ca-certificates
- 验证证书是否已复制到
/etc/ssl/certs/localhost.pem
(扩展名更改)
- 现在应该可以在没有 CAfile 选项的情况下验证证书
$ openssl verify localhost.crt
localhost.crt: OK
-
强制您的应用程序使用此证书
- 使用以下设置更新您的 appsettings.json:
"Kestrel": {
"Certificates": {
"Default": {
"Path": "localhost.pfx",
"Password": ""
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)