From: Michael M Slusarz Date: Wed, 14 Jul 2010 06:57:12 +0000 (-0600) Subject: Add Horde_Crypt_Exception X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=23d8fd6f05716d237f59456260930aadcf19071c;p=horde.git Add Horde_Crypt_Exception --- diff --git a/framework/Crypt/lib/Horde/Crypt.php b/framework/Crypt/lib/Horde/Crypt.php index 9f9a16f72..8430c428f 100644 --- a/framework/Crypt/lib/Horde/Crypt.php +++ b/framework/Crypt/lib/Horde/Crypt.php @@ -36,7 +36,7 @@ class Horde_Crypt * or parameters a subclass might need. * * @return Horde_Crypt The newly created concrete instance. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ static public function factory($driver, $params = array()) { @@ -57,7 +57,7 @@ class Horde_Crypt return new $class($params); } - throw new Horde_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.'); + throw new Horde_Crypt_Exception(__CLASS__ . ': Class definition of ' . $driver . ' not found.'); } /** @@ -113,7 +113,7 @@ class Horde_Crypt * @param array $params An array of arguments needed to decrypt the data. * * @return array The decrypted data. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function decrypt($data, $params = array()) { diff --git a/framework/Crypt/lib/Horde/Crypt/Exception.php b/framework/Crypt/lib/Horde/Crypt/Exception.php new file mode 100644 index 000000000..18932cd2d --- /dev/null +++ b/framework/Crypt/lib/Horde/Crypt/Exception.php @@ -0,0 +1,17 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Crypt + */ +class Horde_Crypt_Exception extends Horde_Exception_Prior +{ +} diff --git a/framework/Crypt/lib/Horde/Crypt/Pgp.php b/framework/Crypt/lib/Horde/Crypt/Pgp.php index 721cdf270..e5d305b8c 100644 --- a/framework/Crypt/lib/Horde/Crypt/Pgp.php +++ b/framework/Crypt/lib/Horde/Crypt/Pgp.php @@ -177,7 +177,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * 'public' => Public Key * 'private' => Private Key * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function generateKey($realname, $email, $passphrase, $comment = '', $keylength = 1024) @@ -224,7 +224,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt if (!empty($result->stderr)) { $msg .= ' ' . _("Returned error message:") . ' ' . $result->stderr; } - throw new Horde_Exception($msg); + throw new Horde_Crypt_Exception($msg); } return array('public' => $public_key, 'private' => $secret_key); @@ -276,7 +276,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * UID (e.g. revocation signatures and sub keys) will be stored under the * special keyword '_SIGNATURE'. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function pgpPacketInformation($pgpdata) { @@ -408,7 +408,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $pgpdata The PGP data block. * * @return string Tabular information on the PGP key. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function pgpPrettyKey($pgpdata) { @@ -504,7 +504,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * created => Signature creation - UNIX timestamp * micalg => The hash used to create the signature * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function pgpPacketSignature($pgpdata, $email) { @@ -549,7 +549,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $uid_idx The UID index. * * @return array See pgpPacketSignature(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function pgpPacketSignatureByUidIndex($pgpdata, $uid_idx) { @@ -617,7 +617,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $text The PGP signed text block. * * @return string The key ID of the key used to sign $text. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function getSignersKeyID($text) { @@ -647,27 +647,27 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * @return boolean Returns true on valid passphrase, false on invalid * passphrase. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function verifyPassphrase($public_key, $private_key, $passphrase) { /* Get e-mail address of public key. */ $key_info = $this->pgpPacketInformation($public_key); if (!isset($key_info['signature']['id1']['email'])) { - throw new Horde_Exception(_("Could not determine the recipient's e-mail address.")); + throw new Horde_Crypt_Exception(_("Could not determine the recipient's e-mail address.")); } /* Encrypt a test message. */ try { $result = $this->encrypt('Test', array('type' => 'message', 'pubkey' => $public_key, 'recips' => array($key_info['signature']['id1']['email'] => $public_key))); - } catch (Horde_Exception $e) { + } catch (Horde_Crypt_Exception $e) { return false; } /* Try to decrypt the message. */ try { $this->decrypt($result, array('type' => 'message', 'pubkey' => $public_key, 'privkey' => $private_key, 'passphrase' => $passphrase)); - } catch (Horde_Exception $e) { + } catch (Horde_Crypt_Exception $e) { return false; } @@ -754,7 +754,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt return substr($start, 0, $length); } - throw new Horde_Exception(_("Could not obtain public key from the keyserver.")); + throw new Horde_Crypt_Exception(_("Could not obtain public key from the keyserver.")); } /** @@ -764,7 +764,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $server The keyserver to use. * @param float $timeout The keyserver timeout. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function putPublicKeyserver($pubkey, $server = self::KEYSERVER_PUBLIC, @@ -776,8 +776,8 @@ class Horde_Crypt_Pgp extends Horde_Crypt /* See if the public key already exists on the keyserver. */ try { $this->getPublicKeyserver($info['keyid'], $server, $timeout); - } catch (Horde_Exception $e) { - throw new Horde_Exception(_("Key already exists on the public keyserver.")); + } catch (Horde_Crypt_Exception $e) { + throw new Horde_Crypt_Exception(_("Key already exists on the public keyserver.")); } /* Connect to the public keyserver. _connectKeyserver() */ @@ -804,7 +804,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param float $timeout The keyserver timeout. * * @return string The PGP key ID. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function getKeyID($address, $server = self::KEYSERVER_PUBLIC, $timeout = self::KEYSERVER_TIMEOUT) @@ -843,7 +843,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt } } - throw new Horde_Exception(_("Could not obtain public key from the keyserver.")); + throw new Horde_Crypt_Exception(_("Could not obtain public key from the keyserver.")); } /** @@ -852,7 +852,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $pgpdata The PGP data block. * * @return array The fingerprints in $pgpdata indexed by key id. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function getFingerprintsFromKey($pgpdata) { @@ -897,7 +897,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param float $timeout The timeout value. * * @return string The text from standard output on success. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _connectKeyserver($method, $server, $resource, $command, $timeout) @@ -934,9 +934,9 @@ class Horde_Crypt_Pgp extends Horde_Crypt } while (++$connRefuse < self::KEYSERVER_REFUSE); if ($errno == 0) { - throw new Horde_Exception(_("Connection refused to the public keyserver.")); + throw new Horde_Crypt_Exception(_("Connection refused to the public keyserver.")); } else { - throw new Horde_Exception(sprintf(_("Connection refused to the public keyserver. Reason: %s (%s)"), Horde_String::convertCharset($errstr, $this->_params['external_charset']), $errno)); + throw new Horde_Crypt_Exception(sprintf(_("Connection refused to the public keyserver. Reason: %s (%s)"), Horde_String::convertCharset($errstr, $this->_params['external_charset']), $errno)); } } @@ -949,7 +949,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * parameter requirements. * * @return string The encrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function encrypt($text, $params = array()) { @@ -975,7 +975,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * 'message' - (string) The signature result text. * 'result' - (boolean) The result of the signature test. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function decrypt($text, $params = array()) { @@ -995,7 +995,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $text The PGP encrypted text. * * @return boolean True if the text is symmetricallly encrypted. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function encryptedSymmetrically($text) { @@ -1041,7 +1041,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * (Default) or 'private' * * @return string Command line keystring option to use with gpg program. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _putInKeyring($keys = array(), $type = 'public') { @@ -1084,7 +1084,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * * @return string The encrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptMessage($text, $params) { @@ -1118,7 +1118,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt $result = $this->_callGpg($cmdline, 'w', empty($params['symmetric']) ? null : $params['passphrase'], true, true); if (empty($result->output)) { $error = preg_replace('/\n.*/', '', $result->stderr); - throw new Horde_Exception(_("Could not PGP encrypt message: ") . $error); + throw new Horde_Crypt_Exception(_("Could not PGP encrypt message: ") . $error); } return $result->output; @@ -1142,7 +1142,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * * @return string The signed message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptSignature($text, $params) { @@ -1150,7 +1150,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt if (!isset($params['pubkey']) || !isset($params['privkey']) || !isset($params['passphrase'])) { - throw new Horde_Exception(_("A public PGP key, private PGP key, and passphrase are required to sign a message.")); + throw new Horde_Crypt_Exception(_("A public PGP key, private PGP key, and passphrase are required to sign a message.")); } /* Create temp files for input. */ @@ -1187,7 +1187,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt $result = $this->_callGpg($cmdline, 'w', $params['passphrase'], true, true); if (empty($result->output)) { $error = preg_replace('/\n.*/', '', $result->stderr); - throw new Horde_Exception(_("Could not PGP sign message: ") . $error); + throw new Horde_Crypt_Exception(_("Could not PGP sign message: ") . $error); } return $result->output; @@ -1218,7 +1218,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * 'message' - (string) The signature result text. * 'result' - (boolean) The result of the signature test. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _decryptMessage($text, $params) { @@ -1226,7 +1226,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt /* Check for required parameters. */ if (!isset($params['passphrase']) && empty($params['no_passphrase'])) { - throw new Horde_Exception(_("A passphrase is required to decrypt a message.")); + throw new Horde_Crypt_Exception(_("A passphrase is required to decrypt a message.")); } /* Create temp files. */ @@ -1262,7 +1262,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt } if (empty($result->output)) { $error = preg_replace('/\n.*/', '', $result->stderr); - throw new Horde_Exception(_("Could not decrypt PGP data: ") . $error); + throw new Horde_Crypt_Exception(_("Could not decrypt PGP data: ") . $error); } /* Create the return object. */ @@ -1287,17 +1287,17 @@ class Horde_Crypt_Pgp extends Horde_Crypt * 'message' - (string) The signature result text. * 'result' - (boolean) The result of the signature test. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _decryptSignature($text, $params) { /* Check for required parameters. */ if (!isset($params['pubkey'])) { - throw new Horde_Exception(_("A public PGP key is required to verify a signed message.")); + throw new Horde_Crypt_Exception(_("A public PGP key is required to verify a signed message.")); } if (($params['type'] === 'detached-signature') && !isset($params['signature'])) { - throw new Horde_Exception(_("The detached PGP signature block is required to verify the signed message.")); + throw new Horde_Crypt_Exception(_("The detached PGP signature block is required to verify the signed message.")); } $good_sig_flag = 0; @@ -1347,7 +1347,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * 'message' - (string) The signature result text. * 'result' - (boolean) The result of the signature test. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _checkSignatureResult($result, $message = null) { @@ -1356,7 +1356,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * Bad signature: * gpg: BAD signature from "blah blah blah (Comment)" */ if (strpos($result, 'gpg: BAD signature') !== false) { - throw new Horde_Exception($result); + throw new Horde_Crypt_Exception($result); } $ob = new stdClass; @@ -1375,7 +1375,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * @return mixed A Horde_Mime_Part object that is signed according to RFC * 3156. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function signMIMEPart($mime_part, $params = array()) { @@ -1422,7 +1422,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * @return mixed A Horde_Mime_Part object that is encrypted according to * RFC 3156. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function encryptMIMEPart($mime_part, $params = array()) { @@ -1466,7 +1466,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * * @return mixed A Horde_Mime_Part object that is signed and encrypted * according to RFC 3156. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function signAndEncryptMIMEPart($mime_part, $sign_params = array(), $encrypt_params = array()) @@ -1515,7 +1515,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param boolean $verbose Run GnuPG with verbose flag? * * @return stdClass Class with members output, stderr, and stdout. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _callGpg($options, $mode, $input = array(), $output = false, $stderr = false, @@ -1570,7 +1570,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt } } } else { - throw new Horde_Exception(_("Error while talking to pgp binary.")); + throw new Horde_Crypt_Exception(_("Error while talking to pgp binary.")); } } elseif ($mode == 'r') { if ($fp = popen($cmdline, 'r')) { @@ -1578,7 +1578,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt $data->stdout .= fgets($fp, 1024); } } else { - throw new Horde_Exception(_("Error while talking to pgp binary.")); + throw new Horde_Crypt_Exception(_("Error while talking to pgp binary.")); } } pclose($fp); @@ -1603,7 +1603,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt * @param string $passphrase The passphrase to use for the key. * * @return string The revocation certificate. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function generateRevocation($key, $email, $passphrase) { @@ -1630,7 +1630,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt /* If the key is empty, something went wrong. */ if (empty($results->output)) { - throw new Horde_Exception(_("Revocation key not generated successfully.")); + throw new Horde_Crypt_Exception(_("Revocation key not generated successfully.")); } return $results->output; diff --git a/framework/Crypt/lib/Horde/Crypt/Smime.php b/framework/Crypt/lib/Horde/Crypt/Smime.php index f5d3c49af..04e13e0bc 100644 --- a/framework/Crypt/lib/Horde/Crypt/Smime.php +++ b/framework/Crypt/lib/Horde/Crypt/Smime.php @@ -88,7 +88,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * the parameter requirements. * * @return string The encrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function encrypt($text, $params = array()) { @@ -113,7 +113,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * the parameter requirements. * * @return string The decrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function decrypt($text, $params = array()) { @@ -141,7 +141,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * 'cert' -> The certificate of the signer stored * in the message (in PEM format). * 'email' -> The email of the signing person. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function verify($text, $certs) { @@ -183,11 +183,11 @@ class Horde_Crypt_Smime extends Horde_Crypt $result = openssl_pkcs7_verify($input, PKCS7_NOVERIFY, $output); if ($result === true) { - throw new Horde_Exception(_("Message Verified Successfully but the signer's certificate could not be verified.")); + throw new Horde_Crypt_Exception(_("Message Verified Successfully but the signer's certificate could not be verified.")); } elseif ($result == -1) { - throw new Horde_Exception(_("Verification failed - an unknown error has occurred.")); + throw new Horde_Crypt_Exception(_("Verification failed - an unknown error has occurred.")); } else { - throw new Horde_Exception(_("Verification failed - this message may have been tampered with.")); + throw new Horde_Crypt_Exception(_("Verification failed - this message may have been tampered with.")); } $ob->cert = file_get_contents($output); @@ -203,7 +203,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * @param string $sslpath The path to the OpenSSL binary. * * @return string The contents embedded in the signed data. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function extractSignedContents($data, $sslpath) { @@ -225,7 +225,7 @@ class Horde_Crypt_Smime extends Horde_Crypt return $ret; } - throw new Horde_Exception(_("OpenSSL error: Could not extract data from signed S/MIME part.")); + throw new Horde_Crypt_Exception(_("OpenSSL error: Could not extract data from signed S/MIME part.")); } /** @@ -235,7 +235,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * @param array $params The parameters required for signing. * * @return mixed A Horde_Mime_Part object that is signed. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function signMIMEPart($mime_part, $params) { @@ -268,7 +268,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * encryption. * * @return mixed A Horde_Mime_Part object that is encrypted. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function encryptMIMEPart($mime_part, $params = array()) { @@ -299,13 +299,13 @@ class Horde_Crypt_Smime extends Horde_Crypt * * * @return string The encrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptMessage($text, $params) { /* Check for required parameters. */ if (!isset($params['pubkey'])) { - throw new Horde_Exception(_("A public S/MIME key is required to encrypt a message.")); + throw new Horde_Crypt_Exception(_("A public S/MIME key is required to encrypt a message.")); } /* Create temp files for input/output. */ @@ -324,7 +324,7 @@ class Horde_Crypt_Smime extends Horde_Crypt } } - throw new Horde_Exception(_("Could not S/MIME encrypt message.")); + throw new Horde_Crypt_Exception(_("Could not S/MIME encrypt message.")); } /** @@ -346,7 +346,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * * * @return string The signed message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptSignature($text, $params) { @@ -354,7 +354,7 @@ class Horde_Crypt_Smime extends Horde_Crypt if (!isset($params['pubkey']) || !isset($params['privkey']) || !array_key_exists('passphrase', $params)) { - throw new Horde_Exception(_("A public S/MIME key, private S/MIME key, and passphrase are required to sign a message.")); + throw new Horde_Crypt_Exception(_("A public S/MIME key, private S/MIME key, and passphrase are required to sign a message.")); } /* Create temp files for input/output/certificates. */ @@ -385,7 +385,7 @@ class Horde_Crypt_Smime extends Horde_Crypt } if (!$res) { - throw new Horde_Exception(_("Could not S/MIME sign message.")); + throw new Horde_Crypt_Exception(_("Could not S/MIME sign message.")); } $data = file_get_contents($output); @@ -408,7 +408,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * * * @return string The decrypted message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _decryptMessage($text, $params) { @@ -416,7 +416,7 @@ class Horde_Crypt_Smime extends Horde_Crypt if (!isset($params['pubkey']) || !isset($params['privkey']) || !array_key_exists('passphrase', $params)) { - throw new Horde_Exception(_("A public S/MIME key, private S/MIME key, and passphrase are required to decrypt a message.")); + throw new Horde_Crypt_Exception(_("A public S/MIME key, private S/MIME key, and passphrase are required to decrypt a message.")); } /* Create temp files for input/output. */ @@ -434,7 +434,7 @@ class Horde_Crypt_Smime extends Horde_Crypt return file_get_contents($output); } - throw new Horde_Exception(_("Could not decrypt S/MIME data.")); + throw new Horde_Crypt_Exception(_("Could not decrypt S/MIME data.")); } /** @@ -448,7 +448,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * @see _encryptMessage(). * * @return mixed A Horde_Mime_Part object that is signed and encrypted. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function signAndEncryptMIMEPart($mime_part, $sign_params = array(), $encrypt_params = array()) @@ -1125,22 +1125,22 @@ class Horde_Crypt_Smime extends Horde_Crypt * @param array $params The parameters needed for verification. * * @return string The verification message. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _decryptSignature($text, $params) { - throw new Horde_Exception('_decryptSignature() ' . _("not yet implemented")); + throw new Horde_Crypt_Exception('_decryptSignature() ' . _("not yet implemented")); } /** * Check for the presence of the OpenSSL extension to PHP. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function checkForOpenSSL() { if (!Horde_Util::extensionExists('openssl')) { - throw new Horde_Exception(_("The openssl module is required for the Horde_Crypt_Smime:: class.")); + throw new Horde_Crypt_Exception(_("The openssl module is required for the Horde_Crypt_Smime:: class.")); } } @@ -1203,7 +1203,7 @@ class Horde_Crypt_Smime extends Horde_Crypt * 'private' - The private key in PEM format. * 'public' - The public key in PEM format. * 'certs' - An array of additional certs. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function parsePKCS12Data($pkcs12, $params) { @@ -1211,7 +1211,7 @@ class Horde_Crypt_Smime extends Horde_Crypt $this->checkForOpenSSL(); if (!isset($params['sslpath'])) { - throw new Horde_Exception(_("No path to the OpenSSL binary provided. The OpenSSL binary is necessary to work with PKCS 12 data.")); + throw new Horde_Crypt_Exception(_("No path to the OpenSSL binary provided. The OpenSSL binary is necessary to work with PKCS 12 data.")); } $sslpath = escapeshellcmd($params['sslpath']); @@ -1245,12 +1245,12 @@ class Horde_Crypt_Smime extends Horde_Crypt } pclose($fd); } else { - throw new Horde_Exception(_("Error while talking to smime binary.")); + throw new Horde_Crypt_Exception(_("Error while talking to smime binary.")); } $ob->private = trim(file_get_contents($output)); if (empty($ob->private)) { - throw new Horde_Exception(_("Password incorrect")); + throw new Horde_Crypt_Exception(_("Password incorrect")); } /* Extract the client public key next. */ @@ -1263,7 +1263,7 @@ class Horde_Crypt_Smime extends Horde_Crypt fwrite($fd, $params['password'] . "\n"); pclose($fd); } else { - throw new Horde_Exception(_("Error while talking to smime binary.")); + throw new Horde_Crypt_Exception(_("Error while talking to smime binary.")); } $ob->public = trim(file_get_contents($output)); @@ -1278,7 +1278,7 @@ class Horde_Crypt_Smime extends Horde_Crypt fwrite($fd, $params['password'] . "\n"); pclose($fd); } else { - throw new Horde_Exception(_("Error while talking to smime binary.")); + throw new Horde_Crypt_Exception(_("Error while talking to smime binary.")); } $ob->certs = trim(file_get_contents($output)); diff --git a/framework/Crypt/package.xml b/framework/Crypt/package.xml index 981181c73..5d13bbbbc 100644 --- a/framework/Crypt/package.xml +++ b/framework/Crypt/package.xml @@ -24,13 +24,15 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Better error handling for gnupg and openssl command line binaries. -* Initial Horde 4 package. + * Add Horde_Crypt_Exception::. + * Better error handling for gnupg and openssl command line binaries. + * Initial Horde 4 package. + @@ -84,6 +86,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.5.0 + Exception + pear.horde.org + + Mime pear.horde.org @@ -100,6 +106,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/imp/lib/Crypt/Pgp.php b/imp/lib/Crypt/Pgp.php index af87e04fb..7a7d6e003 100644 --- a/imp/lib/Crypt/Pgp.php +++ b/imp/lib/Crypt/Pgp.php @@ -27,7 +27,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param string $comment See Horde_Crypt_Pgp:: * @param string $keylength See Horde_Crypt_Pgp:: * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function generatePersonalKeys($name, $email, $passphrase, $comment = '', $keylength = 1024) @@ -98,6 +98,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param string $public_key An PGP public key. * * @return array See Horde_Crypt_Pgp::pgpPacketInformation() + * @throws Horde_Crypt_Exception * @throws Horde_Exception */ public function addPublicKey($public_key) @@ -105,7 +106,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp /* Make sure the key is valid. */ $key_info = $this->pgpPacketInformation($public_key); if (!isset($key_info['signature'])) { - throw new Horde_Exception(_("Not a valid public key.")); + throw new Horde_Crypt_Exception(_("Not a valid public key.")); } /* Remove the '_SIGNATURE' entry. */ @@ -122,7 +123,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp unset($key_info['signature'][$id]); continue; } - } catch (Horde_Exception $e) {} + } catch (Horde_Crypt_Exception $e) {} /* Add key to the user's address book. */ $GLOBALS['registry']->call('contacts/addField', array($sig['email'], $sig['name'], self::PUBKEY_FIELD, $public_key, $GLOBALS['prefs']->getValue('add_source'))); @@ -152,7 +153,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * * * @return string The PGP public key requested. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function getPublicKey($address, $options = array()) { @@ -175,14 +176,16 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp if ($key) { return $key; } - } catch (Horde_Exception_HookNotSet $e) { - } + } catch (Horde_Exception_HookNotSet $e) {} /* Try retrieving by e-mail only first. */ $params = IMP::getAddressbookSearchParams(); + $result = null; try { $result = $GLOBALS['registry']->call('contacts/getField', array($address, self::PUBKEY_FIELD, $params['sources'], false, true)); - } catch (Horde_Exception $e) { + } catch (Horde_Exception $e) {} + + if (is_null($result)) { /* TODO: Retrieve by ID. */ /* See if the address points to the user's public key. */ @@ -200,10 +203,10 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp if (is_object($cache)) { $cache->set("PGPpublicKey_" . $address . $keyid, $result, 3600); } - } catch (Horde_Exception $e) { + } catch (Horde_Crypt_Exception $e) { /* Return now, if no public key found at all. */ Horde::logMessage('PGPpublicKey: ' . $e->getMessage(), 'DEBUG'); - throw new Horde_Exception(sprintf(_("Could not retrieve public key for %s."), $address)); + throw new Horde_Crypt_Exception(sprintf(_("Could not retrieve public key for %s."), $address)); } } else { $result = ''; @@ -224,7 +227,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * Retrieves all public keys from a user's address book(s). * * @return array All PGP public keys available. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function listPublicKeys() { @@ -241,7 +244,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * * @param string $email The e-mail address to delete. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function deletePublicKey($email) { @@ -256,7 +259,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param string $address The email address of the requested key. * * @return string See Horde_Crypt_Pgp::getPublicKeyserver() - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function getFromPublicKeyserver($keyid, $address = null) { @@ -269,7 +272,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param string $pubkey The PGP public key. * * @return string See Horde_Crypt_Pgp::putPublicKeyserver() - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function sendToPublicKeyserver($pubkey) { @@ -285,14 +288,14 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * * @return string See Horde_Crypt_Pgp::getPublicKeyserver() -or- * Horde_Crypt_Pgp::putPublicKeyserver(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _keyserverConnect($data, $method, $additional = null) { global $conf; if (empty($conf['gnupg']['keyserver'])) { - throw new Horde_Exception(_("Public PGP keyserver support has been disabled.")); + throw new Horde_Crypt_Exception(_("Public PGP keyserver support has been disabled.")); } $timeout = empty($conf['gnupg']['timeout']) @@ -306,9 +309,9 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp foreach ($conf['gnupg']['keyserver'] as $server) { try { return $this->getPublicKeyserver($data, $server, $timeout, $additional); - } catch (Horde_Exception $e) {} + } catch (Horde_Crypt_Exception $e) {} } - throw new Horde_Exception(_("Could not connect to public PGP keyserver")); + throw new Horde_Crypt_Exception(_("Could not connect to public PGP keyserver")); } /** @@ -319,7 +322,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param string $signature A PGP signature block. * * @return stdClass See Horde_Crypt_Pgp::decrypt(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function verifySignature($text, $address, $signature = '') { @@ -357,7 +360,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * the passphrase to use. * * @return stdClass See Horde_Crypt_Pgp::decrypt(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function decryptMessage($text, $type, $passphrase = null) { @@ -499,7 +502,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * encrypting. If null, uses the personal key. * * @return array The list of parameters needed by encrypt(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptParameters($addresses, $symmetric) { @@ -529,7 +532,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * @param Horde_Mime_Part $mime_part The object to sign. * * @return Horde_Mime_Part See Horde_Crypt_Pgp::signMIMEPart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function impSignMimePart($mime_part) { @@ -547,7 +550,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * the personal key. * * @return Horde_Mime_Part See Horde_Crypt_Pgp::encryptMimePart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function impEncryptMimePart($mime_part, $addresses, $symmetric = null) @@ -567,7 +570,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp * the personal key. * * @return Horde_Mime_Part See Horde_Crypt_Pgp::signAndencryptMimePart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function impSignAndEncryptMimePart($mime_part, $addresses, $symmetric = null) @@ -597,7 +600,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp { try { $key_info = $this->pgpPrettyKey($key); - } catch (Horde_Exception $e) { + } catch (Horde_Crypt_Exception $e) { Horde::logMessage($e, 'INFO'); $key_info = $e->getMessage(); } diff --git a/imp/lib/Crypt/Smime.php b/imp/lib/Crypt/Smime.php index 64cee41d5..212b3f623 100644 --- a/imp/lib/Crypt/Smime.php +++ b/imp/lib/Crypt/Smime.php @@ -94,20 +94,20 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * * @param string $cert A public certificate to add. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function addPublicKey($cert) { /* Make sure the certificate is valid. */ $key_info = openssl_x509_parse($cert); if (!is_array($key_info) || !isset($key_info['subject'])) { - throw new Horde_Exception(_("Not a valid public key.")); + throw new Horde_Crypt_Exception(_("Not a valid public key.")); } /* Add key to the user's address book. */ $email = $this->getEmailFromKey($cert); if (is_null($email)) { - throw new Horde_Exception(_("No email information located in the public key.")); + throw new Horde_Crypt_Exception(_("No email information located in the public key.")); } /* Get the name corresponding to this key. */ @@ -116,7 +116,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime } elseif (isset($key_info['subject']['OU'])) { $name = $key_info['subject']['OU']; } else { - throw new Horde_Exception(_("Not a valid public key.")); + throw new Horde_Crypt_Exception(_("Not a valid public key.")); } $GLOBALS['registry']->call('contacts/addField', array($email, $name, self::PUBKEY_FIELD, $cert, $GLOBALS['prefs']->getValue('add_source'))); @@ -129,7 +129,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param string $address The e-mail address of the recipient. * * @return array The list of parameters needed by encrypt(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ protected function _encryptParameters($address) { @@ -161,8 +161,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime if ($key) { return $key; } - } catch (Horde_Exception_HookNotSet $e) { - } + } catch (Horde_Exception_HookNotSet $e) {} $params = IMP::getAddressbookSearchParams(); @@ -189,7 +188,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * Retrieves all public keys from a user's address book(s). * * @return array All S/MIME public keys available. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function listPublicKeys() { @@ -205,7 +204,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * * @param string $email The e-mail address to delete. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function deletePublicKey($email) { @@ -236,7 +235,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param string $text The text to verify. * * @return stdClass See Horde_Crypt_Smime::verify(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function verifySignature($text) { @@ -250,7 +249,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param string $text The text to decrypt. * * @return string See Horde_Crypt_Smime::decrypt(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function decryptMessage($text) { @@ -345,7 +344,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * encryption. * * @return MIME_Part See Horde_Crypt_Smime::encryptMIMEPart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function IMPencryptMIMEPart($mime_part, $to_address) { @@ -358,7 +357,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param MIME_Part $mime_part The MIME_Part object to sign. * * @return MIME_Part See Horde_Crypt_Smime::signMIMEPart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function IMPsignMIMEPart($mime_part) { @@ -373,7 +372,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * encryption. * * @return MIME_Part See Horde_Crypt_Smime::signAndencryptMIMEPart(). - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function IMPsignAndEncryptMIMEPart($mime_part, $to_address) { @@ -388,7 +387,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param string $password The password of the PKCS 12 file. * @param string $pkpass The password to use to encrypt the private key. * - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function addFromPKCS12($pkcs12, $password, $pkpass = null) { @@ -413,7 +412,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime * @param string $data The signed S/MIME data. * * @return string The contents embedded in the signed data. - * @throws Horde_Exception + * @throws Horde_Crypt_Exception */ public function extractSignedContents($data) {