【问题标题】:Protect WCF from fiddler (MITM) (PCL XAMARIN FORMS)保护 WCF 免受提琴手 (MITM) (PCL XAMARIN FORMS)
【发布时间】:2019-06-19 15:17:26
【问题描述】:

我有使用可移植类库的 xamarin 表单项目。 在那个 PCL 中,我引用了托管在某个服务器中的 WCF 服务。

wcf 绑定是具有安全传输的 Basichttpbinding,因为 PCL 不支持 wshttpbinding。

wcf 也使用 https,我有一个有效的证书。

我想保护消息的安全,因为现在如果我在我的 android 中安装某种应用程序提琴手或打包监视器,每次调用我的服务时,我都可以看到可读格式的 xml 数据。

我认为通过使用 https 我可以保护它。 我尝试使用 wcf TransportWithMessageCredential 但它无法登录到我的服务,因为 xamarin 尚不支持此组合

所以:(经过研究我发现)

  • PCL 不支持 wshttpbinding,只支持 basicHttpBinding
  • Xamarin.Forms basicHttpBinding 不支持消息安全,但仅支持 仅传输凭据

还有

  • Xamarin 不支持 TransportWithMessageCredential,但仅支持 传输安全,但传输安全不能保护数据免受 MITM 的侵害。

其他人如何使用 xamarin 表单并保护这些数据? 我错过了什么吗? 有什么建议?

已编辑


我正在尝试在发送到服务之前加密 xml 请求,但每次我将消息从 xml 更改为编码字符时都会失败(我猜是因为服务器无法识别架构)

我在客户端实现了 IClientMessageInspector,在服务器端也实现了 IDispatchMessageInspector

我需要一些帮助,如何将加密的 xml 请求发送到服务器。如果我在这里这样做,那么我可以从服务端(服务器)解码它

在客户端我有以下内容

  Public Function BeforeSendRequest(ByRef request As Message, channel As IClientChannel) As Object Implements IClientMessageInspector.BeforeSendRequest

    Dim Binding As New BasicHttpBinding(BasicHttpSecurityMode.Transport)

    Dim ms As MemoryStream = New MemoryStream(System.Text.Encoding.UTF8.GetBytes(EncryptedData(request.ToString)))

    Dim RQuotas As Xml.XmlDictionaryReaderQuotas = Binding.ReaderQuotas

    Dim reader = Xml.XmlDictionaryReader.CreateTextReader(ms, RQuotas)
    request = Message.CreateMessage(reader, Int32.MaxValue, request.Version)


    Return Nothing

End Function

我不确定我是否做得正确。欢迎任何帮助。

【问题讨论】:

  • 为什么不创建一个调用您的 wcf 服务的 restful webapi,然后从您的移动应用程序中使用该 webapi?
  • 您关于basicHttpBinding 不支持消息安全的说法是不正确的。 (docs.microsoft.com/en-us/dotnet/framework/wcf/samples/…doc]
  • 在 xamarin.Forms BasicHttpBinding 中仅支持 TransportCredentialOnly 。我会编辑它。

标签: wcf xamarin.forms portable-class-library basichttpbinding


【解决方案1】:

Fiddler 仅在您接受其证书的情况下解密 Https Traffic,它基本上充当中间人并处理从服务到您的应用程序的所有调用,这里有一些有用的信息 https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/DecryptHTTPS


在您第二次更新问题时,您需要创建一个容器来容纳您的所有消息, 这样您就可以根据需要对数据进行解密和加密,

一个简单的例子可以在https://misaxionsoftware.wordpress.com/2011/07/29/secure-restful-web-service-by-wcf-web-api-no-https-seriously/找到

您可以尽可能地自定义它

这是上面链接中定义的消息

留言

public class Message
{
    public string AppId { get; set; }

    public string Data { get; set; }

    public string Id { get; set; }

    public string TimeStamp { get; set; }

    public byte[] GenerateFingerprint();

    public bool ValidateHash(byte[] fingerprint);
}

加密消息

public class EncryptedMessage
{
    public string AppId { get; set; }

    public byte[] Fingerprint { get; set; }

    ///<summary>
    /// The 3DES key used to encrypt/decrypt the message 
    /// </summary>
    public byte[] Key { get; set; }

    ///<summary>
    /// Encrypted message
    /// </summary>
    public byte[] Message { get; set; }
}

IEncryptionHelper

public interface IEncryptionHelper
{
    EncryptedMessage Encrypt(Message message);

    Message Decrypt(EncryptedMessage encryptedMessage);
}

【讨论】:

  • 这是我想要保护的。但是 WCF、PCL、XAMARIN 的组合不允许我完全使用安全功能(至少我知道的),现在通过堆栈...我问是否有任何解决方法
  • 如果你不信任证书,它可以解密它,就这么简单,如果你正在寻找不同的东西,你需要加密服务上的信息并在你身边使用解密它在众多加密算法中
  • 简单查看https://security.stackexchange.com/questions/53596/how-safe-is-ssl 即可了解 SSL 的安全性。
  • 很抱歉,但我仍然对如何防止这种情况感到困惑:例如,有人在他的手机上安装了我的 android 应用程序,在安装 fiddler 之后,然后开始运行我的应用程序,那么当然如果他会检查 fiddler 他将从我的服务响应中看到我的 xml 结构和数据.. 那么如何保护..?你怎么能保护它?
  • https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rijndaelmanaged?redirectedfrom=MSDN&view=netframework-4.7.2 向您展示如何使用 AES,您需要在客户端和服务器端使用相同的密钥来解密数据
猜你喜欢
  • 2016-07-29
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-11
  • 1970-01-01
相关资源
最近更新 更多