【问题标题】:Implementing SelfSigned X509 Certificate for WCF Services hosted on IIS为托管在 IIS 上的 WCF 服务实施 SelfSigned X509 证书
【发布时间】:2014-01-08 23:47:10
【问题描述】:

在进入这个问题之前,让我先解释一下我在寻找什么以及我做了什么。

我创建了一个自签名 X509 证书,一个用于客户端,另一个用于服务器。 我已经创建了 WCF 服务并配置了 Web.Config 以使用证书。 我什至配置了客户端 Web.Config 以根据基于证书的安全性发出请求。 自托管一切正常。

但是,当我在 IIS 上部署服务时,我遇到了一大堆问题,我一直在寻找解决方案,但没有任何结果。

如果有人可以为此提供可能的解决方案,那就太好了。

下面是服务器和客户端的配置文件。

服务器(WCF 服务)Web.config:

   <configuration>
  <appSettings />
  <connectionStrings />
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
  </system.web>
  <system.web.extensions>
    <scripting>
      <webServices/>
    </scripting>
  </system.web.extensions>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpEndpointBinding">
          <security>
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="WCFServiceCertificate.Service1" behaviorConfiguration="WCFServiceCertificate.Service1Behavior">
        <endpoint address="https://***.***.**.**:91" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="WCFServiceCertificate.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCFServiceCertificate.Service1Behavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" />
            </clientCertificate>
            <serviceCertificate findValue="WCfServer" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

客户端配置:

  <?xml version="1.0"?>
<configuration>
  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="false" targetFramework="4.0"/>
    <authentication mode="Windows"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="Windows" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="Certificate" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:1387/Service1.svc" binding="wsHttpBinding"
        bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
        name="WSHttpBinding_IService1" behaviorConfiguration="CustomBehavior">
        <identity>
          <dns value="WCfServer" />
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="CustomBehavior">
          <clientCredentials>
            <clientCertificate findValue="WcfClient" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My"/>
            <serviceCertificate>
              <authentication certificateValidationMode="PeerTrust"/>
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

浏览服务时输出截屏。

浏览器

任何帮助都可以得到...
在此先感谢各位..

【问题讨论】:

  • 有什么问题?你有例外吗?
  • 好吧,我没有遇到异常,但我无法浏览服务。我将附上从浏览器访问时得到的响应的屏幕截图。

标签: asp.net wcf c#-4.0 iis ssl


【解决方案1】:

您需要在受信任的证书颁发机构下创建客户端证书和服务器证书。客户端和服务器都必须信任创建证书的证书颁发机构。
如果您没有 CA 或没有钱从公共 CA 购买证书,您可以设置一个工作的本地环境:
- 创建根 CA 证书:rootCA
- 在服务器和客户端的受信任根证书存储库中安装 rootCA(公钥)
- 从 rootCA 创建 https 证书并将其安装在 IIS
- 创建客户端证书并将其安装在客户端上

从上一个关于 stackoverflow 的问题开始Using makecert for Development SSL
我写了一个分步指南:
https://docs.google.com/document/d/1s0DpnFhwhBamYfwZUGLJokDJPDSzGYO5Ct2hxzq4SA4/edit?usp=sharing

【讨论】:

  • 感谢 Fabrizio 提供有用的链接和材料。
    我的配置在托管环境中运行良好,但我意识到客户端计算机不接受证书,因为它不受信任的安全性。除了一切正常。再次感谢您。
【解决方案2】:

感谢大家的支持。
唯一的问题是证书不是在受信任的安全性下创建的,它是一个正常的自签名证书,浏览器不接受。

在受信任的安全性下创建证书后问题已解决。 配置设置很好。

最后感谢@Fabrizio 的大力帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2011-01-18
    • 2012-07-06
    • 1970-01-01
    • 2022-12-13
    • 2014-09-09
    相关资源
    最近更新 更多