php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57711 gnupg_encrypt gives no output.
Submitted: 2007-06-19 19:40 UTC Modified: 2015-02-11 18:46 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: alex at schestag dot info Assigned:
Status: Wont fix Package: gnupg (PECL)
PHP Version: 5.2.1 OS: Debian GNU/Linux Lenny/testing
Private report: No CVE-ID: None
 [2007-06-19 19:40 UTC] alex at schestag dot info
Description:
------------
Hi,

I have a problem with the PECL gnupg extension 1.3.1 that might be a bug. When I try to encrypt or sign a string with gnupg_encrypt or gnupg_sign and try to produce an output of the signed or encrypted string, the output is empty. I tested it with the code given below and with some of my own code. This code is the original code that can be found in the manual. I get this behaviour with PHP 4.4.7, 5.2.3 and 6.0.0dev on Apache 2.2.3 on Debian Lenny (so, please ignore the version selection above as my PHP versions are not listed there).  PHP 4.4.7 is compiled as a module, 5.2.3 and 6.0.0dev are CGIs. The Apache errorlog and the accesslog don't shown any error. The script doesn't crash like in Bug #10840;. When I add an additional line like echo 'hello';, hello is given as output. gnupg is installed and works fine, the extension is shown in phpinfo(); for all versions mentioned above. The environment GNUPGHOME is set properly.

Kind regards,

Alexander Schestag

Reproduce code:
---------------
Encryption:
<?php
$res = gnupg_init();
gnupg_addencryptkey($res,"8660281B6051D071D94B5B230549F9DC851566DC");
$enc = gnupg_encrypt($res, "just a test");
echo $enc;
?>

Signing:
<?php
$res = gnupg_init();
gnupg_addsignkey($res,"8660281B6051D071D94B5B230549F9DC851566DC","test");
$signed = gnupg_sign($res, "just a test");
echo $signed;
?>

Expected result:
----------------
I expect echo $enc; to give me the encrypted/signed string as output.

Actual result:
--------------
echo $enc; gives just an empty string as output.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-20 03:46 UTC] traufeisen@php.net
What is your gnupg-version?
Does it work, if you use the extension in OO-Style instead of procedural?
 [2007-06-20 05:39 UTC] alex at schestag dot info
The gnupg version is 1.4.6. The problem also appears using the OO style example in the manual. The behaviour is the same.
 [2007-06-20 07:54 UTC] traufeisen@php.net
Please switch the errormode to at least GNUPG_ERROR_WARNING with
gnupg_seterrormode($res,GNUPG_ERROR_WARNING);
and set error_reporting to E_ALL
Ensure that display_errors is active.
You should get some kind of an errormessage.
 [2007-06-20 09:53 UTC] alex at schestag dot info
The result of this is:

Warning: gnupg_addencryptkey() [function.gnupg-addencryptkey]: get_key failed in...

Warning: gnupg_encrypt() [function.gnupg-encrypt]: no key for encryption set in...

Yes, this looks as if I made a mistake, but:

- I additionally set GNUPGHOME to the propper directory
- The directory has the propper rights (rwxrw-rw-)
- The pubring.pgp has the propper rights (rw-r--r--)
- The key is in my pubring.gpg
 [2007-06-20 09:56 UTC] alex at schestag dot info
Sorry, the rights of the directory are rwx-r-xr-x
 [2007-06-26 14:08 UTC] traufeisen@php.net
addencryptkey fails. Are you sure, you?re specifying the correct public key?
 [2007-06-27 08:18 UTC] alex at schestag dot info
Hi,

yes I am sure and I have tested this once again a few minutes ago with the original key and the fingerprint of this key. Using the fingerprin also fails.
 [2007-07-05 15:14 UTC] traufeisen@php.net
In this case I need something reproduceable.
 [2007-08-21 13:02 UTC] nsazulus at yahoo dot com
I'm seeing this exact same issue as well with Debian and PHP 5.2.0 on Apache 2.2.3.  Permissions have been set correctly on the .gnupg directory.  The same thing happens without running the putenv function.

Reproduce code:
---------------------
<?php
putenv("GNUPGHOME=/home/apacheuser/.gnupg/");
$res = gnupg_init();
gnupg_seterrormode($res,GNUPG_ERROR_WARNING);
gnupg_addencryptkey($res,"8660281B6051D071D94B5B230549F9DC851566DC");
$enc = gnupg_encrypt($res, "just a test");
echo "'$enc'";
?>


