证书验证.NET标准2.1在Linux上运行

发布于 2025-02-13 06:25:46 字数 466 浏览 0 评论 0原文

我正在使用.NET标准2.1上的申请。对于HTTP客户端,我正在使用httpwebrequest,并且在某一时刻,我们必须使用CALLBACK ServicePointManager.ServerCertificateValidatifificateValidatifificatificateValidationCallback属性进行自定义证书验证。 在Windows OS上,我们在CA商店中添加证书,并且通过在回调中构建证书链来正常工作。 公共代表Bool remoteCertificateValidationCallback(对象发送者,x509certificate?证书,x509链?链,sslpolicyErrors sslpolicyErrors);。我的第一个问题是我应该在Linux上添加证书在哪里以便验证有效? 除此之外,这是一种添加证书而无需通过提供路径而安装证书的方法?

I am working on application on .net standard 2.1. For the http client I am using HttpWebRequest and in one point we had to make a custom certificate validation using the callback ServicePointManager.ServerCertificateValidationCallback Property.
On Windows Os we add the certificate in CA store and the validation works properly by building the chain of certificates X509Chain in the callback
public delegate bool RemoteCertificateValidationCallback(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors);. My first question is where should I add the certificate on linux so the validation works?
Apart from that is it a way to add the certificate without installing it by providing maybe the path ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぽ尐不点ル 2025-02-20 06:25:47

我的第一个问题是我应该在Linux上添加证书以便验证有效?

要在Linux上信任证书,您可以将其添加到您的系统信任集合中(指令取决于您的发行版),也可以将其添加到Currentuser \ root x509Store(由.NET管理,并且不影响curl之类的系统工具。

除此之外,这是一种添加证书而无需安装路径的方法吗?

.NET 5向X509链添加了一个功能,该功能允许为特定链构建指定信任的根存储集。如果您使用的是.NET 5+,则可以重新配置X509链实例,该实例将其切换为自定义信任并以这种方式指定您的证书。 (对于.NET 7,我们希望更容易将其指定为SSLSTREAM/HTTPCLIENT的输入,以便您不必等到回调并丢弃第一个链构建。)

我正在申请.NET标准2.1。

FWIW:您不能拥有.NET标准应用程序,因为.NET标准是一组类型,并且没有关联的运行时。 .NET CORE 3.0+(包括.NET 5+),显然是一些Xamarin和Unity Workloads实施.NET Standard 2.1 ...,您的应用程序将适用于其中之一( https://learn.microsoft.com/en-us/dotnet/standard/net-antard/net-standard?tabs=net-standard-2-1 )。

My first question is where should I add the certificate on linux so the validation works?

To trust a certificate on Linux you can either add it to your system trust collection (instructions depends on your distro), or you can add it to the CurrentUser\Root X509Store (which is managed by .NET and doesn't influence system tools like curl).

Apart from that is it a way to add the certificate without installing it by providing maybe the path?

.NET 5 added a feature to X509Chain which allows for specifying the set of trusted root stores for a specific chain build. If you're using .NET 5+ you could reconfigure the X509Chain instance that's provided to switch it to custom trust and specify your certificate that way. (For .NET 7 we're hoping to make it easier to specify this as an input to SslStream/HttpClient so that you don't have to wait until the callback and throw away the first chain build.)

I am working on application on .net standard 2.1.

FWIW: You can't have a .NET Standard application, because .NET Standard is a set of types and members with no associated runtime. .NET Core 3.0+ (including .NET 5+), and apparently some Xamarin and Unity workloads implement .NET Standard 2.1... and your application would be for one of them (https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文