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

8297065: DerOutputStream operations should not throw IOExceptions #11302

Closed
wants to merge 4 commits into from

Conversation

wangweij
Copy link
Contributor

@wangweij wangweij commented Nov 22, 2022

This is mostly cleanup. Everything around DerOutputStream no longer throws an IOException. This includes:

  • Remove unnecessary throws IOException in code and spec
  • Remove catch (IOException ioe) blocks. If new exception is thrown, remove further throws in code and spec
  • More classes implementing DerEncoder if they have a encode(DerOutputStream) method
  • Modify write(bytes) to writeBytes(bytes) to avoid IOE
  • Some unused methods removed
  • DerOutputStream is final

The only actual changes (still trivial) are:

  • Since PKCS7::encodeSignedData(OutputStream out) is removed, its usages in PKCS7::constructToken and TsaSigner::createResponse (in test) are modified to use another method with a DerOutputStream argument.
  • In PKCS8Key, since getEncodedInternal never returns non-null, remove null check on result
  • Since DerOutputStream is final, no need to clone bytes in encode of X509CertImpl and X509CRLImpl.

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-8297065: DerOutputStream operations should not throw IOExceptions

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11302

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 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 added the rfr Pull request is ready for review label Nov 22, 2022
@openjdk
Copy link

openjdk bot commented Nov 22, 2022

@wangweij The following labels will be automatically applied to this pull request:

  • compiler
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added security security-dev@openjdk.org compiler compiler-dev@openjdk.org labels Nov 22, 2022
@wangweij
Copy link
Contributor Author

/label remove compiler

@openjdk openjdk bot removed the compiler compiler-dev@openjdk.org label Nov 22, 2022
@openjdk
Copy link

openjdk bot commented Nov 22, 2022

@wangweij
The compiler label was successfully removed.

@mlbridge
Copy link

mlbridge bot commented Nov 22, 2022

Webrevs

