From 69dec7cd121cf05e057b762d05c94372cafc8ec7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 6 Apr 2009 14:45:55 -0600 Subject: [PATCH] More config options for PGP's getPublicKey() Allows us to skip cache checks, which would prevent importation of user keys. --- imp/lib/Crypt/Pgp.php | 29 ++++++++++++++++++++--------- imp/pgp.php | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/imp/lib/Crypt/Pgp.php b/imp/lib/Crypt/Pgp.php index caa81ff41..89f89de49 100644 --- a/imp/lib/Crypt/Pgp.php +++ b/imp/lib/Crypt/Pgp.php @@ -126,7 +126,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * address book and remove the id from the key_info for a correct * output. */ try { - $result = $this->getPublicKey($sig['email'], null, false); + $result = $this->getPublicKey($sig['email'], array('nocache' => true, 'noserver' => true)); if (!empty($result)) { unset($key_info['signature'][$id]); continue; @@ -151,19 +151,30 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * Second, if unsuccessful, the key is attempted to be retrieved via a * public PGP keyserver. * - * @param string $address The e-mail address to search by. - * @param string $fingerprint The fingerprint of the user's key. - * @param boolean $server Whether to check the public key servers for - * the key. + * @param string $address The e-mail address to search by. + * @param array $options Additional options: + *
+     * 'fingerprint' - (string) The fingerprint of the user's key.
+     *                 DEFAULT: fingerprint not used
+     * 'nocache' - (boolean) Don't retrieve from cache?
+     *             DEFAULT: false
+     * 'noserver' - (boolean) Whether to check the public key servers for the
+     *              key.
+     *              DEFAULT: false
+     * 
* * @return string The PGP public key requested. * @throws Horde_Exception */ - public function getPublicKey($address, $fingerprint = null, $server = true) + public function getPublicKey($address, $options = array()) { + $fingerprint = empty($options['fingerprint']) + ? '' + : $options['fingerprint']; + /* If there is a cache driver configured, try to get the public key * from the cache. */ - if (($cache = IMP::getCache())) { + if (empty($options['nocache']) && ($cache = IMP::getCache())) { $result = $cache->get("PGPpublicKey_" . $address . $fingerprint, 3600); if ($result) { Horde::logMessage('PGPpublicKey: ' . serialize($result), __FILE__, __LINE__, PEAR_LOG_DEBUG); @@ -188,7 +199,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp } /* Try retrieving via a PGP public keyserver. */ - if ($server && is_a($result, 'PEAR_Error')) { + if (empty($options['noserver']) && is_a($result, 'PEAR_Error')) { try { $result = $this->getFromPublicKeyserver($fingerprint, $address); @@ -338,7 +349,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp $fingerprint = $this->getSignersKeyID($text); } - $public_key = $this->getPublicKey($address, $fingerprint); + $public_key = $this->getPublicKey($address, array('fingerprint' => $fingerprint)); if (empty($signature)) { $options = array('type' => 'signature'); diff --git a/imp/pgp.php b/imp/pgp.php index 8054c2b57..bb4ee3b4a 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -131,7 +131,7 @@ case 'process_import_public_key': } else { /* Add the public key to the storage system. */ try { - $imp_pgp->addPublicKey($publicKey); + $key_info = $imp_pgp->addPublicKey($publicKey); foreach ($key_info['signature'] as $sig) { $notification->push(sprintf(_("PGP Public Key for \"%s (%s)\" was successfully added."), $sig['name'], $sig['email']), 'horde.success'); } @@ -217,7 +217,7 @@ case 'process_import_personal_private_key': case 'view_public_key': case 'info_public_key': try { - $key = $imp_pgp->getPublicKey(Util::getFormData('email'), null, false); + $key = $imp_pgp->getPublicKey(Util::getFormData('email'), array('noserver' => true)); } catch (Horde_Exception $e) { $key = $e->getMessage(); } -- 2.11.0