You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Laurent MARTIN <la...@gide.net> on 2009/10/15 16:12:54 UTC

GnuPG module producing empty files

Hi!

I've recently upgraded one of my old website to mod_perl  
(ModPerl::PerlRun) and I'm not able to make GnuPG (0.10) work  
properly :/ As soon as I try to encrypt a plaintext file, I get an  
empty encrypted file. See below what I get in error log with the  
'trace' option set to true:
protocol error: expected SHM_GET_XXX got \n at /usr/lib/perl5/ 
site_perl/5.8.5/GnuPG.pm line 154

Any clue? Thanks in advance :)

-- 
Laurent MARTIN

Re: GnuPG module producing empty files

Posted by Michael Schout <ms...@gkg.net>.
Laurent MARTIN wrote:

> Has anyone on the list some experience with mod_perl and an alternative
> to GnuPG module (which is "simply" a wrapper around pgp binary).

I use GnuPG::Interface, and it works fine.

Regards,
Michael Schout

Re: GnuPG module producing empty files

Posted by Laurent MARTIN <la...@gide.net>.
Hi Cees,
Thank you for your help on this. Unfortunately, this doesn't fix my  
problem.
Has anyone on the list some experience with mod_perl and an  
alternative to GnuPG module (which is "simply" a wrapper around pgp  
binary). Crypt::GPG? Crypt::OpenPGP?
TIA.
Laurent.

On 19 oct. 2009, at 08:26, Cees Hek wrote:

> On Fri, Oct 16, 2009 at 1:12 AM, Laurent MARTIN <la...@gide.net>  
> wrote:
> Hi!
>
> I've recently upgraded one of my old website to mod_perl  
> (ModPerl::PerlRun) and I'm not able to make GnuPG (0.10) work  
> properly :/ As soon as I try to encrypt a plaintext file, I get an  
> empty encrypted file. See below what I get in error log with the  
> 'trace' option set to true:
> protocol error: expected SHM_GET_XXX got \n at /usr/lib/perl5/ 
> site_perl/5.8.5/GnuPG.pm line 154
>
> Any clue? Thanks in advance :)
>
> This might be because the GnuPG module executes the 'gpg' binary  
> directly to run it's commands and it plays with STDIN, STDOUT and  
> STDERR to do that.
>
> I had a similar issue using GnuPG::Interface under mod_perl, but was  
> able to solve it by untieing and saving STDIN and STDOUT when making  
> calls to GnuPG::Interface (the example below calls Mail::GPG which  
> in turn uses GnuPG::Interface to do the grunt work):
>
> use constant MP => ( exists $ENV{MOD_PERL} );
> use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and $ENV 
> {MOD_PERL_API_VERSION} >= 2 );
>
>     # mod_perl ties STDIN and STDOUT which conflicts with  
> GnuPG::Interface
>     my ( $stdin, $stdout );
>     if ( MP and not MP2 ) {
>         $stdin  = tied *STDIN;
>         $stdout = tied *STDOUT;
>         untie *STDIN;
>         untie *STDOUT;
>     }
>     my $mg = Mail::GPG->new( gnupg_hash_init => \%GNUPG_OPTIONS );
>     my $key_id = eval { $mg->query_keyring( search => $name ); };
>     if ( MP and not MP2 ) {
>         tie *STDIN,  ref $stdin,  $stdin;
>         tie *STDOUT, ref $stdout, $stdout;
>     }
>     die "query_keyring failed:  $@" if $@;
>
>
> Note though that I only noticed the issues with mod_perl1 and not  
> with mod_perl2 so it may be something different that you are  
> seeing.  Here's hoping it gives you some hints on where to look  
> next...
>
> Cheers,
>
> Cees



Re: GnuPG module producing empty files

Posted by Cees Hek <ce...@gmail.com>.
On Fri, Oct 16, 2009 at 1:12 AM, Laurent MARTIN <la...@gide.net> wrote:

> Hi!
> I've recently upgraded one of my old website to mod_perl (ModPerl::PerlRun)
> and I'm not able to make GnuPG (0.10) work properly :/ As soon as I try to
> encrypt a plaintext file, I get an empty encrypted file. See below what I
> get in error log with the 'trace' option set to true:
> protocol error: expected SHM_GET_XXX got \n at
> /usr/lib/perl5/site_perl/5.8.5/GnuPG.pm line 154
>
> Any clue? Thanks in advance :)
>

This might be because the GnuPG module executes the 'gpg' binary directly to
run it's commands and it plays with STDIN, STDOUT and STDERR to do that.

I had a similar issue using GnuPG::Interface under mod_perl, but was able to
solve it by untieing and saving STDIN and STDOUT when making calls to
GnuPG::Interface (the example below calls Mail::GPG which in turn uses
GnuPG::Interface to do the grunt work):

use constant MP => ( exists $ENV{MOD_PERL} );
use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and
$ENV{MOD_PERL_API_VERSION} >= 2 );

    # mod_perl ties STDIN and STDOUT which conflicts with GnuPG::Interface
    my ( $stdin, $stdout );
    if ( MP and not MP2 ) {
        $stdin  = tied *STDIN;
        $stdout = tied *STDOUT;
        untie *STDIN;
        untie *STDOUT;
    }
    my $mg = Mail::GPG->new( gnupg_hash_init => \%GNUPG_OPTIONS );
    my $key_id = eval { $mg->query_keyring( search => $name ); };
    if ( MP and not MP2 ) {
        tie *STDIN,  ref $stdin,  $stdin;
        tie *STDOUT, ref $stdout, $stdout;
    }
    die "query_keyring failed:  $@" if $@;


Note though that I only noticed the issues with mod_perl1 and not with
mod_perl2 so it may be something different that you are seeing.  Here's
hoping it gives you some hints on where to look next...

Cheers,

Cees

Re: GnuPG module producing empty files

Posted by NWB <ni...@ntlworld.com>.
I had this problem recently and found it was due to mod_perl running as user
"apache" which does not have a home directory in the same way that the
script running under cgi-bin did. Use of homedir in the
$gnupg->options->hash_init line sorted this out though. I guess an
environment variable GNUPGHOME may be a better way to go when I've finished
with this.


Laurent MARTIN wrote:
> 
> Hi!
> 
> I've recently upgraded one of my old website to mod_perl  
> (ModPerl::PerlRun) and I'm not able to make GnuPG (0.10) work  
> properly :/ As soon as I try to encrypt a plaintext file, I get an  
> empty encrypted file. See below what I get in error log with the  
> 'trace' option set to true:
> protocol error: expected SHM_GET_XXX got \n at /usr/lib/perl5/ 
> site_perl/5.8.5/GnuPG.pm line 154
> 
> Any clue? Thanks in advance :)
> 
> -- 
> Laurent MARTIN
> 

-- 
View this message in context: http://old.nabble.com/GnuPG-module-producing-empty-files-tp25909395p34789227.html
Sent from the mod_perl - General mailing list archive at Nabble.com.