/**
 * gp11_slot_open_session_full:
 * @self: The slot to open a session on.
 * @flags: The flags to open a session with.
 * @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.
 **/
GP11Session*
gp11_slot_open_session_full (GP11Slot *self, gulong flags, gpointer app_data,
                             CK_NOTIFY notify, GCancellable *cancellable, GError **err)
{
	GP11Session *session = NULL;
	GP11Module *module = NULL;
	CK_SESSION_HANDLE handle;
	CK_SLOT_ID slot_id;

	flags |= CKF_SERIAL_SESSION;
	
	g_object_ref (self);
	
	/* Try to use a cached session */
	module = gp11_slot_get_module (self);
	slot_id = gp11_slot_get_handle (self);
	handle = _gp11_module_pooled_session_handle (module, slot_id, flags);
	if (handle != 0) 
		session = make_session_object (self, flags, handle);

	/* Open a new session */
	if (session == NULL) {
		OpenSession args = { GP11_ARGUMENTS_INIT, 0,  };
		
		args.slot = self;
		args.flags = flags;
		args.app_data = app_data;
		args.notify = notify;
		args.password = NULL;
		args.auto_login = (gp11_module_get_auto_authenticate (module) & GP11_AUTHENTICATE_TOKENS) ? TRUE : FALSE;
		args.session = 0;
		
		if (_gp11_call_sync (self, perform_open_session, complete_open_session, &args, cancellable, err))
			session = make_session_object (self, flags, args.session);
	}

	g_object_unref (module);
	g_object_unref (self);
	
	return session;
}
Example #2
0
/**
 * gck_slot_open_session_finish:
 * @self: The slot to open a session on.
 * @result: The result passed to the callback.
 * @err: A location to return an error or NULL.
 *
 * Get the result of an open session operation. If the 'auto reuse' setting is set,
 * then this may be a recycled session with the same flags.
 *
 * Return value: The new session or NULL if an error occurs.
 */
GckSession*
gck_slot_open_session_finish (GckSlot *self, GAsyncResult *result, GError **err)
{
	GckSession *session = NULL;

	g_object_ref (self);

	{
		OpenSession *args;

		if (_gck_call_basic_finish (result, err)) {
			args = _gck_call_arguments (result, OpenSession);
			session = make_session_object (self, args->flags, args->session);
		}
	}

	g_object_unref (self);

	return session;
}
Example #3
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;
}