【问题标题】:WCF wsHttpBinding Certificate Security Negotiation ExceptionWCF wsHttpBinding 证书安全协商异常
【发布时间】:2016-07-28 16:53:24
【问题描述】:

所以在梳理了 MSDN、无数文章甚至 SO 之后——我挣扎了几天仍然没有什么可展示的。

所以我有这个:WCF 服务需要由客户端使用,我只是不断遇到 SecurityNegotiationException

无法打开安全通道,因为与远程端点的安全协商失败。这可能是由于用于创建通道的 EndpointAddress 中缺少或错误指定了 EndpointIdentity。请验证 EndpointAddress 指定或暗示的 EndpointIdentity 是否正确标识了远程端点。

我在网上看到了这个错误,似乎没有人知道我的确切情况(至少有一个可行的答案)。

我的设置是本地的,不是由 IIS(暂时)托管,而是通过 Visual Studios 2010 托管。我的 GenericIntegration(WCF 服务)使用通过证书验证的 wsHttpBinding(消息模式)(我有一个非常自定义的用户名/密码身份验证 + 授权类通过设计作为参数传递)并且没有退出安全措施。

主机配置

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpintBinding">
      <security mode ="Message">
        <message clientCredentialType="Certificate" establishSecurityContext="false" negotiateServiceCredential="false"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="wsHttpBehaviour" name="GenericIntegration.GenericService">
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpintBinding" 
      name="wsHttpEndpoint" contract="GenericIntegration.GenInterface" />
    <host>
      <baseAddresses>
        <!--<add baseAddress="http://localhost:59082/GenericService.svc" />-->
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="wsHttpBehaviour">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceCredentials>
        <clientCertificate>
          <certificate findValue="GenIntegrationClient" storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectName" />
          <authentication certificateValidationMode="PeerTrust" />
        </clientCertificate>

        <serviceCertificate findValue="GenIntegrationClient" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
      </serviceCredentials>
    </behavior>
    <behavior name="metadataBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>    

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

以及客户端的配置

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="endpointBehaviour">
                <clientCredentials>
                    <clientCertificate findValue="GenIntegrationClient" storeLocation="LocalMachine" storeName="My"
                        x509FindType="FindBySubjectName" />
                  <serviceCertificate>
                    <authentication certificateValidationMode="PeerTrust" revocationMode="NoCheck"/>
                  </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="wsHttpEndpoint" maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000">
                <security mode="Message">
                    <message clientCredentialType="Certificate" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:59082/GenericService.svc"
            binding="wsHttpBinding" bindingConfiguration="wsHttpEndpoint" behaviorConfiguration="endpointBehaviour"
            contract="GenService.GenInterface" name="wsHttpEndpoint">
            <identity>
                <certificate encodedValue="AwAAAAEAAAAUAAAAKdyUELIKMtdh2MFsYQ09ja+vyeEgAAAAAQAAACICAAAwggIeMIIBi6ADAgECAhCFBfF1EXQZhkPKaBpQCl84MAkGBSsOAwIdBQAwJDEiMCAGA1UEAxMZNE1PU1RHZW5JbnRlZ3JhdGlvblNlcnZlcjAeFw0xNjA3MjgxNDQ5MjVaFw0zOTEyMzEyMzU5NTlaMCQxIjAgBgNVBAMTGTRNT1NUR2VuSW50ZWdyYXRpb25DbGllbnQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAIwsIlz5nZ3HxeYofTpYKr6RcfQMe/jZxPuHcljT+8pBOZ6KmYcyxeRTO074yP6yF8b1IqFskII+qqmCT8nDsb8xdo5Ee0oqL1LKR+xeTgg2ZXXoocxqR1AdxWFVdlMxMSjKIEGE+MnSDdB6vgXahhpUbAS7cdrNoAFKNIz+vrt1AgMBAAGjWTBXMFUGA1UdAQROMEyAEB4cu6OjBqQHct6przmowGyhJjAkMSIwIAYDVQQDExk0TU9TVEdlbkludGVncmF0aW9uU2VydmVyghD75YH5y52zsU5wcmZLJzPiMAkGBSsOAwIdBQADgYEA2BinUmEfgZKcb1qFD1T5ajc2OWHGLjDLpDi8Y7amM4P3rFGvelx7NmCNUH88iGS9LcbDsmY59HcZwUavtPOr4LMRDhl+5YuGht1fIYEk8QSDIhjevijgDOIVBBAeNIA8tva1faMNtYnFXsj0VxMvlrZ4exeKFVFjv2sib5YNFxY=" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

现在关于证书(是的,这仅用于测试):GenIntegrationServer.cer 已创建为自签名 CA 根证书,带有用于签署客户端证书的私钥。 GenIntegrationServer 和 GenIntegrationClient 证书都是使用 makecert 生成的。客户端证书链接到私钥并正确安装在个人存储中。

我对证书、私钥和安全通信还是很陌生——我根本无法解释我在哪里犯了错误。我没有找到太多关于以这种方式专门使用证书的帖子。

在我失去更多头发或为此睡觉之前,谁能提供帮助?

更新

根据要求,我添加了日志记录。但他们透露的最多的是:

<s:Body>
    <s:Fault>
        <s:Code>
            <s:Value>s:Sender</s:Value>
            <s:Subcode>
                <s:Value>a:InvalidSecurity</s:Value>
            </s:Subcode>
       </s:Code>
       <s:Reason>
           <s:Text xml:lang="en-ZA">An error occurred when verifying security for the message.</s:Text>
       </s:Reason>
    </s:Fault>
</s:Body>

遗憾的是,我仍然不明白为什么安全验证失败。有什么想法吗?

【问题讨论】:

  • 为详细日志记录配置服务客户端和主机 (msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx)。当谈判失败时,这应该让您更好地了解内部出了什么问题。使用此信息来解决问题或在获得更多信息后提出更具体的问题。
  • 另外一个常见的问题是我在安装时遇到的问题是 IIS 服务帐户没有读取私钥的权限。安装WSE3.0工具,然后使用证书工具授予私钥权限。
  • 根据请求添加了日志记录。我会用结果编辑我的问题。
  • 您是否使用服务日志查看器工具查看日志?这里应该有更多的信息。
  • 我确实使用了跟踪日志查看器,但这似乎不是我的问题(是的,它产生了更多但似乎与我无关)。原来我的证书没有安装在正确的证书存储中。除了安装在个人存储中之外,每一方还需要将彼此的证书安装在受信任的人证书存储中。稍后我将发布完整的解决方案。谢谢!

标签: c# wcf x509certificate ca wshttpbinding


【解决方案1】:

原来我需要将证书添加到不同的商店。

除了已经在个人存储中设置了证书(如配置所示),我还必须在客户端上安装服务器的证书,反之亦然。我还必须确保客户端包含客户端证书的个人密钥并且与服务器相同。

这听起来不太完整,但我会发布一篇关于我是如何做到这一点的完整文章。

【讨论】:

  • 如果您找到了自己问题的解决方案,请注意,您可以将自己的答案标记为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-29
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多