.net核心在哪里搜索linux平台上的证书

问题描述 投票:10回答:2

在Windows上,对于.NET Framework类,我们可以将sslkeyrepository指定为* SYSTEM / * USER.On linux默认情况下.NET Core类在哪里搜索certificatessslkeyrepository的值可能是什么。

c# ssl .net-core .net-standard .net-standard-2.0
2个回答
3
投票

.Net Core在Linux上使用OpenSSL,因此,您需要在容器中设置Linux environment,以便OpenSSL获取证书。

你可以通过两种方式做到这一点:

  1. 将证书.crt文件复制到update-ca-certificates将扫描可信证书的位置 - 例如/usr/local/share/ca-certificates/ oron RHEL /etc/pki/ca-trust/source/anchors/COPY myca.crt /usr/local/share/ca-certificates/
  2. 调用update-ca-certificatesRUN update-ca-certificates

5
投票

对于Linux和Mac,.NET CORE将使用OpenSSL

命令生成私钥和证书签名请求:

openssl req -config https.config -new -out csr.pem

命令创建自签名证书:

openssl x509 -req -days 365 -extfile https.config -extensions v3_req -in csr.pem -signkey key.pem -out https.crt

命令生成一个pfx文件,其中包含可与Kestrel一起使用的证书和私钥:

openssl pkcs12 -export -out https.pfx -inkey key.pem -in https.crt -password pass:<password>

在那之后Trust the certificate

此步骤是可选的,但如果没有它,浏览器将警告您网站可能不安全。如果浏览器没有trust your certificate,你会看到类似下面的内容:

在Linux上没有集中的方式来信任证书,因此您可以执行以下操作之一:

  1. 排除您在浏览器排除列表中使用的URL
  2. 信任localhost上的所有自签名证书
  3. 将https.crt添加到浏览器中的可信证书列表中。

如何实现这一点取决于您的浏览器/发行版。

您还可以参考完整的 Kestrel HTTPS sample app

或关注此博客Configuring HTTPS in ASP.NET Core across different platforms

© www.soinside.com 2019 - 2024. All rights reserved.