提交 3cad1e6f 编写于 作者: I igerasim

8172525: Improve key keying case

Reviewed-by: mullan
上级 41156ddc
...@@ -76,7 +76,7 @@ final class DESKey implements SecretKey { ...@@ -76,7 +76,7 @@ final class DESKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 0); DESKeyGenerator.setParityBit(this.key, 0);
} }
public byte[] getEncoded() { public synchronized 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(); return this.key.clone();
...@@ -151,9 +151,11 @@ final class DESKey implements SecretKey { ...@@ -151,9 +151,11 @@ final class DESKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (this.key != null) { synchronized (this) {
java.util.Arrays.fill(this.key, (byte)0x00); if (this.key != null) {
this.key = null; java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
} }
} finally { } finally {
super.finalize(); super.finalize();
......
...@@ -78,7 +78,7 @@ final class DESedeKey implements SecretKey { ...@@ -78,7 +78,7 @@ final class DESedeKey implements SecretKey {
DESKeyGenerator.setParityBit(this.key, 16); DESKeyGenerator.setParityBit(this.key, 16);
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return this.key.clone(); return this.key.clone();
} }
...@@ -152,9 +152,11 @@ final class DESedeKey implements SecretKey { ...@@ -152,9 +152,11 @@ final class DESedeKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (this.key != null) { synchronized (this) {
java.util.Arrays.fill(this.key, (byte)0x00); if (this.key != null) {
this.key = null; java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
} }
} finally { } finally {
super.finalize(); super.finalize();
......
...@@ -72,7 +72,7 @@ final class PBEKey implements SecretKey { ...@@ -72,7 +72,7 @@ final class PBEKey implements SecretKey {
type = keytype; type = keytype;
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return this.key.clone(); return this.key.clone();
} }
...@@ -147,9 +147,11 @@ final class PBEKey implements SecretKey { ...@@ -147,9 +147,11 @@ final class PBEKey implements SecretKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (this.key != null) { synchronized (this) {
java.util.Arrays.fill(this.key, (byte)0x00); if (this.key != null) {
this.key = null; java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
} }
} finally { } finally {
super.finalize(); super.finalize();
......
...@@ -190,7 +190,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -190,7 +190,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return key; return key;
} }
public byte[] getEncoded() { public synchronized byte[] getEncoded() {
return key.clone(); return key.clone();
} }
...@@ -202,7 +202,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -202,7 +202,7 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
return iterCount; return iterCount;
} }
public char[] getPassword() { public synchronized char[] getPassword() {
return passwd.clone(); return passwd.clone();
} }
...@@ -264,13 +264,15 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey { ...@@ -264,13 +264,15 @@ final class PBKDF2KeyImpl implements javax.crypto.interfaces.PBEKey {
*/ */
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (this.passwd != null) { synchronized (this) {
java.util.Arrays.fill(this.passwd, '0'); if (this.passwd != null) {
this.passwd = null; java.util.Arrays.fill(this.passwd, '0');
} this.passwd = null;
if (this.key != null) { }
java.util.Arrays.fill(this.key, (byte)0x00); if (this.key != null) {
this.key = null; java.util.Arrays.fill(this.key, (byte)0x00);
this.key = null;
}
} }
} finally { } finally {
super.finalize(); super.finalize();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册