【问题标题】:Configurating WCF service with HTTPS使用 HTTPS 配置 WCF 服务
【发布时间】:2013-12-20 09:11:47
【问题描述】:

我正在开发一个 WCF 服务,该服务必须使用用户名凭据在 HTTPS 上运行,并且发现以下配置在我在 IIS 上运行的测试解决方案中有效;

服务器配置:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <customErrors mode="Off" />
  </system.web>

  <system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="Behavior1">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Service.UserNamePassValidator, Service" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <wsHttpBinding>
        <binding name="Binding1">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service behaviorConfiguration="Behavior1" name="Service.Service">
        <host>
          <baseAddresses>
            <add baseAddress="https://localhost/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="Service.IService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>

  </system.serviceModel>

</configuration>

客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

    <client>
      <endpoint address="https://localhost:44303/UsernamePasswordService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
        contract="ServiceReference1.IService" name="WSHttpBinding_IService" />
    </client>

  </system.serviceModel>
</configuration>

我的场景中的客户端是一个 winforms 应用程序。

我对配置它非常陌生,只是想确认这是否是具有用户名凭据的 HTTPS (SSL) 的有效/良好设置?

由于我使用的是自签名证书,我必须绕过客户端的证书验证,因此我觉得我无法清楚地看到这将如何使用有效的证书。

我想象它的工作方式是服务器在开始通信时将客户端证书传递给客户端,然后客户端使用客户端证书加密它发送到服务器的所有流量。然后在服务器端使用服务器证书解密此流量。

但这就是它的工作方式吗?现在的配置方式,证书只在IIS监听端口上指定,那么它会根据每个请求的服务器证书为客户端生成一个证书吗?还是来自客户端的流量未加密?

我尝试在我的请求上运行提琴手并启用解密 HTTPS,并注意到我可以在 XML 中以纯文本格式读取用户名和密码。这是因为提琴手做了一些魔术来读取我的证书加密还是发送的消息根本没有加密?

在这种情况下,我是否必须自己加密和解密数据?

我不想在客户端上安装证书。

【问题讨论】:

    标签: c# wcf iis ssl https


    【解决方案1】:

    在我看来,对您的第一个问题的简短回答是肯定的 - 带有 UserName 凭据的 HTTPS (SSL) 可以是有效的安全配置。使用 WSHttpBinding 实现 WS-Security 规范并提供与实现 WS-* 规范的服务的互操作性。

    参考:http://msdn.microsoft.com/en-us/library/ms731172(v=vs.110).aspx

    为了提供进一步的评估,需要将该解决方案的安全性与您的系统要求进行比较。

    老实说,我没有完全理解问题的其余部分,尽管我了解到您对使用自签名证书的客户端含义有所顾虑。也就是说,以下链接(至少一个)应该提供一些指导:

    http://msdn.microsoft.com/en-us/library/ff648840.aspx
    http://www.codeproject.com/Articles/570539/HTTPSplusCommunicationplusinplusWCFplususingplusSe
    http://blog.adnanmasood.com/2010/04/29/step-by-step-guide-for-authenticating-wcf-service-with-username-and-password-over-ssl/

    【讨论】:

      猜你喜欢
      • 2013-10-14
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 2018-10-08
      • 2012-02-09
      • 1970-01-01
      • 2022-01-16
      • 2011-08-03
      相关资源
      最近更新 更多