Esempio n. 1
0
/**
 * gck_password_get_module:
 * @self: the password object
 *
 * Get the PKCS\#11 module that is requesting the password.
 *
 * Returns: (transfer full): the module that is requesting the password, which
 *          must be unreferenced after use
 */
GckModule *
gck_password_get_module (GckPassword *self)
{
	g_return_val_if_fail (GCK_IS_PASSWORD (self), NULL);
	if (self->pv->for_token)
		return gck_slot_get_module (self->pv->token_or_key);
	else
		return gck_object_get_module (self->pv->token_or_key);
}
Esempio n. 2
0
static void
gck_slot_get_property (GObject *obj, guint prop_id, GValue *value,
                       GParamSpec *pspec)
{
	GckSlot *self = GCK_SLOT (obj);

	switch (prop_id) {
	case PROP_MODULE:
		g_value_take_object (value, gck_slot_get_module (self));
		break;
	case PROP_HANDLE:
		g_value_set_ulong (value, gck_slot_get_handle (self));
		break;
	}
}
Esempio n. 3
0
static GckSession*
make_session_object (GckSlot *self, guint options, CK_SESSION_HANDLE handle)
{
	GckSession *session;
	GckModule *module;

	g_return_val_if_fail (handle != 0, NULL);

	module = gck_slot_get_module (self);

	session = gck_session_from_handle (self, handle, options);
	g_return_val_if_fail (session != NULL, NULL);

	g_object_unref (module);

	return session;
}
Esempio n. 4
0
/**
 * gck_slot_open_session_full:
 * @self: The slot to open a session on.
 * @options: The options to open the new session with.
 * @pkcs11_flags: Additional raw PKCS#11 flags.
 * @app_data: Application data for notification callback.
 * @notify: PKCS#11 notification callback.
 * @cancellable: Optional cancellation object, or NULL.
 * @err: A location to return an error, or NULL.
 *
 * Open a session on the slot. If the 'auto reuse' setting is set,
 * then this may be a recycled session with the same flags.
 *
 * This call may block for an indefinite period.
 *
 * Return value: A new session or NULL if an error occurs.
 **/
GckSession*
gck_slot_open_session_full (GckSlot *self, guint options, gulong pkcs11_flags, gpointer app_data,
                            CK_NOTIFY notify, GCancellable *cancellable, GError **err)
{
	OpenSession args = { GCK_ARGUMENTS_INIT, 0,  };
	GckSession *session = NULL;
	GckModule *module = NULL;
	CK_SLOT_ID slot_id;

	g_object_ref (self);

	/* Try to use a cached session */
	module = gck_slot_get_module (self);
	slot_id = gck_slot_get_handle (self);

	/* Open a new session */
	args.slot = self;
	args.app_data = app_data;
	args.notify = notify;
	args.password = NULL;
	args.session = 0;

	args.auto_login = ((options & GCK_SESSION_LOGIN_USER) == GCK_SESSION_LOGIN_USER);

	args.flags = pkcs11_flags | CKF_SERIAL_SESSION;
	if ((options & GCK_SESSION_READ_WRITE) == GCK_SESSION_READ_WRITE)
		args.flags |= CKF_RW_SESSION;

	if (_gck_call_sync (self, perform_open_session, complete_open_session, &args, cancellable, err))
		session = make_session_object (self, options, args.session);

	g_object_unref (module);
	g_object_unref (self);

	return session;
}
Esempio n. 5
0
static gboolean
complete_open_session (OpenSession *args, CK_RV result)
{
	GckModule *module;
	gboolean ret = TRUE;

	g_free (args->password);
	args->password = NULL;

	/* Ask the token for a password */
	module = gck_slot_get_module (args->slot);

	if (args->auto_login && result == CKR_PIN_INCORRECT) {

		ret = _gck_module_fire_authenticate_slot (module, args->slot, NULL, &args->password);

		/* If authenticate returns TRUE then call is not complete */
		ret = !ret;
	}

	g_object_unref (module);

	return ret;
}