【问题标题】:Configure WCF with client certificate signing XMLDsig, WS-Security or XADES使用客户端证书签名 XMLDsig、WS-Security 或 XADES 配置 WCF
【发布时间】:2020-03-12 15:11:36
【问题描述】:

使用VS2019,ASP.NET项目运行.net 4.0。

我创建了将服务引用添加到 wsdl 文件的 soap 客户端。现在我正在配置证书和调用方法。

这种方式在旧的soap 服务器中有效,但现在soap 服务器发生了变化。我使用相同的基本身份验证配置对 SoapUI 进行了测试,并且可以完美运行,但不适用于我的 .Net 4.0 客户端...

Web.config

<system.serviceModel>
<bindings>
  <customBinding>
     <binding name="PLATAFORMA">
  <textMessageEncoding messageVersion="Soap11WSAddressing10" />
  <security 
    authenticationMode="MutualCertificateDuplex" 
    messageProtectionOrder="SignBeforeEncrypt"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
    <secureConversationBootstrap />
  </security>
      <httpsTransport />
    </binding>
  </customBinding>
</bindings> 
  <behaviors>
    <endpointBehaviors>
      <behavior name="CERT">
        <clientCredentials>
          <clientCertificate findValue="ClientCert" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            <serviceCertificate>
              <defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            </serviceCertificate>
          </clientCredentials>  
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <client>
    <endpoint
      address="endpointURI"
          binding="customBinding"
          bindingConfiguration="PLATAFORMA"
      behaviorConfiguration="CERT"
      contract="ServiceReference1.RequestPort1"
      name="Request.Request1">
      <identity>
        <dns value="*.ServerCert.com" />
      </identity>
    </endpoint>
  </client>
</system.serviceModel>

XML Outoing header(被拦截器捕获):

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <a:Action s:mustUnderstand="1">peticionSincrona</a:Action>
    <a:MessageID>urn:uuid:e3a5c4bd-f159-48c1-8f3f-cf22da6b7e3b</a:MessageID>
    <ActivityId CorrelationId="035f2491-0772-4b1e-a286-9be30720d5ea" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">4d7f76c2-0486-4a81-93ad-32aecf02b035</ActivityId>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo9ph/BcvvnBFuLQYdch+LyYAAAAAHsOKxYeqzk+Do5pQmamNIPUdiXOiYjpBl1dsV5pp+SMACQAA</VsDebuggerCausalityData>
  </s:Header>

我了解需要一些信息,如何指定以 XMLDsig 签名?为什么不是肥皂/信封/编码?我需要帮助来配置soap客户端。

服务器返回错误 500 并带有默认的 tomcat 错误,甚至不是 soapenv:fault 或类似错误。我认为请求信封没有正确生成。

编辑:必须超过soap11

【问题讨论】:

    标签: asp.net wcf soap x509certificate ws-security


    【解决方案1】:

    这是更改 SOAP 服务器后生成的客户端配置吗?如果需要Basic认证,为什么我们不需要提供用户名/密码,而只需要提供一个客户端证书(根据绑定类型)? 我建议您通过添加服务引用重新生成客户端代理类。这也会在webconfig 文件中生成正确的配置。
    另外,由于服务器发生变化,服务器用来实现HTTPS安全的证书也可能发生变化,所以我们在客户端提供的默认证书也应该发生变化。

    <serviceCertificate>
                  <defaultCertificate findValue="*.ServerCert.com" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
                </serviceCertificate>
    

    相互证书认证需要客户端和服务器之间的信任关系。

    <security 
        authenticationMode="MutualCertificateDuplex"
    

    我们不仅需要在新服务器上安装客户端证书以信任客户端,还需要在客户端安装服务器的证书。 详情,
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/transport-security-with-certificate-authentication
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-certificate-client
    如果有什么可以帮助的,请随时告诉我。

    【讨论】:

    • 您好亚伯拉罕,感谢您的回复。我已经安装了证书客户端和服务器。我正在使用代理类生成的配置,但修改为添加 MutualCertificate 和客户端/服务器证书。此配置有效,因为我以前使用过它。我认为问题是生成的请求 XML 信封。或者至少我需要用我的私人证书和信任服务器证书(我已经拥有)在信封上签名。
    • 使用公钥加密和私钥对消息进行签名是由 WCF 框架完成的。无需手动设置。我们只是根据绑定类型提供凭据并在调用服务时设置证书(如果需要证书)。
    • 但是使用该配置,我遇到了这个问题:System.ServiceModel.FaultException 1: '0307 No se ha encontrado el nodo firma' 这意味着,它找不到签名节点。
    • 我设法按照你所说的开始工作,但现在我得到了像 soapfault:12 这样的错误,无法将消息版本更改为 soap11。
    • 试试 SOAP11 或 SOAP11WSAddressingAugust2004,如果您解决了问题,请分享解决方案,以便我们了解更多。
    猜你喜欢
    • 2013-07-14
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2013-01-22
    相关资源
    最近更新 更多