Skip to content

Commit 37df1cb

Browse files
committed
8293345: SunPKCS11 provider checks on PKCS11 Mechanism are problematic
Backport-of: 1b476f52ba85f9ceaabe785d36cb07df831fd0e8
1 parent 7511a0b commit 37df1cb

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
@@ -1212,25 +1212,6 @@ public Object run() {
12121212
}
12131213
}
12141214

1215-
private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
1216-
throws PKCS11Exception {
1217-
// assume full support if no mech info available
1218-
// For vendor-specific mechanisms, often no mech info is provided
1219-
boolean partialSupport = false;
1220-
1221-
if (mechInfo != null) {
1222-
if ((mechInfo.flags & CKF_DECRYPT) != 0) {
1223-
// non-legacy cipher mechs should support encryption
1224-
partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
1225-
}
1226-
if ((mechInfo.flags & CKF_VERIFY) != 0) {
1227-
// non-legacy signature mechs should support signing
1228-
partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
1229-
}
1230-
}
1231-
return partialSupport;
1232-
}
1233-
12341215
// test if a token is present and initialize this provider for it if so.
12351216
// does nothing if no token is found
12361217
// called from constructor and by poller
@@ -1281,12 +1262,6 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
12811262
}
12821263
continue;
12831264
}
1284-
if (isLegacy(mechInfo)) {
1285-
if (showInfo) {
1286-
System.out.println("DISABLED due to legacy");
1287-
}
1288-
continue;
1289-
}
12901265

12911266
// we do not know of mechs with the upper 32 bits set
12921267
if (longMech >>> 32 != 0) {
@@ -1301,6 +1276,7 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
13011276
if (ds == null) {
13021277
continue;
13031278
}
1279+
boolean allowLegacy = config.getAllowLegacy();
13041280
descLoop:
13051281
for (Descriptor d : ds) {
13061282
Integer oldMech = supportedAlgs.get(d);
@@ -1316,6 +1292,21 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
13161292
}
13171293
}
13181294
}
1295+
1296+
// assume full support if no mech info available
1297+
if (!allowLegacy && mechInfo != null) {
1298+
if ((d.type == CIP &&
1299+
(mechInfo.flags & CKF_ENCRYPT) == 0) ||
1300+
(d.type == SIG &&
1301+
(mechInfo.flags & CKF_SIGN) == 0)) {
1302+
if (showInfo) {
1303+
System.out.println("DISABLED " + d.type +
1304+
" " + d.algorithm +
1305+
" due to partial support");
1306+
}
1307+
continue;
1308+
}
1309+
}
13191310
supportedAlgs.put(d, integerMech);
13201311
continue;
13211312
}

0 commit comments

Comments
 (0)