wcf - 客户端证书身份验证 WCF

标签 wcf iis certificate client-certificates

所以我完全失去了证书。我在网上搜索了有关此问题的解决方案和教程,但没有发现任何可以真正帮助我的内容。
我想要做的是对我的 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”是“创建”证书的“权威”,我把他放在本地计算机上的受信任根证书以及本地计算机的个人目录中。
它是客户端证书“CN=MyTestClientCertificate”的颁发者。

几样东西..

我知道客户端证书应该在“MMC”的 CurretUser 目录中,但是当它存在时,我有一个异常(exception),应用程序找不到证书。
我尝试通过“FindBySubjectDistinguishedName”和“FindByThumbprint”定位它,两次都是相同的异常(exception)“无法找到具有给定标准的证书......”所以我把它放在LocalMachine中并且很好。
任何人都知道为什么它不起作用?

我有很多问题和异常(exception) =\当前的问题是:
“私钥未出现在 X.509 证书中”
任何熟悉此异常并知道如何修复它的人?

非常感谢您的回答,我已经坐了几天了

最佳答案

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

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

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

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

关于wcf - 客户端证书身份验证 WCF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19118918/

相关文章:

asp.net-mvc - 使用 Windows 身份验证在 MVC 应用程序中模拟 Active Directory 用户

PHP PDO 扩展不适用于 IIS

IOS 一次登录多个开发者证书/一个Apple ID/一台开发机

c# - 如何使用 json 通过 SSL 在 IIS 中托管的 WCF 端点上使用基本身份验证?

wcf - 使用SQL成员资格提供程序的WCF身份验证

IIS 6 - 按名称对网站进行排序

wcf - IIS 使用 SSL 证书托管 WCF

Java OpenSSL 验证和获取公钥

c# - XmlEnumAttribute 在 WCF 请求中不起作用

wcf - 服务器拒绝 session 建立请求 : WCF hosted on IIS