php - gnupg 与 php 抛出 "could not init keylist"

标签 php linux gnupg

尝试使用 gnupg 加密邮件,方法调用 gnupg::keyinfo() 抛出错误 could not init keylist

这是我初始化扩展的方式:

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

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

gnupg 确实存在的地方(调用 is_dir('./gnupg') 返回 true - 我也尝试过绝对路径但没有成功)。

一些附加信息:

  • 完全相同的代码确实可以使用 PHP-CLI。 (但是,我需要它使用 HTTP)
  • 我正在使用 ubuntu 网络服务器:Linux name 3.2.0-23-generic#36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 GNU/Linux
  • gnupg 版本:gpg --version -> gpg (GnuPG) 1.4.10
  • 基础设施:客户端 -> nginx -> apache -> php 5.3
  • 为了测试,我设置了文件权限(递归):drwxrwxrwx 4 www-data web1 4096 29. Nov 12:30 .

调试日志显示以下错误:

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

完整的调试日志上传到这里:http://nopaste.penguinfriends.org/view/84317/

提前致谢!

最佳答案

当您从命令行运行时,您指定的 GNUPGHOME 路径是相对于您运行脚本时所在的工作目录的。在 Web 环境中,您不能依赖特定的工作目录,因此您可能需要指定 gnupg 目录的完整绝对路径。但是,您可以指定相对于当前脚本的路径:

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

此外,您永远不应该使用 777 权限,尤其是与安全相关的程序,例如 sshgnupg 可能会检查并拒绝, 但 775 可能有效。

关于php - gnupg 与 php 抛出 "could not init keylist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20285379/

相关文章:

PHP PDO - MySQL 查询创建或更新(唯一索引)

linux - 在 KornShell 中检查大小大于零的多个文件

encryption - 是否可以在 gpg 中加密原始输入?

maven - 在 Maven Artifact 上查看 PGP 签名

php - Laravel 4 - 渲染递归@include

php - 使用外键将项目插入数据库

php - 字段 'user_id' 没有默认值

linux - 打开多个网页,使用 wget 并合并输出

linux - socat 两个串口在一起