Skip to content

Commit 7585508

Browse files
authored
RH2104724: Avoid import/export of DH private keys (#14)
Reviewed-by: @gnu-andrew
1 parent 03b584e commit 7585508

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;
@@ -194,34 +193,6 @@ static Long importKey(SunPKCS11 sunPKCS11, long hSession, CK_ATTRIBUTE[] attribu
194193
attrsMap.put(CKA_NETSCAPE_DB,
195194
new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
196195
}
197-
} else if (keyType == CKK_DH) {
198-
if (debug != null) {
199-
debug.println("Importing a Diffie-Hellman private key...");
200-
}
201-
if (DHKF == null) {
202-
DHKFLock.lock();
203-
try {
204-
if (DHKF == null) {
205-
DHKF = KeyFactory.getInstance(
206-
"DH", P11Util.getSunJceProvider());
207-
}
208-
} finally {
209-
DHKFLock.unlock();
210-
}
211-
}
212-
DHPrivateKeySpec spec = new DHPrivateKeySpec
213-
(((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null)
214-
? v : BigInteger.ZERO,
215-
((v = attrsMap.get(CKA_PRIME).getBigInteger()) != null)
216-
? v : BigInteger.ZERO,
217-
((v = attrsMap.get(CKA_BASE).getBigInteger()) != null)
218-
? v : BigInteger.ZERO);
219-
keyBytes = DHKF.generatePrivate(spec).getEncoded();
220-
if (token.config.getNssNetscapeDbWorkaround() &&
221-
attrsMap.get(CKA_NETSCAPE_DB) == null) {
222-
attrsMap.put(CKA_NETSCAPE_DB,
223-
new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
224-
}
225196
} else {
226197
if (debug != null) {
227198
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
@@ -384,7 +384,8 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm,
384384
new CK_ATTRIBUTE(CKA_SENSITIVE),
385385
new CK_ATTRIBUTE(CKA_EXTRACTABLE),
386386
});
387-
if (!plainKeySupportEnabled && (attributes[1].getBoolean() ||
387+
boolean exportable = plainKeySupportEnabled && !algorithm.equals("DH");
388+
if (!exportable && (attributes[1].getBoolean() ||
388389
(attributes[2].getBoolean() == false))) {
389390
return new P11PrivateKey
390391
(session, keyID, algorithm, keyLength, attributes);

0 commit comments

Comments
 (0)