Skip to content

Commit a601814

Browse files
franferraxgnu-andrew
authored andcommitted
RH2104724: Avoid import/export of DH private keys (openjdk#14)
Reviewed-by: @gnu-andrew
1 parent aa83f06 commit a601814

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
@@ -396,7 +396,8 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm,
396396
new CK_ATTRIBUTE(CKA_EXTRACTABLE),
397397
});
398398

399-
boolean keySensitive = (!plainKeySupportEnabled &&
399+
boolean exportable = plainKeySupportEnabled && !algorithm.equals("DH");
400+
boolean keySensitive = (!exportable &&
400401
(attrs[0].getBoolean() ||
401402
attrs[1].getBoolean() || !attrs[2].getBoolean()));
402403

0 commit comments

Comments
 (0)