所以我完全迷失了证书。我已经在网上搜索了解决方案和教程,但没有发现任何可以真正帮助我的东西。我要做的是对我的 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”是“Authority”的“Creating”证书,我把他放在localComputer上受信任的根证书以及本地计算机的个人目录中。它是客户端证书“CN=MyTestClientCertificate”的颁发者。
一些事情..
我知道客户端证书应该在“MMC”的 CurretUser 目录中,但是当它在那里时,我有一个例外,即应用程序找不到证书。我尝试通过“FindBySubjectDistinguishedName”和“FindByThumbprint”定位它,两次都是相同的例外“无法找到具有给定标准的证书......”所以我把它放在 LocalMachine 和它的罚款。任何人都知道为什么它不起作用?
我对此有很多问题和异常=\当前的一个是:“X.509 证书中没有提供私钥” 任何熟悉此异常并知道如何解决它的人?
非常感谢您的回答,我已经坐了几天了