在Windows上,对于.NET Framework类,我们可以将sslkeyrepository
指定为* SYSTEM / * USER.On linux
默认情况下.NET Core类在哪里搜索certificates
,sslkeyrepository
的值可能是什么。
.Net Core
在Linux上使用OpenSSL
,因此,您需要在容器中设置Linux environment
,以便OpenSSL
获取证书。
你可以通过两种方式做到这一点:
.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/
update-ca-certificates
:
RUN update-ca-certificates
对于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上没有集中的方式来信任证书,因此您可以执行以下操作之一:
如何实现这一点取决于您的浏览器/发行版。
您还可以参考完整的 Kestrel HTTPS sample app
或关注此博客Configuring HTTPS in ASP.NET Core across different platforms