我有一个WCF服务,它使用带有消息安全性和用户名身份验证的NetTcpBinding。在此之前,我使用的是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中指定的算法呢?它加密了什么?
我需要很好地理解这一点,这样我才能在我的论文中解释它。
发布于 2012-09-11 22:35:46
证书导致用于对消息进行加密的密钥(我不确定它是直接用作密钥本身,还是用于协商密钥)。AlgorithmSuite确定将使用该密钥加密消息的算法。
为什么需要指定一个算法?
因为您需要告诉WCF它应该如何加密您的消息。所使用的算法也在SOAP消息中被识别,因为接收方必须知道要使用什么算法来解密消息。注意,如果没有显式设置一个算法,它仍然有一个值,即默认的Basic256 for NetTcp (来源)。
如果启用消息跟踪,将在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/...范围内将有几个操作来协商所有的安全选项。在WCF中的消息安全性 MSDN页面上,您可以看到WCF使用WS-Security规范。有关此规范的更多信息,您可以访问此页,在那里我找到了WS-安全2004规范(pdf)。这也可能是有用的,如果你需要官方参考你的论文。
,加密了什么?
该算法同时加密凭据和消息(使用从证书中获得的密钥),就像您已经说过的那样:-)。如果启用消息跟踪,您可以看到这一点:凭据和消息正文都将使用所选的算法进行加密。
免责声明:我还在WCF学习曲线的斜坡上,所以如果你的论文成绩取决于这个,你最好再检查一遍我的说法:D
https://stackoverflow.com/questions/11960098
复制相似问题