8172525: Improve key keying case
Reviewed-by: mullan, valeriep, rhalade, ahgross
This commit is contained in:
parent
2ad7c43b76
commit
bb2e7a3311
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package com.sun.crypto.provider;
|
package com.sun.crypto.provider;
|
||||||
|
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.KeyRep;
|
import java.security.KeyRep;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
@ -86,7 +87,12 @@ final class DESKey implements SecretKey {
|
|||||||
public byte[] getEncoded() {
|
public byte[] getEncoded() {
|
||||||
// Return a copy of the key, rather than a reference,
|
// Return a copy of the key, rather than a reference,
|
||||||
// so that the key data cannot be modified from outside
|
// so that the key data cannot be modified from outside
|
||||||
return this.key.clone();
|
|
||||||
|
// The key is zeroized by finalize()
|
||||||
|
// The reachability fence ensures finalize() isn't called early
|
||||||
|
byte[] result = key.clone();
|
||||||
|
Reference.reachabilityFence(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlgorithm() {
|
public String getAlgorithm() {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package com.sun.crypto.provider;
|
package com.sun.crypto.provider;
|
||||||
|
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.KeyRep;
|
import java.security.KeyRep;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
@ -86,7 +87,11 @@ final class DESedeKey implements SecretKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getEncoded() {
|
public byte[] getEncoded() {
|
||||||
return this.key.clone();
|
// The key is zeroized by finalize()
|
||||||
|
// The reachability fence ensures finalize() isn't called early
|
||||||
|
byte[] result = key.clone();
|
||||||
|
Reference.reachabilityFence(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlgorithm() {
|
public String getAlgorithm() {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package com.sun.crypto.provider;
|
package com.sun.crypto.provider;
|
||||||
|
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.KeyRep;
|
import java.security.KeyRep;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
@ -80,7 +81,11 @@ final class PBEKey implements SecretKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getEncoded() {
|
public byte[] getEncoded() {
|
||||||
return this.key.clone();
|
// The key is zeroized by finalize()
|
||||||
|
// The reachability fence ensures finalize() isn't called early
|
||||||
|
byte[] result = key.clone();
|
||||||
|
Reference.reachabilityFence(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlgorithm() {
|
public String getAlgorithm() {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package com.sun.crypto.provider;
|
package com.sun.crypto.provider;
|
||||||
|
|
||||||
import java.io.ObjectStreamException;
|
import java.io.ObjectStreamException;
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -208,7 +209,11 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getEncoded() {
|
public byte[] getEncoded() {
|
||||||
return key.clone();
|
// The key is zeroized by finalize()
|
||||||
|
// The reachability fence ensures finalize() isn't called early
|
||||||
|
byte[] result = key.clone();
|
||||||
|
Reference.reachabilityFence(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlgorithm() {
|
public String getAlgorithm() {
|
||||||
@ -220,7 +225,11 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public char[] getPassword() {
|
public char[] getPassword() {
|
||||||
return passwd.clone();
|
// The password is zeroized by finalize()
|
||||||
|
// The reachability fence ensures finalize() isn't called early
|
||||||
|
char[] result = passwd.clone();
|
||||||
|
Reference.reachabilityFence(this);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getSalt() {
|
public byte[] getSalt() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user