Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/eng_back.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ ENGINE_CTX *ENGINE_CTX_new()
return NULL;
memset(ctx, 0, sizeof(ENGINE_CTX));
ctx->util_ctx = UTIL_CTX_new();
if (!ctx->util_ctx)
if (!ctx->util_ctx) {
OPENSSL_free(ctx);
return NULL;
}
pthread_mutex_init(&ctx->lock, 0);

mod = getenv("PKCS11_MODULE_PATH");
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int UTIL_CTX_ctrl_set_user_interface(UTIL_CTX *ctx, UI_METHOD *ui_method);
int UTIL_CTX_ctrl_set_callback_data(UTIL_CTX *ctx, void *callback_data);
int UTIL_CTX_enumerate_slots(UTIL_CTX *ctx);
int UTIL_CTX_init_libp11(UTIL_CTX *ctx);
int UTIL_CTX_free_libp11(UTIL_CTX *ctx);
void UTIL_CTX_free_libp11(UTIL_CTX *ctx);

void UTIL_CTX_set_vlog_a(UTIL_CTX *ctx, PKCS11_VLOG_A_CB vlog);
void UTIL_CTX_set_debug_level(UTIL_CTX *ctx, int debug_level);
Expand Down
37 changes: 23 additions & 14 deletions src/util_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int UTIL_CTX_init_libp11(UTIL_CTX *ctx)
if (ctx->pkcs11_ctx && ctx->slot_list)
return 0;

UTIL_CTX_log(ctx, LOG_NOTICE, "PKCS#11: Initializing the engine: %s\n", ctx->module);
UTIL_CTX_log(ctx, LOG_NOTICE, "PKCS#11: Initializing the module: %s\n", ctx->module);

pkcs11_ctx = PKCS11_CTX_new();
PKCS11_set_vlog_a_method(pkcs11_ctx, ctx->vlog);
Expand All @@ -164,7 +164,7 @@ int UTIL_CTX_init_libp11(UTIL_CTX *ctx)
return ctx->pkcs11_ctx && ctx->slot_list ? 0 : -1;
}

int UTIL_CTX_free_libp11(UTIL_CTX *ctx)
void UTIL_CTX_free_libp11(UTIL_CTX *ctx)
{
if (ctx->slot_list) {
PKCS11_release_all_slots(ctx->pkcs11_ctx,
Expand Down Expand Up @@ -230,7 +230,8 @@ void UTIL_CTX_log(UTIL_CTX *ctx, int level, const char *format, ...)

static char *dump_hex(unsigned char *val, const size_t len)
{
int i, j = 0, size = 2 * len + 1;
int j = 0;
size_t i, size = 2 * len + 1;
char *hexbuf = OPENSSL_malloc((size_t)size);

if (!hexbuf)
Expand Down Expand Up @@ -921,8 +922,8 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
}
UTIL_CTX_log(ctx, LOG_NOTICE, "- [%lu] %-25.25s %-36s (%s)\n",
PKCS11_get_slotid_from_slot(slot),
slot->description, flags,
slot->token->label[0] ? slot->token->label : "no label");
slot->description ? slot->description : "(no description)",
flags, slot->token->label[0] ? slot->token->label : "no label");

/* Ignore slots without tokens. Thales HSM (and potentially
* other modules) allow objects on uninitialized tokens. */
Expand Down Expand Up @@ -967,10 +968,12 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
if (matched_count == 1) {
slot = matched_slots[0];
if (!slot->token) {
UTIL_CTX_log(ctx, LOG_ERR, "Empty slot found: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_ERR, "Empty slot found: %s\n",
slot->description ? slot->description : "(no description)");
goto cleanup; /* failed */
}
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n",
slot->description ? slot->description : "(no description)");
UTIL_CTX_log(ctx, LOG_NOTICE, "Found token: %s\n", slot->token->label[0]?
slot->token->label : "no label");

Expand Down Expand Up @@ -1002,7 +1005,8 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
for (m = 0; m < matched_count; m++) {
slot = matched_slots[m];
if (!slot->token) {
UTIL_CTX_log(ctx, LOG_INFO, "Empty slot found: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_INFO, "Empty slot found: %s\n",
slot->description ? slot->description : "(no description)");
continue; /* skipped */
}
if (slot->token->initialized) {
Expand All @@ -1017,7 +1021,8 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
/* Initialized tokens */
if (init_count == 1) {
slot = init_slots[0];
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n",
slot->description ? slot->description : "(no description)");
UTIL_CTX_log(ctx, LOG_NOTICE, "Found token: %s\n", slot->token->label[0]?
slot->token->label : "no label");

Expand All @@ -1030,6 +1035,8 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
goto cleanup; /* failed */
}
}
free(init_slots);
free(uninit_slots);
} else {
/* Multiple slots with initialized token */
if (init_count > 1) {
Expand All @@ -1039,8 +1046,7 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
for (m = 0; m < init_count; m++) {
slot = init_slots[m];
UTIL_CTX_log(ctx, LOG_WARNING, "- [%u] %s: %s\n", m + 1,
slot->description? slot->description:
"(no description)",
slot->description ? slot->description : "(no description)",
(slot->token && slot->token->label)?
slot->token->label: "no label");
}
Expand All @@ -1049,7 +1055,8 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
/* Uninitialized tokens, user PIN is unset */
for (m = 0; m < uninit_count; m++) {
slot = uninit_slots[m];
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n",
slot->description ? slot->description : "(no description)");
UTIL_CTX_log(ctx, LOG_NOTICE, "Found token: %s\n", slot->token->label[0]?
slot->token->label : "no label");
object = match_func(ctx, slot->token, obj_id, obj_id_len, obj_label);
Expand All @@ -1069,10 +1076,12 @@ static void *ctx_try_load_object(UTIL_CTX *ctx,
for (n = 0; n < matched_count; n++) {
slot = matched_slots[n];
if (!slot->token) {
UTIL_CTX_log(ctx, LOG_INFO, "Empty slot found: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_INFO, "Empty slot found: %s\n",
slot->description ? slot->description : "(no description)");
break;
}
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n", slot->description);
UTIL_CTX_log(ctx, LOG_NOTICE, "Found slot: %s\n",
slot->description ? slot->description : "(no description)");
UTIL_CTX_log(ctx, LOG_NOTICE, "Found token: %s\n", slot->token->label[0]?
slot->token->label : "no label");
object = match_func(ctx, slot->token, obj_id, obj_id_len, obj_label);
Expand Down
Loading