Skip to content

xtest: pkcs11: add tests for indestructible token objects#803

Open
sahesaha wants to merge 1 commit intoOP-TEE:masterfrom
sahesaha:add-new-pkcs11-tests-Indestrcutible-object
Open

xtest: pkcs11: add tests for indestructible token objects#803
sahesaha wants to merge 1 commit intoOP-TEE:masterfrom
sahesaha:add-new-pkcs11-tests-Indestrcutible-object

Conversation

@sahesaha
Copy link

@sahesaha sahesaha commented Nov 3, 2025

Add test cases that validate CKA_INDESTRUCTIBLE behavior:

  • A session object with CKA_INDESTRUCTIBLE=CK_TRUE and CKA_TOKEN=CK_FALSE is rejected with CKR_TEMPLATE_INCONSISTENT.
  • Token objects marked CKA_INDESTRUCTIBLE cannot be destroyed.

Tested on: SM7325 SoC

Reviewed-by: Neeraj Soni neersoni@qti.qualcomm.com
Signed-off-by: Saheli Saha sahesaha@qti.qualcomm.com

Add test cases that validate CKA_INDESTRUCTIBLE behavior:
- A session object with CKA_INDESTRUCTIBLE=CK_TRUE and CKA_TOKEN=CK_FALSE
  is rejected with CKR_TEMPLATE_INCONSISTENT.
- Token objects marked CKA_INDESTRUCTIBLE cannot be destroyed.

Tested on: SM7325 SoC

Reviewed-by: Neeraj Soni <neersoni@qti.qualcomm.com>
Signed-off-by: Saheli Saha <sahesaha@qti.qualcomm.com>
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Dec 4, 2025
@sahesaha
Copy link
Author

sahesaha commented Dec 8, 2025

Commenting to keep alive.

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note that you can always re-open a closed pull request at any time.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Thanks for the test sequences related to indestructible objects.
The issue is that once such objects are created, they're never destroyed and the pkcs11 TA persistent database would continuously grow. That said, it's nice for testing purpose only when it's easy to wipe the persistent database. I would suggest to add a config switch (e.g. CFG_PKCS11_TA_TEST_INDESTRUCTIBLE_OBJECT_ATTR=y|n) so we can leverage these tests on Qemu (emulated persistent secure storage) and maybe other platforms where one can deal with such forced database destruction.

Comment on lines +10224 to +10228
rv = C_CreateObject(session, cktest_destructible_token,
ARRAY_SIZE(cktest_destructible_token),
&obj_hdl2);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto end;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these lines? the destrcutible object is create right below, after C_DestroyObject(session, obj_hdl) call.

goto end;

/* Indestructible object is accessible */
rv = C_GetObjectSize(session, obj_hdl, &obj_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Once the sessions are closed (even if token is NOT re-initialized), the object handles should no more be valid. You should still be able to find the object, do not access its handle.

/*
* This test involves creating multiple token keys with both
* indestructible and destructible objects, and checking
* the uniqueness of key handles.
Copy link
Contributor

Choose a reason for hiding this comment

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

Objects being destructible or not, handles of created objects are always different. I don't think this test is useful.

/*
* Creating object with incorrect template
* (CKA_TOKEN is false but CKA_INDESTRUCTIBLE is true)
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you fix the indentation?

if (!ADBG_EXPECT_CK_RESULT(c, CKR_TEMPLATE_INCONSISTENT, rv))
goto end;

rv = C_GetObjectSize(session, obj_hdl, &obj_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a programming error to use obj_hdl when previous call to C_CreateObject() failed. The PKCS#11 API does not say the generated object handle needs to be set the CK_INVALID_ID or whatever when such C_CreateObject()/C_CopyOject()/C_DeriveKey()/... fail.

goto end;

/* Indestructible object is accessible */
rv = C_GetObjectSize(session, obj_hdl, &obj_size2);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should search the object first (use C_FindObjects*() functions), not reuse obj_hdl that is bound to a session.
(I need to verify this assertion).

{ CKA_CLASS, &(CK_OBJECT_CLASS){CKO_SECRET_KEY},
sizeof(CK_OBJECT_CLASS) },
{ CKA_KEY_TYPE, &(CK_KEY_TYPE){CKK_AES}, sizeof(CK_KEY_TYPE) },
{ CKA_KEY_TYPE, &(CK_KEY_TYPE) { CKK_AES }, sizeof(CK_KEY_TYPE) },
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to discard this change.
(or change also all other equivalent occurrences, preferably in a dedicated commit)

Copy link
Author

Choose a reason for hiding this comment

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

Hi @etienne-lms, this was shown as an error when I ran the checkpatch for this PR. hence fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants