-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8358451: SunJCE PBEKey impl should throw IllegalStateException when getEncoded() is called #25632
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
base: master
Are you sure you want to change the base?
Conversation
…etEncoded() is called
👋 Welcome back valeriep! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@valeriepeng The following label will be automatically applied to this pull request:
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. |
Webrevs
|
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.
Shall we also throw ISE when getFormat
and getAlgorithm
are called? Calling these methods after the key is destroyed looks suspicious and may reveal a coding error.
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.
Well, I see that throw IllegalStateException
for almost all methods seems to be the style for the Destroyable
impl classes under the javax.security.auth.kerberos
package. But I am not sure if this would be too "noisy" for Key objects. At a minimum, we should throw IllegalStateException
for method which trying to use the sensitive info which has been cleared out. However, if we throw IllegalStateException
for all methods such as getAlgorithm()
, then it may lead to even more IllegalStateException
being thrown unexpectedly and may make troubleshooting harder.
@@ -80,6 +81,9 @@ final class PBEKey implements SecretKey { | |||
|
|||
public byte[] getEncoded() { |
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 understand this is not a public API class so there is no need to provide @throws
in the spec. But, on the other hand, do we need to provide one in its super class java.security.key
? I have no opinion.
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.
Well, I am not sure. java.securityKey
is the super interface for all keys, including private, public, and secret keys. The Exception is due to implementing the javax.security.auth.Destroyable
interface, so the @throws
spec should goes to the class which implements both Destroyable
and Key
interfaces. PBEKey
is not a public API class, so perhaps we can documenting this in the SunJCE
provider section as this is implementation-specific?
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.
Also, PublicKey
does not implement (or implement by inheritance) Destroyable
.
@@ -202,6 +205,9 @@ private void readObject(java.io.ObjectInputStream s) | |||
@java.io.Serial | |||
private Object writeReplace() throws java.io.ObjectStreamException { | |||
try { | |||
if (isDestroyed()) { | |||
throw new NotSerializableException("key is destroyed"); |
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.
nit: for uniformity, you may want to capitalize key
since it is capitalized elsewhere
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.
Yes, will fix.
@@ -80,6 +81,9 @@ final class PBEKey implements SecretKey { | |||
|
|||
public byte[] getEncoded() { | |||
try { | |||
if (isDestroyed()) { | |||
throw new IllegalStateException("key is destroyed"); |
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.
nit: for uniformity, you may want to capitalize key since it is capitalized elsewhere
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.
Yes, will fix.
JCA SecretKeyFactory class. Changed to throw ISE whenever destroyed key is encountered.
Update the
PBEKey
class of the SunJCE provider which override thejavax.security.auth.Destroyable
interface toIllegalStateException
ifgetEncoded()
is called after key is destroyedPBEKey
object will lead to exception.Also update the
PBEKeyFactory
class of the SunJCE provider to check for destroyed keys and throw exceptions per the method javadoc.Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25632/head:pull/25632
$ git checkout pull/25632
Update a local copy of the PR:
$ git checkout pull/25632
$ git pull https://git.openjdk.org/jdk.git pull/25632/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25632
View PR using the GUI difftool:
$ git pr show -t 25632
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25632.diff
Using Webrev
Link to Webrev Comment