Skip to content

Commit 6276789

Browse files
author
Valerie Peng
committed
8328785: IOException: Symbol not found: C_GetInterface for PKCS11 interface prior to V3.0
Reviewed-by: djelinski, weijun
1 parent 316361b commit 6276789

File tree

1 file changed

+25
-34
lines changed
  • src/jdk.crypto.cryptoki/unix/native/libj2pkcs11

1 file changed

+25
-34
lines changed

src/jdk.crypto.cryptoki/unix/native/libj2pkcs11/p11_md.c

+25-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44

55
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -103,7 +103,6 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
103103
/*
104104
* Load the PKCS #11 DLL
105105
*/
106-
dlerror(); /* clear any old error message not fetched */
107106
#ifdef DEBUG
108107
hModule = dlopen(libraryNameStr, RTLD_NOW);
109108
#else
@@ -124,9 +123,6 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
124123
goto cleanup;
125124
}
126125

127-
// clear any old error message not fetched
128-
dlerror();
129-
130126
#ifdef DEBUG
131127
C_GetInterfaceList = (CK_C_GetInterfaceList) dlsym(hModule,
132128
"C_GetInterfaceList");
@@ -158,47 +154,42 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
158154
}
159155
#endif
160156

161-
if (jGetFunctionList != NULL) {
157+
// if none specified, then we try 3.0 API first before trying 2.40
158+
if (jGetFunctionList == NULL) {
159+
C_GetInterface = (CK_C_GetInterface) dlsym(hModule, "C_GetInterface");
160+
if (C_GetInterface != NULL) {
161+
TRACE0("Connect: Found C_GetInterface func\n");
162+
rv = (C_GetInterface)(NULL, NULL, &interface, 0L);
163+
// don't use ckAssertReturnValueOK as we want to continue trying
164+
// C_GetFunctionList() or method named by "getFunctionListStr"
165+
if (rv == CKR_OK) {
166+
goto setModuleData;
167+
}
168+
}
169+
getFunctionListStr = "C_GetFunctionList";
170+
} else {
162171
getFunctionListStr = (*env)->GetStringUTFChars(env,
163172
jGetFunctionList, 0);
164173
if (getFunctionListStr == NULL) {
165174
goto cleanup;
166175
}
167-
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
176+
}
177+
178+
dlerror(); // clear any old error message not fetched
179+
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
168180
getFunctionListStr);
181+
if (C_GetFunctionList == NULL) {
169182
if ((systemErrorMessage = dlerror()) != NULL){
183+
TRACE2("Connect: error finding %s func: %s\n", getFunctionListStr,
184+
systemErrorMessage);
170185
p11ThrowIOException(env, systemErrorMessage);
171-
goto cleanup;
172-
}
173-
if (C_GetFunctionList == NULL) {
186+
} else {
174187
TRACE1("Connect: No %s func\n", getFunctionListStr);
175188
p11ThrowIOException(env, "ERROR: C_GetFunctionList == NULL");
176-
goto cleanup;
177189
}
178-
TRACE1("Connect: Found %s func\n", getFunctionListStr);
179-
} else {
180-
// if none specified, then we try 3.0 API first before trying 2.40
181-
C_GetInterface = (CK_C_GetInterface) dlsym(hModule, "C_GetInterface");
182-
if ((C_GetInterface != NULL) && (dlerror() == NULL)) {
183-
TRACE0("Connect: Found C_GetInterface func\n");
184-
rv = (C_GetInterface)(NULL, NULL, &interface, 0L);
185-
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
186-
goto setModuleData;
187-
}
188-
}
189-
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
190-
"C_GetFunctionList");
191-
if ((systemErrorMessage = dlerror()) != NULL){
192-
p11ThrowIOException(env, systemErrorMessage);
193-
goto cleanup;
194-
}
195-
if (C_GetFunctionList == NULL) {
196-
TRACE0("Connect: No C_GetFunctionList func\n");
197-
p11ThrowIOException(env, "ERROR: C_GetFunctionList == NULL");
198-
goto cleanup;
199-
}
200-
TRACE0("Connect: Found C_GetFunctionList func\n");
190+
goto cleanup;
201191
}
192+
TRACE1("Connect: Found %s func\n", getFunctionListStr);
202193

203194
setModuleData:
204195
/*

0 commit comments

Comments
 (0)