-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added Indestructible token objects attributes/keys feature. #7581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,9 @@ static uint8_t *pkcs11_object_default_boolprop(uint32_t attribute) | |
| case PKCS11_CKA_WRAP: | ||
| case PKCS11_CKA_UNWRAP: | ||
| case PKCS11_CKA_EXTRACTABLE: | ||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||
| case PKCS11_CKA_OPTEE_INDESTRUCTIBLE: | ||
| #endif | ||
| case PKCS11_CKA_TRUSTED: | ||
| return (uint8_t *)&bool_false; | ||
| default: | ||
|
|
@@ -1186,6 +1189,9 @@ create_attributes_from_template(struct obj_attrs **out, void *template, | |
| struct obj_attrs *attrs = NULL; | ||
| enum pkcs11_rc rc = PKCS11_CKR_OK; | ||
| uint8_t local = 0; | ||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||
| uint8_t indestructible = 0; | ||
| #endif | ||
| uint8_t always_sensitive = 0; | ||
| uint8_t never_extract = 0; | ||
| uint8_t extractable = 0; | ||
|
|
@@ -1392,6 +1398,26 @@ create_attributes_from_template(struct obj_attrs **out, void *template, | |
| if (rc) | ||
| goto out; | ||
|
|
||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||
| /* Check if CKA_INDESTRUCTIBLE exists in the template */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build break: declaration-after-statement + shadowing. |
||
| enum pkcs11_rc rc_check = get_attribute_ptr(temp, PKCS11_CKA_OPTEE_INDESTRUCTIBLE, NULL, NULL); | ||
|
|
||
| if (rc_check == PKCS11_RV_NOT_FOUND) { | ||
| DMSG("CKA_INDESTRUCTIBLE not present in template"); | ||
| } else { | ||
| /* Attribute exists, get its value (TRUE or FALSE) */ | ||
| bool indestructible = get_bool(temp, PKCS11_CKA_OPTEE_INDESTRUCTIBLE); | ||
|
|
||
| DMSG("CKA_INDESTRUCTIBLE present, value: %s", indestructible ? "TRUE" : "FALSE"); | ||
|
|
||
| /* Add attribute with the actual value from template */ | ||
| rc = add_attribute(&attrs, PKCS11_CKA_OPTEE_INDESTRUCTIBLE, | ||
| &indestructible, sizeof(indestructible)); | ||
| if (rc) | ||
| goto out; | ||
| } | ||
| #endif | ||
|
|
||
| if (get_attribute_ptr(temp, PKCS11_CKA_LOCAL, NULL, NULL) != | ||
| PKCS11_RV_NOT_FOUND) { | ||
| rc = PKCS11_CKR_TEMPLATE_INCONSISTENT; | ||
|
|
@@ -1528,6 +1554,16 @@ static enum pkcs11_rc check_attrs_misc_integrity(struct obj_attrs *head) | |
| return PKCS11_CKR_TEMPLATE_INCONSISTENT; | ||
| } | ||
|
|
||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||
| /* Only token objects can be indestructible */ | ||
| if (get_bool(head, PKCS11_CKA_OPTEE_INDESTRUCTIBLE) && | ||
| !get_bool(head, PKCS11_CKA_TOKEN)) { | ||
| DMSG("Can't create a non-token Indestructible object"); | ||
|
|
||
| return PKCS11_CKR_TEMPLATE_INCONSISTENT; | ||
| } | ||
| #endif | ||
|
|
||
| return PKCS11_CKR_OK; | ||
| } | ||
|
|
||
|
|
@@ -2337,6 +2373,10 @@ static bool attribute_is_modifiable(struct pkcs11_session *session, | |
| * direction i.e from TRUE -> FALSE. | ||
| */ | ||
| return get_bool(obj->attributes, req_attr->id); | ||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||
| case PKCS11_CKA_OPTEE_INDESTRUCTIBLE: | ||
| return false; | ||
| #endif | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -956,12 +956,29 @@ enum pkcs11_rc entry_ck_token_initialize(uint32_t ptypes, TEE_Param *params) | |||||
| while (!LIST_EMPTY(&token->object_list)) { | ||||||
| obj = LIST_FIRST(&token->object_list); | ||||||
|
|
||||||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||||||
| if (!obj->attributes) { | ||||||
| rc = load_persistent_object_attributes(obj); | ||||||
| if (rc) | ||||||
| TEE_Panic(rc); | ||||||
| } | ||||||
|
|
||||||
| if (get_bool(obj->attributes, PKCS11_CKA_OPTEE_INDESTRUCTIBLE)) { | ||||||
| // Skip deletion for indestructible objects | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| LIST_REMOVE(obj, link); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need a bit more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expectation of the implementation is that the INDETSRUCTIBLE objects should persist in the persistent_storage even after reinit. So, we need not call cleanup_volatile_obj_ref().
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the token in re-initialized, the object would still remain loaded in memory.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please confirm whether this leaks: indestructible objects are unlinked from |
||||||
| continue; | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| /* Try twice otherwise panic! */ | ||||||
| if (unregister_persistent_object(token, obj->uuid) && | ||||||
| unregister_persistent_object(token, obj->uuid)) | ||||||
| unregister_persistent_object(token, obj->uuid)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discard this change. Previous indentation was fine. |
||||||
| TEE_Panic(0); | ||||||
|
|
||||||
| cleanup_persistent_object(obj, token); | ||||||
| #if defined(CFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR) | ||||||
| token_invalidate_object_handles(obj); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I retained token_invalidate_object_handles(obj) because cleanup_persistent_object() only frees the object memory and does not invalidate the open handles associated with it as I tested some pointers were still remaining after cleanup-persistent_object() call. I was following the sequence observed in the destroy_object definition where both calls are present. |
||||||
| #endif | ||||||
| } | ||||||
|
|
||||||
| IMSG("PKCS11 token %"PRIu32": initialized", token_id); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build break: unused variable. This outer
indestructibleis never read or written — the inner block below (elsebranch) declares and uses its ownbool indestructible. With-Wunused-variableand-Werror(both on inmk/compile.mk), this fails to compile whenCFG_PKCS11_TA_INDESTRUCTIBLE_OBJECT_ATTR=y.