Molloc has asked for the wisdom of the Perl Monks concerning the following question:

I'm throwing a dictionary at a --symmetric Gnupg file:
#!/usr/bin/perl -w use strict; open (DICT ,"/usr/share/dict/linux.words") || die "can't read +dictionary: $!\n"; while (<DICT>) { my @tab=split("\n",<DICT>); for ( my $cnt = 0 ; $cnt < @tab ; $cnt++ ) { system ('gpg ~/file.gpg'); sleep (2); print $tab[$cnt], "\r"; #also tried 'system ($tab[$cnt])', no d +ice. } } close DICT;
...but when gpg promts for a passphrase, the dictionary word doesn't appear until I hit enter. How can I get my word to the passphrase prompt? Thanks, Seth Jackson.

Replies are listed 'Best First'.
Re: GPG w/o modules question
by sgifford (Prior) on Jul 19, 2003 at 06:10 UTC
    Maybe these command-line options will help you:
    --passphrase-fd n
    Read the passphrase from file descriptor n. If you use 0 for n, the passphrase will be read from stdin. This can only be used if only one passphrase is supplied. Don't use this option if you can avoid it.
    --command-fd n
    This is a replacement for the deprecated shared-memory IPC mode. If this option is enabled, user input on questions is not expected from the TTY but from the given file descriptor. It should be used together with --status-fd. See the file doc/DETAILS in the source distribution for details on how to use it.
    --status-fd n
    Write special status strings to the file descriptor n. See the file DETAILS in the documentation for a listing of them.
      Thank you, I missed that section of the man page. Works great now, using --passphrase-fd 0. BTW, why should that option be avoided?

        I have no idea; that's just pasted from the manpage. Maybe using the other two options makes error handling easier?...

        Because it is much safer if you enter the password yourself, instead of using a program that knows the password. The program can get broken and expose your password.

Re: GPG w/o modules question
by sauoq (Abbot) on Jul 19, 2003 at 09:23 UTC

    Change your system call to this:

    system( "echo $tab[$cnt] | gpg --passphrase-fd 0 ~/file.gpg" );
    And that should do it.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: GPG w/o modules question
by vek (Prior) on Jul 19, 2003 at 07:28 UTC

    Just out of curiosity, why are you against using modules? I use Crypt::GPG in production with great success.

    -- vek --
      Vex- Either a do it yourself reinvent the wheel walk uphill both ways attitude, or too much laziness to sift through all of the modules out there..
      I did take a look at CRYPT::GPG and will probably make use of it soon, I just had spent a couple of hours trying to make my code work and more wanted to know that it was possible to do it that way.

      Thanks to all of you for helping me out.
Re: GPG w/o modules question
by bobn (Chaplain) on Jul 19, 2003 at 06:13 UTC

    perldoc -f open with attention to the magic open, as in open(OUT, "|gpg ~/file.gpg") (might also be in perldoc perlipc) - but I suspect this won't work because things like gpg, when interacting with users, really want to talk with a terminal. At the very least you'll probably be dealing with Expect.pm, and the perl gpg modules may be unavoidable and/or less painful that what you'll go through trying to avoid them.

    --Bob Niederman, http://bob-n.com
Re: GPG w/o modules question
by naChoZ (Curate) on Jul 19, 2003 at 12:31 UTC
    You can take a look at my code in this thread which uses GnuPG::Interface. It has both decrypt and encrypt routines, but you can just pull out the decrypt routine and supply a password where I've left it blank.

    ~~
    naChoZ