-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8320449: ECDHKeyAgreement should validate parameters before using them #17373
Conversation
👋 Welcome back jjiang! A progress list of the required criteria for merging this PR into |
@johnshajiang 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
|
privateKey = null; | ||
privateKeyOps = null; | ||
publicKey = null; |
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 fields should be initialized to null, so I don't think you need these lines.
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.
KeyAgreement ka = KeyAgreement.getInstance("ECDH");
ka.init(key1);
ka.init(key2);
If no those lines, when the second init
throws exception, and the keys set by the first init
are not cleared.
Please consider the test case testInitWithInvalidKey
in ECDHKeyAgreementParamValidation
.
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, you are right.
* @test | ||
* @bug 8320449 | ||
* @summary ECDHKeyAgreement should validate parameters before assigning them to fields. | ||
* @run junit ECDHKeyAgreementParamValidation |
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.
Most security regression tests don't use junit. I think it would be better to not rely on it. There is a similar asserts library for tests that you can use in test/lib/jdk/test/lib/Asserts.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 originally didn't depend on JUnit. But this tool can easily execute multiple test cases independently.
A single failed case doesn't make the whole test fail fast, and all cases always be executed.
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.
Fair point, although there are ways to workaround that w/o junit.
AFAICT, this will be the first security test to depend on junit. @rhalade are you ok with this?
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.
Just updated this test and not used JUnit.
|
||
KeyAgreement ka = KeyAgreement.getInstance("ECDH"); | ||
ka.init(kpP256.getPrivate()); | ||
try { |
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.
Should this be assertThrows like the other ones?
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 assumed this point must fail and my fix for this bug didn't concern it.
Maybe some test on KeyAgreement already does that, so I didn't add a check point on it.
Anyway, just added this assertion.
Asserts.assertThrows( | ||
IllegalStateException.class, | ||
()->ka.doPhase(kp.getPublic(), true)); | ||
} |
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.
How about also calling generateSecret
and checking for IllegalStateException
?
InvalidKeyException.class, | ||
() -> ka.doPhase(kpP384.getPublic(), true)); | ||
|
||
// Should not generate share key with SECP256R1 private key and SECP384R1 public key |
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.
Typo: s/share/shared/
@johnshajiang 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 80 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 |
@seanjmullan /integrate |
Going to push as commit 43d2d68.
Your commit was automatically rebased without conflicts. |
@johnshajiang Pushed as commit 43d2d68. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
ECDHKeyAgreement should validate the parameters before assigning them to the fields.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17373/head:pull/17373
$ git checkout pull/17373
Update a local copy of the PR:
$ git checkout pull/17373
$ git pull https://git.openjdk.org/jdk.git pull/17373/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17373
View PR using the GUI difftool:
$ git pr show -t 17373
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17373.diff
Webrev
Link to Webrev Comment