【发布时间】: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 中以纯文本格式读取用户名和密码。这是因为提琴手做了一些魔术来读取我的证书加密还是发送的消息根本没有加密?
在这种情况下,我是否必须自己加密和解密数据?
我不想在客户端上安装证书。
【问题讨论】: