예제 #1
0
/* create slots associated with a reader, called whenever a reader is seen. */
CK_RV initialize_reader(sc_reader_t *reader)
{
	unsigned int i;
	CK_RV rv;

	scconf_block *conf_block = NULL;
	const scconf_list *list = NULL;

	conf_block = sc_get_conf_block(context, "pkcs11", NULL, 1);
	if (conf_block != NULL) {
		list = scconf_find_list(conf_block, "ignored_readers");
		while (list != NULL) {
			if (strstr(reader->name, list->data) != NULL) {
				sc_debug(context, SC_LOG_DEBUG_NORMAL, "Ignoring reader \'%s\' because of \'%s\'\n", reader->name, list->data);
				return CKR_OK;
			}
			list = list->next;
		}
	}

	for (i = 0; i < sc_pkcs11_conf.slots_per_card; i++) {
		rv = create_slot(reader);
		if (rv != CKR_OK)
			return rv;
	}

	if (sc_detect_card_presence(reader)) {
		card_detect(reader);
	}

	return CKR_OK;
}
예제 #2
0
int
create_chunk(ldt_record *lrecord)
{
	lrecord->chunk   = cf_malloc(sizeof(ldt_slot_chunk));
	if (!lrecord->chunk) {
		return -1;
	}
	lrecord->chunk[0].slots = create_slot();
	if (lrecord->chunk[0].slots == NULL) {
		cf_free(lrecord->chunk);
		return -1;
	}

	for(int j = 0; j < LDT_SLOT_CHUNK_SIZE; j++) {
		lrecord->chunk[0].slots[j].inuse = false;
	}

	return 0;
}
예제 #3
0
MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);
    setFixedSize(this->width(), this->height());
    move((QApplication::desktop()->width()-this->width())/2, (QApplication::desktop()->height()-this->height())/2);
    this->setWindowTitle(tr("Ö÷½çÃæ"));
    m_wgt_create = new CreateWidget;
    m_wgt_import = new ImportWidget;
    m_wgt_query = new QueryWidget;

    connect(ui->m_btn_import, SIGNAL(clicked()), this, SLOT(import_slot()));
    connect(ui->m_btn_query, SIGNAL(clicked()), this, SLOT(query_slot()));
    connect(ui->m_btn_create, SIGNAL(clicked()), this, SLOT(create_slot()));
    connect(m_wgt_create, SIGNAL(back_sig(QWidget*)), this, SLOT(back_slot(QWidget*)));
    connect(m_wgt_import, SIGNAL(back_sig(QWidget*)), this, SLOT(back_slot(QWidget*)));
    connect(m_wgt_query, SIGNAL(back_sig(QWidget*)), this, SLOT(back_slot(QWidget*)));
}
예제 #4
0
파일: slot.c 프로젝트: llogar/OpenSC
/* create slots associated with a reader, called whenever a reader is seen. */
CK_RV initialize_reader(sc_reader_t *reader)
{
	unsigned int i;
	CK_RV rv;

	for (i = 0; i < sc_pkcs11_conf.slots_per_card; i++) {
		rv = create_slot(reader);
		if (rv != CKR_OK)
			return rv;
	}

	sc_log(context, "Initialize reader '%s': detect SC card presence", reader->name);
	if (sc_detect_card_presence(reader))   {
		sc_log(context, "Initialize reader '%s': detect PKCS11 card presence", reader->name);
		card_detect(reader);
	}

	sc_log(context, "Reader '%s' initialized", reader->name);
	return CKR_OK;
}
예제 #5
0
int
expand_chunk(ldt_record *lrecord)
{
	uint64_t   new_size  = lrecord->max_chunks + 1;
	void *old_chunk      = lrecord->chunk;

	if (lrecord->max_chunks) {
		lrecord->chunk = cf_realloc(lrecord->chunk, sizeof(ldt_slot_chunk) * new_size);
	} else {
		lrecord->chunk = cf_malloc(sizeof(ldt_slot_chunk) * new_size);
	}

	if (lrecord->chunk == NULL) {
		cf_warning(AS_LDT, "expand_chunk: Allocation Error !! [Chunk cannot be allocated ]... Fail");
		lrecord->chunk = old_chunk;
		return -1;
	}

	lrecord->chunk[lrecord->max_chunks].slots = create_slot();
	if (lrecord->chunk[lrecord->max_chunks].slots == NULL) {
		cf_warning(AS_LDT, "expand_chunk: Allocation Error !! [Slot cannot be allocated ]... Fail");
		cf_free(lrecord->chunk);
		lrecord->chunk = old_chunk;
		return -1;
	}

	for (int i = lrecord->max_chunks; i < new_size; i++) {
		for(int j = 0; j < LDT_SLOT_CHUNK_SIZE; j++) {
			lrecord->chunk[i].slots[j].inuse = false;
		}
	}

	cf_detail(AS_LDT, "Bumping up chunks from %"PRIu64" to %"PRIu64"", lrecord->max_chunks, new_size);
	lrecord->max_chunks = new_size;
	return 0;
}
예제 #6
0
CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
{
	CK_RV rv;
#if !defined(_WIN32)
	pid_t current_pid = getpid();
#endif
	int rc;
	unsigned int i;
	sc_context_param_t ctx_opts;

#if !defined(_WIN32)
	/* Handle fork() exception */
	if (current_pid != initialized_pid) {
		if (context)
			context->flags |= SC_CTX_FLAG_TERMINATE;
		C_Finalize(NULL_PTR);
	}
	initialized_pid = current_pid;
	in_finalize = 0;
#endif

	if (context != NULL) {
		sc_log(context, "C_Initialize(): Cryptoki already initialized\n");
		return CKR_CRYPTOKI_ALREADY_INITIALIZED;
	}

	rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs);
	if (rv != CKR_OK)
		goto out;

	/* set context options */
	memset(&ctx_opts, 0, sizeof(sc_context_param_t));
	ctx_opts.ver        = 0;
	ctx_opts.app_name   = MODULE_APP_NAME;
	ctx_opts.thread_ctx = &sc_thread_ctx;

	rc = sc_context_create(&context, &ctx_opts);
	if (rc != SC_SUCCESS) {
		rv = CKR_GENERAL_ERROR;
		goto out;
	}

	/* Load configuration */
	load_pkcs11_parameters(&sc_pkcs11_conf, context);

	/* List of sessions */
	list_init(&sessions);
	list_attributes_seeker(&sessions, session_list_seeker);

	/* List of slots */
	list_init(&virtual_slots);
	list_attributes_seeker(&virtual_slots, slot_list_seeker);

	/* Create a slot for a future "PnP" stuff. */
	if (sc_pkcs11_conf.plug_and_play) {
		create_slot(NULL);
	}

	/* Create slots for readers found on initialization, only if in 2.11 mode */
	if (!sc_pkcs11_conf.plug_and_play) {
		for (i=0; i<sc_ctx_get_reader_count(context); i++) {
			initialize_reader(sc_ctx_get_reader(context, i));
		}
	}

