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
8263779: SSLEngine reports NEED_WRAP continuously without producing any further output #3292
Conversation
…ny further output
👋 Welcome back xuelei! A progress list of the required criteria for merging this PR into |
@XueleiFan The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
ping ... |
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.
Would it be possible to add a test for that?
@@ -584,20 +584,34 @@ private void initiateOutboundClose() throws IOException { | |||
closeNotify(useUserCanceled); | |||
} | |||
|
|||
// Note; HandshakeStatus.FINISHED status is retrieved in other places. | |||
// Note: HandshakeStatus.FINISHED status is retrieved in other places. | |||
HandshakeStatus getHandshakeStatus() { | |||
if (!outputRecord.isEmpty()) { | |||
// If no handshaking, special case to wrap alters or |
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.
// If no handshaking, special case to wrap alters or | |
// If not handshaking, special case to wrap alerts or |
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.
Thank you for the correction.
HandshakeStatus getHandshakeStatus() { | ||
if (!outputRecord.isEmpty()) { | ||
// If no handshaking, special case to wrap alters or | ||
// post-handshake messages. | ||
return HandshakeStatus.NEED_WRAP; | ||
if (!isOutboundClosed()) { |
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.
If I'm reading the TransportContect#closeNotify and TransportContext#passiveInboundClose correctly, non-empty output record with both inbound and outbound closed happens when we reply with our close_notify to peer's. Now we will return NOT_HANDSHAKING which appears to be wrong.
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.
Good catch! I will have an update. Thank you for the code review.
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.
SSLEngineOutputRecord.java:
Missing copyright date update.
SSLEngineOutputRecord:77
Unnecessary extra line added. Please remove.
@@ -1686,7 +1691,7 @@ private void handleException(Exception cause) throws IOException { | |||
|
|||
if (cause instanceof SocketException) { | |||
try { | |||
conContext.fatal(alert, cause); | |||
throw conContext.fatal(alert, cause); |
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.
Why did you change to a throw here? Isn't everything from fatal() going to be thrown anyway?
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.
The fatal() will always throw an exception. We could use the method without throw. In some places, IDE or compiler could complain because it cannot detect that the fatal() method will throw and the program ends here. In the past, we use fatal() method without throw, later we change the fatal() return value form "void" to an exception so that throw could be used to mitigate the IDE or compiler complaints.
It is not really necessary to make this code change here. I just want to make the coding style consistent for the fatal() calling.
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.
Interesting, ok. I don't recall seeing such situations with the IDE I often use. (Netbeans)
@@ -584,10 +584,10 @@ private void initiateOutboundClose() throws IOException { | |||
closeNotify(useUserCanceled); | |||
} | |||
|
|||
// Note; HandshakeStatus.FINISHED status is retrieved in other places. | |||
// Note: HandshakeStatus.FINISHED status is retrieved in other places. |
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.
I now see that v1 of this change had quite a few changes here, and what's left is now just compacting a line and making some old comment corrections.
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.
Yes.
@XueleiFan This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 105 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Yes, I missed the copyright date.
Oops, I will correct it. |
/integrate |
@XueleiFan Since your change was applied there have been 107 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 1a37bce. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
As described in the bug, by connecting the SSLEngine with a misbehaving peer SSL implementation, it can get into a state where it calling
wrap
reports getStatus == OK, getHandshakeStatus === NEED_WRAP but still doesn't produce any further output. It happens when the output bound is not empty.It is caused by a mismatching condition in the SSLEngineOutputRecord. The use hasAlert() method should be replaced with isEmpty(). Otherwise, there is conflicts of the closing status while checking with OutputRecord.isEmpty() in TransportContext.getHandshakeStatus() implementation. It is safe to remove hasAlert() method, as we don't allow creation of new output record if the closure is in progress, thus isEmpty() could be used instead.
The patch passed the test provided by the bug submitter.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3292/head:pull/3292
$ git checkout pull/3292
Update a local copy of the PR:
$ git checkout pull/3292
$ git pull https://git.openjdk.java.net/jdk pull/3292/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3292
View PR using the GUI difftool:
$ git pr show -t 3292
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3292.diff