/**
* 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;
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);
+ }
}
}
{
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;
}
{
for (i = 0; i < count; i++)
{
- handle_slot(entry, slots[i]);
+ handle_slot(entry, slots[i], FALSE);
}
free(slots);
}
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,
.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))
{
(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;
}