-
Notifications
You must be signed in to change notification settings - Fork 219
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
fix(dht)!: add message padding for message decryption, to reduce message length leaks (fixes #4140) #4362
fix(dht)!: add message padding for message decryption, to reduce message length leaks (fixes #4140) #4362
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.
Could have also used a VarInt for the length, but since we're padding anyway, it's fine
…tari into ja-message-length-leaked
Co-authored-by: Stan Bondi <sdbondi@users.noreply.github.com>
Co-authored-by: Stan Bondi <sdbondi@users.noreply.github.com>
…tari into ja-message-length-leaked
Co-authored-by: Stan Bondi <sdbondi@users.noreply.github.com>
…tari into ja-message-length-leaked
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.
Thanks for the corrections - tested and works! 🚀
Happy to hear that ! :) |
* development: fix: wallet database encryption does not bind to field keys tari-project#4137 (tari-project#4340) fix: use SafePassword struct instead of String for passwords (tari-project#4320) feat(dan): template macro handles component state (tari-project#4380) fix(dht)!: add message padding for message decryption, to reduce message length leaks (fixes tari-project#4140) (tari-project#4362) fix(wallet): update seed words for output manager tests (tari-project#4379)
Description --- [PR 4362](#4362) mitigates a metadata leak whereby encrypted messages are the same length as plaintext messages due to the use of a stream cipher. This work adds more complete length checks, such that padding can fail. It also more efficiently handles the edge case where no padding is needed. Motivation and Context --- To avoid directly leaking the length of plaintext messages after stream cipher encryption, [PR 4362](#4362) pads such messages to a multiple of a fixed base length after first prepending the original message length using a fixed encoding. However, the following cases do not appear to be handled by the padding and unpadding code: - The plaintext message length exceeds the fixed encoding length - The ciphertext message is not long enough for extraction of the fixed encoding length - The ciphertext message is not a multiple of the base length Further, in the case where the message length (after length prepending) is exactly a multiple of the base length, an entire base length of padding is unnecessarily applied. This work addresses these issues. The padding process now checks that the plaintext message does not exceed the limit enforced by the length encoding; as a result, it can now return an error that propagates to the encryption function caller. The padding algorithm has been simplified and now handles the multiple-of-the-base-length edge case by correctly applying no padding. The unpadding process now checks that it can safely extract the message length, and checks that the ciphertext message is a multiple of the base length. How Has This Been Tested? --- No test has been added for the case where the message length exceeds the limit allowed by the encoding, as this would imply very high memory usage (or swapping) exceeding 4 GB. Existing tests pass. A new test exercises the other failure modes. * Updates to message padding Adds better length checks. Simplifies the padding algorithm and handles an edge case hitting a base length multiple. * Add test * Propagate padding errors * Rename parameter for clarity * Better overflow and error handling * Formatting Co-authored-by: stringhandler <mikethetike@tari.com>
Description
--- Message length is leaked while performing ChaCha20 encryption for message outbound/inbound. In order to mitigate this vulnerability, we use padding to every message before encryption. In this way, message length is always a multiple of a base length value.
Motivation and Context
--- Tackle issue #4140, see here.
How Has This Been Tested?
--- Add unit tests