Skip to content

Securely generate network key when resetting adapters - #5833

Merged
manup merged 3 commits into
dresden-elektronik:masterfrom
puddly:puddly/unsafe-random-fix
Feb 27, 2022
Merged

manup merged 3 commits into
dresden-elektronik:masterfrom
puddly:puddly/unsafe-random-fix

Conversation

@puddly

@puddly puddly commented Feb 26, 2022

Copy link
Copy Markdown
Contributor

qrand() is not suitable for generating the network key when factory resetting an adapter.

The first call to qrand() sets the public PAN ID. This leaks enough RNG state to make bruteforcing the full state feasible from a single captured packet and thus allows the network key to be easily computed.

Unoptimized PoC: https://github.com/puddly/deconz-network-key-leak-poc


I can't figure out how to test this branch with the deCONZ Docker image so while the code compiles, I'm not certain of its correctness. Feel free to close this PR and re-implement it yourself, the changes are pretty minor.

`qrand` is a wrapper around `rand`, which is entirely unsuitable for
generating cryptographic keys.
No more than 16 sequential bytes are ever generated by `fallbackRandom`
so this is probably an inconsequential change but the Mersenne Twister
is not cryptographically secure, while `std::random_device` is pulling
from a high-quality source on all platforms.  This is "good enough" for
a fallback.
@manup

manup commented Feb 27, 2022

Copy link
Copy Markdown
Member

Thanks, very nice good spot on the Mersenne Twister use. The fallback is likely not used much as in most installations OpenSSL should be available.

@manup manup added this to the v2.15.0-beta milestone Feb 27, 2022
@manup
manup merged commit 564744c into dresden-elektronik:master Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants