Skip to content

Conversation

@driverkt
Copy link
Member

@driverkt driverkt commented Jul 28, 2022

As mentioned in the bug report, this issue should not be a framework-level issue, since potentially an individual provider could create a keysize of zero to have a certain significance.

In the changes made here for HmacMD5- and HmacSHA1- KeyGenerators, the check is for keysize <= 0 and this message indicates this is a check characteristic to the SunJCE provider.


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-6227536: KeyGenerator.init() methods do not throw IllegalArgumentException for keysize == 0

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9679/head:pull/9679
$ git checkout pull/9679

Update a local copy of the PR:
$ git checkout pull/9679
$ git pull https://git.openjdk.org/jdk pull/9679/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9679

View PR using the GUI difftool:
$ git pr show -t 9679

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9679.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 28, 2022

👋 Welcome back kdriver! 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.

@driverkt
Copy link
Member Author

/issue add 6227536

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 28, 2022
@openjdk openjdk bot changed the title JDK-6227536: KeyGenerator.init() methods do not throw IllegalArgumentException for keysize == 0 6227536: KeyGenerator.init() methods do not throw IllegalArgumentException for keysize == 0 Jul 28, 2022
@openjdk
Copy link

openjdk bot commented Jul 28, 2022

@driverkt This issue is referenced in the PR title - it will now be updated.

@openjdk
Copy link

openjdk bot commented Jul 28, 2022

@driverkt 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 Jul 28, 2022
@mlbridge
Copy link

mlbridge bot commented Jul 28, 2022

Copy link
Contributor

@bradfordwetmore bradfordwetmore left a comment

Choose a reason for hiding this comment

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

Needs regression tests.

Have you looked at the other Key(Pair)Generators? We've probably added more when this bug was filed. I took a quick look at some, and they were covered. (DES/DESede/Blowfish/AES/etc.)

protected void engineInit(int keysize, SecureRandom random) {

if (keysize <= 0) {
throw new IllegalArgumentException("keysize must not be <= 0 for SunJCE");
Copy link
Contributor

Choose a reason for hiding this comment

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

< 80 chars please

Copy link
Member

Choose a reason for hiding this comment

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

The "for SunJCE" is odd to see in an exception message, I would leave that out.

Copy link
Member

Choose a reason for hiding this comment

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

A stack trace of the exception should be sufficient to tell what provider/code is generating it.

Copy link
Member Author

@driverkt driverkt Jul 28, 2022

Choose a reason for hiding this comment

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

@seanjmullan I thought about this, but I added it due to the bug describing that this would be implementation-specific rather than framework-specific. I can take it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

Needs regression tests.

Have you looked at the other Key(Pair)Generators? We've probably added more when this bug was filed. I took a quick look at some, and they were covered. (DES/DESede/Blowfish/AES/etc.)

@bradfordwetmore The bug mentions only the Hmac*KeyGenerators. I thought about this too, but you mentioned in your initial triage comment on the bug that it should be treated as only relevant to the classes I modified. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

What bug/Sean meant was that we wouldn't put in a check into java.security.* framework, but rather in sun.security.* implementation. And that we don't need to put "SunJCE" in this particular throws message, as we'll know where it is from the stack trace.

My comment agrees that we have a problem in the JCE Hmac code, but there might be other locations where init's like this might allow for invalid 0 values. It's just a general idea to check we didn't make the same issue elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Other (newer) HmacXXX KeyGenerator enforces min key size to be 40. So, perhaps just enforce the same lower limit or just check for <0?

Copy link
Contributor

@valeriepeng valeriepeng Jul 28, 2022

Choose a reason for hiding this comment

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

Also, it'd be nice to include HmacMD5 and HmacSHA1 to the bug synopsis as KeyGenerator covers many algorithms. Would be nice to add SunJCE provider to synopsis, so it's clear that this change/fix is provider-specific.

@driverkt
Copy link
Member Author

Needs regression tests.

Have you looked at the other Key(Pair)Generators? We've probably added more when this bug was filed. I took a quick look at some, and they were covered. (DES/DESede/Blowfish/AES/etc.)

Yes, the others are covered.

@driverkt
Copy link
Member Author

All review comments have been addressed.

Copy link
Contributor

@bradfordwetmore bradfordwetmore left a comment

Choose a reason for hiding this comment

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

We are Slacking on some other test issues. Will approve on next update.

}

public static void main(String[] args) throws Exception {
Test6227536 test = new Test6227536();
Copy link
Contributor

Choose a reason for hiding this comment

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

Calling the constructor just to get the class name seems redundant, as the test name will appear in all of the jtreg test output. I would probably pull it out, just my $0.02.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack. It's also a nice pattern for avoiding issues with main being static.

@openjdk
Copy link

openjdk bot commented Jul 29, 2022

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

6227536: KeyGenerator.init() methods do not throw IllegalArgumentException for keysize == 0

Reviewed-by: wetmore

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 24 new commits pushed to the master branch:

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 (@bradfordwetmore) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 29, 2022
@driverkt
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 29, 2022
@openjdk
Copy link

openjdk bot commented Jul 29, 2022

@driverkt
Your change (at version 921fb97) is now ready to be sponsored by a Committer.

@bradfordwetmore
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 29, 2022

Going to push as commit 0bcf176.
Since your change was applied there have been 24 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 29, 2022
@openjdk openjdk bot closed this Jul 29, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jul 29, 2022
@openjdk
Copy link

openjdk bot commented Jul 29, 2022

@bradfordwetmore @driverkt Pushed as commit 0bcf176.

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

@driverkt driverkt deleted the JDK-6227536 branch July 29, 2022 20:50
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.

5 participants