Skip to content

fix: encrypt/decrypt node #133

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

Merged
merged 5 commits into from
Jul 9, 2019
Merged

Conversation

seebees
Copy link
Contributor

@seebees seebees commented Jul 8, 2019

Small frames exacerbate a race between VerifyStream and DecipherStream.
Once an AuthTag event is sent to DecipherStream
the current frame is decrypted and verified before being flushed.
More frame data will not be processed by DecipherStream
because DecipherStream will not execute the _transform callback
until the frame is flushed.
However nothing stops VerifyStream from continuing to process data.
VerifyStream will push the next frame's data,
which will be cached by DecipherStream.
But once VerifyStream reaches the end of the frame it will emit AuthTag.
This means the DecipherStream will receive the AuthTag before the frame data
and it will correctly fail on precondition checks.

To resolve this a simple callback is passed from VerifyStream to DecipherStream
in the AuthTag event.

Tests for both encrypt and decrypt are included here,
because that is how this issue was found.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Small frames exacerbate a race between VerifyStream and DecipherStream.
Once an `AuthTag` event is sent to DecipherStream
the current frame is decrypted and verified before being flushed.
More frame data will not be processed by DecipherStream
because DecipherStream will not execute the _transform callback
until the frame is flushed.
However nothing stops VerifyStream from continuing to process data.
VerifyStream will push the next frame's data,
which will be cached by DecipherStream.
But once VerifyStream reaches the end of the frame it will emit `AuthTag`.
This means the DecipherStream will receive the AuthTag before the frame data
and it will correctly fail on precondition checks.

To resolve this a simple callback is passed from VerifyStream to DecipherStream
in the `AuthTag` event.

Tests for both encrypt and decrypt are included here,
because that is how this issue was found.
@seebees seebees requested a review from a team July 8, 2019 19:05
lizroth
lizroth previously approved these changes Jul 9, 2019
Copy link

@lizroth lizroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks reasonable, though there's some messaging I'd try to make more helpful.

@seebees seebees merged commit 896883a into aws:master Jul 9, 2019
@seebees seebees deleted the encrypt-decrypt-node-testing branch July 9, 2019 20:49
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.

2 participants