[git] Scute - branch, master, updated. scute-1.5.0-13-g90fe9f7

by Werner Koch cvs at cvs.gnupg.org
Mon Feb 18 17:21:38 CET 2019


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 "PKCS#11 token on top of gpg-agent".

The branch, master has been updated
       via  90fe9f7be2a386fa7e4d7869fec32a4f4e24151b (commit)
      from  a148c216517c6dcf2d339f5060c5b09164dd18c9 (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 90fe9f7be2a386fa7e4d7869fec32a4f4e24151b
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Feb 18 16:53:23 2019 +0100

    Clean up use of label and s/n in CK_TOKEN_INFO.
    
    * src/agent.c (scute_agent_learn): Also get the DISPSERIALNO.
    (learn_status_cb): Support it.
    * src/p11-gettokeninfo.c (C_GetTokenInfo): Simplify serialNumber
    setting.
    * src/slots.c (slot_token_label): Redirect to ...
    (slot_token_serial): here and remove the secial OpenPGP card handling
    which is not needed due to DISPSERIALNO.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/agent.c b/src/agent.c
index 3316c97..9a25820 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -463,6 +463,7 @@ scute_agent_release_card_info (struct agent_card_info_s *info)
     return;
 
   free (info->serialno);
+  free (info->dispserialno);
   free (info->cardtype);
   free (info->disp_name);
   free (info->disp_lang);
@@ -539,6 +540,11 @@ learn_status_cb (void *opaque, const char *line)
       free (parm->serialno);
       parm->serialno = store_serialno (line);
     }
+  else if (keywordlen == 13 && !memcmp (keyword, "$DISPSERIALNO", keywordlen))
+    {
+      free (parm->dispserialno);
+      parm->dispserialno = unescape_status_string (line);
+    }
   else if (keywordlen == 7 && !memcmp (keyword, "APPTYPE", keywordlen))
     {
       parm->is_piv = !strcmp (line, "PIV");
@@ -710,8 +716,9 @@ scute_agent_learn (struct agent_card_info_s *info)
 
   memset (info, 0, sizeof (*info));
   err = assuan_transact (agent_ctx, "LEARN --sendinfo",
-			 NULL, NULL, default_inq_cb,
-			 NULL, learn_status_cb, info);
+			 NULL, NULL,
+                         default_inq_cb, NULL,
+			 learn_status_cb, info);
   if (gpg_err_source(err) == GPG_ERR_SOURCE_SCD
       && gpg_err_code (err) == GPG_ERR_CARD_REMOVED)
     {
@@ -722,10 +729,23 @@ scute_agent_learn (struct agent_card_info_s *info)
         {
           memset (info, 0, sizeof (*info));
           err = assuan_transact (agent_ctx, "LEARN --sendinfo",
-                                 NULL, NULL, default_inq_cb,
-                                 NULL, learn_status_cb, info);
+                                 NULL, NULL,
+                                 default_inq_cb, NULL,
+                                 learn_status_cb, info);
         }
     }
+  if (!err)
+    {
+      /* Also try to get the human readabale serial number.  */
+      err = assuan_transact (agent_ctx, "SCD GETATTR $DISPSERIALNO",
+                             NULL, NULL,
+                             default_inq_cb, NULL,
+                             learn_status_cb, info);
+      if (gpg_err_code (err) == GPG_ERR_INV_NAME
+          || gpg_err_code (err) == GPG_ERR_UNSUPPORTED_OPERATION)
+        err = 0; /* Not implemented or GETATTR not supported.  */
+    }
+
 
   return err;
 }
