TL; DR —» Where exactly in the Mission Planner source code would I insert encryption/decryption functions from the libsodium-net crypto library?

(With help from a friend) I've already integrated encryption & decryption functions from NaCl into the APM 2.5 source code, so now I need to do the same in the ground control station to be able to communicate with it... my problem: I'm unfamiliar with C#. I'm familiar with enough programming languages to be able to read & understand it, but not enough to know how/where to include the "SecretBox" functions from libsodium-net in the Mission Planner source code to accomplish this.

Here's where I think I should include the encryption & decryption functions (I hope a developer will correct me if I'm wrong):

[For encryption] From the "MAVLink.cs" file in the MissionPlanner-master\Mavlink\ directory, the generatePacket() function [my speculation is in red]

lock (objlock)
{
    byte[] data;
    byte[] key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; //ADDED THIS!
    byte[] nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //ADDED THIS!
    byte[] ct; //ADDED THIS!

    data = MavlinkUtil.StructureToByteArray(indata);
    ct = SecretBox.Create(data, nonce, key); //ADDED THIS!

//Console.WriteLine(DateTime.Now + " PC Doing req "+ messageType + " " + this.BytesToRead);
    byte[] packet = new byte[data.Length + 6 + 2];

    packet[0] = 254;
    packet[1] = (byte)ct.Length;
    packet[2] = (byte)packetcount;

    packetcount++;

    packet[3] = 255; // this is always 255 - MYGCS
    packet[4] = (byte)MAV_COMPONENT.MAV_COMP_ID_MISSIONPLANNER;
    packet[5] = messageType;

    int i = 6;
    foreach (byte b in ct)
    {
        packet[i] = b;
        i++;
    }

    ushort checksum = MavlinkCRC.crc_calculate(packet, packet[1] + 6); 

    checksum = MavlinkCRC.crc_accumulate(MAVLINK_MESSAGE_CRCS[messageType], checksum);

    byte ck_a = (byte)(checksum & 0xFF); ///< High byte
    byte ck_b = (byte)(checksum >> 8); ///< Low byte

    packet[i] = ck_a;
    i += 1;
    packet[i] = ck_b;
    i += 1;

[For decryption] From the "MavlinkParse.cs" file in the MissionPlanner-master\ExtLibs\Mavlink\ directory, the GenerateMAVLinkPacket() function [my speculation is in red]

public byte[] GenerateMAVLinkPacket(MAVLINK_MSG_ID messageType, object indata)
{
    byte[] data;

    byte[] key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; //ADDED THIS!
    byte[] nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //ADDED THIS!
    byte[] pt; //ADDED THIS!

    data = MavlinkUtil.StructureToByteArray(indata);

    pt = SecretBox.Open(data, nonce, key); //ADDED THIS!

    byte[] packet = new byte[pt.Length + 6 + 2];

    packet[0] = 254;
    packet[1] = (byte)pt.Length;
    packet[2] = (byte)packetcount;

    packetcount++;

    packet[3] = 255; // this is always 255 - MYGCS
    packet[4] = (byte)MAV_COMPONENT.MAV_COMP_ID_MISSIONPLANNER;
    packet[5] = (byte)messageType;


    int i = 6;
    foreach (byte b in pt)
    {
        packet[i] = b;
        i++;
    }

    ushort checksum = MavlinkCRC.crc_calculate(packet, packet[1] + 6);

    checksum =     MavlinkCRC.crc_accumulate(MAVLINK_MESSAGE_CRCS[(byte)messageType],     checksum);

    byte ck_a = (byte)(checksum & 0xFF); ///< High byte
    byte ck_b = (byte)(checksum >> 8); ///< Low byte

    packet[i] = ck_a;
    i += 1;
    packet[i] = ck_b;
    i += 1;

    return packet;
    }

}

Cany any Mission Planner developers, or anyone familiar with C# please help me?

[Note: I'm aware the MAVLink developers are in the process of developing sMAVLink, but their completion deadline isn't as soon as mine.]

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Developer

    the encryption part looks like its in the correct place.

    the decription however is not.

    look in the MP/mavlink/mavlink.cs in function readPacket

This reply was deleted.

Activity

Gremsy liked Gremsy's profile
Mar 12
DIY Robocars via Twitter
RT @chr1sa: Donkeycar 4.4 released with tons of new features, including path learning (useful with GPS outdoors), better Web and Lidar supp…
Nov 27, 2022
DIY Robocars via Twitter
RT @NXP: We are already biting our nails in anticipation of the #NXPCupEMEA challenge! 😉 Did you know there are great cash prizes to be won…
Nov 24, 2022
DIY Robocars via Twitter
RT @gclue_akira: レースまであと3日。今回のコースは激ムズかも。あと一歩 #jetracer https://t.co/GKcEjImQ3t
Nov 24, 2022
DIY Robocars via Twitter
UC Berkeley's DIY robocar program https://roar.berkeley.edu/
Nov 24, 2022
DIY Robocars via Twitter
RT @chr1sa: The next @DIYRobocars autonomous car race at @circuitlaunch will be on Sat, Dec 10. Thrills, spills and a Brazilian BBQ. Fun…
Nov 24, 2022
DIY Robocars via Twitter
RT @arthiak_tc: Donkey car platform ... Still training uses behavioral cloning #TCXpo #diyrobocar @OttawaAVGroup https://t.co/PHBYwlFlnE
Nov 20, 2022
DIY Robocars via Twitter
RT @emurmur77: Points for style. @donkeycar racing in @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/Y2hMyj1…
Nov 20, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Going to @diyrobocars race at @UCSDJacobs https://t.co/Rrf9vDJ8TJ
Nov 8, 2022
DIY Robocars via Twitter
RT @SmallpixelCar: Race @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/kK686Hb9Ej
Nov 8, 2022
DIY Robocars via Twitter
RT @PiWarsRobotics: Presenting: the Hacky Racers Robotic Racing Series in collaboration with #PiWars. Find out more and register your inter…
Oct 23, 2022
DIY Robocars via Twitter
RT @Hacky_Racers: There will be three classes at this event: A4, A2, and Hacky Racer! A4 and A2 are based around UK paper sizing and existi…
Oct 23, 2022
DIY Robocars via Twitter
Oct 23, 2022
DIY Robocars via Twitter
Oct 19, 2022
DIY Robocars via Twitter
Oct 18, 2022
DIY Robocars via Twitter
RT @NeaveEng: Calling all UK based folks interested in @diyrobocars, @f1tenth, @donkey_car, and similar robot racing competitions! @hacky_r…
Oct 13, 2022
More…