Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8293345: SunPKCS11 provider checks on PKCS11 Mechanism are problematic #2983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -126,6 +126,9 @@ private static void debug(Object o) {
// whether to print debug info during startup
private boolean showInfo = false;

// whether to allow legacy mechanisms
private boolean allowLegacy = false;

// template manager, initialized from parsed attributes
private TemplateManager templateManager;

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

boolean getAllowLegacy() {
return allowLegacy;
}

TemplateManager getTemplateManager() {
if (templateManager == null) {
templateManager = new TemplateManager();
Expand Down Expand Up @@ -449,6 +456,8 @@ private void parse() throws IOException {
destroyTokenAfterLogout = parseBooleanEntry(word);
} else if (word.equals("showInfo")) {
showInfo = parseBooleanEntry(word);
} else if (word.equals("allowLegacy")) {
allowLegacy = parseBooleanEntry(word);
} else if (word.equals("keyStoreCompatibilityMode")) {
keyStoreCompatibilityMode = parseBooleanEntry(word);
} else if (word.equals("explicitCancel")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,25 +956,6 @@ public Object run() {
}
}

private static boolean isLegacy(CK_MECHANISM_INFO mechInfo)
throws PKCS11Exception {
// assume full support if no mech info available
// For vendor-specific mechanisms, often no mech info is provided
boolean partialSupport = false;

if (mechInfo != null) {
if ((mechInfo.flags & CKF_DECRYPT) != 0) {
// non-legacy cipher mechs should support encryption
partialSupport |= ((mechInfo.flags & CKF_ENCRYPT) == 0);
}
if ((mechInfo.flags & CKF_VERIFY) != 0) {
// non-legacy signature mechs should support signing
partialSupport |= ((mechInfo.flags & CKF_SIGN) == 0);
}
}
return partialSupport;
}

// test if a token is present and initialize this provider for it if so.
// does nothing if no token is found
// called from constructor and by poller
Expand Down Expand Up @@ -1025,12 +1006,6 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
}
continue;
}
if (isLegacy(mechInfo)) {
if (showInfo) {
System.out.println("DISABLED due to legacy");
}
continue;
}

// we do not know of mechs with the upper 32 bits set
if (longMech >>> 32 != 0) {
Expand All @@ -1045,9 +1020,25 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception {
if (ds == null) {
continue;
}
boolean allowLegacy = config.getAllowLegacy();
for (Descriptor d : ds) {
Integer oldMech = supportedAlgs.get(d);
if (oldMech == null) {

// assume full support if no mech info available
if (!allowLegacy && mechInfo != null) {
if ((d.type == CIP &&
(mechInfo.flags & CKF_ENCRYPT) == 0) ||
(d.type == SIG &&
(mechInfo.flags & CKF_SIGN) == 0)) {
if (showInfo) {
System.out.println("DISABLED " + d.type +
" " + d.algorithm +
" due to partial support");
}
continue;
}
}
supportedAlgs.put(d, integerMech);
continue;
}
Expand Down