Skip to content

Commit 1c68a80

Browse files
committed
RH2104724: Avoid import/export of DH private keys
Backport-Of: rh-openjdk/jdk@7585508
1 parent 46ffa10 commit 1c68a80

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import javax.crypto.Cipher;
3939
import javax.crypto.SecretKeyFactory;
4040
import javax.crypto.spec.SecretKeySpec;
41-
import javax.crypto.spec.DHPrivateKeySpec;
4241
import javax.crypto.spec.IvParameterSpec;
4342

4443
import sun.security.jca.JCAUtil;
@@ -193,34 +192,6 @@ static Long importKey(SunPKCS11 sunPKCS11, long hSession, CK_ATTRIBUTE[] attribu
193192
attrsMap.put(CKA_NETSCAPE_DB,
194193
new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
195194
}
196-
} else if (keyType == CKK_DH) {
197-
if (debug != null) {
198-
debug.println("Importing a Diffie-Hellman private key...");
199-
}
200-
if (DHKF == null) {
201-
DHKFLock.lock();
202-
try {
203-
if (DHKF == null) {
204-
DHKF = KeyFactory.getInstance(
205-
"DH", P11Util.getSunJceProvider());
206-
}
207-
} finally {
208-
DHKFLock.unlock();
209-
}
210-
}
211-
DHPrivateKeySpec spec = new DHPrivateKeySpec
212-
(((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null)
213-
? v : BigInteger.ZERO,
214-
((v = attrsMap.get(CKA_PRIME).getBigInteger()) != null)
215-
? v : BigInteger.ZERO,
216-
((v = attrsMap.get(CKA_BASE).getBigInteger()) != null)
217-
? v : BigInteger.ZERO);
218-
keyBytes = DHKF.generatePrivate(spec).getEncoded();
219-
if (token.config.getNssNetscapeDbWorkaround() &&
220-
attrsMap.get(CKA_NETSCAPE_DB) == null) {
221-
attrsMap.put(CKA_NETSCAPE_DB,
222-
new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
223-
}
224195
} else {
225196
if (debug != null) {
226197
debug.println("Unrecognized private key type.");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm,
383383
new CK_ATTRIBUTE(CKA_SENSITIVE),
384384
new CK_ATTRIBUTE(CKA_EXTRACTABLE),
385385
});
386-
if (!plainKeySupportEnabled && (attributes[1].getBoolean() ||
386+
boolean exportable = plainKeySupportEnabled && !algorithm.equals("DH");
387+
if (!exportable && (attributes[1].getBoolean() ||
387388
(attributes[2].getBoolean() == false))) {
388389
return new P11PrivateKey
389390
(session, keyID, algorithm, keyLength, attributes);

0 commit comments

Comments
 (0)