【问题标题】:wcf: adding username to the message header is this secure?wcf:将用户名添加到消息头是否安全?
【发布时间】:2009-05-21 15:37:32
【问题描述】:

我正在连接到 ASP.NET 应用程序中的 WCF 服务。我正在使用一个用户名和密码登录,并将登录到 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>

我担心的是这种保护是否足以阻止人们获取存储在邮件标题中的用户名?

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>

【问题讨论】:

    标签: asp.net wcf web-services security


    【解决方案1】:

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

    如果您具有传输级别的安全性(通常通过使用基于 SSL 的 HTTPS),那么您将拥有一个我认为非常安全的点对点加密传输通道。

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

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

    马克

    【讨论】:

    • 我已经更新了我的帖子以显示我的配置。仍然对所有这些东西感觉我的方式,所以我会感激任何智慧的金块!
    • 我认为你应该没事。您已指定 wsHttpBinding,并且服务使用服务证书向客户端验证自身。您已经指定了消息级别的安全性,这意味着,客户端都将使用服务证书的公钥来加密他们的消息,通过网络发送它们,并且由于它们是使用服务的公钥加密的,因此只有具有相应的服务的服务私钥可以解密它们。我认为你应该是安全的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多