[git] Pinentry - branch, master, updated. pinentry-0.8.4-4-g2ef788f

by Werner Koch cvs at cvs.gnupg.org
Fri Oct 24 20:41:53 CEST 2014


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 standard pinentry collection".

The branch, master has been updated
       via  2ef788fb5dce2e49fa925264802388f4c002cd31 (commit)
       via  e483abb883f65719ce8008a211f49b8d207ee4af (commit)
       via  9f78f0709d9ba60677129c179f7f0ef835c51c1d (commit)
      from  b3ecb6497373119a67794aae44633d7b1ed4b962 (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 2ef788fb5dce2e49fa925264802388f4c002cd31
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 24 16:10:15 2014 +0200

    gtk+-2: Make current focus visible again.
    
    * gtk+-2/pinentry-gtk-2.c (grab_keyboard): Return false
    (ungrab_keyboard): Ditto.
    --
    
    Probably due to a change in GTK+ the grab handler now need to return a
    flag wether to call the other event handler.  Without that the focus
    was not visible.

diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index 10298d6..8322530 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -132,11 +132,11 @@ make_transient (GtkWidget *win, GdkEvent *event, gpointer data)
 
 
 /* Grab the keyboard for maximum security */
-static void
+static int
 grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
 {
   if (! pinentry->grab)
-    return;
+    return FALSE;
 
   if (gdk_keyboard_grab (win->window, FALSE, gdk_event_get_time (event)))
     {
@@ -144,11 +144,12 @@ grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
       grab_failed = 1;
       gtk_main_quit ();
     }
+  return FALSE;
 }
 
 
 /* Remove grab.  */
-static void
+static int
 ungrab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
 {
   gdk_keyboard_ungrab (gdk_event_get_time (event));
@@ -158,6 +159,7 @@ ungrab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
      code is taken from gtk_window_transient_parent_unrealized.  */
   gdk_property_delete (win->window,
                        gdk_atom_intern_static_string ("WM_TRANSIENT_FOR"));
+  return FALSE;
 }
 
 

commit e483abb883f65719ce8008a211f49b8d207ee4af
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 24 16:11:59 2014 +0200

    gtk+-2: Implement the SETREPEAT command.
    
    * gtk+-2/pinentry-gtk-2.c (repeat_entry, error_label): New.
    (button_clicked): Implement repeat check.
    (changed_text_handler): Clear repeat field.
    (create_window): Add repeat entry.

diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
index 421bc02..10298d6 100644
--- a/gtk+-2/pinentry-gtk-2.c
+++ b/gtk+-2/pinentry-gtk-2.c
@@ -58,6 +58,8 @@ typedef enum { CONFIRM_CANCEL, CONFIRM_OK, CONFIRM_NOTOK } confirm_value_t;
 static confirm_value_t confirm_value;
 
 static GtkWidget *entry;
+static GtkWidget *repeat_entry;
+static GtkWidget *error_label;
 static GtkWidget *qualitybar;
 #ifdef ENABLE_ENHANCED
 static GtkWidget *insure;
@@ -173,22 +175,40 @@ button_clicked (GtkWidget *widget, gpointer data)
 {
   if (data)
     {
-      const char *s;
+      const char *s, *s2;
 
       /* Okay button or enter used in text field.  */
 #ifdef ENABLE_ENHANCED
       /* FIXME: This is not compatible with assuan.  We can't just
 	 print stuff on stdout.  */
-      if (pinentry->enhanced)
-	printf ("Options: %s\nTimeout: %d\n\n",
-		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (insure))
-		? "insure" : "",
-		gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (time_out)));
+      /* if (pinentry->enhanced) */
+      /*   printf ("Options: %s\nTimeout: %d\n\n", */
+      /*   	gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (insure)) */
+      /*   	? "insure" : "", */
+      /*   	gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (time_out))); */
 #endif
 
       s = gtk_secure_entry_get_text (GTK_SECURE_ENTRY (entry));
       if (!s)
 	s = "";
+
+      if (pinentry->repeat_passphrase && repeat_entry)
+        {
+          s2 = gtk_secure_entry_get_text (GTK_SECURE_ENTRY (repeat_entry));
+          if (!s2)
+            s2 = "";
+          if (strcmp (s, s2))
+            {
+              gtk_label_set_text (GTK_LABEL (error_label),
+                                  pinentry->repeat_error_string?
+                                  pinentry->repeat_error_string:
+                                  "not correctly repeated");
+              gtk_widget_grab_focus (entry);
+              return; /* again */
+            }
+          pinentry->repeat_okay = 1;
+        }
+
       passphrase_ok = 1;
       pinentry_setbufferlen (pinentry, strlen (s) + 1);
       if (pinentry->pin)
@@ -252,6 +272,12 @@ changed_text_handler (GtkWidget *widget)
 
   got_input = TRUE;
 
+  if (pinentry->repeat_passphrase && repeat_entry)
+    {
+      gtk_secure_entry_set_text (GTK_SECURE_ENTRY (repeat_entry), "");
+      gtk_label_set_text (GTK_LABEL (error_label), "");
+    }
+
   if (!qualitybar || !pinentry->quality_bar)
     return;
 
@@ -369,25 +395,41 @@ create_window (int confirm_mode)
       gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
       gtk_box_pack_start (GTK_BOX (box), w, TRUE, FALSE, 0);
     }
-  if (pinentry->error && !confirm_mode)
+  if (!confirm_mode && (pinentry->error || pinentry->repeat_passphrase))
     {
+      /* With the repeat passphrase option we need to create the label
+         in any case so that it may later be updated by the error
+         message.  */
       GdkColor color = { 0, 0xffff, 0, 0 };
 
-      msg = pinentry_utf8_validate (pinentry->error);
-      w = gtk_label_new (msg);
-      g_free (msg);
-      gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
-      gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
-      gtk_box_pack_start (GTK_BOX (box), w, TRUE, FALSE, 0);
-      gtk_widget_modify_fg (w, GTK_STATE_NORMAL, &color);
+      if (pinentry->error)
+        msg = pinentry_utf8_validate (pinentry->error);
+      else
+        msg = "";
+      error_label = gtk_label_new (msg);
+      if (pinentry->error)
+        g_free (msg);
+      gtk_misc_set_alignment (GTK_MISC (error_label), 0.0, 0.5);
+      gtk_label_set_line_wrap (GTK_LABEL (error_label), TRUE);
+      gtk_box_pack_start (GTK_BOX (box), error_label, TRUE, FALSE, 0);
+      gtk_widget_modify_fg (error_label, GTK_STATE_NORMAL, &color);
     }
 
   qualitybar = NULL;
 
   if (!confirm_mode)
     {
-      GtkWidget* table = gtk_table_new (pinentry->quality_bar ? 2 : 1, 2,
-					FALSE);
+      int nrow;
+      GtkWidget* table;
+
+      nrow = 1;
+      if (pinentry->quality_bar)
+        nrow++;
+      if (pinentry->repeat_passphrase)
+        nrow++;
+
+      table = gtk_table_new (nrow, 2, FALSE);
+      nrow = 0;
       gtk_box_pack_start (GTK_BOX (box), table, FALSE, FALSE, 0);
 
       if (pinentry->prompt)
@@ -396,7 +438,7 @@ create_window (int confirm_mode)
 	  w = gtk_label_new_with_mnemonic (msg);
 	  g_free (msg);
 	  gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
-	  gtk_table_attach (GTK_TABLE (table), w, 0, 1, 0, 1,
+	  gtk_table_attach (GTK_TABLE (table), w, 0, 1, nrow, nrow+1,
 			    GTK_FILL, GTK_FILL, 4, 0);
 	}
 
@@ -406,10 +448,11 @@ create_window (int confirm_mode)
 			G_CALLBACK (enter_callback), entry);
       g_signal_connect (G_OBJECT (entry), "changed",
                         G_CALLBACK (changed_text_handler), entry);
