asp.net - wcf:将用户名添加到消息 header 安全吗?

标签 asp.net wcf web-services security

我正在连接到 ASP.NET 应用程序中的 WCF 服务。我使用一个用户名和密码登录,并在消息 header 中传递登录 ASP.NET Web 应用程序的实际用户名,如下所示。

  using (OperationContextScope scope = new OperationContextScope(myService2.InnerChannel))
  {
    Guid myToken = Guid.NewGuid();

    MessageHeader<string> messageHeader = new MessageHeader<string>(HttpContext.Current.User.Identity.Name);
    MessageHeader untyped = messageHeader.GetUntypedHeader("token", "ns");

    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);

    lblResult.Text = myService2.GetData(1231);
  }

我还使用如下服务证书

      <serviceCredentials>
        <serviceCertificate findValue="CN=tempCert" />
        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
          membershipProviderName="MySqlMembershipProvider" />
      </serviceCredentials>

我担心的是,这是否足以阻止人们获取存储在邮件 header 中的用户名?

ASP.NET 配置是

    <system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="NewBehavior">
                <clientCredentials>
                    <serviceCertificate>
                        <authentication revocationMode="NoCheck"/>
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="wsHttpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/WCFTestService/Service.svc" behaviorConfiguration="NewBehavior" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpoint" contract="WCFTestService.IService" name="wsHttpEndpoint">
            <identity>
                <certificate encodedValue=""/>
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

在服务端它

  <system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding">
      <security>
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="ServiceBehavior" name="Service">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
      name="wsHttpEndpoint" contract="IService">
      <!--<identity>
        <dns value="" />
      </identity>-->
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <serviceCredentials>
        <serviceCertificate findValue="CN=tempCert" />
        <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
          membershipProviderName="MySqlMembershipProvider" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

最佳答案

最大的问题是:您的绑定(bind)是否启用了任何类型的传输级或消息级安全性?您使用什么绑定(bind)?

如果您具有传输级安全性(通常通过在 SSL 上使用 HTTPS),那么您就有一个我认为非常安全的点对点加密传输 channel 。

如果您也使用客户端上的证书实现消息级安全性,并且您确实加密了整个消息,那么您也应该是安全的。

这实际上归结为您正在使用的绑定(bind)以及您在该绑定(bind)上使用的安全设置。向我们展示服务器的配置!

马克

关于asp.net - wcf:将用户名添加到消息 header 安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/893588/

相关文章:

javascript - 拖放列表项后获取列表顺序 asp.net c#

c# - .Net Identity 中 UserManager 的奇怪行为

C# 动态站点地图内存泄漏

php - 如何从 bash 和 php 脚本更新 Bugzilla 错误?

javascript - 有没有办法获取我的 Stack Exchange 统计数据?

c# - 如何在 public static void 方法中创建消息框

c# - 诊断应用程序变慢和内存消耗(可能是 WCF 或 MongoDB C# 驱动程序)?

c# - 一个 WCF 服务可以返回另一个吗?

sql - 从 C# 中的 SQL CLR 过程调用 WCF 服务

php - 通过 SoapClient 连接到 eBay Trading API 抛出 'The web service eBayAPI is not properly configured or not found and is disabled' 异常