Esempio n. 1
0
/*
 * Load a module - this will load the shared object, call
 * C_Initialize, and get the list of function pointers
 */
void *
C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
{
	sc_pkcs11_module_t *mod;
	CK_RV rv, (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
	mod = calloc(1, sizeof(*mod));
	mod->_magic = MAGIC;

	if (mspec == NULL) {
		free(mod);
		return NULL;
	}
	mod->handle = sc_dlopen(mspec);
	if (mod->handle == NULL) {
		fprintf(stderr, "sc_dlopen failed: %s\n", sc_dlerror());
		goto failed;
	}

	/* Get the list of function pointers */
	c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
				sc_dlsym(mod->handle, "C_GetFunctionList");
	if (!c_get_function_list)
		goto failed;
	rv = c_get_function_list(funcs);
	if (rv == CKR_OK)
		return (void *) mod;
	else
		fprintf(stderr, "C_GetFunctionList failed %lx", rv);
failed:
	C_UnloadModule((void *) mod);
	free(mod);
	return NULL;
}
/*
 * Load a module - this will load the shared object, call
 * C_Initialize, and get the list of function pointers
 */
void *
C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
{
	sc_pkcs11_module_t *mod;
	CK_RV (*c_get_function_list)(CK_FUNCTION_LIST_PTR_PTR);
	int rv;

	lt_dlinit();

	mod = (sc_pkcs11_module_t *) calloc(1, sizeof(*mod));
	mod->_magic = MAGIC;

	if (mspec == NULL)
		mspec = PKCS11_DEFAULT_MODULE_NAME;
	mod->handle = lt_dlopen(mspec);
	if (mod->handle == NULL) {
#if 0
		fprintf(stderr, "lt_dlopen failed: %s\n", lt_dlerror());
#endif
		goto failed;
	}

	/* Get the list of function pointers */
	c_get_function_list = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
				lt_dlsym(mod->handle, "C_GetFunctionList");
	if (!c_get_function_list)
		goto failed;
	rv = c_get_function_list(funcs);
	if (rv == CKR_OK)
		return (void *) mod;

failed:
	C_UnloadModule((void *) mod);
	return NULL;
}
Esempio n. 3
0
const char *
get_module_name(const char *module_path)
{
	const char *name = NULL;
	CK_FUNCTION_LIST_PTR p11 = NULL;
	void *module = C_LoadModule(module_path, &p11);
	if (module) {
		CK_INFO info;
		if (CKR_OK == p11->C_Initialize(NULL)
				&& CKR_OK == p11->C_GetInfo(&info)) {
			static char module_name[32+sizeof " (255.255)"];
			int libraryDescription_len = 32;

			while (libraryDescription_len > 0
					&& info.libraryDescription[libraryDescription_len-1] == ' ')
				libraryDescription_len--;

			snprintf(module_name, sizeof module_name,
					"%.*s (%d.%d)",
					libraryDescription_len, info.libraryDescription,
					info.libraryVersion.major, info.libraryVersion.minor);

			name = module_name;
		}
		p11->C_Finalize(NULL);
		C_UnloadModule(module);
	}
	return name;
}
Esempio n. 4
0
/*
 * Unload the shared library
 */
void PKCS11_CTX_unload(PKCS11_CTX * ctx)
{
    PKCS11_CTX_private *priv;
    priv = PRIVCTX(ctx);

    /* Tell the PKCS11 library to shut down */
    priv->method->C_Finalize(NULL);

    /* Unload the module */
    C_UnloadModule(handle);
}
Esempio n. 5
0
/*
 * Unload the shared library
 */
void pkcs11_CTX_unload(PKCS11_CTX * ctx)
{
	PKCS11_CTX_private *cpriv;
	cpriv = PRIVCTX(ctx);

	/* Tell the PKCS11 library to shut down */
	if (cpriv->forkid == _P11_get_forkid())
		cpriv->method->C_Finalize(NULL);

	/* Unload the module */
	C_UnloadModule(cpriv->handle);
}