-      gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
+      gtk_table_attach (GTK_TABLE (table), entry, 1, 2, nrow, nrow+1,
                         GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
       gtk_widget_grab_focus (entry);
       gtk_widget_show (entry);
+      nrow++;
 
       if (pinentry->quality_bar)
 	{
@@ -417,7 +460,7 @@ create_window (int confirm_mode)
 	  w = gtk_label_new (msg);
           g_free (msg);
 	  gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
-	  gtk_table_attach (GTK_TABLE (table), w, 0, 1, 1, 2,
+	  gtk_table_attach (GTK_TABLE (table), w, 0, 1, nrow, nrow+1,
 			    GTK_FILL, GTK_FILL, 4, 0);
 	  qualitybar = gtk_progress_bar_new();
 	  gtk_widget_add_events (qualitybar,
@@ -428,10 +471,33 @@ create_window (int confirm_mode)
           if (pinentry->quality_bar_tt)
             gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), qualitybar,
                                   pinentry->quality_bar_tt, "");
-	  gtk_table_attach (GTK_TABLE (table), qualitybar, 1, 2, 1, 2,
+	  gtk_table_attach (GTK_TABLE (table), qualitybar, 1, 2, nrow, nrow+1,
 	  		    GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
+          nrow++;
 	}
 
+
+      if (pinentry->repeat_passphrase)
+        {
+	  msg = pinentry_utf8_validate (pinentry->repeat_passphrase);
+	  w = gtk_label_new (msg);
+	  g_free (msg);
+	  gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
+	  gtk_table_attach (GTK_TABLE (table), w, 0, 1, nrow, nrow+1,
+			    GTK_FILL, GTK_FILL, 4, 0);
+
+          repeat_entry = gtk_secure_entry_new ();
+          gtk_widget_set_size_request (repeat_entry, 200, -1);
+          g_signal_connect (G_OBJECT (entry), "activate",
+                            G_CALLBACK (enter_callback), repeat_entry);
+          gtk_table_attach (GTK_TABLE (table), repeat_entry, 1, 2, nrow, nrow+1,
+                            GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
+          gtk_widget_grab_focus (entry);
+          gtk_widget_show (entry);
+          nrow++;
+        }
+
+
 #ifdef ENABLE_ENHANCED
       if (pinentry->enhanced)
 	{

commit 9f78f0709d9ba60677129c179f7f0ef835c51c1d
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Oct 24 16:20:20 2014 +0200

    Add commands to allow implementing a "repeat passphrase" field.
    
    * pinentry/pinentry.c (cmd_setrepeat): New.
    (cmd_setrepeaterror): New.
    (register_commands): Add new commands.
    (cmd_getpin): Print "PIN_REPEATED" status.

diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
index 4f7958a..0030754 100644
--- a/pinentry/pinentry.c
+++ b/pinentry/pinentry.c
@@ -85,6 +85,9 @@ struct pinentry pinentry =
     0,		/* Close button flag.  */
     0,          /* Locale error flag. */
     0,          /* One-button flag.  */
+    NULL,       /* Repeat passphrase flag.  */
+    NULL,       /* Repeat error string.  */
+    0,          /* Correctly repeated flag.  */
     NULL,       /* Quality-Bar flag and description.  */
     NULL,       /* Quality-Bar tooltip.  */
     PINENTRY_COLOR_DEFAULT,
@@ -759,6 +762,38 @@ cmd_setprompt (ASSUAN_CONTEXT ctx, char *line)
 
 
 static int
+cmd_setrepeat (ASSUAN_CONTEXT ctx, char *line)
+{
+  char *p;
+
+  p = malloc (strlen (line) + 1);
+  if (!p)
+    return ASSUAN_Out_Of_Core;
+
+  strcpy_escaped (p, line);
+  free (pinentry.repeat_passphrase);
+  pinentry.repeat_passphrase = p;
+  return 0;
+}
+
+
+static int
+cmd_setrepeaterror (ASSUAN_CONTEXT ctx, char *line)
+{
+  char *p;
+
+  p = malloc (strlen (line) + 1);
+  if (!p)
+    return ASSUAN_Out_Of_Core;
+
+  strcpy_escaped (p, line);
+  free (pinentry.repeat_error_string);
+  pinentry.repeat_error_string = p;
+  return 0;
+}
+
+
+static int
 cmd_seterror (ASSUAN_CONTEXT ctx, char *line)
 {
   char *newe;
@@ -909,6 +944,7 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
     }
   pinentry.locale_err = 0;
   pinentry.close_button = 0;
+  pinentry.repeat_okay = 0;
   pinentry.one_button = 0;
   pinentry.ctx_assuan = ctx;
   result = (*pinentry_cmd_handler) (&pinentry);
@@ -918,6 +954,11 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
       free (pinentry.error);
       pinentry.error = NULL;
     }
+  if (pinentry.repeat_passphrase)
+    {
+      free (pinentry.repeat_passphrase);
+      pinentry.repeat_passphrase = NULL;
+    }
   if (set_prompt)
     pinentry.prompt = NULL;
 
@@ -938,6 +979,8 @@ cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
 
   if (result)
     {
+      if (pinentry.repeat_okay)
+        assuan_write_status (ctx, "PIN_REPEATED", "");
       result = assuan_send_data (ctx, pinentry.pin, result);
       if (!result)
 	result = assuan_send_data (ctx, NULL, 0);
@@ -1058,6 +1101,8 @@ register_commands (ASSUAN_CONTEXT ctx)
     {
       { "SETDESC",    0,  cmd_setdesc },
       { "SETPROMPT",  0,  cmd_setprompt },
+      { "SETREPEAT",  0,  cmd_setrepeat },
+      { "SETREPEATERROR",0, cmd_setrepeaterror },
       { "SETERROR",   0,  cmd_seterror },
       { "SETOK",      0,  cmd_setok },
       { "SETNOTOK",   0,  cmd_setnotok },
diff --git a/pinentry/pinentry.h b/pinentry/pinentry.h
index d4f86f9..d419550 100644
--- a/pinentry/pinentry.h
+++ b/pinentry/pinentry.h
@@ -1,20 +1,20 @@
 /* pinentry.h - The interface for the PIN entry support library.
    Copyright (C) 2002, 2003, 2010 g10 Code GmbH
-   
+
    This file is part of PINENTRY.
-   
+
    PINENTRY is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
- 
+
    PINENTRY is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
- 
+
    You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>. 
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifndef PINENTRY_H
@@ -22,7 +22,7 @@
 
 #ifdef __cplusplus
 extern "C" {
-#if 0 
+#if 0
 }
 #endif
 #endif
@@ -111,6 +111,18 @@ struct pinentry
      dismiss button is required. */
   int one_button;
 
+  /* If true a second prompt for the passphrase is show and the user
+     is expected to enter the same passphrase again.  Pinentry checks
+     that both match.  */
+  char *repeat_passphrase;
+
+  /* The string to show if a repeated passphrase does not match.  */
+  char *repeat_error_string;
+
+  /* Set to true if the passphrase has been entered a second time and
+     matches the first passphrase.  */
+  int repeat_okay;
+
   /* If this is not NULL, a passphrase quality indicator is shown.
      There will also be an inquiry back to the caller to get an
      indication of the quality for the passphrase entered so far.  The
@@ -170,7 +182,7 @@ char *pinentry_local_to_utf8 (char *lc_ctype, char *text, int secure);
 
 
 /* Run a quality inquiry for PASSPHRASE of LENGTH. */
-int pinentry_inq_quality (pinentry_t pin, 
+int pinentry_inq_quality (pinentry_t pin,
                           const char *passphrase, size_t length);
 
 /* Try to make room for at least LEN bytes for the pin in the pinentry
@@ -206,7 +218,7 @@ extern pinentry_cmd_handler_t pinentry_cmd_handler;
 
 
 
-#if 0 
+#if 0
 {
 #endif
 #ifdef __cplusplus

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

Summary of changes:
 gtk+-2/pinentry-gtk-2.c |  114 +++++++++++++++++++++++++++++++++++++----------
 pinentry/pinentry.c     |   45 +++++++++++++++++++
 pinentry/pinentry.h     |   28 ++++++++----
 3 files changed, 156 insertions(+), 31 deletions(-)


hooks/post-receive
-- 
The standard pinentry collection
http://git.gnupg.org




More information about the Gnupg-commits mailing list