Skip to content

Commit

Permalink
8328785: IOException: Symbol not found: C_GetInterface for PKCS11 int…
Browse files Browse the repository at this point in the history
…erface prior to V3.0

Reviewed-by: djelinski, weijun
  • Loading branch information
Valerie Peng committed Apr 9, 2024
1 parent 316361b commit 6276789
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions src/jdk.crypto.cryptoki/unix/native/libj2pkcs11/p11_md.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
*/

/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
Expand Down Expand Up @@ -103,7 +103,6 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
/*
* Load the PKCS #11 DLL
*/
dlerror(); /* clear any old error message not fetched */
#ifdef DEBUG
hModule = dlopen(libraryNameStr, RTLD_NOW);
#else
Expand All @@ -124,9 +123,6 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
goto cleanup;
}

// clear any old error message not fetched
dlerror();

#ifdef DEBUG
C_GetInterfaceList = (CK_C_GetInterfaceList) dlsym(hModule,
"C_GetInterfaceList");
Expand Down Expand Up @@ -158,47 +154,42 @@ JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_connect
}
#endif

if (jGetFunctionList != NULL) {
// if none specified, then we try 3.0 API first before trying 2.40
if (jGetFunctionList == NULL) {
C_GetInterface = (CK_C_GetInterface) dlsym(hModule, "C_GetInterface");
if (C_GetInterface != NULL) {
TRACE0("Connect: Found C_GetInterface func\n");
rv = (C_GetInterface)(NULL, NULL, &interface, 0L);
// don't use ckAssertReturnValueOK as we want to continue trying
// C_GetFunctionList() or method named by "getFunctionListStr"
if (rv == CKR_OK) {
goto setModuleData;
}
}
getFunctionListStr = "C_GetFunctionList";
} else {
getFunctionListStr = (*env)->GetStringUTFChars(env,
jGetFunctionList, 0);
if (getFunctionListStr == NULL) {
goto cleanup;
}
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
}

dlerror(); // clear any old error message not fetched
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
getFunctionListStr);
if (C_GetFunctionList == NULL) {
if ((systemErrorMessage = dlerror()) != NULL){
TRACE2("Connect: error finding %s func: %s\n", getFunctionListStr,
systemErrorMessage);
p11ThrowIOException(env, systemErrorMessage);
goto cleanup;
}
if (C_GetFunctionList == NULL) {
} else {
TRACE1("Connect: No %s func\n", getFunctionListStr);
p11ThrowIOException(env, "ERROR: C_GetFunctionList == NULL");
goto cleanup;
}
TRACE1("Connect: Found %s func\n", getFunctionListStr);
} else {
// if none specified, then we try 3.0 API first before trying 2.40
C_GetInterface = (CK_C_GetInterface) dlsym(hModule, "C_GetInterface");
if ((C_GetInterface != NULL) && (dlerror() == NULL)) {
TRACE0("Connect: Found C_GetInterface func\n");
rv = (C_GetInterface)(NULL, NULL, &interface, 0L);
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
goto setModuleData;
}
}
C_GetFunctionList = (CK_C_GetFunctionList) dlsym(hModule,
"C_GetFunctionList");
if ((systemErrorMessage = dlerror()) != NULL){
p11ThrowIOException(env, systemErrorMessage);
goto cleanup;
}
if (C_GetFunctionList == NULL) {
TRACE0("Connect: No C_GetFunctionList func\n");
p11ThrowIOException(env, "ERROR: C_GetFunctionList == NULL");
goto cleanup;
}
TRACE0("Connect: Found C_GetFunctionList func\n");
goto cleanup;
}
TRACE1("Connect: Found %s func\n", getFunctionListStr);

setModuleData:
/*
Expand Down

3 comments on commit 6276789

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 6276789 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheRealMDoerr the backport was successfully created on the branch backport-TheRealMDoerr-6276789f in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 6276789f from the openjdk/jdk repository.

The commit being backported was authored by Valerie Peng on 9 Apr 2024 and was reviewed by Daniel Jeliński and Weijun Wang.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-6276789f:backport-TheRealMDoerr-6276789f
$ git checkout backport-TheRealMDoerr-6276789f
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-6276789f

Please sign in to comment.