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

Hello all,

I'm using the Perl module Crypt::GPG and I'm unable to decrypt a file (using the Mageia 8 distribution).

Encryption works well.

So up to now, I was using the system command (system("gpg --decrypt ...) but it seems that now there is a 2mn timeout which makes me unable to use this command on big encrypted files.

As I could not succeed to replace the "system" command with "use IPC::Run qw(run timeout) ; run ...", I'm trying again with the Crypt::GPG module.

Here is my code :

#!/usr/bin/perl use strict ; # Does not exist anymore in Mageia. # use GnuPG qw( :algo ) ; use Crypt::GPG ; my $gpg = new Crypt::GPG ; $gpg->gpgbin('/bin/gpg') ; $gpg->secretkey('my_email_address') ; $gpg->passphrase('my_gpg_passphrase') ; my $encryptedFile = 'myfile.tar.gz.gpg' ; my $tarFile = 'myfile.tar.gz' ; my @encryptedFileArray = () ; open(GPG_FILE, "$encryptedFile") || die "can't open file $encryptedFil +e !" ; @encryptedFileArray = <GPG_FILE> ; close(GPG_FILE) ; my ($plaintext, $signature) = $gpg->verify("\@encryptedFileArray"); # print("$plaintext\n"); open(TAR_FILE, ">$tarFile") || die "can't open file $tarFile !" ; print(TAR_FILE $plaintext) ; close(TAR_FILE) ; exit ;

Do you know what I'm doing wrong ?

Thank you for your wisdom.

Regards.

Xuo.

Replies are listed 'Best First'.
Re: Unable to get any decrypted output from $gpg->verify
by tobyink (Canon) on Aug 14, 2023 at 14:01 UTC

    The Crypt::GPG documentation suggests it only supports ASCII-armoured GPG, which usually has a ".asc" filename, not ".gpg".

    Also I found a bug in Crypt::GPG. In the verify method, the regular expression /SIG_ID/g should be changed to /(SIG_ID|END_DECRYPTION)/g.

    If you switch to ASCII-armoured files, patch the bug, and remove those quote marks I pointed out in the previous comment, I believe your code should start working.

    That said, system seems the easier option.

      Hi,

      Thank you for the explanations.

      I can try to create an ASCII-armoured file, but I don't see how to patch the code. Is it enough to find the file containing the regular expression /SIG_ID/g and to change it to /(SIG_ID|END_DECRYPTION)/g ?

      Regards.

      Xuo.
Re: Unable to get any decrypted output from $gpg->verify
by tobyink (Canon) on Aug 14, 2023 at 09:48 UTC
      Hello,

      I had already tested this syntax and it works the same way.

      Regards.

      Xuo.
Re: Unable to get any decrypted output from $gpg->verify
by karlgoethebier (Abbot) on Aug 14, 2023 at 18:29 UTC
    «I could not succeed to replace the "system" command with "use IPC::Run…»

    What does your command line look like?

    «The Crux of the Biscuit is the Apostrophe»

      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.

        Please post the code you really use.

        «The Crux of the Biscuit is the Apostrophe»