客户端上的WCF服务dns身份不起作用

时间:2016-02-05 15:30:51

标签: c# wcf https ssl-certificate x509certificate

尝试通过https与某些SOAP服务进行通信。服务有证书。如果我将此证书安装到本地存储或在config中将其编码的内容编写为

,一切正常
<certificate encodedValue="CCBF......"/>

但我不想在客户端提供硬性参考来为服务证书数据提供服务,因为它将很快到期并将被更改。我想通过CN接受服务证书或者像那样接受服务证书。

根据MSDN client.endpoint.identity.dns 值可以在这种情况下使用。因此,如果服务证书中的dns.value == CN,则连接应该没问题。

但它没有。

当我打开连接时,我得到一个例外:

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

其他信息:目标&#39; https://sss.myhost.com&#39;未提供服务证书。在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>

1 个答案:

答案 0 :(得分:0)

我相信您必须实施自己的证书验证。

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

其中您的VALIDATOR是实现X509CertificateValidator的类的程序集限定类型名称。在那里,您可以完全自由地验证您想要的任何内容 - CN,指纹等。

相关问题