2016-02-05 72 views
0

嘗試通過https與某些SOAP服務進行通信。服務有證書。一切工作正常,如果我將此證書安裝到本地存儲或寫它的編碼配置內容WCF服務客戶端上的dns身份不起作用

<certificate encodedValue="CCBF......"/> 

但我不希望在客戶服務證書數據硬引用,因爲它很快就會到期並會改變。我想接受由CN或類似的服務證書。

根據MSDNclient.endpoint.identity.dns值可以在這種情況下使用。所以如果服務證書中的dns.value == CN,那麼連接應該是OK的。

但它沒有。

當我打開連接,我得到一個異常:

client.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign; 
client.Open(); 

其他信息:不提供目標「https://sss.myhost.com」服務證書。在ClientCredentials中指定一個服務證書。

<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.serviceModel> 
     <bindings> 
      <customBinding> 
     <binding> 
       <security authenticationMode="MutualCertificate" 
          enableUnsecuredResponse="true" 
          messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
        <secureConversationBootstrap /> 
       </security> 
       <textMessageEncoding messageVersion="Soap11" /> 
       <httpsTransport /> 
       </binding> 
      </customBinding> 
     </bindings> 
     <behaviors> 
     <endpointBehaviors> 
      <behavior> 
      <clientCredentials> 
       <clientCertificate findValue="Foo" storeName="My" storeLocation="CurrentUser" x509FindType="FindByIssuerName"/> 
       <serviceCertificate> 
       <!--<defaultCertificate storeLocation="LocalMachine" x509FindType="FindByIssuerName" storeName="Root" findValue="MyIssuerName" />--> 
       </serviceCertificate> 
      </clientCredentials> 
      </behavior> 
     </endpointBehaviors> 
     </behaviors> 
     <client> 
      <endpoint address="https://sss.myhost.com" 
       binding="customBinding" 
       contract="RS.InstanceManagerPortType" name="InstanceManagerPort"> 
      <identity> 
       <!--<certificate encodedValue="CCBF......"/>--> 
       <dns value="*.myhost.com"/> 
      </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

回答

0

我認爲你必須實現自己的證書驗證。

<behavior name="credentialConfiguration"> 
    <clientCredentials> 
    <serviceCertificate> 
     <authentication 
     certificateValidationMode="Custom" 
     customCertificateValidatorType="YOUR VALIDATOR"/> 
    </serviceCertificate> 
    </clientCredentials> 
</behavior> 

其中您的VALIDATOR是實現X509CertificateValidator的類的彙編合格類型名稱。在那裏你可以完全自由地驗證任何你想要的 - CN,指紋等。

相關問題