Using GnuPG::Interface daemonised

M

Matthew Braid

Hi all,

I've run into a problem using GnuPG::Interface. I'm not sure if it's the
package or GPG itself, but its kind of debilitating.

Basically, if my script's STDOUT/STDERR handles are not connected to a
terminal, GnuPG::Interface will return nothing on the stdout/stderr
handles, despite the fact that these are supplied as IO::Handles and
should (as far as I can tell) not be bound to STDOUT/STDERR unless I
explicitly made them so.

The following code is how I tested this. You'll need
gpg/GnuPG::Interface/a keyring/a default key without a password to make
this work:

============= START CODE =====================

use GnuPG::Interface;
#print "OK - CLOSE THE TERMINAL!\n";
#sleep(20);
print "HERE GOES!\n";
my $gpg = GnuPG::Interface->new;
$gpg->options->hash_init(armor => 1);
$gpg->options->meta_interactive(0);
$gpg->call('/usr/local/bin/gpg');
my ($in, $out, $err, $stat) = (IO::Handle->new, IO::Handle->new,
IO::Handle->new, IO::Handle->new);
my $pid = $gpg->sign(handles => GnuPG::Handles->new(stdin => $in,
stdout => $out,
stderr => $err,
status => $stat));
print $in "THIS IS A TEST";
close($in);
my @ciphered = <$out>;
close($out);
close($err);
close($stat);
waitpid($pid, 0);
print "CIPHERED IS: ", @ciphered, "\n";
$pid = $gpg->decrypt(handles => GnuPG::Handles->new(stdin => $in,
stdout => $out,
stderr => $err,
status => $stat));
print $in @ciphered;
close($in);

use IO::File;
my $mout = IO::File->new("|/usr/sbin/sendmail -ti");
print $mout "To: ME\n\n"; # <--- CHANGE THIS!!!

print $mout "DECRYPT STATUS IS: ", <$stat>, "\n\n";
close($stat);
print $mout "DECRYPT ERROR IS: ", <$err>, "\n\n";
close $mout;
close($err);
close($out);
waitpid($pid, 0);

============= END CODE =====================

You need to change the line with CHANGE THIS so it points to an email
address you can get to.

First time, run it from a terminal. All should be OK (as long as you
have GPG set up correctly) - you'll get an email to the address you added

Next, uncomment lines 2 and 3, and run it again.
This time, when "OK - CLOSE THE TERMINAL!" comes up, do as it says (I;m
assuming you're running this from withing a window manager too).

This time I get a message with contents of:

DECRYPT STATUS IS: [GNUPG:] NODATA 2


DECRYPT ERROR IS:

Further digging shows that the filehandles specified by stdout and
stderr (to GnuPG::Handles) are at EOF immediately. Nothing comes out of
there at all. The status handle however spits out data as normal.

Is there a way around this? This has been very disappointing as
GnuPG::Interface is otherwise very clean to use, and now I've had to go
back to juggling temp files.

MB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top