[gnome-keyring: 7/8] [gpg-agent] Allow unlock options to be used.



commit 606b73fda831a34612e5f12af4ae94d4e30c5785
Author: Stef Walter <stef memberwebs com>
Date:   Sun Jun 13 02:45:08 2010 +0000

    [gpg-agent] Allow unlock options to be used.
    
     * The lock after X minutes options.

 daemon/gpg-agent/gkd-gpg-agent-ops.c |   45 +++++++++++++++++++++++++++-------
 ui/gku-prompt.ui                     |   30 ++++++++++------------
 2 files changed, 50 insertions(+), 25 deletions(-)
---
diff --git a/daemon/gpg-agent/gkd-gpg-agent-ops.c b/daemon/gpg-agent/gkd-gpg-agent-ops.c
index 28371c7..5defe24 100644
--- a/daemon/gpg-agent/gkd-gpg-agent-ops.c
+++ b/daemon/gpg-agent/gkd-gpg-agent-ops.c
@@ -158,7 +158,7 @@ find_saved_items (GP11Session *session, GP11Attributes *attrs)
 
 static void
 do_save_password (GP11Session *session, const gchar *keyid, const gchar *description,
-                  const gchar *password, const gchar *collection_id)
+                  const gchar *password, GP11Attributes *options)
 {
 	GP11Attributes *attrs;
 	gpointer identifier;
@@ -168,8 +168,8 @@ do_save_password (GP11Session *session, const gchar *keyid, const gchar *descrip
 	GP11Object *item;
 	gchar *text;
 	gchar *label;
+	gint i;
 
-	g_assert (collection_id);
 	g_assert (password);
 	g_assert (keyid);
 
@@ -179,9 +179,12 @@ do_save_password (GP11Session *session, const gchar *keyid, const gchar *descrip
 	/* Build up basic set of attributes */
 	gp11_attributes_add_boolean (attrs, CKA_TOKEN, TRUE);
 	gp11_attributes_add_ulong (attrs, CKA_CLASS, CKO_SECRET_KEY);
-	gp11_attributes_add_string (attrs, CKA_G_COLLECTION, collection_id);
 	keyid_to_field_attribute (keyid, attrs);
 
+	/* Bring in all the unlock options */
+	for (i = 0; options && i < gp11_attributes_count (options); ++i)
+		gp11_attributes_add (attrs, gp11_attributes_at (options, i));
+
 	/* Find a previously stored object like this, and replace if so */
 	previous = find_saved_items (session, attrs);
 	if (previous) {
@@ -290,6 +293,7 @@ prepare_password_prompt (GP11Session *session, const gchar *errmsg, const gchar
 {
 	GkuPrompt *prompt;
 	GError *error = NULL;
+	gboolean auto_unlock;
 	GList *objects;
 
 	g_assert (GP11_IS_SESSION (session));
@@ -306,6 +310,11 @@ prepare_password_prompt (GP11Session *session, const gchar *errmsg, const gchar
 	else
 		gku_prompt_hide_widget (prompt, "confirm_area");
 	gku_prompt_show_widget (prompt, "password_area");
+	gku_prompt_show_widget (prompt, "details_area");
+	gku_prompt_show_widget (prompt, "options_area");
+	gku_prompt_show_widget (prompt, "lock_area");
+
+	auto_unlock = FALSE;
 
 	/* Check if the login keyring is usable */
 	objects = gp11_session_find_objects (session, &error,
@@ -321,11 +330,14 @@ prepare_password_prompt (GP11Session *session, const gchar *errmsg, const gchar
 		g_warning ("gpg agent couldn't lookup for login keyring: %s", egg_error_message (error));
 		g_clear_error (&error);
 	} else if (objects) {
-		gku_prompt_show_widget (prompt, "details_area");
-		gku_prompt_show_widget (prompt, "lock_area");
-		gku_prompt_hide_widget (prompt, "options_area");
+		auto_unlock = TRUE;
 	}
 
+	if (auto_unlock)
+		gku_prompt_show_widget (prompt, "auto_area");
+	else
+		gku_prompt_hide_widget (prompt, "auto_area");
+
 	gp11_list_unref_free (objects);
 
 	return prompt;
@@ -342,6 +354,7 @@ static gchar*
 do_get_password (GP11Session *session, const gchar *keyid, const gchar *errmsg,
                  const gchar *prompt_text, const gchar *description, gboolean confirm)
 {
+	GP11Attributes *attrs;
 	gchar *password = NULL;
 	gint value = 0;
 	GkuPrompt *prompt;
@@ -363,9 +376,23 @@ do_get_password (GP11Session *session, const gchar *keyid, const gchar *errmsg,
 		password = gku_prompt_get_password (prompt, "password");
 		g_return_val_if_fail (password, NULL);
 
-		/* Save away the password appropriately */
-		gku_prompt_get_unlock_option (prompt, GKU_UNLOCK_AUTO, &value);
-		do_save_password (session, keyid, description, password, value == 0 ? "session" : "login");
+		/* Load up the save options */
+		attrs = gp11_attributes_new ();
+
+		if (gku_prompt_get_unlock_option (prompt, GKU_UNLOCK_AUTO, &value))
+			gp11_attributes_add_string (attrs, CKA_G_COLLECTION, "login");
+		else
+			gp11_attributes_add_string (attrs, CKA_G_COLLECTION, "session");
+
+		if (gku_prompt_get_unlock_option (prompt, GKU_UNLOCK_IDLE, &value) && value > 0)
+			gp11_attributes_add_ulong (attrs, CKA_G_DESTRUCT_IDLE, value);
+
+		if (gku_prompt_get_unlock_option (prompt, GKU_UNLOCK_TIMEOUT, &value) && value > 0)
+			gp11_attributes_add_ulong (attrs, CKA_G_DESTRUCT_AFTER, value);
+
+		/* Now actually save the password */
+		do_save_password (session, keyid, description, password, attrs);
+		gp11_attributes_unref (attrs);
 	}
 
 	g_object_unref (prompt);
diff --git a/ui/gku-prompt.ui b/ui/gku-prompt.ui
index 91b4b5e..a480f64 100644
--- a/ui/gku-prompt.ui
+++ b/ui/gku-prompt.ui
@@ -9,13 +9,11 @@
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
             <property name="border_width">6</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">12</property>
             <child>
               <object class="GtkHBox" id="hbox1">
@@ -37,7 +35,6 @@
                 <child>
                   <object class="GtkVBox" id="vbox3">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">12</property>
                     <child>
                       <object class="GtkLabel" id="prompt_label">
@@ -66,7 +63,6 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
                     <child>
                       <object class="GtkVBox" id="prompt_area">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkHBox" id="name_area">
@@ -166,7 +162,6 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
                         </child>
                         <child>
                           <object class="GtkVBox" id="confirm_area">
-                            <property name="orientation">vertical</property>
                             <property name="spacing">6</property>
                             <child>
                               <object class="GtkHBox" id="confirm_box">
@@ -261,19 +256,22 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
                     <child>
                       <object class="GtkVBox" id="vbox2">
                         <property name="visible">True</property>
-                        <property name="orientation">vertical</property>
                         <property name="spacing">6</property>
                         <child>
                           <object class="GtkVBox" id="lock_area">
-                            <property name="orientation">vertical</property>
                             <property name="spacing">6</property>
                             <child>
-                              <object class="GtkCheckButton" id="auto_unlock_check">
-                                <property name="label" translatable="yes">Automatically unlock this keyring whenever I'm logged in</property>
+                              <object class="GtkAlignment" id="auto_area">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="receives_default">False</property>
-                                <property name="draw_indicator">True</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="auto_unlock_check">
+                                    <property name="label" translatable="yes">Automatically unlock this keyring whenever I'm logged in</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                </child>
                               </object>
                               <packing>
                                 <property name="position">0</property>
@@ -375,11 +373,11 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
   </object>
   <object class="GtkSizeGroup" id="prompt_label_sizegroup">
     <widgets>
-      <widget name="name_label"/>
-      <widget name="original_label"/>
-      <widget name="password_label"/>
-      <widget name="confirm_label"/>
       <widget name="strength_label"/>
+      <widget name="confirm_label"/>
+      <widget name="password_label"/>
+      <widget name="original_label"/>
+      <widget name="name_label"/>
     </widgets>
   </object>
 </interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]