C# 使用带有 SSL 和服务器证书的 ws-security Web 服务 无法通过权限为 SSL/TLS 建立安全通



我必须使用带有SSL证书和服务器证书的java网络服务。我获得了 TLS 证书和 WSS 证书

我的应用配置:

<endpoint address="ADDR"
   binding="customBinding" bindingConfiguration="customB" behaviorConfiguration="myBehavior" contract="ServiceReference1.MyClient" name="Name" >
<identity>
    <dns value="DNS-CERTIFICATE-VALUE"/>
</identity>

<behavior name="myBehavior">
<clientCredentials supportInteractive="false">
    <clientCertificate findValue="TLS CERT" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" />
    <serviceCertificate>
        <defaultCertificate findValue="WSS CERT" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" />
        <authentication certificateValidationMode="None" revocationMode="NoCheck" trustedStoreLocation="LocalMachine" />
    </serviceCertificate>
</clientCredentials>

<customBinding>
<binding name="customB">
    <textMessageEncoding messageVersion="Soap11" />
    <security enableUnsecuredResponse="true" authenticationMode="MutualCertificate" includeTimestamp="false" securityHeaderLayout="Lax" allowInsecureTransport="true" 
                messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" > </security>
    <httpsTransport />
</binding>

在应用程序代码中,我添加了:

 ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
 ServicePointManager.Expect100Continue = true;
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

我一直收到错误:无法通过 ADDR 权限为 SSL/TLS 建立安全通道

我也试过:

client.ClientCredentials.ClientCertificate.Certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "THUMB", false)[0];

其中 THUMB 是 TLS 或 WSS 证书(同时选中(

我还尝试在接口之前添加参考.cs:

ProtectionLevel = ProtectionLevel.Sign

还是没有运气。你能给我任何建议吗?我在 Soap UI 中有一个工作项目,在选项中我选择了 SSL 证书,并在传出 WS 安全配置中添加了带有证书 (WSS( 和二进制安全令牌选项的 Siganture。它工作得很好。

答案在这里:https://blogs.msdn.microsoft.com/saurabs/2016/03/07/wcf-how-to-send-two-different-client-certificates-as-credentials-at-both-transport-and-message-level/

您必须为 传输证书创建自定义凭据,然后将其添加到行为中。没有同时使用 3 个证书的标准选项。提供的解决方案是为我的项目定制的,我正在使用身份验证模式="互助证书",并且在行为上我也使用服务器证书。我只自定义添加传输证书,所有其他内容都来自基类。

最新更新