Skip to content

Commit 6f16a44

Browse files
committed
8293345: SunPKCS11 provider checks on PKCS11 Mechanism are problematic
Reviewed-by: mbaesken, mbalao Backport-of: 1b476f52ba85f9ceaabe785d36cb07df831fd0e8
1 parent e29b061 commit 6f16a44

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, 2021, 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
@@ -127,6 +127,9 @@ private static void debug(Object o) {
127127
// whether to print debug info during startup
128128
private boolean showInfo = false;
129129

130+
// whether to allow legacy mechanisms
131+
private boolean allowLegacy = false;
132+
130133
// template manager, initialized from parsed attributes
131134
private TemplateManager templateManager;
132135

@@ -257,6 +260,10 @@ boolean getShowInfo() {
257260
return (SunPKCS11.debug != null) || showInfo;
258261
}
259262

263+
boolean getAllowLegacy() {
264+
return allowLegacy;
265+
}
266+
260267
TemplateManager getTemplateManager() {
261268
if (templateManager == null) {
262269
templateManager = new TemplateManager();
@@ -450,6 +457,8 @@ private void parse() throws IOException {
450457
destroyTokenAfterLogout = parseBooleanEntry(word);
451458
} else if (word.equals("showInfo")) {
452459
showInfo = parseBooleanEntry(word);
460+
} else if (word.equals("allowLegacy")) {
461+
allowLegacy = parseBooleanEntry(word);
453462
} else if (word.equals("keyStoreCompatibilityMode")) {
454463
keyStoreCompatibilityMode = parseBooleanEntry(word);
455464
} else if (word.equals("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
@@ -1055,25 +1055,6 @@ public Object run() {
10551055
}
10561056
}
10571057

1058-
private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
1059-
throws PKCS11Exception {
1060-
// assume full support if no mech info available
1061-
// For vendor-specific mechanisms, often no mech info is provided
1062-
boolean partialSupport = false;
1063-
1064-
if (mechInfo != null) {
1065-
if ((mechInfo.flags & CKF_DECRYPT) != 0) {
1066-
// non-legacy cipher mechs should support encryption
1067-
partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
1068-
}
1069-
if ((mechInfo.flags & CKF_VERIFY) != 0) {
1070-
// non-legacy signature mechs should support signing
1071-
partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
1072-
}
1073-
}
1074-
return partialSupport;
1075-
}
1076-
10771058
// test if a token is present and initialize this provider for it if so.
10781059
// does nothing if no token is found
10791060
// called from constructor and by poller
@@ -1124,12 +1105,6 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
11241105
}
11251106
continue;
11261107
}
1127-
if (isLegacy(mechInfo)) {
1128-
if (showInfo) {
1129-
System.out.println("DISABLED due to legacy");
1130-
}
1131-
continue;
1132-
}
11331108

11341109
// we do not know of mechs with the upper 32 bits set
11351110
if (longMech >>> 32 != 0) {
@@ -1144,9 +1119,25 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
11441119
if (ds == null) {
11451120
continue;
11461121
}
1122+
boolean allowLegacy = config.getAllowLegacy();
11471123
for (Descriptor d : ds) {
11481124
Integer oldMech = supportedAlgs.get(d);
11491125
if (oldMech == null) {
1126+
1127+
// assume full support if no mech info available
1128+
if (!allowLegacy && mechInfo != null) {
1129+
if ((d.type == CIP &&
1130+
(mechInfo.flags & CKF_ENCRYPT) == 0) ||
1131+
(d.type == SIG &&
1132+
(mechInfo.flags & CKF_SIGN) == 0)) {
1133+
if (showInfo) {
1134+
System.out.println("DISABLED " + d.type +
1135+
" " + d.algorithm +
1136+
" due to partial support");
1137+
}
1138+
continue;
1139+
}
1140+
}
11501141
supportedAlgs.put(d, integerMech);
11511142
continue;
11521143
}

0 commit comments

Comments
 (0)