[svn] GnuPG - r4793 - in trunk: doc scd

svn author wk cvs at cvs.gnupg.org
Tue Jun 24 18:00:33 CEST 2008


Author: wk
Date: 2008-06-24 18:00:29 +0200 (Tue, 24 Jun 2008)
New Revision: 4793

Modified:
   trunk/doc/scdaemon.texi
   trunk/scd/ChangeLog
   trunk/scd/app-common.h
   trunk/scd/app-nks.c
   trunk/scd/app-openpgp.c
   trunk/scd/command.c
Log:
Add support for the TCOS NullPIN feature.


Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/scd/ChangeLog	2008-06-24 16:00:29 UTC (rev 4793)
@@ -1,3 +1,14 @@
+2008-06-24  Werner Koch  <wk at g10code.com>
+
+	* app-common.h (app_ctx_s): Renamed reset_mode parameter of
+	change_pin to mode_Flags and make it an unsigned int.
+	(APP_CHANGE_FLAG_RESET, APP_CHANGE_FLAG_NULLPIN): New.
+	* app-openpgp.c (do_change_pin): Adjust for that.
+
+	* command.c (cmd_passwd): Add option --nullpin.
+	* app-nks.c (do_check_pin, do_change_pin): New.
+	(app_select_nks): Register new functions.
+
 2008-04-21  Moritz Schulte  <mo at g10code.com>  (wk)
 
 	* app-openpgp.c (verify_a_chv): Make use of the default CHV flag.

Modified: trunk/doc/scdaemon.texi
===================================================================
--- trunk/doc/scdaemon.texi	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/doc/scdaemon.texi	2008-06-24 16:00:29 UTC (rev 4793)
@@ -580,11 +580,12 @@
 @subsection Change PINs.
 
 @example
-   PASSWD [--reset] @var{chvno}
+   PASSWD [--reset] [--nullpin] @var{chvno}
 @end example
   
 Change the PIN or reset the retry counter of the card holder
-verification vector number @var{chvno}.
+verification vector number @var{chvno}.  The option @option{--nullpin}
+is used to initialize the PIN of TCOS cards (6 byte NullPIN only).
 
 
 @node Scdaemon CHECKPIN

Modified: trunk/scd/app-common.h
===================================================================
--- trunk/scd/app-common.h	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/scd/app-common.h	2008-06-24 16:00:29 UTC (rev 4793)
@@ -31,6 +31,10 @@
 #endif
 
 
+#define APP_CHANGE_FLAG_RESET    1
+#define APP_CHANGE_FLAG_NULLPIN  2
+
+
 struct app_local_s;  /* Defined by all app-*.c.  */
 
 struct app_ctx_s {
@@ -101,7 +105,7 @@
                            gpg_error_t (*pincb)(void*, const char *, char **),
                            void *pincb_arg);
     gpg_error_t (*change_pin) (app_t app, ctrl_t ctrl,
-                       const char *chvnostr, int reset_mode,
+                       const char *chvnostr, unsigned int flags,
                        gpg_error_t (*pincb)(void*, const char *, char **),
                        void *pincb_arg);
     gpg_error_t (*check_pin) (app_t app, const char *keyidstr,

Modified: trunk/scd/app-nks.c
===================================================================
--- trunk/scd/app-nks.c	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/scd/app-nks.c	2008-06-24 16:00:29 UTC (rev 4793)
@@ -1,5 +1,5 @@
 /* app-nks.c - The Telesec NKS 2.0 card application.
- * Copyright (C) 2004, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -414,7 +414,7 @@
   if (indatalen != 20 && indatalen != 16 && indatalen != 35)
     return gpg_error (GPG_ERR_INV_VALUE);
 
-  /* Check that the provided ID is vaid.  This is not really needed
+  /* Check that the provided ID is valid.  This is not really needed
      but we do it to enforce correct usage by the caller. */
   if (strncmp (keyidstr, "NKS-DF01.", 9) ) 
     return gpg_error (GPG_ERR_INV_ID);
@@ -517,7 +517,66 @@
 }
 
 
