Skip to content

pkcs11: test context authentication and PIN lockout - #853

Merged
jenswikl merged 2 commits into
OP-TEE:masterfrom
mu-sec:fix/pkcs11-context-login
Dec 1, 2026
Merged

jenswikl merged 2 commits into
OP-TEE:masterfrom
mu-sec:fix/pkcs11-context-login

Conversation

@mu-sec

@mu-sec mu-sec commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Add context-login tests for correct and incorrect PINs, retry on an active
operation, isolation between operations and sessions, and ordinary-key
behavior. Verify successful signatures with the public key.

Also test that context PIN lockout makes both sessions public and
terminates their active operations. Restore the test token and PIN after
each case, including failure paths. Keep the existing no-active-operation
check in case 1003 unchanged.

Requires the companion OS fix: OP-TEE/optee_os#8172.
Validation: AArch64 QEMU using OS f54190f22611, client
da81fb7b3078 and test baseline 179740b43809. Case 1031 fails on
the original TA; the patched default-level suite passes all 33 cases
and 5856 subtests.

Assisted by AI.

@jenswikl

jenswikl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@etienne-lms, @Emantor?

@etienne-lms etienne-lms left a comment

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.

Thanks for the test. LGTM with suggestions.

Could you update the commit message header line, like the below?

-pkcs11: test context authentication and PIN lockout
+xtest: pkcs11: test context authentication and PIN lockout

Comment thread host/xtest/pkcs11_1000.c Outdated
if (!ADBG_EXPECT_CK_OK(c, rv))
goto out;

Do_ADBG_Log("Ordinary key");

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.

Suggestion: use Do_ADBG_BeginSubCase(c, ...)/Do_ADBG_EndSubCase(c, ...) to enhance separation of the test cases.

Comment thread host/xtest/pkcs11_1000.c Outdated
Comment on lines +10257 to +10258
(CKF_USER_PIN_LOCKED | CKF_USER_PIN_FINAL_TRY |
CKF_USER_PIN_COUNT_LOW))))

@etienne-lms etienne-lms Nov 5, 2026 •

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 indent to the opening parenthesis to ease readibility?

Suggested change
(CKF_USER_PIN_LOCKED | CKF_USER_PIN_FINAL_TRY |
CKF_USER_PIN_COUNT_LOW))))
(CKF_USER_PIN_LOCKED | CKF_USER_PIN_FINAL_TRY |
CKF_USER_PIN_COUNT_LOW))))

Comment thread host/xtest/pkcs11_1000.c Resolved
Comment thread host/xtest/pkcs11_1000.c
cleanup_context_auth_token(c, slot, token_initialized);
rv = close_lib();
ADBG_EXPECT_CK_OK(c, rv);
}

@etienne-lms etienne-lms Nov 5, 2026 •

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 would be nice we also test CKA_ALWAYS_AUTHENTICATE against ACL_AUTH case. That would need to cover only the "Missing context login" and "Context login" sub-cases.
We can postponed that to a later P-R.

@mu-sec

mu-sec commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the detailed review, @etienne-lms .

I've split the PIN scenarios into ADBG subcases, aligned the flag checks, and added a second C_Sign() call after a rejected signature to verify CKR_OPERATION_NOT_INITIALIZED. I also included the two ACL_AUTH scenarios, reusing the existing identity setup helpers.

Validated with OP-TEE/optee_os#8172, the full default-level PKCS#11 suite passes 35 cases and 6,021 subtests on AArch64 QEMU. The new ACL test also fails as expected against the pre-context-login-fix TA.

All test commit subjects now use the requested xtest: pkcs11: prefix.

Could you please take another look when you have a chance?

@etienne-lms etienne-lms left a comment

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.

Reviewed-by: Etienne Carriere <etienne.carriere@st.com>
The pending review comments are non-blocking.

@mu-sec

mu-sec commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the Reviewed-by tag, @etienne-lms, and thank you @dachaac for testing the series on QEMU v7/v8.

All four pending review items (converting the PIN scenarios to ADBG subcases, aligning the flag parentheses, checking CKR_OPERATION_NOT_INITIALIZED on a second C_Sign() after rejection, and adding the ACL_AUTH test case 1034) have already been addressed in 5d836f8 and 0a3dda7.

I will consolidate the fixup/formatting commits and add the Reviewed-by / Tested-by trailers before force-pushing for merge.

Check context login for CKA_ALWAYS_AUTHENTICATE private keys. Cover
valid and invalid PINs, retries on an active operation, operation and
session isolation, and signing with ordinary keys. Verify signatures
with the public key and check that rejected signing ends the operation.

Check that context PIN lockout returns sessions to the public state
and terminates their operations. Use the token's final-try flag and
restore the test token after each PIN case, including failure paths.

In ACL_AUTH mode, cover rejected signing without context login and
successful signing after context login using the existing TEE identity
setup. Keep the generated keys local to the test session.

Link: OP-TEE/optee_os#8161
Signed-off-by: Yilin Li <mu_lyl@163.com>
Reviewed-by: Etienne Carriere <etienne.carriere@st.com>
Reviewed-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Tested-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Check explicit and default CKA_ALWAYS_AUTHENTICATE/CKA_PRIVATE
combinations when importing private keys and generating key pairs.
Cover attribute readback and copy inheritance. Check the existing
restrictions on changing the attributes through C_SetAttributeValue
and C_CopyObject.

Signed-off-by: Yilin Li <mu_lyl@163.com>
Reviewed-by: Etienne Carriere <etienne.carriere@st.com>
Reviewed-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
Tested-by: Vesa Jääskeläinen <vesa.jaaskelainen@vaisala.com>
@mu-sec
mu-sec force-pushed the fix/pkcs11-context-login branch from 0a3dda7 to 276eac3 Compare December 1, 2026 08:10
@jenswikl
jenswikl merged commit d0c44ab into OP-TEE:master Dec 1, 2026
2 checks passed
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