Re: Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-07-05 Thread Jacob Adams
On 07/04/2018 01:23 PM, Werner Koch wrote:
> Hi!
> 
> Are you setting the homedir in your code also for the Assuan context?
> That might explain the behaviour.

I had been manually setting the Assuan context's homedir to ~/.gnupg by
accident (Was originally using a temporary directory, but that caused
all kinds of issues). Setting it to NULL instead appears to have fixed
the problem.

Thanks,
Jacob



signature.asc
Description: OpenPGP digital signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users


Re: Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-07-04 Thread Werner Koch
Hi!

Are you setting the homedir in your code also for the Assuan context?
That might explain the behaviour.


Shalom-Salam,

   Werner

-- 
#  Please read:  Daniel Ellsberg - The Doomsday Machine  #
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.


pgpGNpv0Jj7Xp.pgp
Description: PGP signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users


Re: Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-07-04 Thread Werner Koch
On Wed, 27 Jun 2018 22:50, tookm...@gmail.com said:

> 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

The gpg-agent log shows that the pinentry started on behalf of the "SCD
PASSWD 1" does not send the ttyname to pinentry.  I will do some code
staring ...


Salam-Shalom,

   Werner

-- 
#  Please read:  Daniel Ellsberg - The Doomsday Machine  #
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.


pgpaIpAkt7x7c.pgp
Description: PGP signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users


Re: Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-07-03 Thread Jacob Adams
On 06/29/2018 07:45 PM, Jacob Adams wrote:
> 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
>>

> 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.

I have a solution for this but it's definitely the wrong solution.

I've applied the following patch to pinentry to fix this problem:

--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -1187,7 +1187,8 @@
   alarm (pinentry->timeout);
 }
 #endif
-
+  if (pinentry->ttyname == NULL)
+pinentry->ttyname = getenv("GPG_TTY");
   rc = dialog_run (pinentry, pinentry->ttyname, pinentry->ttytype);
   do_touch_file (pinentry);
   return rc;

Clearly this is not the right approach as it appears that gpg-agent is
supposed to handle the GPG_TTY variable. For some reason, it is simply
not passing it on to pinentry in this one case.

I've tried to reproduce this issue in a separate program but have been
unsuccessful. However it's consistently reproducible without this patch
in my program. Does anyone have an insight into why this patch would be
required?

Thanks,
Jacob



signature.asc
Description: OpenPGP digital signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users


Re: Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-06-29 Thread Jacob Adams
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


--- a/pinentry/pinentry-curses.c
+++ b/pinentry/pinentry-curses.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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, ))
 {
+   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 ())


signature.asc
Description: OpenPGP digital signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users


Pinentry: Inappropriate ioctl for device when getting smartcard PIN

2018-06-27 Thread Jacob Adams
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'm really not sure what's going wrong here and any insight would be
much appreciated.

Thanks,
Jacob



signature.asc
Description: OpenPGP digital signature
___
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users