Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ static void cache_key(P11PROV_OBJ *obj)
CK_BBOOL val_false = CK_FALSE;
CK_ATTRIBUTE template[] = { { CKA_TOKEN, &val_false, sizeof(val_false) } };
CK_SESSION_HANDLE sess;
CK_OBJECT_HANDLE obj_handle;
CK_BBOOL can_cache = CK_TRUE;
CK_RV ret;
int cache_keys;
Expand All @@ -388,6 +389,12 @@ static void cache_key(P11PROV_OBJ *obj)
return;
}

obj_handle = p11prov_obj_get_handle(obj);
if (obj_handle == 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please us CK_INVALID_HANDLE here.

P11PROV_debug("Skip caching key with zero object handle");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

zero -> invalid

return;
}

ret = p11prov_take_login_session(obj->ctx, obj->slotid, &session);
if (ret != CKR_OK || session == NULL) {
P11PROV_debug("Failed to get login session. Error %lx", ret);
Expand All @@ -398,8 +405,8 @@ static void cache_key(P11PROV_OBJ *obj)
destroy_key_cache(obj, session);

sess = p11prov_session_handle(session);
ret = p11prov_CopyObject(obj->ctx, sess, p11prov_obj_get_handle(obj),
template, 1, &obj->cached);
ret = p11prov_CopyObject(obj->ctx, sess, obj_handle, template, 1,
&obj->cached);
if (ret != CKR_OK) {
P11PROV_raise(obj->ctx, ret, "Failed to cache key");
if (ret == CKR_FUNCTION_NOT_SUPPORTED) {
Expand Down