Пример #1
0
/*
 * Helper functions
 */
static int pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id)
{
	PKCS11_SLOT_private *priv;
	CK_SLOT_INFO info;
	int rv;

	rv = CRYPTOKI_call(ctx, C_GetSlotInfo(id, &info));
	CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv);

	priv = OPENSSL_malloc(sizeof(PKCS11_SLOT_private));
	if (priv == NULL)
		return -1;
	memset(priv, 0, sizeof(PKCS11_SLOT_private));

	priv->parent = ctx;
	priv->id = id;
	priv->forkid = PRIVCTX(ctx)->forkid;
	priv->prev_rw = 0;
	priv->prev_pin = NULL;
	priv->prev_so = 0;
	priv->lockid = CRYPTO_get_new_dynlockid();

	slot->description = PKCS11_DUP(info.slotDescription);
	slot->manufacturer = PKCS11_DUP(info.manufacturerID);
	slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0;
	slot->_private = priv;

	if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot))
		return -1;

	return 0;
}
Пример #2
0
ENGINE_CTX *pkcs11_new()
{
	ENGINE_CTX *ctx;
	char *mod;

	ctx = OPENSSL_malloc(sizeof(ENGINE_CTX));
	if (ctx == NULL)
		return NULL;
	memset(ctx, 0, sizeof(ENGINE_CTX));

	mod = getenv("PKCS11_MODULE_PATH");
	if (mod) {
		ctx->module = OPENSSL_strdup(mod);
	} else {
#ifdef DEFAULT_PKCS11_MODULE
		ctx->module = OPENSSL_strdup(DEFAULT_PKCS11_MODULE);
#else
		ctx->module = NULL;
#endif
	}

#if OPENSSL_VERSION_NUMBER >= 0x10100004L
	ctx->rwlock = CRYPTO_THREAD_lock_new();
#else
	ctx->rwlock = CRYPTO_get_dynlock_create_callback() ?
		CRYPTO_get_new_dynlockid() : 0;
#endif

	return ctx;
}
Пример #3
0
int sthreads_init(void) {
    int i;

    /* initialize OpenSSL dynamic locks callbacks */
    CRYPTO_set_dynlock_create_callback(dyn_create_function);
    CRYPTO_set_dynlock_lock_callback(dyn_lock_function);
    CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function);

    /* initialize stunnel critical sections */
    for(i=0; i<STUNNEL_LOCKS; i++)
        stunnel_locks[i]=CRYPTO_get_new_dynlockid();

    /* initialize OpenSSL locking callback */
    lock_cs=str_alloc_detached(
        (size_t)CRYPTO_num_locks()*sizeof(struct CRYPTO_dynlock_value));
    for(i=0; i<CRYPTO_num_locks(); i++)
        pthread_rwlock_init(&lock_cs[i].rwlock, NULL);
#if OPENSSL_VERSION_NUMBER>=0x10000000L
    CRYPTO_THREADID_set_callback(threadid_func);
#else
    CRYPTO_set_id_callback(stunnel_thread_id);
#endif
    CRYPTO_set_locking_callback(locking_callback);

    return 0;
}
Пример #4
0
static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
	HWCryptoHook_CallerContext *cactx)
	{
	mt->lockid = CRYPTO_get_new_dynlockid();
	if (mt->lockid == 0)
		return 1; /* failure */
	return 0; /* success */
	}
Пример #5
0
int CRYPTO_THREAD_lock_new()
{
	int i;

	if (CRYPTO_get_dynlock_create_callback() == NULL ||
			CRYPTO_get_dynlock_lock_callback() == NULL ||
			CRYPTO_get_dynlock_destroy_callback() == NULL)
		return 0; /* Dynamic callbacks not set */
	i = CRYPTO_get_new_dynlockid();
	if (i == 0)
		ERR_clear_error(); /* Dynamic locks are optional -> ignore */
	return i;
}
Пример #6
0
int sthreads_init(void) {
    int i;

    /* initialize OpenSSL dynamic locks callbacks */
    CRYPTO_set_dynlock_create_callback(dyn_create_function);
    CRYPTO_set_dynlock_lock_callback(dyn_lock_function);
    CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function);

    /* initialize stunnel critical sections */
    for(i=0; i<STUNNEL_LOCKS; i++)
        stunnel_locks[i]=CRYPTO_get_new_dynlockid();

    /* initialize OpenSSL locking callback */
    lock_cs=str_alloc_detached(
        (size_t)CRYPTO_num_locks()*sizeof(struct CRYPTO_dynlock_value));
    for(i=0; i<CRYPTO_num_locks(); i++)
        InitializeCriticalSection(&lock_cs[i].mutex);
    CRYPTO_set_locking_callback(locking_callback);

    return 0;
}