From 324d71a1fd5514b3d54f60738acf61d7be5bc7a4 Mon Sep 17 00:00:00 2001 From: Francisco Ferrari Bihurriet Date: Thu, 7 Jul 2022 00:52:49 -0300 Subject: [PATCH] RH2104724: Avoid import/export of DH private keys --- .../sun/security/pkcs11/FIPSKeyImporter.java | 29 ------------------- .../classes/sun/security/pkcs11/P11Key.java | 3 +- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java index 9bb31555f480d..8cfa2734d4ec5 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java @@ -38,7 +38,6 @@ import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.SecretKeySpec; -import javax.crypto.spec.DHPrivateKeySpec; import javax.crypto.spec.IvParameterSpec; import sun.security.jca.JCAUtil; @@ -194,34 +193,6 @@ static Long importKey(SunPKCS11 sunPKCS11, long hSession, CK_ATTRIBUTE[] attribu attrsMap.put(CKA_NETSCAPE_DB, new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO)); } - } else if (keyType == CKK_DH) { - if (debug != null) { - debug.println("Importing a Diffie-Hellman private key..."); - } - if (DHKF == null) { - DHKFLock.lock(); - try { - if (DHKF == null) { - DHKF = KeyFactory.getInstance( - "DH", P11Util.getSunJceProvider()); - } - } finally { - DHKFLock.unlock(); - } - } - DHPrivateKeySpec spec = new DHPrivateKeySpec - (((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null) - ? v : BigInteger.ZERO, - ((v = attrsMap.get(CKA_PRIME).getBigInteger()) != null) - ? v : BigInteger.ZERO, - ((v = attrsMap.get(CKA_BASE).getBigInteger()) != null) - ? v : BigInteger.ZERO); - keyBytes = DHKF.generatePrivate(spec).getEncoded(); - if (token.config.getNssNetscapeDbWorkaround() && - attrsMap.get(CKA_NETSCAPE_DB) == null) { - attrsMap.put(CKA_NETSCAPE_DB, - new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO)); - } } else { if (debug != null) { debug.println("Unrecognized private key type."); diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java index b403e6d3c6d1e..babf19d7157d9 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java @@ -384,7 +384,8 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm, new CK_ATTRIBUTE(CKA_SENSITIVE), new CK_ATTRIBUTE(CKA_EXTRACTABLE), }); - if (!plainKeySupportEnabled && (attributes[1].getBoolean() || + boolean exportable = plainKeySupportEnabled && !algorithm.equals("DH"); + if (!exportable && (attributes[1].getBoolean() || (attributes[2].getBoolean() == false))) { return new P11PrivateKey (session, keyID, algorithm, keyLength, attributes);