seahorse r2283 - in trunk: . daemon gkr libseahorse pgp src ssh



Author: nnielsen
Date: Sat Jul 19 17:16:27 2008
New Revision: 2283
URL: http://svn.gnome.org/viewvc/seahorse?rev=2283&view=rev

Log:
	* daemon/seahorse-service.c:
	* gkr/seahorse-gkeyring-source.c:
	* libseahorse/seahorse-source.c:
	* libseahorse/seahorse-source.h:
	* libseahorse/seahorse-util.c:
	* libseahorse/seahorse-util.h:
	* pgp/seahorse-gpgmex-op.c:
	* pgp/seahorse-pgp-key-properties.c:
	* src/seahorse-key-manager-store.c:
	* ssh/seahorse-ssh-key-properties.c:
	* ssh/seahrose-ssh-operation.c:
	* ssh/seahorse-ssh-source.c:
	* ssh/seahorse-ssh-source.h: Remove the exporting of secret keys from 
	the SeahorseSource interface, and push this into the modules.


Modified:
   trunk/ChangeLog
   trunk/daemon/seahorse-service.c
   trunk/gkr/seahorse-gkeyring-source.c
   trunk/libseahorse/seahorse-source.c
   trunk/libseahorse/seahorse-source.h
   trunk/libseahorse/seahorse-util.c
   trunk/libseahorse/seahorse-util.h
   trunk/pgp/seahorse-gpgmex-op.c
   trunk/pgp/seahorse-pgp-key-properties.c
   trunk/src/seahorse-key-manager-store.c
   trunk/ssh/seahorse-ssh-key-properties.c
   trunk/ssh/seahorse-ssh-operation.c
   trunk/ssh/seahorse-ssh-source.c
   trunk/ssh/seahorse-ssh-source.h

Modified: trunk/daemon/seahorse-service.c
==============================================================================
--- trunk/daemon/seahorse-service.c	(original)
+++ trunk/daemon/seahorse-service.c	Sat Jul 19 17:16:27 2008
@@ -206,7 +206,7 @@
         g_return_val_if_fail (sksrc != NULL, FALSE);
         
         /* We pass our own data object, to which data is appended */
-        op = seahorse_source_export (sksrc, l, FALSE, G_OUTPUT_STREAM (output));
+        op = seahorse_source_export (sksrc, l, G_OUTPUT_STREAM (output));
         g_return_val_if_fail (op != NULL, FALSE);
 
         g_list_free (l);

Modified: trunk/gkr/seahorse-gkeyring-source.c
==============================================================================
--- trunk/gkr/seahorse-gkeyring-source.c	(original)
+++ trunk/gkr/seahorse-gkeyring-source.c	Sat Jul 19 17:16:27 2008
@@ -602,8 +602,7 @@
 }
 
 static SeahorseOperation* 
-seahorse_gkeyring_source_export (SeahorseSource *sksrc, GList *keys, 
-                                 gboolean complete, GOutputStream *output)
+seahorse_gkeyring_source_export (SeahorseSource *sksrc, GList *keys, GOutputStream *output)
 {
 	GError *err = NULL;
     

Modified: trunk/libseahorse/seahorse-source.c
==============================================================================
--- trunk/libseahorse/seahorse-source.c	(original)
+++ trunk/libseahorse/seahorse-source.c	Sat Jul 19 17:16:27 2008
@@ -213,7 +213,7 @@
         }
         
         /* We pass our own data object, to which data is appended */
-        op = seahorse_source_export (sksrc, objects, FALSE, output);
+        op = seahorse_source_export (sksrc, objects, output);
         g_return_val_if_fail (op != NULL, FALSE);
 
         g_list_free (objects);
@@ -260,8 +260,7 @@
 }
 
 SeahorseOperation* 
