2011-08-25 71 views
2

我创建了一个应用程序,让机器可以通过网络彼此交谈。我想使用NetTCPBinding并加密邮件。但是我不想要或不需要证书或Windows身份验证。我尝试安全模式设置为留言以获得加密和传输的安全性,以无以避免证书/ windows身份验证,但我仍然得到:如何加密但不保护WCF消息?

System.ServiceModel.Security.SecurityNegotiationException:来电者 没有被验证服务。 ---> System.ServiceModel.FaultException:由于身份验证失败,无法满足安全令牌 的请求。

下面是相关代码:

NetTcpBinding binding = new NetTcpBinding(); 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; 
+0

见http://stackoverflow.com/questions/1570939/wcf-message-security-without-certificate-and-windows-auth – Cocowalla

+0

为什么?这似乎是一个不寻常的目标 - 如果攻击者可以在自己的两个端点之间拼接,那么加密就没有多大意义。这只是假安全。我建议您使用带有服务器证书的传输安全性来满足大多数基本加密需求(HTTPS风格的方法)。 – Sander

+0

@Sander - 是否有办法做到这一点,以便可以通过用户计算机上的安装程序安装可下载的桌面应用程序,而无需执行任何操作或了解证书,或者必须为每次安装生成证书? – DaveO

回答

3

从这个问题的回答工作:selfhosting wcf server - load certificate from file instead of certificate store

我的代码:

var certificate = new X509Certificate2("cert.pfx", ""); 

host = new ServiceHost(MessageProvider, address); 
host.Credentials.ServiceCertificate.Certificate = certificate; 
host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 

NetTcpBinding binding = new NetTcpBinding(); 
binding.Security.Mode = SecurityMode.Message; 
binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; 
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; 
host.AddServiceEndpoint(typeof(IService), binding, address); 
host.Open(); 
1

我认为这是你在找什么:Message Security with an Anonymous Client。我想在你的情况下,问题是,你的服务没有指定服务器端的证书:

初始协商要求服务器验证,而不是客户端身份验证

所以实例化的服务尝试时做这样的事情(从MSDN):

myServiceHost.Credentials.ServiceCertificate.SetCertificate(
    StoreLocation.LocalMachine, 
    StoreName.My, 
    X509FindType.FindByThumbprint, 
    "00000000000000000000000000000000");