繁体   English   中英

客户端证书身份验证WCF

[英]Client certificate authentication WCF

所以我完全迷失了证书。 我在网上搜索了有关此问题的解决方案和教程,但没有任何东西可以真正帮助我。 我想做的是为WCF客户端-服务器应用程序同时进行服务器和客户端证书验证。 该应用程序托管在IIS上。 我希望它在我的开发计算机(服务器是本地主机)上并在测试中(即时消息客户端和服务器是Windows服务器)。

我现在的配置是:

客户:

<behaviors>
  <endpointBehaviors>
    <behavior name="myBehaviorConfig">
      <clientCredentials>
        <clientCertificate findValue="CN=MyTestClientCertificate"
                            storeLocation="LocalMachine"
                            x509FindType="FindBySubjectDistinguishedName"/>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

<bindings>
  <wsHttpBinding>
    <binding name="MyBindingConfig">
      <security mode="TransportWithMessageCredential">
        <transport realm=""/>
        <message clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<client>
  <endpoint address="https://localhost/Service.Calculator.svc"
            binding="wsHttpBinding"
            bindingConfiguration="MyBindingConfig"
            behaviorConfiguration="MyBehaviorConfig"
            contract="Service.ICalculator"
            name="ICalculatorServiceEndpoint">
    <identity>
      <servicePrincipalName value="host"/>
    </identity>
  </endpoint>    
</client>

服务器:

 <behaviors>
  <serviceBehaviors>
    <behavior name="myBehavior">
      <serviceCredentials>
        <serviceCertificate findValue="CN=MyTestRootCA"
                            storeLocation="LocalMachine"
                            x509FindType="FindBySubjectDistinguishedName"/>
        <userNameAuthentication userNamePasswordValidationMode="Windows"/>
        <clientCertificate>
          <authentication certificateValidationMode="PeerOrChainTrust"/>
        </clientCertificate>
      </serviceCredentials>
      <serviceMetadata httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <unity operationContextEnabled="true"
             instanceContextEnabled="true"
             contextChannelEnabled="true"
             serviceHostBaseEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <wsHttpBinding>
    <binding name="MyBinding">
      <security mode="TransportWithMessageCredential">
        <transport realm=""/>
        <message clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<services>
  <service name="Service.Calculator"
           behaviorConfiguration="myBehavior">
    <endpoint address=""
              binding="wsHttpBinding"
              bindingConfiguration="MyBinding"
              contract="Service.ICalculator" />
    <endpoint address="mex"
              binding="mexHttpsBinding"
              contract="IMetadataExchange"
              name="CalculatorServiceMex" />
  </service>
</services>

“ CN = MyTestRootCA”是“授权”证书,是“正在创建”证书,我将其放在localComputer以及本地计算机的个人目录中的受信任的根证书中。 它是客户端证书“ CN = MyTestClientCertificate”的颁发者。

一些事情..

我知道客户端证书应该在“ MMC”中的CurretUser目录中,但是当它存在时,我有一个例外,即应用程序找不到证书。 我尝试通过“ FindBySubjectDistinguishedName”和“ FindByThumbprint”来定位它,两次都是相同的例外,“无法以给定的条件找到证书……”,所以我将其放在LocalMachine中,并且很好。 有人知道为什么它不起作用吗?

我在使用此= \\时遇到了很多问题和异常,当前的问题是:“ X.509证书中未提供私钥”熟悉此异常并知道如何解决的人吗?

非常感谢您的回答,我现在坐在这几天上

您的配置文件未指定clientCertificate storeLocation值,因此客户端证书必须位于LocalMachine存储中,这是storeLocation的默认值。

考虑以下来自msdn的示例,该示例设置了客户端证书存储位置:

<clientCertificate>
   <certificate 
         findValue="www.cohowinery.com" 
         storeLocation="CurrentUser" 
         storeName="TrustedPeople"
         x509FindType="FindByIssuerName" />
   <authentication …

注意:另一个错误“私钥未在X.509证书中出现”,很可能引发此错误,因为您的证书没有关联的私钥,或者您的进程的用户上下文没有访问私钥的权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM