[git] GPA - branch, master, updated. gpa-0.9.4-5-g6742525

by Werner Koch cvs at cvs.gnupg.org
Sat Aug 10 09:06:21 CEST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Assistant".

The branch, master has been updated
       via  6742525110270b0098e41157edfb13e36483f1ca (commit)
      from  3a8458ae7c083fd46e8d5e165997422a35bdd21f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6742525110270b0098e41157edfb13e36483f1ca
Author: Werner Koch <wk at gnupg.org>
Date:   Sat Aug 10 08:34:38 2013 +0200

    Allow import and export of X.509 certificates.
    
    * src/filetype.c (is_cms_data_ext): New.
    * src/gpaimportop.c (gpa_import_operation_idle_cb): Set the
    appropriate protocol.
    * src/gpaexportop.c (gpa_export_operation_idle_cb): Ditto.

diff --git a/src/filetype.c b/src/filetype.c
index 4e68d27..58b4145 100644
--- a/src/filetype.c
+++ b/src/filetype.c
@@ -200,3 +200,26 @@ is_cms_data (const char *data, size_t datalen)
   return result;
 #endif
 }
+
+/* New version of is_cms_data which requires a decent version of
+   gpgme.  In contrast to is_cms_data this works directly on a gpgme
+   data object.  */
+int
+is_cms_data_ext (gpgme_data_t dh)
+{
+#ifdef HAVE_GPGME_DATA_IDENTIFY
+  switch (gpgme_data_identify (dh, 0))
+    {
+    case GPGME_DATA_TYPE_CMS_SIGNED:
+    case GPGME_DATA_TYPE_CMS_ENCRYPTED:
+    case GPGME_DATA_TYPE_CMS_OTHER:
+    case GPGME_DATA_TYPE_X509_CERT:
+    case GPGME_DATA_TYPE_PKCS12:
+      return 1;
+    default:
+      return 0;
+    }
+#else
+  return 0;
+#endif
+}
diff --git a/src/filetype.h b/src/filetype.h
index 6c88c68..8ba4c2e 100644
--- a/src/filetype.h
+++ b/src/filetype.h
@@ -20,6 +20,7 @@
 
 int is_cms_file (const char *fname);
 int is_cms_data (const char *data, size_t datalen);
+int is_cms_data_ext (gpgme_data_t dh);
 
 
 #endif /*FILETYPE_H*/
diff --git a/src/gpaexportop.c b/src/gpaexportop.c
index 51df806..9caf49f 100644
--- a/src/gpaexportop.c
+++ b/src/gpaexportop.c
@@ -38,7 +38,7 @@ enum
 static gboolean gpa_export_operation_idle_cb (gpointer data);
 static void gpa_export_operation_done_cb (GpaContext *context, gpg_error_t err,
 			      GpaExportOperation *op);
