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

I'm trying to use linux GPG on a Perl script but i can't get it working via Apache/CGI.

Iv'e tried:

1 - simple command line with `` it gives a fatal error if no --homedir is specified and permission error if --homedir is specified (/home/<user>/.gnupg).

2 - Crypt::GPG , seemed like the perfect solution but it does not work and it seems there is no way to read errors to figure it out.

3 - GnuPg module does not work. I try to encrypt and i get "Can't call method "encrypt" on an undefined value", anyway according to the documentation import function does not return key id of the imported pub key, i do need the key id on importing.

  • Comment on CGI and GPG, how are you people doing it?

Replies are listed 'Best First'.
Re: CGI and GPG, how are you people doing it?
by Anonymous Monk on Apr 07, 2015 at 00:38 UTC
      I can make the command line method work with gpg homedir chmod 777, but how unsafe is that?

        Look into suExec or mod_itk or some other method of running your CGI as the user.

        I can make the command line method work with gpg homedir chmod 777, but how unsafe is that?

        What means unsafe?

        chmod 777 says

        rwxrwxrwx (symbolic)
        User: read, write and execute
        Group: read, write and execute
        Others: read, write and execute
        

        Is that unsafe? Are you the only user of this webserver?

        Maybe you want to set up https://httpd.apache.org/docs/2.2/suexec.html

Re: CGI and GPG, how are you people doing it?
by Anonymous Monk on Apr 07, 2015 at 00:05 UTC

    After you encounter an error, why not work to resolve it?

      I would not be asking i if i knew how to solve this, google was helpless.

        I would not be asking i if i knew how to solve this, google was helpless.

        so which one do you want to try to solve?

        Anyway, i just want to know how people are doing it via CGI. From terminal everything works.
Re: CGI and GPG, how are you people doing it?
by locked_user sundialsvc4 (Abbot) on Apr 07, 2015 at 11:37 UTC

    I think that you’re getting a bit of the run-around here, and it might be because you really haven’t told us anything about your errors other than that you’re having them.

    Remember that any CGI script runs in the context of the Apache server, generally as nobody, who of course has no access to anything, and might even be forbidden to execute external commands.   Regarding #1, “consider that.”

    If errors occur, they generally will be reported in the Apache error_log file for that server.   Anything that you print STDERR ... will also wind up there.   Regarding #2, “look there.”

    Start by running “the guts of your script,” as yourself, to see that in fact it works and to get the bugs out.   Figure out how Crypt::GPG works, appropriate to your circumstances, and get the bugs out of your code.   Only then, adapt the same thing to be used by nobody in a CGI context.

    (Or, this being the PerlMonks Code-Writing Service,™ post a fragment of your code.   Within fifteen minutes’ time, three other Monks will have [re-]written the entire program for you.)   ;-)