簡體   English   中英

WCF wsHttpBinding證書安全協商異常

[英]WCF wsHttpBinding Certificate Security Negotiation Exception

因此,在梳理了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>

可悲的是,我仍然不明白為什么安全驗證失敗。 有任何想法嗎?

原來我需要將證書添加到其他商店。

除了已經在個人存儲中設置了證書(如配置所示)之外,我還必須在客戶端上安裝服務器的證書,反之亦然。 我還必須確保客戶端包含客戶端證書的個人密鑰,並且與服務器相同。

聽起來還不太完整,但是我將發表一篇完整的文章來說明如何做到這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM