Skip to content

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

Open
sahesaha wants to merge 1 commit into
OP-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 into
OP-TEE:masterfrom
sahesaha:add-new-pkcs11-tests-Indestrcutible-object

Conversation

@sahesaha
Copy link
Copy Markdown

@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
Copy Markdown

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
Copy Markdown
Author

sahesaha commented Dec 8, 2025

Commenting to keep alive.

@jenswikl jenswikl removed the Stale label Dec 8, 2025
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Jan 8, 2026
@jenswikl jenswikl removed the Stale label Jan 8, 2026
Copy link
Copy Markdown
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 thread host/xtest/pkcs11_1000.c
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
Copy Markdown
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.

Comment thread host/xtest/pkcs11_1000.c
goto end;

/* Indestructible object is accessible */
rv = C_GetObjectSize(session, obj_hdl, &obj_size);
Copy link
Copy Markdown
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.

Comment thread host/xtest/pkcs11_1000.c
/*
* This test involves creating multiple token keys with both
* indestructible and destructible objects, and checking
* the uniqueness of key handles.
Copy link
Copy Markdown
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.

Comment thread host/xtest/pkcs11_1000.c
/*
* Creating object with incorrect template
* (CKA_TOKEN is false but CKA_INDESTRUCTIBLE is true)
*/
Copy link
Copy Markdown
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?

Comment thread host/xtest/pkcs11_1000.c
if (!ADBG_EXPECT_CK_RESULT(c, CKR_TEMPLATE_INCONSISTENT, rv))
goto end;

rv = C_GetObjectSize(session, obj_hdl, &obj_size);
Copy link
Copy Markdown
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.

Comment thread host/xtest/pkcs11_1000.c
goto end;

/* Indestructible object is accessible */
rv = C_GetObjectSize(session, obj_hdl, &obj_size2);
Copy link
Copy Markdown
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).

Comment thread host/xtest/pkcs11_1000.c
{ 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
Copy Markdown
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
Copy Markdown
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.

@sahesaha
Copy link
Copy Markdown
Author

@etienne-lms , could you suggest where and how to introduce the control flag to control the tests which I introduced for this feature?

@github-actions
Copy link
Copy Markdown

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 Mar 14, 2026
@github-actions github-actions Bot closed this Mar 19, 2026
@sahesaha
Copy link
Copy Markdown
Author

@jenswi-linaro @etienne-lms, could you please help restore the PR? Review is pending for this.

@jenswikl jenswikl reopened this Mar 19, 2026
@github-actions github-actions Bot removed the Stale label Mar 20, 2026
@github-actions
Copy link
Copy Markdown

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 Apr 19, 2026
@github-actions github-actions Bot closed this Apr 24, 2026
@sahesaha
Copy link
Copy Markdown
Author

@jenswi-linaro @etienne-lms, could you please help restore the PR and review it?

@jenswikl jenswikl reopened this Apr 24, 2026
@jenswikl jenswikl removed the Stale label Apr 24, 2026
@github-actions
Copy link
Copy Markdown

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 May 25, 2026
@sahesaha
Copy link
Copy Markdown
Author

Commenting to keep alive.

@github-actions github-actions Bot removed the Stale label May 26, 2026
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