Skip to content

Commit ca78f7b

Browse files
author
Hai-May Chao
committed
8286259: Password cleanup after KeyStore.PasswordProtection in P11KeyStore
Reviewed-by: valeriep
1 parent e322e77 commit ca78f7b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import javax.crypto.SecretKey;
5858
import javax.crypto.interfaces.*;
5959

60+
import javax.security.auth.DestroyFailedException;
6061
import javax.security.auth.x500.X500Principal;
6162
import javax.security.auth.login.LoginException;
6263
import javax.security.auth.callback.Callback;
@@ -454,7 +455,18 @@ public synchronized void engineSetKeyEntry(String alias, Key key,
454455
} catch (NullPointerException | IllegalArgumentException e) {
455456
throw new KeyStoreException(e);
456457
}
457-
engineSetEntry(alias, entry, new KeyStore.PasswordProtection(password));
458+
459+
KeyStore.PasswordProtection passwordProtection =
460+
new KeyStore.PasswordProtection(password);
461+
try {
462+
engineSetEntry(alias, entry, passwordProtection);
463+
} finally {
464+
try {
465+
passwordProtection.destroy();
466+
} catch (DestroyFailedException dfe) {
467+
// ignore
468+
}
469+
}
458470
}
459471

460472
/**

0 commit comments

Comments
 (0)