Add hook to retrieve public S/MIME and PGP keys.
authorJan Schneider <jan@horde.org>
Fri, 9 Oct 2009 13:15:04 +0000 (15:15 +0200)
committerJan Schneider <jan@horde.org>
Fri, 9 Oct 2009 13:20:24 +0000 (15:20 +0200)
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/lib/Crypt/Pgp.php
imp/lib/Crypt/Smime.php

index f34b697..d5089f9 100644 (file)
@@ -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
index 81d61a6..d8c1aac 100644 (file)
@@ -104,7 +104,7 @@ v5.0-git
 v4.3.6-cvs
 ----------
 
-
+[jan] Add hook to retrieve public S/MIME and PGP keys.
 
 
 ------
index ecba1fe..d77c76d 100644 (file)
@@ -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 {
index fea83d9..856ea49 100644 (file)
@@ -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 {