Skip to content
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 #21760 - Close Tls connection if Inbound closed before receiving peer's close_notify (v.2) #21786

Merged
merged 1 commit into from
Nov 4, 2016

Conversation

sashagavrilov
Copy link

@sashagavrilov sashagavrilov commented Nov 2, 2016

Fixes #21760
Also fixes akka/akka-http#380 and probably akka/akka-http#87

This is a second variant of testing the fix (an alternative is #21785)
Initial discussion is in #21761

When application closes inboud using engine.closeInbound the engine can generate an alert message and put it into writer.outboundList. As a result the engine can have a new data packet in outbound and its isOutboundDone will be false. We have to ensure that it will be flushed to the network, that's why we have to update lastHandshakeStatus via the actual status of the engine. Otherwise the actor will transition to the flushingOutbound state but will never flush outbound, since engineNeedsWrap precondition will be false.

Generally speaking whenever we signal something to the SSLEngine, weshould also read getHandshakeStatus afterwards to understand what we need to do next. This was done everywhere but for this engine.closeInbound.

…ing peer's close_notify

When application closes inboud using engine.closeInbound the engine can generate an alert message and put it into writer.outboundList. As a result the engine can have a new data packet in outbound and its isOutboundDone will be false. We have to ensure that it will be flushed to the network, that's why we have to update lastHandshakeStatus via the actual status of the engine. Otherwise the actor will transition to the flushingOutbound state but will never flush outbound, since engineNeedsWrap precondition will be false.

Generally speaking whenever we signal something to the SSLEngine, weshould also read getHandshakeStatus afterwards to understand what we need to do next. This was done everywhere but for this engine.closeInbound.
@akka-ci
Copy link

akka-ci commented Nov 2, 2016

Can one of the repo owners verify this patch?

@ktoso
Copy link
Member

ktoso commented Nov 2, 2016

OK TO TEST

@akka-ci akka-ci added the validating PR is currently being validated by Jenkins label Nov 2, 2016
@ktoso
Copy link
Member

ktoso commented Nov 2, 2016

Thanks for the excellent research + writeup and fix.
Seems to make sense to me. I somehow prefer this alternative to the other one.
I know @jrudolph wanted to get deeper into this PR. I think your explanations seem good so if jenkins is happy I'd say it's LGTM

@akka-ci akka-ci added needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR is currently being validated by Jenkins labels Nov 2, 2016
@akka-ci
Copy link

akka-ci commented Nov 2, 2016

Test FAILed.

@sashagavrilov
Copy link
Author

Does not look like the failed test is related to this commit.

@ktoso
Copy link
Member

ktoso commented Nov 2, 2016

PLS BUILD

@akka-ci akka-ci added validating PR is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR is currently being validated by Jenkins labels Nov 2, 2016
@akka-ci
Copy link

akka-ci commented Nov 2, 2016

Test PASSed.

Copy link
Member

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

LGTM, I vote for this one.

Copy link
Member

@drewhk drewhk left a comment

Choose a reason for hiding this comment

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

LGTM

})
.runWith(Sink.last)

Await.result(f, 8.second).utf8String should be(scenario.output.utf8String)
Copy link
Member

Choose a reason for hiding this comment

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

Nice test!

@@ -292,6 +292,7 @@ class TLSActor(
if (tracing) log.debug("closing inbound")
try engine.closeInbound()
catch { case ex: SSLException ⇒ outputBunch.enqueue(UserOut, SessionTruncated) }
lastHandshakeStatus = engine.getHandshakeStatus
Copy link
Member

Choose a reason for hiding this comment

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

ah, so this needs to be updated here. Thanks!

@ktoso
Copy link
Member

ktoso commented Nov 4, 2016

Enough LGTMs I believe :)
Thanks again for digging into this!

@ktoso ktoso merged commit 20942b3 into akka:master Nov 4, 2016
@sashagavrilov sashagavrilov deleted the fix/21760-2 branch November 4, 2016 14:52
412b pushed a commit to 412b/akka that referenced this pull request Nov 17, 2016
…ing peer's close_notify (akka#21786)

When application closes inboud using engine.closeInbound the engine can generate an alert message and put it into writer.outboundList. As a result the engine can have a new data packet in outbound and its isOutboundDone will be false. We have to ensure that it will be flushed to the network, that's why we have to update lastHandshakeStatus via the actual status of the engine. Otherwise the actor will transition to the flushingOutbound state but will never flush outbound, since engineNeedsWrap precondition will be false.

Generally speaking whenever we signal something to the SSLEngine, weshould also read getHandshakeStatus afterwards to understand what we need to do next. This was done everywhere but for this engine.closeInbound.
jrudolph added a commit to jrudolph/akka-http that referenced this pull request Sep 11, 2017
…cenario

That is we are simulating a TLS truncation attack here. Before
akka/akka#21786 the TLS stage just got stuck
(I tested again an old Akka version).

Now, all streams are properly closed and also the response entity
stream is completed. A stricter version would actually fail the response
entity stream when TLS truncation is detected. If that is worthwhile is
actually questionable. See akka#235
for more information.
jrudolph added a commit to jrudolph/akka-http that referenced this pull request Sep 11, 2017
…cenario

That is we are simulating a TLS truncation attack here. Before
akka/akka#21786 the TLS stage just got stuck
(I tested again an old Akka version).

Now, all streams are properly closed and also the response entity
stream is completed. A stricter version would actually fail the response
entity stream when TLS truncation is detected. If that is worthwhile is
actually questionable. See akka#235
for more information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
5 participants