@@ -24,11 +24,12 @@ jobs:
2424 ref : v1.3.0-stable
2525 path : wolfpkcs11-1.3.0
2626
27- # Setup wolfSSL for v1.3.0
27+ # Setup wolfSSL (pinned to v5.8.2-stable for compatibility)
2828 - name : Checkout wolfSSL
2929 uses : actions/checkout@v4
3030 with :
3131 repository : wolfssl/wolfssl
32+ ref : v5.8.2-stable
3233 path : wolfssl
3334
3435 - name : Build wolfSSL
@@ -49,13 +50,147 @@ jobs:
4950 ./configure --enable-debug CFLAGS="-DDEBUG_WOLFPKCS11"
5051 make
5152
53+ # Create inline token initialization program
54+ - name : Create token initialization program
55+ run : |
56+ cat > init_token.c << 'EOF'
57+ #define _GNU_SOURCE
58+ #include <stdio.h>
59+ #include <stdlib.h>
60+ #include <string.h>
61+ #include <dlfcn.h>
62+
63+ #define CK_PTR *
64+ #define CK_DEFINE_FUNCTION(returnType, name) returnType name
65+ #define CK_DECLARE_FUNCTION(returnType, name) returnType name
66+ #define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
67+ #define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
68+ #ifndef NULL_PTR
69+ #define NULL_PTR 0
70+ #endif
71+
72+ #include "wolfpkcs11-1.3.0/wolfpkcs11/pkcs11.h"
73+
74+ static CK_FUNCTION_LIST* funcList = NULL;
75+ static void* libHandle = NULL;
76+
77+ int load_library(const char* path) {
78+ CK_RV rv;
79+ CK_C_GetFunctionList pC_GetFunctionList;
80+
81+ libHandle = dlopen(path, RTLD_NOW | RTLD_LOCAL);
82+ if (!libHandle) {
83+ printf("ERROR: Failed to load library: %s\n", dlerror());
84+ return -1;
85+ }
86+
87+ pC_GetFunctionList = (CK_C_GetFunctionList)dlsym(libHandle, "C_GetFunctionList");
88+ if (!pC_GetFunctionList) {
89+ printf("ERROR: Failed to get C_GetFunctionList: %s\n", dlerror());
90+ dlclose(libHandle);
91+ return -1;
92+ }
93+
94+ rv = pC_GetFunctionList(&funcList);
95+ if (rv != CKR_OK) {
96+ printf("ERROR: C_GetFunctionList failed with 0x%08lx\n", (unsigned long)rv);
97+ dlclose(libHandle);
98+ return -1;
99+ }
100+
101+ return 0;
102+ }
103+
104+ int main(int argc, char* argv[]) {
105+ CK_RV rv;
106+ CK_SESSION_HANDLE session;
107+ CK_BYTE soPin[] = "test-so-pin-12345";
108+ CK_BYTE userPin[] = "test-pin-12345";
109+ CK_BYTE label[32];
110+ CK_SLOT_ID slotList[16];
111+ CK_ULONG slotCount = sizeof(slotList) / sizeof(slotList[0]);
112+ CK_SLOT_ID slot;
113+ const char* lib_path = argv[1];
114+
115+ /* Pad label to 32 bytes with spaces */
116+ memset(label, ' ', sizeof(label));
117+ memcpy(label, "wolfPKCS11 Test", 15);
118+
119+ printf("=== Initializing token in v1.3.0 ===\n");
120+ printf("Loading library: %s\n", lib_path);
121+ if (load_library(lib_path) != 0) return 1;
122+
123+ rv = funcList->C_Initialize(NULL);
124+ if (rv != CKR_OK) {
125+ printf("ERROR: C_Initialize failed with 0x%08lx\n", (unsigned long)rv);
126+ return 1;
127+ }
128+
129+ /* Get slot list (use CK_FALSE to get slots even if no token present) */
130+ rv = funcList->C_GetSlotList(CK_FALSE, slotList, &slotCount);
131+ if (rv != CKR_OK || slotCount == 0) {
132+ printf("ERROR: C_GetSlotList failed or no slots\n");
133+ return 1;
134+ }
135+ slot = slotList[0];
136+ printf("Using slot %lu\n", (unsigned long)slot);
137+
138+ /* Initialize token and set SO PIN */
139+ printf("Calling C_InitToken...\n");
140+ rv = funcList->C_InitToken(slot, soPin, sizeof(soPin) - 1, label);
141+ if (rv != CKR_OK) {
142+ printf("ERROR: C_InitToken failed with 0x%08lx\n", (unsigned long)rv);
143+ return 1;
144+ }
145+ printf("✓ Token initialized with SO PIN\n");
146+
147+ /* Open RW session */
148+ rv = funcList->C_OpenSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION,
149+ NULL, NULL, &session);
150+ if (rv != CKR_OK) {
151+ printf("ERROR: C_OpenSession failed with 0x%08lx\n", (unsigned long)rv);
152+ return 1;
153+ }
154+
155+ /* Login as SO */
156+ printf("Logging in as SO...\n");
157+ rv = funcList->C_Login(session, CKU_SO, soPin, sizeof(soPin) - 1);
158+ if (rv != CKR_OK) {
159+ printf("ERROR: C_Login(SO) failed with 0x%08lx\n", (unsigned long)rv);
160+ return 1;
161+ }
162+ printf("✓ Logged in as SO\n");
163+
164+ /* Set initial user PIN */
165+ printf("Setting user PIN...\n");
166+ rv = funcList->C_InitPIN(session, userPin, sizeof(userPin) - 1);
167+ if (rv != CKR_OK) {
168+ printf("ERROR: C_InitPIN failed with 0x%08lx\n", (unsigned long)rv);
169+ return 1;
170+ }
171+ printf("✓ User PIN set\n");
172+
173+ /* Cleanup */
174+ funcList->C_Logout(session);
175+ funcList->C_CloseSession(session);
176+ funcList->C_Finalize(NULL);
177+
178+ printf("=== Token initialization complete ===\n");
179+ return 0;
180+ }
181+ EOF
182+
183+ - name : Compile token initialization program
184+ run : |
185+ gcc -o init_token init_token.c -I./wolfpkcs11-1.3.0 -ldl -lpthread
186+
52187 # Initialize token with PIN in v1.3.0
53188 - name : Initialize token with PIN (v1.3.0)
54- working-directory : ./wolfpkcs11-1.3.0
189+ env :
190+ WOLFPKCS11_TOKEN_PATH : ${{ github.workspace }}/.wolfPKCS11_upgrade_test
55191 run : |
56- export WOLFPKCS11_TOKEN_PATH="${HOME}/.wolfPKCS11_upgrade_test"
57192 mkdir -p "${WOLFPKCS11_TOKEN_PATH}"
58- ./examples/ init_token -userPin "test-pin-12345"
193+ ./init_token ./wolfpkcs11-1.3.0/src/.libs/libwolfpkcs11.so
59194 echo "Token initialized with PIN in v1.3.0"
60195 echo "Token path: ${WOLFPKCS11_TOKEN_PATH}"
61196 ls -la "${WOLFPKCS11_TOKEN_PATH}"
@@ -182,8 +317,9 @@ jobs:
182317 gcc -o verify_pin_1.3.0 verify_pin_1.3.0.c -I./wolfpkcs11-1.3.0 -ldl -lpthread
183318
184319 - name : Run v1.3.0 PIN verification test
320+ env :
321+ WOLFPKCS11_TOKEN_PATH : ${{ github.workspace }}/.wolfPKCS11_upgrade_test
185322 run : |
186- export WOLFPKCS11_TOKEN_PATH="${HOME}/.wolfPKCS11_upgrade_test"
187323 ./verify_pin_1.3.0 ./wolfpkcs11-1.3.0/src/.libs/libwolfpkcs11.so
188324
189325 # Build PR version of wolfPKCS11
@@ -311,10 +447,15 @@ jobs:
311447 printf("BUG DETECTED: WP11_TOKEN_FLAG_USER_PIN_SET not set after upgrade\n");
312448 printf("The token was created in v1.3.0 with a PIN, but v2.0.0+ doesn't detect it\n");
313449 printf("This is the bug we're testing for!\n");
450+ funcList->C_CloseSession(session);
451+ funcList->C_Finalize(NULL);
452+ return 100; /* Special exit code for expected bug */
314453 } else {
315454 printf("Unexpected login failure\n");
455+ funcList->C_CloseSession(session);
456+ funcList->C_Finalize(NULL);
457+ return 1;
316458 }
317- return 1;
318459 }
319460
320461 printf("✓ Successfully logged in with PIN in v2.0.0+\n");
@@ -335,11 +476,14 @@ jobs:
335476
336477 # Test accessing token with PR version
337478 - name : Test PIN flag after upgrade to v2.0.0+
479+ env :
480+ WOLFPKCS11_TOKEN_PATH : ${{ github.workspace }}/.wolfPKCS11_upgrade_test
338481 run : |
339- export WOLFPKCS11_TOKEN_PATH="${HOME}/.wolfPKCS11_upgrade_test"
340482 echo "Testing with token path: ${WOLFPKCS11_TOKEN_PATH}"
341483 ls -la "${WOLFPKCS11_TOKEN_PATH}"
342- ./verify_pin_2.0.0 ./wolfpkcs11-pr/src/.libs/libwolfpkcs11.so || {
484+ ./verify_pin_2.0.0 ./wolfpkcs11-pr/src/.libs/libwolfpkcs11.so
485+ EXIT_CODE=$?
486+ if [ $EXIT_CODE -eq 100 ]; then
343487 echo ""
344488 echo "=========================================="
345489 echo "BUG CONFIRMED: PIN flag not set after upgrade"
@@ -350,7 +494,16 @@ jobs:
350494 echo ""
351495 echo "This test successfully reproduces the issue."
352496 exit 1
353- }
497+ elif [ $EXIT_CODE -ne 0 ]; then
498+ echo ""
499+ echo "=========================================="
500+ echo "WORKFLOW ERROR: Unexpected failure"
501+ echo "=========================================="
502+ echo "The test failed with exit code $EXIT_CODE, which indicates"
503+ echo "a workflow or setup error, not the expected bug."
504+ echo "Please check the logs above for details."
505+ exit 1
506+ fi
354507
355508 - name : Test summary
356509 if : always()
0 commit comments