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
Friday
DIY Robocars via Twitter
RT @_JonMyer: 🏎 We need your help in naming my #AWS DeepRacer Underground Track 🏎 @davidfsmith's track is going to be referred to as 𝗔𝗪𝗦 𝗗…
Thursday
DIY Robocars via Twitter
RT @gclue_akira: 仕事もおわったし、電脳化にとらい #マリオカートハック https://t.co/4IU90hCLgm
Thursday
DIY Robocars via Twitter
This is the hashtag to follow all the people in Japan who are hacking the new Nintendo Mario Kart with the real AR… https://twitter.com/i/web/status/1319281354664677376
Thursday
DIY Robocars via Twitter
RT @gclue_akira: @chr1sa @diyrobocars jupyter mario https://t.co/P0oHdjlCRq
Thursday
DIY Robocars via Twitter
RT @_JonMyer: 🚨Our 1st AWS DeepRacer Community Race is Underway on http://twitch.tv/aws 🚨 Join us to find out which member of your commu…
Oct 20
DIY Robocars via Twitter
Oct 19
DIY Robocars via Twitter
RT @BackyardRobotcs: After an admittedly long wait, the new Tinymovr R3.3 motor controller is now available https://tinymovr.com 🥳
Oct 19
DIY Robocars via Twitter
RT @_JonMyer: 🏎 1 hr left before the #AWS #DeepRacer Community 🏎 Top 5 Race tomorrow LIVE on Twitch 1st Place = $50 Amazon GC or AWS Credit…
Oct 19
DIY Robocars via Twitter
Oct 16
DIY Robocars via Twitter
Oct 15
DIY Robocars via Twitter
Oct 14
DIY Robocars via Twitter
RT @davidfsmith: Race virtually with The AWS DeepRacer Community Race and then join us on the track to see how your times compare on the ph…
Oct 14
DIY Robocars via Twitter
Oct 14
Hiroki Tanaka liked Hiroki Tanaka's profile
Oct 13
DIY Robocars via Twitter
RT @breadcentric: It's now!
Oct 13
More…