Skip to content
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

C_FindObjects: init list to reload new objects #789

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions src/lib/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,6 @@ CK_RV db_get_tokens(token *tok, size_t *len) {
goto error;
}

rc = init_tobjects(t);
if (rc != SQLITE_OK) {
goto error;
}

/* token initialized, bump cnt */
cnt++;
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ CK_RV db_update_token_config(token *tok);

CK_RV db_update_tobject_attrs(unsigned id, attr_list *attrs);

WEAK int init_tobjects(token *tok);

/* Debug testing */
#ifdef TESTING
#include <stdio.h>
Expand All @@ -83,7 +85,6 @@ int get_blob(sqlite3_stmt *stmt, int i, twist *blob);
tobject *db_tobject_new(sqlite3_stmt *stmt);
tobject *__real_db_tobject_new(sqlite3_stmt *stmt);
int init_pobject_v3_from_stmt(sqlite3_stmt *stmt, pobject_v3 *old_pobj);
int init_tobjects(token *tok);
int __real_init_tobjects(token *tok);
CK_RV convert_pobject_v3_to_v4(pobject_v3 *old_pobj, pobject_v4 *new_pobj);
CK_RV db_add_pobject_v4(sqlite3 *updb, pobject_v4 *new_pobj);
Expand Down
7 changes: 7 additions & 0 deletions src/lib/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ CK_RV object_find_init(session_ctx *ctx, CK_ATTRIBUTE_PTR templ, CK_ULONG count)
token *tok = session_ctx_get_token(ctx);
assert(tok);

session_ctx_delete_tobject_list(ctx);

int rc = init_tobjects(tok);
if (rc != SQLITE_OK) {
goto out;
}

if (!tok->tobjects.head) {
LOGV("Token %i contains no objects.", tok->id);
goto empty;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/session_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ void session_ctx_opdata_clear(session_ctx *ctx) {
session_ctx_opdata_set(ctx, operation_none, NULL, NULL, NULL);
}

void session_ctx_delete_tobject_list(session_ctx *ctx)
{
token_delete_tobject_list(ctx->tok);
}

static bool is_user(CK_USER_TYPE user) {
return user == CKU_USER || user == CKU_CONTEXT_SPECIFIC;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/session_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,6 @@ CK_RV session_ctx_get_info(session_ctx *ctx, CK_SESSION_INFO *info);
*/
CK_RV session_ctx_tobject_authenticated(session_ctx *ctx);

void session_ctx_delete_tobject_list(session_ctx *ctx);

#endif /* SRC_PKCS11_SESSION_CTX_H_ */
20 changes: 20 additions & 0 deletions src/lib/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ void token_free_list(token **tok_ptr, size_t *ptr_len) {
free(t);
}

void token_delete_tobject_list(token *tok)
{
if (tok->tobjects.head) {
list *cur = &tok->tobjects.head->l;
while(cur) {
tobject *tobj = list_entry(cur, tobject, l);
cur = cur->next;
if (tobj->tpm_handle) {
bool result = tpm_flushcontext(tok->tctx, tobj->tpm_handle);
assert(result);
UNUSED(result);
tobj->tpm_handle = 0;
}

tobject_free(tobj);
}
tok->tobjects.head = tok->tobjects.tail = NULL;
}
}

WEAK CK_RV token_add_tobject_last(token *tok, tobject *t) {

if (!tok->tobjects.tail) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ CK_RV token_init(token *t, CK_BYTE_PTR pin, CK_ULONG pin_len, CK_BYTE_PTR label)

void pobject_config_free(pobject_config *c);

void token_delete_tobject_list(token *tok);

#endif /* SRC_TOKEN_H_ */
Loading