please forgive lack of tags - not sure how as yet.

I have a linux mint lisa desktop with an apache2 server installed, php 5.3.6 and the Gnupg wrapper installed (GPGME version 1.2.0, Extension Version 1.3.2-dev)

I have an php script which will decrypt a passed file name automatically. With the script these are the pertinent lines of code.

$GnuPG = new gnupg();
$GnuPG -> adddecryptkey("fingerprint","passphrase");
$text = file_get_contents($path1.$file);
$plain = $GnuPG -> decrypt($text);

This works without an issue, the encrypted file is grabbed and its contents decrypted, the rest of the script doing what it needs to do.

Now I have since created an ubuntu 12.04 server version of the above, with apache2, php 5.3.10 and the same versions of GNUGP wrapper installed. The same process was used for installing the wrapper on both machines, the pertinent code is the same but I get nothing.

In an attempt to debug, I have written about the $path1.$file and $text variables to a log file and they are as I would expect. I have tried to write out the $plain information as well but nothing is returned.

Does anyone have any ideas either about the problem itself or where I may find more information to debug it?

I know its not the fingerprint of gpg itself because if I drop to cli and manually decrypt there isnt an issue. I have managed to get some more information through trial and error

PHP Warning: gnupg::adddecryptkey(): get_key failed in /var/www/decrypt.php

which appears quite obvious but I have no idea how to resolve it. As I say this works fine on the desktop server, rather than server server.

Any help gratefully received

thanks!!

    thanks for the reply.
    user running the webserver is www-data, so i already made that the owner of the secring file but that doesnt appear to be making a difference.
    Tony

      oh and that is the same as my desktop server; webserver running as www-data, secring owned by www-data. Essentially I tried to make the 2 server and spot the differences;

      OS
      PHP version

      as far as I can tell.

        in /home/monkey/var/www/,gnupg, I moved from the default location out from under the /var/www location so it was easier to upload/move files. I have made www-data a member of the group "monkey".

        althougth I may have got the chmod wrong, what would the correct numbers be?

          certainly can

          on the problem ubuntu server

          ls -l /home/monkey/.gnupg/secring.gpg
          -rw-rw---- 1 www-data www-data 1434 May 18 00:45 /home/monkey/.gnupg/secring.gpg

          on the working linux mint desktop
          ls -la secring.gpg
          -rw------- 1 www-data www-data 1434 2012-05-11 18:07 secring.gpg

            ls -ld /home/monkey
            drwxr-xr-x 7 monkey monkey 4096 May 21 22:19 /home/monkey
            ls -ld /home/monkey/.gnupg
            drwx------ 2 monkey monkey 4096 May 22 18:42 /home/monkey/.gnupg

            www-data is a member of the group monkey

              blimey, sometimes I spend too long looking at these things.

              just found this series of info, gave it a whirl and low and behold that has got it sorted!!

              basically I made www-data the owner of the .gnupg folder.

              Many thanks for your help

                3 years later

                Hi,
                I have the same problem:
                My server Os : gentoo
                php version: 5.4.36
                GPGME version 1.3.2

                I'm using the following code:
                putenv("GNUPGHOME=/var/www/traveltec.pro/.gnupg");
                $pubkey = "-----BEGIN PGP PUBLIC KEY BLOCK-----
                Version: BCPG C# v1.6.1.0

                content public key********
                -----END PGP PUBLIC KEY BLOCK-----";

                $encrypted_content = (null);
                $res = gnupg_init();
                gnupg_seterrormode($res, gnupg::ERROR_EXCEPTION);
                $rtv = gnupg_import($res, $pubkey);
                $rtv = gnupg_addencryptkey($res, "Finger print");
                $encrypted_content = gnupg_encrypt($res, $content);
                echo "Encrypted Data: " . $encrypted_content . "<br/>";

                ==> this code return the following error:
                Fatal error: Uncaught exception 'Exception' with message 'get_key failed' in /var/www/traveltec.pro/dev/encrypt2.php:25 Stack trace: #0 /var/www/traveltec.pro/dev/encrypt2.php(25): gnupg_addencryptkey(Resource id #2, '4C6DCA2A9821339...') #1 {main} thrown in /var/www/traveltec.pro/dev/encrypt2.php on line 25

                Any idea??

                  Write a Reply...