mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-23 21:45:07 +00:00
oops - fix failed text message rx
This commit is contained in:
parent
fbe56531d2
commit
49b1f4c5af
@ -34,8 +34,8 @@ You probably don't care about this section - skip to the next one.
|
|||||||
* DONE combine acks and responses in a single message if possible (do routing plugin LAST and drop ACK if someone else has already replied)
|
* DONE combine acks and responses in a single message if possible (do routing plugin LAST and drop ACK if someone else has already replied)
|
||||||
* DONE don't send packets we received from the phone BACK TOWARDS THE PHONE (possibly use fromnode 0 for packets the phone sends?)
|
* DONE don't send packets we received from the phone BACK TOWARDS THE PHONE (possibly use fromnode 0 for packets the phone sends?)
|
||||||
* fix 1.1.50 android debug panel display
|
* fix 1.1.50 android debug panel display
|
||||||
* test android channel setting
|
* DONE test android channel setting
|
||||||
* release to users
|
* DONE release to users
|
||||||
* DONE warn in android app about unset regions
|
* DONE warn in android app about unset regions
|
||||||
* DONE use set-channel from android
|
* DONE use set-channel from android
|
||||||
* DONE add gui in android app for setting region
|
* DONE add gui in android app for setting region
|
||||||
|
@ -54,7 +54,7 @@ class ESP32CryptoEngine : public CryptoEngine
|
|||||||
static uint8_t scratch[MAX_BLOCKSIZE];
|
static uint8_t scratch[MAX_BLOCKSIZE];
|
||||||
size_t nc_off = 0;
|
size_t nc_off = 0;
|
||||||
|
|
||||||
// DEBUG_MSG("ESP32 encrypt!\n");
|
// DEBUG_MSG("ESP32 crypt fr=%x, num=%x, numBytes=%d!\n", fromNode, (uint32_t) packetNum, numBytes);
|
||||||
initNonce(fromNode, packetNum);
|
initNonce(fromNode, packetNum);
|
||||||
assert(numBytes <= MAX_BLOCKSIZE);
|
assert(numBytes <= MAX_BLOCKSIZE);
|
||||||
memcpy(scratch, bytes, numBytes);
|
memcpy(scratch, bytes, numBytes);
|
||||||
|
@ -275,10 +275,11 @@ const char *Channels::getPrimaryName()
|
|||||||
bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
|
bool Channels::decryptForHash(ChannelIndex chIndex, ChannelHash channelHash)
|
||||||
{
|
{
|
||||||
if(chIndex > getNumChannels() || getHash(chIndex) != channelHash) {
|
if(chIndex > getNumChannels() || getHash(chIndex) != channelHash) {
|
||||||
DEBUG_MSG("Skipping channel %d due to invalid hash/index\n", chIndex);
|
// DEBUG_MSG("Skipping channel %d (hash %x) due to invalid hash/index, want=%x\n", chIndex, getHash(chIndex), channelHash);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
DEBUG_MSG("Using channel %d (hash 0x%x)\n", chIndex, channelHash);
|
||||||
setCrypto(chIndex);
|
setCrypto(chIndex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
void CryptoEngine::setKey(const CryptoKey &k)
|
void CryptoEngine::setKey(const CryptoKey &k)
|
||||||
{
|
{
|
||||||
DEBUG_MSG("Installing AES%d key!\n", k.length * 8);
|
DEBUG_MSG("Installing AES%d key!\n", k.length * 8);
|
||||||
|
/* for(uint8_t i = 0; i < k.length; i++)
|
||||||
|
DEBUG_MSG("%02x ", k.bytes[i]);
|
||||||
|
DEBUG_MSG("\n"); */
|
||||||
|
|
||||||
key = k;
|
key = k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,13 @@ ErrorCode Router::sendLocal(MeshPacket *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printBytes(const char *label, const uint8_t *p, size_t numbytes) {
|
||||||
|
DEBUG_MSG("%s: ", label);
|
||||||
|
for(size_t i = 0; i < numbytes; i++)
|
||||||
|
DEBUG_MSG("%02x ", p[i]);
|
||||||
|
DEBUG_MSG("\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet on a suitable interface. This routine will
|
* Send a packet on a suitable interface. This routine will
|
||||||
* later free() the packet to pool. This routine is not allowed to stall.
|
* later free() the packet to pool. This routine is not allowed to stall.
|
||||||
@ -173,6 +180,8 @@ ErrorCode Router::send(MeshPacket *p)
|
|||||||
if (p->which_payloadVariant == MeshPacket_decoded_tag) {
|
if (p->which_payloadVariant == MeshPacket_decoded_tag) {
|
||||||
static uint8_t bytes[MAX_RHPACKETLEN]; // we have to use a scratch buffer because a union
|
static uint8_t bytes[MAX_RHPACKETLEN]; // we have to use a scratch buffer because a union
|
||||||
|
|
||||||
|
// printPacket("pre encrypt", p); // portnum valid here
|
||||||
|
|
||||||
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), Data_fields, &p->decoded);
|
size_t numbytes = pb_encode_to_bytes(bytes, sizeof(bytes), Data_fields, &p->decoded);
|
||||||
|
|
||||||
if (numbytes > MAX_RHPACKETLEN) {
|
if (numbytes > MAX_RHPACKETLEN) {
|
||||||
@ -180,6 +189,8 @@ ErrorCode Router::send(MeshPacket *p)
|
|||||||
return ERRNO_TOO_LARGE;
|
return ERRNO_TOO_LARGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printBytes("plaintext", bytes, numbytes);
|
||||||
|
|
||||||
auto hash = channels.setActiveByIndex(p->channel);
|
auto hash = channels.setActiveByIndex(p->channel);
|
||||||
if (hash < 0) {
|
if (hash < 0) {
|
||||||
// No suitable channel could be found for sending
|
// No suitable channel could be found for sending
|
||||||
@ -189,7 +200,7 @@ ErrorCode Router::send(MeshPacket *p)
|
|||||||
|
|
||||||
// Now that we are encrypting the packet channel should be the hash (no longer the index)
|
// Now that we are encrypting the packet channel should be the hash (no longer the index)
|
||||||
p->channel = hash;
|
p->channel = hash;
|
||||||
crypto->encrypt(p->from, p->id, numbytes, bytes);
|
crypto->encrypt(getFrom(p), p->id, numbytes, bytes);
|
||||||
|
|
||||||
// Copy back into the packet and set the variant type
|
// Copy back into the packet and set the variant type
|
||||||
memcpy(p->encrypted.bytes, bytes, numbytes);
|
memcpy(p->encrypted.bytes, bytes, numbytes);
|
||||||
@ -230,20 +241,26 @@ bool Router::perhapsDecode(MeshPacket *p)
|
|||||||
if (channels.decryptForHash(chIndex, p->channel)) {
|
if (channels.decryptForHash(chIndex, p->channel)) {
|
||||||
// Try to decrypt the packet if we can
|
// Try to decrypt the packet if we can
|
||||||
static uint8_t bytes[MAX_RHPACKETLEN];
|
static uint8_t bytes[MAX_RHPACKETLEN];
|
||||||
|
size_t rawSize = p->encrypted.size;
|
||||||
|
assert(rawSize <= sizeof(bytes));
|
||||||
memcpy(bytes, p->encrypted.bytes,
|
memcpy(bytes, p->encrypted.bytes,
|
||||||
p->encrypted
|
rawSize); // we have to copy into a scratch buffer, because these bytes are a union with the decoded protobuf
|
||||||
.size); // we have to copy into a scratch buffer, because these bytes are a union with the decoded protobuf
|
crypto->decrypt(p->from, p->id, rawSize, bytes);
|
||||||
crypto->decrypt(p->from, p->id, p->encrypted.size, bytes);
|
|
||||||
|
//printBytes("plaintext", bytes, p->encrypted.size);
|
||||||
|
|
||||||
// Take those raw bytes and convert them back into a well structured protobuf we can understand
|
// Take those raw bytes and convert them back into a well structured protobuf we can understand
|
||||||
memset(&p->decoded, 0, sizeof(p->decoded));
|
memset(&p->decoded, 0, sizeof(p->decoded));
|
||||||
if (!pb_decode_from_bytes(bytes, p->encrypted.size, Data_fields, &p->decoded)) {
|
if (!pb_decode_from_bytes(bytes, rawSize, Data_fields, &p->decoded)) {
|
||||||
DEBUG_MSG("Invalid protobufs in received mesh packet (bad psk?!\n");
|
DEBUG_MSG("Invalid protobufs in received mesh packet (bad psk?)!\n");
|
||||||
} else {
|
} else if(p->decoded.portnum == PortNum_UNKNOWN_APP) {
|
||||||
|
DEBUG_MSG("Invalid portnum (bad psk?)!\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
// parsing was successful
|
// parsing was successful
|
||||||
|
p->which_payloadVariant = MeshPacket_decoded_tag; // change type to decoded
|
||||||
p->channel = chIndex; // change to store the index instead of the hash
|
p->channel = chIndex; // change to store the index instead of the hash
|
||||||
// printPacket("decoded message", p);
|
printPacket("decoded message", p);
|
||||||
p->which_payloadVariant = MeshPacket_decoded_tag;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,10 +286,9 @@ void Router::handleReceived(MeshPacket *p)
|
|||||||
|
|
||||||
// Take those raw bytes and convert them back into a well structured protobuf we can understand
|
// Take those raw bytes and convert them back into a well structured protobuf we can understand
|
||||||
bool decoded = perhapsDecode(p);
|
bool decoded = perhapsDecode(p);
|
||||||
printPacket("handleReceived", p);
|
|
||||||
DEBUG_MSG("decoded=%d\n", decoded);
|
|
||||||
if (decoded) {
|
if (decoded) {
|
||||||
// parsing was successful, queue for our recipient
|
// parsing was successful, queue for our recipient
|
||||||
|
printPacket("handleReceived", p);
|
||||||
|
|
||||||
// call any promiscious plugins here, make a (non promisiocous) plugin for forwarding messages to phone api
|
// call any promiscious plugins here, make a (non promisiocous) plugin for forwarding messages to phone api
|
||||||
// sniffReceived(p);
|
// sniffReceived(p);
|
||||||
|
Loading…
Reference in New Issue
Block a user