Skip to content

Commit 5face3f

Browse files
committed
Improved test + build (copilot's review)
1 parent a85dfde commit 5face3f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

test-app/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ if(BUILD_TEST_APPS)
205205
endif()
206206

207207
if(WOLFCRYPT_TZ_PKCS11)
208-
list(APPEND TEST_APP_COMPILE_DEFINITIONS WOLFBOOT_PKCS11_APP SECURE_PKCS11 WOLFPKCS11_USER_SETTINGS)
208+
list(APPEND TEST_APP_COMPILE_DEFINITIONS
209+
WOLFBOOT_PKCS11_APP
210+
SECURE_PKCS11
211+
WOLFBOOT_TZ_PKCS11
212+
WOLFPKCS11_USER_SETTINGS)
209213
if(PKCS11_TESTAPP)
210214
list(APPEND TEST_APP_COMPILE_DEFINITIONS WOLFBOOT_PKCS11_TESTAPP)
211215
endif()

test-app/test_pkcs11.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ static int test_pkcs11_open_user_session(CK_SESSION_HANDLE *session)
242242
{
243243
CK_RV rv;
244244

245+
*session = CK_INVALID_HANDLE;
246+
245247
rv = wolfpkcs11nsFunctionList.C_OpenSession(TEST_PKCS11_SLOT_ID,
246248
CKF_SERIAL_SESSION | CKF_RW_SESSION, NULL, NULL, session);
247249
if (test_pkcs11_ck_ok("C_OpenSession(USER)", rv) < 0)
@@ -254,11 +256,13 @@ static int test_pkcs11_open_user_session(CK_SESSION_HANDLE *session)
254256

255257
if (rv == CKR_USER_PIN_NOT_INITIALIZED) {
256258
(void)wolfpkcs11nsFunctionList.C_CloseSession(*session);
259+
*session = CK_INVALID_HANDLE;
257260
return -2;
258261
}
259262

260263
test_pkcs11_dump_rv("C_Login(USER)", rv);
261264
(void)wolfpkcs11nsFunctionList.C_CloseSession(*session);
265+
*session = CK_INVALID_HANDLE;
262266
return -1;
263267
}
264268

@@ -398,6 +402,7 @@ static int test_pkcs11_load_blob(CK_SESSION_HANDLE session,
398402
CK_OBJECT_HANDLE data_obj, struct test_pkcs11_blob *blob)
399403
{
400404
CK_ULONG len = sizeof(*blob);
405+
CK_ULONG expected_len;
401406
int ret;
402407

403408
ret = test_pkcs11_get_attr(session, data_obj, CKA_VALUE, (CK_BYTE *)blob, &len);
@@ -412,6 +417,11 @@ static int test_pkcs11_load_blob(CK_SESSION_HANDLE session,
412417
blob->payload_len + blob->sig_len > sizeof(blob->data))
413418
return -1;
414419

420+
expected_len = (CK_ULONG)(sizeof(*blob) - sizeof(blob->data) +
421+
blob->payload_len + blob->sig_len);
422+
if (len < expected_len)
423+
return -1;
424+
415425
printf("pkcs11: restored blob payload_len=%lu sig_len=%lu\r\n",
416426
(unsigned long)blob->payload_len, (unsigned long)blob->sig_len);
417427
test_pkcs11_log_blob_checksum(blob, "restored");

0 commit comments

Comments
 (0)