Add AES-CTR decryption support for encrypted Meshtastic packets in meshview.ino - #5
Draft
SpudGunMan with Copilot wants to merge 7 commits into
Draft
Add AES-CTR decryption support for encrypted Meshtastic packets in meshview.ino#5SpudGunMan with Copilot wants to merge 7 commits into
SpudGunMan with Copilot wants to merge 7 commits into
Conversation
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ability to decode packets and change channel and key
Add AES-CTR decryption support for encrypted Meshtastic packets in meshview.ino
Oct 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Enhances
meshview.inoto fully support encrypted Meshtastic packet decryption, transforming it from a basic unencrypted packet viewer into a complete UDP packet decoder with encryption support.Problem
The original
meshview.inoonly handled unencrypted packets (decoded variant). When it encountered encrypted packets, it would simply report "Packet does not contain decoded Data (maybe encrypted or other variant)" and skip them. This made it unusable for most real-world Meshtastic networks that use encryption.Example of previous behavior:
Solution
Implemented full AES-CTR decryption based on the Meshtastic firmware's CryptoEngine, including:
Core Features
Special Key Handling
Supports Meshtastic's special PSK conventions:
"AQ=="(0x01) → Uses default Meshtastic key"Ag=="(0x02) through"Cg=="(0x10) → Uses default key with last byte incrementedSecurity
Debugging
Extensive diagnostic output to help troubleshoot configuration issues:
Configuration Example
Documentation
Technical Details
Encryption Algorithm
Nonce Format (16 bytes)
Testing
Ready for testing with real encrypted Meshtastic packets. Users should:
References
Fixes #[issue_number]
Original prompt
This section details on the original issue you should resolve
<issue_title>.ino file enhance with ability to decode packets and change channel and key </issue_title>
<issue_description>Complete this as fully working example to display data from UDP.
https://github.com/SpudGunMan/node-slurper/blob/main/meshview.ino
Currently decodes outer wrapper but has no decryption of encrypted packets.
Haven't tested but assume licensed mode will decrypt as it's clear text.</issue_description>
Comments on the Issue (you are @copilot in this section)
@SpudGunMan Some details on encryptionhttps://meshtastic.org/docs/overview/encryption/
https://meshtastic.org/docs/about/overview/encryption/limitations/
If any improvements otherwise are seen to handling packets.
https://meshtastic.org/docs/overview/mesh-algo/
@SpudGunMan Encryption in the Meshtastic firmware is handled primarily through the `CryptoEngine` class and its platform-specific implementations (such as `ESP32CryptoEngine`). Here’s where encryption is managed in the codebasehttps://github.com/meshtastic/firmware
1. src/mesh/CryptoEngine.h & src/mesh/CryptoEngine.cpp
CryptoEngineclass provides the main interfaces for encryption and decryption, such as:encryptPacket(...)decrypt(...)encryptAESCtr(...)(AES in counter mode)encryptCurve25519(...)anddecryptCurve25519(...)(for PKI/Curve25519 encryption)2. Platform-specific implementation:
ESP32CryptoEngineinsrc/platform/esp32/ESP32CryptoEngine.cppimplements the crypto functions using mbedtls:3. Usage in Packet Handling (src/mesh/Router.cpp)
perhapsEncode()encrypts the data using the active channel key:4. Curve25519/PKI Encryption
encryptCurve25519anddecryptCurve25519support public key encryption for secure communications using node public keys.Summary:
CryptoEngineclass, with actual cryptographic routines (AES, Curve25519, etc.) implemented in both platform-agnostic (src/mesh/CryptoEngine.cpp) and platform-specific files (likesrc/platform/esp32/ESP32CryptoEngine.cpp).<comment_new>@SpudGunMan
Something like this?
#include <AES.h>
#include <CTR.h>
byte key[16] = { /* your key here / };
byte nonce[16] = { / nonce for this packet / };
byte ciphertext[] = { / ciphertext bytes */ };
size_t len = sizeof(ciphertext);
void setup() {
Serial.begin(115200);
AES128 aes;
CTR ctr;
aes.setKey(key, sizeof(key));
ctr.clear();
ctr.setCipher(&aes);
ctr.setIV(nonce, sizeof(nonce));
ctr.seek(0);
byte plaintext[len];
ctr.decrypt(plaintext, ciphertext, len);
Serial.print("Decrypted: ");
for (size_t i = 0; i < len; i++) Serial.write(plaintext[i]);
Serial.println();
}
void loop() {}</comment_new>
<comment_new>@SpudGunMan
Details on some aes arduino capability
https://www.arduinolibraries.info/libraries/aes-lib
And
https://www.arduinolibraries.info/libraries/aes-utils
As well as some others
https://github.com/DavyLandman/AESLib
https://www.arduinolibraries.info/libraries/aes_cmac
Having clear direction of which module to use which is supported by the Arduino IDE
@SpudGunMan there is this branch with some ideas that look good https://github.com/SpudGunMan/node-slurper/tree/copilot/enhance-decrypt-packets @SpudGunMan One issue the last branch and PR had was no accounting for the channel name @SpudGunM...Fixes #1
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.