Skip to content

Commit da5bfa9

Browse files
vieirognu-andrew
authored andcommitted
8293345: SunPKCS11 provider checks on PKCS11 Mechanism are problematic
Reviewed-by: andrew Backport-of: 6f16a44784fbaeedfe4ccd6c4e7fb5280b329c2b
1 parent c56a86d commit da5bfa9

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

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

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

262+
boolean getAllowLegacy() {
263+
return allowLegacy;
264+
}
265+
259266
TemplateManager getTemplateManager() {
260267
if (templateManager == null) {
261268
templateManager = new TemplateManager();
@@ -449,6 +456,8 @@ private void parse() throws IOException {
449456
destroyTokenAfterLogout = parseBooleanEntry(word);
450457
} else if (word.equals("showInfo")) {
451458
showInfo = parseBooleanEntry(word);
459+
} else if (word.equals("allowLegacy")) {
460+
allowLegacy = parseBooleanEntry(word);
452461
} else if (word.equals("keyStoreCompatibilityMode")) {
453462
keyStoreCompatibilityMode = parseBooleanEntry(word);
454463
} 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
@@ -956,25 +956,6 @@ public Object run() {
956956
}
957957
}
958958

959-
private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
960-
throws PKCS11Exception {
961-
// assume full support if no mech info available
962-
// For vendor-specific mechanisms, often no mech info is provided
963-
boolean partialSupport = false;
964-
965-
if (mechInfo != null) {
966-
if ((mechInfo.flags & CKF_DECRYPT) != 0) {
967-
// non-legacy cipher mechs should support encryption
968-
partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
969-
}
970-
if ((mechInfo.flags & CKF_VERIFY) != 0) {
971-
// non-legacy signature mechs should support signing
972-
partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
973-
}
974-
}
975-
return partialSupport;
976-
}
977-
978959
// test if a token is present and initialize this provider for it if so.
979960
// does nothing if no token is found
980961
// called from constructor and by poller
@@ -1025,12 +1006,6 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
10251006
}
10261007
continue;
10271008
}
1028-
if (isLegacy(mechInfo)) {
1029-
if (showInfo) {
1030-
System.out.println("DISABLED due to legacy");
1031-
}
1032-
continue;
1033-
}
10341009

10351010
// we do not know of mechs with the upper 32 bits set
10361011
if (longMech >>> 32 != 0) {
@@ -1045,9 +1020,25 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
10451020
if (ds == null) {
10461021
continue;
10471022
}
1023+
boolean allowLegacy = config.getAllowLegacy();
10481024
for (Descriptor d : ds) {
10491025
Integer oldMech = supportedAlgs.get(d);
10501026
if (oldMech == null) {
1027+
1028+
// assume full support if no mech info available
1029+
if (!allowLegacy && mechInfo != null) {
1030+
if ((d.type == CIP &&
1031+
(mechInfo.flags & CKF_ENCRYPT) == 0) ||
1032+
(d.type == SIG &&
1033+
(mechInfo.flags & CKF_SIGN) == 0)) {
1034+
if (showInfo) {
1035+
System.out.println("DISABLED " + d.type +
1036+
" " + d.algorithm +
1037+
" due to partial support");
1038+
}
1039+
continue;
1040+
}
1041+
}
10511042
supportedAlgs.put(d, integerMech);
10521043
continue;
10531044
}

0 commit comments

Comments
 (0)