gpa: Add patches to fix card key generation.
[gpg4win.git] / patches / gpa-0.9.4 / 02-x509-import.patch
1 #! /bin/sh
2 patch -p1 -l -f $* < $0
3 exit $?
4
5 From 6742525110270b0098e41157edfb13e36483f1ca Mon Sep 17 00:00:00 2001
6 From: Werner Koch <wk@gnupg.org>
7 Date: Sat, 10 Aug 2013 08:34:38 +0200
8 Subject: [PATCH] Allow import and export of X.509 certificates.
9
10 * src/filetype.c (is_cms_data_ext): New.
11 * src/gpaimportop.c (gpa_import_operation_idle_cb): Set the
12 appropriate protocol.
13 * src/gpaexportop.c (gpa_export_operation_idle_cb): Ditto.
14 ---
15  src/filetype.c    |   23 +++++++++++++++++++++++
16  src/filetype.h    |    1 +
17  src/gpaexportop.c |   41 +++++++++++++++++++++++++++++------------
18  src/gpaimportop.c |   26 +++++++++++++++-----------
19  4 files changed, 68 insertions(+), 23 deletions(-)
20
21 diff --git a/src/filetype.c b/src/filetype.c
22 index 4e68d27..58b4145 100644
23 --- a/src/filetype.c
24 +++ b/src/filetype.c
25 @@ -200,3 +200,26 @@ is_cms_data (const char *data, size_t datalen)
26    return result;
27  #endif
28  }
29 +
30 +/* New version of is_cms_data which requires a decent version of
31 +   gpgme.  In contrast to is_cms_data this works directly on a gpgme
32 +   data object.  */
33 +int
34 +is_cms_data_ext (gpgme_data_t dh)
35 +{
36 +#ifdef HAVE_GPGME_DATA_IDENTIFY
37 +  switch (gpgme_data_identify (dh, 0))
38 +    {
39 +    case GPGME_DATA_TYPE_CMS_SIGNED:
40 +    case GPGME_DATA_TYPE_CMS_ENCRYPTED:
41 +    case GPGME_DATA_TYPE_CMS_OTHER:
42 +    case GPGME_DATA_TYPE_X509_CERT:
43 +    case GPGME_DATA_TYPE_PKCS12:
44 +      return 1;
45 +    default:
46 +      return 0;
47 +    }
48 +#else
49 +  return 0;
50 +#endif
51 +}
52 diff --git a/src/filetype.h b/src/filetype.h
53 index 6c88c68..8ba4c2e 100644
54 --- a/src/filetype.h
55 +++ b/src/filetype.h
56 @@ -20,6 +20,7 @@
57
58  int is_cms_file (const char *fname);
59  int is_cms_data (const char *data, size_t datalen);
60 +int is_cms_data_ext (gpgme_data_t dh);
61
62
63  #endif /*FILETYPE_H*/
64 diff --git a/src/gpaexportop.c b/src/gpaexportop.c
65 index 51df806..9caf49f 100644
66 --- a/src/gpaexportop.c
67 +++ b/src/gpaexportop.c
68 @@ -38,7 +38,7 @@ enum
69  static gboolean gpa_export_operation_idle_cb (gpointer data);
70  static void gpa_export_operation_done_cb (GpaContext *context, gpg_error_t err,
71                               GpaExportOperation *op);
72 -static void gpa_export_operation_done_error_cb (GpaContext *context,
73 +static void gpa_export_operation_done_error_cb (GpaContext *context,
74                                                 gpg_error_t err,
75                                                 GpaExportOperation *op);
76
77 @@ -97,7 +97,7 @@ gpa_export_operation_finalize (GObject *object)
78      {
79        gpgme_data_release (op->dest);
80      }
81 -
82 +
83    G_OBJECT_CLASS (parent_class)->finalize (object);
84  }
85
86 @@ -138,14 +138,14 @@ static void
87  gpa_export_operation_class_init (GpaExportOperationClass *klass)
88  {
89    GObjectClass *object_class = G_OBJECT_CLASS (klass);
90 -
91 +
92    parent_class = g_type_class_peek_parent (klass);
93
94    object_class->constructor = gpa_export_operation_constructor;
95    object_class->finalize = gpa_export_operation_finalize;
96    object_class->set_property = gpa_export_operation_set_property;
97    object_class->get_property = gpa_export_operation_get_property;
98 -
99 +
100    /* Virtual methods */
101    klass->get_destination = NULL;
102    klass->complete_export = NULL;
103 @@ -153,7 +153,7 @@ gpa_export_operation_class_init (GpaExportOperationClass *klass)
104    /* Properties */
105    g_object_class_install_property (object_class,
106                                    PROP_KEYS,
107 -                                  g_param_spec_pointer
108 +                                  g_param_spec_pointer
109                                    ("keys", "Keys",
110                                     "Keys",
111                                     G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
112 @@ -163,7 +163,7 @@ GType
113  gpa_export_operation_get_type (void)
114  {
115    static GType file_operation_type = 0;
116 -
117 +
118    if (!file_operation_type)
119      {
120        static const GTypeInfo file_operation_info =
121 @@ -178,12 +178,12 @@ gpa_export_operation_get_type (void)
122          0,              /* n_preallocs */
123          (GInstanceInitFunc) gpa_export_operation_init,
124        };
125 -
126 +
127        file_operation_type = g_type_register_static (GPA_OPERATION_TYPE,
128                                                     "GpaExportOperation",
129                                                     &file_operation_info, 0);
130      }
131 -
132 +
133    return file_operation_type;
134  }
135
136 @@ -198,10 +198,11 @@ gpa_export_operation_idle_cb (gpointer data)
137    if (GPA_EXPORT_OPERATION_GET_CLASS (op)->get_destination (op, &op->dest,
138                                                             &armor))
139      {
140 -      gpg_error_t err;
141 +      gpg_error_t err = 0;
142        const char **patterns;
143        GList *k;
144        int i;
145 +      gpgme_protocol_t prot = GPGME_PROTOCOL_UNKNOWN;
146
147        gpgme_set_armor (GPA_OPERATION (op)->context->ctx, armor);
148        /* Create the set of keys to export */
149 @@ -210,17 +211,33 @@ gpa_export_operation_idle_cb (gpointer data)
150         {
151           gpgme_key_t key = (gpgme_key_t) k->data;
152           patterns[i] = key->subkeys->fpr;
153 +          if (prot == GPGME_PROTOCOL_UNKNOWN)
154 +            prot = key->protocol;
155 +          else if (prot != key->protocol)
156 +            {
157 +              gpa_window_error
158 +                (_("Only keys of the same procotol may be exported"
159 +                   " as a collection."), NULL);
160 +              g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
161 +              goto cleanup;
162 +            }
163         }
164 +      if (prot == GPGME_PROTOCOL_UNKNOWN)
165 +        {
166 +          g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
167 +          goto cleanup;  /* No keys.  */
168 +        }
169 +      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx, prot);
170        /* Export to the gpgme_data_t */
171 -      err = gpgme_op_export_ext_start (GPA_OPERATION (op)->context->ctx,
172 +      err = gpgme_op_export_ext_start (GPA_OPERATION (op)->context->ctx,
173                                        patterns, 0, op->dest);
174        if (err)
175         {
176           gpa_gpgme_warning (err);
177           g_signal_emit_by_name (GPA_OPERATION (op), "completed", err);
178         }
179 -      /* Clean up */
180 -      g_free (patterns);
181 +    cleanup:
182 +      g_free (patterns);
183      }
184    else
185      /* Abort the operation.  */
186 diff --git a/src/gpaimportop.c b/src/gpaimportop.c
187 index 81ed769..0680a21 100644
188 --- a/src/gpaimportop.c
189 +++ b/src/gpaimportop.c
190 @@ -25,6 +25,7 @@
191  #include "i18n.h"
192  #include "gtktools.h"
193  #include "gpaimportop.h"
194 +#include "filetype.h"
195
196  static GObjectClass *parent_class = NULL;
197
198 @@ -40,7 +41,7 @@ static guint signals [LAST_SIGNAL] = { 0 };
199  static gboolean gpa_import_operation_idle_cb (gpointer data);
200  static void gpa_import_operation_done_cb (GpaContext *context, gpg_error_t err,
201                               GpaImportOperation *op);
202 -static void gpa_import_operation_done_error_cb (GpaContext *context,
203 +static void gpa_import_operation_done_error_cb (GpaContext *context,
204                                                 gpg_error_t err,
205                                                 GpaImportOperation *op);
206
207 @@ -56,7 +57,7 @@ gpa_import_operation_finalize (GObject *object)
208      {
209        gpgme_data_release (op->source);
210      }
211 -
212 +
213    G_OBJECT_CLASS (parent_class)->finalize (object);
214  }
215
216 @@ -95,12 +96,12 @@ static void
217  gpa_import_operation_class_init (GpaImportOperationClass *klass)
218  {
219    GObjectClass *object_class = G_OBJECT_CLASS (klass);
220 -
221 +
222    parent_class = g_type_class_peek_parent (klass);
223
224    object_class->constructor = gpa_import_operation_constructor;
225    object_class->finalize = gpa_import_operation_finalize;
226 -
227 +
228    /* Virtual methods */
229    klass->get_source = NULL;
230    klass->complete_import = NULL;
231 @@ -130,7 +131,7 @@ GType
232  gpa_import_operation_get_type (void)
233  {
234    static GType file_operation_type = 0;
235 -
236 +
237    if (!file_operation_type)
238      {
239        static const GTypeInfo file_operation_info =
240 @@ -145,12 +146,12 @@ gpa_import_operation_get_type (void)
241          0,              /* n_preallocs */
242          (GInstanceInitFunc) gpa_import_operation_init,
243        };
244 -
245 +
246        file_operation_type = g_type_register_static (GPA_OPERATION_TYPE,
247                                                     "GpaImportOperation",
248                                                     &file_operation_info, 0);
249      }
250 -
251 +
252    return file_operation_type;
253  }
254
255 @@ -164,7 +165,10 @@ gpa_import_operation_idle_cb (gpointer data)
256    if (GPA_IMPORT_OPERATION_GET_CLASS (op)->get_source (op, &op->source))
257      {
258        gpg_error_t err;
259 -
260 +
261 +      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
262 +                          is_cms_data_ext (op->source)?
263 +                          GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP);
264        err = gpgme_op_import_start (GPA_OPERATION (op)->context->ctx,
265                                    op->source);
266        if (err)
267 @@ -181,8 +185,8 @@ gpa_import_operation_idle_cb (gpointer data)
268    return FALSE;
269  }
270
271 -static void
272 -key_import_results_dialog_run (GtkWidget *parent,
273 +static void
274 +key_import_results_dialog_run (GtkWidget *parent,
275                                gpgme_import_result_t info)
276  {
277    GtkWidget *dialog;
278 @@ -211,7 +215,7 @@ key_import_results_dialog_run (GtkWidget *parent,
279                                         info->unchanged, info->secret_read,
280                                         info->secret_imported,
281                                        info->secret_unchanged);
282 -    }
283 +    }
284
285    /* Run the dialog */
286    gtk_widget_show_all (dialog);
287 --
288 1.7.7.1