gpt4 book ai didi

c# - SSLStream 在服务器身份验证上设置受信任的证书颁发机构

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:33 25 4
gpt4 key购买 nike

我正在尝试对存在证书交换的客户端进行身份验证。我遇到的问题是 openssl 客户端拒绝连接尝试,因为身份验证握手中没有包含任何证书颁发机构。

这对于在 Windows Server 2008 R2 上运行的实例来说似乎工作正常,但在我的两个开发环境(Windows 10 和 Windows 7)中它都失败了。我已经查看并尝试更改一些 Windows 设置(主要是本地组策略),这些设置可能会禁止添加证书颁发机构但无法使其正常工作。

是LocalCertificateSelectionCallback的字符串数组acceptableIssuers字段的函数吗?

我还找到了另一个stackoverflow php solution这是相关的,但不知道如何将其应用于 sslstream 类。

我的代码是这样的

var _nwStream = new SslStream(client.GetStream(), true,
(sender, certificate, chain, sslPolicyErrors) =>
{
bool policyErrs = (sslPolicyErrors & (SslPolicyErrors.RemoteCertificateChainErrors | SslPolicyErrors.RemoteCertificateNotAvailable)) != 0;
if (policyErrs)
{
string message = string.Format("Remote Certificate failed for client: {0}, SSL policy errors {1}", client.Client.RemoteEndPoint, sslPolicyErrors);
return !policyErrs;
},
(sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) =>
{
acceptableIssuers = new string[] { _cert.Issuer };
return _cert;
});

_nwStream.AuthenticateAsServer(_cert, true, System.Security.Authentication.SslProtocols.Tls, true);

如有任何帮助,我们将不胜感激 - 谢谢!

最佳答案

嗯,我不知道为什么它没有早点出现。有一个注册表项HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL名为 SendTrustedIssuerList 的设置为 0,将其更改为 1 解决了该问题。在 Windows Server 实例上,此标志可能默认设置为 1。

关于c# - SSLStream 在服务器身份验证上设置受信任的证书颁发机构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34858691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com