Skip to content

Commit 633edab

Browse files
Fix TPM corruption test workflow for old version compatibility
Changes requested by user: 1. Remove C_Finalize and unload_library calls from corruption test - These could cause metadata to fix itself upon closing - Use _exit(0) instead to avoid cleanup handlers 2. Update both test programs to use C_GetSlotList instead of hardcoded slot 1 - More robust and portable across different CI environments 3. Update access_test expectations to properly handle migration - Treat CKR_USER_PIN_NOT_INITIALIZED (0x00000102) as migration bug - Provide clear error messages distinguishing migration vs corruption issues - Expect login to succeed after proper migration is implemented These changes prepare the workflow for the upcoming migration/repair function that will detect old-format tokens and set WP11_TOKEN_STATE_INITIALIZED flag. Co-Authored-By: [email protected] <[email protected]>
1 parent 764222c commit 633edab

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

.github/workflows/tpm-corruption-test.yml

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
#include <stdlib.h>
9797
#include <string.h>
9898
#include <dlfcn.h>
99+
#include <unistd.h>
99100
100101
#define CK_PTR *
101102
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
@@ -178,6 +179,9 @@ jobs:
178179
CK_RV rv;
179180
CK_SESSION_HANDLE session;
180181
CK_BYTE userPin[] = "wolfpkcs11-test";
182+
CK_SLOT_ID slotList[16];
183+
CK_ULONG slotCount = sizeof(slotList) / sizeof(slotList[0]);
184+
CK_SLOT_ID slot;
181185
int i, created = 0;
182186
const char* lib_path = argv[1];
183187
@@ -190,7 +194,20 @@ jobs:
190194
return 1;
191195
}
192196
193-
rv = funcList->C_OpenSession(1, CKF_SERIAL_SESSION | CKF_RW_SESSION,
197+
/* Get available slots */
198+
rv = funcList->C_GetSlotList(CK_TRUE, slotList, &slotCount);
199+
if (rv != CKR_OK) {
200+
printf("ERROR: C_GetSlotList failed with 0x%08lx\n", (unsigned long)rv);
201+
return 1;
202+
}
203+
if (slotCount == 0) {
204+
printf("ERROR: No slots available\n");
205+
return 1;
206+
}
207+
slot = slotList[0];
208+
printf("Using slot %lu\n", (unsigned long)slot);
209+
210+
rv = funcList->C_OpenSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION,
194211
NULL, NULL, &session);
195212
if (rv != CKR_OK) {
196213
printf("ERROR: C_OpenSession failed with 0x%08lx\n", (unsigned long)rv);
@@ -218,10 +235,10 @@ jobs:
218235
219236
printf("Successfully created %d AES keys\n", created);
220237
221-
funcList->C_Finalize(NULL);
222-
unload_library();
223-
224-
return 0;
238+
/* Do NOT call C_Finalize or unload_library - this could cause
239+
* metadata to fix itself upon closing. Use _exit to avoid any
240+
* cleanup handlers that might "heal" the corrupted state. */
241+
_exit(0);
225242
}
226243
EOF
227244
@@ -334,6 +351,9 @@ jobs:
334351
CK_OBJECT_HANDLE objects[1000];
335352
CK_ULONG count = 0;
336353
CK_BBOOL ckTrue = CK_TRUE;
354+
CK_SLOT_ID slotList[16];
355+
CK_ULONG slotCount = sizeof(slotList) / sizeof(slotList[0]);
356+
CK_SLOT_ID slot;
337357
const char* lib_path = argv[1];
338358
339359
printf("Testing access to corrupted TPM state with PR version...\n");
@@ -348,8 +368,22 @@ jobs:
348368
}
349369
printf("C_Initialize succeeded\n");
350370
371+
/* Get available slots */
372+
printf("Getting slot list...\n");
373+
rv = funcList->C_GetSlotList(CK_TRUE, slotList, &slotCount);
374+
if (rv != CKR_OK) {
375+
printf("ERROR: C_GetSlotList failed with 0x%08lx\n", (unsigned long)rv);
376+
return 1;
377+
}
378+
if (slotCount == 0) {
379+
printf("ERROR: No slots available\n");
380+
return 1;
381+
}
382+
slot = slotList[0];
383+
printf("Using slot %lu\n", (unsigned long)slot);
384+
351385
printf("Attempting C_OpenSession...\n");
352-
rv = funcList->C_OpenSession(1, CKF_SERIAL_SESSION | CKF_RW_SESSION,
386+
rv = funcList->C_OpenSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION,
353387
NULL, NULL, &session);
354388
if (rv != CKR_OK) {
355389
printf("CORRUPTION DETECTED: C_OpenSession failed with 0x%08lx\n", (unsigned long)rv);
@@ -360,11 +394,16 @@ jobs:
360394
printf("Attempting C_Login...\n");
361395
rv = funcList->C_Login(session, CKU_USER, userPin, sizeof(userPin) - 1);
362396
if (rv != CKR_OK) {
363-
printf("CORRUPTION DETECTED: C_Login failed with 0x%08lx\n", (unsigned long)rv);
364-
printf("This is the expected corruption behavior - login fails after TPM corruption\n");
397+
printf("ERROR: C_Login failed with 0x%08lx\n", (unsigned long)rv);
398+
if (rv == 0x00000102) { /* CKR_USER_PIN_NOT_INITIALIZED / PIN_NOT_SET_E */
399+
printf("MIGRATION BUG: Token state not properly migrated from old version\n");
400+
printf("The PR version needs to detect old-format tokens and set WP11_TOKEN_STATE_INITIALIZED\n");
401+
} else {
402+
printf("CORRUPTION DETECTED: Unexpected login failure\n");
403+
}
365404
return 1;
366405
}
367-
printf("C_Login succeeded\n");
406+
printf("C_Login succeeded (migration handled correctly)\n");
368407
369408
printf("Attempting C_FindObjectsInit...\n");
370409
CK_ATTRIBUTE findTemplate[] = {

0 commit comments

Comments
 (0)