GnuPG::Interface Hanging
am 06.04.2006 16:45:13 von newsgroup_mike
Hi, I've been working with GnuPG::Interface lately and all has been
working well so far. However, today I've been trying to decrypt a
message that is larger than the ones I've been using and I've
discovered that the script is now hanging trying to decrypt this
message.
I notice in the module documentation that there is a mention about
hanging with large messages however I'm not too sure how to fix it ?
I've been working on it for hours now and I'm just about ready to pull
my hair out. I was wondering if anyone has had any luck with decrypting
larger messages that could offer some advice or assistance.
Here is the code I am using:
my ($gnupg);
my $xmlDataIn = shift;
print "
$xmlDataIn
";
my $passphrase = '******';
$gnupg = GnuPG::Interface->new();
$gnupg->call('/usr/local/bin/gpg');
$gnupg->options->meta_interactive(0);
$gnupg->options->homedir('/home/mike/.gnupg');
$gnupg->options->extra_args('--no-secmem-warning');
my ($input,$output,$error,$passphrase_fh,$status_fh) =
(IO::Handle->new(),IO::Handle->new(),IO::Handle->new(),IO::H andle->new(),IO::Handle->new());
my $handles = GnuPG::Handles->new(stdin => $input,stdout =>
$output,stderr => $error,passphrase => $passphrase_fh,status =>
$status_fh);
foreach my $handle ($input,$output,$error,$passphrase_fh,$status_fh) {
$handle->autoflush(1);
}
my $pid = $gnupg->decrypt(handles => $handles);
print $passphrase_fh $passphrase;
close $passphrase_fh;
print $input $xmlDataIn;
close $input;
my $decryptedText = <$output>;
my @error = <$error>;
my @status_info = <$status_fh>;
close $output;
close $error;
close $status_fh;
waitpid $pid, 0;
print "$decryptedText
\n";
print "@error
\n";
print "@status_info
\n";
As I stated, this works perfectly on smaller messages but is choking on
larger ones. Here my environment details in case it helps:
OS: Red Hat Enterprise
Perl: Perl v5.8.4 built for i686-linux
GPG (GnuPG): 1.4.2.2
GnuPG::Interface: 0.33
Regards,
Mike Mackay.
Re: GnuPG::Interface Hanging
am 10.04.2006 18:05:23 von newsgroup_mike
Managed to solve the problem by using File::Temp and binding the Input
& Output directly to files:
$gnupg = GnuPG::Interface->new();
$gnupg->call('/usr/local/bin/gpg');
$gnupg->options->meta_interactive(0);
$gnupg->options->homedir('/home/mike/.gnupg');
$gnupg->options->extra_args('--no-secmem-warning');
my ($error,$passphrase_fh,$status_fh) =
(IO::Handle->new(),IO::Handle->new(),IO::Handle->new());
# use File::Temp for creating physical files that GnuPG can use
my $input = File::Temp::tempfile()|| die "Can't create input file: $!";
my $output = File::Temp::tempfile()|| die "Can't create output file:
$!";
my $handles = GnuPG::Handles->new(stdin => $input,stdout =>
$output,stderr => error,passphrase => $passphrase_fh,status =>
$status_fh);
# GnuPG Docs - use this method for direct file access and buffering
issues
$handles->options('stdin')->{direct} = 1;
$handles->options('stdout')->{direct} = 1;
my $pid = $gnupg->decrypt(handles => $handles);
print $passphrase_fh $passphrase;
close ($passphrase_fh);
# write to the tempfile/input
print $input $xmlDataIn;
# seek back to read the data (Only way I could get it to read the
input?)
seek($input, 0, 0);
close ($input);
my @error = <$error>;
my @status_info = <$status_fh>;
close ($error);
close ($status_fh);
waitpid $pid, 0;
# seek to the beginning of my output to collect decrypted data
seek($output, 0, 0);
print "$_" while <$output>;
close($output);
#print "Error: @error
\n";
#print "Status: @status_info
\n";
Just thought I'd post my solution in case it helps anyone else with the
same issue(s).
- Mike
newsgroup_mike@ultrafusion.co.uk wrote:
> Hi, I've been working with GnuPG::Interface lately and all has been
> working well so far. However, today I've been trying to decrypt a
> message that is larger than the ones I've been using and I've
> discovered that the script is now hanging trying to decrypt this
> message.
>
> I notice in the module documentation that there is a mention about
> hanging with large messages however I'm not too sure how to fix it ?
> I've been working on it for hours now and I'm just about ready to pull
> my hair out. I was wondering if anyone has had any luck with decrypting
> larger messages that could offer some advice or assistance.
>
> Here is the code I am using:
>
> my ($gnupg);
> my $xmlDataIn = shift;
> print "
$xmlDataIn
";
> my $passphrase = '******';
> $gnupg = GnuPG::Interface->new();
> $gnupg->call('/usr/local/bin/gpg');
> $gnupg->options->meta_interactive(0);
> $gnupg->options->homedir('/home/mike/.gnupg');
> $gnupg->options->extra_args('--no-secmem-warning');
> my ($input,$output,$error,$passphrase_fh,$status_fh) =
> (IO::Handle->new(),IO::Handle->new(),IO::Handle->new(),IO::H andle->new(),IO::Handle->new());
> my $handles = GnuPG::Handles->new(stdin => $input,stdout =>
> $output,stderr => $error,passphrase => $passphrase_fh,status =>
> $status_fh);
>
> foreach my $handle ($input,$output,$error,$passphrase_fh,$status_fh) {
> $handle->autoflush(1);
> }
>
> my $pid = $gnupg->decrypt(handles => $handles);
> print $passphrase_fh $passphrase;
> close $passphrase_fh;
> print $input $xmlDataIn;
> close $input;
> my $decryptedText = <$output>;
> my @error = <$error>;
> my @status_info = <$status_fh>;
> close $output;
> close $error;
> close $status_fh;
> waitpid $pid, 0;
> print "$decryptedText
\n";
> print "@error
\n";
> print "@status_info
\n";
>
> As I stated, this works perfectly on smaller messages but is choking on
> larger ones. Here my environment details in case it helps:
>
> OS: Red Hat Enterprise
> Perl: Perl v5.8.4 built for i686-linux
> GPG (GnuPG): 1.4.2.2
> GnuPG::Interface: 0.33
>
> Regards,
> Mike Mackay.