1

这已经困扰了我三天了,经过大量的谷歌搜索后,我决定发布一个问题。我有一个 WCF 服务应用程序(“本地服务”),它安全地连接到“远程 Web 服务”(Java)(2 路证书身份验证)。

我的服务端配置:

<system.serviceModel>
  <bindings>
      <basicHttpBinding>
          <binding name="IhAdapterPortBinding" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
              useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="Transport">
                  <transport clientCredentialType="Certificate" proxyCredentialType="None"
                      realm="" />
                  <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
          </binding>              
      </basicHttpBinding>
  </bindings>
  <client>
      <endpoint address="https://someserver.com:8085/IhAdapter" binding="basicHttpBinding"
          bindingConfiguration="IhAdapterPortBinding" contract="IHAdapter.IhAdapter"
          name="IhAdapterPort" behaviorConfiguration="IHAdapterEndpointBehavior" />       
  </client>
<services>
  <service name="SomeCompany.SomeService">
    <endpoint address="" binding="basicHttpBinding"
      contract="SomeCompany.ISomeService" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="IHAdapterEndpointBehavior">
             <clientCredentials>
                  <clientCertificate storeLocation="LocalMachine" storeName="My" findValue="123...abc" x509FindType="FindByThumbprint"/>
                  <serviceCertificate>
                       <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
                  </serviceCertificate>
             </clientCredentials>
        </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

现在来解决问题。在 Visual Studio Web 开发服务器中托管服务或从本地测试客户端 (.exe) 调用远程服务时,调用成功。但是当本地服务是 IIS 托管(本地主机或其他服务器 IIS)时,我得到异常:

无法为具有权限“ https://someserver.com:8085 ”的 SSL/TLS 建立安全通道

内部异常:

请求被中止:无法创建 SSL/TLS 安全通道。

到目前为止我尝试或检查的内容:

  • 正确的证书存储位置(本地计算机,而不是用户)
  • 私钥权限(去MMC,找到证书,右键单击,所有任务,管理私钥,设置为所有人的所有权限)
  • 将 IIS 应用程序用户 (Connect As) 设置为具有管理权限的本地用户

还有一件事:当前的远程服务器证书是为另一个主机名颁发的,所以我必须以编程方式覆盖验证。所以要在本地服务中创建一个远程服务对象,我有这些代码行:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = ((senderParam, certificate, chain, sslPolicyErrors) => true);

IHAdapter.IhAdapterClient ihAdapter = new IHAdapter.IhAdapterClient();

ihAdapter.SomeMethod(parameters); // the exception gets thrown here

我还能错过什么?任何想法,指针?

4

2 回答 2

4

好的,回答我自己的问题。

基于此链接:How to give ASP.NET access to a private key in a certificate in the certificate store? 我解决了我的问题。

我的解决方案的关键是这个清单:

  1. 创建/购买证书。确保它有一个私钥。
  2. 将证书导入“本地计算机”帐户。最好使用证书 MMC。确保选中“允许导出私钥”
  3. 基于此,IIS 7.5 应用程序池的标识使用以下之一:
    • IIS 7.5 网站在 ApplicationPoolIdentity 下运行。使用证书 MMC,将“IIS AppPool\AppPoolName”添加到“本地计算机\个人”中证书的完全信任中。将“AppPoolName”替换为您的应用程序池的名称。
    • IIS 7.5 网站在 NETWORK SERVICE 下运行。使用证书 MMC,将“网络服务”添加到“本地计算机\个人”中证书的完全信任中。
    • IIS 7.5 网站在“MyIISUser”本地计算机用户帐户下运行。使用证书 MMC,将“MyIISUser”(一个新的本地计算机用户帐户)添加到“本地计算机\个人”中证书的完全信任中。

我几乎可以肯定地做了所有这些事情,但显然从来没有一次全部在一起。希望这对其他人有帮助。无论如何感谢所有的帮助。

于 2013-02-22T11:05:50.527 回答
0

我认为所有这些消息都是由于链中的某些机器(客户端、代理、服务器)由于某种原因不“喜欢”证书。

要详细说明 twk 所说的内容,如果您使用的是自签名证书或您自己的 CA,您需要至少在服务器上的受信任的权威存储中安装签名证书,并且可能在代理上。

我遇到的常见问题:

  • 服务器上的证书未由 PROXY 或 CLIENT 信任的机构签署
  • CLIENT 上的证书未由 PROXY 或 SERVER 信任的权威机构签署
  • 糟糕,我在创建要安装在客户端上的证书时忘记导出私钥
  • 我的进程对客户端上的私钥没有读取权限
  • 客户端证书受密码保护,我在读取证书时没有指定凭据。

更多访问无法创建 SSL/TLS 安全通道 - 问题可能出在代理服务器上吗?

于 2013-02-20T07:36:18.477 回答