in reply to Re: Unable to get any decrypted output from $gpg->verify
in thread Unable to get any decrypted output from $gpg->verify

Hello,


I didn't keep the "real" line of code but it was more or less similar to :

$gpgCmd = "gpg --pinentry-mode=loopback --quiet --batch --passphrase-file $passphraseFile --decrypt $gpgFile_shell > $gpgTmpDir/$gpgFileBaseName_shell" ;

run "$gpgCmd" timeout(600) ;

This command was working (as far as I remember) but the reason I've tried using the "run" command instead of the 'system' one is because I was getting such an error :

IPC::Run: timeout on timer #1 at /usr/share/perl5/vendor_perl/IPC/Run.pm line 2951.

and the run command didn't prevent this error to occur and I thought it was coming from the "system" command.

But after I've bypassed this command (creating the gpg file manually to prevent the script to do it), I've noticed that I could have this error during the extraction of a tar file using the :

$tar->read("$gpgTmpDir/$gpgFileBaseName_shell") ;

$tar->extract() ;

$tar->clear ;
commands.
So, the system command was not the reason of the error.

In both cases, the error appeared when "big" files were used (big gpg or big tar file to be extracted).

I need to simplify my script to try to reproduce the issue more easily before posting again :)

Regards.

Xuo.
  • Comment on Re^2: Unable to get any decrypted output from $gpg->verify

Replies are listed 'Best First'.
Re^3: Unable to get any decrypted output from $gpg->verify
by karlgoethebier (Abbot) on Aug 14, 2023 at 20:13 UTC

    Please post the code you really use.

    «The Crux of the Biscuit is the Apostrophe»


      Hi all,

      I'got an explanation about the IPC error.

      After I've rebooted my PC, the script is passing without any issue.

      If I run it on a newer/more powerfull/... PC, I can make it pass as well.

      Then means that after several trials of my script => several decryption, untar, tar and diff commands, the internal memory (lets call it that way) becomes full and some commands make the script to fail.

      About the decryption with "use Crypt::GPG", I still can't make it work. I can create an armour encrypted file as suggested by Tobyink but I can't decrypt it.

      Here is the code I'm using :
      #!/usr/bin/perl use strict ; use Crypt::GPG ; use Archive::Tar ; my $gpg = new Crypt::GPG ; $gpg->gpgbin('/bin/gpg') ; $gpg->secretkey('my_email_address') ; $gpg->passphrase('my_gpg_passphrase') ; $gpg->armor(1) ; my $encryptedFile = '/home/xuo/TheCat.gpg' ; my $tarFile_read = '/home/xuo/TheCat.tar.gz' ; my $tarFile_write = '/home/xuo/TheCat_from_gpg_encrypt.gpg' ; my @encryptedFileArray = () ; my @fileToBeEncrypted = () ; my @fileToBeDecrypted = () ; my @gpgEncryptedFile = () ; open(TAR_FILE, "$tarFile_read") || die "can't open file $tarFile_read +!" ; @fileToBeEncrypted = <TAR_FILE> ; close(TAR_FILE) ; my @gpgEncryptedFile = $gpg->encrypt(\@fileToBeEncrypted, 'my_email_ad +dress') ; open(GPG_FILE, ">$encryptedFile") || die "can't open file $encryptedFi +le !" ; print GPG_FILE "@gpgEncryptedFile" ; close(GPG_FILE) ; open(GPG_FILE, "$encryptedFile") || die "can't open file $encryptedFil +e !" ; @fileToBeDecrypted = <GPG_FILE> ; close(GPG_FILE) ; my ($plaintext, $signature) = $gpg->verify(\@fileToBeDecrypted) ; open(TAR_FILE, ">$tarFile_write") || die "can't open file $tarFile_wri +te !" ; print TAR_FILE "$plaintext" ; close(TAR_FILE) ; exit ;

      $ more TheCat.gpg

      -----BEGIN PGP MESSAGE-----

      Comment: Crypt::GPG v1.64



      hQEMA8z8x+FbnSQ6AQf9FXqGTJuwvp4uI51iZSmioyROTK0XkkHUHqnGhJYhJAdN

      zQliHEr1ubGHFtcmI7qg4dNpKTZcKD5XWoTNWMEK98CV9t/dzlXVrjlBIT8ztTlQ

      5dTJiU0E/SenMpnTTOERL5hm4qIW5+TWWF1zYsuBFIB/4TLX6GrABNTUlNWhsL95

      This is a pgp-armored file but the decrypted file is of size 0.

      Regards.

      Xuo.

        Here is an SSCCE showing an encryption/decryption round trip. Just set the three env vars accordingly and run.

        #!/usr/bin/env perl use strict; use warnings; use feature 'say'; use Crypt::GPG; my $gpg = Crypt::GPG->new; $gpg->gpgbin ('/usr/bin/gpg'); $gpg->secretkey ($ENV{SECRET_KEY}); $gpg->passphrase ($ENV{GPG_PP}); $gpg->armor (1); my $plaintext = 'PerlMonks Rocks!'; say "Plain text: $plaintext"; my @enctext = $gpg->encrypt ([$plaintext], $ENV{TO_EMAIL}); say "Encrypted text: @enctext"; my $decrypted = $gpg->verify (\@enctext); say "Decrypted text: $decrypted";

        🦛


      Hi,

      I need to try reproducing the IPC error after I've simplified my script. I will do that only during the next week-end.

      Regards.

      Xuo.