[svn] GnuPG - r4961 - in trunk: agent doc scd sm

svn author wk cvs at cvs.gnupg.org
Fri Mar 20 20:04:48 CET 2009


Author: wk
Date: 2009-03-20 20:04:47 +0100 (Fri, 20 Mar 2009)
New Revision: 4961

Modified:
   trunk/agent/ChangeLog
   trunk/agent/agent.h
   trunk/agent/learncard.c
   trunk/doc/DETAILS
   trunk/scd/ChangeLog
   trunk/scd/app-nks.c
   trunk/sm/ChangeLog
   trunk/sm/call-agent.c
   trunk/sm/keylist.c
Log:
Fix keygrip computation for TCOS 3 cards.
Emit PROGRESS status lines during --learn-card.


Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/agent/ChangeLog	2009-03-20 19:04:47 UTC (rev 4961)
@@ -1,3 +1,12 @@
+2009-03-20  Werner Koch  <wk at g10code.com>
+
+	* learncard.c (struct kpinfo_cp_parm_s): Add field CTRL.
+	(struct certinfo_cb_parm_s): Ditto.
+	(agent_handle_learn): Set CTRL field.
+	(kpinfo_cb, certinfo_cb): Send progress status.
+
+	* agent.h (agent_write_status): Flag with GNUPG_GCC_A_SENTINEL.
+
 2009-03-19  Werner Koch  <wk at g10code.com>
 
 	* trustlist.c (struct trustitem_s): Add field DISABLED.

Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/scd/ChangeLog	2009-03-20 19:04:47 UTC (rev 4961)
@@ -1,3 +1,7 @@
+2009-03-20  Werner Koch  <wk at g10code.com>
+
+	* app-nks.c (keygripstr_from_pk_file): Fix for TCOS 3 cards.
+
 2009-03-18  Werner Koch  <wk at g10code.com>
 
 	* apdu.c (open_pcsc_reader_wrapped): Use close_all_fds.

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/sm/ChangeLog	2009-03-20 19:04:47 UTC (rev 4961)
@@ -1,3 +1,11 @@
+2009-03-20  Werner Koch  <wk at g10code.com>
+
+	* keylist.c (list_internal_keys): Set released cert to NULL.
+
+	* call-agent.c (learn_status_cb): New.
+	(gpgsm_agent_learn): Use it.
+	(learn_cb): Send a progress for every certificate.
+
 2009-03-18  Werner Koch  <wk at g10code.com>
 
 	* gpgsm.h (struct opt): Move field WITH_EPHEMERAL_KEYS to struct

Modified: trunk/agent/agent.h
===================================================================
--- trunk/agent/agent.h	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/agent/agent.h	2009-03-20 19:04:47 UTC (rev 4961)
@@ -212,7 +212,8 @@
 
 /*-- command.c --*/
 gpg_error_t agent_inq_pinentry_launched (ctrl_t ctrl, unsigned long pid);
-gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...);
+gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...)
+     GNUPG_GCC_A_SENTINEL(0);
 void bump_key_eventcounter (void);
 void bump_card_eventcounter (void);
 void start_command_handler (ctrl_t, gnupg_fd_t, gnupg_fd_t);

Modified: trunk/agent/learncard.c
===================================================================
--- trunk/agent/learncard.c	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/agent/learncard.c	2009-03-20 19:04:47 UTC (rev 4961)
@@ -1,5 +1,5 @@
 /* learncard.c - Handle the LEARN command
- *	Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -32,7 +32,8 @@
 
 /* Structures used by the callback mechanism to convey information
    pertaining to key pairs.  */
