我正在尝试使用C#来使用WSSecurity保护的Java SOAP服务,但我没有取得多大成功 . 服务使用多种安全方法:

  • Connection使用需要客户端证书的TLS .

  • 消息由BinarySecurityToken签名,需要另一个证书 .

  • 在消息内部我们还有另一个证明某个用户的证书(但是's probably another story, as it'更像是消息体的一部分) .

每个证书都存储在系统存储中(它们最初是.p12文件) .

现在我有错误:{“一般安全错误(没有找到解密证书(KeyId))”}

因此握手成功并 Build 了连接 . 但我没有附加消息的第二个密钥 .

我当前的配置看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint address="https://myServiceAdress"
        behaviorConfiguration="myEndpointBehavior" binding="customBinding"
        bindingConfiguration="myBinding" contract="service.contract"
        name="myClientConfiguration">
        <identity>
          <dns value="system_authentication" />
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="myEndpointBehavior">
          <clientCredentials>
            <clientCertificate storeName="My" storeLocation="CurrentUser" x509FindType="FindBySubjectName" findValue="system_authentication"/>
            <serviceCertificate>
              <defaultCertificate storeName="My" storeLocation="CurrentUser" x509FindType="FindBySubjectName" findValue="system_authentication"/>
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="myBinding">
          <textMessageEncoding messageVersion="Soap11" />
          <security allowSerializedSigningTokenOnReply="true" authenticationMode="MutualCertificate"
            includeTimestamp="false" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
          </security>
          <httpsTransport requireClientCertificate="true" />
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我们可以清楚地看到我附加了允许我打开TLS连接的第一个密钥,但我不知道如何正确地将第二个密钥(“data_authentication”)附加到消息中 .

在SOAPUI中很容易做到 - 我必须将keystore(data_authentication.p12)添加到测试项目中,然后使用此密钥库和二进制安全性令牌类型创建带签名的传出WS-Security配置,但在C#中它不太明显 .