php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58272 gnupg_decrypt() fails when data encrypted to multiple keys
Submitted: 2008-07-14 11:32 UTC Modified: 2008-08-08 11:44 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kmdm2 at kennynet dot co dot uk Assigned:
Status: Open Package: gnupg (PECL)
PHP Version: 5.2.4 OS: Ubuntu 8.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kmdm2 at kennynet dot co dot uk
New email:
PHP Version: OS:

 

 [2008-07-14 11:32 UTC] kmdm2 at kennynet dot co dot uk
Description:
------------
The reproduce code will show this better but essentially when I encrypt some data to 2 keys (2 calls to addenencryptkey) only the first key will be able to decrypt the data using the gnupg extension.

Reproduce code:
---------------
PHP style shell script available at:-

http://home.kennynet.co.uk/~kenny/gnupg.php.txt

Expected result:
----------------
The expected result would be successful decryption using the gnupg extension...

$ ./gnupg.php 
KEY 1: (php-gpg)...string(4) "TEST"
KEY 2: (php-gpg)...string(4) "TEST"
KEY 2: (using gpg-shell)...string(4) "TEST"

Actual result:
--------------
The actual result shows that the 2nd key fails to decrypt the data using the gnupg extension (yet it works fine using the gpg binary):-
 
$ ./gnupg.php 
KEY 1: (php-gpg)...string(4) "TEST"
KEY 2: (php-gpg)...bool(false)
KEY 2: (using gpg-shell)...string(4) "TEST"

Patches

gnupg_fix_14345.patch (last revision 2013-02-06 08:04 UTC) by kenny at kennynet dot co dot uk)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-15 03:42 UTC] kmdm2 at kennynet dot co dot uk
I've now done the sensible thing of setting the errormode to warning, the actual output of the script is now thus:-

$ ./gpgbug.php 
KEY 1: (php-gpg)...string(4) "TEST"

Warning: gnupg::decrypt(): no passphrase set in /tmp/gpgbug.php on line 38

Warning: gnupg::decrypt(): decrypt failed in /tmp/gpgbug.php on line 38
KEY 2: (php-gpg)...bool(false)
KEY 2: (using gpg-shell)...string(4) "TEST"

This now looks similar to a previous bug awaiting feedback:-
http://pecl.php.net/bugs/bug.php?id=9103

HTH
 [2008-07-15 04:48 UTC] kmdm2 at kennynet dot co dot uk
Ok, last comment from me since I'm reaching the end of my limited C ability. ;-)

It looks like the uid_hint coming into the passphrase_decrypt_cb function is that of the first key used to encrypt the data, thus when the uid is used to search for a passphrase it's not looking for the uid of the 2nd key, only the first...
 [2008-08-08 11:44 UTC] kmdm2 at kennynet dot co dot uk
I reproduced a simple testcase for this in C and ran it by the GPGME maintainer.

The problem is caused because if we don't find the uid_int in the passphrase_decrypt_cb function we return 1. This tells GPGME to abort attempting to decrypt the data so it will never ask for the passphrase for other uid's that the data has been encrypted to.

Correct behavior is to write \n to the fd and return 0 to continue processing.

The following patch fixes this:-
http://home.kennynet.co.uk/~kenny/gnupg_fix_14345.patch
 [2013-02-06 07:55 UTC] peterp at pocos dot nl
This bug hasn't been fixed in 1.3.2. Could you please post your patch?
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC