【问题标题】:How can I encrypt, but not secure WCF messages?如何加密但不保护 WCF 消息?
【发布时间】:2011-11-03 14:43:24
【问题描述】:

我创建了一个应用程序,它可以让机器通过网络相互通信。我想使用 NetTCPBinding 并加密消息。但是我不想要或不需要证书或 Windows 身份验证。我尝试将安全模式设置为 Message 以获取加密并将传输安全设置为 none 以避免证书/Windows 身份验证,但我仍然得到:

System.ServiceModel.Security.SecurityNegotiationException:调用者 未通过服务进行身份验证。 ---> System.ServiceModel.FaultException:安全令牌请求 无法满足,因为身份验证失败。

以下是相关代码:

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

【问题讨论】:

  • 为什么?这似乎是一个不寻常的目标 - 如果攻击者可以将自己拼接在您的两个端点之间,那么加密就没有什么意义了。这只是假的安全。我建议您使用带有服务器证书的传输安全性来满足大多数基本加密需求(HTTPS 风格的方法)。
  • @Sander - 有没有办法做到这一点,以便可以通过用户机器上的安装程序安装可下载的桌面应用程序,而无需他们做任何事情或了解证书,或不必为证书生成证书每次安装?

标签: .net wcf wcf-security


【解决方案1】:

这个问题的答案有效: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();

【讨论】:

    【解决方案2】:

    我想这就是你要找的东西:Message Security with an Anonymous Client。我想你的问题是你的服务没有在服务器端指定证书:

    初始协商需要服务器认证,但不需要客户端认证

    因此,在实例化服务时,请尝试执行类似(来自 MSDN)的操作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多