proto_handshake: clear the cookie before freeing it - #441
Open
woahwhattheheck wants to merge 1 commit into
Open
Conversation
struct handshake_cookie holds x, the diffie-hellman private value, and the two diffie-hellman parameter MAC keys derived from the shared secret. All four sites which free the cookie did so without wiping it: handshakefail(), proto_handshake() at err1, handshakedone(), and proto_handshake_cancel(). handshakedone() runs once per successful connection, at exactly the point where x has served its purpose and should stop existing; forgetting it is what makes the PFS handshake forward-secret. Wipe on all four rather than only where x is known to be populated, so that "the cookie is cleared before it is freed" holds without tracing which paths populate what, as scryptenc.c does with dk at err1. The nonces and yh_* values go over the wire in the clear and are simply covered by wiping the whole structure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #440.
struct handshake_cookieholdsx— the diffie-hellman private value, whosebeing forgotten is what makes the PFS handshake forward-secret — and the two
diffie-hellman parameter MAC keys derived from the shared secret. All four
sites which free the cookie did so without wiping it:
handshakefail()proto_handshake()aterr1handshakedone(), which runs once per successful connection, at exactly thepoint where
xhas served its purposeproto_handshake_cancel()Four
insecure_memzero()calls and the include; no other change.Why all four rather than only where
xis populatederr1is reached before the diffie-hellman value is ever generated, sostrictly it has nothing to protect. I wiped it anyway so that "the cookie is
always cleared before it is freed" is a property that holds without the reader
having to trace which paths populate what — the same reasoning as
scryptenc.c, which wipesdkaterr1on paths where it may never havebeen filled in. Happy to drop that one if you would rather keep it exact.
The nonces and
yh_*values in the cookie go over the wire in the clear, sothey are not the point here; they are simply covered by wiping the whole
structure, which is cheaper and less fragile than picking members.