-
Notifications
You must be signed in to change notification settings - Fork 231
8302111: Serialization considerations #3278
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
Conversation
|
👋 Welcome back goetz! A progress list of the required criteria for merging this PR into |
|
@GoeLin 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 20 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 |
|
This backport pull request has now been updated with issue from the original commit. |
Webrevs
|
| * @param p the prime modulus | ||
| * @param g the base generator | ||
| * | ||
| * @throws ProviderException if the key cannot be encoded |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Hi @reinrich,
thanks for looking at this backport. I fixed DHPrivateKey accordingly.
| c = decode(encodedKeyIntern); | ||
| } catch (IOException e) { | ||
| InvalidObjectException ioe = new InvalidObjectException("Invalid encoding"); | ||
| if (ioe != 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.
Isn't this condition always true?
Note also that the throw below will throw a NPE if it ioe was null.
I think you can actually remove the condition.
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.
My inital desing was
throw new InvalidObjectException("Invalid encoding").initCause(e);
But the compiler does not like this:
error: unreported exception Throwable; must be caught or declared to be thrown
So I decided to add the try/catch with the null check.
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 see... strange. But it does compile without the null check. I think it should be removed.
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'll remove the null check in both places where I added initCause().
| } catch (IOException e) { | ||
| // Ignore, see JDK-8297065. | ||
| derKey = null; | ||
| } | ||
| return derKey.toByteArray(); |
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.
This looks weired if someone has a quick look at these lines of code: if an IOE occurs and is caught here, then derKey will be assigned null and 2 lines below an NPE will thrown because of this.
I'd suggest to wrap the whole method body in a try-catch. This would reduce the diff to jdk 21.
In the IOE catch clause you shouldn't say that the IOE is ignored but you should state that it cannot even occur since DerOutputStream is a ByteArrayOutputStream which doesn't do any I/O. Then just return null or throw an InternalError are something else if more appropriate.
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.
ok, this makes sense. See extra commit. I did it for all three places where I catch the IO exception.
| try { | ||
| this.key = new DerValue(DerValue.tag_Integer, | ||
| this.y.toByteArray()).toByteArray(); | ||
| this.encodedKey = getEncoded(); | ||
| this.encodedKey = encode(p, g, l, key); | ||
| } catch (IOException e) { | ||
| throw new ProviderException("Cannot produce ASN.1 encoding", e); | ||
| } |
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.
You should remove the try-catch. encode doesn't throw IOE. This also removes the diff to jdk 21.
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.
It is toByteArray that trows the IOException.
I can add the InternalError here as in the other places?
But here I thought it's obvious to have the old behaviour.
| if (ioe != null) { | ||
| ioe.initCause(e); | ||
| } |
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 null check is redundant.
| if (ioe != null) { | |
| ioe.initCause(e); | |
| } | |
| ioe.initCause(e); |
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.
Removed.
|
Triggered by the discussion here and offline I had a second look at the exceptions I need to add because JDK-8297065 is not in 17. I committed some code that brings these closer to the origin. One I had added is not really needed as IOException is caught at the callsite anyways. |
reinrich
left a comment
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.
Looks good to me.
Cheers, Richard.
|
|
And the diff to the versions of DHPublicKey.java and DHPrivateKey.java is minimal now. |
Yes, thanks for reviewing! |
|
Hi @martinuy, |
|
/integrate |
|
Going to push as commit ae0177b.
Your commit was automatically rebased without conflicts. |
I backport this to match 17.0.13-oracle based on the commit to 21.
I had to resolve several files, two of them considerably:
src/java.base/share/classes/com/sun/crypto/provider/DHPrivateKey.java
Resolved larger chunk.
src/java.base/share/classes/com/sun/crypto/provider/DHPublicKey.java
Resolved some code.
The new code in DHPublic/PrivateKey depends on the removal
of IOExceptions in JDK-8297065 "DerOutputStream operations should not throw IOExceptions".
This change is in 21 but not in 17. Thus code backported from 21 calls functions of
DerOutputStream that do not throw an exception in 21, but do so in 17.
JDK-8297065 makes the point that these exceptions can never be thrown, which also
holds for 17. So I just catch and ignore them.
Also, I had to adapt code because an exception constructor with cause for
InvalidObjectException is missing in 17.
This was added by JDK-8282696 "Add constructors taking a cause
to InvalidObjectException and InvalidClassException" in 19.
I added a call to initCause() to store the causing exception.
I double-checked that JDK-8297065 was not backported
by Oracle. Backporting this change would simplify matters considerably.
The remaining files only needed trivial resolves:
src/java.base/share/classes/java/security/Permissions.java
src/java.base/share/classes/java/security/SignedObject.java
Only Copyright.
src/java.base/share/classes/java/security/Timestamp.java
Copyright and import.
src/java.base/share/classes/java/security/UnresolvedPermissionCollection.java
src/java.base/share/classes/java/security/cert/CertificateRevokedException.java
src/java.base/share/classes/sun/security/provider/DRBG.java
src/java.base/share/classes/sun/security/util/ObjectIdentifier.java
src/java.base/share/classes/sun/security/x509/AlgIdDSA.java
Only Copyright.
src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5Context.java
Resolved imports.
src/java.security.jgss/share/classes/sun/security/jgss/krb5/Krb5InitCredential.java
src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11SecureRandom.java
Only Copyright.
I manually ran these tests on linux x86_64:
test/jdk/com/sun/security
test/jdk/java/awt/security
test/jdk/java/net/httpclient/security
test/jdk/java/net/httpclient/websocket/security
test/jdk/java/security
test/jdk/javax/management/security
test/jdk/javax/security
test/jdk/jdk/security
test/jdk/security
test/jdk/sun/security
Our well-known nightly tests passed, too.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/3278/head:pull/3278$ git checkout pull/3278Update a local copy of the PR:
$ git checkout pull/3278$ git pull https://git.openjdk.org/jdk17u-dev.git pull/3278/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3278View PR using the GUI difftool:
$ git pr show -t 3278Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/3278.diff
Using Webrev
Link to Webrev Comment