out:
	if (context != NULL)
		sc_log(context, "C_Initialize() = %s", lookup_enum ( RV_T, rv ));

	if (rv != CKR_OK) {
		if (context != NULL) {
			sc_release_context(context);
			context = NULL;
		}
		/* Release and destroy the mutex */
		sc_pkcs11_free_lock();
	}

	return rv;
}
예제 #7
0
CK_RV C_Initialize(CK_VOID_PTR pInitArgs)
{
	CK_RV rv;
#if !defined(_WIN32)
	pid_t current_pid = getpid();
#endif
	int rc;
	unsigned int i;
	sc_context_param_t ctx_opts;

	/* Handle fork() exception */
#if !defined(_WIN32)
	if (current_pid != initialized_pid) {
		C_Finalize(NULL_PTR);
	}
	initialized_pid = current_pid;
	in_finalize = 0;
#endif

	if (context != NULL) {
		sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_Initialize(): Cryptoki already initialized\n");
		return CKR_CRYPTOKI_ALREADY_INITIALIZED;
	}

	rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs);
	if (rv != CKR_OK)
		goto out;

	/* set context options */
	memset(&ctx_opts, 0, sizeof(sc_context_param_t));
	ctx_opts.ver        = 0;
	ctx_opts.app_name   = "opensc-pkcs11";
	ctx_opts.thread_ctx = &sc_thread_ctx;
	
	rc = sc_context_create(&context, &ctx_opts);
	if (rc != SC_SUCCESS) {
		rv = CKR_GENERAL_ERROR;
		goto out;
	}

	/* Load configuration */
	load_pkcs11_parameters(&sc_pkcs11_conf, context);

	/* List of sessions */
	list_init(&sessions);
	list_attributes_seeker(&sessions, session_list_seeker);
	
	/* List of slots */
	list_init(&virtual_slots);
	list_attributes_seeker(&virtual_slots, slot_list_seeker);
	
	/* Create a slot for a future "PnP" stuff. */
	if (sc_pkcs11_conf.plug_and_play) {
		create_slot(NULL);
	}
	/* Create slots for readers found on initialization */
	for (i=0; i<sc_ctx_get_reader_count(context); i++) {
		initialize_reader(sc_ctx_get_reader(context, i));
	}

	/* Set initial event state on slots */
	for (i=0; i<list_size(&virtual_slots); i++) {
		sc_pkcs11_slot_t *slot = (sc_pkcs11_slot_t *) list_get_at(&virtual_slots, i);
		slot->events = 0; /* Initially there are no events */
	}

