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

8285404: RSA signature verification should reject non-DER OCTET STRING #8365

Closed
wants to merge 2 commits into from

Conversation

wangweij
Copy link
Contributor

@wangweij wangweij commented Apr 22, 2022

Compare encoded instead of decoded digest in RSA signature verification.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8285404: RSA signature verification should reject non-DER OCTET STRING

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8365/head:pull/8365
$ git checkout pull/8365

Update a local copy of the PR:
$ git checkout pull/8365
$ git pull https://git.openjdk.java.net/jdk pull/8365/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 8365

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8365.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 22, 2022

👋 Welcome back weijun! 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 changed the title 8285404: RSA signature verification should follow RFC 8017 8285404: RSA signature verification should follow RFC 8017 8.2.2 Step 4 Apr 22, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 22, 2022
@openjdk
Copy link

openjdk bot commented Apr 22, 2022

@wangweij 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 Apr 22, 2022
@mlbridge
Copy link

mlbridge bot commented Apr 22, 2022

Webrevs

@mlbridge
Copy link

mlbridge bot commented Apr 22, 2022

Mailing list message from Michael StJohns on security-dev:

On 4/22/2022 1:21 PM, Weijun Wang wrote:

This is a weird one.? AFAICT the way it was being done is valid and
allowed by RFC8017 - I would have closed the bug report as notabug.?
Here's the relevant text from? RFC8017:

4. Compare the encoded message EM and the second encoded message
EM'. If they are the same, output "valid signature";
otherwise, output "invalid signature".

   Note\:\*\_Another way to implement the signature verification operation is to 

apply a "decoding" operation (not specified in this document) to the
encoded message to recover the underlying hash value, and then compare
it to a newly computed hash value._*
This has the advantage that it requires less intermediate storage
(two hash values rather than two encoded messages), but the
disadvantage that it requires additional code.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/security-dev/attachments/20220422/eaadcb8c/attachment-0001.htm>

@wangweij
Copy link
Contributor Author

This is a weird one.? AFAICT the way it was being done is valid and
allowed by RFC8017 - I would have closed the bug report as notabug

Yes, I saw the "Note". It's definitely OK to decode but one has to make sure the input is DER encoded. Unfortunately, the old RsaUtil::decodeSignature method has not guaranteed it.

@valeriepeng
Copy link

valeriepeng commented Apr 22, 2022

Regardless whether we ended up with decode/encode, we should make sure RSASSA-PSS signature impl is also covered and consistent.

Comment on lines 219 to 220
byte[] decrypted = RSACore.rsa(sigBytes, publicKey);
byte[] unpadded = padding.unpad(decrypted);
Copy link
Member

Choose a reason for hiding this comment

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

It looks like safer to me that decodeSignature() method is removed and the same method get used for the verification.

Maybe, these two lines could be moved ahead (at line 215) so that the processing order is consistent with the RFC 8017 described order, for readability.

@wangweij
Copy link
Contributor Author

Regardless whether we ended up with decode/encode, we should make sure RSASSA-PSS signature impl is also covered and consistent.

RSASSA-PSS is not affected. Neither with the PKCS11 RSA signature.

@mlbridge
Copy link

mlbridge bot commented Apr 26, 2022

Mailing list message from xueleifan(XueleiFan) on security-dev:

With this update, is the purpose of this PR changed? The bug subject and description may need an update.

Xuelei

@wangweij
Copy link
Contributor Author

Mailing list message from xueleifan(XueleiFan) on security-dev:

With this update, is the purpose of this PR changed? The bug subject and description may need an update.

Xuelei

Good catch. I'll reword.

@wangweij wangweij changed the title 8285404: RSA signature verification should follow RFC 8017 8.2.2 Step 4 8285404: RSA signature verification should reject non-DER OCTET STRING Apr 26, 2022
@valeriepeng
Copy link

Regardless whether we ended up with decode/encode, we should make sure RSASSA-PSS signature impl is also covered and consistent.

Never mind, PSS has its own way of verification and its impl is based on RFC 8017.

@openjdk
Copy link

openjdk bot commented Apr 26, 2022

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

8285404: RSA signature verification should reject non-DER OCTET STRING

Reviewed-by: valeriep

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

  • 03bcf7b: 8283620: System.out does not use the encoding/charset specified in the Javadoc
  • 20a132d: 8284994: -Xdoclint:all returns warning for records, even when documented properly
  • a3b7881: 8284930: Re-examine FilterInputStream mark/reset
  • 97a0a29: 8283643: [AIX, testbug] MachCodeFramesInErrorFile test fails to find 'Native frames' text
  • 67755ed: 8284890: Support for Do not fragment IP socket options
  • a7b5157: 8282541: AArch64: Auto-vectorize Math.round API
  • 8de3c65: 8284951: Compile::flatten_alias_type asserts with "indeterminate pointers come only from unsafe ops"
  • 552e1b0: 8284779: Test java/util/logging/Logger/logrb/TestLogrbResourceBundle.java fails intermittently with vthreads wrapper
  • e333cd3: 8285611: Retrofit (Doc)Pretty with java.io.UncheckedIOException
  • 9478696: 8283441: C2: segmentation fault in ciMethodBlocks::make_block_at(int)
  • ... and 58 more: https://git.openjdk.java.net/jdk/compare/5291ec8d56b0e89aa96c3d53d9dcf093480cf48f...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 Apr 26, 2022
@wangweij
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Apr 26, 2022

Going to push as commit 14e7d91.
Since your change was applied there have been 73 commits pushed to the master branch:

  • 110edd9: 8284965: closed test sun/java2d/OpenGL/XORPaint.java is unstable
  • dbcf389: 8198666: Many java/awt/Modal/OnTop/ test fails on mac
  • 102a305: 8202790: DnD test DisposeFrameOnDragTest.java does not clean up
  • e3d714d: 8285677: ProblemList two tests from JDK-8285671 on macosx-x64
  • 975a060: 8284642: Unexpected behavior of -XX:MaxDirectMemorySize=0
  • 03bcf7b: 8283620: System.out does not use the encoding/charset specified in the Javadoc
  • 20a132d: 8284994: -Xdoclint:all returns warning for records, even when documented properly
  • a3b7881: 8284930: Re-examine FilterInputStream mark/reset
  • 97a0a29: 8283643: [AIX, testbug] MachCodeFramesInErrorFile test fails to find 'Native frames' text
  • 67755ed: 8284890: Support for Do not fragment IP socket options
  • ... and 63 more: https://git.openjdk.java.net/jdk/compare/5291ec8d56b0e89aa96c3d53d9dcf093480cf48f...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Apr 26, 2022

@wangweij Pushed as commit 14e7d91.

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

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
3 participants