【问题标题】:Securing a WCF WebService without using a certificate在不使用证书的情况下保护 WCF WebService
【发布时间】:2011-03-04 16:58:25
【问题描述】:

几天来,我一直在尝试正确保护我的 WCF WebService,但是我现在遇到了障碍。我正在尝试在不使用证书的情况下保护此 WebService,因为这将在安全的 Intranet 中运行。

我希望能够通过用户名/密码保护 WebService,而不必更改每个方法来验证用户名和密码,也不必使用证书。这可能吗:

我当前的 web.config 如下:

<?xml version="1.0"?>
<configuration>
 <system.web>
  <compilation debug="true" targetFramework="4.0" />
 </system.web>
 <system.serviceModel>
  <services>
   <service name="TestWS.Service1" behaviorConfiguration="Default">
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    <endpoint contract="TestWS.IService1" binding="wsHttpBinding" bindingConfiguration="Binding1" address="" />
  </service>
 </services>
 <bindings>
  <wsHttpBinding>
    <binding name="Binding1">
      <security mode="Message">
       <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
 </bindings>
 <behaviors>
  <serviceBehaviors>
    <behavior name="Default">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="TestWS.Validation.VanguardValidator, TestWS" />
      </serviceCredentials>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
</configuration>

提前致谢,

帕特里克

【问题讨论】:

  • 如果您使用用户名/密码验证,您可能会在消息中以纯文本形式发送凭据。因此,您要么需要使用传输级安全性 (https://....),要么您必须在服务器端拥有一个证书来提供共享密钥的方法,以便客户端和服务器可以加密和签名。或者,如果您根本不需要任何东西,您可以一起关闭安全性。
  • 这被回答了好几次...... WsHttpBinding 不可能。可以使用自定义绑定,但凭据将以纯文本形式发送,因此不应使用。
  • 我认为是适合您的链接,webservices20.blogspot.com/2008/11/… 此链接显示了如何在 HTTP 上使用用户名/密码安全性,即不使用证书。干杯!!!
  • 感谢您的文章!但它并没有最终奏效。我想我最终会放弃这个。

标签: .net wcf web-services security wcf-security


【解决方案1】:

如果您使用用户名/密码验证,您可能会在消息中以纯文本形式发送凭据。因此,您要么需要使用传输级 (SSL) 安全性 (https://....),要么必须在服务器端拥有证书以提供共享机密的方式,以便客户端和服务器之间的消息可以加密并签字。或者,如果您根本不需要任何东西,您可以一起关闭安全性。

请参阅 Fundamentals of WCF Security 了解 WCF 安全性的精彩介绍、MSDN docs on Programming WCF Security 或 Juval Löwy 在 Declarative WCF Security 上的出色 MSDN 文章

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    相关资源
    最近更新 更多