-
-
Notifications
You must be signed in to change notification settings - Fork 2k
security: add optional MAC for AES-CTR channel encryption #9602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
security: add optional MAC for AES-CTR channel encryption #9602
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
c684e5d to
d4f39da
Compare
|
I left Claude to vibe on this one lol, not sure how practical this one is. It's probably the most realistic attack vector but also needs the most attention. Bit flipping is easy with the PSK and you know the header structure of the protobufs, it shouldn't be too hard to modify message content. Of course this presumes your attacker is already in your channel. |
Channel PSK encryption uses AES-CTR which provides confidentiality but no integrity/authenticity. An attacker who knows the channel key can flip ciphertext bits to produce predictable plaintext changes (bit-flip attack). PKI encryption already uses AES-CCM (authenticated), but channel mode does not. This adds an opt-in AES-CBC-MAC that appends a 4-byte authentication tag to channel-encrypted packets. Disabled by default behind MESHTASTIC_CHANNEL_HMAC define in CryptoEngine.h. When enabled: - Send: encrypts with AES-CTR then appends 4-byte CBC-MAC - Receive: verifies MAC if present, falls back to legacy if not - Max payload reduced by 4 bytes (251 -> 247 after header) Backward compatibility: - Receive path accepts both authenticated and legacy packets - Send path is NOT backward-compatible (old firmware will fail to decode the extra MAC bytes) - Full mesh must be upgraded before enabling Also adds constant_time_compare to meshUtils (needed for MAC verify).
d4f39da to
9acc584
Compare
|
Hey thanks for submitting this I want a feature similar to this,
Cryptography is tricky and you need to show that you understand the decisions you have made. I didn't actually looked at the code since it looks to me like fixing all of theses equals to redoing this PR from scratch. I would like to have a chat on discord or in a new issue about how an implementation should look like (tldr; |
|
@Jorropo agreed. I didn't even notice Claude opened this PR to be honest. I was having it look at the code just for fun. Looking at what it came up with, I think it's valid concern but will definitely need more context and describe practical attacks to figure out if the fix is useful. If there's no bad actors this shouldn't be needed ever - let's hope people aren't relying on meshtastic for this kind of integrity protection currently 😄 |
see #9606 |
Summary
#define MESHTASTIC_CHANNEL_HMACinCryptoEngine.hThe vulnerability
Channel PSK encryption uses AES-CTR without any authentication tag. An attacker who knows the channel key (the default PSK is publicly known) can:
PKI encryption already uses AES-CCM (authenticated), but channel mode does not.
The fix
When
MESHTASTIC_CHANNEL_HMACis enabled:Backward compatibility
Why opt-in?
This is a wire-format change that breaks compatibility with older firmware on the send path. It should be:
Also includes
constant_time_comparein meshUtils (needed for MAC verification).Test plan
tbeambuild succeeds with flag disabled (default — no behavioral change)tbeambuild succeeds with flag enabled🤖 Generated with Claude Code