使用HTTPS配置WCF服务

时间:2013-12-20 09:11:47

标签: c# wcf iis ssl https

我正在开发一个必须使用UserName凭据在HTTPS上运行的WCF服务,并且发现以下配置在我在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应用程序。

我很擅长这个,并且只是想确认这是否是使用UserName凭据的HTTPS(SSL)的有效/良好设置?

由于我使用的是自签名证书,因此我不得不绕过客户端证书的验证,因此我不觉得我能清楚地看到它如何与有效证书一起使用。

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

但这是否会起作用?现在配置它的方式,证书仅在IIS侦听端口上指定,因此它是否会根据每个请求的服务器证书为客户端生成证书?或者来自客户端的流量是否未加密?

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

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

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

1 个答案:

答案 0 :(得分:0)

对我的第一个问题的简短回答是,在我看来,是 - 带有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/

相关问题