我是 ASP.NET 的新手。
环境:
我在运行某些命令时遇到了麻烦。
我正在阅读教程
https://docs.microsoft.com/ja-jp/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-2.2&tabs=visual-studio-code
并运行此命令:
dotnet dev-certs https --trust
我期待 https://localhost应该被信任。
但我发现了错误信息;
$ Specify --help for a list of available options and commands.
似乎命令“dotnet dev-certs https”没有 --trust 选项。
如何解决这个问题?
最佳答案
在 Ubuntu 上,标准机制是:
dotnet dev-certs https -v
生成自签名证书openssl pkcs12 -in <certname>.pfx -nokeys -out localhost.crt -nodes
将 ~/.dotnet/corefx/cryptography/x509stores/my 中生成的证书从 pfx 转换为 pem localhost.crt
至/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 中描述的问题影响的证书和 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 上测试)
详细:
[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
生成证书openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crt
将证书转换为 pfx 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
/usr/local/share/ca-certificates
sudo update-ca-certificates
信任证书/etc/ssl/certs/localhost.pem
(扩展更改)$ openssl verify localhost.crt
localhost.crt: OK
"Kestrel": {
"Certificates": {
"Default": {
"Path": "localhost.pfx",
"Password": ""
}
}
}
关于asp.net - 如何运行 'dotnet dev-certs https --trust' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60815781/