diff options
-rw-r--r-- | src/libstrongswan/plugins/pkcs11/pkcs11_manager.c | 16 | ||||
-rw-r--r-- | src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c | 14 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c index 204a9545b..8ff63fd4a 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_manager.c @@ -137,7 +137,7 @@ static void handle_token(lib_entry_t *entry, CK_SLOT_ID slot) /** * Handle slot changes */ -static void handle_slot(lib_entry_t *entry, CK_SLOT_ID slot) +static void handle_slot(lib_entry_t *entry, CK_SLOT_ID slot, bool hot) { CK_SLOT_INFO info; CK_RV rv; @@ -155,13 +155,19 @@ static void handle_slot(lib_entry_t *entry, CK_SLOT_ID slot) DBG1(DBG_CFG, " found token in slot '%s':%lu (%s)", entry->lib->get_name(entry->lib), slot, info.slotDescription); handle_token(entry, slot); - entry->this->cb(entry->this->data, entry->lib, slot, TRUE); + if (hot) + { + entry->this->cb(entry->this->data, entry->lib, slot, TRUE); + } } else { DBG1(DBG_CFG, "token removed from slot '%s':%lu (%s)", entry->lib->get_name(entry->lib), slot, info.slotDescription); - entry->this->cb(entry->this->data, entry->lib, slot, FALSE); + if (hot) + { + entry->this->cb(entry->this->data, entry->lib, slot, FALSE); + } } } @@ -191,7 +197,7 @@ static job_requeue_t dispatch_slot_events(lib_entry_t *entry) { DBG1(DBG_CFG, "error in C_WaitForSlotEvent: %N", ck_rv_names, rv); } - handle_slot(entry, slot); + handle_slot(entry, slot, TRUE); return JOB_REQUEUE_DIRECT; } @@ -249,7 +255,7 @@ static void query_slots(lib_entry_t *entry) { for (i = 0; i < count; i++) { - handle_slot(entry, slots[i]); + handle_slot(entry, slots[i], FALSE); } free(slots); } diff --git a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c index 68e3076e2..40970b3d1 100644 --- a/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c +++ b/src/libstrongswan/plugins/pkcs11/pkcs11_plugin.c @@ -126,6 +126,9 @@ METHOD(plugin_t, destroy, void, plugin_t *pkcs11_plugin_create() { private_pkcs11_plugin_t *this; + enumerator_t *enumerator; + pkcs11_library_t *p11; + CK_SLOT_ID slot; INIT(this, .public.plugin.destroy = _destroy, @@ -133,6 +136,8 @@ plugin_t *pkcs11_plugin_create() .mutex = mutex_create(MUTEX_TYPE_DEFAULT), ); + this->manager = pkcs11_manager_create((void*)token_event_cb, this); + if (lib->settings->get_bool(lib->settings, "libstrongswan.plugins.pkcs11.use_hasher", FALSE)) { @@ -150,10 +155,15 @@ plugin_t *pkcs11_plugin_create() (hasher_constructor_t)pkcs11_hasher_create); } - this->manager = pkcs11_manager_create((void*)token_event_cb, this); - lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ANY, (builder_function_t)pkcs11_private_key_connect); + enumerator = this->manager->create_token_enumerator(this->manager); + while (enumerator->enumerate(enumerator, &p11, &slot)) + { + token_event_cb(this, p11, slot, TRUE); + } + enumerator->destroy(enumerator); + return &this->public.plugin; } |