2012-08-14 186 views
4

我有一个WCF服务,它使用NetTcpBinding与消息安全和用户名认证。在此之前,我使用WsHttpBinding,但我切换到NetTcp,因为我可以使用回调。WCF NetTcpBinding安全

我服务的配置是这样的:

<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> 

我认为-in这种情况下,证明书的使用,因此该服务可以登录所有它发送给客户端的数据服务的凭证,所以客户端可以知道它正在与正确的服务进行通信。

客户端的配置如下:

<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

证书导致密钥用于加密邮件(我不确定它是否直接用作密钥本身,或用于协商密钥)。 AlgorithmSuite确定algorithm,它将使用该密钥来加密消息。


为什么你需要指定一个算法?
因为您需要告诉WCF 如何它应该加密您的消息。所使用的算法也在SOAP消息中标识,因为接收方必须知道使用什么算法来解密消息。请注意,如果您没有明确设置算法,它仍然会有一个值,即NetTcp的默认Basic256(source)。

如果启用消息跟踪,你会看到沿SOAP体这些线路的东西适当的(加密)的行动为您服务操作:

<e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" /> 

如果你想改变AlgorithmSuite到Basic128的以上将在算法属性的后一位中显示aes128-cbc

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

什么它加密?
该算法对证书和消息(使用在证书帮助下获得的密钥)进行加密,就像您已经说过的那样:-)。如果您启用message tracing,则可以看到这一点:凭证和邮件正文将使用选定的算法进行加密。


免责声明:我仍然在某处WCF学习曲线的斜率,因此,如果你的论文等级取决于这个你最好仔细检查我的主张:d