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

DIY Robocars via Twitter
RT @_JonMyer: 🚨Attention DeepRacer's including #UndergroundDeepRacer🚨 Check our our LIVE stream that including @IAM_dbro Take a few moments…
14 hours ago
DIY Drones via Twitter
RT @MarvelmindMaxim: Extreme precision for 60 swarming robots. #marvelmind #autonomousrobotics #robotics #swarmrobotics #rtls #ips #indoor…
Monday
DIY Drones via Twitter
RT @MarvelmindMaxim: Precise (±2cm) tracking for racing boats and autonomous boats. Works outdoor and indoor. #autonomous #AutonomousVehic…
Monday
DIY Drones via Twitter
RT @MarvelmindMaxim: Helping PixHawk folks to fly autonomous quadcopters using PX4 and ArduPilot. https://marvelmind.com/drones/ Equally suitab…
Monday
DIY Robocars via Twitter
RT @chr1sa: The @DIYRobocars @donkey_car virtual AI car race is starting in 15 minutes! Watch it live on Twitch https://www.twitch.tv/mossmann3333 htt…
Saturday
DIY Robocars via Twitter
RT @chr1sa: Don't miss our monthly @DIYRobocars @donkey_car virtual AI car race tomorrow at 10:00am PT live on Twitch. Head-to-head racing…
Friday
DIY Robocars via Twitter
RT @sparkfun: Our completed tutorial on building an @NVIDIA Jetson Nano-powered @Sphero RVR gets your bot up and running via teleoperation…
Jul 30
DIY Robocars via Twitter
RT @SmallpixelCar: Freeway test https://t.co/4V5tV9lhIP
Jul 29
DIY Robocars via Twitter
Very small autonomous cars racing, thanks to an overhead camera: https://control.ee.ethz.ch/research/team-projects/autonomous-rc-car-racing.html
Jul 29
DIY Robocars via Twitter
Jul 29
DIY Robocars via Twitter
Jul 29
DIY Robocars via Twitter
RT @chr1sa: Don't miss our virtual AI car race this Saturday! Real developers + virtual cars =🏎️🏎️🏎️ Head-to-head battles with thrills, sp…
Jul 28
DIY Robocars via Twitter
Jul 27
DIY Robocars via Twitter
RT @usashirou1: Jetson nano by Isaac Kaya #jetson https://t.co/Mu1N0CyQkN
Jul 23
DIY Robocars via Twitter
RT @GPUsolution: JetRacer mady by Iflytek company #JetsonNANO #Nvidia https://t.co/MimTymIwge
Jul 23
DIY Robocars via Twitter
RT @openmvcam: I love this: Mega or Mini? Image Classification on the 1MB OpenMV Cam H7 by Ish Ot Jr. in OpenMV, Edge Impulse, Internet of…
Jul 23
More…