我创建了 WCF,并使用 wsHttpBinding 和 MTOM 作为消息传输,并将身份验证作为“Windows”。
现在我的服务不是当前安全的,它是纯 HTTP,在自定义端口上运行。
WCF 的 wsHttpBinding 的 Windows 身份验证安全吗?任何人都可以通过网络跟踪看到或猜测密码吗?
环境信息:
- 托管在互联网上
- 没有 Active Directory,只有一个服务器
- 使用服务器的管理员用户名和密码从我的办公室连接
- 在客户端,配置文件中没有提到密码,它是在运行时输入的。它可以正常工作,因为输入错误的凭据也会返回某种安全异常。
- 在自定义端口 89 上运行 .NET 4.0,目前我在我的自定义 Windows 服务的 app.config 中设置了以下配置,我在安装为本地服务的自定义 Windows 服务中托管我的 WCF。我在每种方法上都启用了模拟。
这是app.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metaAndErrors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceAuthorization impersonateCallerForAllOperations="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="CustomServiceHost.CustomService"
behaviorConfiguration="metaAndErrors"
>
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpLargeBinding"
contract="CustomServiceHost.ICustomService"/>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:89/CustomService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding
name="wsHttpLargeBinding" messageEncoding="Mtom"
maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="512000"/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
以下是在运行时完成的客户端配置,
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Message.ClientCredentialType
= MessageCredentialType.Windows;
binding.Security.Mode = SecurityMode.Message;
binding.MessageEncoding = WSMessageEncoding.Mtom;
binding.ReaderQuotas.MaxArrayLength = 512000;
CustomServiceClient cc = new CustomServiceClient(
binding,
new EndpointAddress(string.Format(
"http://{0}:89/CustomService",
host.ServerHost))
);
cc.ClientCredentials.Windows.AllowedImpersonationLevel
= System.Security.Principal.TokenImpersonationLevel.Impersonation;
cc.ClientCredentials.Windows.ClientCredential
= new NetworkCredential(host.Username, host.Password);
谢谢, - 阿卡什
最佳答案
关于您关于密码的问题:Windows 身份验证使用 Kerberos 或 NTLM,并且这两种协议(protocol)都不以明文形式传输密码。
此信息写在这里: http://msdn.microsoft.com/en-us/library/ff647076.aspx
You should use Integrated Windows authentication instead of basic authentication because it avoids transmitting user credentials over the network.
这意味着您不需要 SSL 来保护您的密码,但如果您有其他敏感信息(在您的服务调用中),那么您应该考虑使用加密(例如 SSL)。我没有尝试过这个,但它应该可以帮助您入门:
http://www.codeproject.com/KB/WCF/WCFSSL.aspx
另一种选择是加密消息(消息安全而不是传输安全)。这是另一个可以帮助您入门的链接:
关于.net - WCF wsHttpBinding 的 Windows 身份验证有多安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2906685/