Pinentry: Inappropriate ioctl for device when getting smartcard PIN

Jacob Adams tookmund at gmail.com
Sat Jun 30 01:45:16 CEST 2018


On 06/27/2018 04:50 PM, Jacob Adams wrote:
> I've got another pinentry problem unfortunately.
> The tty is owned by the correct user this time and $GPG_TTY is set
> correctly.
> 
> I have two gpgme contexts, one for openpgp and another for assuan
> commands to the smartcard. Pinentry triggered by the openpgp context
> works perfectly, but any pinentry launched in service of the assuan
> context fails with the error in the subject. They're both using the same
> gpg-agent launched shortly after the creation of the openpgp context
> with gpgconf --launch gpg-agent.
> 
> The relevant logs are available at:
> https://salsa.debian.org/tookmund-guest/pgpcr/issues/10
> 

I've now done a bit of poking around into this.
Attached is the patch I used to try and get some information out of
pinentry-curses.

It appears that tty_name is not being set, despite the fact that GPG_TTY
is set and thus gpg-agent has this information from the previous Context.

> I'm really not sure what's going wrong here and any insight would be
> much appreciated.

The above is still definitely true.

Thanks,
Jacob


-------------- next part --------------
--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -26,6 +26,7 @@
 #include <signal.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <locale.h>
 #include <iconv.h>
@@ -820,6 +821,16 @@
 dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
 {
   int confirm_mode = !pinentry->pin;
+  FILE *log = fopen("/tmp/pinentry-curses.log", "a");
+  if (log == NULL)
+  {
+    pinentry->specific_err = gpg_error_from_syserror ();
+    pinentry->specific_err_loc = "log_setup";
+    return confirm_mode? 0 : -1;
+  }
+  fputs("Pinentry\n", log);
+  fprintf(log, "TTY Name: %s\nTTY Type: %s\n", tty_name, tty_type);
+  fprintf(log, "Title: %s\nDescription: %s\n", pinentry->title, pinentry->description);
   struct dialog diag;
   FILE *ttyfi = NULL;
   FILE *ttyfo = NULL;
@@ -853,6 +864,7 @@
           pinentry->specific_err_loc = "open_tty_for_read";
           return confirm_mode? 0 : -1;
         }
+	  fputs("Open TTY for reading\n", log);
       ttyfo = fopen (tty_name, "w");
       if (!ttyfo)
 	{
@@ -863,15 +875,19 @@
           pinentry->specific_err_loc = "open_tty_for_write";
 	  return confirm_mode? 0 : -1;
 	}
+	  fputs("Open TTY for writing\n", log);
       screen = newterm (tty_type, ttyfo, ttyfi);
       set_term (screen);
+	  fputs("Setup screen\n", log);
     }
   else
     {
       if (!init_screen)
 	{
+		fputs("No init screen\n", log);
           if (!(isatty(fileno(stdin)) && isatty(fileno(stdout))))
             {
+		      fputs("ENOTTY\n", log);
               errno = ENOTTY;
               pinentry->specific_err = gpg_error_from_syserror ();
               pinentry->specific_err_loc = "isatty";
@@ -879,6 +895,7 @@
             }
 	  init_screen = 1;
 	  initscr ();
+	  fputs("Setup ncurses\n", log);
 	}
       else
 	clear ();
@@ -921,10 +938,11 @@
 	}
     }
   refresh ();
-
+fputs("Create dialog\n", log);
   /* Create the dialog.  */
   if (dialog_create (pinentry, &diag))
     {
+	fputs("Failed to create dialog\n", log);
       /* Note: pinentry->specific_err has already been set.  */
       endwin ();
       if (screen)
@@ -951,6 +969,7 @@
 
   do
     {
+	  fputs("Made it to event loop\n", log);
       int c;
 
       c = wgetch (stdscr);     /* Refresh, accept single keystroke of input.  */
--- a/curses/pinentry-curses.c
+++ b/curses/pinentry-curses.c
@@ -34,8 +34,17 @@
 int
 main (int argc, char *argv[])
 {
+  FILE *log = fopen("/tmp/pinentry-args.log", "a");
+  if (log == NULL)
+  {
+	return 1;
+  }
+  fputs("Begin Pinentry\n", log);
   pinentry_init ("pinentry-curses");
-
+  for (int i = 0; i < argc; i++)
+  {
+	  fprintf(log, "%d: %s\n", i, argv[i]);
+  }
   pinentry_parse_opts (argc, argv);
 
   if (pinentry_loop ())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20180629/36fca73d/attachment.sig>


More information about the Gnupg-users mailing list