-seahorse_source_export (SeahorseSource *sksrc, GList *objects, 
-                        gboolean complete, GOutputStream *output)
+seahorse_source_export (SeahorseSource *sksrc, GList *objects, GOutputStream *output)
 {
 	SeahorseSourceClass *klass;
 	SeahorseOperation *op;
@@ -273,7 +272,7 @@
 	
 	klass = SEAHORSE_SOURCE_GET_CLASS (sksrc);   
 	if (klass->export)
-		return (*klass->export) (sksrc, objects, complete, output);
+		return (*klass->export) (sksrc, objects, output);
 
 	/* Either export or export_raw must be implemented */
 	g_return_val_if_fail (klass->export_raw != NULL, NULL);
@@ -316,7 +315,7 @@
 	}
     
 	objects = g_list_reverse (objects);
-	op = (*klass->export) (sksrc, objects, FALSE, output);
+	op = (*klass->export) (sksrc, objects, output);
 	g_list_free (objects);
 	return op;
 }

Modified: trunk/libseahorse/seahorse-source.h
==============================================================================
--- trunk/libseahorse/seahorse-source.h	(original)
+++ trunk/libseahorse/seahorse-source.h	Sat Jul 19 17:16:27 2008
@@ -122,8 +122,7 @@
      * 
      * Returns: The export operation
      */    
-    SeahorseOperation* (*export) (SeahorseSource *sksrc, GList *objects, 
-                                  gboolean complete, GOutputStream *output);
+    SeahorseOperation* (*export) (SeahorseSource *sksrc, GList *objects, GOutputStream *output);
 
     /**
      * export_raw
@@ -189,7 +188,6 @@
 
 SeahorseOperation*  seahorse_source_export                (SeahorseSource *sksrc,
                                                            GList *objects,
-                                                           gboolean complete,
                                                            GOutputStream *output);
 
 SeahorseOperation*  seahorse_source_export_raw            (SeahorseSource *sksrc, 

Modified: trunk/libseahorse/seahorse-util.c
==============================================================================
--- trunk/libseahorse/seahorse-util.c	(original)
+++ trunk/libseahorse/seahorse-util.c	Sat Jul 19 17:16:27 2008
@@ -845,7 +845,7 @@
 }
 
 void
-seahorse_util_chooser_set_filename (GtkDialog *dialog, GList *keys)
+seahorse_util_chooser_set_filename_full (GtkDialog *dialog, GList *keys)
 {
     gchar *t = NULL;
     
@@ -855,6 +855,14 @@
         g_free (t);
     }
 }
+
+void
+seahorse_util_chooser_set_filename (GtkDialog *dialog, SeahorseKey *skey)
+{
+	GList *keys = g_list_append (NULL, skey);
+	seahorse_util_chooser_set_filename_full (dialog, keys);
+	g_list_free (keys);
+}
     
 gchar*      
 seahorse_util_chooser_save_prompt (GtkDialog *dialog)

Modified: trunk/libseahorse/seahorse-util.h
==============================================================================
--- trunk/libseahorse/seahorse-util.h	(original)
+++ trunk/libseahorse/seahorse-util.h	Sat Jul 19 17:16:27 2008
@@ -38,6 +38,8 @@
 const AvahiPoll* seahorse_util_dns_sd_get_poll ();
 #endif
 
+struct _SeahorseKey;
+
 typedef enum {
     SEAHORSE_CRYPT_SUFFIX,
     SEAHORSE_SIG_SUFFIX,
@@ -118,9 +120,12 @@
 
 void        seahorse_util_chooser_show_archive_files    (GtkDialog *dialog);
 
-void        seahorse_util_chooser_set_filename          (GtkDialog *dialog, 
+void        seahorse_util_chooser_set_filename_full     (GtkDialog *dialog, 
                                                          GList *keys);
 
+void        seahorse_util_chooser_set_filename          (GtkDialog *dialog, 
+                                                         struct _SeahorseKey *skey);
+
 gchar*      seahorse_util_chooser_open_prompt           (GtkDialog *dialog);
 
 gchar*      seahorse_util_chooser_save_prompt           (GtkDialog *dialog);

Modified: trunk/pgp/seahorse-gpgmex-op.c
==============================================================================
--- trunk/pgp/seahorse-gpgmex-op.c	(original)
+++ trunk/pgp/seahorse-gpgmex-op.c	Sat Jul 19 17:16:27 2008
@@ -65,14 +65,15 @@
 {
     gchar *output = NULL;
     gpgme_error_t err;
-    gboolean armor;
     gchar *args;
     
     g_return_val_if_fail (pattern != NULL, GPG_E (GPG_ERR_INV_VALUE));
-    /* TODO: Use the context's arguments for armor */
-    armor = gpgme_get_armor (ctx) ? TRUE : FALSE;
-    args = g_strdup_printf ("%s --export-secret-key '%s'", 
-                            armor ? "--armor" : "",
+    
+    /* 
+     * We have to use armor mode, because otherwise below 
+     * string stuff doesn't work 
+     */
+    args = g_strdup_printf ("--armor --export-secret-key '%s'", 
                             pattern);
     
     err = execute_gpg_command (ctx, args, &output, NULL);

Modified: trunk/pgp/seahorse-pgp-key-properties.c
==============================================================================
--- trunk/pgp/seahorse-pgp-key-properties.c	(original)
+++ trunk/pgp/seahorse-pgp-key-properties.c	Sat Jul 19 17:16:27 2008
@@ -1011,56 +1011,70 @@
 }
 
 static void