diff --git a/src/agent.h b/src/agent.h
index 0b75f14..d14ebb7 100644
--- a/src/agent.h
+++ b/src/agent.h
@@ -61,7 +61,8 @@ typedef struct key_info_s *key_info_t;
 struct agent_card_info_s
 {
   char *serialno;	/* Malloced hex string.  */
-  char *cardtype;       /* Null or mallcoed string with the card type.  */
+  char *dispserialno;   /* NULL or malloced human readable S/N.  */
+  char *cardtype;       /* Null or malloced string with the card type.  */
   char *disp_name;	/* Malloced.  */
   char *disp_lang;	/* Malloced.  */
   int  disp_sex;	/* 0 = unspecified, 1 = male, 2 = female.  */
diff --git a/src/p11-gettokeninfo.c b/src/p11-gettokeninfo.c
index 4094f42..bb9190a 100644
--- a/src/p11-gettokeninfo.c
+++ b/src/p11-gettokeninfo.c
@@ -65,9 +65,7 @@ C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
   scute_copy_string (pInfo->manufacturerID,
 		     slot_token_manufacturer (slot), 32);
   scute_copy_string (pInfo->model, slot_token_application (slot), 16);
-  len = slot_token_serial (slot, pInfo->serialNumber);
-  while (len < 16)
-    pInfo->serialNumber[len++] = ' ';
+  scute_copy_string (pInfo->serialNumber, slot_token_serial (slot), 16);
 
   pInfo->flags = CKF_TOKEN_INITIALIZED
     | CKF_PROTECTED_AUTHENTICATION_PATH | CKF_WRITE_PROTECTED
diff --git a/src/slots.c b/src/slots.c
index 1e9b1a6..70d4ea2 100644
--- a/src/slots.c
+++ b/src/slots.c
@@ -536,14 +536,12 @@ slot_token_present (slot_iterator_t id)
 }
 
 
-/* Return the token label.  */
-char *
+/* Return the token label.  We use the dispserialno here too because
+ * Firefox prints that value in the prompt ("Stored at:").  */
+const char *
 slot_token_label (slot_iterator_t id)
 {
-  struct slot *slot = scute_table_data (slots, id);
-
-  /* slots_update() makes sure this is valid.  */
-  return slot->info.serialno;
+  return slot_token_serial (id);
 }
 
 
@@ -615,26 +613,14 @@ slot_token_application (slot_iterator_t id)
 }
 
 
-/* Get the serial number of the token.  Must not write more than 16
-   bytes starting from DST.  */
-int
-slot_token_serial (slot_iterator_t id, char *dst)
+/* Get the serial number of the token.  */
+const char *
+slot_token_serial (slot_iterator_t id)
 {
   struct slot *slot = scute_table_data (slots, id);
-  int i;
 
-  if (slot->info.is_piv)
-    {
-      strncpy (dst, slot->info.serialno, 15);
-      dst[15] = 0;
-      return 16;
-    }
-
-  /* slots_update() makes sure serialno is valid.  */
-  for (i = 0; i < 8; i++)
-    dst[i] = slot->info.serialno[20 + i];
-
-  return 8;
+  /* slots_update() makes sure this is valid.  */
+  return slot->info.dispserialno? slot->info.dispserialno : slot->info.serialno;
 }
 
 
diff --git a/src/slots.h b/src/slots.h
index ac34734..6783219 100644
--- a/src/slots.h
+++ b/src/slots.h
@@ -90,7 +90,7 @@ CK_RV slots_lookup (CK_SLOT_ID id, slot_iterator_t *slot);
 bool slot_token_present (slot_iterator_t slot);
 
 /* Return the token label.  */
-char *slot_token_label (slot_iterator_t id);
+const char *slot_token_label (slot_iterator_t id);
 
 /* Get the manufacturer of the token.  */
 const char *slot_token_manufacturer (slot_iterator_t id);
@@ -98,9 +98,8 @@ const char *slot_token_manufacturer (slot_iterator_t id);
 /* Get the application of the token.  */
 const char *slot_token_application (slot_iterator_t id);
 
-/* Get the serial number of the token.  Must not write more than 16
-   bytes starting from DST.  */
-int slot_token_serial (slot_iterator_t id, char *dst);
+/* Get the serial number of the token.  */
+const char *slot_token_serial (slot_iterator_t id);
 
 /* Get the manufacturer of the token.  */
 void slot_token_version (slot_iterator_t id,

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

Summary of changes:
 src/agent.c            | 28 ++++++++++++++++++++++++----
 src/agent.h            |  3 ++-
 src/p11-gettokeninfo.c |  4 +---
 src/slots.c            | 32 +++++++++-----------------------
 src/slots.h            |  7 +++----
 5 files changed, 39 insertions(+), 35 deletions(-)


hooks/post-receive
-- 
PKCS#11 token on top of gpg-agent
http://git.gnupg.org




More information about the Gnupg-commits mailing list