WCF NetTcpBinding安全性

4

我有一个使用NetTcpBinding、消息安全和用户名验证的WCF服务。之前我使用的是WsHttpBinding,但我转换到了NetTcp,因为我可以使用回调函数。

我的服务配置如下:

<service behaviorConfiguration="WcfServiceLibrary1.ServiceBehavior" name="WcfServiceLibrary1.Service">

    <endpoint
            address="net.tcp://localhost:9000/Design_Time_Addresses/WcfServiceLibrary1/Service/"
            binding="netTcpBinding"
            bindingConfiguration="NetTCPbinding"
            contract="WcfServiceLibrary1.IService"
            name="NetTCPBinding">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1/Service/" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <netTcpBinding>
    <binding name="NetTCPbinding">
      <security mode="Message">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="WcfServiceLibrary1.ServiceBehavior">
      <serviceCredentials>
        <serviceCertificate findValue="ServerCert" 
                            storeLocation="CurrentUser" 
                            storeName="TrustedPeople" 
                            x509FindType="FindBySubjectName" />
        <userNameAuthentication 
          userNamePasswordValidationMode="MembershipProvider" 
          membershipProviderName="CustomMembershipProvider" />
      </serviceCredentials>
      <!-- To avoid disclosing metadata information, 
      set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="True" />
      <!-- 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="true" />
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="MyRoleProvider" />
      <!-- Logs when an authentication failure -->
      <serviceSecurityAudit auditLogLocation="Application" 
                            suppressAuditFailure="true" 
                            serviceAuthorizationAuditLevel="Failure" 
                            messageAuthenticationAuditLevel="SuccessOrFailure" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我假设服务凭据- 在这种情况下是证书- 被用于让服务对发送给客户端的所有数据进行签名,以便客户端可以知道它正在与正确的服务通信。

客户端配置如下:

<behaviors>
  <endpointBehaviors>
    <behavior name="messageSecurityBehavior">
      <clientCredentials>
        <clientCertificate storeLocation="CurrentUser" 
                           storeName="TrustedPeople" 
                           x509FindType="FindBySubjectName" 
                           findValue="ClientCert" />
        <serviceCertificate>
          <authentication certificateValidationMode="None" />
        </serviceCertificate>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <netTcpBinding>
    <binding name="NetTCPBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
                transferMode="Buffered" transactionProtocol="OleTransactions"
                hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
                maxReceivedMessageSize="65536">
      <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" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </netTcpBinding>

</bindings>
<client>
  <endpoint address="net.tcp://localhost:9000/Design_Time_Addresses/WcfServiceLibrary1/Service/"
            binding="netTcpBinding" bindingConfiguration="NetTCPBinding"
            contract="IService" name="NetTCPBinding" behaviorConfiguration="messageSecurityBehavior">
    <identity>
      <certificate encodedValue="AwAAAAEAAAAUAAAAQerRMlEg2a66HMxD/8El6LutassgAAAAAQAAAOwBAAAwggHoMIIBVaADAgECAhAzOWVhNWUzM2Y5MzUwNzFhMAkGBSsOAwIdBQAwIjELMAkGA1UEBhMCVVMxEzARBgNVBAMTClNlcnZlckNlcnQwHhcNMTIwMTE3MTk1NDQ2WhcNMjUwOTI1MTk1NDQ2WjAiMQswCQYDVQQGEwJVUzETMBEGA1UEAxMKU2VydmVyQ2VydDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAs6SaYi3pDDIOuXeCe7HgOOTvOpwajKdxM8MzZpkK3l+DqkriMQUx9DT5I9WZvNK5FMuorLueG5adWkTgWpvttC7Sp8CJ//A+PbPewiAU4L3Txln6dX3jHZFd99LY/58/2AzY8ln2NykQFzz1DdmVeyShG9ktVsX82Ogz60lzpeUCAwEAAaMnMCUwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDgYDVR0PBAcDBQD6AAAAMAkGBSsOAwIdBQADgYEAMGQ7fIW34CYjybCc0gWOLaxeRFiNHmX/dgxqPIWGgg3uc0avz1GHJ3uMHcPAZBKcw9QpbccALpqZxZzkDBxufWjRni+8XCzeAKUqaB7XaJTYYUYBbz7/2+EuaAw7/vF4JTtZGWhPkHZZcX5+Oyo2ktK0z24MfXP2Ggy+IsQJ2JM=" />
    </identity>
  </endpoint>
</client>

所有这些都运行良好。我已经了解到服务证书用于加密客户端凭据和消息。那么我们为什么需要AlgorithmSuite中指定的算法呢?它加密了什么内容?
我需要充分理解这个问题,这样我才能在我的论文中进行解释。
1个回答

1
证书会导致用于加密消息的密钥(我不确定它是否直接用作密钥本身,还是用于协商密钥)。算法套件确定算法,该算法将使用该密钥对消息进行加密。
为什么需要指定算法? 因为您需要告诉WCF如何加密您的消息。所使用的算法也在SOAP消息中标识,因为接收方必须知道要使用什么算法来解密消息。请注意,如果您未明确设置算法,则仍将具有默认值Basic256 for NetTcp(source)。
如果启用了消息跟踪,则会在适当(加密的)操作中看到类似以下内容的SOAP正文:
<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />

如果您将AlgorithmSuite更改为Basic128,则上述内容将在Algorithm属性的后半部分显示aes128-cbc

在消息跟踪中,在与您的服务操作相对应的操作之前,将有几个操作在http://schemas.xmlsoap.org/ws/2005/02/trust/...范围内来协商所有安全选项。在WCF中的消息安全性 MSDN页面上,您可以看到WCF使用WS-Security规范。有关此规范的更多信息,您可以访问此页面,我在其中找到了WS-Security 2004规范(pdf)。如果您需要论文的官方参考资料,这也可能很有用。

它加密了什么?
该算法加密了凭据和消息(使用从证书获取的密钥),就像您已经说明的那样 :-)。如果您启用message tracing,您可以看到这一点:所选算法将加密凭据和消息正文。


免责声明:我仍然处于 WCF 学习曲线的某个阶段,所以如果您的论文成绩取决于此,请最好再次核实我的说法:D

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接