gpt4 book ai didi

.net - 如何使用 ssl 通配符证书通过 X509 相互验证多个 WCF 服务器?

转载 作者:行者123 更新时间:2023-12-02 04:18:03 25 4
gpt4 key购买 nike

我有两个 WCF 服务器,都在域 mydomain.com 上(虚构示例,如下 IP !),分别命名为 server1 和 server2。

它们都可以通过它们的公共(public) IP 地址(foo.1 和 2)访问,也可以从它们所在的私有(private) LAN(即 192.168.0.1 和 192.168.0.2)访问

我拥有 *.mydomain.com 的通配符 ssl 证书。它已正确安装在相关商店中(即用于加密的个人和用于身份验证的可信客户端)

我希望我的两台服务器使用我的通配符证书在其本地网络地址上相互连接以进行身份​​验证。

我更新了 C:\Windows\System32\drivers\etc\hosts 文件,使其看起来像这样:

192.168.0.1     Server1.mydomain.com
192.186.0.2 Server2.mydomain.com

如果我解析 Server1.mydomain.com,这些不是我得到的 IP 地址(我宁愿得到 foo.1 - 2)

我还将 IPV4 本地接口(interface)的连接特定 DNS 后缀编辑为“mydomain.com”

我的证书在我的 Server.config 文件中是这样引用的(我已经剥离了所有与身份验证无关的部分)
        <behavior name="ServerToServerBehavior" >
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="Online"/>
</clientCertificate>
<serviceCertificate x509FindType="FindByThumbprint" findValue="13a41b3456e431131cd461de"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myServerAsClientBehaviorConfiguration">
<clientCredentials>
<clientCertificate x509FindType="FindByThumbprint" findValue="13a41b3456e431131cd461de" storeLocation="LocalMachine"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="Online" trustedStoreLocation="LocalMachine"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>

这在我自己的具有本地生成的 X509 证书的开发计算机上运行良好,但在我的生产环境中,这就是我得到的:

Server.Connect : Failed to connect to server Server2 : System.ServiceModel.Security.MessageSecurityException: Identity check failed for outgoing message. The expected DNS identity of the remote endpoint was 'server2.mydomain.com' but the remote endpoint provided DNS claim 'mydomain.com'. If this is a legitimate remote endpoint, you can fix the problem by explicitly specifying DNS identity 'mydomain.com' as the Identity property of EndpointAddress when creating channel proxy.



我试图让服务器回答 Server2.mydomain.com 而不仅仅是 mydomain.com,但没有成功。关于如何做到这一点的任何提示?

我也尝试了错误消息中建议的解决方案,但这似乎根本没有效果(其他用户似乎有 the same problem 而我还​​没有找到解决方案)。关于如何解决这个问题的任何想法?

编辑 :
我已经与我的证书提供商确认我确实可以将它用于 X509 身份验证。

最佳答案

我最终明白了为什么我的身份字段被忽略了。

我的端点是这样构造的:

DistantServer = new ServiceReferenceServerToServer.ServerToServerClient("myServerBinding", "net.tcp://server.mydomain.com/Server");

当提供 uri 参数时,DNS 身份字段(在 app.config 中定义)也会被覆盖(即使它是空的,当我们使用字符串而不是真正的 URI 对象时就是这种情况)。

解决方案是使用以下代码以编程方式设置它:
        System.ServiceModel.EndpointAddress uri = new System.ServiceModel.EndpointAddress(new Uri("net.tcp://server.mydomain.com/Server"),new System.ServiceModel.DnsEndpointIdentity("mydomain.com"),new System.ServiceModel.Channels.AddressHeader[0]);

DistantServer = new ServiceReferenceServerToServer.ServerToServerClient("myServerBinding", uri );

关于.net - 如何使用 ssl 通配符证书通过 X509 相互验证多个 WCF 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1630968/

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