-details_export_button_clicked (GtkWidget *widget, SeahorseWidget *swidget)
+export_complete (GFile *file, GAsyncResult *result, gchar *contents)
 {
-    SeahorseSource *sksrc;
-    SeahorseOperation *op;
-    SeahorseKey *skey;
-    GtkDialog *dialog;
-    gchar* uri = NULL;
-    GError *err = NULL;
-    GFile *file;
-    GFileOutputStream *output;
-    GList *keys = NULL;
-    
-    skey = SEAHORSE_KEY_WIDGET (swidget)->skey;
-    keys = g_list_prepend (NULL, skey);
-    
-    dialog = seahorse_util_chooser_save_new (_("Export Complete Key"), 
-                                             GTK_WINDOW (seahorse_widget_get_toplevel (swidget)));
-    seahorse_util_chooser_show_key_files (dialog);
-    seahorse_util_chooser_set_filename (dialog, keys);
-    
-    uri = seahorse_util_chooser_save_prompt (dialog);
-    gtk_widget_destroy (GTK_WIDGET (dialog));
-    if(!uri) 
-        return;
-    
-    sksrc = seahorse_key_get_source (skey);
-    g_assert (SEAHORSE_IS_SOURCE (sksrc));
-    
-	file = g_file_new_for_uri (uri);
-	output = g_file_replace (file, NULL, FALSE, 0, NULL, &err);  
-	g_object_unref (file);
-    
-	if (output) {
-		op = seahorse_source_export (sksrc, keys, TRUE, G_OUTPUT_STREAM (output));
-    
-		seahorse_operation_wait (op);
-		g_object_unref (output);
-        
-		if (!seahorse_operation_is_successful (op))
-			seahorse_operation_copy_error (op, &err);
+	GError *err = NULL;
+	gchar *uri;
+	
+	free (contents);
+
+	if (!g_file_replace_contents_finish (file, result, NULL, &err)) {
+		uri = g_file_get_uri (file);
+	        seahorse_util_handle_error (err, _("Couldn't export key to \"%s\""),
+	                                    seahorse_util_uri_get_last (uri));
+	        g_clear_error (&err);
+	        g_free (uri);
 	}
+}
+
+static void
+details_export_button_clicked (GtkWidget *widget, SeahorseWidget *swidget)
+{
+	SeahorseKey *skey;
+	SeahorsePGPKey *pkey;
+	GtkDialog *dialog;
+	gchar* uri = NULL;
+	GError *err = NULL;
+	GFile *file;
+	gpgme_error_t gerr;
+	gpgme_ctx_t ctx;
+	gpgme_data_t data;
+	gchar *results;
+	gsize n_results;
     
-	if (err) {
-		seahorse_util_handle_error (err, _("Couldn't export key to \"%s\""),
-		                            seahorse_util_uri_get_last (uri));
+	skey = SEAHORSE_KEY_WIDGET (swidget)->skey;
+	pkey = SEAHORSE_PGP_KEY (skey);
+	
+	dialog = seahorse_util_chooser_save_new (_("Export Complete Key"), 
+	                                         GTK_WINDOW (seahorse_widget_get_toplevel (swidget)));
+	seahorse_util_chooser_show_key_files (dialog);
+	seahorse_util_chooser_set_filename (dialog, skey);
+    
+	uri = seahorse_util_chooser_save_prompt (dialog);
+	if (!uri) 
+		return;
+	
+	/* Export to a data block */
+	gerr = gpgme_data_new (&data);
+	g_return_if_fail (GPG_IS_OK (gerr));
+	ctx = seahorse_pgp_source_new_context ();
+	g_return_if_fail (ctx);
+	gerr = gpgmex_op_export_secret (ctx, seahorse_pgp_key_get_id (pkey->seckey, 0), data);
+	gpgme_release (ctx);
+	results = gpgme_data_release_and_get_mem (data, &n_results);
+
+	if (GPG_IS_OK (gerr)) {
+		file = g_file_new_for_uri (uri);
+		g_file_replace_contents_async (file, results, n_results, NULL, FALSE, 
+		                               G_FILE_CREATE_PRIVATE, NULL, 
+		                               (GAsyncReadyCallback)export_complete, results);
+	} else {
+		seahorse_gpgme_to_error (gerr, &err);
+		seahorse_util_handle_error (err, _("Couldn't export key."));
 		g_clear_error (&err);
 	}
-    
-    g_list_free (keys);
-    g_free (uri);
+	
+	g_free (uri);
 }
 
 /*

Modified: trunk/src/seahorse-key-manager-store.c
==============================================================================
--- trunk/src/seahorse-key-manager-store.c	(original)
+++ trunk/src/seahorse-key-manager-store.c	Sat Jul 19 17:16:27 2008
@@ -489,7 +489,7 @@
 			mop = seahorse_multi_operation_new ();
 
 		/* We pass our own data object, to which data is appended */
-		op = seahorse_source_export (sksrc, objects, FALSE, output);
+		op = seahorse_source_export (sksrc, objects, output);
 		g_return_val_if_fail (op != NULL, FALSE);
 
 		seahorse_multi_operation_take (mop, op);

Modified: trunk/ssh/seahorse-ssh-key-properties.c
==============================================================================
--- trunk/ssh/seahorse-ssh-key-properties.c	(original)
+++ trunk/ssh/seahorse-ssh-key-properties.c	Sat Jul 19 17:16:27 2008
@@ -202,56 +202,66 @@
 }
 
 static void
+export_complete (GFile *file, GAsyncResult *result, guchar *contents)
+{
+	GError *err = NULL;
+	gchar *uri;
+	
+	g_free (contents);
+	
+	if (!g_file_replace_contents_finish (file, result, NULL, &err)) {
+		uri = g_file_get_uri (file);
+	        seahorse_util_handle_error (err, _("Couldn't export key to \"%s\""),
+	                                    seahorse_util_uri_get_last (uri));
+	        g_clear_error (&err);
+	        g_free (uri);
+	}
+}
+
+static void
 export_button_clicked (GtkWidget *widget, SeahorseWidget *swidget)
 {
-    SeahorseSource *sksrc;
-    SeahorseOperation *op;
-    SeahorseKey *skey;
-    GFileOutputStream *output;
-    GFile *file;
-    GtkDialog *dialog;
-    gchar* uri = NULL;
-    GError *err = NULL;
-    GList *keys = NULL;
-
-    skey = SEAHORSE_KEY_WIDGET (swidget)->skey;
-    keys = g_list_prepend (keys, skey);
-
-    dialog = seahorse_util_chooser_save_new (_("Export Complete Key"), 
-                                             GTK_WINDOW (seahorse_widget_get_toplevel (swidget)));
-    seahorse_util_chooser_show_key_files (dialog);
-    seahorse_util_chooser_set_filename (dialog, keys);
-
-    uri = seahorse_util_chooser_save_prompt (dialog);
-    gtk_widget_destroy (GTK_WIDGET (dialog));
-    if(!uri) 
-        return;
-    
-    sksrc = seahorse_key_get_source (skey);
-    g_assert (SEAHORSE_IS_SOURCE (sksrc));
-    
-	file = g_file_new_for_uri (uri);
-	output = g_file_replace (file, NULL, FALSE, 0, NULL, &err);  
-	g_object_unref (file);
+	SeahorseSource *sksrc;
+	SeahorseKey *skey;
+	GFile *file;
+	GtkDialog *dialog;
+	guchar *results;
+	gsize n_results;
+	gchar* uri = NULL;
+	GError *err = NULL;
+
+	skey = SEAHORSE_KEY_WIDGET (swidget)->skey;
+	g_return_if_fail (SEAHORSE_IS_SSH_KEY (skey));
+	sksrc = seahorse_object_get_source (SEAHORSE_OBJECT (skey));
+	g_return_if_fail (SEAHORSE_IS_SSH_SOURCE (sksrc));
 	
-	if (output) {
-		op = seahorse_source_export (sksrc, keys, TRUE, G_OUTPUT_STREAM (output));
-    
-		seahorse_operation_wait (op);
-		g_object_unref (output);
-		
-		if (!seahorse_operation_is_successful (op))
-			seahorse_operation_copy_error (op, &err);
+	dialog = seahorse_util_chooser_save_new (_("Export Complete Key"), 
+	                                         GTK_WINDOW (seahorse_widget_get_toplevel (swidget)));
+	seahorse_util_chooser_show_key_files (dialog);
+	seahorse_util_chooser_set_filename (dialog, skey);
+
+	uri = seahorse_util_chooser_save_prompt (dialog);
+	if (!uri) 
+		return;
+	
+	results = seahorse_ssh_source_export_private (SEAHORSE_SSH_SOURCE (sksrc), 
+	                                              SEAHORSE_SSH_KEY (skey),
+	                                              &n_results, &err);
+	
+	if (results) {
+		g_return_if_fail (err == NULL);
+		file = g_file_new_for_uri (uri);
+		g_file_replace_contents_async (file, (gchar*)results, n_results, NULL, FALSE, 
+		                               G_FILE_CREATE_PRIVATE, NULL, 
+		                               (GAsyncReadyCallback)export_complete, results);
 	}
-    
-    if (err) {
-        seahorse_util_handle_error (err, _("Couldn't export key to \"%s\""),
-                                    seahorse_util_uri_get_last (uri));
-        g_clear_error (&err);
-    }
-    
-    g_free (uri);
-    g_list_free (keys);
+	
+	if (err) {
+	        seahorse_util_handle_error (err, _("Couldn't export key."));
+	        g_clear_error (&err);
+	}
+	
+	g_free (uri);
 }
 
 static void 

Modified: trunk/ssh/seahorse-ssh-operation.c
==============================================================================
--- trunk/ssh/seahorse-ssh-operation.c	(original)
+++ trunk/ssh/seahorse-ssh-operation.c	Sat Jul 19 17:16:27 2008
@@ -752,7 +752,7 @@
     	g_return_val_if_fail (output, NULL);
     	
     	/* Buffer for what we send to the server */
-    	op = seahorse_source_export (SEAHORSE_SOURCE (ssrc), keys, FALSE, G_OUTPUT_STREAM (output));
+    	op = seahorse_source_export (SEAHORSE_SOURCE (ssrc), keys, G_OUTPUT_STREAM (output));
     	g_return_val_if_fail (op != NULL, NULL);
     
     /* 

Modified: trunk/ssh/seahorse-ssh-source.c
==============================================================================
--- trunk/ssh/seahorse-ssh-source.c	(original)
+++ trunk/ssh/seahorse-ssh-source.c	Sat Jul 19 17:16:27 2008
@@ -583,7 +583,7 @@
 
 static SeahorseOperation* 
 seahorse_ssh_source_export (SeahorseSource *sksrc, GList *keys, 
-                            gboolean complete, GOutputStream *output)
+                            GOutputStream *output)
 {
     SeahorseSSHKeyData *keydata;
     SeahorseOperation *op;
@@ -609,21 +609,8 @@
         g_object_get (skey, "key-data", &keydata, NULL);
         g_return_val_if_fail (keydata, NULL);
         
-        /* Complete key means the private key */
-        if (complete && keydata->privfile) {
-            
-            /* And then the data itself */
-            if (!g_file_get_contents (keydata->privfile, &raw, NULL, &error)) {
-                raw = results = NULL;
-            } else {
-                /* Add the seahorse specific prefix */
-                results = g_strdup_printf ("%s %s\n%s\n", SSH_KEY_SECRET_SIG, 
-                                           keydata->comment ? keydata->comment : "",
-                                           raw);
-            }
-           
-        /* Public key. We should already have the data loaded */
-        } else if (keydata->pubfile) { 
+        /* We should already have the data loaded */
+        if (keydata->pubfile) { 
             g_assert (keydata->rawdata);
             results = g_strdup_printf ("%s\n", keydata->rawdata);
             
@@ -940,3 +927,30 @@
     return g_build_filename (ssrc->priv->ssh_homedir, 
             authorized ? AUTHORIZED_KEYS_FILE : OTHER_KEYS_FILE, NULL);
 }
+
+guchar*
+seahorse_ssh_source_export_private (SeahorseSSHSource *ssrc, SeahorseSSHKey *skey,
+                                    gsize *n_results, GError **err)
+{
+	SeahorseSSHKeyData *keydata;
+	gchar *results;
+	
+	g_return_val_if_fail (SEAHORSE_IS_SSH_SOURCE (ssrc), NULL);
+	g_return_val_if_fail (SEAHORSE_IS_SSH_KEY (skey), NULL);
+	g_return_val_if_fail (n_results, NULL);
+	g_return_val_if_fail (!err || !*err, NULL);
+	
+	g_object_get (skey, "key-data", &keydata, NULL);
+	g_return_val_if_fail (keydata, NULL);
+
+	if (!keydata->privfile) {
+		g_set_error (err, SEAHORSE_ERROR, 0, "%s", _("No private key file is available for this key."));
+		return NULL;
+	}
+
+        /* And then the data itself */
+        if (!g_file_get_contents (keydata->privfile, &results, n_results, err))
+        	return NULL;
+        
+        return (guchar*)results;
+}

Modified: trunk/ssh/seahorse-ssh-source.h
==============================================================================
--- trunk/ssh/seahorse-ssh-source.h	(original)
+++ trunk/ssh/seahorse-ssh-source.h	Sat Jul 19 17:16:27 2008
@@ -78,4 +78,10 @@
 gchar*               seahorse_ssh_source_file_for_algorithm (SeahorseSSHSource *ssrc,
                                                              guint algo);
 
+guchar*              seahorse_ssh_source_export_private     (SeahorseSSHSource *ssrc,
+                                                             SeahorseSSHKey *skey,
+                                                             gsize *n_results,
+                                                             GError **err);
+
+
 #endif /* __SEAHORSE_SSH_SOURCE_H__ */



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