客户证书是必需的。在请求中未找到证书

时间:2013-12-02 20:47:07

标签: wcf authentication iis https certificate

我正在尝试使用SSL服务上的证书设置安全传输。

该服务是通过IIS安装的,我使用自签名证书验证的“MyLaptop”证书(存储在本地计算机/个人身份上)进行配置(“我的根CA”证书 - 存储在本地计算机受信任的根证书上当局)。服务似乎一切都好;我可以使用Internet Explorer访问它。

在服务器端,web.config看起来像

<behaviors>
      <serviceBehaviors>
        <behavior name="EchoServiceBehavior">
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" revocationMode="NoCheck" />
            </clientCertificate>                
          </serviceCredentials>
          <serviceMetadata httpsGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>    
    <bindings>
      <wsHttpBinding>
        <binding name="MutualSslBinding">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="EchoServiceBehavior" name="HttpsBindingDemo.EchoService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MutualSslBinding"
          contract="HttpsBindingDemo.IEchoService">
          <identity>
            <dns value="MyLaptop" />
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="https://MyLaptop:12643/EchoService/" />
          </baseAddresses>
        </host>
      </service>

在客户端,我安装了一个新证书“MyClient”(存储在CurrentUser / Personal上),该证书由相同的“My Root CA”证书验证。

在客户端,app.config看起来像

<behaviors>
      <endpointBehaviors>
        <behavior name="EchoClientBehavior">
          <clientCredentials>
            <clientCertificate findValue="MyClient" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IEchoService">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://MyLaptop:12643/EchoService/EchoService.svc" behaviorConfiguration="EchoClientBehavior"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEchoService"
        contract="SecuredServices.IEchoService" name="WSHttpBinding_IEchoService">
        <identity>
          <dns value="MyLaptop" />
        </identity>
      </endpoint>
    </client>

每次尝试执行EchoService.svc的操作时,我都会收到以下错误: “使用客户端身份验证方案禁止HTTP请求&#39; Anonymous&#39;” 启用服务日志我发现第一个异常消息实际上是“需要客户端证书。在请求中未找到证书。这可能是因为操作系统或IIS无法成功验证客户端证书。有关如何绕过这些验证并在WCF中使用自定义X509CertificateValidator的信息,请参阅http://go.microsoft.com/fwlink/?LinkId=208540。“。

您能否帮我理解如何正确配置服务以避免所描述的错误? 谢谢!

2 个答案:

答案 0 :(得分:0)

您的服务行为中很可能遗漏了 serviceCredentials 标记内的 serviceCertificate 标记。尝试添加它,它应该解决问题。每次我使用带有WCF服务的证书时,我总是必须在配置中指定服务应该使用的证书。

http://msdn.microsoft.com/en-us/library/ms731340%28v=vs.110%29.aspx

答案 1 :(得分:0)

将客户端证书导入个人存储区时,请尝试使用pfx文件导入并指定密码