从内存

时间:2016-06-14 09:20:42

标签: c# wcf soap

我已经设置了一个小型演示项目来展示我的问题。我有一个vanilla WCF服务,通过基本的http绑定使用SOAP。

class Program
{
    static void Main(string[] args)
    {
        RunService();
        GC.WaitForFullGCComplete();
        Console.ReadKey();
    }

    static void RunService()
    {
        new WebService().Create("http://localhost:50562/Service1.svc", "", "");
    }
}

class WebService
{
    public void Create(string url, string username, string password)
    {
        var binding = createBinding();
        var endpoint = new EndpointAddress(new Uri(url));
        var channelFactory = new ChannelFactory<IService1>(binding, endpoint);
        var service = channelFactory.CreateChannel();

        Console.WriteLine(service.GetData(5));

        var channel = service as IClientChannel;
        channel.Close();
    }

    /// <summary>
    /// Creates the HttpBinding.
    /// </summary>
    /// <returns>The binding.</returns>
    private BasicHttpBinding createBinding()
    {
        var binding = new BasicHttpBinding();
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        binding.SendTimeout = new TimeSpan(0, 1, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 1, 0);
        return binding;
    }}

我有一个使用ChannelFactory创建代理的控制台应用程序。我们调用服务关闭连接然后运行GC。

问题在于,如果此时在Console.ReadKey()行执行应用程序的内存转储,则可以在内存中看到完整的SOAP请求字符串。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetData xmlns="http://tempuri.org/"><value>5</value></GetData></s:Body></s:Envelope> 

enter image description here

问题是如何将其保留在内存中以及如何将其删除?在此演示项目中可以,但我们希望从内存中删除敏感信息(标头中的用户凭据)我们的真实应用。

到目前为止,我已经看过验证我们正在正确关闭通道和WCF MessageBuffers以查看它们是否将它保留在内存中。我还使用了内存分析器来试着看看这个对象是什么但没有运气。我得出的唯一结论是它似乎是WCF引擎盖下的东西,因为我们的目标都不存在。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

  

问题在于,如果此时在Console.ReadKey()行执行应用程序的内存转储,则可以在内存中看到完整的SOAP请求字符串。

尝试以下方法之一可能会消除不安全地显示邮件内容的问题:

  1. 消息级而不是传输级加密。这样,消息不应该从内存中解读

  2. 自定义标头和身份验证提供程序:通过使用SecureString和自定义标头构造,您可以完全控制标头的形成和加密。您可以将此与传输或进一步的消息级加密一起使用

  3. 这里免费提供的牛排刀是您通过电线增强信息的安全性,而不仅仅是保护自己免受内存转储

    SecureString的

    OP的代码:

    public void Create(string url, string username, string password)
    

    为什么不使用SecureString作为参数?

    MSDN对此有SecureString

      

    SecureString是一种提供安全措施的字符串类型。它会尝试避免在流程内存中将潜在的敏感字符串存储为纯文本More...

    e.g。

    public void Create(string url, string username, SecureString password) { ... }    
    

    我会更担心您的凭据已发送 未加密,因此请务必使用消息级传输级加密。

相关问题