Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnupg with php throws "could not init keylist"

Tags:

linux

php

gnupg

Trying to encrypt mails with gnupg, the method call gnupg::keyinfo() throws the error could not init keylist.

This is how I initialize the extension:

putenv('GPGME_DEBUG=9:./gnupg/debug.log');
putenv('GNUPGHOME=./gnupg/');

$this->gpg = new gnupg();
$this->gpg->seterrormode(gnupg::ERROR_EXCEPTION);

Where gnupg really does exist (calling is_dir('./gnupg') returns true - I've also tried the absolute path without success).

Some additional information:

  • the exactly same code DOES work using PHP-CLI. (However, I need it using HTTP)
  • I'm using an ubuntu webserver: Linux name 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 GNU/Linux
  • gnupg version: gpg --version -> gpg (GnuPG) 1.4.10
  • infrastructure: client -> nginx -> apache -> php 5.3
  • for testing, I've set the file permissions (recursively): drwxrwxrwx 4 www-data web1 4096 29. Nov 12:30 .

The debug.log shows the following error:

_gpgme_io_set_close_notify (fd=0x282): enter: close_handler=0x7f6d2a409780/0x7f6d38edb730
_gpgme_io_set_close_notify (fd=0x282): error: Invalid argument

The full debug log is uploded here: http://nopaste.penguinfriends.org/view/84317/

Thanks in advance!

like image 405
Daniel M Avatar asked Nov 02 '22 09:11

Daniel M


1 Answers

When you run from the command line, the GNUPGHOME path you specified is relative to your working directory where you are when you run the script. From a web environment you can't rely on a particular working directory so you may need to specify the full absolute path to your gnupg directory. You could, however, specify the path relative to the current script:

putenv('GNUPGHOME='.dirname(__FILE__).'/gnupg');

Also, you shouldn't ever use 777 permissions, especially with programs related to security like ssh and gnupg that may check and refuse, but 775 might have worked.

like image 112
Joshua Jackson Avatar answered Nov 15 '22 03:11

Joshua Jackson