else
tmp = seq;
DerOutputStream tmp = new DerOutputStream();
if (isExplicit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use curley braces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do. This is new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just went through 17 such cases. Each of them is actually old code that was inside a try-catch block. I feel hesitated to update them. Keep them untouched is actually easier for code review.

*/
public IssuingDistributionPointExtension(
DistributionPointName distributionPoint, ReasonFlags revocationReasons,
boolean hasOnlyUserCerts, boolean hasOnlyCACerts,
boolean hasOnlyAttributeCerts, boolean isIndirectCRL)
throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need throws IllegalArgumentException?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not - it's a runtime exception and those are special.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the reason. BTW, I did update the javadoc to list the new reason.

@@ -298,48 +298,43 @@ private X500Principal getCertIssuer(X509CRLEntryImpl entry,
* @exception CRLException on encoding errors.
*/
public byte[] encodeInfo() throws CRLException {

Choose a reason for hiding this comment

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

"throws CRLException" can be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inside the method there is

if ((version == 0) && (issuer.toString() == null))
                throw new CRLException("Null Issuer DN not allowed in v1 CRL");

Choose a reason for hiding this comment

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

I see.

@@ -605,36 +600,31 @@ public static X509CRLImpl newSigned(TBSCertList info, PrivateKey key, String alg
public static X509CRLImpl newSigned(TBSCertList info, PrivateKey key, String algorithm, String provider)
throws CRLException, NoSuchAlgorithmException, InvalidKeyException,

Choose a reason for hiding this comment

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

Does this method still has calls which throw CRLException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it calls TBSCertList::encodeInfo.

Choose a reason for hiding this comment

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

Ok.

@@ -468,35 +466,31 @@ public static X509CertImpl newSigned(X509CertInfo info, PrivateKey key, String a
public static X509CertImpl newSigned(X509CertInfo info, PrivateKey key, String algorithm, String provider)
throws CertificateException, NoSuchAlgorithmException,

Choose a reason for hiding this comment

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

The javadoc above states that CertificateException is thrown on encoding errors. Will there still be encoding errors? The updated code seems not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inside X509CertInfo::emit, there is

        if ((version.compare(CertificateVersion.V1) == 0) &&
            (issuer.toString() == null))
            throw new CertificateParsingException(
                      "Null issuer DN not allowed in v1 certificate");

and more places where the exception might be thrown.

Choose a reason for hiding this comment

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

Ok.

@@ -75,55 +75,49 @@ public NegTokenTarg(byte[] in) throws GSSException {
}

final byte[] encode() throws GSSException {

Choose a reason for hiding this comment

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

Probably no need for GSSException?

Copy link
Contributor Author

@wangweij wangweij Nov 27, 2022

Choose a reason for hiding this comment

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

This is because Oid::getDER still throws it, and I don't want to modify a public API.

Choose a reason for hiding this comment

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

Ok.

@@ -98,47 +98,38 @@ public final class ECPrivateKeyImpl extends PKCS8Key implements ECPrivateKey {

private void makeEncoding(byte[] s) throws InvalidKeyException {

Choose a reason for hiding this comment

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

No need for the InvalidKeyException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ECParameters::getAlgorithmParameters throws it.

Choose a reason for hiding this comment

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

Hmm, alright.

Arrays.fill(privBytes, (byte) 0);
DerValue val = DerValue.wrap(DerValue.tag_Sequence, out);
key = val.toByteArray();
val.clear();
}

private void makeEncoding(BigInteger s) throws InvalidKeyException {

Choose a reason for hiding this comment

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

No need for the InvalidKeyException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@wangweij
Copy link
Contributor Author

wangweij commented Nov 28, 2022

New commit pushed. I cannot touched Old::getDER without a public API change. I did notice there are also a lot of asn1Encode methods in JGSS but it does not have the same signature as DerEncoder::encode. I've filed https://bugs.openjdk.org/browse/JDK-8297723.

Copy link
Member

@seanjmullan seanjmullan left a comment

Choose a reason for hiding this comment

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

All changes look reasonable to me.

@openjdk
Copy link

openjdk bot commented Nov 28, 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:

8297065: DerOutputStream operations should not throw IOExceptions

Reviewed-by: mullan, 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 79 new commits pushed to the master branch:

  • d83a07b: 8297200: java/net/httpclient/SpecialHeadersTest.java failed once in AssertionError due to selector thread remaining alive
  • 5d2772a: 8297424: java/net/httpclient/AsyncExecutorShutdown.java fails in AssertionError due to misplaced assert
  • 361b50e: 8292594: Use CSS custom properties for all fonts and colors
  • 42b60ed: 8297030: Reduce Default Keep-Alive Timeout Value for httpclient
  • 1301fb0: 8296470: Refactor VMError::report STEP macro to improve readability
  • 48017b1: 8296804: Document HttpClient configuration properties in java.net.http module-info
  • bd51b7e: 8296645: org.openjdk.bench.javax.tools.Javac leaves class files in current directory
  • b27a61e: 8297216: Search results omit some methods
  • 33dfc7d: 8296954: G1: Enable parallel scanning for heap region remset
  • 6f06f44: 8297242: Use-after-free during library unloading on Linux
  • ... and 69 more: https://git.openjdk.org/jdk/compare/e174558cad836e56ac31725813abf7d8540c9919...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 Nov 28, 2022
@wangweij
Copy link
Contributor Author

A new commit pushed. A small somewhat related cleanup.

@wangweij
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 29, 2022

Going to push as commit 2deb318.
Since your change was applied there have been 79 commits pushed to the master branch:

  • d83a07b: 8297200: java/net/httpclient/SpecialHeadersTest.java failed once in AssertionError due to selector thread remaining alive
  • 5d2772a: 8297424: java/net/httpclient/AsyncExecutorShutdown.java fails in AssertionError due to misplaced assert
  • 361b50e: 8292594: Use CSS custom properties for all fonts and colors
  • 42b60ed: 8297030: Reduce Default Keep-Alive Timeout Value for httpclient
  • 1301fb0: 8296470: Refactor VMError::report STEP macro to improve readability
  • 48017b1: 8296804: Document HttpClient configuration properties in java.net.http module-info
  • bd51b7e: 8296645: org.openjdk.bench.javax.tools.Javac leaves class files in current directory
  • b27a61e: 8297216: Search results omit some methods
  • 33dfc7d: 8296954: G1: Enable parallel scanning for heap region remset
  • 6f06f44: 8297242: Use-after-free during library unloading on Linux
  • ... and 69 more: https://git.openjdk.org/jdk/compare/e174558cad836e56ac31725813abf7d8540c9919...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 29, 2022

@wangweij Pushed as commit 2deb318.

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

@wangweij wangweij deleted the 8297065 branch November 29, 2022 13:41
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
4 participants