4

我正在尝试使用 ssl(传输安全)两种方式创建 wcf 客户端和服务器(自托管) - 服务器证书和客户端证书。

在 Windows XP 中一切正常,但在 Windows 7 中,客户端证书失败。如果服务器在winXp,而客户端在win7——它会工作,相反——它不会工作。

这是服务器的 app.config:

<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>         
        </behavior>
        <behavior name="NewBehavior1">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceCredentials>
            <serviceCertificate findValue="ServerCert" storeName="My" x509FindType="FindBySubjectName" />
            <clientCertificate>
              <authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck" trustedStoreLocation="LocalMachine" />
            </clientCertificate>
            <windowsAuthentication allowAnonymousLogons="True"/>
          </serviceCredentials>

        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="Binding1">
          <security mode="Transport">
           <transport clientCredentialType="Certificate" proxyCredentialType="None" realm=""/>
          </security>
        </binding>
      </basicHttpBinding>

    </bindings>
    <services>
      <service behaviorConfiguration="NewBehavior1"
            name="Service.Calc">
        <endpoint
          address="https://172.18.96.116:8413/MyCalcService1"
          binding="basicHttpBinding"
          bindingConfiguration="Binding1"
          name="TestWCFService.Http"
          contract="Contarcts.ICalc" />
        <host>
          <baseAddresses>
            <add baseAddress="https://172.18.96.116:8413/MyCalcService1" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

</configuration>

客户:

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="clientBehavior1">
          <clientCredentials>
            <clientCertificate findValue="ClientCert"
                 storeLocation="LocalMachine"
                 storeName="My"
                 x509FindType="FindBySubjectName" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="TestWCFService.Http1">
          <security mode="Transport">
          <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://172.18.96.116:8413/MyCalcService1"
      binding="basicHttpBinding"
      bindingConfiguration="TestWCFService.Http1"
      contract="CalcProxy.ICalc"
      name="TestWCFService.WSHttp1"
      behaviorConfiguration="clientBehavior1"
      />
    </client>
  </system.serviceModel>

服务器的代码:

ServiceHost calcHost = new ServiceHost(typeof(Calc));
calcHost.Open();

客户代码:

System.Net.ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);


CalcClient proxy = new CalcClient();
int res = proxy.Add(2, 4);

我的 makecert 命令是:

makecert -sv SignRoot.pvk -cy authority -r MyCA.cer -a sha1 -n "CN=MyCA" -ss my -sr localmachine

makecert -iv SignRoot.pvk -ic MyCA.cer -cy end -pe -n CN="ClientCert" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

makecert -iv SignRoot.pvk -ic MyCA.cer -cy end -pe -n CN="ServerCert" -eku 1.3.6.1.5.5.7.3.2 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

我还验证了 ca 位于正确的位置(本地计算机 - 受信任的根 CA),并且服务器/客户端证书也在正确的位置(本地计算机 - 个人)。

私钥可以导出,并且我验证“每个人”都有权访问私钥(C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys)。

它通过提琴手工作。


我从 SvcTraceViewer 得到的错误:

客户端 -客户端身份验证方案“匿名”禁止 HTTP 请求。

服务器端 -需要客户端证书。在请求中未找到证书。

http 跟踪错误:服务器应用程序尝试接收客户端证书失败,状态为:0xC0000225。

我发现了类似的问题,但我仍然坚持: .NET 应用程序无法发送客户端证书 - Win 7 vs Win XP?

如何让它在 Windows 7 上运行?

谢谢。

4

1 回答 1

1

我会尝试的几件事:

  1. 证书的友好名称应与运行服务的机器的 dns 相同。如果服务器和客户端都在同一台机器上运行,请使用“CN=localhost”。

  2. 查看此链接以获取有关如何创建和安装证书的重要信息。

  3. 自托管时,您需要手动将证书与端口关联。使用netsh命令行。检查这个

希望这些步骤会有所帮助......祝你好运

于 2013-01-15T15:41:38.453 回答