From 154adb11e8bc9a13e7ebc4c62adae6f953a55537 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 9 Oct 2009 15:15:04 +0200 Subject: [PATCH] Add hook to retrieve public S/MIME and PGP keys. --- imp/config/hooks.php.dist | 84 +++++++++++++++++++++++++++++++++++++++++++++++ imp/docs/CHANGES | 2 +- imp/lib/Crypt/Pgp.php | 8 +++++ imp/lib/Crypt/Smime.php | 8 +++++ 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index f34b69795..d5089f964 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -460,6 +460,90 @@ class IMP_Hooks // return array($quota[1] * 1024, $quota[2] * 1024); // } + /** + * Retrieves public S/MIME keys of message recipients. + * + * The hook will be called first when searching for the keys, and further + * lookup techniques will only be used if the hook throws an excpetion or + * returns an empty result. + * + * @param string $address The email address of the recipient. + * + * @return string The base64-encoded public S/MIME key that matches the + * email address. + */ +// public function smime_key($address) +// { +// $ldapServer = 'localhost'; +// $ldapPort = 389; +// $searchBase = 'ou=users,dc=example,dc=com'; +// $binddn = 'uid=admin,dc=example,dc=com'; +// $bindpw = 'secret'; +// $attribute = 'simepublickey'; +// +// if (!@ldap_connect($ldapServer, $ldapPort)) { +// return; +// } +// if (!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { +// return; +// } +// if (!@ldap_bind($ds, $binddn, $bindpw)) { +// return; +// } +// +// $searchResult = @ldap_search($ds, $searchBase, 'mail=' . $address); +// $information = @ldap_get_entries($ds, $searchResult); +// ldap_close($ds); +// +// if ($information === false || $information['count'] == 0) { +// return; +// } +// +// return $information[0][$attribute][0]; +// } + + /** + * Retrieves public PGP keys of message recipients. + * + * The hook will be called first when searching for the keys, and further + * lookup techniques will only be used if the hook throws an excpetion or + * returns an empty result. + * + * @param string $address The email address of the recipient. + * @param string $keyid The PGP key id of the recipient. + * + * @return string The base64-encoded public PGP key that matches either + * the email address or the fingerprint. + */ +// public function pgp_key($address, $keyid) +// { +// $ldapServer = 'localhost'; +// $ldapPort = 389; +// $searchBase = 'ou=users,dc=example,dc=com'; +// $binddn = 'uid=admin,dc=example,dc=com'; +// $bindpw = 'secret'; +// $attribute = 'pgppublickey'; +// +// if (!@ldap_connect($ldapServer, $ldapPort)) { +// return; +// } +// if (!@ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { +// return; +// } +// if (!@ldap_bind($ds, $binddn, $bindpw)) { +// return; +// } +// +// $searchResult = @ldap_search($ds, $searchBase, 'mail=' . $address); +// $information = @ldap_get_entries($ds, $searchResult); +// ldap_close($ds); +// +// if ($information === false || $information['count'] == 0) { +// return; +// } +// +// return $information[0][$attribute][0]; +// } /** * DIMP: Allow additional information to be added to the array that is diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 81d61a6d8..d8c1aaca1 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -104,7 +104,7 @@ v5.0-git v4.3.6-cvs ---------- - +[jan] Add hook to retrieve public S/MIME and PGP keys. ------ diff --git a/imp/lib/Crypt/Pgp.php b/imp/lib/Crypt/Pgp.php index ecba1fead..d77c76da4 100644 --- a/imp/lib/Crypt/Pgp.php +++ b/imp/lib/Crypt/Pgp.php @@ -179,6 +179,14 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp } } + try { + $key = Horde::callHook('pgp_key', array($address, $keyid), 'imp'); + if ($key) { + return $key; + } + } catch (Horde_Exception_HookNotSet $e) { + } + /* Try retrieving by e-mail only first. */ $params = IMP_Compose::getAddressSearchParams(); try { diff --git a/imp/lib/Crypt/Smime.php b/imp/lib/Crypt/Smime.php index fea83d9ac..856ea493b 100644 --- a/imp/lib/Crypt/Smime.php +++ b/imp/lib/Crypt/Smime.php @@ -162,6 +162,14 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime */ public function getPublicKey($address) { + try { + $key = Horde::callHook('smime_key', array($address), 'imp'); + if ($key) { + return $key; + } + } catch (Horde_Exception_HookNotSet $e) { + } + $params = IMP_Compose::getAddressSearchParams(); try { -- 2.11.0