From ca78f7bd762e1d5cd843d1ff36fafb8c943aba97 Mon Sep 17 00:00:00 2001 From: Hai-May Chao Date: Mon, 27 Jun 2022 23:15:13 +0000 Subject: [PATCH] 8286259: Password cleanup after KeyStore.PasswordProtection in P11KeyStore Reviewed-by: valeriep --- .../classes/sun/security/pkcs11/P11KeyStore.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java index c52ca66b326..46a0cf79442 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java @@ -57,6 +57,7 @@ import java.security.spec.*; import javax.crypto.SecretKey; import javax.crypto.interfaces.*; +import javax.security.auth.DestroyFailedException; import javax.security.auth.x500.X500Principal; import javax.security.auth.login.LoginException; import javax.security.auth.callback.Callback; @@ -454,7 +455,18 @@ final class P11KeyStore extends KeyStoreSpi { } catch (NullPointerException | IllegalArgumentException e) { throw new KeyStoreException(e); } - engineSetEntry(alias, entry, new KeyStore.PasswordProtection(password)); + + KeyStore.PasswordProtection passwordProtection = + new KeyStore.PasswordProtection(password); + try { + engineSetEntry(alias, entry, passwordProtection); + } finally { + try { + passwordProtection.destroy(); + } catch (DestroyFailedException dfe) { + // ignore + } + } } /**