out:	
	if (context != NULL)
		sc_debug(context, SC_LOG_DEBUG_NORMAL, "C_Initialize() = %s", lookup_enum ( RV_T, rv ));

	if (rv != CKR_OK) {
		if (context != NULL) {
			sc_release_context(context);
			context = NULL;
		}
		/* Release and destroy the mutex */
		sc_pkcs11_free_lock();
	}

	return rv;
}
예제 #8
0
void *do_set_create( dict *d, epoch *e, void *key, void *val, create_type type, set_spec *spec ) {
    usref *new_usref = NULL;
    if ( spec->usref ) {
        dev_assert( type != CREATE_XTRN );
        dev_assert( type != CREATE_SREF );
        new_usref = spec->usref;
    }
    else {
        xtrn *new_xtrn = NULL;
        if ( val || type == CREATE_XTRN ) {
            dev_assert( val );
            new_xtrn = create_xtrn( d, val );
            if ( !new_xtrn ) return NULL;
        }

        if ( type == CREATE_XTRN ) return new_xtrn;

        trigger_ref *trig = NULL;
        if ( spec->trigger ) {
            trig = malloc( sizeof( trigger_ref ));
            if ( trig == NULL ) {
                if( new_xtrn ) dispose( d, (trash *)new_xtrn );
                return NULL;
            }

            xtrn *arg = create_xtrn( d, spec->trigger_arg );
            if ( !arg ) {
                free( trig );
                if( new_xtrn ) dispose( d, (trash *)new_xtrn );
                return NULL;
            }

            trig->function = spec->trigger;
            trig->arg      = arg;
        }

        sref *new_sref = create_sref( new_xtrn, trig );
        if( !new_sref ) {
            if ( trig ) free( trig );
            if( new_xtrn ) dispose( d, (trash *)new_xtrn );
            return NULL;
        }
        if ( type == CREATE_SREF ) {
            new_sref->refcount = 1;
            return new_sref;
        }

        new_usref = create_usref( new_sref );
        if( !new_usref ) {
            dispose( d, (trash *)new_sref );
            return NULL;
        }
    }

    xtrn *new_xtrn_key = create_xtrn( d, key );
    if ( !new_xtrn_key ) {
        dispose( d, (trash *)new_usref );
        return NULL;
    }

    node *new_node = create_node( new_xtrn_key, new_usref, 0 );
    if ( !new_node ) {
        dispose( d, (trash *)new_usref );
        dispose( d, (trash *)new_xtrn_key );
        return NULL;
    }
    if ( type == CREATE_NODE ) return new_node;

    slot *new_slot = create_slot( new_node );
    if ( !new_slot ) {
        dispose( d, (trash *)new_node );
        return NULL;
    }
    return new_slot;
}