Expected result:
---------------------
'encrypted result'


Actual result:
---------------------
Warning: gnupg_addencryptkey() [function.gnupg-addencryptkey]: get_key failed in /var/www/site/public_html/index.php on line 5

Warning: gnupg_encrypt() [function.gnupg-encrypt]: no key for encryption set in /var/www/site/public_html/index.php on line 6
''
 [2007-08-21 16:28 UTC] nsazulus at yahoo dot com
We fixed it by regenerating the gnupg fingerprint, the test code on php.net was using the some other encrypt key that our fingerprint didn't match and we didn't think to change it until now.
 [2008-04-15 21:36 UTC] alex at schestag dot info
Hi

The problem is solved. It was a very strange problem with the rights of the .gnup directory. Sorry for the inconvenience.

Alex
 [2009-02-02 03:24 UTC] bugreporter at udmvt dot ru
I have the same problem, but only in mod_php.
Running that in cli mode (under the same account as apache) returns no error, just encrypts OK.

What can be the difference between mod_php and cli from the point of view of gnupg extension?
 [2009-10-29 17:17 UTC] troy at totus dot us
I?m having a problem getting keys as well:

[root@mirage enrollment]# php encrypt.php
PHP Warning: gnupg_addencryptkey(): get_key failed in /var/www/vhosts/madeupdomain.com/httpdocs/enrollment/encrypt.php on line 10
PHP Warning: gnupg_encrypt(): no key for encryption set in /var/www/vhosts/madeupdomain.com/httpdocs/enrollment/encrypt.php on line 13
GNUPGHOME set to: /var/www/.gnupg

[root@mirage enrollment]# gpg ?homedir /var/www/.gnupg ?fingerprint
gpg: WARNING: unsafe ownership on homedir `/var/www/.gnupg?
/var/www/.gnupg/pubring.gpg
?????????
pub 1024D/24F0C25E 2009-10-29
Key fingerprint = 61EC B598 C01B 3DD4 2543 FB1A 1A16 8972 24F0 C25E
uid dummy
sub 2048g/3F9A5055 2009-10-29

[root@mirage enrollment]# cat encrypt.php
seterrormode(gnupg::ERROR_EXCEPTION); // throw an exception in case of an error

// set the environment so gnupg can find the keyring
putenv(?GNUPGHOME=/var/www/.gnupg?);

$res = gnupg_init();
gnupg_seterrormode($res,GNUPG_ERROR_WARNING); // raise a PHP-Warning in case of an error
gnupg_addencryptkey($res,?61ECB598C01B3DD42543FB1A1A16897224F0C25E?);
#gnupg_addencryptkey($res,?61EC B598 C01B 3DD4 2543 FB1A 1A16 8972 24F0 C25E?);
#gnupg_addencryptkey($res,?5C798B98314176C041DD66324A83C80EF1817BFB?);
$enc = gnupg_encrypt($res, ?just a test?);
echo $enc;
echo getenv(?GNUPGHOME?). ?\n?;
?>

[root@mirage enrollment]# ls -al /var/www/.gnupg
total 32
drwxrwxrwx 2 apache apache 4096 Oct 29 11:39 .
drwxr-xr-x 11 root root 4096 Oct 28 20:42 ..
-rwxrwxrwx 1 apache apache 1155 Oct 28 20:47 pubring.gpg
-rwxrwxrwx 1 apache apache 1155 Oct 28 20:47 pubring.gpg~
-rwxrwxrwx 1 apache apache 600 Oct 28 20:47 random_seed
-rwxrwxrwx 1 apache apache 1304 Oct 28 20:47 secring.gpg
-rwxrwxrwx 1 apache apache 1280 Oct 28 20:47 trustdb.gpg
[root@mirage enrollment]# php -m | grep gnugp
[root@mirage enrollment]# php -m

[root@mirage enrollment]# php -m | grep gnupg
gnupg

CLI works fine and I've triple checked my fingerprints
 [2015-02-11 18:46 UTC] jimjag@php.net
-Status: Open +Status: Wont fix
 [2015-02-11 18:46 UTC] jimjag@php.net
OLD
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC