证书验证.NET标准2.1在Linux上运行
我正在使用.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 callbackpublic 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在Linux上信任证书,您可以将其添加到您的系统信任集合中(指令取决于您的发行版),也可以将其添加到
Currentuser \ root
x509Store
(由.NET管理,并且不影响curl
之类的系统工具。.NET 5向X509链添加了一个功能,该功能允许为特定链构建指定信任的根存储集。如果您使用的是.NET 5+,则可以重新配置X509链实例,该实例将其切换为自定义信任并以这种方式指定您的证书。 (对于.NET 7,我们希望更容易将其指定为SSLSTREAM/HTTPCLIENT的输入,以便您不必等到回调并丢弃第一个链构建。)
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 )。
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 likecurl
)..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.)
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).