-struct keypair_info_s {
+struct keypair_info_s 
+{
   struct keypair_info_s *next;
   int no_cert;
   char *id;          /* points into grip */
@@ -43,13 +44,14 @@
 };
 typedef struct keypair_info_s *KEYPAIR_INFO;
 
-struct kpinfo_cb_parm_s {
+struct kpinfo_cb_parm_s 
+{
+  ctrl_t ctrl;
   int error;
   KEYPAIR_INFO info;
 };
 
 
-
 /* Structures used by the callback mechanism to convey information
    pertaining to certificates.  */
 struct certinfo_s {
@@ -60,7 +62,9 @@
 };
 typedef struct certinfo_s *CERTINFO;
 
-struct certinfo_cb_parm_s {
+struct certinfo_cb_parm_s 
+{
+  ctrl_t ctrl;
   int error;
   CERTINFO info;
 };
@@ -130,6 +134,11 @@
 
   if (parm->error)
     return; /* no need to gather data after an error coccured */
+
+  if ((parm->error = agent_write_status (parm->ctrl, "PROGRESS",
+                                         "learncard", "k", "0", "0", NULL)))
+    return;
+
   item = xtrycalloc (1, sizeof *item + strlen (line));
   if (!item)
     {
@@ -183,6 +192,10 @@
   if (parm->error)
     return; /* no need to gather data after an error coccured */
 
+  if ((parm->error = agent_write_status (parm->ctrl, "PROGRESS",
+                                         "learncard", "c", "0", "0", NULL)))
+    return;
+
   type = strtol (line, &p, 10);
   while (spacep (p))
     p++;
@@ -296,6 +309,8 @@
   memset (&parm, 0, sizeof parm);
   memset (&cparm, 0, sizeof cparm);
   memset (&sparm, 0, sizeof sparm);
+  parm.ctrl = ctrl;
+  cparm.ctrl = ctrl;
 
   /* Check whether a card is present and get the serial number */
   rc = agent_card_serialno (ctrl, &serialno);

Modified: trunk/doc/DETAILS
===================================================================
--- trunk/doc/DETAILS	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/doc/DETAILS	2009-03-20 19:04:47 UTC (rev 4961)
@@ -518,7 +518,8 @@
                           still working.
              "starting_agent" - A gpg-agent was started because it is not
                           running as a daemon.
-
+             "learncard"  Send by the agent and gpgsm while learing
+	                  the data of a smartcard.
         
     SIG_CREATED <type> <pubkey algo> <hash algo> <class> <timestamp> <key fpr>
 	A signature has been created using these parameters.

Modified: trunk/scd/app-nks.c
===================================================================
--- trunk/scd/app-nks.c	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/scd/app-nks.c	2009-03-20 19:04:47 UTC (rev 4961)
@@ -124,7 +124,8 @@
   size_t buflen[2];
   gcry_sexp_t sexp;
   int i;
-  
+  int offset[2] = { 0, 0 };
+
   err = iso7816_select_file (app->slot, fid, 0, NULL, NULL);
   if (err)
     return err;
@@ -137,7 +138,7 @@
       xfree (buffer[0]);
       return err;
     }
-  
+
   if (app->app_local->nks_version < 3)
     {
       /* Old versions of NKS store the values in a TLV encoded format.
@@ -152,14 +153,55 @@
             err = gpg_error (GPG_ERR_TOO_SHORT);
           else if (buffer[i][1] != buflen[i]-2 )
             err = gpg_error (GPG_ERR_INV_OBJ);
+          else
+            offset[i] = 2;
         }
     }
+  else
+    {
+      /* Remove leading zeroes to get a correct keygrip.  Take care of
+         negative numbers.  We should also fix it the same way in
+         libgcrypt but we can't yet rely on it yet.  */
+      for (i=0; i < 2; i++)
+        {
+          while (buflen[i]-offset[i] > 1 
+                 && !buffer[i][offset[i]] 
+                 && !(buffer[i][offset[i]+1] & 0x80))
+            offset[i]++;
+        }
+    }
 
+  /* Check whether negative values are not prefixed with a zero and
+     fix that.  */
+  for (i=0; i < 2; i++)
+    {
+      if ((buflen[i]-offset[i]) && (buffer[i][offset[i]] & 0x80))
+        {
+          unsigned char *newbuf;          
+          size_t newlen;
+          
+          newlen = 1 + buflen[i] - offset[i];
+          newbuf = xtrymalloc (newlen);
+          if (!newlen)
+            {
+              xfree (buffer[0]);
+              xfree (buffer[1]);
+              return gpg_error_from_syserror ();
+            }
+          newbuf[0] = 0;
+          memcpy (newbuf+1, buffer[i]+offset[i], buflen[i] - offset[i]);
+          xfree (buffer[i]);
+          buffer[i] = newbuf;
+          buflen[i] = newlen;
+          offset[i] = 0;
+        }
+    }
+
   if (!err)
     err = gcry_sexp_build (&sexp, NULL,
                            "(public-key (rsa (n %b) (e %b)))",
-                           (int)buflen[0]-2, buffer[0]+2,
-                           (int)buflen[1]-2, buffer[1]+2);
+                           (int)buflen[0]-offset[0], buffer[0]+offset[0],
+                           (int)buflen[1]-offset[1], buffer[1]+offset[1]);
 
   xfree (buffer[0]);
   xfree (buffer[1]);

Modified: trunk/sm/call-agent.c
===================================================================
--- trunk/sm/call-agent.c	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/sm/call-agent.c	2009-03-20 19:04:47 UTC (rev 4961)
@@ -668,6 +668,25 @@
 
 
 static int
+learn_status_cb (void *opaque, const char *line)
+{
+  struct learn_parm_s *parm = opaque;
+
+  /* Pass progress data to the caller.  */
+  if (!strncmp (line, "PROGRESS", 8) && (line[8]==' ' || !line[8]))
+    {
+      if (parm->ctrl)
+        {
+          for (line += 8; *line == ' '; line++)
+            ;
+          if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, line))
+            return gpg_error (GPG_ERR_ASS_CANCELED);
+        }
+    }
+  return 0;
+}
+
+static int
 learn_cb (void *opaque, const void *buffer, size_t length)
 {
   struct learn_parm_s *parm = opaque;
@@ -692,6 +711,8 @@
       return 0;
     }
 
+  if (gpgsm_status (parm->ctrl, STATUS_PROGRESS, "learncard C 0 0"))
+    return gpg_error (GPG_ERR_ASS_CANCELED);
 
   /* FIXME: this should go into import.c */
   rc = ksba_cert_new (&cert);
@@ -755,7 +776,8 @@
   learn_parm.data = &data;
   rc = assuan_transact (agent_ctx, "LEARN --send",
                         learn_cb, &learn_parm, 
-                        NULL, NULL, NULL, NULL);
+                        NULL, NULL, 
+                        learn_status_cb, &learn_parm);
   xfree (get_membuf (&data, &len));
   if (rc)
     return rc;

Modified: trunk/sm/keylist.c
===================================================================
--- trunk/sm/keylist.c	2009-03-19 11:19:48 UTC (rev 4960)
+++ trunk/sm/keylist.c	2009-03-20 19:04:47 UTC (rev 4961)
@@ -1391,6 +1391,7 @@
       if (gpgsm_certs_identical_p (cert, lastcert))
 	{
 	  ksba_cert_release (cert);
+          cert = NULL;
 	  continue;
 	}
 




More information about the Gnupg-commits mailing list