Skip to content

Commit 1b476f5

Browse files
author
Valerie Peng
committed
8293345: SunPKCS11 provider checks on PKCS11 Mechanism are problematic
Reviewed-by: djelinski, weijun
1 parent 1c5f150 commit 1b476f5

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -121,6 +121,9 @@ public List<String> run() {
121121
// whether to print debug info during startup
122122
private boolean showInfo = false;
123123

124+
// whether to allow legacy mechanisms
125+
private boolean allowLegacy = false;
126+
124127
// template manager, initialized from parsed attributes
125128
private TemplateManager templateManager;
126129

@@ -251,6 +254,10 @@ boolean getShowInfo() {
251254
return (SunPKCS11.debug != null) || showInfo;
252255
}
253256

257+
boolean getAllowLegacy() {
258+
return allowLegacy;
259+
}
260+
254261
TemplateManager getTemplateManager() {
255262
if (templateManager == null) {
256263
templateManager = new TemplateManager();
@@ -453,6 +460,8 @@ private void parse() throws IOException {
453460
destroyTokenAfterLogout = parseBooleanEntry(st.sval);
454461
case "showInfo"->
455462
showInfo = parseBooleanEntry(st.sval);
463+
case "allowLegacy"->
464+
allowLegacy = parseBooleanEntry(st.sval);
456465
case "keyStoreCompatibilityMode"->
457466
keyStoreCompatibilityMode = parseBooleanEntry(st.sval);
458467
case "explicitCancel"->

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,25 +1222,6 @@ public Object run() {
12221222
}
12231223
}
12241224

1225-
private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
1226-
throws PKCS11Exception {
1227-
// assume full support if no mech info available
1228-
// For vendor-specific mechanisms, often no mech info is provided
1229-
boolean partialSupport = false;
1230-
1231-
if (mechInfo != null) {
1232-
if ((mechInfo.flags & CKF_DECRYPT) != 0) {
1233-
// non-legacy cipher mechs should support encryption
1234-
partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
1235-
}
1236-
if ((mechInfo.flags & CKF_VERIFY) != 0) {
1237-
// non-legacy signature mechs should support signing
1238-
partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
1239-
}
1240-
}
1241-
return partialSupport;
1242-
}
1243-
12441225
// test if a token is present and initialize this provider for it if so.
12451226
// does nothing if no token is found
12461227
// called from constructor and by poller
@@ -1309,12 +1290,6 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
13091290
}
13101291
continue;
13111292
}
1312-
if (isLegacy(mechInfo)) {
1313-
if (showInfo) {
1314-
System.out.println("DISABLED due to legacy");
1315-
}
1316-
continue;
1317-
}
13181293

13191294
if (brokenMechanisms.contains(longMech)) {
13201295
if (showInfo) {
@@ -1336,6 +1311,7 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
13361311
if (ds == null) {
13371312
continue;
13381313
}
1314+
boolean allowLegacy = config.getAllowLegacy();
13391315
descLoop:
13401316
for (Descriptor d : ds) {
13411317
Integer oldMech = supportedAlgs.get(d);
@@ -1351,6 +1327,21 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
13511327
}
13521328
}
13531329
}
1330+
1331+
// assume full support if no mech info available
1332+
if (!allowLegacy && mechInfo != null) {
1333+
if ((d.type == CIP &&
1334+
(mechInfo.flags & CKF_ENCRYPT) == 0) ||
1335+
(d.type == SIG &&
1336+
(mechInfo.flags & CKF_SIGN) == 0)) {
1337+
if (showInfo) {
1338+
System.out.println("DISABLED " + d.type +
1339+
" " + d.algorithm +
1340+
" due to partial support");
1341+
}
1342+
continue;
1343+
}
1344+
}
13541345
supportedAlgs.put(d, integerMech);
13551346
continue;
13561347
}

0 commit comments

Comments
 (0)