-static void gpa_export_operation_done_error_cb (GpaContext *context, 
+static void gpa_export_operation_done_error_cb (GpaContext *context,
 						gpg_error_t err,
 						GpaExportOperation *op);
 
@@ -97,7 +97,7 @@ gpa_export_operation_finalize (GObject *object)
     {
       gpgme_data_release (op->dest);
     }
-  
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -138,14 +138,14 @@ static void
 gpa_export_operation_class_init (GpaExportOperationClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->constructor = gpa_export_operation_constructor;
   object_class->finalize = gpa_export_operation_finalize;
   object_class->set_property = gpa_export_operation_set_property;
   object_class->get_property = gpa_export_operation_get_property;
-  
+
   /* Virtual methods */
   klass->get_destination = NULL;
   klass->complete_export = NULL;
@@ -153,7 +153,7 @@ gpa_export_operation_class_init (GpaExportOperationClass *klass)
   /* Properties */
   g_object_class_install_property (object_class,
 				   PROP_KEYS,
-				   g_param_spec_pointer 
+				   g_param_spec_pointer
 				   ("keys", "Keys",
 				    "Keys",
 				    G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
@@ -163,7 +163,7 @@ GType
 gpa_export_operation_get_type (void)
 {
   static GType file_operation_type = 0;
-  
+
   if (!file_operation_type)
     {
       static const GTypeInfo file_operation_info =
@@ -178,12 +178,12 @@ gpa_export_operation_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_export_operation_init,
       };
-      
+
       file_operation_type = g_type_register_static (GPA_OPERATION_TYPE,
 						    "GpaExportOperation",
 						    &file_operation_info, 0);
     }
-  
+
   return file_operation_type;
 }
 
@@ -198,10 +198,11 @@ gpa_export_operation_idle_cb (gpointer data)
   if (GPA_EXPORT_OPERATION_GET_CLASS (op)->get_destination (op, &op->dest,
 							    &armor))
     {
-      gpg_error_t err;
+      gpg_error_t err = 0;
       const char **patterns;
       GList *k;
       int i;
+      gpgme_protocol_t prot = GPGME_PROTOCOL_UNKNOWN;
 
       gpgme_set_armor (GPA_OPERATION (op)->context->ctx, armor);
       /* Create the set of keys to export */
@@ -210,17 +211,33 @@ gpa_export_operation_idle_cb (gpointer data)
 	{
 	  gpgme_key_t key = (gpgme_key_t) k->data;
 	  patterns[i] = key->subkeys->fpr;
+          if (prot == GPGME_PROTOCOL_UNKNOWN)
+            prot = key->protocol;
+          else if (prot != key->protocol)
+            {
+              gpa_window_error
+                (_("Only keys of the same procotol may be exported"
+                   " as a collection."), NULL);
+              g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
+              goto cleanup;
+            }
 	}
+      if (prot == GPGME_PROTOCOL_UNKNOWN)
+        {
+          g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
+          goto cleanup;  /* No keys.  */
+        }
+      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx, prot);
       /* Export to the gpgme_data_t */
-      err = gpgme_op_export_ext_start (GPA_OPERATION (op)->context->ctx, 
+      err = gpgme_op_export_ext_start (GPA_OPERATION (op)->context->ctx,
 				       patterns, 0, op->dest);
       if (err)
 	{
 	  gpa_gpgme_warning (err);
 	  g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
 	}
-      /* Clean up */
-      g_free (patterns);      
+    cleanup:
+      g_free (patterns);
     }
   else
     /* Abort the operation.  */
diff --git a/src/gpaimportop.c b/src/gpaimportop.c
index 81ed769..0680a21 100644
--- a/src/gpaimportop.c
+++ b/src/gpaimportop.c
@@ -25,6 +25,7 @@
 #include "i18n.h"
 #include "gtktools.h"
 #include "gpaimportop.h"
+#include "filetype.h"
 
 static GObjectClass *parent_class = NULL;
 
@@ -40,7 +41,7 @@ static guint signals [LAST_SIGNAL] = { 0 };
 static gboolean gpa_import_operation_idle_cb (gpointer data);
 static void gpa_import_operation_done_cb (GpaContext *context, gpg_error_t err,
 			      GpaImportOperation *op);
-static void gpa_import_operation_done_error_cb (GpaContext *context, 
+static void gpa_import_operation_done_error_cb (GpaContext *context,
 						gpg_error_t err,
 						GpaImportOperation *op);
 
@@ -56,7 +57,7 @@ gpa_import_operation_finalize (GObject *object)
     {
       gpgme_data_release (op->source);
     }
-  
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -95,12 +96,12 @@ static void
 gpa_import_operation_class_init (GpaImportOperationClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->constructor = gpa_import_operation_constructor;
   object_class->finalize = gpa_import_operation_finalize;
-  
+
   /* Virtual methods */
   klass->get_source = NULL;
   klass->complete_import = NULL;
@@ -130,7 +131,7 @@ GType
 gpa_import_operation_get_type (void)
 {
   static GType file_operation_type = 0;
-  
+
   if (!file_operation_type)
     {
       static const GTypeInfo file_operation_info =
@@ -145,12 +146,12 @@ gpa_import_operation_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_import_operation_init,
       };
-      
+
       file_operation_type = g_type_register_static (GPA_OPERATION_TYPE,
 						    "GpaImportOperation",
 						    &file_operation_info, 0);
     }
-  
+
   return file_operation_type;
 }
 
@@ -164,7 +165,10 @@ gpa_import_operation_idle_cb (gpointer data)
   if (GPA_IMPORT_OPERATION_GET_CLASS (op)->get_source (op, &op->source))
     {
       gpg_error_t err;
-      
+
+      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
+                          is_cms_data_ext (op->source)?
+                          GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP);
       err = gpgme_op_import_start (GPA_OPERATION (op)->context->ctx,
 				   op->source);
       if (err)
@@ -181,8 +185,8 @@ gpa_import_operation_idle_cb (gpointer data)
   return FALSE;
 }
 
-static void 
-key_import_results_dialog_run (GtkWidget *parent, 
+static void
+key_import_results_dialog_run (GtkWidget *parent,
 			       gpgme_import_result_t info)
 {
   GtkWidget *dialog;
@@ -211,7 +215,7 @@ key_import_results_dialog_run (GtkWidget *parent,
                                        info->unchanged, info->secret_read,
                                        info->secret_imported,
 				       info->secret_unchanged);
-    }			   
+    }
 
   /* Run the dialog */
   gtk_widget_show_all (dialog);

-----------------------------------------------------------------------

Summary of changes:
 src/filetype.c    |   23 +++++++++++++++++++++++
 src/filetype.h    |    1 +
 src/gpaexportop.c |   41 +++++++++++++++++++++++++++++------------
 src/gpaimportop.c |   26 +++++++++++++++-----------
 4 files changed, 68 insertions(+), 23 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Assistant
http://git.gnupg.org




More information about the Gnupg-commits mailing list