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

8320449: ECDHKeyAgreement should validate parameters before using them #17373

Closed
wants to merge 4 commits into from

Conversation

johnshajiang
Copy link
Member

@johnshajiang johnshajiang commented Jan 11, 2024

ECDHKeyAgreement should validate the parameters before assigning them to the fields.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8320449: ECDHKeyAgreement should validate parameters before using them (Bug - P3)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 11, 2024

👋 Welcome back jjiang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 11, 2024
@openjdk
Copy link

openjdk bot commented Jan 11, 2024

@johnshajiang The following label will be automatically applied to this pull request:

  • security

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.

@openjdk openjdk bot added the security security-dev@openjdk.org label Jan 11, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 11, 2024

Webrevs

Comment on lines +81 to +83
privateKey = null;
privateKeyOps = null;
publicKey = null;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Contributor

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?

Copy link
Member Author

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));
}
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Typo: s/share/shared/

@openjdk
Copy link

openjdk bot commented Jan 16, 2024

@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:

8320449: ECDHKeyAgreement should validate parameters before using them

Reviewed-by: mullan

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 master branch:

  • b533272: 8299627: Fix/improve handling of "missing" element-list file
  • 1007618: 8323731: Unproblemlist gc/stress/TestStressG1Humongous.java
  • 790871e: 8323800: Serial: Fix include guard macro in generation.hpp
  • 0216f5d: 8323730: Tweak TestZAllocationStallEvent.java to allocate smaller objects
  • 21f6473: 8322675: JFR: Fail-fast mode when constants cannot be resolved
  • e2d6023: 8323631: JfrTypeSet::write_klass can enqueue a CLD klass that is unloading
  • 2fd775f: 8323651: compiler/c2/irTests/TestPrunedExHandler.java fails with -XX:+DeoptimizeALot
  • ee4d9aa: 8323659: LinkedTransferQueue add and put methods call overridable offer
  • 5045839: 8323635: Test gc/g1/TestHumongousAllocConcurrentStart.java fails with -XX:TieredStopAtLevel=3
  • 44a9392: 8323780: Serial: Remove unused _full_collections_completed
  • ... and 70 more: https://git.openjdk.org/jdk/compare/b530c0281b5082994065b10addeb8366ffa58e2f...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 16, 2024
@johnshajiang
Copy link
Member Author

@seanjmullan
Thanks for your approval!

/integrate

@openjdk
Copy link

openjdk bot commented Jan 16, 2024

Going to push as commit 43d2d68.
Since your change was applied there have been 82 commits pushed to the master branch:

  • b058063: 8323820: [MacOS] build failure: non-void function does not return a value
  • 19c9388: 8323616: [JVMCI] TestInvalidJVMCIOption.java fails intermittently with NPE
  • b533272: 8299627: Fix/improve handling of "missing" element-list file
  • 1007618: 8323731: Unproblemlist gc/stress/TestStressG1Humongous.java
  • 790871e: 8323800: Serial: Fix include guard macro in generation.hpp
  • 0216f5d: 8323730: Tweak TestZAllocationStallEvent.java to allocate smaller objects
  • 21f6473: 8322675: JFR: Fail-fast mode when constants cannot be resolved
  • e2d6023: 8323631: JfrTypeSet::write_klass can enqueue a CLD klass that is unloading
  • 2fd775f: 8323651: compiler/c2/irTests/TestPrunedExHandler.java fails with -XX:+DeoptimizeALot
  • ee4d9aa: 8323659: LinkedTransferQueue add and put methods call overridable offer
  • ... and 72 more: https://git.openjdk.org/jdk/compare/b530c0281b5082994065b10addeb8366ffa58e2f...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 16, 2024
@openjdk openjdk bot closed this Jan 16, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 16, 2024
@openjdk
Copy link

openjdk bot commented Jan 16, 2024

@johnshajiang Pushed as commit 43d2d68.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@johnshajiang johnshajiang deleted the 8320449 branch January 16, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated security security-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants