Don't use channel index for encrypted packet (#5509)

* Don't use channel index for encrypted packet

* Remove assert in `getKey`, set invalid key length
So encrypting will fail without reboot

* Reset channel to 0 when unable to encrypt
Such that the NAK doesn't use the failing channel hash
This commit is contained in:
GUVWAF
2024-12-05 03:00:19 +01:00
committed by GitHub
parent d3e3985e39
commit c3d60342f4
3 changed files with 4 additions and 3 deletions

View File

@@ -178,12 +178,11 @@ CryptoKey Channels::getKey(ChannelIndex chIndex)
{
meshtastic_Channel &ch = getByIndex(chIndex);
const meshtastic_ChannelSettings &channelSettings = ch.settings;
assert(ch.has_settings);
CryptoKey k;
memset(k.bytes, 0, sizeof(k.bytes)); // In case the user provided a short key, we want to pad the rest with zeros
if (ch.role == meshtastic_Channel_Role_DISABLED) {
if (!ch.has_settings || ch.role == meshtastic_Channel_Role_DISABLED) {
k.length = -1; // invalid
} else {
memcpy(k.bytes, channelSettings.psk.bytes, channelSettings.psk.size);