+/* Handle the PASSWD command.  CHVNOSTR is currently ignored; we
+   always use VHV0.  RESET_MODE is not yet implemented.  */
+static gpg_error_t 
+do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr, 
+               unsigned int flags,
+               gpg_error_t (*pincb)(void*, const char *, char **),
+               void *pincb_arg)
+{
+  gpg_error_t err;
+  char *pinvalue;
+  const char *oldpin;
+  size_t oldpinlen;
 
+  if ((flags & APP_CHANGE_FLAG_RESET))
+    return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+
+  if ((flags & APP_CHANGE_FLAG_NULLPIN))
+    {
+      /* With the nullpin flag, we do not verify the PIN - it would fail
+         if the Nullpin is still set.  */
+      oldpin = "\0\0\0\0\0";
+      oldpinlen = 6;
+    }
+  else
+    {
+      err = verify_pin (app, pincb, pincb_arg);
+      if (err)
+        return err;
+      oldpin = NULL;
+      oldpinlen = 0;
+    }
+
+  /* TRANSLATORS: Do not translate the "|*|" prefixes but
+     keep it at the start of the string.  We need this elsewhere
+     to get some infos on the string. */
+  err = pincb (pincb_arg, _("|N|New PIN"), &pinvalue); 
+  if (err)
+    {
+      log_error (_("error getting new PIN: %s\n"), gpg_strerror (err));
+      return err;
+    }
+
+  err = iso7816_change_reference_data (app->slot, 0x00, 
+                                       oldpin, oldpinlen,
+                                       pinvalue, strlen (pinvalue));
+  xfree (pinvalue);
+  return err;
+}
+
+
+/* Perform a simple verify operation.  KEYIDSTR should be NULL or empty.  */
+static gpg_error_t 
+do_check_pin (app_t app, const char *keyidstr,
+              gpg_error_t (*pincb)(void*, const char *, char **),
+              void *pincb_arg)
+{
+  return verify_pin (app, pincb, pincb_arg);
+}
+
+
 /* Select the NKS 2.0 application.  */
 gpg_error_t
 app_select_nks (app_t app)
@@ -539,8 +598,8 @@
       app->fnc.sign = do_sign;
       app->fnc.auth = NULL;
       app->fnc.decipher = do_decipher;
-      app->fnc.change_pin = NULL;
-      app->fnc.check_pin = NULL;
+      app->fnc.change_pin = do_change_pin;
+      app->fnc.check_pin = do_check_pin;
    }
 
   return rc;

Modified: trunk/scd/app-openpgp.c
===================================================================
--- trunk/scd/app-openpgp.c	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/scd/app-openpgp.c	2008-06-24 16:00:29 UTC (rev 4793)
@@ -1644,13 +1644,15 @@
 
 /* Handle the PASSWD command. */
 static gpg_error_t 
-do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr, int reset_mode,
+do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr, 
+               unsigned int flags,
                gpg_error_t (*pincb)(void*, const char *, char **),
                void *pincb_arg)
 {
   int rc = 0;
   int chvno = atoi (chvnostr);
   char *pinvalue;
+  int reset_mode = !!(flags & APP_CHANGE_FLAG_RESET);
 
   if (reset_mode && chvno == 3)
     {

Modified: trunk/scd/command.c
===================================================================
--- trunk/scd/command.c	2008-06-23 14:43:14 UTC (rev 4792)
+++ trunk/scd/command.c	2008-06-24 16:00:29 UTC (rev 4793)
@@ -1273,18 +1273,24 @@
 }
 
 
-/* PASSWD [--reset] <chvno>
+/* PASSWD [--reset] [--nullpin] <chvno>
   
    Change the PIN or reset the retry counter of the card holder
-   verfication vector CHVNO. */
+   verfication vector CHVNO.  The option --nullpin is used for TCOS
+   cards to set the initial PIN. */
 static int
 cmd_passwd (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
   int rc;
   char *chvnostr;
-  int reset_mode = has_option (line, "--reset");
+  unsigned int flags = 0;
 
+  if (has_option (line, "--reset"))
+    flags |= APP_CHANGE_FLAG_RESET;
+  if (has_option (line, "--nullpin"))
+    flags |= APP_CHANGE_FLAG_NULLPIN;
+
   if ( IS_LOCKED (ctrl) )
     return gpg_error (GPG_ERR_LOCKED);
 
@@ -1312,7 +1318,7 @@
   chvnostr = xtrystrdup (chvnostr);
   if (!chvnostr)
     return out_of_core ();
-  rc = app_change_pin (ctrl->app_ctx, ctrl, chvnostr, reset_mode, pin_cb, ctx);
+  rc = app_change_pin (ctrl->app_ctx, ctrl, chvnostr, flags, pin_cb, ctx);
   if (rc)
     log_error ("command passwd failed: %s\n", gpg_strerror (rc));
   xfree (chvnostr);




More information about the Gnupg-commits mailing list