-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8275811 Incorrect instance to dispose #6084
Conversation
👋 Welcome back djelinski! A progress list of the required criteria for merging this PR into |
@djelinski 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
|
Did you want to cover the update for line 222 at OutputRecord.java as well? |
Ah, missed that one. Fixed. |
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.
Looks good to me. Thank you!
|
@djelinski 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 172 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@XueleiFan) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Thanks @XueleiFan , but I guess this needs a bit more love. Just finished running jdk_security tests, and a few tests failed, apparently related: I'll see if I can figure this out. |
The problem is with SSLEngine; we create the ChangeCipherSpec message in a delegated task, then encrypt it later using memoized cipher:
(line numbers may be off a bit) If the memoized cipher is disposed, the operation produces incorrect output. This happens only when ChangeCipherSpec or KeyUpdate is encrypted and we're using SSLEngine. Looks like we can move writeCipher disposal to the relevant OutputRecord subclasses. Will look into it. |
After reviewing the scope of changes to fix writeCipher disposal I decided to remove it entirely. It would probably be a nice follow-up enhancement, but I'm not confident I'd implement it correctly on the first try, so I'd rather not introduce it in a bugfix PR. @XueleiFan is that acceptable to you? On a side note, I had another look at DTLSOutputRecord. It looks like we keep a reference to |
I'm not sure of the removal. Please hold on the integration, and I will have a further look if I have cycles. |
Hi @XueleiFan, |
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 update. It looks good to me, except a minor comment.
// SSLEngine and SSLSocket | ||
abstract void disposeWriteCipher(); | ||
|
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.
Alternatively, this method could have a default implementation that throws UnsupportedOperationException. Then, there is no need to update DTLSOutputRecord.java.
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 like that idea. Updated the PR.
jdk_security still passes, automated checks green. @XueleiFan could you sponsor? /integrate |
@djelinski |
Please hold off on the integration, the regression testing failed. |
@@ -422,6 +432,15 @@ void queueUpAlert(byte level, byte description) { | |||
handshakeMemos.add(memo); | |||
} | |||
|
|||
void queueUpCipherDispose() { | |||
RecordMemo lastMemo = handshakeMemos.getLast(); |
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.
Sorry, I missed that the getLast could throw exception if it is empty. I may check it before the call to getLast.
+ if (handshakeMemos.isEmpty()) {
+ return;
+ }
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.
my mistake. Replaced with peekLast
, should be better now.
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.
Well, looks like this uncovered another, unrelated bug. handshakeMemos
is only empty here when we handle TLS1.3 server hello and session ID is empty, see stack trace:
Caused by: java.util.NoSuchElementException
at java.base/java.util.LinkedList.getLast(LinkedList.java:261)
at java.base/sun.security.ssl.SSLEngineOutputRecord$HandshakeFragment.queueUpCipherDispose(SSLEngineOutputRecord.java:436)
at java.base/sun.security.ssl.SSLEngineOutputRecord.disposeWriteCipher(SSLEngineOutputRecord.java:159)
at java.base/sun.security.ssl.OutputRecord.changeWriteCiphers(OutputRecord.java:198)
at java.base/sun.security.ssl.ServerHello$T13ServerHelloConsumer.consume(ServerHello.java:1372)
This is only supposed to be empty when jdk.tls.client.useCompatibilityMode is false, which it never is (also the comment above that line is copy/pasted, should be fixed). So I did some more digging and found that we do not set sessionId in clientHello when resuming TLS1.3 session:
- sessionId is set to empty here
- not updated here because it's TLS 1.3
- not updated here because session is not null
Apparently we have no tests for TLS1.3 session resumption in jdk_security and no tests for useCompatibilityMode=false (otherwise I would have noticed this sooner).
Let me know if I should fix these issues here or in a separate PR.
could you point me to the failing test? I'm running the jdk_security suite; only sun/security/mscapi/ShortRSAKeyWithinTLS is failing, and it's failing because of environmental reasons (Windows is asking for some PIN) EDIT |
I normally run tier1 and tier2 test. |
Mailing list message from Xuelei Fan on security-dev: I would suggest to fix in a separate bug. Thanks, |
/integrate tier1, tier2 and jdk_core are all clean now. I think we're good to go. A few closing thoughts: |
@djelinski |
Thanks, I will sponsor the integration soon.
That's a pretty old and interesting topic. I don't think doFinal could really have PKCS11 release its resources. As there is not close APIs for key instance, there is not much we can do right now. Maybe, we could consider to support closable keys in the future.
It makes sense. But it may make it complicated to check different ciphers. In the long run, the doFinal() should be replaced with something like close(). |
/sponsor |
Going to push as commit cddc6ce.
Your commit was automatically rebased without conflicts. |
@XueleiFan @djelinski Pushed as commit cddc6ce. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
The current code that changes cipher suites disposes the new suite instead of the old one, which usually silently fails. This patch fixes the code to dispose the old instance instead.
DTLS appears to be unaffected: DTLSOutputRecord keeps 2 ciphers and correctly disposes the old one, and DTLSInputRecord doesn't dispose anything
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6084/head:pull/6084
$ git checkout pull/6084
Update a local copy of the PR:
$ git checkout pull/6084
$ git pull https://git.openjdk.java.net/jdk pull/6084/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6084
View PR using the GUI difftool:
$ git pr show -t 6084
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6084.diff