gpa: Add binary option for ui-server encryption.
authorWerner Koch <wk@gnupg.org>
Fri, 9 Aug 2013 08:18:04 +0000 (10:18 +0200)
committerWerner Koch <wk@gnupg.org>
Fri, 9 Aug 2013 08:18:04 +0000 (10:18 +0200)
* patches/gpa-0.9.4/01-bin-encrypt.patch: New.
* Makefile.am (EXTRA_DIST): Add patch.

Makefile.am
patches/gpa-0.9.4/01-bin-encrypt.patch [new file with mode: 0755]

index 03eb2cb..84e0641 100644 (file)
@@ -48,7 +48,8 @@ EXTRA_DIST = autogen.sh README.GIT ONEWS \
         patches/claws-mail-3.9.1/80-src-makefile.postcfg-build \
         patches/gtkhtml2_viewer-0.34/80-src-makefile.postcfg-build \
        patches/gnutls-2.12.21/01-openssl-wincrypt.patch \
-        patches/libgpg-error-1.12/01-fix-get-string.patch
+        patches/libgpg-error-1.12/01-fix-get-string.patch \
+       patches/gpa-0.9.4/01-bin-encrypt.patch
 
 copy-news:
        cp NEWS doc/website/NEWS.last
diff --git a/patches/gpa-0.9.4/01-bin-encrypt.patch b/patches/gpa-0.9.4/01-bin-encrypt.patch
new file mode 100755 (executable)
index 0000000..4eb9a4d
--- /dev/null
@@ -0,0 +1,509 @@
+#! /bin/sh
+patch -p1 -l -f $* < $0
+exit $?
+
+From 5574ece82ed5950dca11d729744f52ac159444d5 Mon Sep 17 00:00:00 2001
+From: Werner Koch <wk@gnupg.org>
+Date: Wed, 31 Jul 2013 17:35:39 +0200
+Subject: [PATCH] Implement the binary option for server based encrypt and
+ sign.
+
+* src/server.c (conn_ctrl_s): Add field OUTPUT_BINARY.
+(prepare_io_streams): Set data encoding to binary if requested.
+(output_notify): New.
+(connection_startup): Register new callback.
+* src/gpastreamencryptop.c (start_encryption): Use a provided encoding.
+* src/gpastreamsignop.c (start_signing): Ditto.
+--
+
+Note that these changes have not yet been tested.
+---
+ src/gpastreamencryptop.c |   62 +++++++++++++++++++++++---------------------
+ src/gpastreamsignop.c    |   64 ++++++++++++++++++++++++---------------------
+ src/server.c             |   23 ++++++++++++++++
+ 3 files changed, 90 insertions(+), 59 deletions(-)
+
+diff --git a/src/gpastreamencryptop.c b/src/gpastreamencryptop.c
+index 146707f..70a5e24 100644
+--- a/src/gpastreamencryptop.c
++++ b/src/gpastreamencryptop.c
+@@ -28,11 +28,11 @@
+ #include "selectkeydlg.h"
+
+
+-struct _GpaStreamEncryptOperation
++struct _GpaStreamEncryptOperation
+ {
+   GpaStreamOperation parent;
+-
+-  SelectKeyDlg *key_dialog;
++
++  SelectKeyDlg *key_dialog;
+   RecipientDlg *recp_dialog;
+   GSList *recipients;
+   gpgme_key_t *keys;
+@@ -40,7 +40,7 @@ struct _GpaStreamEncryptOperation
+ };
+
+
+-struct _GpaStreamEncryptOperationClass
++struct _GpaStreamEncryptOperationClass
+ {
+   GpaStreamOperationClass parent_class;
+ };
+@@ -48,7 +48,7 @@ struct _GpaStreamEncryptOperationClass
+
+
+ /* Indentifiers for our properties. */
+-enum
++enum
+   {
+     PROP_0,
+     PROP_RECIPIENTS,
+@@ -95,7 +95,7 @@ static GSList *
+ copy_recipients (GSList *recipients)
+ {
+   GSList *recp, *newlist;
+-
++
+   newlist= NULL;
+   for (recp = recipients; recp; recp = g_slist_next (recp))
+     newlist = g_slist_append (newlist, g_strdup (recp->data));
+@@ -110,7 +110,7 @@ gpa_stream_encrypt_operation_get_property (GObject *object, guint prop_id,
+                                            GValue *value, GParamSpec *pspec)
+ {
+   GpaStreamEncryptOperation *op = GPA_STREAM_ENCRYPT_OPERATION (object);
+-
++
+   switch (prop_id)
+     {
+     case PROP_RECIPIENTS:
+@@ -156,7 +156,7 @@ gpa_stream_encrypt_operation_set_property (GObject *object, guint prop_id,
+
+ static void
+ gpa_stream_encrypt_operation_finalize (GObject *object)
+-{
++{
+   GpaStreamEncryptOperation *op = GPA_STREAM_ENCRYPT_OPERATION (object);
+
+   release_recipients (op->recipients);
+@@ -180,7 +180,7 @@ gpa_stream_encrypt_operation_init (GpaStreamEncryptOperation *op)
+
+
+ static GObject*
+-gpa_stream_encrypt_operation_constructor
++gpa_stream_encrypt_operation_constructor
+       (GType type,
+          guint n_construct_properties,
+          GObjectConstructParam *construct_properties)
+@@ -224,7 +224,7 @@ gpa_stream_encrypt_operation_constructor
+   g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
+                   G_CALLBACK (done_cb), op);
+
+-  gtk_window_set_title
++  gtk_window_set_title
+     (GTK_WINDOW (GPA_STREAM_OPERATION (op)->progress_dialog),
+                       _("Encrypting message ..."));
+
+@@ -241,7 +241,7 @@ static void
+ gpa_stream_encrypt_operation_class_init (GpaStreamEncryptOperationClass *klass)
+ {
+   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+-
++
+   parent_class = g_type_class_peek_parent (klass);
+
+   object_class->constructor = gpa_stream_encrypt_operation_constructor;
+@@ -249,21 +249,21 @@ gpa_stream_encrypt_operation_class_init (GpaStreamEncryptOperationClass *klass)
+   object_class->set_property = gpa_stream_encrypt_operation_set_property;
+   object_class->get_property = gpa_stream_encrypt_operation_get_property;
+
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_RECIPIENTS,
+-     g_param_spec_pointer
++     g_param_spec_pointer
+      ("recipients", "Recipients",
+       "A list of recipients in rfc-822 mailbox format.",
+       G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_RECIPIENT_KEYS,
+-     g_param_spec_pointer
++     g_param_spec_pointer
+      ("recipient-keys", "Recipient-keys",
+       "An array of gpgme_key_t with the selected keys.",
+       G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_PROTOCOL,
+-     g_param_spec_int
++     g_param_spec_int
+      ("protocol", "Protocol",
+       "The gpgme protocol currently selected.",
+       GPGME_PROTOCOL_OpenPGP, GPGME_PROTOCOL_UNKNOWN, GPGME_PROTOCOL_UNKNOWN,
+@@ -276,7 +276,7 @@ GType
+ gpa_stream_encrypt_operation_get_type (void)
+ {
+   static GType stream_encrypt_operation_type = 0;
+-
++
+   if (!stream_encrypt_operation_type)
+     {
+       static const GTypeInfo stream_encrypt_operation_info =
+@@ -291,12 +291,12 @@ gpa_stream_encrypt_operation_get_type (void)
+         0,    /* n_preallocs */
+         (GInstanceInitFunc) gpa_stream_encrypt_operation_init,
+       };
+-
+-      stream_encrypt_operation_type = g_type_register_static
++
++      stream_encrypt_operation_type = g_type_register_static
+       (GPA_STREAM_OPERATION_TYPE, "GpaStreamEncryptOperation",
+        &stream_encrypt_operation_info, 0);
+     }
+-
++
+   return stream_encrypt_operation_type;
+ }
+
+@@ -343,10 +343,14 @@ start_encryption (GpaStreamEncryptOperation *op)
+     goto leave;
+
+   /* Set the output encoding.  */
+-  if (GPA_STREAM_OPERATION (op)->input_stream
++  if (GPA_STREAM_OPERATION (op)->input_stream
+       && GPA_STREAM_OPERATION (op)->output_stream)
+     {
+-      if (op->selected_protocol == GPGME_PROTOCOL_CMS)
++      if (gpgme_data_get_encoding (GPA_STREAM_OPERATION(op)->output_stream))
++        gpgme_data_set_encoding
++          (GPA_STREAM_OPERATION (op)->output_stream,
++           gpgme_data_get_encoding (GPA_STREAM_OPERATION(op)->output_stream));
++      else if (op->selected_protocol == GPGME_PROTOCOL_CMS)
+         gpgme_data_set_encoding (GPA_STREAM_OPERATION (op)->output_stream,
+                                  GPGME_DATA_ENCODING_BASE64);
+       else
+@@ -358,8 +362,8 @@ start_encryption (GpaStreamEncryptOperation *op)
+           err = gpg_error (GPG_ERR_CONFLICT);
+           goto leave;
+         }
+-
+-      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
++
++      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
+                           op->selected_protocol);
+
+       /* We always trust the keys because the recipient selection
+@@ -376,7 +380,7 @@ start_encryption (GpaStreamEncryptOperation *op)
+
+       /* Show and update the progress dialog.  */
+       gtk_widget_show_all (GPA_STREAM_OPERATION (op)->progress_dialog);
+-      gpa_progress_dialog_set_label
++      gpa_progress_dialog_set_label
+         (GPA_PROGRESS_DIALOG (GPA_STREAM_OPERATION (op)->progress_dialog),
+          _("Message encryption"));
+     }
+@@ -394,13 +398,13 @@ start_encryption (GpaStreamEncryptOperation *op)
+
+
+ /* The recipient key selection dialog has returned.  */
+-static void
++static void
+ response_cb (GtkDialog *dialog, int response, void *user_data)
+ {
+   GpaStreamEncryptOperation *op = user_data;
+
+   gtk_widget_hide (GTK_WIDGET (dialog));
+-
++
+   if (response != GTK_RESPONSE_OK)
+     {
+       /* The dialog was canceled, so we do nothing and complete the
+@@ -514,7 +518,7 @@ gpa_stream_encrypt_operation_get_keys (GpaStreamEncryptOperation *op,
+                                        gpgme_protocol_t *r_protocol)
+ {
+   g_return_val_if_fail (op, NULL);
+-
++
+   if (r_protocol)
+     *r_protocol = op->selected_protocol;
+   return gpa_gpgme_copy_keyarray (op->keys);
+diff --git a/src/gpastreamsignop.c b/src/gpastreamsignop.c
+index 0b955eb..a19b0a3 100644
+--- a/src/gpastreamsignop.c
++++ b/src/gpastreamsignop.c
+@@ -28,19 +28,19 @@
+
+
+
+-struct _GpaStreamSignOperation
++struct _GpaStreamSignOperation
+ {
+   GpaStreamOperation parent;
+
+   GtkWidget *sign_dialog;
+-
++
+   const char *sender;
+   gpgme_protocol_t requested_protocol;
+   gboolean detached;
+ };
+
+
+-struct _GpaStreamSignOperationClass
++struct _GpaStreamSignOperationClass
+ {
+   GpaStreamOperationClass parent_class;
+ };
+@@ -48,7 +48,7 @@ struct _GpaStreamSignOperationClass
+
+
+ /* Indentifiers for our properties. */
+-enum
++enum
+   {
+     PROP_0,
+     PROP_SENDER,
+@@ -76,7 +76,7 @@ gpa_stream_sign_operation_get_property (GObject *object, guint prop_id,
+                                            GValue *value, GParamSpec *pspec)
+ {
+   GpaStreamSignOperation *op = GPA_STREAM_SIGN_OPERATION (object);
+-
++
+   switch (prop_id)
+     {
+     case PROP_SENDER:
+@@ -122,7 +122,7 @@ gpa_stream_sign_operation_set_property (GObject *object, guint prop_id,
+
+ static void
+ gpa_stream_sign_operation_finalize (GObject *object)
+-{
++{
+ /*   GpaStreamSignOperation *op = GPA_STREAM_SIGN_OPERATION (object); */
+
+   G_OBJECT_CLASS (parent_class)->finalize (object);
+@@ -171,7 +171,7 @@ gpa_stream_sign_operation_ctor (GType type, guint n_construct_properties,
+   g_signal_connect (G_OBJECT (GPA_OPERATION (op)->context), "done",
+                   G_CALLBACK (done_cb), op);
+
+-  gtk_window_set_title
++  gtk_window_set_title
+     (GTK_WINDOW (GPA_STREAM_OPERATION (op)->progress_dialog),
+                       _("Signing message ..."));
+
+@@ -186,7 +186,7 @@ static void
+ gpa_stream_sign_operation_class_init (GpaStreamSignOperationClass *klass)
+ {
+   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+-
++
+   parent_class = g_type_class_peek_parent (klass);
+
+   object_class->constructor = gpa_stream_sign_operation_ctor;
+@@ -194,22 +194,22 @@ gpa_stream_sign_operation_class_init (GpaStreamSignOperationClass *klass)
+   object_class->set_property = gpa_stream_sign_operation_set_property;
+   object_class->get_property = gpa_stream_sign_operation_get_property;
+
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_SENDER,
+-     g_param_spec_pointer
++     g_param_spec_pointer
+      ("sender", "Sender",
+       "The sender of the message in rfc-822 mailbox format or NULL.",
+       G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_PROTOCOL,
+-     g_param_spec_int
++     g_param_spec_int
+      ("protocol", "Protocol",
+       "The requested gpgme protocol.",
+       GPGME_PROTOCOL_OpenPGP, GPGME_PROTOCOL_UNKNOWN, GPGME_PROTOCOL_UNKNOWN,
+       G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
+-  g_object_class_install_property
++  g_object_class_install_property
+     (object_class, PROP_DETACHED,
+-     g_param_spec_boolean
++     g_param_spec_boolean
+      ("detached", "Detached",
+       "Flag requesting a detached signature.",
+       FALSE,
+@@ -221,7 +221,7 @@ GType
+ gpa_stream_sign_operation_get_type (void)
+ {
+   static GType stream_sign_operation_type = 0;
+-
++
+   if (!stream_sign_operation_type)
+     {
+       static const GTypeInfo stream_sign_operation_info =
+@@ -236,12 +236,12 @@ gpa_stream_sign_operation_get_type (void)
+         0,    /* n_preallocs */
+         (GInstanceInitFunc) gpa_stream_sign_operation_init,
+       };
+-
+-      stream_sign_operation_type = g_type_register_static
++
++      stream_sign_operation_type = g_type_register_static
+       (GPA_STREAM_OPERATION_TYPE, "GpaStreamSignOperation",
+        &stream_sign_operation_info, 0);
+     }
+-
++
+   return stream_sign_operation_type;
+ }
+
+@@ -274,11 +274,11 @@ set_signers (GpaStreamSignOperation *op, GList *signers)
+         {
+           /* Should not happen because the selection dialog should
+              have not allowed to select different key types.  */
+-          gpa_window_error
++          gpa_window_error
+             (_("The selected certificates are not all of the same type."
+                " That is, you mixed OpenPGP and X.509 certificates."
+                " Please make sure to select only certificates of the"
+-               " same type."),
++               " same type."),
+              GPA_OPERATION (op)->window);
+           return FALSE;
+         }
+@@ -311,7 +311,7 @@ start_signing (GpaStreamSignOperation *op)
+   GList *signers;
+   gpgme_protocol_t protocol;
+
+-  signers = gpa_file_sign_dialog_signers
++  signers = gpa_file_sign_dialog_signers
+     (GPA_FILE_SIGN_DIALOG (op->sign_dialog));
+   if (!set_signers (op, signers))
+     {
+@@ -332,29 +332,33 @@ start_signing (GpaStreamSignOperation *op)
+     goto leave;
+
+   /* Set the output encoding.  */
+-  if (GPA_STREAM_OPERATION (op)->input_stream
++  if (GPA_STREAM_OPERATION (op)->input_stream
+       && GPA_STREAM_OPERATION (op)->output_stream)
+     {
+-      if (protocol == GPGME_PROTOCOL_CMS)
++      if (gpgme_data_get_encoding (GPA_STREAM_OPERATION(op)->output_stream))
++        gpgme_data_set_encoding
++          (GPA_STREAM_OPERATION (op)->output_stream,
++           gpgme_data_get_encoding (GPA_STREAM_OPERATION(op)->output_stream));
++      else if (protocol == GPGME_PROTOCOL_CMS)
+         gpgme_data_set_encoding (GPA_STREAM_OPERATION (op)->output_stream,
+                                  GPGME_DATA_ENCODING_BASE64);
+       else
+         gpgme_set_armor (GPA_OPERATION (op)->context->ctx, 1);
+
+-      err = gpgme_op_sign_start (GPA_OPERATION (op)->context->ctx,
++      err = gpgme_op_sign_start (GPA_OPERATION (op)->context->ctx,
+                                  GPA_STREAM_OPERATION (op)->input_stream,
+                                  GPA_STREAM_OPERATION (op)->output_stream,
+                                  (op->detached? GPGME_SIG_MODE_DETACH
+-                                  /* */       : GPGME_SIG_MODE_NORMAL));
++                                  /* */       : GPGME_SIG_MODE_NORMAL));
+       if (err)
+         {
+           gpa_gpgme_warning (err);
+           goto leave;
+         }
+-
++
+       /* Show and update the progress dialog.  */
+       gtk_widget_show_all (GPA_STREAM_OPERATION (op)->progress_dialog);
+-      gpa_progress_dialog_set_label
++      gpa_progress_dialog_set_label
+         (GPA_PROGRESS_DIALOG (GPA_STREAM_OPERATION (op)->progress_dialog),
+          _("Message signing"));
+     }
+@@ -372,13 +376,13 @@ start_signing (GpaStreamSignOperation *op)
+
+
+ /* The recipient key selection dialog has returned.  */
+-static void
++static void
+ response_cb (GtkDialog *dialog, int response, void *user_data)
+ {
+   GpaStreamSignOperation *op = user_data;
+
+   gtk_widget_hide (GTK_WIDGET (dialog));
+-
++
+   if (response != GTK_RESPONSE_OK)
+     {
+       /* The dialog was canceled, so we do nothing and complete the
+@@ -448,7 +452,7 @@ done_cb (GpaContext *context, gpg_error_t err, GpaStreamSignOperation *op)
+           {
+             char *str;
+             char *algo_name;
+-
++
+             str = g_strdup_printf
+               ("%s%s", (protocol == GPGME_PROTOCOL_OpenPGP) ? "pgp-" : "",
+                gpgme_hash_algo_name (sig->hash_algo));
+diff --git a/src/server.c b/src/server.c
+index ee4ec8f..d220ccb 100644
+--- a/src/server.c
++++ b/src/server.c
+@@ -78,6 +78,9 @@ struct conn_ctrl_s
+   /* File descriptor set with the MESSAGE command.  */
+   int message_fd;
+
++  /* Flag indicating the the output shall be binary.  */
++  int output_binary;
++
+   /* Channels used with the gpgme callbacks.  */
+   GIOChannel *input_channel;
+   GIOChannel *output_channel;
+@@ -535,6 +538,8 @@ prepare_io_streams (assuan_context_t ctx,
+       err = gpgme_data_new_from_cbs (r_output_data, &my_gpgme_data_cbs, ctrl);
+       if (err)
+         goto leave;
++      if (ctrl->output_binary)
++        gpgme_data_set_encoding (*r_output_data, GPGME_DATA_ENCODING_BINARY);
+     }
+   if (ctrl->message_channel)
+     {
+@@ -1637,6 +1642,7 @@ reset_notify (assuan_context_t ctx, char *line)
+   assuan_close_output_fd (ctx);
+   ctrl->input_fd = -1;
+   ctrl->output_fd = -1;
++  ctrl->output_binary = 0;
+   if (ctrl->gpa_op)
+     {
+       g_object_unref (ctrl->gpa_op);
+@@ -1648,6 +1654,22 @@ reset_notify (assuan_context_t ctx, char *line)
+   return 0;
+ }
+
++
++static gpg_error_t
++output_notify (assuan_context_t ctx, char *line)
++{
++  conn_ctrl_t ctrl = assuan_get_pointer (ctx);
++
++  if (strstr (line, "--binary"))
++    ctrl->output_binary = 1;
++  else
++    ctrl->output_binary = 0;
++  /* Note: We also allow --armor and --base64 but because we don't
++     check for errors we don't need to parse them.  */
++  return 0;
++}
++
++
\f
+ /* Tell libassuan about our commands.   */
+ static int
+@@ -1738,6 +1760,7 @@ connection_startup (assuan_fd_t fd)
+   assuan_set_pointer (ctx, ctrl);
+   assuan_set_log_stream (ctx, stderr);
+   assuan_register_reset_notify (ctx, reset_notify);
++  assuan_register_output_notify (ctx, output_notify);
+   ctrl->message_fd = -1;
+
+   connection_counter++;
+--
+1.7.7.1