[gnome-keyring] Use GcrPrompt and GcrSystemPrompt for prompting
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] Use GcrPrompt and GcrSystemPrompt for prompting
- Date: Mon, 19 Dec 2011 07:52:36 +0000 (UTC)
commit 084ce5e086cd9b1ac2a64157023e192747c8cd14
Author: Stef Walter <stefw collabora co uk>
Date: Mon Oct 3 08:59:39 2011 +0200
Use GcrPrompt and GcrSystemPrompt for prompting
* This is a dbus based prompting interface recently
added to libgcr
https://bugzilla.gnome.org/show_bug.cgi?id=656954
Makefile.am | 1 -
configure.ac | 10 +-
daemon/Makefile.am | 1 -
daemon/dbus/gkd-secret-change.c | 317 ++++--
daemon/dbus/gkd-secret-change.h | 7 +-
daemon/dbus/gkd-secret-create.c | 197 ++--
daemon/dbus/gkd-secret-create.h | 2 +-
daemon/dbus/gkd-secret-error.c | 35 +-
daemon/dbus/gkd-secret-error.h | 12 +-
daemon/dbus/gkd-secret-prompt.c | 127 +-
daemon/dbus/gkd-secret-prompt.h | 24 +-
daemon/dbus/gkd-secret-service.c | 15 +-
daemon/dbus/gkd-secret-session.c | 29 +-
daemon/dbus/gkd-secret-session.h | 2 +-
daemon/dbus/gkd-secret-unlock.c | 8 +-
daemon/dbus/gkd-secret-unlock.h | 2 +-
daemon/gpg-agent/Makefile.am | 2 +-
daemon/gpg-agent/gkd-gpg-agent-ops.c | 143 +--
docs/Makefile.am | 5 +-
docs/gnome-keyring-daemon/Makefile.am | 22 -
docs/gnome-keyring-daemon/docbook-params.xsl | 39 -
.../org.gnome.keyring.Prompter.xml | 103 --
docs/tools/resolve-type.xsl | 122 --
docs/tools/spec-to-docbook.xsl | 1242 --------------------
docs/tools/spec-to-introspect.xsl | 147 ---
pkcs11/wrap-layer/Makefile.am | 3 +-
pkcs11/wrap-layer/gkm-wrap-prompt.c | 630 +++++-----
pkcs11/wrap-layer/gkm-wrap-prompt.h | 16 +-
pkcs11/wrap-layer/tests/Makefile.am | 3 +-
pkcs11/wrap-layer/tests/mock-secret-store.c | 2 -
pkcs11/wrap-layer/tests/test-create-credential.c | 22 +-
pkcs11/wrap-layer/tests/test-init-pin.c | 16 +-
pkcs11/wrap-layer/tests/test-login-auto.c | 50 +-
pkcs11/wrap-layer/tests/test-login-specific.c | 22 +-
pkcs11/wrap-layer/tests/test-login-user.c | 22 +-
pkcs11/wrap-layer/tests/test-set-pin.c | 17 +-
po/POTFILES.in | 3 -
ui/.gitignore | 2 -
ui/Makefile.am | 94 --
ui/gku-prompt-marshal.list | 1 -
ui/gku-prompt-tool.c | 1208 -------------------
ui/gku-prompt.c | 1200 -------------------
ui/gku-prompt.h | 150 ---
ui/gku-prompt.ui | 357 ------
ui/gnome-keyring-prompt.desktop.in.in | 8 -
ui/tests/Makefile.am | 3 -
ui/tests/files/prompt-create | 12 -
ui/tests/files/prompt-empty | 4 -
ui/tests/files/prompt-full | 17 -
ui/tests/files/prompt-test | 8 -
50 files changed, 1001 insertions(+), 5483 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e01be00..988d28c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,6 @@ endif
SUBDIRS = \
. \
egg \
- ui \
pkcs11 \
schema \
daemon \
diff --git a/configure.ac b/configure.ac
index fdea526..2665aa5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -197,11 +197,11 @@ fi
# GCR and GCK libraries
PKG_CHECK_MODULES(GCK, gck-1 >= 3.3.3)
-PKG_CHECK_MODULES(GCR, gcr-3 >= 3.3.1)
-PKG_CHECK_MODULES(GCR_BASE, gcr-base-3 >= 3.3.1)
+PKG_CHECK_MODULES(GCR, gcr-3 >= 3.3.3)
+PKG_CHECK_MODULES(GCR_BASE, gcr-base-3 >= 3.3.3)
DAEMON_CFLAGS="$DAEMON_CFLAGS $GCK_CFLAGS $GCR_BASE_CFLAGS"
-DAEMON_LIBS="$DAEMON_LIBS $GCK_LIBS $GCR_BASE_CFLAGS"
+DAEMON_LIBS="$DAEMON_LIBS $GCK_LIBS $GCR_BASE_LIBS"
AC_SUBST(GCK_CFLAGS)
AC_SUBST(GCR_CFLAGS)
@@ -713,7 +713,6 @@ daemon/gpg-agent/Makefile
daemon/login/Makefile
daemon/ssh-agent/Makefile
docs/Makefile
-docs/gnome-keyring-daemon/Makefile
egg/Makefile
egg/tests/Makefile
pam/Makefile
@@ -738,9 +737,6 @@ po/Makefile.in
schema/Makefile
testing/Makefile
tool/Makefile
-ui/Makefile
-ui/gnome-keyring-prompt.desktop.in
-ui/tests/Makefile
])
# ------------------------------------------------------------------------------
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 449a513..b598c5f 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -30,7 +30,6 @@ gnome_keyring_daemon_LDADD = \
$(top_builddir)/daemon/dbus/libgkd-dbus.la \
$(top_builddir)/daemon/login/libgkd-login.la \
$(top_builddir)/daemon/control/libgkd-control.la \
- $(top_builddir)/ui/libgku-prompt.la \
$(top_builddir)/daemon/ssh-agent/libgkd-ssh-agent.la \
$(top_builddir)/daemon/gpg-agent/libgkd-gpg-agent.la \
$(top_builddir)/pkcs11/wrap-layer/libgkm-wrap-layer.la \
diff --git a/daemon/dbus/gkd-secret-change.c b/daemon/dbus/gkd-secret-change.c
index bd51239..4afb489 100644
--- a/daemon/dbus/gkd-secret-change.c
+++ b/daemon/dbus/gkd-secret-change.c
@@ -37,6 +37,7 @@
#include <glib/gi18n.h>
#include <gck/gck.h>
+#include <gcr/gcr-base.h>
#include <string.h>
@@ -48,26 +49,32 @@ enum {
struct _GkdSecretChange {
GkdSecretPrompt parent;
gchar *collection_path;
+ GckSession *session;
+ GkdSecretSecret *master;
+ gboolean unlocked;
+ gboolean confirmed;
};
-G_DEFINE_TYPE (GkdSecretChange, gkd_secret_change, GKD_SECRET_TYPE_PROMPT);
+struct _GkdSecretChangeClass {
+ GkdSecretPromptClass parent_class;
+};
-/* -----------------------------------------------------------------------------
- * INTERNAL
- */
+static void perform_prompting (GkdSecretChange *self,
+ GckObject *collection);
+
+G_DEFINE_TYPE (GkdSecretChange, gkd_secret_change, GCR_TYPE_SYSTEM_PROMPT);
static void
-prepare_change_prompt (GkdSecretChange *self, GckObject *collection, gboolean first)
+setup_original_prompt (GkdSecretChange *self,
+ GckObject *collection)
{
+ GcrPrompt *prompt = GCR_PROMPT (self);
GError *error = NULL;
- GkuPrompt *prompt;
gpointer data;
gsize n_data;
gchar *label;
gchar *text;
- prompt = GKU_PROMPT (self);
-
data = gck_object_get_data (collection, CKA_LABEL, NULL, &n_data, &error);
if (!data) {
g_warning ("couldn't get label for collection: %s", egg_error_message (error));
@@ -80,89 +87,252 @@ prepare_change_prompt (GkdSecretChange *self, GckObject *collection, gboolean fi
label = g_strndup (data, n_data);
g_free (data);
- /* Hard reset on first prompt, soft thereafter */
- gku_prompt_reset (prompt, first);
-
- gku_prompt_set_title (prompt, _("Change Keyring Password"));
+ text = g_strdup_printf (_("Enter the old password for the '%s' keyring"), label);
+ gcr_prompt_set_message (prompt, text);
+ g_free (text);
- text = g_markup_printf_escaped (_("Choose a new password for the '%s' keyring"), label);
- gku_prompt_set_primary_text (prompt, text);
+ text = g_strdup_printf (_("An application wants to change the password for the '%s' keyring. "
+ "Enter the old password for it."), label);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- text = g_markup_printf_escaped (_("An application wants to change the password for the '%s' keyring. "
- "Choose the new password you want to use for it."), label);
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_password_new (prompt, FALSE);
+}
+
+static void
+setup_password_prompt (GkdSecretChange *self,
+ GckObject *collection)
+{
+ GcrPrompt *prompt = GCR_PROMPT (self);
+ GError *error = NULL;
+ gpointer data;
+ gsize n_data;
+ gchar *label;
+ gchar *text;
+
+ data = gck_object_get_data (collection, CKA_LABEL, NULL, &n_data, &error);
+ if (!data) {
+ g_warning ("couldn't get label for collection: %s", egg_error_message (error));
+ g_clear_error (&error);
+ }
+
+ if (!data || !n_data)
+ label = g_strdup (_("Unnamed"));
+ else
+ label = g_strndup (data, n_data);
+ g_free (data);
+
+ text = g_strdup_printf (_("Choose a new password for the '%s' keyring"), label);
+ gcr_prompt_set_message (prompt, text);
g_free (text);
- gku_prompt_hide_widget (prompt, "name_area");
- gku_prompt_hide_widget (prompt, "details_area");
+ text = g_strdup_printf (_("An application wants to change the password for the '%s' keyring. "
+ "Choose the new password you want to use for it."), label);
+ gcr_prompt_set_description (prompt, text);
+ g_free (text);
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "original_area");
- gku_prompt_show_widget (prompt, "confirm_area");
+ gcr_prompt_set_password_new (prompt, TRUE);
+}
- g_free (label);
+static void
+setup_confirmation_prompt (GkdSecretChange *self)
+{
+ gcr_prompt_set_message (GCR_PROMPT (self), _("Store passwords unencrypted?"));
+ gcr_prompt_set_description (GCR_PROMPT (self),
+ _("By choosing to use a blank password, your stored passwords will not be safely encrypted. "
+ "They will be accessible by anyone with access to your files."));
}
static void
set_warning_wrong (GkdSecretChange *self)
{
- g_assert (GKD_SECRET_IS_CHANGE (self));
- gku_prompt_set_warning (GKU_PROMPT (self), _("The original password was incorrect"));
+ gcr_prompt_set_warning (GCR_PROMPT (self), _("The original password was incorrect"));
}
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
static void
-gkd_secret_change_prompt_ready (GkdSecretPrompt *prompt)
+on_prompt_original_complete (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- GkdSecretChange *self = GKD_SECRET_CHANGE (prompt);
- GkdSecretSecret *original, *master;
- DBusError derr = DBUS_ERROR_INIT;
+ GkdSecretChange *self = GKD_SECRET_CHANGE (source);
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
+ GckBuilder builder = GCK_BUILDER_INIT;
+ gboolean continue_prompting = TRUE;
+ GkdSecretSecret *original;
+ GckAttributes *attrs;
+ GError *error = NULL;
GckObject *collection;
- gboolean result;
+ GckObject *cred;
+
+ gcr_prompt_password_finish (GCR_PROMPT (source), result, &error);
+ if (error != NULL) {
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
+ return;
+ }
collection = gkd_secret_prompt_lookup_collection (prompt, self->collection_path);
+ if (collection != NULL) {
+ gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_CREDENTIAL);
+ gck_builder_add_boolean (&builder, CKA_TOKEN, FALSE);
+ gck_builder_add_ulong (&builder, CKA_G_OBJECT, gck_object_get_handle (collection));
+
+ attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
+ original = gkd_secret_prompt_take_secret (prompt);
+
+ /* Create the original credential, in order to make sure we can unlock the collection */
+ cred = gkd_secret_session_create_credential (original->session,
+ self->session, attrs,
+ original, &error);
+
+ gck_attributes_unref (attrs);
+ gkd_secret_secret_free (original);
+
+ /* The unlock failed because password was bad */
+ if (g_error_matches (error, GCK_ERROR, CKR_PIN_INCORRECT)) {
+ set_warning_wrong (self);
+ g_error_free (error);
+
+ /* The unlock failed for some other reason */
+ } else if (error != NULL) {
+ continue_prompting = FALSE;
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
+
+ /* The unlock succeeded */
+ } else {
+ if (self->session == NULL)
+ self->session = gck_object_get_session (cred);
+ gck_object_destroy (cred, NULL, NULL);
+ self->unlocked = TRUE;
+ }
+ }
- /* No more prompt, just go away */
- if (collection == NULL) {
+ if (continue_prompting)
+ perform_prompting (self, collection);
+
+ g_clear_object (&cred);
+ g_clear_object (&collection);
+}
+
+static void
+on_prompt_password_complete (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GkdSecretChange *self = GKD_SECRET_CHANGE (source);
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
+ GError *error = NULL;
+ GckObject *collection;
+
+ gcr_prompt_password_finish (GCR_PROMPT (source), result, &error);
+ if (error != NULL) {
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
+ return;
+ }
+
+ self->master = gkd_secret_prompt_take_secret (prompt);
+ if (self->master == NULL) {
gkd_secret_prompt_dismiss (prompt);
return;
}
- if (!gku_prompt_has_response (GKU_PROMPT (prompt))) {
- prepare_change_prompt (self, collection, TRUE);
+ /* If the password strength is greater than zero, then don't confirm */
+ if (gcr_prompt_get_password_strength (GCR_PROMPT (source)) > 0)
+ self->confirmed = TRUE;
+
+ collection = gkd_secret_prompt_lookup_collection (prompt, self->collection_path);
+ perform_prompting (self, collection);
+ g_clear_object (&collection);
+}
+
+static void
+on_prompt_confirmation_complete (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GkdSecretChange *self = GKD_SECRET_CHANGE (source);
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
+ GError *error = NULL;
+ GckObject *collection;
+
+ self->confirmed = gcr_prompt_confirm_finish (GCR_PROMPT (source), result, &error);
+ if (error != NULL) {
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
return;
}
- original = gkd_secret_prompt_get_secret (prompt, "original");
- master = gkd_secret_prompt_get_secret (prompt, "password");
+ /* If not confirmed, then prompt again */
+ if (!self->confirmed) {
+ gkd_secret_secret_free (self->master);
+ self->master = NULL;
+ }
- result = gkd_secret_change_with_secrets (collection, original, master, &derr);
+ collection = gkd_secret_prompt_lookup_collection (prompt, self->collection_path);
+ perform_prompting (self, collection);
+ g_clear_object (&collection);
+}
- gkd_secret_secret_free (original);
- gkd_secret_secret_free (master);
+static void
+perform_prompting (GkdSecretChange *self,
+ GckObject *collection)
+{
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (self);
+ GError *error = NULL;
- /* The change succeeded, yay */
- if (result) {
- gkd_secret_prompt_complete (prompt);
+ /* Collection doesn't exist, just go away */
+ if (collection == NULL) {
+ gkd_secret_prompt_dismiss (prompt);
- /* The original password was incorrect */
- } else if (dbus_error_has_name (&derr, INTERNAL_ERROR_DENIED)) {
- prepare_change_prompt (self, collection, FALSE);
- set_warning_wrong (self);
+ /* Get the original password and unlock */
+ } else if (self->unlocked) {
+ setup_original_prompt (self, collection);
+ gcr_prompt_password_async (GCR_PROMPT (self),
+ gkd_secret_prompt_get_cancellable (prompt),
+ on_prompt_original_complete, NULL);
+
+ /* Get the new password */
+ } else if (self->master == NULL) {
+ setup_password_prompt (self, collection);
+ gcr_prompt_password_async (GCR_PROMPT (self),
+ gkd_secret_prompt_get_cancellable (prompt),
+ on_prompt_password_complete, NULL);
+
+ /* Check that the password is not empty */
+ } else if (!self->confirmed) {
+ setup_confirmation_prompt (self);
+ gcr_prompt_confirm_async (GCR_PROMPT (self),
+ gkd_secret_prompt_get_cancellable (prompt),
+ on_prompt_confirmation_complete, NULL);
+
+ /* Actually create the keyring */
+ } else if (gkd_secret_change_with_secrets (collection, self->session,
+ NULL, self->master, &error)) {
+ gkd_secret_prompt_complete (prompt);
- /* Other failures */
+ /* Failed */
} else {
- gkd_secret_prompt_dismiss (prompt);
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
}
g_object_unref (collection);
}
static void
+gkd_secret_change_prompt_ready (GkdSecretPrompt *prompt)
+{
+ GkdSecretChange *self = GKD_SECRET_CHANGE (prompt);
+ GckObject *collection;
+
+ collection = gkd_secret_prompt_lookup_collection (prompt, self->collection_path);
+ perform_prompting (self, collection);
+ g_clear_object (&collection);
+}
+
+static void
gkd_secret_change_encode_result (GkdSecretPrompt *base, DBusMessageIter *iter)
{
DBusMessageIter variant;
@@ -176,7 +346,7 @@ gkd_secret_change_encode_result (GkdSecretPrompt *base, DBusMessageIter *iter)
static void
gkd_secret_change_init (GkdSecretChange *self)
{
-
+ gcr_prompt_set_title (GCR_PROMPT (self), _("Change Keyring Password"));
}
static void
@@ -262,21 +432,28 @@ gkd_secret_change_new (GkdSecretService *service, const gchar *caller,
}
gboolean
-gkd_secret_change_with_secrets (GckObject *collection, GkdSecretSecret *original,
- GkdSecretSecret *master, DBusError *derr)
+gkd_secret_change_with_secrets (GckObject *collection,
+ GckSession *session,
+ GkdSecretSecret *original,
+ GkdSecretSecret *master,
+ GError **error)
{
GckBuilder builder = GCK_BUILDER_INIT;
- GError *error = NULL;
GckAttributes *attrs = NULL;
gboolean result = FALSE;
GckObject *ocred = NULL;
GckObject *mcred = NULL;
+ g_assert (GCK_IS_OBJECT (collection));
+ g_assert (session == NULL || GCK_IS_SESSION (session));
+ g_assert (master != NULL);
+ g_assert (error == NULL || *error == NULL);
+
/* Create the new credential */
gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_CREDENTIAL);
gck_builder_add_boolean (&builder, CKA_TOKEN, FALSE);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
- mcred = gkd_secret_session_create_credential (master->session, NULL, attrs, master, derr);
+ mcred = gkd_secret_session_create_credential (master->session, session, attrs, master, error);
if (mcred == NULL)
goto cleanup;
@@ -284,17 +461,19 @@ gkd_secret_change_with_secrets (GckObject *collection, GkdSecretSecret *original
gck_attributes_unref (attrs);
/* Create the original credential, in order to make sure we can the collection */
- gck_builder_add_ulong (&builder, CKA_G_OBJECT, gck_object_get_handle (collection));
- attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
- ocred = gkd_secret_session_create_credential (original->session, NULL, attrs, original, derr);
- if (ocred == NULL)
- goto cleanup;
+ if (original) {
+ gck_builder_add_ulong (&builder, CKA_G_OBJECT, gck_object_get_handle (collection));
+ attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
+ ocred = gkd_secret_session_create_credential (original->session, session, attrs, original, error);
+ if (ocred == NULL)
+ goto cleanup;
+ }
gck_attributes_unref (attrs);
gck_builder_add_ulong (&builder, CKA_G_CREDENTIAL, gck_object_get_handle (mcred));
/* Now set the collection credentials to the first one */
- result = gck_object_set (collection, attrs, NULL, &error);
+ result = gck_object_set (collection, attrs, NULL, error);
cleanup:
if (ocred) {
@@ -310,17 +489,5 @@ cleanup:
}
gck_attributes_unref (attrs);
-
- if (!result && error) {
- if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN))
- dbus_set_error (derr, INTERNAL_ERROR_DENIED, "The original password was invalid");
- else
- g_warning ("failure occurred while changing password: %s", egg_error_message (error));
- }
-
- if (!result && !dbus_error_is_set (derr))
- dbus_set_error (derr, DBUS_ERROR_FAILED, "Couldn't change master password");
-
- g_clear_error (&error);
return result;
}
diff --git a/daemon/dbus/gkd-secret-change.h b/daemon/dbus/gkd-secret-change.h
index 2f2daf4..73fa2f2 100644
--- a/daemon/dbus/gkd-secret-change.h
+++ b/daemon/dbus/gkd-secret-change.h
@@ -38,10 +38,6 @@
typedef struct _GkdSecretChangeClass GkdSecretChangeClass;
-struct _GkdSecretChangeClass {
- GkdSecretPromptClass parent_class;
-};
-
GType gkd_secret_change_get_type (void);
GkdSecretChange* gkd_secret_change_new (GkdSecretService *service,
@@ -49,8 +45,9 @@ GkdSecretChange* gkd_secret_change_new (GkdSecretService
const gchar *path);
gboolean gkd_secret_change_with_secrets (GckObject *collection,
+ GckSession *session,
GkdSecretSecret *original,
GkdSecretSecret *master,
- DBusError *derr);
+ GError **error);
#endif /* __GKD_SECRET_CHANGE_H__ */
diff --git a/daemon/dbus/gkd-secret-create.c b/daemon/dbus/gkd-secret-create.c
index a9c88d7..b700931 100644
--- a/daemon/dbus/gkd-secret-create.c
+++ b/daemon/dbus/gkd-secret-create.c
@@ -45,6 +45,12 @@
#include <string.h>
enum {
+ STATE_BEGIN,
+ STATE_PROMPTING,
+ STATE_PROMPTED
+};
+
+enum {
PROP_0,
PROP_PKCS11_ATTRIBUTES,
PROP_ALIAS
@@ -52,52 +58,50 @@ enum {
struct _GkdSecretCreate {
GkdSecretPrompt parent;
- GckAttributes *pkcs11_attrs;
- gchar *alias;
+ GckAttributes *attributes;
+ GkdSecretSecret *master;
gchar *result_path;
+ gchar *alias;
+ gboolean confirmed;
};
-G_DEFINE_TYPE (GkdSecretCreate, gkd_secret_create, GKD_SECRET_TYPE_PROMPT);
+static void perform_prompting (GkdSecretCreate *self);
-/* -----------------------------------------------------------------------------
- * INTERNAL
- */
+G_DEFINE_TYPE (GkdSecretCreate, gkd_secret_create, GKD_SECRET_TYPE_PROMPT);
static void
-prepare_create_prompt (GkdSecretCreate *self)
+setup_password_prompt (GkdSecretCreate *self)
{
- GkuPrompt *prompt;
gchar *label;
gchar *text;
- g_assert (GKD_SECRET_IS_CREATE (self));
- g_assert (self->pkcs11_attrs);
-
- prompt = GKU_PROMPT (self);
-
- if (!gck_attributes_find_string (self->pkcs11_attrs, CKA_LABEL, &label))
+ if (!gck_attributes_find_string (self->attributes, CKA_LABEL, &label))
label = g_strdup (_("Unnamed"));
- gku_prompt_reset (prompt, TRUE);
+ text = g_strdup_printf (_("An application wants to create a new keyring called '%s'. "
+ "Choose the password you want to use for it."), label);
+ g_free (label);
- gku_prompt_set_title (prompt, _("New Keyring Password"));
- gku_prompt_set_primary_text (prompt, _("Choose password for new keyring"));
+ gcr_prompt_set_message (GCR_PROMPT (self), _("Choose password for new keyring"));
+ gcr_prompt_set_description (GCR_PROMPT (self), text);
+ gcr_prompt_set_password_new (GCR_PROMPT (self), TRUE);
- text = g_markup_printf_escaped (_("An application wants to create a new keyring called '%s'. "
- "Choose the password you want to use for it."), label);
- gku_prompt_set_secondary_text (prompt, text);
g_free (text);
+}
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "confirm_area");
-
- g_free (label);
+static void
+setup_confirmation_prompt (GkdSecretCreate *self)
+{
+ gcr_prompt_set_message (GCR_PROMPT (self), _("Store passwords unencrypted?"));
+ gcr_prompt_set_description (GCR_PROMPT (self),
+ _("By choosing to use a blank password, your stored passwords will not be safely encrypted. "
+ "They will be accessible by anyone with access to your files."));
}
static gboolean
create_collection_with_secret (GkdSecretCreate *self, GkdSecretSecret *master)
{
- DBusError derr = DBUS_ERROR_INIT;
+ GError *error = NULL;
GkdSecretService *service;
gchar *identifier;
@@ -105,11 +109,11 @@ create_collection_with_secret (GkdSecretCreate *self, GkdSecretSecret *master)
g_assert (master);
g_assert (!self->result_path);
- self->result_path = gkd_secret_create_with_secret (self->pkcs11_attrs, master, &derr);
+ self->result_path = gkd_secret_create_with_secret (self->attributes, master, &error);
if (!self->result_path) {
- g_warning ("couldn't create new collection: %s", derr.message);
- dbus_error_free (&derr);
+ g_warning ("couldn't create new collection: %s", error->message);
+ g_error_free (error);
return FALSE;
}
@@ -191,39 +195,98 @@ unlock_or_complete_this_prompt (GkdSecretCreate *self)
g_object_unref (self);
}
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
static void
-gkd_secret_create_prompt_ready (GkdSecretPrompt *prompt)
+on_prompt_password_complete (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- GkdSecretCreate *self = GKD_SECRET_CREATE (prompt);
- GkdSecretSecret *master;
+ GkdSecretCreate *self = GKD_SECRET_CREATE (source);
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
+ GError *error = NULL;
- if (!gku_prompt_has_response (GKU_PROMPT (prompt))) {
+ gcr_prompt_password_finish (GCR_PROMPT (source), result, &error);
- /* Does the alias exist? */
- if (locate_alias_collection_if_exists (self))
- unlock_or_complete_this_prompt (self);
+ if (error != NULL) {
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
+ return;
+ }
- /* Otherwise we're going to prompt */
- else
- prepare_create_prompt (self);
+ self->master = gkd_secret_prompt_take_secret (prompt);
+ if (self->master == NULL) {
+ gkd_secret_prompt_dismiss (prompt);
+ return;
+ }
+
+ /* If the password strength is greater than zero, then don't confirm */
+ if (gcr_prompt_get_password_strength (GCR_PROMPT (source)) > 0)
+ self->confirmed = TRUE;
+
+ perform_prompting (self);
+}
+
+static void
+on_prompt_confirmation_complete (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GkdSecretCreate *self = GKD_SECRET_CREATE (source);
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (source);
+ GError *error = NULL;
+ self->confirmed = gcr_prompt_confirm_finish (GCR_PROMPT (source), result, &error);
+ if (error != NULL) {
+ gkd_secret_prompt_dismiss_with_error (prompt, error);
+ g_error_free (error);
return;
}
- /* Already prompted, create collection */
- g_return_if_fail (gku_prompt_get_response (GKU_PROMPT (prompt)) == GKU_RESPONSE_OK);
- master = gkd_secret_prompt_get_secret (prompt, "password");
+ /* If not confirmed, then prompt again */
+ if (!self->confirmed) {
+ gkd_secret_secret_free (self->master);
+ self->master = NULL;
+ }
- if (master && create_collection_with_secret (self, master))
+ perform_prompting (self);
+}
+
+static void
+perform_prompting (GkdSecretCreate *self)
+{
+ GkdSecretPrompt *prompt = GKD_SECRET_PROMPT (self);
+
+ /* Does the alias exist? */
+ if (locate_alias_collection_if_exists (self)) {
+ unlock_or_complete_this_prompt (self);
+
+ /* Have we gotten a password yet? */
+ } else if (self->master == NULL) {
+ setup_password_prompt (self);
+ gcr_prompt_password_async (GCR_PROMPT (self),
+ gkd_secret_prompt_get_cancellable (prompt),
+ on_prompt_password_complete, NULL);
+
+ /* Check that the password is not empty */
+ } else if (!self->confirmed) {
+ setup_confirmation_prompt (self);
+ gcr_prompt_confirm_async (GCR_PROMPT (self),
+ gkd_secret_prompt_get_cancellable (prompt),
+ on_prompt_confirmation_complete, NULL);
+
+ /* Actually create the keyring */
+ } else if (create_collection_with_secret (self, self->master)) {
gkd_secret_prompt_complete (prompt);
- else
+
+ /* Failed */
+ } else {
gkd_secret_prompt_dismiss (prompt);
+ }
+}
- gkd_secret_secret_free (master);
+static void
+gkd_secret_create_prompt_ready (GkdSecretPrompt *prompt)
+{
+ perform_prompting (GKD_SECRET_CREATE (prompt));
}
static void
@@ -242,7 +305,7 @@ gkd_secret_create_encode_result (GkdSecretPrompt *base, DBusMessageIter *iter)
static void
gkd_secret_create_init (GkdSecretCreate *self)
{
-
+ gcr_prompt_set_title (GCR_PROMPT (self), _("New Keyring Password"));
}
static void
@@ -250,7 +313,8 @@ gkd_secret_create_finalize (GObject *obj)
{
GkdSecretCreate *self = GKD_SECRET_CREATE (obj);
- gck_attributes_unref (self->pkcs11_attrs);
+ gkd_secret_secret_free (self->master);
+ gck_attributes_unref (self->attributes);
g_free (self->result_path);
g_free (self->alias);
@@ -265,9 +329,9 @@ gkd_secret_create_set_property (GObject *obj, guint prop_id, const GValue *value
switch (prop_id) {
case PROP_PKCS11_ATTRIBUTES:
- g_return_if_fail (!self->pkcs11_attrs);
- self->pkcs11_attrs = g_value_dup_boxed (value);
- g_return_if_fail (self->pkcs11_attrs);
+ g_return_if_fail (!self->attributes);
+ self->attributes = g_value_dup_boxed (value);
+ g_return_if_fail (self->attributes);
break;
case PROP_ALIAS:
g_return_if_fail (!self->alias);
@@ -287,7 +351,7 @@ gkd_secret_create_get_property (GObject *obj, guint prop_id, GValue *value,
switch (prop_id) {
case PROP_PKCS11_ATTRIBUTES:
- g_value_set_boxed (value, self->pkcs11_attrs);
+ g_value_set_boxed (value, self->attributes);
break;
case PROP_ALIAS:
g_value_set_string (value, self->alias);
@@ -358,15 +422,15 @@ gkd_secret_create_with_credential (GckSession *session, GckAttributes *attrs,
}
gchar*
-gkd_secret_create_with_secret (GckAttributes *attrs, GkdSecretSecret *master,
- DBusError *derr)
+gkd_secret_create_with_secret (GckAttributes *attrs,
+ GkdSecretSecret *master,
+ GError **error)
{
GckBuilder builder = GCK_BUILDER_INIT;
GckAttributes *atts;
GckObject *cred;
GckObject *collection;
GckSession *session;
- GError *error = NULL;
gpointer identifier;
gsize n_identifier;
gboolean token;
@@ -384,33 +448,26 @@ gkd_secret_create_with_secret (GckAttributes *attrs, GkdSecretSecret *master,
/* Create ourselves some credentials */
atts = gck_attributes_ref_sink (gck_builder_end (&builder));
- cred = gkd_secret_session_create_credential (master->session, session, atts, master, derr);
+ cred = gkd_secret_session_create_credential (master->session, session,
+ atts, master, error);
gck_attributes_unref (atts);
if (cred == NULL)
return FALSE;
- collection = gkd_secret_create_with_credential (session, attrs, cred, &error);
+ collection = gkd_secret_create_with_credential (session, attrs, cred, error);
gck_attributes_unref (atts);
g_object_unref (cred);
- if (collection == NULL) {
- g_warning ("couldn't create collection: %s", egg_error_message (error));
- g_clear_error (&error);
- dbus_set_error (derr, DBUS_ERROR_FAILED, "Couldn't create new collection");
+ if (collection == NULL)
return FALSE;
- }
- identifier = gck_object_get_data (collection, CKA_ID, NULL, &n_identifier, &error);
+ identifier = gck_object_get_data (collection, CKA_ID, NULL, &n_identifier, error);
g_object_unref (collection);
- if (!identifier) {
- g_warning ("couldn't lookup new collection identifier: %s", egg_error_message (error));
- g_clear_error (&error);
- dbus_set_error (derr, DBUS_ERROR_FAILED, "Couldn't find new collection just created");
+ if (!identifier)
return FALSE;
- }
path = gkd_secret_util_build_path (SECRET_COLLECTION_PREFIX, identifier, n_identifier);
g_free (identifier);
diff --git a/daemon/dbus/gkd-secret-create.h b/daemon/dbus/gkd-secret-create.h
index 75c3c6e..d76a8e9 100644
--- a/daemon/dbus/gkd-secret-create.h
+++ b/daemon/dbus/gkd-secret-create.h
@@ -56,6 +56,6 @@ GckObject* gkd_secret_create_with_credential (GckSession *sessi
gchar* gkd_secret_create_with_secret (GckAttributes *attrs,
GkdSecretSecret *master,
- DBusError *derr);
+ GError **error);
#endif /* __GKD_SECRET_CREATE_H__ */
diff --git a/daemon/dbus/gkd-secret-error.c b/daemon/dbus/gkd-secret-error.c
index 3faa633..e44af78 100644
--- a/daemon/dbus/gkd-secret-error.c
+++ b/daemon/dbus/gkd-secret-error.c
@@ -21,10 +21,14 @@
#include "config.h"
-#include <glib.h>
-
#include "gkd-secret-error.h"
+#include "egg/egg-error.h"
+
+#include <gck/gck.h>
+
+#include <glib.h>
+
DBusMessage*
gkd_secret_error_no_such_object (DBusMessage *message)
{
@@ -46,3 +50,30 @@ gkd_secret_error_to_reply (DBusMessage *message, DBusError *derr)
dbus_error_free (derr);
return reply;
}
+
+DBusMessage *
+gkd_secret_propagate_error (DBusMessage *message,
+ const gchar *description,
+ GError *error)
+{
+ DBusError derr = DBUS_ERROR_INIT;
+
+ g_return_val_if_fail (error != NULL, NULL);
+
+ if (g_error_matches (error, GCK_ERROR, CKR_USER_NOT_LOGGED_IN)) {
+ dbus_set_error (&derr, INTERNAL_ERROR_DENIED, "The password was invalid");
+
+ } else if (g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_INVALID) ||
+ g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_LEN_RANGE) ||
+ g_error_matches (error, GCK_ERROR, CKR_MECHANISM_PARAM_INVALID)) {
+ dbus_set_error_const (&derr, DBUS_ERROR_INVALID_ARGS,
+ "The secret was transferred or encrypted in an invalid way.");
+
+ } else {
+ g_warning ("%s: %s", description, egg_error_message (error));
+ dbus_set_error (&derr, DBUS_ERROR_FAILED, "Couldn't create new collection");
+ }
+
+ g_error_free (error);
+ return gkd_secret_error_to_reply (message, &derr);
+}
diff --git a/daemon/dbus/gkd-secret-error.h b/daemon/dbus/gkd-secret-error.h
index bc38e70..43692b3 100644
--- a/daemon/dbus/gkd-secret-error.h
+++ b/daemon/dbus/gkd-secret-error.h
@@ -24,11 +24,17 @@
#include "gkd-secret-types.h"
+#include <glib.h>
+
#include <dbus/dbus.h>
-DBusMessage* gkd_secret_error_no_such_object (DBusMessage *message);
+DBusMessage * gkd_secret_error_no_such_object (DBusMessage *message);
+
+DBusMessage * gkd_secret_propagate_error (DBusMessage *message,
+ const gchar *description,
+ GError *error);
-DBusMessage* gkd_secret_error_to_reply (DBusMessage *message,
- DBusError *derr);
+DBusMessage * gkd_secret_error_to_reply (DBusMessage *message,
+ DBusError *derr);
#endif /* __GKD_SECRET_ERROR_H__ */
diff --git a/daemon/dbus/gkd-secret-prompt.c b/daemon/dbus/gkd-secret-prompt.c
index 9d8f277..d72c081 100644
--- a/daemon/dbus/gkd-secret-prompt.c
+++ b/daemon/dbus/gkd-secret-prompt.c
@@ -33,9 +33,8 @@
#include "gkd-secret-types.h"
#include "gkd-secret-util.h"
-#include "ui/gku-prompt.h"
-
#include "egg/egg-dh.h"
+#include "egg/egg-error.h"
#include <string.h>
@@ -50,6 +49,7 @@ struct _GkdSecretPromptPrivate {
gchar *object_path;
GkdSecretService *service;
GkdSecretExchange *exchange;
+ GCancellable *cancellable;
gboolean prompted;
gboolean completed;
gchar *caller;
@@ -58,30 +58,11 @@ struct _GkdSecretPromptPrivate {
};
static void gkd_secret_dispatch_iface (GkdSecretDispatchIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GkdSecretPrompt, gkd_secret_prompt, GKU_TYPE_PROMPT,
+G_DEFINE_TYPE_WITH_CODE (GkdSecretPrompt, gkd_secret_prompt, GCR_TYPE_SYSTEM_PROMPT,
G_IMPLEMENT_INTERFACE (GKD_SECRET_TYPE_DISPATCH, gkd_secret_dispatch_iface));
static guint unique_prompt_number = 0;
-/* -----------------------------------------------------------------------------
- * INTERNAL
- */
-
-static GkuPrompt*
-on_prompt_attention (gpointer user_data)
-{
- GkdSecretPrompt *self = user_data;
-
- /* Check with the derived class */
- g_return_val_if_fail (GKD_SECRET_PROMPT_GET_CLASS (self)->prompt_ready, NULL);
- GKD_SECRET_PROMPT_GET_CLASS (self)->prompt_ready (self);
-
- if (self->pv->completed)
- return NULL;
-
- return g_object_ref (self);
-}
-
static void
emit_completed (GkdSecretPrompt *self, gboolean dismissed)
{
@@ -104,12 +85,31 @@ emit_completed (GkdSecretPrompt *self, gboolean dismissed)
dbus_message_unref (signal);
}
-/* -----------------------------------------------------------------------------
- * DBUS
- */
+static void
+on_system_prompt_inited (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GkdSecretPrompt *self = GKD_SECRET_PROMPT (source);
+ GkdSecretPromptClass *klass;
+ GError *error = NULL;
+
+ if (g_async_initable_init_finish (G_ASYNC_INITABLE (source), result, &error)) {
+ klass = GKD_SECRET_PROMPT_GET_CLASS (self);
+ g_assert (klass->prompt_ready);
+ (klass->prompt_ready) (self);
+ } else {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_message ("couldn't initialize prompt: %s", error->message);
+ g_error_free (error);
+ if (!self->pv->completed)
+ gkd_secret_prompt_dismiss (self);
+ }
+}
static DBusMessage*
-prompt_method_prompt (GkdSecretPrompt *self, DBusMessage *message)
+prompt_method_prompt (GkdSecretPrompt *self,
+ DBusMessage *message)
{
DBusMessage *reply;
const char *window_id;
@@ -127,11 +127,13 @@ prompt_method_prompt (GkdSecretPrompt *self, DBusMessage *message)
return dbus_message_new_error (message, SECRET_ERROR_ALREADY_EXISTS,
"This prompt has already been shown.");
- gku_prompt_set_window_id (GKU_PROMPT (self), window_id);
- gku_prompt_request_attention_async (window_id, on_prompt_attention,
- g_object_ref (self), g_object_unref);
self->pv->prompted = TRUE;
+ gcr_prompt_set_caller_window (GCR_PROMPT (self), window_id);
+
+ g_async_initable_init_async (G_ASYNC_INITABLE (self), G_PRIORITY_DEFAULT,
+ self->pv->cancellable, on_system_prompt_inited, NULL);
+
reply = dbus_message_new_method_return (message);
dbus_message_append_args (reply, DBUS_TYPE_INVALID);
return reply;
@@ -156,35 +158,8 @@ prompt_method_dismiss (GkdSecretPrompt *self, DBusMessage *message)
return reply;
}
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-static gboolean
-gkd_secret_prompt_responded (GkuPrompt *base)
-{
- GkdSecretPrompt *self = GKD_SECRET_PROMPT (base);
- gint res;
-
- res = gku_prompt_get_response (GKU_PROMPT (self));
- if (res <= GKU_RESPONSE_NO) {
- gkd_secret_prompt_dismiss (self);
- return FALSE;
- }
-
- /* Check with the prompt ready guys */
- g_return_val_if_fail (GKD_SECRET_PROMPT_GET_CLASS (self)->prompt_ready, TRUE);
- GKD_SECRET_PROMPT_GET_CLASS (self)->prompt_ready (self);
-
- /* Not yet done, will display again */
- if (!self->pv->completed)
- return TRUE;
-
- return FALSE;
-}
-
static void
-gkd_secret_prompt_real_ready (GkdSecretPrompt *self)
+gkd_secret_prompt_real_prompt_ready (GkdSecretPrompt *self)
{
/* Default implementation, unused */
g_return_if_reached ();
@@ -245,13 +220,14 @@ gkd_secret_prompt_constructed (GObject *obj)
self->pv->exchange = gkd_secret_exchange_new (self->pv->service, self->pv->caller);
/* Set the exchange for the prompt */
- g_object_set (self, "exchange", self->pv->exchange, NULL);
+ g_object_set (self, "secret-exchange", self->pv->exchange, NULL);
}
static void
gkd_secret_prompt_init (GkdSecretPrompt *self)
{
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, GKD_SECRET_TYPE_PROMPT, GkdSecretPromptPrivate);
+ self->pv->cancellable = g_cancellable_new ();
}
static void
@@ -259,6 +235,8 @@ gkd_secret_prompt_dispose (GObject *obj)
{
GkdSecretPrompt *self = GKD_SECRET_PROMPT (obj);
+ g_cancellable_cancel (self->pv->cancellable);
+
g_free (self->pv->object_path);
self->pv->object_path = NULL;
@@ -284,6 +262,8 @@ gkd_secret_prompt_finalize (GObject *obj)
g_free (self->pv->caller);
self->pv->caller = NULL;
+ g_clear_object (&self->pv->cancellable);
+
G_OBJECT_CLASS (gkd_secret_prompt_parent_class)->finalize (obj);
}
@@ -337,7 +317,6 @@ static void
gkd_secret_prompt_class_init (GkdSecretPromptClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GkuPromptClass *prompt_class = GKU_PROMPT_CLASS (klass);
gobject_class->constructed = gkd_secret_prompt_constructed;
gobject_class->dispose = gkd_secret_prompt_dispose;
@@ -345,10 +324,8 @@ gkd_secret_prompt_class_init (GkdSecretPromptClass *klass)
gobject_class->set_property = gkd_secret_prompt_set_property;
gobject_class->get_property = gkd_secret_prompt_get_property;
- prompt_class->responded = gkd_secret_prompt_responded;
-
klass->encode_result = gkd_secret_prompt_real_encode_result;
- klass->prompt_ready = gkd_secret_prompt_real_ready;
+ klass->prompt_ready = gkd_secret_prompt_real_prompt_ready;
g_type_class_add_private (klass, sizeof (GkdSecretPromptPrivate));
@@ -420,6 +397,9 @@ gkd_secret_prompt_complete (GkdSecretPrompt *self)
g_return_if_fail (!self->pv->completed);
self->pv->completed = TRUE;
emit_completed (self, FALSE);
+
+ /* Make this object go away */
+ g_object_run_dispose (G_OBJECT (self));
}
void
@@ -429,6 +409,17 @@ gkd_secret_prompt_dismiss (GkdSecretPrompt *self)
g_return_if_fail (!self->pv->completed);
self->pv->completed = TRUE;
emit_completed (self, TRUE);
+
+ /* Make this object go away */
+ g_object_run_dispose (G_OBJECT (self));
+}
+
+void
+gkd_secret_prompt_dismiss_with_error (GkdSecretPrompt *self,
+ GError *error)
+{
+ g_warning ("prompting failed: %s", egg_error_message (error));
+ gkd_secret_prompt_dismiss (self);
}
GckObject*
@@ -444,13 +435,17 @@ gkd_secret_prompt_lookup_collection (GkdSecretPrompt *self, const gchar *path)
}
GkdSecretSecret *
-gkd_secret_prompt_get_secret (GkdSecretPrompt *self, const gchar *password_type)
+gkd_secret_prompt_take_secret (GkdSecretPrompt *self)
{
g_return_val_if_fail (GKD_SECRET_IS_PROMPT (self), NULL);
- /* Ignore the result of this, since GkdSecretExchange doesn't decrypt */
- gku_prompt_get_password (GKU_PROMPT (self), password_type);
-
/* ... instead it stashes away the raw cipher text, and makes it available here */
return gkd_secret_exchange_take_last_secret (self->pv->exchange);
}
+
+GCancellable *
+gkd_secret_prompt_get_cancellable (GkdSecretPrompt *self)
+{
+ g_return_val_if_fail (GKD_SECRET_IS_PROMPT (self), NULL);
+ return self->pv->cancellable;
+}
diff --git a/daemon/dbus/gkd-secret-prompt.h b/daemon/dbus/gkd-secret-prompt.h
index 84fc187..ba6d259 100644
--- a/daemon/dbus/gkd-secret-prompt.h
+++ b/daemon/dbus/gkd-secret-prompt.h
@@ -26,9 +26,8 @@
#include "gkd-secret-types.h"
-#include "ui/gku-prompt.h"
-
#include <gck/gck.h>
+#include <gcr/gcr-base.h>
#include <dbus/dbus.h>
@@ -43,19 +42,20 @@ typedef struct _GkdSecretPromptClass GkdSecretPromptClass;
typedef struct _GkdSecretPromptPrivate GkdSecretPromptPrivate;
struct _GkdSecretPrompt {
- GkuPrompt parent;
+ GcrSystemPrompt parent;
GkdSecretPromptPrivate *pv;
};
struct _GkdSecretPromptClass {
- GkuPromptClass parent_class;
+ GcrSystemPromptClass parent_class;
+
+ void (*prompt_ready) (GkdSecretPrompt *self);
- /* virtual methods */
- void (*prompt_ready) (GkdSecretPrompt *self);
- void (*encode_result) (GkdSecretPrompt *self, DBusMessageIter *iter);
+ void (*encode_result) (GkdSecretPrompt *self,
+ DBusMessageIter *iter);
};
-GType gkd_secret_prompt_get_type (void);
+GType gkd_secret_prompt_get_type (void) G_GNUC_CONST;
const gchar* gkd_secret_prompt_get_caller (GkdSecretPrompt *self);
@@ -67,8 +67,9 @@ GkdSecretService* gkd_secret_prompt_get_service (GkdSecretPrompt *
GkdSecretObjects* gkd_secret_prompt_get_objects (GkdSecretPrompt *self);
-GkdSecretSecret* gkd_secret_prompt_get_secret (GkdSecretPrompt *self,
- const gchar *password_type);
+GCancellable * gkd_secret_prompt_get_cancellable (GkdSecretPrompt *self);
+
+GkdSecretSecret * gkd_secret_prompt_take_secret (GkdSecretPrompt *self);
GckObject* gkd_secret_prompt_lookup_collection (GkdSecretPrompt *self,
const gchar *path);
@@ -77,4 +78,7 @@ void gkd_secret_prompt_complete (GkdSecretPrompt *
void gkd_secret_prompt_dismiss (GkdSecretPrompt *self);
+void gkd_secret_prompt_dismiss_with_error (GkdSecretPrompt *self,
+ GError *error);
+
#endif /* __GKD_SECRET_PROMPT_H__ */
diff --git a/daemon/dbus/gkd-secret-service.c b/daemon/dbus/gkd-secret-service.c
index d5724fc..5adc1ba 100644
--- a/daemon/dbus/gkd-secret-service.c
+++ b/daemon/dbus/gkd-secret-service.c
@@ -670,6 +670,7 @@ service_method_create_with_master_password (GkdSecretService *self, DBusMessage
DBusMessage *reply = NULL;
GkdSecretSecret *secret = NULL;
GckAttributes *attrs = NULL;
+ GError *error = NULL;
gchar *path;
/* Parse the incoming message */
@@ -692,12 +693,12 @@ service_method_create_with_master_password (GkdSecretService *self, DBusMessage
gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
- path = gkd_secret_create_with_secret (attrs, secret, &derr);
+ path = gkd_secret_create_with_secret (attrs, secret, &error);
gck_attributes_unref (attrs);
gkd_secret_secret_free (secret);
if (path == NULL)
- return gkd_secret_error_to_reply (message, &derr);
+ return gkd_secret_propagate_error (message, "Couldn't create collection", error);
reply = dbus_message_new_method_return (message);
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
@@ -714,6 +715,7 @@ service_method_change_with_master_password (GkdSecretService *self, DBusMessage
GckObject *collection;
DBusMessageIter iter;
DBusMessage *reply;
+ GError *error = NULL;
const gchar *path;
/* Parse the incoming message */
@@ -744,12 +746,12 @@ service_method_change_with_master_password (GkdSecretService *self, DBusMessage
"The collection does not exist");
/* Success */
- else if (gkd_secret_change_with_secrets (collection, original, master, &derr))
+ else if (gkd_secret_change_with_secrets (collection, NULL, original, master, &error))
reply = dbus_message_new_method_return (message);
/* Failure */
else
- reply = gkd_secret_error_to_reply (message, &derr);
+ reply = gkd_secret_propagate_error (message, "Couldn't change collection password", error);
gkd_secret_secret_free (original);
gkd_secret_secret_free (master);
@@ -765,6 +767,7 @@ service_method_unlock_with_master_password (GkdSecretService *self, DBusMessage
{
DBusError derr = DBUS_ERROR_INIT;
GkdSecretSecret *master;
+ GError *error = NULL;
GckObject *collection;
DBusMessageIter iter;
DBusMessage *reply;
@@ -792,12 +795,12 @@ service_method_unlock_with_master_password (GkdSecretService *self, DBusMessage
"The collection does not exist");
/* Success */
- else if (gkd_secret_unlock_with_secret (collection, master, &derr))
+ else if (gkd_secret_unlock_with_secret (collection, master, &error))
reply = dbus_message_new_method_return (message);
/* Failure */
else
- reply = gkd_secret_error_to_reply (message, &derr);
+ reply = gkd_secret_propagate_error (message, "Couldn't unlock collection", error);
gkd_secret_secret_free (master);
diff --git a/daemon/dbus/gkd-secret-session.c b/daemon/dbus/gkd-secret-session.c
index 8316998..2b2e480 100644
--- a/daemon/dbus/gkd-secret-session.c
+++ b/daemon/dbus/gkd-secret-session.c
@@ -712,18 +712,19 @@ gkd_secret_session_set_item_secret (GkdSecretSession *self, GckObject *item,
}
GckObject*
-gkd_secret_session_create_credential (GkdSecretSession *self, GckSession *session,
- GckAttributes *attrs, GkdSecretSecret *secret,
- DBusError *derr)
+gkd_secret_session_create_credential (GkdSecretSession *self,
+ GckSession *session,
+ GckAttributes *attrs,
+ GkdSecretSecret *secret,
+ GError **error)
{
GckBuilder builder = GCK_BUILDER_INIT;
GckAttributes *alloc = NULL;
GckMechanism mech;
GckObject *object;
- GError *error = NULL;
g_assert (GCK_IS_OBJECT (self->key));
- g_assert (attrs);
+ g_assert (attrs != NULL);
if (session == NULL)
session = gkd_secret_service_get_pkcs11_session (self->service, self->caller);
@@ -740,25 +741,9 @@ gkd_secret_session_create_credential (GkdSecretSession *self, GckSession *sessio
mech.n_parameter = secret->n_parameter;
object = gck_session_unwrap_key_full (session, self->key, &mech, secret->value,
- secret->n_value, attrs, NULL, &error);
+ secret->n_value, attrs, NULL, error);
gck_attributes_unref (alloc);
- if (object == NULL) {
- if (g_error_matches (error, GCK_ERROR, CKR_PIN_INCORRECT)) {
- dbus_set_error_const (derr, INTERNAL_ERROR_DENIED, "The password was incorrect.");
- } else if (g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_INVALID) ||
- g_error_matches (error, GCK_ERROR, CKR_WRAPPED_KEY_LEN_RANGE) ||
- g_error_matches (error, GCK_ERROR, CKR_MECHANISM_PARAM_INVALID)) {
- dbus_set_error_const (derr, DBUS_ERROR_INVALID_ARGS,
- "The secret was transferred or encrypted in an invalid way.");
- } else {
- g_message ("couldn't unwrap credential: %s", egg_error_message (error));
- dbus_set_error_const (derr, DBUS_ERROR_FAILED, "Couldn't use credentials");
- }
- g_clear_error (&error);
- return NULL;
- }
-
return object;
}
diff --git a/daemon/dbus/gkd-secret-session.h b/daemon/dbus/gkd-secret-session.h
index 6b1092e..a38a36d 100644
--- a/daemon/dbus/gkd-secret-session.h
+++ b/daemon/dbus/gkd-secret-session.h
@@ -71,7 +71,7 @@ GckObject* gkd_secret_session_create_credential (GkdSecretSession
GckSession *session,
GckAttributes *attrs,
GkdSecretSecret *secret,
- DBusError *derr);
+ GError **error);
DBusMessage* gkd_secret_session_handle_open (GkdSecretSession *self,
DBusMessage *message);
diff --git a/daemon/dbus/gkd-secret-unlock.c b/daemon/dbus/gkd-secret-unlock.c
index 4161396..2e3fbed 100644
--- a/daemon/dbus/gkd-secret-unlock.c
+++ b/daemon/dbus/gkd-secret-unlock.c
@@ -625,8 +625,9 @@ gkd_secret_unlock_call_prompt (GkdSecretUnlock *self, const gchar *window_id)
}
gboolean
-gkd_secret_unlock_with_secret (GckObject *collection, GkdSecretSecret *master,
- DBusError *derr)
+gkd_secret_unlock_with_secret (GckObject *collection,
+ GkdSecretSecret *master,
+ GError **error)
{
GckBuilder builder = GCK_BUILDER_INIT;
GckAttributes *attrs;
@@ -645,7 +646,8 @@ gkd_secret_unlock_with_secret (GckObject *collection, GkdSecretSecret *master,
gck_builder_add_boolean (&builder, CKA_TOKEN, TRUE);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
- cred = gkd_secret_session_create_credential (master->session, NULL, attrs, master, derr);
+ cred = gkd_secret_session_create_credential (master->session, NULL,
+ attrs, master, error);
gck_attributes_unref (attrs);
diff --git a/daemon/dbus/gkd-secret-unlock.h b/daemon/dbus/gkd-secret-unlock.h
index fdd7c8a..b49de59 100644
--- a/daemon/dbus/gkd-secret-unlock.h
+++ b/daemon/dbus/gkd-secret-unlock.h
@@ -62,7 +62,7 @@ void gkd_secret_unlock_call_prompt (GkdSecretUnlock *
gboolean gkd_secret_unlock_with_secret (GckObject *collection,
GkdSecretSecret *master,
- DBusError *derr);
+ GError **error);
gboolean gkd_secret_unlock_with_password (GckObject *collection,
const guchar *password,
diff --git a/daemon/gpg-agent/Makefile.am b/daemon/gpg-agent/Makefile.am
index 40a85bf..e167037 100644
--- a/daemon/gpg-agent/Makefile.am
+++ b/daemon/gpg-agent/Makefile.am
@@ -4,6 +4,7 @@ INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/pkcs11 \
-DGCK_API_SUBJECT_TO_CHANGE \
+ -DGCR_API_SUBJECT_TO_CHANGE \
$(DAEMON_CFLAGS)
# ------------------------------------------------------------------------------
@@ -28,6 +29,5 @@ gkd_gpg_agent_standalone_SOURCES = \
gkd_gpg_agent_standalone_LDADD = \
libgkd-gpg-agent.la \
- $(top_builddir)/ui/libgku-prompt.la \
$(top_builddir)/egg/libegg.la \
$(DAEMON_LIBS)
diff --git a/daemon/gpg-agent/gkd-gpg-agent-ops.c b/daemon/gpg-agent/gkd-gpg-agent-ops.c
index d2d6423..154e172 100644
--- a/daemon/gpg-agent/gkd-gpg-agent-ops.c
+++ b/daemon/gpg-agent/gkd-gpg-agent-ops.c
@@ -27,11 +27,10 @@
#include "egg/egg-error.h"
#include "egg/egg-secure-memory.h"
-#include <gcr/gcr-unlock-options.h>
-
#include "pkcs11/pkcs11i.h"
-#include "ui/gku-prompt.h"
+#include <gcr/gcr-base.h>
+#include <gcr/gcr-unlock-options.h>
#include <glib/gi18n.h>
@@ -296,11 +295,11 @@ do_lookup_password (GckSession *session, const gchar *keyid)
}
static void
-load_unlock_options (GkuPrompt *prompt)
+load_unlock_options (GcrPrompt *prompt)
{
GSettings *settings;
gchar *method;
- gint ttl;
+ gboolean chosen;
settings = gkd_gpg_agent_settings ();
@@ -317,67 +316,60 @@ load_unlock_options (GkuPrompt *prompt)
method = g_strdup (GCR_UNLOCK_OPTION_SESSION);
}
- gku_prompt_set_unlock_choice (prompt, method);
- g_free (method);
+ chosen = g_str_equal (GCR_UNLOCK_OPTION_ALWAYS, method);
+ gcr_prompt_set_choice_chosen (prompt, chosen);
- ttl = g_settings_get_int (settings, "gpg-cache-ttl");
- gku_prompt_set_unlock_ttl (prompt, ttl <= 0 ? 1 : (guint)ttl);
+ g_free (method);
}
static void
-save_unlock_options (GkuPrompt *prompt)
+save_unlock_options (GcrPrompt *prompt)
{
GSettings *settings;
- const gchar *method;
- gint ttl;
settings = gkd_gpg_agent_settings ();
- method = gku_prompt_get_unlock_choice (prompt);
- if (method)
- g_settings_set_string (settings, "gpg-cache-method", method);
-
- ttl = gku_prompt_get_unlock_ttl (prompt);
- if (ttl >= 0)
- g_settings_set_int (settings, "gpg-cache-ttl", (gint)ttl);
+ if (gcr_prompt_get_choice_chosen (prompt))
+ g_settings_set_string (settings, "gpg-cache-method", GCR_UNLOCK_OPTION_ALWAYS);
}
-static GkuPrompt*
-prepare_password_prompt (GckSession *session, const gchar *keyid, const gchar *errmsg,
- const gchar *prompt_text, const gchar *description, gboolean confirm)
+static GcrPrompt *
+open_password_prompt (GckSession *session,
+ const gchar *keyid,
+ const gchar *errmsg,
+ const gchar *prompt_text,
+ const gchar *description,
+ gboolean confirm)
{
GckBuilder builder = GCK_BUILDER_INIT;
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
GError *error = NULL;
gboolean auto_unlock;
GList *objects;
+ const gchar *choice;
g_assert (GCK_IS_SESSION (session));
- prompt = gku_prompt_new ();
+ prompt = GCR_PROMPT (gcr_system_prompt_open (-1, NULL, &error));
+ if (prompt == NULL) {
+ g_warning ("couldn't create prompt for gnupg passphrase: %s", egg_error_message (error));
+ g_error_free (error);
+ return NULL;
+ }
- gku_prompt_set_title (prompt, _("Enter Passphrase"));
- gku_prompt_set_primary_text (prompt, prompt_text ? prompt_text : _("Enter Passphrase"));
- gku_prompt_set_secondary_text (prompt, description);
+ gcr_prompt_set_title (prompt, _("Enter Passphrase"));
+ gcr_prompt_set_message (prompt, prompt_text ? prompt_text : _("Enter Passphrase"));
+ gcr_prompt_set_description (prompt, description);
- gku_prompt_hide_widget (prompt, "name_area");
- if (confirm)
- gku_prompt_show_widget (prompt, "confirm_area");
- else
- gku_prompt_hide_widget (prompt, "confirm_area");
- gku_prompt_show_widget (prompt, "password_area");
+ gcr_prompt_set_password_new (prompt, confirm);
if (errmsg)
- gku_prompt_set_warning (prompt, errmsg);
+ gcr_prompt_set_warning (prompt, errmsg);
if (keyid == NULL) {
- gku_prompt_hide_widget (prompt, "details_area");
- gku_prompt_hide_widget (prompt, "options_area");
+ gcr_prompt_set_choice_label (prompt, NULL);
} else {
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "options_area");
-
auto_unlock = FALSE;
gck_builder_add_ulong (&builder, CKA_CLASS, CKO_G_COLLECTION);
@@ -396,10 +388,10 @@ prepare_password_prompt (GckSession *session, const gchar *keyid, const gchar *e
gck_list_unref_free (objects);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS, auto_unlock, NULL);
- gku_prompt_set_unlock_label (prompt, GCR_UNLOCK_OPTION_IDLE, _("Forget this password if idle for"));
- gku_prompt_set_unlock_label (prompt, GCR_UNLOCK_OPTION_TIMEOUT, _("Forget this password after"));
- gku_prompt_set_unlock_label (prompt, GCR_UNLOCK_OPTION_SESSION, _("Forget this password when I log out"));
+ choice = NULL;
+ if (auto_unlock)
+ choice = _("Automatically unlock this key, whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
load_unlock_options (prompt);
}
@@ -407,13 +399,6 @@ prepare_password_prompt (GckSession *session, const gchar *keyid, const gchar *e
return prompt;
}
-static GkuPrompt*
-on_prompt_attention (gpointer user_data)
-{
- /* We passed the prompt as the argument */
- return g_object_ref (user_data);
-}
-
static gchar*
do_get_password (GckSession *session, const gchar *keyid, const gchar *errmsg,
const gchar *prompt_text, const gchar *description, gboolean confirm)
@@ -421,9 +406,9 @@ do_get_password (GckSession *session, const gchar *keyid, const gchar *errmsg,
GckBuilder builder = GCK_BUILDER_INIT;
GckAttributes *attrs;
gchar *password = NULL;
- GkuPrompt *prompt;
- const gchar *choice;
- guint ttl;
+ GcrPrompt *prompt;
+ gboolean chosen;
+ GError *error = NULL;
g_assert (GCK_IS_SESSION (session));
@@ -432,42 +417,36 @@ do_get_password (GckSession *session, const gchar *keyid, const gchar *errmsg,
if (password != NULL)
return password;
- prompt = prepare_password_prompt (session, keyid, errmsg, prompt_text,
- description, confirm);
-
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (prompt), g_object_unref);
-
- if (gku_prompt_get_response (prompt) == GKU_RESPONSE_OK) {
- password = gku_prompt_get_password (prompt, "password");
- g_return_val_if_fail (password, NULL);
-
- if (keyid != NULL) {
- /* Load up the save options */
- choice = gku_prompt_get_unlock_choice (prompt);
- ttl = gku_prompt_get_unlock_ttl (prompt);
+ prompt = open_password_prompt (session, keyid, errmsg, prompt_text,
+ description, confirm);
+ if (prompt != NULL) {
+ password = egg_secure_strdup (gcr_prompt_password (prompt, NULL, &error));
+ if (password == NULL) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("couldn't prompt for password: %s", egg_error_message (error));
+ g_clear_error (&error);
+ }
+ }
- if (g_str_equal (choice, GCR_UNLOCK_OPTION_ALWAYS))
- gck_builder_add_string (&builder, CKA_G_COLLECTION, "login");
- else
- gck_builder_add_string (&builder, CKA_G_COLLECTION, "session");
+ if (password != NULL && keyid != NULL) {
- if (g_str_equal (choice, GCR_UNLOCK_OPTION_IDLE))
- gck_builder_add_ulong (&builder, CKA_G_DESTRUCT_IDLE, ttl);
+ /* Load up the save options */
+ chosen = gcr_prompt_get_choice_chosen (prompt);
- else if (g_str_equal (choice, GCR_UNLOCK_OPTION_TIMEOUT))
- gck_builder_add_ulong (&builder, CKA_G_DESTRUCT_AFTER, ttl);
+ if (chosen)
+ gck_builder_add_string (&builder, CKA_G_COLLECTION, "login");
+ else
+ gck_builder_add_string (&builder, CKA_G_COLLECTION, "session");
- /* Now actually save the password */
- attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
- do_save_password (session, keyid, description, password, attrs);
- gck_attributes_unref (attrs);
+ /* Now actually save the password */
+ attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
+ do_save_password (session, keyid, description, password, attrs);
+ gck_attributes_unref (attrs);
- save_unlock_options (prompt);
- }
+ save_unlock_options (prompt);
}
- g_object_unref (prompt);
+ g_clear_object (&prompt);
return password;
}
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 133c72c..3f519b7 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -2,7 +2,4 @@
EXTRA_DIST = \
file-format.txt \
keyring-intro.txt \
- gnome-keyring.svg \
- tools
-
-SUBDIRS = gnome-keyring-daemon
\ No newline at end of file
+ gnome-keyring.svg
\ No newline at end of file
diff --git a/pkcs11/wrap-layer/Makefile.am b/pkcs11/wrap-layer/Makefile.am
index 1779a85..4d5c536 100644
--- a/pkcs11/wrap-layer/Makefile.am
+++ b/pkcs11/wrap-layer/Makefile.am
@@ -6,7 +6,8 @@ INCLUDES = -I. \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/pkcs11 \
- $(GCR_BASE_CFLAGS)
+ $(GCR_BASE_CFLAGS) \
+ -DGCR_API_SUBJECT_TO_CHANGE
# ------------------------------------------------------------------------------
# The code
diff --git a/pkcs11/wrap-layer/gkm-wrap-prompt.c b/pkcs11/wrap-layer/gkm-wrap-prompt.c
index e6f671d..a10cc29 100644
--- a/pkcs11/wrap-layer/gkm-wrap-prompt.c
+++ b/pkcs11/wrap-layer/gkm-wrap-prompt.c
@@ -24,24 +24,41 @@
#include "gkm-wrap-login.h"
#include "gkm-wrap-prompt.h"
+#include "egg/egg-error.h"
#include "egg/egg-secure-memory.h"
-#include <gcr/gcr-unlock-options.h>
-
#include "gkm/gkm-attributes.h"
#include "gkm/gkm-util.h"
#include "pkcs11/pkcs11.h"
#include "pkcs11/pkcs11i.h"
-#include "ui/gku-prompt.h"
+#include <gcr/gcr-base.h>
#include <glib/gi18n.h>
#include <string.h>
+EGG_SECURE_DECLARE (wrap_prompt);
+
+#define GKM_TYPE_WRAP_PROMPT (gkm_wrap_prompt_get_type ())
+#define GKM_WRAP_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKM_TYPE_WRAP_PROMPT, GkmWrapPrompt))
+#define GKM_WRAP_PROMPT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKM_TYPE_WRAP_PROMPT, GkmWrapPromptClass))
+#define GKM_IS_WRAP_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKM_TYPE_WRAP_PROMPT))
+#define GKM_IS_WRAP_PROMPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKM_TYPE_WRAP_PROMPT))
+#define GKM_WRAP_PROMPT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKM_TYPE_WRAP_PROMPT, GkmWrapPromptClass))
+
+GType gkm_wrap_prompt_get_type (void);
+
+typedef struct _GkmWrapPromptClass GkmWrapPromptClass;
+
+struct _GkmWrapPromptClass {
+ GcrSystemPromptClass parent_class;
+};
+
struct _GkmWrapPrompt {
- GkuPrompt parent;
+ GcrSystemPrompt parent;
+ gboolean initialized;
CK_FUNCTION_LIST_PTR module;
CK_SESSION_HANDLE session;
@@ -54,7 +71,9 @@ struct _GkmWrapPrompt {
GQueue pool;
};
-G_DEFINE_TYPE (GkmWrapPrompt, gkm_wrap_prompt, GKU_TYPE_PROMPT);
+G_DEFINE_TYPE (GkmWrapPrompt, gkm_wrap_prompt, GCR_TYPE_SYSTEM_PROMPT);
+
+static const gchar *the_prompter_name = NULL;
/* -----------------------------------------------------------------------------
* UTILITIES
@@ -65,7 +84,7 @@ pool_alloc (GkmWrapPrompt *self, gsize length)
{
gpointer memory = g_malloc0 (length);
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_queue_push_tail (&self->pool, memory);
return memory;
}
@@ -82,15 +101,6 @@ pool_dup (GkmWrapPrompt *self, gconstpointer original, gsize length)
* AUTO UNLOCK
*/
-#if 0
-static void
-set_warning_wrong (GkdSecretUnlock *self)
-{
- g_assert (GKD_SECRET_IS_UNLOCK (self));
- gku_prompt_set_warning (GKU_PROMPT (self), _("The unlock password was incorrect"));
-}
-#endif
-
static gboolean
is_login_keyring (CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs)
{
@@ -232,14 +242,7 @@ auto_unlock_lookup_token (CK_TOKEN_INFO_PTR info)
static gboolean
auto_unlock_should_attach (GkmWrapPrompt *self)
{
- GkuPrompt *prompt = GKU_PROMPT (self);
- const gchar *choice;
-
- if (!gku_prompt_has_response (prompt))
- return FALSE;
-
- choice = gku_prompt_get_unlock_choice (prompt);
- return (choice && g_str_equal (choice, GCR_UNLOCK_OPTION_ALWAYS));
+ return gcr_prompt_get_choice_chosen (GCR_PROMPT (self));
}
static void
@@ -400,13 +403,6 @@ auto_unlock_remove_token (CK_TOKEN_INFO_PTR info)
* PROMPTING
*/
-static GkuPrompt*
-on_prompt_attention (gpointer user_data)
-{
- /* We passed the prompt as the argument */
- return g_object_ref (user_data);
-}
-
static CK_ATTRIBUTE_PTR
get_unlock_options_from_object (GkmWrapPrompt *self, CK_ULONG_PTR n_options)
{
@@ -415,7 +411,7 @@ get_unlock_options_from_object (GkmWrapPrompt *self, CK_ULONG_PTR n_options)
CK_ULONG i;
CK_RV rv;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->module);
g_assert (n_options);
@@ -469,7 +465,7 @@ set_unlock_options_on_object (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR options, CK_
CK_ATTRIBUTE attr;
CK_RV rv;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->module);
g_assert (options);
@@ -489,22 +485,12 @@ static CK_ATTRIBUTE_PTR
get_unlock_options_from_prompt (GkmWrapPrompt *self, CK_ULONG_PTR n_options)
{
CK_ATTRIBUTE_PTR options;
- const gchar *choice;
CK_BBOOL bval;
- CK_ULONG uval;
- guint ttl;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (n_options);
- if (!gku_prompt_has_response (GKU_PROMPT (self)))
- return NULL;
-
- ttl = gku_prompt_get_unlock_ttl (GKU_PROMPT (self));
- choice = gku_prompt_get_unlock_choice (GKU_PROMPT (self));
- g_return_val_if_fail (choice, NULL);
-
- *n_options = 4;
+ *n_options = 2;
options = pool_alloc (self, sizeof (CK_ATTRIBUTE) * (*n_options));
/* CKA_TOKEN */
@@ -519,52 +505,22 @@ get_unlock_options_from_prompt (GkmWrapPrompt *self, CK_ULONG_PTR n_options)
options[1].pValue = pool_dup (self, &bval, sizeof (bval));
options[1].ulValueLen = sizeof (bval);
- /* CKA_G_DESTRUCT_IDLE */
- uval = g_str_equal (choice, GCR_UNLOCK_OPTION_IDLE) ? ttl : 0;
- options[2].type = CKA_G_DESTRUCT_IDLE;
- options[2].pValue = pool_dup (self, &uval, sizeof (uval));
- options[2].ulValueLen = sizeof (uval);
-
- /* CKA_G_DESTRUCT_AFTER */
- uval = g_str_equal (choice, GCR_UNLOCK_OPTION_TIMEOUT) ? ttl : 0;
- options[3].type = CKA_G_DESTRUCT_AFTER;
- options[3].pValue = pool_dup (self, &uval, sizeof (uval));
- options[3].ulValueLen = sizeof (uval);
-
return options;
}
static void
set_unlock_options_on_prompt (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR options, CK_ULONG n_options)
{
- const gchar *choice = 0;
- gboolean have_ttl = FALSE;
+ gboolean chosen = FALSE;
gboolean bval;
- gulong uval;
- guint ttl = 0;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (options || !n_options);
- if (gkm_attributes_find_boolean (options, n_options, CKA_GNOME_TRANSIENT, &bval)) {
- choice = bval ? GCR_UNLOCK_OPTION_SESSION : GCR_UNLOCK_OPTION_ALWAYS;
- }
+ if (gkm_attributes_find_boolean (options, n_options, CKA_GNOME_TRANSIENT, &bval))
+ chosen = bval;
- if (gkm_attributes_find_ulong (options, n_options, CKA_G_DESTRUCT_IDLE, &uval) && uval) {
- choice = GCR_UNLOCK_OPTION_IDLE;
- have_ttl = TRUE;
- ttl = uval;
- }
-
- if (gkm_attributes_find_ulong (options, n_options, CKA_G_DESTRUCT_AFTER, &uval) && uval) {
- choice = GCR_UNLOCK_OPTION_TIMEOUT;
- have_ttl = TRUE;
- ttl = uval;
- }
-
- gku_prompt_set_unlock_choice (GKU_PROMPT (self), choice);
- if (have_ttl)
- gku_prompt_set_unlock_ttl (GKU_PROMPT (self), ttl);
+ gcr_prompt_set_choice_chosen (GCR_PROMPT (self), chosen);
}
static CK_ATTRIBUTE_PTR
@@ -574,7 +530,7 @@ get_attributes_from_object (GkmWrapPrompt *self, CK_ULONG *n_attrs)
CK_ULONG i;
CK_RV rv;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (n_attrs);
g_assert (self->module);
@@ -622,64 +578,59 @@ get_info_for_token (GkmWrapPrompt *self, CK_TOKEN_INFO_PTR tinfo)
}
static void
-prepare_unlock_keyring_login (GkmWrapPrompt *self)
+setup_unlock_keyring_login (GkmWrapPrompt *self)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
const gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
- prompt = GKU_PROMPT (self);
+ prompt = GCR_PROMPT (self);
- gku_prompt_set_title (prompt, _("Unlock Login Keyring"));
+ gcr_prompt_set_title (prompt, _("Unlock Login Keyring"));
text = _("Enter password to unlock your login keyring");
- gku_prompt_set_primary_text (prompt, text);
+ gcr_prompt_set_message (prompt, text);
if (gkm_wrap_login_did_unlock_fail ())
text = _("The password you use to log in to your computer no longer matches that of your login keyring.");
else
text = _("The login keyring did not get unlocked when you logged into your computer.");
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_description (prompt, text);
- gku_prompt_hide_widget (prompt, "name_area");
- gku_prompt_hide_widget (prompt, "confirm_area");
- gku_prompt_show_widget (prompt, "password_area");
+ gcr_prompt_set_choice_label (prompt, NULL);
}
static void
-prepare_unlock_keyring_other (GkmWrapPrompt *self, const gchar *label)
+setup_unlock_keyring_other (GkmWrapPrompt *self,
+ const gchar *label)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
+ const gchar *choice;
gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ prompt = GCR_PROMPT (self);
- prompt = GKU_PROMPT (self);
-
- gku_prompt_set_title (prompt, _("Unlock Keyring"));
+ gcr_prompt_set_title (prompt, _("Unlock Keyring"));
text = g_markup_printf_escaped (_("Enter password for keyring '%s' to unlock"), label);
- gku_prompt_set_primary_text (prompt, text);
+ gcr_prompt_set_message (prompt, text);
g_free (text);
text = g_markup_printf_escaped (_("An application wants access to the keyring '%s', but it is locked"), label);
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- gku_prompt_hide_widget (prompt, "name_area");
- gku_prompt_hide_widget (prompt, "confirm_area");
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "options_area");
-
- if (!gkm_wrap_login_is_usable ())
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS, FALSE, NULL);
+ choice = NULL;
+ if (gkm_wrap_login_is_usable ())
+ choice = _("Automatically unlock this keyring whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
}
static const gchar*
-prepare_unlock_object_title (CK_OBJECT_CLASS klass)
+calc_unlock_object_title (CK_OBJECT_CLASS klass)
{
switch (klass) {
case CKO_PRIVATE_KEY:
@@ -694,7 +645,7 @@ prepare_unlock_object_title (CK_OBJECT_CLASS klass)
}
static const gchar*
-prepare_unlock_object_primary (CK_OBJECT_CLASS klass)
+calc_unlock_object_primary (CK_OBJECT_CLASS klass)
{
switch (klass) {
case CKO_PRIVATE_KEY:
@@ -708,8 +659,23 @@ prepare_unlock_object_primary (CK_OBJECT_CLASS klass)
}
}
+static const gchar *
+calc_unlock_object_choice (CK_OBJECT_CLASS klass)
+{
+ switch (klass) {
+ case CKO_PRIVATE_KEY:
+ case CKO_PUBLIC_KEY:
+ return _("Automatically unlock this key whenever I'm logged in");
+ case CKO_CERTIFICATE:
+ return _("Automatically unlock this certificate whenever I'm logged in");
+ default:
+ return _("Automatically unlock whenever I'm logged in");
+ }
+}
+
static gchar*
-prepare_unlock_object_secondary (CK_OBJECT_CLASS klass, const gchar *label)
+calc_unlock_object_secondary (CK_OBJECT_CLASS klass,
+ const gchar *label)
{
switch (klass) {
case CKO_PRIVATE_KEY:
@@ -728,48 +694,43 @@ prepare_unlock_object_secondary (CK_OBJECT_CLASS klass, const gchar *label)
}
static void
-prepare_unlock_object (GkmWrapPrompt *self, const gchar *label, CK_OBJECT_CLASS klass)
+setup_unlock_object (GkmWrapPrompt *self,
+ const gchar *label,
+ CK_OBJECT_CLASS klass)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
+ const gchar *choice;
gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
-
- prompt = GKU_PROMPT (self);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ prompt = GCR_PROMPT (self);
- gku_prompt_set_title (prompt, prepare_unlock_object_title (klass));
- gku_prompt_set_primary_text (prompt, prepare_unlock_object_primary (klass));
+ gcr_prompt_set_title (prompt, calc_unlock_object_title (klass));
+ gcr_prompt_set_message (prompt, calc_unlock_object_primary (klass));
- text = prepare_unlock_object_secondary (klass, label);
- gku_prompt_set_secondary_text (prompt, text);
+ text = calc_unlock_object_secondary (klass, label);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- gku_prompt_hide_widget (prompt, "name_area");
- gku_prompt_hide_widget (prompt, "confirm_area");
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "options_area");
-
- /* TODO: After string freeze need to add a reason */
- if (!gkm_wrap_login_is_usable ())
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS, FALSE, NULL);
+ choice = NULL;
+ if (gkm_wrap_login_is_usable ())
+ choice = calc_unlock_object_choice (klass);
+ gcr_prompt_set_choice_label (prompt, choice);
}
static void
-prepare_unlock_prompt (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR attrs,
- CK_ULONG n_attrs, gboolean first)
+setup_unlock_prompt (GkmWrapPrompt *self,
+ CK_ATTRIBUTE_PTR attrs,
+ CK_ULONG n_attrs,
+ gboolean first)
{
CK_ATTRIBUTE_PTR attr;
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
const gchar *label = NULL;
CK_OBJECT_CLASS klass;
- g_assert (GKM_WRAP_IS_PROMPT (self));
-
- prompt = GKU_PROMPT (self);
-
- /* Hard reset on first prompt, soft on later */
- gku_prompt_reset (GKU_PROMPT (prompt), first);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ prompt = GCR_PROMPT (self);
/* Load up the object class */
if (!gkm_attributes_find_ulong (attrs, n_attrs, CKA_CLASS, &klass))
@@ -790,49 +751,45 @@ prepare_unlock_prompt (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR attrs,
if (klass == CKO_G_COLLECTION) {
if (is_login_keyring (attrs, n_attrs))
- prepare_unlock_keyring_login (self);
+ setup_unlock_keyring_login (self);
else
- prepare_unlock_keyring_other (self, label);
+ setup_unlock_keyring_other (self, label);
} else {
- prepare_unlock_object (self, label, klass);
+ setup_unlock_object (self, label, klass);
}
if (!first)
- gku_prompt_set_warning (GKU_PROMPT (self), _("The unlock password was incorrect"));
+ gcr_prompt_set_warning (prompt, _("The unlock password was incorrect"));
}
static void
-prepare_unlock_token (GkmWrapPrompt *self, CK_TOKEN_INFO_PTR tinfo)
+setup_unlock_token (GkmWrapPrompt *self,
+ CK_TOKEN_INFO_PTR tinfo)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
+ const gchar *choice;
gchar *label;
gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
-
- prompt = GKU_PROMPT (self);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ prompt = GCR_PROMPT (self);
label = g_strndup ((gchar*)tinfo->label, sizeof (tinfo->label));
g_strchomp (label);
/* Build up the prompt */
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_hide_widget (prompt, "confirm_area");
- gku_prompt_hide_widget (prompt, "original_area");
- gku_prompt_set_title (prompt, _("Unlock certificate/key storage"));
- gku_prompt_set_primary_text (prompt, _("Enter password to unlock the certificate/key storage"));
+ gcr_prompt_set_title (prompt, _("Unlock certificate/key storage"));
+ gcr_prompt_set_message (prompt, _("Enter password to unlock the certificate/key storage"));
/* TRANSLATORS: The storage is locked, and needs unlocking before the application can use it. */
text = g_strdup_printf (_("An application wants access to the certificate/key storage '%s', but it is locked"), label);
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "options_area");
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_IDLE, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_TIMEOUT, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS,
- gkm_wrap_login_is_usable (), NULL);
+ choice = NULL;
+ if (gkm_wrap_login_is_usable ())
+ choice = _("Automatically unlock whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
g_free (label);
}
@@ -896,9 +853,42 @@ fix_login_keyring_if_unlock_failed (GkmWrapPrompt *self, const gchar *password)
g_message ("fixed login keyring password to match login password");
}
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
+static gboolean
+gkm_wrap_prompt_prepare (GkmWrapPrompt *self)
+{
+ GError *error = NULL;
+
+ if (!self->initialized) {
+ if (!g_initable_init (G_INITABLE (self), NULL, &error)) {
+ g_warning ("couldn't create system prompt: %s", egg_error_message (error));
+ g_error_free (error);
+ return FALSE;
+ }
+ self->initialized = TRUE;
+ }
+
+ return TRUE;
+}
+
+static const gchar *
+gkm_wrap_prompt_request_password (GkmWrapPrompt *self)
+{
+ GError *error = NULL;
+ const gchar *password;
+
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+
+ if (!gkm_wrap_prompt_prepare (self))
+ return NULL;
+
+ password = gcr_prompt_password (GCR_PROMPT (self), NULL, &error);
+ if (error != NULL) {
+ g_warning ("couldn't prompt for password: %s", egg_error_message (error));
+ g_error_free (error);
+ }
+
+ return password;
+}
static void
gkm_wrap_prompt_init (GkmWrapPrompt *self)
@@ -919,7 +909,6 @@ gkm_wrap_prompt_finalize (GObject *obj)
while (!g_queue_is_empty(&self->pool))
g_free (g_queue_pop_head (&self->pool));
-
G_OBJECT_CLASS (gkm_wrap_prompt_parent_class)->finalize (obj);
}
@@ -938,14 +927,13 @@ gkm_wrap_prompt_class_init (GkmWrapPromptClass *klass)
typedef struct _CredentialPrompt {
GArray *template;
CK_ULONG n_template;
- gchar *password;
+ const gchar *password;
} CredentialPrompt;
static void
credential_prompt_free (gpointer user_data)
{
CredentialPrompt *data = user_data;
- egg_secure_strfree (data->password);
g_array_free (data->template, TRUE);
g_slice_free (CredentialPrompt, data);
}
@@ -956,10 +944,10 @@ gkm_wrap_prompt_for_credential (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE s
{
CredentialPrompt *data;
CK_ATTRIBUTE_PTR attr;
- CK_ULONG i;
CK_OBJECT_CLASS klass;
CK_OBJECT_HANDLE object;
GkmWrapPrompt *self;
+ CK_ULONG i;
g_return_val_if_fail (module, NULL);
g_return_val_if_fail (session, NULL);
@@ -976,8 +964,12 @@ gkm_wrap_prompt_for_credential (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE s
if (attr == NULL || attr->pValue != NULL)
return NULL;
+ self = g_object_new (GKM_TYPE_WRAP_PROMPT,
+ "timeout-seconds", -1,
+ "bus-name", the_prompter_name,
+ NULL);
+
/* Build up the prompt */
- self = g_object_new (GKM_WRAP_TYPE_PROMPT, NULL);
self->prompt_data = data = g_slice_new0 (CredentialPrompt);
self->destroy_data = credential_prompt_free;
self->module = module;
@@ -1006,8 +998,9 @@ gkm_wrap_prompt_do_credential (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR *template,
CK_ATTRIBUTE_PTR attr;
CK_ULONG n_attrs, n_options, i;
CredentialPrompt *data;
+ GError *error = NULL;
- g_return_val_if_fail (GKM_WRAP_IS_PROMPT (self), FALSE);
+ g_return_val_if_fail (GKM_IS_WRAP_PROMPT (self), FALSE);
g_return_val_if_fail (template, FALSE);
g_return_val_if_fail (n_template, FALSE);
@@ -1017,7 +1010,6 @@ gkm_wrap_prompt_do_credential (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR *template,
attrs = get_attributes_from_object (self, &n_attrs);
g_return_val_if_fail (attrs, FALSE);
- egg_secure_free (data->password);
data->password = NULL;
if (self->iteration == 0) {
@@ -1029,7 +1021,7 @@ gkm_wrap_prompt_do_credential (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR *template,
}
if (!data->password) {
- prepare_unlock_prompt (self, attrs, n_attrs, self->iteration == 1);
+ setup_unlock_prompt (self, attrs, n_attrs, self->iteration == 1);
/* Now load up the unlock options into the prompt*/
if (self->iteration == 1) {
@@ -1040,14 +1032,14 @@ gkm_wrap_prompt_do_credential (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR *template,
++(self->iteration);
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (self), g_object_unref);
-
- if (gku_prompt_get_response (GKU_PROMPT (self)) != GKU_RESPONSE_OK)
+ data->password = gkm_wrap_prompt_request_password (self);
+ if (data->password == NULL) {
+ if (error != NULL) {
+ g_warning ("couldn't prompt for password: %s", egg_error_message (error));
+ g_error_free (error);
+ }
return FALSE;
-
- data->password = gku_prompt_get_password (GKU_PROMPT (self), "password");
- g_return_val_if_fail (data->password, FALSE);
+ }
}
/* Truncate any extra options off the end of template */
@@ -1058,7 +1050,7 @@ gkm_wrap_prompt_do_credential (GkmWrapPrompt *self, CK_ATTRIBUTE_PTR *template,
/* Put the password into the template, always first */
attr = &g_array_index (data->template, CK_ATTRIBUTE, 0);
g_assert (attr->type == CKA_VALUE);
- attr->pValue = data->password;
+ attr->pValue = (gpointer)data->password;
attr->ulValueLen = strlen (data->password);
/* Tag any options onto the end of template */
@@ -1079,7 +1071,7 @@ gkm_wrap_prompt_done_credential (GkmWrapPrompt *self, CK_RV call_result)
CK_ULONG n_options, n_attrs;
CredentialPrompt *data;
- g_return_if_fail (GKM_WRAP_IS_PROMPT (self));
+ g_return_if_fail (GKM_IS_WRAP_PROMPT (self));
g_assert (self->destroy_data == credential_prompt_free);
data = self->prompt_data;
@@ -1111,37 +1103,35 @@ gkm_wrap_prompt_done_credential (GkmWrapPrompt *self, CK_RV call_result)
*/
static void
-prepare_init_token (GkmWrapPrompt *self, CK_TOKEN_INFO_PTR tinfo)
+setup_init_token (GkmWrapPrompt *self,
+ CK_TOKEN_INFO_PTR tinfo)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
+ const gchar *choice;
gchar *label;
gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (tinfo);
- prompt = GKU_PROMPT (self);
+ prompt = GCR_PROMPT (self);
label = g_strndup ((gchar*)tinfo->label, sizeof (tinfo->label));
g_strchomp (label);
/* Build up the prompt */
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "confirm_area");
- gku_prompt_hide_widget (prompt, "original_area");
- gku_prompt_set_title (prompt, _("New Password Required"));
- gku_prompt_set_primary_text (prompt, _("New password required for secure storage"));
+ gcr_prompt_set_password_new (prompt, TRUE);
+ gcr_prompt_set_title (prompt, _("New Password Required"));
+ gcr_prompt_set_message (prompt, _("New password required for secure storage"));
text = g_strdup_printf (_("In order to prepare '%s' for storage of certificates or keys, a password is required"), label);
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "options_area");
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_IDLE, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_TIMEOUT, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS,
- gkm_wrap_login_is_usable (), NULL);
+ choice = NULL;
+ if (gkm_wrap_login_is_usable ())
+ choice = _("Automatically unlock whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
g_free (label);
}
@@ -1152,16 +1142,19 @@ gkm_wrap_prompt_for_init_pin (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE ses
{
GkmWrapPrompt *self;
- g_assert (module);
+ g_assert (module != NULL);
if (pin != NULL || pin_len != 0)
return NULL;
+ self = g_object_new (GKM_TYPE_WRAP_PROMPT,
+ "timeout-seconds", -1,
+ "bus-name", the_prompter_name,
+ NULL);
+
/* Build up the prompt */
- self = g_object_new (GKM_WRAP_TYPE_PROMPT, NULL);
self->module = module;
self->session = session;
- self->destroy_data = (GDestroyNotify)egg_secure_strfree;
return self;
}
@@ -1171,35 +1164,25 @@ gkm_wrap_prompt_do_init_pin (GkmWrapPrompt *self, CK_RV last_result,
CK_UTF8CHAR_PTR *pin, CK_ULONG *n_pin)
{
CK_TOKEN_INFO tinfo;
+ const gchar *password;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->module);
g_assert (pin);
g_assert (n_pin);
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
- egg_secure_strfree (self->prompt_data);
- self->prompt_data = NULL;
-
if (!get_info_for_token (self, &tinfo))
return FALSE;
- /* Hard reset on first prompt, soft on later */
- gku_prompt_reset (GKU_PROMPT (self), last_result == CKR_OK);
-
- prepare_init_token (self, &tinfo);
+ setup_init_token (self, &tinfo);
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (self), g_object_unref);
-
- if (gku_prompt_get_response (GKU_PROMPT (self)) != GKU_RESPONSE_OK)
+ password = gkm_wrap_prompt_request_password (self);
+ if (password == NULL)
return FALSE;
- self->prompt_data = gku_prompt_get_password (GKU_PROMPT (self), "password");
- g_return_val_if_fail (self->prompt_data, FALSE);
-
- *pin = self->prompt_data;
- *n_pin = strlen (self->prompt_data);
+ self->prompt_data = (gpointer)password;
+ *pin = (gpointer)password;
+ *n_pin = strlen (password);
return TRUE;
}
@@ -1208,8 +1191,8 @@ gkm_wrap_prompt_done_init_pin (GkmWrapPrompt *self, CK_RV call_result)
{
CK_TOKEN_INFO tinfo;
- g_assert (GKM_WRAP_IS_PROMPT (self));
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ g_assert (self->destroy_data == NULL);
/* Save auto auto unlock */
if (call_result == CKR_OK && auto_unlock_should_attach (self)) {
@@ -1237,41 +1220,68 @@ set_pin_prompt_free (gpointer user_data)
}
static void
-prepare_set_token (GkmWrapPrompt *self, CK_TOKEN_INFO_PTR tinfo)
+setup_set_token_original (GkmWrapPrompt *self,
+ CK_TOKEN_INFO_PTR tinfo)
{
- GkuPrompt *prompt;
+ GcrPrompt *prompt;
gchar *label;
gchar *text;
- g_assert (GKM_WRAP_IS_PROMPT (self));
- g_assert (tinfo);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ g_assert (tinfo != NULL);
+ prompt = GCR_PROMPT (self);
- prompt = GKU_PROMPT (self);
+ label = g_strndup ((gchar*)tinfo->label, sizeof (tinfo->label));
+ g_strchomp (label);
+
+ /* Build up the prompt */
+ gcr_prompt_set_password_new (prompt, FALSE);
+ gcr_prompt_set_title (prompt, _("Change Password"));
+ gcr_prompt_set_message (prompt, _("Original password for secure storage"));
+
+ text = g_strdup_printf (_("To change the password for '%s', the original password is required"), label);
+ gcr_prompt_set_description (prompt, text);
+ g_free (text);
+
+ gcr_prompt_set_choice_label (prompt, NULL);
+ g_free (label);
+}
+
+
+static void
+setup_set_token_password (GkmWrapPrompt *self,
+ CK_TOKEN_INFO_PTR tinfo)
+{
+ GcrPrompt *prompt;
+ const gchar *choice;
+ gchar *label;
+ gchar *text;
+
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ g_assert (tinfo != NULL);
+ prompt = GCR_PROMPT (self);
label = g_strndup ((gchar*)tinfo->label, sizeof (tinfo->label));
g_strchomp (label);
/* Build up the prompt */
- gku_prompt_show_widget (prompt, "password_area");
- gku_prompt_show_widget (prompt, "confirm_area");
- gku_prompt_show_widget (prompt, "original_area");
- gku_prompt_set_title (prompt, _("Change Password"));
- gku_prompt_set_primary_text (prompt, _("Change password for secure storage"));
-
- text = g_strdup_printf (_("To change the password for '%s', the original and new passwords are required"), label);
- gku_prompt_set_secondary_text (prompt, text);
+ gcr_prompt_set_password_new (prompt, TRUE);
+ gcr_prompt_set_title (prompt, _("Change Password"));
+ gcr_prompt_set_message (prompt, _("Change password for secure storage"));
+
+ text = g_strdup_printf (_("Type a new password for '%s'"), label);
+ gcr_prompt_set_description (prompt, text);
g_free (text);
- gku_prompt_show_widget (prompt, "details_area");
- gku_prompt_show_widget (prompt, "options_area");
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_IDLE, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_TIMEOUT, FALSE, NULL);
- gku_prompt_set_unlock_sensitive (prompt, GCR_UNLOCK_OPTION_ALWAYS,
- gkm_wrap_login_is_usable (), NULL);
+ choice = NULL;
+ if (gkm_wrap_login_is_usable ())
+ choice = _("Automatically unlock whenever I'm logged in");
+ gcr_prompt_set_choice_label (prompt, choice);
g_free (label);
}
+
GkmWrapPrompt*
gkm_wrap_prompt_for_set_pin (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE session,
CK_UTF8CHAR_PTR old_pin, CK_ULONG n_old_pin,
@@ -1279,13 +1289,17 @@ gkm_wrap_prompt_for_set_pin (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE sess
{
GkmWrapPrompt *self;
- g_assert (module);
+ g_assert (module != NULL);
if (new_pin != NULL || n_new_pin != 0)
return NULL;
+ self = g_object_new (GKM_TYPE_WRAP_PROMPT,
+ "timeout-seconds", -1,
+ "bus-name", the_prompter_name,
+ NULL);
+
/* Build up the prompt */
- self = g_object_new (GKM_WRAP_TYPE_PROMPT, NULL);
self->module = module;
self->session = session;
self->destroy_data = set_pin_prompt_free;
@@ -1302,8 +1316,9 @@ gkm_wrap_prompt_do_set_pin (GkmWrapPrompt *self, CK_RV last_result,
gboolean initializing = FALSE;
CK_TOKEN_INFO tinfo;
SetPinPrompt *data;
+ const gchar *password;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->module);
g_assert (old_pin);
g_assert (n_old_pin);
@@ -1316,37 +1331,32 @@ gkm_wrap_prompt_do_set_pin (GkmWrapPrompt *self, CK_RV last_result,
if (!get_info_for_token (self, &tinfo))
return FALSE;
- /* Hard reset on first prompt, soft on later */
- gku_prompt_reset (GKU_PROMPT (self), last_result == CKR_OK);
-
initializing = !(tinfo.flags & CKF_USER_PIN_INITIALIZED);
- if (initializing)
- prepare_init_token (self, &tinfo);
- else
- prepare_set_token (self, &tinfo);
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (self), g_object_unref);
-
- if (gku_prompt_get_response (GKU_PROMPT (self)) != GKU_RESPONSE_OK)
- return FALSE;
-
- egg_secure_strfree (data->password);
- data->password = gku_prompt_get_password (GKU_PROMPT (self), "password");
- g_return_val_if_fail (data->password, FALSE);
-
- *new_pin = (guchar*)data->password;
- *n_new_pin = strlen (data->password);
-
- if (!initializing) {
+ /* Prompt for the original password */
+ if (!initializing || last_result != CKR_OK) {
+ setup_set_token_original (self, &tinfo);
+ password = gkm_wrap_prompt_request_password (self);
+ if (password == NULL)
+ return FALSE;
egg_secure_strfree (data->original);
- data->original = gku_prompt_get_password (GKU_PROMPT (self), "original");
- g_return_val_if_fail (data->original, FALSE);
+ data->original = egg_secure_strdup (password);
+ }
- *old_pin = (guchar*)data->original;
- *n_old_pin = strlen (data->original);
+ /* Prompt for the new password */
+ if (data->password == NULL) {
+ setup_set_token_password (self, &tinfo);
+ password = gkm_wrap_prompt_request_password (self);
+ if (password == NULL)
+ return FALSE;
+ data->password = egg_secure_strdup (password);
}
+ *new_pin = (guchar *)data->password;
+ *n_new_pin = data->password ? strlen (data->password) : 0;
+ *old_pin = (guchar *)data->original;
+ *n_old_pin = data->original ? strlen (data->original) : 0;
+
return TRUE;
}
@@ -1356,7 +1366,7 @@ gkm_wrap_prompt_done_set_pin (GkmWrapPrompt *self, CK_RV call_result)
CK_TOKEN_INFO tinfo;
SetPinPrompt *data;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->destroy_data == set_pin_prompt_free);
data = self->prompt_data;
@@ -1399,12 +1409,15 @@ login_prompt_for_specific (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE sessio
if (rv != CKR_OK || always != CK_TRUE)
return NULL;
+ self = g_object_new (GKM_TYPE_WRAP_PROMPT,
+ "timeout-seconds", -1,
+ "bus-name", the_prompter_name,
+ NULL);
+
/* Build up the prompt */
- self = g_object_new (GKM_WRAP_TYPE_PROMPT, NULL);
self->module = module;
self->session = session;
self->object = object;
- self->destroy_data = (GDestroyNotify)egg_secure_strfree;
return self;
}
@@ -1413,43 +1426,35 @@ static gboolean
login_prompt_do_specific (GkmWrapPrompt *self, CK_RV last_result,
CK_UTF8CHAR_PTR *pin, CK_ULONG *n_pin)
{
+ const gchar *password = NULL;
CK_ATTRIBUTE_PTR attrs;
CK_ULONG n_attrs;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (pin);
g_assert (n_pin);
-
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
- egg_secure_strfree (self->prompt_data);
- self->prompt_data = NULL;
-
attrs = get_attributes_from_object (self, &n_attrs);
g_return_val_if_fail (attrs, FALSE);
if (self->iteration == 0) {
++(self->iteration);
- self->prompt_data = auto_unlock_lookup_object (attrs, n_attrs);
+ password = auto_unlock_lookup_object (attrs, n_attrs);
} else if (self->iteration == 1 && last_result == CKR_PIN_INCORRECT) {
auto_unlock_remove_object (attrs, n_attrs);
}
- if (!self->prompt_data) {
- prepare_unlock_prompt (self, attrs, n_attrs, self->iteration == 1);
-
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (self), g_object_unref);
+ if (!password) {
+ setup_unlock_prompt (self, attrs, n_attrs, self->iteration == 1);
- if (gku_prompt_get_response (GKU_PROMPT (self)) != GKU_RESPONSE_OK)
+ password = gkm_wrap_prompt_request_password (self);
+ if (password == NULL)
return FALSE;
-
- self->prompt_data = gku_prompt_get_password (GKU_PROMPT (self), "password");
- g_return_val_if_fail (self->prompt_data, FALSE);
}
- *pin = self->prompt_data;
- *n_pin = strlen (self->prompt_data);
+ self->prompt_data = (gpointer)password;
+ *pin = (guchar *)password;
+ *n_pin = strlen (password);
return TRUE;
}
@@ -1459,8 +1464,8 @@ login_prompt_done_specific (GkmWrapPrompt *self, CK_RV call_result)
CK_ATTRIBUTE_PTR attrs;
CK_ULONG n_attrs;
- g_assert (GKM_WRAP_IS_PROMPT (self));
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ g_assert (self->destroy_data == NULL);
/* Possibly save away auto unlock */
if (call_result == CKR_OK && auto_unlock_should_attach (self)) {
@@ -1474,13 +1479,16 @@ login_prompt_for_user (CK_FUNCTION_LIST_PTR module, CK_SESSION_HANDLE session)
{
GkmWrapPrompt *self;
- g_assert (module);
+ g_assert (module != NULL);
+
+ self = g_object_new (GKM_TYPE_WRAP_PROMPT,
+ "timeout-seconds", -1,
+ "bus-name", the_prompter_name,
+ NULL);
/* Build up the prompt */
- self = g_object_new (GKM_WRAP_TYPE_PROMPT, NULL);
self->module = module;
self->session = session;
- self->destroy_data = (GDestroyNotify)egg_secure_strfree;
return self;
}
@@ -1490,45 +1498,35 @@ login_prompt_do_user (GkmWrapPrompt *self, CK_RV last_result,
CK_UTF8CHAR_PTR *pin, CK_ULONG *n_pin)
{
CK_TOKEN_INFO tinfo;
+ const gchar *password = NULL;
- g_assert (GKM_WRAP_IS_PROMPT (self));
+ g_assert (GKM_IS_WRAP_PROMPT (self));
g_assert (self->module);
g_assert (pin);
g_assert (n_pin);
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
- egg_secure_strfree (self->prompt_data);
- self->prompt_data = NULL;
-
if (!get_info_for_token (self, &tinfo))
return FALSE;
if (self->iteration == 0) {
++(self->iteration);
- self->prompt_data = auto_unlock_lookup_token (&tinfo);
+ password = auto_unlock_lookup_token (&tinfo);
} else if (self->iteration == 1 && last_result == CKR_PIN_INCORRECT) {
auto_unlock_remove_token (&tinfo);
}
- if (!self->prompt_data) {
- /* Hard reset on first prompt, soft on later */
- gku_prompt_reset (GKU_PROMPT (self), last_result == CKR_OK);
-
- prepare_unlock_token (self, &tinfo);
+ if (!password) {
+ setup_unlock_token (self, &tinfo);
- gku_prompt_request_attention_sync (NULL, on_prompt_attention,
- g_object_ref (self), g_object_unref);
-
- if (gku_prompt_get_response (GKU_PROMPT (self)) != GKU_RESPONSE_OK)
+ password = gkm_wrap_prompt_request_password (self);
+ if (password == NULL)
return FALSE;
-
- self->prompt_data = gku_prompt_get_password (GKU_PROMPT (self), "password");
- g_return_val_if_fail (self->prompt_data, FALSE);
}
- *pin = self->prompt_data;
- *n_pin = strlen (self->prompt_data);
+ self->prompt_data = (gpointer)password;
+ *pin = (guchar *)password;
+ *n_pin = strlen (password);
return TRUE;
}
@@ -1537,8 +1535,8 @@ login_prompt_done_user (GkmWrapPrompt *self, CK_RV call_result)
{
CK_TOKEN_INFO tinfo;
- g_assert (GKM_WRAP_IS_PROMPT (self));
- g_assert (self->destroy_data == (GDestroyNotify)egg_secure_strfree);
+ g_assert (GKM_IS_WRAP_PROMPT (self));
+ g_assert (self->destroy_data == NULL);
/* Save the options, and possibly auto unlock */
if (call_result == CKR_OK && auto_unlock_should_attach (self)) {
@@ -1572,7 +1570,7 @@ gboolean
gkm_wrap_prompt_do_login (GkmWrapPrompt *self, CK_USER_TYPE user_type, CK_RV last_result,
CK_UTF8CHAR_PTR *pin, CK_ULONG *n_pin)
{
- g_return_val_if_fail (GKM_WRAP_IS_PROMPT (self), FALSE);
+ g_return_val_if_fail (GKM_IS_WRAP_PROMPT (self), FALSE);
g_return_val_if_fail (pin, FALSE);
g_return_val_if_fail (n_pin, FALSE);
@@ -1589,7 +1587,7 @@ gkm_wrap_prompt_do_login (GkmWrapPrompt *self, CK_USER_TYPE user_type, CK_RV las
void
gkm_wrap_prompt_done_login (GkmWrapPrompt *self, CK_USER_TYPE user_type, CK_RV call_result)
{
- g_return_if_fail (GKM_WRAP_IS_PROMPT (self));
+ g_return_if_fail (GKM_IS_WRAP_PROMPT (self));
switch (user_type) {
case CKU_CONTEXT_SPECIFIC:
@@ -1600,3 +1598,9 @@ gkm_wrap_prompt_done_login (GkmWrapPrompt *self, CK_USER_TYPE user_type, CK_RV c
break;
}
}
+
+void
+gkm_wrap_prompt_set_prompter_name (const gchar *prompter_name)
+{
+ the_prompter_name = g_intern_string (prompter_name);
+}
diff --git a/pkcs11/wrap-layer/gkm-wrap-prompt.h b/pkcs11/wrap-layer/gkm-wrap-prompt.h
index a736707..47c419c 100644
--- a/pkcs11/wrap-layer/gkm-wrap-prompt.h
+++ b/pkcs11/wrap-layer/gkm-wrap-prompt.h
@@ -24,25 +24,11 @@
#include <glib-object.h>
-#include "ui/gku-prompt.h"
-
#include "pkcs11/pkcs11.h"
-#define GKM_WRAP_TYPE_PROMPT (gkm_wrap_prompt_get_type ())
-#define GKM_WRAP_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKM_WRAP_TYPE_PROMPT, GkmWrapPrompt))
-#define GKM_WRAP_PROMPT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GKM_WRAP_TYPE_PROMPT, GkmWrapPromptClass))
-#define GKM_WRAP_IS_PROMPT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKM_WRAP_TYPE_PROMPT))
-#define GKM_WRAP_IS_PROMPT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKM_WRAP_TYPE_PROMPT))
-#define GKM_WRAP_PROMPT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKM_WRAP_TYPE_PROMPT, GkmWrapPromptClass))
-
typedef struct _GkmWrapPrompt GkmWrapPrompt;
-typedef struct _GkmWrapPromptClass GkmWrapPromptClass;
-
-struct _GkmWrapPromptClass {
- GkuPromptClass parent_class;
-};
-GType gkm_wrap_prompt_get_type (void);
+void gkm_wrap_prompt_set_prompter_name (const gchar *prompter_name);
GkmWrapPrompt* gkm_wrap_prompt_for_credential (CK_FUNCTION_LIST_PTR module,
CK_SESSION_HANDLE session,
diff --git a/pkcs11/wrap-layer/tests/Makefile.am b/pkcs11/wrap-layer/tests/Makefile.am
index 90bbd21..fd9e3b1 100644
--- a/pkcs11/wrap-layer/tests/Makefile.am
+++ b/pkcs11/wrap-layer/tests/Makefile.am
@@ -5,13 +5,14 @@ INCLUDES = \
-I$(top_srcdir)/pkcs11 \
-DSRCDIR="\"@abs_srcdir \"" \
-DWITH_TESTABLE \
+ -DGCR_API_SUBJECT_TO_CHANGE \
+ $(GCR_BASE_CFLAGS) \
$(GLIB_CFLAGS)
LDADD = \
$(top_builddir)/pkcs11/wrap-layer/libgkm-wrap-layer.la \
libgkm-mock-secret-store.a \
$(top_builddir)/pkcs11/gkm/libgkm.la \
- $(top_builddir)/ui/libgku-prompt-testable.la \
$(top_builddir)/egg/libegg.la \
$(GCR_BASE_LIBS) \
$(GLIB_LIBS)
diff --git a/pkcs11/wrap-layer/tests/mock-secret-store.c b/pkcs11/wrap-layer/tests/mock-secret-store.c
index cb57b7f..7e8e08e 100644
--- a/pkcs11/wrap-layer/tests/mock-secret-store.c
+++ b/pkcs11/wrap-layer/tests/mock-secret-store.c
@@ -29,8 +29,6 @@
#include "wrap-layer/gkm-wrap-layer.h"
-#include "ui/gku-prompt.h"
-
static guint secret_identifier = 8800;
EGG_SECURE_GLIB_DEFINITIONS ();
diff --git a/pkcs11/wrap-layer/tests/test-create-credential.c b/pkcs11/wrap-layer/tests/test-create-credential.c
index 5a3b7c9..d0b544d 100644
--- a/pkcs11/wrap-layer/tests/test-create-credential.c
+++ b/pkcs11/wrap-layer/tests/test-create-credential.c
@@ -21,14 +21,17 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
#include "egg/egg-testing.h"
-#include "wrap-layer/gkm-wrap-layer.h"
+#include <gcr/gcr-base.h>
-#include "ui/gku-prompt.h"
+#include <glib-object.h>
#include <string.h>
@@ -45,6 +48,7 @@ setup (Test *test, gconstpointer unused)
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
+ const gchar *prompter;
CK_ULONG count;
CK_RV rv;
@@ -62,7 +66,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -92,7 +97,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -114,7 +120,7 @@ test_ok_password (Test *test, gconstpointer unused)
CK_OBJECT_HANDLE cred = 0;
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo", NULL);
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -134,8 +140,8 @@ test_bad_password_then_cancel (Test *test, gconstpointer unused)
CK_OBJECT_HANDLE cred = 0;
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("bad password");
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_ok ("bad password", NULL);
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
@@ -154,7 +160,7 @@ test_cancel_immediately (Test *test, gconstpointer unused)
CK_OBJECT_HANDLE cred = 0;
CK_RV rv;
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &cred);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
diff --git a/pkcs11/wrap-layer/tests/test-init-pin.c b/pkcs11/wrap-layer/tests/test-init-pin.c
index 1f9e7a1..5f8af50 100644
--- a/pkcs11/wrap-layer/tests/test-init-pin.c
+++ b/pkcs11/wrap-layer/tests/test-init-pin.c
@@ -21,14 +21,15 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
-#include "wrap-layer/gkm-wrap-layer.h"
-
-#include "ui/gku-prompt.h"
+#include <gcr/gcr-base.h>
#include <string.h>
@@ -44,6 +45,7 @@ setup (Test *test, gconstpointer unused)
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
+ const gchar *prompter;
CK_RV rv;
/* Always start off with test test->functions */
@@ -55,7 +57,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -73,7 +76,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -89,7 +93,7 @@ test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("new");
+ gcr_mock_prompter_expect_password_ok ("new", NULL);
rv = (test->module->C_InitPIN) (test->session, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
diff --git a/pkcs11/wrap-layer/tests/test-login-auto.c b/pkcs11/wrap-layer/tests/test-login-auto.c
index 8ab80d9..789c6d6 100644
--- a/pkcs11/wrap-layer/tests/test-login-auto.c
+++ b/pkcs11/wrap-layer/tests/test-login-auto.c
@@ -21,14 +21,17 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
-#include "wrap-layer/gkm-wrap-layer.h"
+#include <gcr/gcr-base.h>
-#include "ui/gku-prompt.h"
+#include <glib-object.h>
#include <string.h>
@@ -49,6 +52,7 @@ setup (Test *test, gconstpointer unused)
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
CK_ULONG count;
+ const gchar *prompter;
CK_RV rv;
CK_BBOOL always = TRUE;
@@ -71,7 +75,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -113,7 +118,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
test->key = 0;
test->collection = 0;
@@ -133,7 +139,11 @@ test_specific (Test *test, gconstpointer unused)
CK_RV rv;
/* Login with prompt */
- gku_prompt_dummy_queue_auto_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo",
+ "choice-label", "Automatically unlock this key whenever I'm logged in",
+ "choice-chosen", TRUE,
+ NULL);
+
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -142,7 +152,8 @@ test_specific (Test *test, gconstpointer unused)
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
- gku_prompt_dummy_prepare_response ();
+ g_assert (!gcr_mock_prompter_is_expecting ());
+
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -154,7 +165,8 @@ test_specific (Test *test, gconstpointer unused)
gkm_assert_cmprv (rv, ==, CKR_OK);
/* This should prompt again, as stored password is now wrong */
- gku_prompt_dummy_queue_ok_password ("other");
+ gcr_mock_prompter_expect_password_ok ("other", NULL);
+
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
@@ -165,14 +177,19 @@ test_user_token (Test *test, gconstpointer unused)
CK_RV rv;
/* Login with prompt */
- gku_prompt_dummy_queue_auto_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo",
+ "choice-label", "Automatically unlock whenever I'm logged in",
+ "choice-chosen", TRUE,
+ NULL);
+
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
rv = (test->module->C_Logout) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
- gku_prompt_dummy_prepare_response ();
+ g_assert (!gcr_mock_prompter_is_expecting ());
+
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
rv = (test->module->C_Logout) (test->session);
@@ -182,7 +199,8 @@ test_user_token (Test *test, gconstpointer unused)
gkm_mock_module_set_pin ("other");
/* This should prompt again, as stored password is now wrong */
- gku_prompt_dummy_queue_ok_password ("other");
+ gcr_mock_prompter_expect_password_ok ("other", NULL);
+
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
@@ -201,14 +219,19 @@ test_unlock_keyring (Test *test, gconstpointer unused)
};
/* Create credential with prompt */
- gku_prompt_dummy_queue_auto_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo",
+ "choice-label", "Automatically unlock this keyring whenever I'm logged in",
+ "choice-chosen", TRUE,
+ NULL);
+
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
rv = (test->module->C_DestroyObject) (test->session, credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
/* No further prompting should be shown, uses stored password */
- gku_prompt_dummy_prepare_response ();
+ g_assert (!gcr_mock_prompter_is_expecting ());
+
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -216,7 +239,8 @@ test_unlock_keyring (Test *test, gconstpointer unused)
gkm_mock_module_set_pin ("other");
/* This should prompt again, as stored password is now wrong */
- gku_prompt_dummy_queue_ok_password ("other");
+ gcr_mock_prompter_expect_password_ok ("other", NULL);
+
rv = (test->module->C_CreateObject) (test->session, attrs, G_N_ELEMENTS (attrs), &credential);
gkm_assert_cmprv (rv, ==, CKR_OK);
}
diff --git a/pkcs11/wrap-layer/tests/test-login-specific.c b/pkcs11/wrap-layer/tests/test-login-specific.c
index a91480e..23a4af0 100644
--- a/pkcs11/wrap-layer/tests/test-login-specific.c
+++ b/pkcs11/wrap-layer/tests/test-login-specific.c
@@ -21,14 +21,17 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
-#include "wrap-layer/gkm-wrap-layer.h"
+#include <gcr/gcr-base.h>
-#include "ui/gku-prompt.h"
+#include <glib-object.h>
typedef struct {
CK_FUNCTION_LIST prompt_login_functions;
@@ -43,6 +46,7 @@ setup (Test *test, gconstpointer unused)
CK_OBJECT_HANDLE key;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
+ const gchar *prompter;
CK_ULONG count;
CK_RV rv;
@@ -62,7 +66,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->prompt_login_functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -96,7 +101,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -112,7 +118,7 @@ test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo", NULL);
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -123,8 +129,8 @@ test_bad_password_then_cancel (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("bad password");
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_ok ("bad password", NULL);
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
@@ -135,7 +141,7 @@ test_cancel_immediately (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_Login) (test->session, CKU_CONTEXT_SPECIFIC, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
diff --git a/pkcs11/wrap-layer/tests/test-login-user.c b/pkcs11/wrap-layer/tests/test-login-user.c
index 61bd34c..e67e89a 100644
--- a/pkcs11/wrap-layer/tests/test-login-user.c
+++ b/pkcs11/wrap-layer/tests/test-login-user.c
@@ -21,14 +21,17 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
-#include "wrap-layer/gkm-wrap-layer.h"
+#include <gcr/gcr-base.h>
-#include "ui/gku-prompt.h"
+#include <glib-object.h>
typedef struct {
CK_FUNCTION_LIST prompt_login_functions;
@@ -42,6 +45,7 @@ setup (Test *test, gconstpointer unused)
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
+ const gchar *prompter;
CK_RV rv;
/* Always start off with test functions */
@@ -53,7 +57,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->prompt_login_functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -71,7 +76,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -105,7 +111,7 @@ test_ok_password (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("booo");
+ gcr_mock_prompter_expect_password_ok ("booo", NULL);
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -116,8 +122,8 @@ test_bad_password_then_cancel (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_password ("bad password");
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_ok ("bad password", NULL);
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
@@ -128,7 +134,7 @@ test_cancel_immediately (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_no ();
+ gcr_mock_prompter_expect_password_cancel ();
rv = (test->module->C_Login) (test->session, CKU_USER, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_PIN_INCORRECT);
diff --git a/pkcs11/wrap-layer/tests/test-set-pin.c b/pkcs11/wrap-layer/tests/test-set-pin.c
index 164bde1..de92cab 100644
--- a/pkcs11/wrap-layer/tests/test-set-pin.c
+++ b/pkcs11/wrap-layer/tests/test-set-pin.c
@@ -21,14 +21,17 @@
#include "config.h"
+#include "wrap-layer/gkm-wrap-layer.h"
+#include "wrap-layer/gkm-wrap-prompt.h"
+
#include "egg/egg-testing.h"
#include "gkm/gkm-mock.h"
#include "gkm/gkm-test.h"
-#include "wrap-layer/gkm-wrap-layer.h"
+#include <gcr/gcr-base.h>
-#include "ui/gku-prompt.h"
+#include <glib-object.h>
typedef struct {
CK_FUNCTION_LIST functions;
@@ -42,6 +45,7 @@ setup (Test *test, gconstpointer unused)
CK_FUNCTION_LIST_PTR funcs;
CK_SLOT_ID slot_id;
CK_ULONG n_slots = 1;
+ const gchar *prompter;
CK_RV rv;
/* Always start off with test test->functions */
@@ -53,7 +57,8 @@ setup (Test *test, gconstpointer unused)
gkm_wrap_layer_add_module (&test->functions);
test->module = gkm_wrap_layer_get_functions ();
- gku_prompt_dummy_prepare_response ();
+ prompter = gcr_mock_prompter_start ();
+ gkm_wrap_prompt_set_prompter_name (prompter);
/* Open a test->session */
rv = (test->module->C_Initialize) (NULL);
@@ -71,7 +76,8 @@ teardown (Test *test, gconstpointer unused)
{
CK_RV rv;
- g_assert (!gku_prompt_dummy_have_response ());
+ g_assert (!gcr_mock_prompter_is_expecting ());
+ gcr_mock_prompter_stop ();
rv = (test->module->C_CloseSession) (test->session);
gkm_assert_cmprv (rv, ==, CKR_OK);
@@ -87,7 +93,8 @@ test_ok_passwords (Test *test, gconstpointer unused)
{
CK_RV rv;
- gku_prompt_dummy_queue_ok_passwords ("booo", "new");
+ gcr_mock_prompter_expect_password_ok ("booo", NULL);
+ gcr_mock_prompter_expect_password_ok ("new", NULL);
rv = (test->module->C_SetPIN) (test->session, NULL, 0, NULL, 0);
gkm_assert_cmprv (rv, ==, CKR_OK);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7013fbd..1f92a0d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -19,6 +19,3 @@ pkcs11/ssh-store/gkm-ssh-private-key.c
pkcs11/wrap-layer/gkm-wrap-login.c
pkcs11/wrap-layer/gkm-wrap-prompt.c
tool/gkr-tool.c
-ui/gku-prompt-tool.c
-[type: gettext/glade]ui/gku-prompt.ui
-ui/gnome-keyring-prompt.desktop.in.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]