-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,9 @@ final class PBEKey implements SecretKey { | |
|
||
public byte[] getEncoded() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I am not sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, |
||
try { | ||
if (isDestroyed()) { | ||
throw new IllegalStateException("Key is destroyed"); | ||
} | ||
return key.clone(); | ||
} finally { | ||
// prevent this from being cleaned for the above block | ||
|
@@ -139,7 +142,6 @@ public boolean equals(Object obj) { | |
|
||
/** | ||
* Clears the internal copy of the key. | ||
* | ||
*/ | ||
@Override | ||
public void destroy() { | ||
|
@@ -202,6 +204,9 @@ private void readObject(java.io.ObjectInputStream s) | |
@java.io.Serial | ||
private Object writeReplace() throws java.io.ObjectStreamException { | ||
try { | ||
if (isDestroyed()) { | ||
throw new IllegalStateException("Key is destroyed"); | ||
} | ||
return new KeyRep(KeyRep.Type.SECRET, | ||
getAlgorithm(), | ||
getFormat(), | ||
|
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
andgetAlgorithm
are called? Calling these methods after the key is destroyed looks suspicious and may reveal a coding error.Uh oh!
There was an error while loading. Please reload this page.
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 theDestroyable
impl classes under thejavax.security.auth.kerberos
package. But I am not sure if this would be too "noisy" for Key objects. At a minimum, we should throwIllegalStateException
for method which trying to use the sensitive info which has been cleared out. However, if we throwIllegalStateException
for all methods such asgetAlgorithm()
, then it may lead to even moreIllegalStateException
being thrown unexpectedly and may make troubleshooting harder.