scd: Fix pinpad input support (backport from master)
authorNIIBE Yutaka <gniibe@fsij.org>
Thu, 1 Dec 2011 02:09:51 +0000 (11:09 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Mon, 25 Jun 2012 01:04:23 +0000 (10:04 +0900)
* app-openpgp.c (do_change_pin): Fix pincb messages when
use_keypad == 1.

scd/app-openpgp.c

index 950968c..4bae875 100644 (file)
@@ -1982,7 +1982,7 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
           if (chvno == 2)
             set_resetcode = 1;
         }
-      else if (chvno == 1 || chvno == 3)
+      else if (!use_keypad && (chvno == 1 || chvno == 3))
         {
           char *promptbuf = NULL;
           const char *prompt;
@@ -1997,7 +1997,7 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
             }
           else
             prompt = _("||Please enter the PIN");
-          rc = pincb (pincb_arg, prompt, use_keypad ? NULL : &oldpinvalue);
+          rc = pincb (pincb_arg, prompt, &oldpinvalue);
           xfree (promptbuf);
           promptbuf = NULL;
           if (rc)
@@ -2007,7 +2007,7 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
               goto leave;
             }
 
-          if (!use_keypad && strlen (oldpinvalue) < minlen)
+          if (strlen (oldpinvalue) < minlen)
             {
               log_info (_("PIN for CHV%d is too short;"
                           " minimum length is %d\n"), chvno, minlen);
@@ -2040,23 +2040,26 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
               log_error (_("Reset Code not or not anymore available\n"));
               rc = gpg_error (GPG_ERR_BAD_PIN);
               goto leave;
-            }          
-          
-          rc = pincb (pincb_arg,
-                      _("||Please enter the Reset Code for the card"),
-                      &resetcode); 
-          if (rc)
-            {
-              log_info (_("PIN callback returned error: %s\n"), 
-                        gpg_strerror (rc));
-              goto leave;
             }
-          if (strlen (resetcode) < minlen)
+
+          if (!use_keypad)
             {
-              log_info (_("Reset Code is too short; minimum length is %d\n"),
-                        minlen);
-              rc = gpg_error (GPG_ERR_BAD_PIN);
-              goto leave;
+              rc = pincb (pincb_arg,
+                          _("||Please enter the Reset Code for the card"),
+                          &resetcode);
+              if (rc)
+                {
+                  log_info (_("PIN callback returned error: %s\n"),
+                            gpg_strerror (rc));
+                  goto leave;
+                }
+              if (strlen (resetcode) < minlen)
+                {
+                  log_info (_("Reset Code is too short; minimum length is %d\n"),
+                            minlen);
+                  rc = gpg_error (GPG_ERR_BAD_PIN);
+                  goto leave;
+                }
             }
         }
       else
@@ -2090,18 +2093,36 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
 
   if (resetcode)
     {
-      char *buffer;
-
-      buffer = xtrymalloc (strlen (resetcode) + strlen (pinvalue) + 1);
-      if (!buffer)
-        rc = gpg_error_from_syserror ();
+      if (use_keypad)
+       {
+         rc = pincb (pincb_arg,
+                     _("||Please enter the Reset Code for the card and New PIN"),
+                     NULL);
+         if (rc)
+           {
+             log_info (_("PIN callback returned error: %s\n"),
+                       gpg_strerror (rc));
+             goto leave;
+           }
+         rc = iso7816_reset_retry_counter_with_rc_kp (app->slot, 0x81,
+                                                      &pininfo);
+         pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
+       }
       else
-        {
-          strcpy (stpcpy (buffer, resetcode), pinvalue);
-          rc = iso7816_reset_retry_counter_with_rc (app->slot, 0x81,
-                                                    buffer, strlen (buffer));
-          wipememory (buffer, strlen (buffer));
-          xfree (buffer);
+       {
+         char *buffer;
+
+         buffer = xtrymalloc (strlen (resetcode) + strlen (pinvalue) + 1);
+         if (!buffer)
+           rc = gpg_error_from_syserror ();
+         else
+           {
+             strcpy (stpcpy (buffer, resetcode), pinvalue);
+             rc = iso7816_reset_retry_counter_with_rc (app->slot, 0x81,
+                                                       buffer, strlen (buffer));
+             wipememory (buffer, strlen (buffer));
+             xfree (buffer);
+           }
         }
     }
   else if (set_resetcode)
@@ -2110,18 +2131,48 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
         {
           log_error (_("Reset Code is too short; minimum length is %d\n"), 8);
           rc = gpg_error (GPG_ERR_BAD_PIN);
-        }
+       }
       else
-        rc = iso7816_put_data (app->slot, 0, 0xD3,
-                               pinvalue, strlen (pinvalue));
+       {
+         if (use_keypad)
+           {
+             rc = pincb (pincb_arg,  _("|RN|New Reset Code"), NULL);
+             if (rc)
+               {
+                 log_info (_("PIN callback returned error: %s\n"),
+                           gpg_strerror (rc));
+                 goto leave;
+               }
+             rc = iso7816_put_data_kp (app->slot, 0xD3, &pininfo);
+             pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
+           }
+         else
+           rc = iso7816_put_data (app->slot, 0, 0xD3,
+                                  pinvalue, strlen (pinvalue));
+       }
     }
   else if (reset_mode)
     {
-      rc = iso7816_reset_retry_counter (app->slot, 0x81,
-                                        pinvalue, strlen (pinvalue));
-      if (!rc && !app->app_local->extcap.is_v2)
-        rc = iso7816_reset_retry_counter (app->slot, 0x82,
-                                          pinvalue, strlen (pinvalue));
+      if (use_keypad)
+        {
+          rc = pincb (pincb_arg, _("|N|New PIN"), NULL);
+          if (rc)
+            {
+              log_info (_("PIN callback returned error: %s\n"),
+                        gpg_strerror (rc));
+              goto leave;
+            }
+          rc = iso7816_reset_retry_counter_kp (app->slot, 0x81, &pininfo);
+          pincb (pincb_arg, NULL, NULL); /* Dismiss the prompt. */
+        }
+      else
+        {
+          rc = iso7816_reset_retry_counter (app->slot, 0x81,
+                                            pinvalue, strlen (pinvalue));
+          if (!rc && !app->app_local->extcap.is_v2)
+            rc = iso7816_reset_retry_counter (app->slot, 0x82,
+                                              pinvalue, strlen (pinvalue));
+        }
     }
   else if (!app->app_local->extcap.is_v2)
     {
@@ -2147,6 +2198,16 @@ do_change_pin (app_t app, ctrl_t ctrl,  const char *chvnostr,
 
       if (use_keypad)
         {
+          rc = pincb (pincb_arg,
+                      chvno == 3 ?
+                      _("||Please enter the Admin PIN and New Admin PIN") :
+                      _("||Please enter the PIN and New PIN"), NULL);
+          if (rc)
+            {
+              log_info (_("PIN callback returned error: %s\n"),
+                        gpg_strerror (rc));
+              goto leave;
+            }
           rc = iso7816_change_reference_data_kp (app->slot, 0x80 + chvno,
                                                  &pininfo);
           /* Dismiss the prompt. */