custom XOR encryption of signalling and media transport in PJSIP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Laurent, tu ne t'es pas gour? de postit de
?
Le 20 janv. 2014 09:24, "master voip" <voip.batsman at gmail.com> a ?crit :

> Hi
>
> I am running a proxy server which supports signalling and media  custom
> encryption based on XOR encryption with a key and prefix base.
>
> Proxy Server side plugin code includes iostream header  which listen for
> UDP stream coming into and match the packet size decrypt the stearm with
> the key  then pass it to SIP server .
>
> i would like to know which files have to be modified in client side PJSIP
> useragent  inorder to send encrypted signalling and media stream ?.
>
>  .
>
> Thank you
>
> Part of code in plugin :
>
>
>
> "
> #include <iostream>
> #include <string>
> #include <vector>
> #include <string.h>
> extern "C" { bool initializePlugin(PROXYPluginContainer* pluginManager); }
> typedef std::vector<char> Packet;
> static PROXYPluginContainer* _pPluginManager = 0;
> class XOREncryptor : public PROXYEncryptionPluginBase
> {
> public:
>  std::string _key;
>  std::string _prefix;
>  XOREncryptor()
>  {
>    for(int i = 0; i < 6; i++)
>      _key.push_back((char)(171 + i));
>    _prefix = "0000";
>  }
>  void applyXor(Packet& packet)
>  {
>    if (packet.empty())
>      return;
>    //
>    // Reserve enough space for the out buffer
>    //
>    Packet out;
>    out.reserve(packet.size());
>    std::size_t keyLen = _key.size();
>    std::size_t offset = 0;
>    //
>    // Apply the XOR for each byte
>    //
>    for (Packet::const_iterator iter = packet.begin(); iter != packet.end();
> iter++)
>    {
>      if (offset == keyLen)
>        offset = 0;
>      out.push_back(*iter ^ _key.at(offset));
>      offset++;
>    }
>    packet = out;
>  }
>  void applyPrefix(Packet& packet)
>  {
>    //
>    // Insert the prefix at the beginning of the packet if it is present
>    //
>    if (_prefix.empty())
>      return;
>    Packet out;
>    out.reserve(packet.size() + _prefix.size());
>    for (std::string::const_iterator iter = _prefix.begin(); iter !=
> _prefix.end(); iter++)
>    {
>      out.push_back(*iter);
>    }
>    for (Packet::const_iterator iter = packet.begin(); iter != packet.end();
> iter++)
>    {
>      out.push_back(*iter);
>    }
>    packet = out;
>  }
>  void removePrefix(Packet& packet, std::size_t len)
>  {
>    if (packet.empty())
>      return;
>    Packet out;
>    std::size_t offset = 0;
>    std::string prefix;
>    prefix.reserve(_prefix.size());
>    out.reserve(len);
>    for (Packet::const_iterator iter = packet.begin(); iter != packet.end();
> iter++)
>    {
>      if (offset < len)
>        prefix.push_back(*iter);
>      else
>        out.push_back(*iter);
>
>      offset++;
>    }
>    if (prefix == _prefix)
>    {
>      //PLUGIN_LOG_INFO("Removed prefix " << prefix << " prior to
> decryption");
>      packet = out;
>    }
>    else
>    {
>      //PLUGIN_LOG_WARNING("Prefix is not removed.  Collected prefix is " <<
> prefix);
>    }
>  }
>
>  void encryptSIP(Packet& packet)
>  {
>    applyXor(packet);
>    //applyPrefix(packet);
>  }
>  void decryptSIP(Packet& packet)
>  {
>    //removePrefix(packet, _prefix.size());
>    applyXor(packet);
>  }
>  void encryptRTP(Packet& packet)
>  {
>    applyXor(packet);
>    applyPrefix(packet);
>  }
>  void decryptRTP(Packet& packet)
>  {
>    if (packet.empty() || packet.size() < _prefix.size())
>    {
>      PLUGIN_LOG_ERROR("XOREncryptor::decryptRTP discarding inadequate size
> packet with " << packet.size() << " bytes.");
>    }
>    removePrefix(packet, _prefix.size());
>    applyXor(packet);
>    if (packet.empty())
>      return;
>    if (((packet[0]>>6)&3) != 2)
>    {
>      //
>      // We had trouble decrypting the RTP packet if it ever gets here
>      //
>      PLUGIN_LOG_ERROR("XOREncryptor::decryptRTP returned a malformed
> output");
>    }
>  }
> };"
> "
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20140120/ad64f26c/attachment-0001.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux