Using GnuPG::Interface daemonised

Discussion in 'Perl Misc' started by Matthew Braid, Oct 29, 2003.

  1. 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
     
    Matthew Braid, Oct 29, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    400
    alisonken1
    Jan 9, 2008
  2. Brot

    smtplib & gnupg

    Brot, Feb 20, 2008, in forum: Python
    Replies:
    2
    Views:
    599
  3. Vinay Sajip
    Replies:
    0
    Views:
    308
    Vinay Sajip
    Jul 4, 2009
  4. Vinay Sajip

    ANN: gnupg v0.2.0 released

    Vinay Sajip, Jul 17, 2009, in forum: Python
    Replies:
    0
    Views:
    464
    Vinay Sajip
    Jul 17, 2009
  5. Vinay Sajip

    ANN: gnupg v0.2.1 released

    Vinay Sajip, Aug 8, 2009, in forum: Python
    Replies:
    0
    Views:
    491
    Vinay Sajip
    Aug 8, 2009
Loading...

Share This Page