// reset credentials so user is not forced to relogin
if (Horde_Auth::getCredential('password') == $info['old']) {
Horde_Auth::setCredential('password', $info['new']);
- if (Horde_Auth::getProvider() == 'imp' || !empty($_SESSION['imp']['pass'])) {
- $_SESSION['imp']['pass'] = Horde_Secret::write(Horde_Secret::getKey('imp'),
- $info['new']);
- } elseif (Horde_Auth::getProvider() == 'mimp' || !empty($_SESSION['mimp']['pass'])) {
- $_SESSION['mimp']['pass'] = Horde_Secret::write(Horde_Secret::getKey('mimp'),
- $info['new']);
+ $secret = $injector->getInstance('Horde_Secret');
+ if (Horde_Auth::getProvider() == 'imp' ||
+ !empty($_SESSION['imp']['pass'])) {
+ $_SESSION['imp']['pass'] = $secret->write($secret->getKey('imp'), $info['new']);
}
}
$credentials = array($credential => $value);
}
- $_SESSION['horde_auth']['app'][$app] = Horde_Secret::write(Horde_Secret::getKey('auth'), serialize($credentials));
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $_SESSION['horde_auth']['app'][$app] = $secret->write($secret->getKey('auth'), serialize($credentials));
}
}
}
$app = $_SESSION['horde_auth']['credentials'];
}
- return isset($_SESSION['horde_auth']['app'])
- ? @unserialize(Horde_Secret::read(Horde_Secret::getKey('auth'), $_SESSION['horde_auth']['app'][$app]))
- : false;
+ if (!isset($_SESSION['horde_auth']['app'])) {
+ return false;
+ }
+
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ return @unserialize($secret->read($secret->getKey('auth'), $_SESSION['horde_auth']['app'][$app]));
}
/**
$app_array = $is_auth
? $_SESSION['horde_auth']['app']
: array();
- $app_array[$app] = Horde_Secret::write(Horde_Secret::getKey('auth'), serialize($credentials));
+
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $app_array[$app] = $secret->write($secret->getKey('auth'), serialize($credentials));
if ($is_auth) {
/* Store app credentials. */
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher:: class provides a common abstracted interface to
- * various Ciphers for encryption of arbitrary length pieces of data.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher
-{
- /**
- * The block mode for the cipher chaining
- *
- * @var string
- */
- protected $_blockMode = 'cbc';
-
- /**
- * The block size.
- *
- * @var integer
- */
- protected $_blockSize = 8;
-
- /**
- * The initialization vector
- *
- * @var string
- */
- protected $_iv = null;
-
- /**
- * Attempts to return a concrete Horde_Cipher instance.
- *
- * @param string $cipher The type of concrete Horde_Cipher subclass to
- * return.
- * @param array $params A hash containing any additional parameters a
- * subclass might need.
- *
- * @return Horde_Cipher The newly created concrete Horde_Cipher instance.
- * @throws Horde_Exception
- */
- static public function factory($driver, $params = null)
- {
- $class = 'Horde_Cipher_' . Horde_String::ucfirst(basename($driver));
- if (!class_exists($class)) {
- throw new Horde_Exception('Driver ' . $driver . ' not found');
- }
- return new $class($params);
- }
-
- /**
- * Set the block mode for cipher chaining.
- *
- * @param string $blockMode The new blockmode.
- */
- public function setBlockMode($blockMode)
- {
- $this->_blockMode = $blockMode;
- }
-
- /**
- * Return the size of the blocks that this cipher needs.
- *
- * @return integer The number of characters per block.
- */
- public function getBlockSize()
- {
- return $this->_blockSize;
- }
-
- /**
- * Set the IV.
- *
- * @param string $iv The new IV.
- */
- public function setIV($iv)
- {
- $this->_iv = $iv;
- }
-
- /**
- * Encrypt a string.
- *
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($plaintext)
- {
- $blockMode = Horde_Cipher_BlockMode::factory($this->_blockMode);
-
- if (!is_null($this->_iv)) {
- $blockMode->setIV($this->_iv);
- }
-
- return $blockMode->encrypt($this, $plaintext);
- }
-
- /**
- * Decrypt a string.
- *
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($ciphertext)
- {
- $blockMode = Horde_Cipher_BlockMode::factory($this->_blockMode);
-
- if (!is_null($this->_iv)) {
- $blockMode->setIV($this->_iv);
- }
-
- return $blockMode->decrypt($this, $ciphertext);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_BlockMode:: class provides a common abstracted
- * interface to various block mode handlers for ciphers.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_BlockMode
-{
- /**
- * The initialization vector.
- *
- * @var string
- */
- protected $_iv = "\0\0\0\0\0\0\0\0";
-
- /**
- * Attempts to return a concrete instance based on $mode.
- *
- * @param string $mode The type of concrete subclass to return.
- * subclass to return.
- * @param array $params A hash containing any additional parameters a
- * subclass might need.
- *
- * @return Horde_Cipher_BlockMode The newly created concrete instance.
- * @throws Horde_Exception
- */
- static public function factory($driver, $params = null)
- {
- $class = 'Horde_Cipher_BlockMode_' . Horde_String::ucfirst(basename($driver));
- if (!class_exists($class)) {
- throw new Horde_Exception('Driver ' . $driver . ' not found');
- }
- return new $class($params);
- }
-
- /**
- * Set the IV.
- *
- * @param string $iv The new IV.
- */
- public function setIV($iv)
- {
- $this->_iv = $iv;
- }
-
- /**
- * Encrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for encryption.
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($cipher, $plaintext)
- {
- return $plaintext;
- }
-
- /**
- * Decrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for decryption.
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($cipher, $ciphertext)
- {
- return $ciphertext;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_BlockMode_Cbc:: class implements Horde_Cipher_BlockMode
- * using the Cipher Block Chaining method of encrypting blocks of data.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_BlockMode_Cbc extends Horde_Cipher_BlockMode
-{
- /**
- * Encrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for encryption.
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($cipher, $plaintext)
- {
- $encrypted = '';
-
- $blocksize = $cipher->getBlockSize();
- $previousCipher = $this->_iv;
-
- $jMax = strlen($plaintext);
- for ($j = 0; $j < $jMax; $j += $blocksize) {
- $plain = substr($plaintext, $j, $blocksize);
-
- if (strlen($plain) < $blocksize) {
- // pad the block with \0's if it's not long enough
- $plain = str_pad($plain, 8, "\0");
- }
-
- $plain = $plain ^ $previousCipher;
- $previousCipher = $cipher->encryptBlock($plain);
- $encrypted .= $previousCipher;
- }
-
- return $encrypted;
- }
-
- /**
- * Decrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for decryption.
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($cipher, $ciphertext)
- {
- $decrypted = '';
-
- $blocksize = $cipher->getBlockSize();
- $previousCipher = $this->_iv;
-
- $jMax = strlen($ciphertext);
- for ($j = 0; $j < $jMax; $j += $blocksize) {
- $plain = substr($ciphertext, $j, $blocksize);
- $decrypted .= $cipher->decryptBlock($plain) ^ $previousCipher;
- $previousCipher = $plain;
- }
-
- // Remove trailing \0's used to pad the last block.
- while (substr($decrypted, -1, 1) == "\0") {
- $decrypted = substr($decrypted, 0, -1);
- }
-
- return $decrypted;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_BlockMode_Cfb64:: class implements Horde_Cipher_BlockMode
- * using a 64 bit cipher feedback.
- *
- * This can be used to encrypt any length string and the encrypted
- * version will be the same length.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_BlockMode_Cfb64 extends Horde_Cipher_BlockMode
-{
- /**
- * Encrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for encryption.
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($cipher, $plaintext)
- {
- $encrypted = '';
-
- $n = 0;
- $jMax = strlen($plaintext);
- for ($j = 0; $j < $jMax; ++$j) {
- if ($n == 0) {
- $this->_iv = $cipher->encryptBlock($this->_iv);
- }
-
- $c = $plaintext[$j] ^ $this->_iv[$n];
- $this->_iv = substr($this->_iv, 0, $n) . $c . substr($this->_iv, $n + 1);
- $encrypted .= $c;
-
- $n = (++$n) & 0x07;
- }
-
- return $encrypted;
- }
-
- /**
- * Decrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for decryption.
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($cipher, $ciphertext)
- {
- $decrypted = '';
-
- $n = 0;
- $jMax = strlen($ciphertext);
- for ($j = 0; $j < $jMax; ++$j) {
- if ($n == 0) {
- $this->_iv = $cipher->encryptBlock($this->_iv);
- }
-
- $c = $ciphertext[$j] ^ $this->_iv[$n];
- $this->_iv = substr($this->_iv, 0, $n) . substr($ciphertext, $j, 1) . substr($this->_iv, $n + 1);
- $decrypted .= $c;
-
- $n = (++$n) & 0x07;
- }
-
- // Remove trailing \0's used to pad the last block.
- while (substr($decrypted, -1, 1) == "\0") {
- $decrypted = substr($decrypted, 0, -1);
- }
-
- return $decrypted;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_BlockMode_Ecb:: class implements Horde_Cipher_BlockMode
- * using the Electronic Code Book method of encrypting blocks of data.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_BlockMode_Ecb extends Horde_Cipher_BlockMode
-{
- /**
- * Encrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for encryption.
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($cipher, $plaintext)
- {
- $encrypted = '';
- $blocksize = $cipher->getBlockSize();
-
- $jMax = strlen($plaintext);
- for ($j = 0; $j < $jMax; $j += $blocksize) {
- $plain = substr($plaintext, $j, $blocksize);
-
- if (strlen($plain) < $blocksize) {
- // pad the block with \0's if it's not long enough
- $plain = str_pad($plain, 8, "\0");
- }
-
- $encrypted .= $cipher->encryptBlock($plain);
- }
-
- return $encrypted;
- }
-
- /**
- * Decrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for decryption.
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($cipher, $ciphertext)
- {
- $decrypted = '';
- $blocksize = $cipher->getBlockSize();
-
- $jMax = strlen($ciphertext);
- for ($j = 0; $j < $jMax; $j += $blocksize) {
- $plain = substr($ciphertext, $j, $blocksize);
- $decrypted .= $cipher->decryptBlock($plain);
- }
-
- // Remove trailing \0's used to pad the last block.
- while (substr($decrypted, -1, 1) == "\0") {
- $decrypted = substr($decrypted, 0, -1);
- }
-
- return $decrypted;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_BlockMode_Ofb64:: class implements Horde_Cipher_BlockMode
- * using a 64 bit output feedback.
- *
- * This can used to encrypt any length string and the encrypted version
- * will be the same length.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_BlockMode_Ofb64 extends Horde_Cipher_BlockMode
-{
- /**
- * Encrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for encryption.
- * @param string $plaintext The data to encrypt.
- *
- * @return string The encrypted data.
- */
- public function encrypt($cipher, $plaintext)
- {
- $encrypted = '';
-
- $n = 0;
- $jMax = strlen($plaintext);
- for ($j = 0; $j < $jMax; ++$j) {
- if ($n == 0) {
- $this->_iv = $cipher->encryptBlock($this->_iv);
- }
-
- $c = $plaintext[$j] ^ $this->_iv[$n];
- $encrypted .= $c;
-
- $n = (++$n) & 0x07;
- }
-
- return $encrypted;
- }
-
- /**
- * Decrypt a string.
- *
- * @param Horde_Cipher $cipher Cipher algorithm to use for decryption.
- * @param string $ciphertext The data to decrypt.
- *
- * @return string The decrypted data.
- */
- public function decrypt($cipher, $ciphertext)
- {
- $decrypted = '';
-
- $n = 0;
- $jMax = strlen($ciphertext);
- for ($j = 0; $j < $jMax; ++$j) {
- if ($n == 0) {
- $this->_iv = $cipher->encryptBlock($this->_iv);
- }
-
- $c = $ciphertext[$j] ^ $this->_iv[$n];
- $decrypted .= $c;
-
- $n = (++$n) & 0x07;
- }
-
- return $decrypted;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Cipher_des:: class implements the Cipher interface encryption data
- * using the Data Encryption Standard (DES) algorithm as defined in FIPS46-3.
- *
- * Copyright 2003-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_Des extends Horde_Cipher
-{
- /**
- * Initial Permutation.
- *
- * @var array
- */
- protected $_ip = array(
- 58, 50, 42, 34, 26, 18, 10, 2,
- 60, 52, 44, 36, 28, 20, 12, 4,
- 62, 54, 46, 38, 30, 22, 14, 6,
- 64, 56, 48, 40, 32, 24, 16, 8,
- 57, 49, 41, 33, 25, 17, 9, 1,
- 59, 51, 43, 35, 27, 19, 11, 3,
- 61, 53, 45, 37, 29, 21, 13, 5,
- 63, 55, 47, 39, 31, 23, 15, 7
- );
-
- /**
- * Final Permutation IP^-1.
- *
- * @var array
- */
- protected $_fp = array(
- 40, 8, 48, 16, 56, 24, 64, 32,
- 39, 7, 47, 15, 55, 23, 63, 31,
- 38, 6, 46, 14, 54, 22, 62, 30,
- 37, 5, 45, 13, 53, 21, 61, 29,
- 36, 4, 44, 12, 52, 20, 60, 28,
- 35, 3, 43, 11, 51, 19, 59, 27,
- 34, 2, 42, 10, 50, 18, 58, 26,
- 33, 1, 41, 9, 49, 17, 57, 25
- );
-
- /**
- * E Bit Selection Table.
- *
- * @var array
- */
- protected $_e = array(
- 32, 1, 2, 3, 4, 5,
- 4, 5, 6, 7, 8, 9,
- 8, 9, 10, 11, 12, 13,
- 12, 13, 14, 15, 16, 17,
- 16, 17, 18, 19, 20, 21,
- 20, 21, 22, 23, 24, 25,
- 24, 25, 26, 27, 28, 29,
- 28, 29, 30, 31, 32, 1
- );
-
- /**
- * S boxes.
- *
- * @var array
- */
- protected $_s = array(
- /* S1 */
- 1 => array(
- 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
- 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
- 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
- 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13
- ),
-
- /* S2 */
- 2 => array(
- 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
- 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
- 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
- 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
- ),
-
- /* S3 */
- 3 => array(
- 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
- 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
- 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
- 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
- ),
-
- /* S4 */
- 4 => array(
- 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
- 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
- 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
- 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
- ),
-
- /* S5 */
- 5 => array(
- 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
- 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
- 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
- 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
- ),
-
- /* S6 */
- 6 => array(
- 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
- 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
- 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
- 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
- ),
-
- /* S7 */
- 7 => array(
- 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
- 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
- 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
- 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
- ),
-
- /* S8 */
- 8 => array(
- 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
- 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
- 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
- 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
- )
- );
-
- /**
- * Primitive function.
- *
- * @var array
- */
- protected $_p = array(
- 16, 7, 20, 21,
- 29, 12, 28, 17,
- 1, 15, 23, 26,
- 5, 18, 31, 10,
- 2, 8, 24, 14,
- 32, 27, 3, 9,
- 19, 13, 30, 6,
- 22, 11, 4, 25
- );
-
- /**
- * Permuted Choice Table.
- *
- * @var array
- */
- protected $_pc1 = array(
- 57, 49, 41, 33, 25, 17, 9,
- 1, 58, 50, 42, 34, 26, 18,
- 10, 2, 59, 51, 43, 35, 27,
- 19, 11, 3, 60, 52, 44, 36,
-
- 63, 55, 47, 39, 31, 23, 15,
- 7, 62, 54, 46, 38, 30, 22,
- 14, 6, 61, 53, 45, 37, 29,
- 21, 13, 5, 28, 20, 12, 4
- );
-
- /**
- * Number left rotations of pc1.
- *
- * @var array
- */
- protected $_shifts = array(
- 1, 1, 2, 2, 2, 2, 2, 2,
- 1, 2, 2, 2, 2, 2, 2, 1
- );
-
- /**
- * Permuted Choice Table 2.
- *
- * @var array
- */
- protected $_pc2 = array(
- 14, 17, 11, 24, 1, 5,
- 3, 28, 15, 6, 21, 10,
- 23, 19, 12, 4, 26, 8,
- 16, 7, 27, 20, 13, 2,
- 41, 52, 31, 37, 47, 55,
- 30, 40, 51, 45, 33, 48,
- 44, 49, 39, 56, 34, 53,
- 46, 42, 50, 36, 29, 32
- );
-
- /**
- * Key Schedule.
- *
- * @var array
- */
- protected $_ks = array();
-
- /**
- * Set the key to be used for en/decryption.
- *
- * @param string $key The key to use.
- */
- public function setKey($key)
- {
- if (!is_null($key)) {
- $this->_ks = $this->_keySchedule($key);
- }
- }
-
- /**
- * Encrypt a block of data.
- *
- * @param string $block The data to encrypt.
- * @param string $key The key to use.
- *
- * @return string The encrypted output.
- */
- public function encryptBlock($block, $key = null)
- {
- $this->setKey($key);
-
- $block = $this->_initialPerm($block);
-
- $L = substr($block, 0, 4);
- $R = substr($block, 4, 4);
-
- for ($i = 1; $i <= 16; ++$i) {
- $R_prev = $R;
- $L_prev = $L;
-
- $L = $R;
- $R = $L_prev ^ $this->_f($R_prev, $i);
- }
-
- $block = $R . $L;
- $block = $this->_finalPerm($block);
-
- return $block;
- }
-
- /**
- * Decrypt a block of data.
- *
- * @param string $block The data to decrypt.
- * @param string $key The key to use.
- *
- * @return string The decrypted output.
- */
- public function decryptBlock($block, $key = null)
- {
- $block = $this->_initialPerm($block);
-
- $this->setKey($key);
-
- $L = substr($block, 0, 4);
- $R = substr($block, 4, 4);
-
- for ($i = 16; $i >= 1; --$i) {
- $R_prev = $R;
- $L_prev = $L;
-
- $L = $R_prev;
- $R = $L_prev ^ $this->_f($R_prev, $i);
- }
-
- $block = $R . $L;
- $block = $this->_finalPerm($block);
-
- return $block;
- }
-
- /**
- * Put an input string through an initial permutation
- *
- * @param string $input Input string.
- *
- * @return string Permutated string.
- */
- protected function _initialPerm($input)
- {
- // TODO: Some stylie bitwise thing instead.
-
- $input_bin = $output = $output_bin = '';
-
- for ($i = 0; $i < 8; ++$i) {
- $input_bin .= str_pad(decbin(ord($input[$i])), 8, '0', STR_PAD_LEFT);
- }
-
- foreach ($this->_ip as $offset) {
- $output_bin .= $input_bin[$offset - 1];
- }
-
- for ($i = 0; $i < 8; $i++) {
- $output .= chr(bindec(substr($output_bin, 8 * $i, 8)));
- }
-
- return $output;
- }
-
- /**
- * Put an input string through a final permutation.
- *
- * @param string $input Input string.
- *
- * @return string Permutated string.
- */
- protected function _finalPerm($input)
- {
- // TODO: Some stylie bitwise thing instead.
-
- $input_bin = $output = $output_bin = '';
-
- for ($i = 0; $i < 8; ++$i) {
- $input_bin .= str_pad(decbin(ord($input[$i])), 8, '0', STR_PAD_LEFT);
- }
-
- foreach ($this->_fp as $offset) {
- $output_bin .= $input_bin[$offset - 1];
- }
-
- for ($i = 0; $i < 8; ++$i) {
- $output .= chr(bindec(substr($output_bin, 8 * $i, 8)));
- }
-
- return $output;
- }
-
-
- /**
- * The permutation function.
- *
- * @param string $input Input string.
- * @param integer $round The round.
- *
- * @return string The output string.
- */
- protected function _f($input, $round)
- {
- // TODO: Some stylie bitwise thing instead.
- $key = $this->_ks[$round];
-
- $combined_bin = $expanded_bin = $input_bin = $output_bin = $output = '';
- $expanded = array();
-
- for ($i = 0; $i < 4; ++$i) {
- $input_bin .= str_pad(decbin(ord($input[$i])), 8, '0', STR_PAD_LEFT);
- }
-
- foreach ($this->_e as $offset) {
- $expanded_bin .= $input_bin[$offset - 1];
- }
-
- for ($i = 0; $i < 8; ++$i) {
- $expanded[$i] = bindec('00' . substr($expanded_bin, $i * 6, 6)) ^ $key[$i];
- }
-
- for ($i = 0; $i < 8; ++$i) {
- $s_index = (($expanded[$i] & 0x20) >> 4) | ($expanded[$i] & 0x01);
- $s_index = 16 * $s_index + (($expanded[$i] & 0x1E) >> 1);
- $val = $this->_s[$i + 1][$s_index];
- $combined_bin .= str_pad(decbin($val), 4, '0', STR_PAD_LEFT);
- }
-
- foreach ($this->_p as $offset) {
- $output_bin .= $combined_bin[$offset - 1];
- }
-
- for ($i = 0; $i < 4; ++$i) {
- $output .= chr(bindec(substr($output_bin, $i * 8, 8)));
- }
-
- return $output;
- }
-
- /**
- * Create the complete key schedule.
- *
- * @param string $key The key to use.
- *
- * @return array Key schedule.
- */
- protected function _keySchedule($key)
- {
- $key = str_pad($key, 8, "\0");
- $c = $d = $key_bin = '';
- $ks = array();
-
- for ($i = 0; $i < 8; ++$i) {
- $key_bin .= str_pad(decbin(ord($key[$i])), 8, '0', STR_PAD_LEFT);
- }
-
- for ($i = 0; $i < 28; ++$i) {
- $c .= $key_bin[$this->_pc1[$i] - 1];
- $d .= $key_bin[$this->_pc1[28 + $i] - 1];
- }
-
- for ($i = 0; $i < 16; ++$i) {
- $c = substr($c, $this->_shifts[$i]) . substr($c, 0, $this->_shifts[$i]);
- $d = substr($d, $this->_shifts[$i]) . substr($d, 0, $this->_shifts[$i]);
-
- $cd = $c . $d;
-
- $permutated_bin = '';
- foreach ($this->_pc2 as $offset) {
- $permutated_bin .= $cd[$offset - 1];
- }
-
- for ($j = 0; $j < 8; $j++) {
- $ks[$i + 1][] = bindec('00' . substr($permutated_bin, $j * 6, 6));
- }
- }
-
- return $ks;
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_Rc2:: class implements the Cipher interface encryption
- * data using the RC2 algorithm as described in RFC2268.
- *
- * Based on the notes by Peter Gutmann <pgut01@cs.auckland.ac.nz>
- * http://www.mirrors.wiretapped.net/security/cryptography/
- * algorithms/rc2/comments/gutman-960211
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_Rc2 extends Horde_Cipher
-{
- /**
- * Permutations array.
- *
- * @var array
- */
- protected $_perm = array(
- 0xD9, 0x78, 0xF9, 0xC4, 0x19, 0xDD, 0xB5, 0xED, 0x28, 0xE9, 0xFD,
- 0x79, 0x4A, 0xA0, 0xD8, 0x9D, 0xC6, 0x7E, 0x37, 0x83, 0x2B, 0x76,
- 0x53, 0x8E, 0x62, 0x4C, 0x64, 0x88, 0x44, 0x8B, 0xFB, 0xA2, 0x17,
- 0x9A, 0x59, 0xF5, 0x87, 0xB3, 0x4F, 0x13, 0x61, 0x45, 0x6D, 0x8D,
- 0x09, 0x81, 0x7D, 0x32, 0xBD, 0x8F, 0x40, 0xEB, 0x86, 0xB7, 0x7B,
- 0x0B, 0xF0, 0x95, 0x21, 0x22, 0x5C, 0x6B, 0x4E, 0x82, 0x54, 0xD6,
- 0x65, 0x93, 0xCE, 0x60, 0xB2, 0x1C, 0x73, 0x56, 0xC0, 0x14, 0xA7,
- 0x8C, 0xF1, 0xDC, 0x12, 0x75, 0xCA, 0x1F, 0x3B, 0xBE, 0xE4, 0xD1,
- 0x42, 0x3D, 0xD4, 0x30, 0xA3, 0x3C, 0xB6, 0x26, 0x6F, 0xBF, 0x0E,
- 0xDA, 0x46, 0x69, 0x07, 0x57, 0x27, 0xF2, 0x1D, 0x9B, 0xBC, 0x94,
- 0x43, 0x03, 0xF8, 0x11, 0xC7, 0xF6, 0x90, 0xEF, 0x3E, 0xE7, 0x06,
- 0xC3, 0xD5, 0x2F, 0xC8, 0x66, 0x1E, 0xD7, 0x08, 0xE8, 0xEA, 0xDE,
- 0x80, 0x52, 0xEE, 0xF7, 0x84, 0xAA, 0x72, 0xAC, 0x35, 0x4D, 0x6A,
- 0x2A, 0x96, 0x1A, 0xD2, 0x71, 0x5A, 0x15, 0x49, 0x74, 0x4B, 0x9F,
- 0xD0, 0x5E, 0x04, 0x18, 0xA4, 0xEC, 0xC2, 0xE0, 0x41, 0x6E, 0x0F,
- 0x51, 0xCB, 0xCC, 0x24, 0x91, 0xAF, 0x50, 0xA1, 0xF4, 0x70, 0x39,
- 0x99, 0x7C, 0x3A, 0x85, 0x23, 0xB8, 0xB4, 0x7A, 0xFC, 0x02, 0x36,
- 0x5B, 0x25, 0x55, 0x97, 0x31, 0x2D, 0x5D, 0xFA, 0x98, 0xE3, 0x8A,
- 0x92, 0xAE, 0x05, 0xDF, 0x29, 0x10, 0x67, 0x6C, 0xBA, 0xC9, 0xD3,
- 0x00, 0xE6, 0xCF, 0xE1, 0x9E, 0xA8, 0x2C, 0x63, 0x16, 0x01, 0x3F,
- 0x58, 0xE2, 0x89, 0xA9, 0x0D, 0x38, 0x34, 0x1B, 0xAB, 0x33, 0xFF,
- 0xB0, 0xBB, 0x48, 0x0C, 0x5F, 0xB9, 0xB1, 0xCD, 0x2E, 0xC5, 0xF3,
- 0xDB, 0x47, 0xE5, 0xA5, 0x9C, 0x77, 0x0A, 0xA6, 0x20, 0x68, 0xFE,
- 0x7F, 0xC1, 0xAD
- );
-
- /**
- * Array to hold the key schedule.
- *
- * @var array
- */
- protected $_keySchedule = array();
-
- /**
- * Set the key to be used for en/decryption.
- *
- * @param string $key The key to use.
- */
- public function setKey($key)
- {
- $key = array_values(unpack('C*', $key));
- $bits = 1024;
-
- /* Expand input key to 128 bytes */
- $len = count($key);
- $last = $key[$len - 1];
- for ($i = $len; $i < 128; ++$i) {
- $last = $this->_perm[($key[$i - $len] + $last) & 0xFF];
- $key[$i] = $last;
- }
-
- /* Phase 2 - reduce effective key size to "bits" */
- if ($len != 8) {
- $len = $len * 8;
- }
- $key[128 - $len] = $this->_perm[$key[128 - $len] & 0xFF];
- for ($i = 127 - $len; $i >= 0; --$i) {
- $key[$i] = $this->_perm[$key[$i + $len] ^ $key[$i + 1]];
- }
-
- /* Phase 3 - convert to 16 bit values */
- for ($i = 63; $i >= 0; --$i) {
- $this->_keySchedule[$i] = ($key[$i * 2 + 1] << 8 | $key[$i * 2]) & 0xFFFF;
- }
- }
-
- /**
- * Encrypt a block of data.
- *
- * @param string $block The data to encrypt.
- * @param string $key The key to use.
- *
- * @return string The encrypted output.
- */
- public function encryptBlock($block, $key = null)
- {
- if (!is_null($key)) {
- $this->setKey($key);
- }
-
- $plain = unpack('v*', $block);
-
- for ($i = 0; $i < 16; ++$i) {
- $plain[1] += ($plain[2] & ~$plain[4]) + ($plain[3] & $plain[4]) + $this->_keySchedule[4 * $i + 0];
- $bin = str_pad(decbin(0xFFFF & $plain[1]), 32, '0', STR_PAD_LEFT);
- $plain[1] = bindec($bin . substr($bin, 16, 1));
-
- $plain[2] += ($plain[3] & ~$plain[1]) + ($plain[4] & $plain[1]) + $this->_keySchedule[4 * $i + 1];
- $bin = str_pad(decbin(0xFFFF & $plain[2]), 32, '0', STR_PAD_LEFT);
- $plain[2] = bindec($bin . substr($bin, 16, 2));
-
- $plain[3] += ($plain[4] & ~$plain[2]) + ($plain[1] & $plain[2]) + $this->_keySchedule[4 * $i + 2];
- $bin = str_pad(decbin(0xFFFF & $plain[3]), 16, '0', STR_PAD_LEFT);
- $plain[3] = bindec($bin . substr($bin, 0, 3));
-
- $plain[4] += ($plain[1] & ~$plain[3]) + ($plain[2] & $plain[3]) + $this->_keySchedule[4 * $i + 3];
- $bin = str_pad(decbin(0xFFFF & $plain[4]), 16, '0', STR_PAD_LEFT);
- $plain[4] = bindec($bin . substr($bin, 0, 5));
-
- if ($i == 4 || $i == 10) {
- $plain[1] += $this->_keySchedule[$plain[4] & 0x3F];
- $plain[2] += $this->_keySchedule[$plain[1] & 0x3F];
- $plain[3] += $this->_keySchedule[$plain[2] & 0x3F];
- $plain[4] += $this->_keySchedule[$plain[3] & 0x3F];
- }
-
- }
-
- return pack("v*", $plain[1], $plain[2], $plain[3], $plain[4]);
- }
-
- /**
- * Decrypt a block of data.
- *
- * @param string $block The data to decrypt.
- * @param string $key The key to use.
- *
- * @return string The decrypted output.
- */
- public function decryptBlock($block, $key = null)
- {
- if (!is_null($key)) {
- $this->setKey($key);
- }
-
- $cipher = unpack('v*', $block);
-
- for ($i = 15; $i >= 0; --$i) {
- $bin = str_pad(decbin(0xFFFF & $cipher[4]), 16, '0', STR_PAD_LEFT);
- $cipher[4] = bindec(substr($bin, -21, 21) . substr($bin, 0, 11));
- $cipher[4] -= ($cipher[1] & ~$cipher[3]) + ($cipher[2] & $cipher[3]) + $this->_keySchedule[4 * $i + 3];
-
- $bin = str_pad(decbin(0xFFFF & $cipher[3]), 16, '0', STR_PAD_LEFT);
- $cipher[3] = bindec(substr($bin, -19, 19) . substr($bin, 0, 13));
- $cipher[3] -= ($cipher[4] & ~$cipher[2]) + ($cipher[1] & $cipher[2]) + $this->_keySchedule[4 * $i + 2];
-
- $bin = str_pad(decbin(0xFFFF & $cipher[2]), 16, '0', STR_PAD_LEFT);
- $cipher[2] = bindec(substr($bin, -18, 18) . substr($bin, 0, 14));
- $cipher[2] -= ($cipher[3] & ~$cipher[1]) + ($cipher[4] & $cipher[1]) + $this->_keySchedule[4 * $i + 1];
-
- $bin = str_pad(decbin(0xFFFF & $cipher[1]), 16, '0', STR_PAD_LEFT);
- $cipher[1] = bindec(substr($bin, -17, 17) . substr($bin, 0, 15));
- $cipher[1] -= ($cipher[2] & ~$cipher[4]) + ($cipher[3] & $cipher[4]) + $this->_keySchedule[4 * $i + 0];
-
- if ($i == 5 || $i == 11) {
- $cipher[4] -= $this->_keySchedule[$cipher[3] & 0x3F];
- $cipher[3] -= $this->_keySchedule[$cipher[2] & 0x3F];
- $cipher[2] -= $this->_keySchedule[$cipher[1] & 0x3F];
- $cipher[1] -= $this->_keySchedule[$cipher[4] & 0x3F];
- }
- }
-
- return pack("v*", $cipher[1], $cipher[2], $cipher[3], $cipher[4]);
- }
-
-}
+++ /dev/null
-<?php
-/**
- * The Horde_Cipher_Rc4:: class implements the Horde_Cipher interface
- * encryption data using the RC4 encryption algorthim. This class uses the
- * PEAR Crypt_RC4 class to do the encryption.
- *
- * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Mike Cochrane <mike@graftonhall.co.nz>
- * @package Horde_Cipher
- */
-class Horde_Cipher_Rc4 extends Horde_Cipher
-{
- /**
- * Pointer to a PEAR Crypt_RC4 object
- *
- * @var Crypt_RC4
- */
- protected $_cipher;
-
- /**
- * Constructor.
- */
- public function __construct($params = null)
- {
- $this->_cipher = new Crypt_Rc4();
- }
-
- /**
- * Set the key to be used for en/decryption.
- *
- * @param string $key The key to use.
- */
- public function setKey($key)
- {
- $this->_cipher->setKey($key);
- }
-
- /**
- * Encrypt a block of data.
- *
- * @param string $block The data to encrypt.
- * @param string $key The key to use.
- *
- * @return string The encrypted output.
- */
- public function encryptBlock($block, $key = null)
- {
- if (!is_null($key)) {
- $this->setKey($key);
- }
-
- // Make a copy of the cipher as it destroys itself during a crypt
- $cipher = $this->_cipher;
- $cipher->crypt($block);
-
- return $block;
- }
-
- /**
- * Decrypt a block of data.
- *
- * @param string $block The data to decrypt.
- * @param string $key The key to use.
- *
- * @return string The decrypted output.
- */
- public function decryptBlock($block, $key = null)
- {
- if (!is_null($key)) {
- $this->setKey($key);
- }
-
- // Make a copy of the cipher as it destroys itself during a
- // crypt.
- $cipher = $this->_cipher;
- $cipher->decrypt($block);
-
- return $block;
- }
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>Cipher</name>
- <channel>pear.horde.org</channel>
- <summary>Cipher API</summary>
- <description>This package provides a Block Mode Cipher API, supporting the following ciphers:
-* DES
-* RC2
-* RC4
-
-And supporting the following block modes:
-* CBC
-* ECB
-* CFB64
-* OFB64
- </description>
- <lead>
- <name>Chuck Hagenbuch</name>
- <user>chuck</user>
- <email>chuck@horde.org</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Jan Schneider</name>
- <user>jan</user>
- <email>jan@horde.org</email>
- <active>yes</active>
- </lead>
- <date>2009-07-05</date>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Removed Blowfish and Cast128 ciphers.
- * Initial Horde 4 Package.
- </notes>
- <contents>
- <dir name="/">
- <dir name="lib">
- <dir name="Horde">
- <dir name="Cipher">
- <dir name="BlockMode">
- <file name="Cbc.php" role="php" />
- <file name="Cfb64.php" role="php" />
- <file name="Ecb.php" role="php" />
- <file name="Ofb64.php" role="php" />
- </dir> <!-- /lib/Horde/Cipher/BlockMode -->
- <file name="BlockMode.php" role="php" />
- <file name="Des.php" role="php" />
- <file name="Rc2.php" role="php" />
- <file name="Rc4.php" role="php" />
- </dir> <!-- /lib/Horde/Cipher -->
- <file name="Cipher.php" role="php" />
- </dir> <!-- /lib/Horde -->
- </dir> <!-- /lib -->
- <dir name="test">
- <dir name="Horde">
- <dir name="Cipher">
- <file name="Cipher1.phpt" role="test" />
- <file name="Cipher2.phpt" role="test" />
- <file name="Cipher3.phpt" role="test" />
- <file name="Cipher4.phpt" role="test" />
- <file name="cipher_functions.php" role="php" />
- </dir> <!-- /test/Horde/Cipher -->
- </dir> <!-- /test/Horde -->
- </dir> <!-- /test -->
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>5.2.0</min>
- </php>
- <pearinstaller>
- <min>1.5.4</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease>
- <filelist>
- <install name="lib/Horde/Cipher/BlockMode/Cbc.php" as="Horde/Cipher/BlockMode/Cbc.php" />
- <install name="lib/Horde/Cipher/BlockMode/Cfb64.php" as="Horde/Cipher/BlockMode/Cfb64.php" />
- <install name="lib/Horde/Cipher/BlockMode/Ecb.php" as="Horde/Cipher/BlockMode/Ecb.php" />
- <install name="lib/Horde/Cipher/BlockMode/Ofb64.php" as="Horde/Cipher/BlockMode/Ofb64.php" />
- <install name="lib/Horde/Cipher/BlockMode.php" as="Horde/Cipher/BlockMode.php" />
- <install name="lib/Horde/Cipher/Des.php" as="Horde/Cipher/Des.php" />
- <install name="lib/Horde/Cipher/Rc2.php" as="Horde/Cipher/Rc2.php" />
- <install name="lib/Horde/Cipher/Rc4.php" as="Horde/Cipher/Rc4.php" />
- <install name="lib/Horde/Cipher.php" as="Horde/Cipher.php" />
- </filelist>
- </phprelease>
-</package>
+++ /dev/null
---TEST--
-RC4 Horde_Cipher:: Tests
---SKIPIF--
-<?php
- $rc4 = @include_once 'Crypt/Rc4.php';
- if (!$rc4) echo 'skip Crypt_Rc4 pear module not available';
-?>
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/cipher_functions.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher/Rc4.php';
-
-/* RC4 Cipher */
-echo "RC4:\n";
-echo "----\n\n";
-
-// 64 Bit key test
-echo "64-bit Key\n";
-$key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
-$plaintext = "\x01\x23\x45\x67\x89\xab\xcd\xef";
-$ciphertext = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
-testCipher('rc4', $key, $plaintext, $ciphertext);
-
-// 64 Bit key test
-echo "64-bit Key\n";
-$key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
-testCipher('rc4', $key, $plaintext, $ciphertext);
-
-// 64 Bit key test
-echo "64-bit Key\n";
-$key = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
-testCipher('rc4', $key, $plaintext, $ciphertext);
-
-// 32 Bit key test
-echo "32-bit Key\n";
-$key = "\xef\x01\x23\x45";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf";
-testCipher('rc4', $key, $plaintext, $ciphertext);
-
-?>
---EXPECT--
-RC4:
-----
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-32-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
+++ /dev/null
---TEST--
-DES Horde_Cipher:: Tests
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/cipher_functions.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher/Des.php';
-
-/* DES Cipher */
-echo "DES:\n";
-echo "----\n\n";
-
-// 64 Bit key test
-$tests = array(
- "\x00\x00\x00\x00\x00\x00\x00\x00", "\x00\x00\x00\x00\x00\x00\x00\x00", "\x8C\xA6\x4D\xE9\xC1\xB1\x23\xA7",
- "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "\x73\x59\xB2\x16\x3E\x4E\xDC\x58",
- "\x30\x00\x00\x00\x00\x00\x00\x00", "\x10\x00\x00\x00\x00\x00\x00\x01", "\x95\x8E\x6E\x62\x7A\x05\x55\x7B",
- "\x01\x23\x45\x67\x89\xAB\xCD\xEF", "\x11\x11\x11\x11\x11\x11\x11\x11", "\x17\x66\x8D\xFC\x72\x92\x53\x2D",
- "\x11\x11\x11\x11\x11\x11\x11\x11", "\x01\x23\x45\x67\x89\xAB\xCD\xEF", "\x8A\x5A\xE1\xF8\x1A\xB8\xF2\xDD",
-
- // Initial Permutation and Expansion test
- "\x01\x01\x01\x01\x01\x01\x01\x01", "\x95\xF8\xA5\xE5\xDD\x31\xD9\x00", "\x80\x00\x00\x00\x00\x00\x00\x00",
-
- // Key Permutation test
- "\x80\x01\x01\x01\x01\x01\x01\x01", "\x00\x00\x00\x00\x00\x00\x00\x00", "\x95\xA8\xD7\x28\x13\xDA\xA9\x4D",
-
- // Data Permutation tests
- "\x10\x46\x91\x34\x89\x98\x01\x31", "\x00\x00\x00\x00\x00\x00\x00\x00", "\x88\xD5\x5E\x54\xF5\x4C\x97\xB4",
-
- // S-Box test
- "\x7C\xA1\x10\x45\x4A\x1A\x6E\x57", "\x01\xA1\xD6\xD0\x39\x77\x67\x42", "\x69\x0F\x5B\x0D\x9A\x26\x93\x9B",
- "\x01\x31\xD9\x61\x9D\xC1\x37\x6E", "\x5C\xD5\x4C\xA8\x3D\xEF\x57\xDA", "\x7A\x38\x9D\x10\x35\x4B\xD2\x71",
- );
-
-for ($i = 0; $i < count($tests); $i+= 3) {
- echo "64-bit Key\n";
- $key = $tests[$i];
- $plaintext = $tests[$i + 1];
- $ciphertext = $tests[$i + 2];
- testCipher('des', $key, $plaintext, $ciphertext);
-}
-
-?>
---EXPECT--
-DES:
-----
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
+++ /dev/null
---TEST--
-RC2 Horde_Cipher:: Tests
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/cipher_functions.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher/Rc2.php';
-
-/* RC2 Cipher */
-echo "RC2:\n";
-echo "----\n\n";
-
-// 8 Bit key test
-echo "8-bit Key\n";
-$key = "\x88";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
-testCipher('rc2', $key, $plaintext, $ciphertext);
-
-// 64 Bit key test
-echo "64-bit Key\n";
-$key = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
-testCipher('rc2', $key, $plaintext, $ciphertext);
-
-// 128 Bit key test
-echo "128-bit Key\n";
-$key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
-$plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
-$ciphertext = "\x50\xDC\x01\x62\xBD\x75\x7F\x31";
-testCipher('rc2', $key, $plaintext, $ciphertext);
-
-// 64 Bit key test
-echo "64-bit Key\n";
-$key = "\xff\xff\xff\xff\xff\xff\xff\xff";
-$plaintext = "\xff\xff\xff\xff\xff\xff\xff\xff";
-$ciphertext = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
-testCipher('rc2', $key, $plaintext, $ciphertext);
-
-?>
---EXPECT--
-RC2:
-----
-
-8-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-128-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-64-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
+++ /dev/null
---TEST--
-Cast128 Horde_Cipher:: Tests
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/cipher_functions.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher.php';
-require_once dirname(__FILE__) . '/../../../lib/Horde/Cipher/Cast128.php';
-
-/* Cast 128 Cipher */
-echo "Cast 128:\n";
-echo "---------\n\n";
-
-// 128 Bit key test
-echo "128-bit Key\n";
-$key = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45\x67\x89\x34\x56\x78\x9A";
-$plaintext = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
-$ciphertext = "\x23\x8B\x4F\xE5\x84\x7E\x44\xB2";
-testCipher('cast128', $key, $plaintext, $ciphertext);
-
-// 80 Bit key text
-echo "80-bit Key\n";
-$key = "\x01\x23\x45\x67\x12\x34\x56\x78\x23\x45";
-$plaintext = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
-$ciphertext = "\xEB\x6A\x71\x1A\x2C\x02\x27\x1B";
-testCipher('cast128', $key, $plaintext, $ciphertext);
-
-// 40 Bit key text
-echo "40-bit Key\n";
-$key = "\x01\x23\x45\x67\x12";
-$plaintext = "\x01\x23\x45\x67\x89\xAB\xCD\xEF";
-$ciphertext = "\x7A\xC8\x16\xD1\x6E\x9B\x30\x2E";
-testCipher('cast128', $key, $plaintext, $ciphertext);
-
-?>
---EXPECT--
-Cast 128:
----------
-
-128-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-80-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
-
-40-bit Key
-Testing Encryption: Pass
-Testing Decryption: Pass
+++ /dev/null
-<?php
-/**
- * This script contains functions used for the cipher tests.
- *
- * @package Horde_Cipher
- */
-
-require_once 'Horde/String.php';
-
-function testCipher($cipher, $key, $plaintext, $ciphertext)
-{
- $cipher = &Horde_Cipher::factory($cipher);
- $cipher->setKey($key);
-
- echo "Testing Encryption: ";
- $res = $cipher->encryptBlock($plaintext);
- if ($res == $ciphertext) {
- echo "Pass\n";
- } else {
- echo "Fail\n";
- echo "Returned: ";
- for ($i = 0; $i < strlen($res); $i++) {
- echo str_pad(dechex(ord(substr($res, $i, 1))), 2, '0', STR_PAD_LEFT) . " ";
- } echo "\n";
- echo "Expected: ";
- for ($i = 0; $i < strlen($ciphertext); $i++) {
- echo str_pad(dechex(ord(substr($ciphertext, $i, 1))), 2, '0', STR_PAD_LEFT) . " ";
- } echo "\n";
-
- }
- echo "Testing Decryption: ";
- $res = $cipher->decryptBlock($ciphertext);
- if ($res == $plaintext) {
- echo "Pass\n";
- } else {
- echo "Fail\n";
- echo "Returned: ";
- for ($i = 0; $i < strlen($res); $i++) {
- echo str_pad(dechex(ord(substr($res, $i, 1))), 2, '0', STR_PAD_LEFT) . " ";
- } echo "\n";
- echo "Expected: ";
- for ($i = 0; $i < strlen($plaintext); $i++) {
- echo str_pad(dechex(ord(substr($plaintext, $i, 1))), 2, '0', STR_PAD_LEFT) . " ";
- } echo "\n";
- }
- echo "\n";
- flush();
-}
--- /dev/null
+<?php
+class Horde_Core_Binder_Secret implements Horde_Injector_Binder
+{
+ public function create(Horde_Injector $injector)
+ {
+ global $conf;
+
+ return new Horde_Secret(array(
+ 'cookie_domain' => $conf['cookie']['domain'],
+ 'cookie_expire' => $conf['session']['timeout'],
+ 'cookie_path' => $conf['cookie']['path'],
+ 'cookie_ssl' => (bool) $conf['use_ssl'],
+ 'session_name' => $conf['session']['name']
+ ));
+ }
+
+ public function equals(Horde_Injector_Binder $binder)
+ {
+ return false;
+ }
+}
'Horde_Memcache' => new Horde_Core_Binder_Memcache(),
'Horde_Notification' => new Horde_Core_Binder_Notification(),
'Horde_Perms' => new Horde_Core_Binder_Perms(),
+ 'Horde_Secret' => new Horde_Core_Binder_Secret(),
'Horde_Template' => new Horde_Core_Binder_Template(),
'Horde_Token' => new Horde_Core_Binder_Token(),
'Horde_Vfs' => new Horde_Core_Binder_Vfs(),
/* Reset cookie timeouts, if necessary. */
if (!empty($GLOBALS['conf']['session']['timeout'])) {
$app = $this->getApp();
- if (Horde_Secret::clearKey($app)) {
- Horde_Secret::setKey($app);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ if ($secret->clearKey($app)) {
+ $secret->setKey($app);
}
- Horde_Secret::setKey('auth');
+ $secret->setKey('auth');
}
}
<file name="Memcache.php" role="php" />
<file name="Notification.php" role="php" />
<file name="Perms.php" role="php" />
+ <file name="Secret.php" role="php" />
<file name="Template.php" role="php" />
<file name="Token.php" role="php" />
<file name="Vfs.php" role="php" />
<install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
<install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
<install name="lib/Horde/Core/Binder/Perms.php" as="Horde/Core/Binder/Perms.php" />
+ <install name="lib/Horde/Core/Binder/Secret.php" as="Horde/Core/Binder/Secret.php" />
<install name="lib/Horde/Core/Binder/Template.php" as="Horde/Core/Binder/Template.php" />
<install name="lib/Horde/Core/Binder/Token.php" as="Horde/Core/Binder/Token.php" />
<install name="lib/Horde/Core/Binder/Vfs.php" as="Horde/Core/Binder/Vfs.php" />
if (!isset($this->_params['_passencrypt'])) {
$key = Horde_Imap_Client::$encryptKey;
if (!is_null($key)) {
- $this->_params['_passencrypt'] = Horde_Secret::write($key, $this->_params['password']);
+ $secret = new Horde_Secret();
+ $this->_params['_passencrypt'] = $secret->write($key, $this->_params['password']);
$this->_params['password'] = null;
}
}
{
if (isset($this->_params['_passencrypt']) &&
!is_null(Horde_Imap_Client::$encryptKey)) {
- $this->_params['password'] = Horde_Secret::read(Horde_Imap_Client::$encryptKey, $this->_params['_passencrypt']);
+ $secret = new Horde_Secret();
+ $this->_params['password'] = $secret->read(Horde_Imap_Client::$encryptKey, $this->_params['_passencrypt']);
}
if (!empty($this->_params['debug'])) {
OUT_LOG | EX_UNAVAILABLE);
}
@session_start();
+
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+
$_SESSION['__auth'] = array(
'authenticated' => true,
'userId' => $calendar_user,
'timestamp' => time(),
- 'credentials' => Horde_Secret::write(Horde_Secret::getKey('auth'),
- serialize(array('password' => $conf['kolab']['filter']['calendar_pass']))),
+ 'credentials' => $secret->write($secret->getKey('auth'),
+ serialize(array('password' => $conf['kolab']['filter']['calendar_pass']))),
'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null,
);
* The Horde_Secret:: class provides an API for encrypting and decrypting
* small pieces of data with the use of a shared key.
*
- * The Horde_Secret:: functions use the Horde_Cipher:: class if mcrypt is not
- * available.
- *
* Copyright 1999-2010 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Secret
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Horde_Secret
*/
class Horde_Secret
{
/**
+ * Configuration parameters.
+ *
+ * @var array
+ */
+ protected $_params = array(
+ 'cookie_domain' => '',
+ 'cookie_expire' => 0,
+ 'cookie_path' => '',
+ 'cookie_ssl' => false,
+ 'session_name' => 'horde_secret'
+ );
+
+ /**
* Cipher cache.
*
* @var array
*/
- static protected $_cipherCache = array();
+ protected $_cipherCache = array();
/**
* Key cache.
*
* @var array
*/
- static protected $_keyCache = array();
+ protected $_keyCache = array();
+
+ /**
+ * Constructor.
+ *
+ * @param array $params Configuration parameters:
+ * <pre>
+ * 'cookie_domain' - (string) The cookie domain.
+ * 'cookie_expire' - (integer) The cookie expiration time (in seconds).
+ * 'cookie_path' - (string) The cookie path.
+ * 'cookie_ssl' - (boolean) Only transmit cookie securely?
+ * 'session_name' - (string) The cookie session name.
+ * </pre>
+ */
+ public function __construct($params = array())
+ {
+ $this->_params = array_merge($this->_params, $params);
+ }
/**
* Take a small piece of data and encrypt it with a key.
* @param string $message The plaintext message.
*
* @return string The ciphertext message.
+ * @throws Horde_Secret_Exception
*/
- static public function write($key, $message)
+ public function write($key, $message)
{
- if (!strlen($key)) {
- return false;
- }
+ $val = strlen($key)
+ ? $this->_getCipherOb($key)->encrypt($message)
+ : false;
- $ret = self::_getMcryptData($key, $message, 'encrypt');
- if ($ret !== false) {
- return $ret;
+ if ($val instanceof PEAR_Error) {
+ throw new Horde_Secret_Exception($val);
}
- $ptr = self::_getCipherOb($key);
- return $ptr->encrypt($message);
+ return $val;
}
/**
* @param string $message The ciphertext message.
*
* @return string The plaintext message.
+ * @throws Horde_Secret_Exception
*/
- static public function read($key, $ciphertext)
+ public function read($key, $ciphertext)
{
- $ret = self::_getMcryptData($key, $ciphertext, 'decrypt');
- if ($ret !== false) {
- return rtrim($ret, "\0");
- }
-
- $ptr = self::_getCipherOb($key);
- return $ptr->decrypt($ciphertext);
- }
+ $val = $this->_getCipherOb($key)->decrypt($ciphertext);
- /**
- * TODO
- */
- static protected function _getMcryptData($key, $text, $type)
- {
- $ret = false;
-
- if (Horde_Util::extensionExists('mcrypt')) {
- $old_error = error_reporting(0);
- $td = mcrypt_module_open(MCRYPT_GOST, '', MCRYPT_MODE_ECB, '');
- if ($td) {
- $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
- mcrypt_generic_init($td, $key, $iv);
- $ret = ($type == 'encrypt') ? mcrypt_generic($td, $text) : mdecrypt_generic($td, $text);
- mcrypt_generic_deinit($td);
- }
- error_reporting($old_error);
+ if ($val instanceof PEAR_Error) {
+ throw new Horde_Secret_Exception($val);
}
- return $ret;
+ return $val;
}
/**
- * TODO
+ * Returns the cached crypt object.
+ *
+ * @param string $key The key to use for [de|en]cryption.
+ *
+ * @return Crypt_Blowfish The crypt object.
+ * @throws Horde_Secret_Exception
*/
- static protected function _getCipherOb($key)
+ protected function _getCipherOb($key)
{
$idx = hash('md5', $key);
- if (!isset(self::$_cipherCache[$idx])) {
- self::$_cipherCache[$idx] = Horde_Cipher::factory('rc2');
- self::$_cipherCache[$idx]->setKey($key);
+ if (!isset($this->_cipherCache[$idx])) {
+ if (!class_exists('Crypt_Blowfish')) {
+ throw new Horde_Secret_Exception('Crypt_Blowfish library not found.');
+ }
+ $this->_cipherCache[$idx] = new Crypt_Blowfish($key);
}
- return self::$_cipherCache[$idx];
+ return $this->_cipherCache[$idx];
}
/**
*
* @return string The secret key that has been generated.
*/
- static public function setKey($keyname = 'generic')
+ public function setKey($keyname = 'generic')
{
- if (isset($_COOKIE[$GLOBALS['conf']['session']['name']])) {
+ $set = true;
+
+ if (isset($_COOKIE[$this->_params['session_name']])) {
if (isset($_COOKIE[$keyname . '_key'])) {
$key = $_COOKIE[$keyname . '_key'];
+ $set = false;
} else {
- $key = hash('md5', mt_rand());
- $_COOKIE[$keyname . '_key'] = $key;
- self::_setCookie($keyname, $key);
+ $key = $_COOKIE[$keyname . '_key'] = hash('md5', uniqid());
}
} else {
$key = session_id();
- self::_setCookie($keyname, $key);
+ }
+
+ if ($set) {
+ $this->_setCookie($keyname, $key);
}
return $key;
*
* @return string The secret key.
*/
- static public function getKey($keyname = 'generic')
+ public function getKey($keyname = 'generic')
{
- if (!isset(self::$_keyCache[$keyname])) {
+ if (!isset($this->_keyCache[$keyname])) {
if (isset($_COOKIE[$keyname . '_key'])) {
- self::$_keyCache[$keyname] = $_COOKIE[$keyname . '_key'];
+ $key = $_COOKIE[$keyname . '_key'];
} else {
- self::$_keyCache[$keyname] = session_id();
- self::_setCookie($keyname, self::$_keyCache[$keyname]);
+ $key = session_id();
+ $this->_setCookie($keyname, $key);
}
- }
- return self::$_keyCache[$keyname];
- }
-
- /**
- * TODO
- */
- static protected function _setCookie($keyname, $key)
- {
- global $conf;
+ $this->_keyCache[$keyname] = $key;
+ }
- $old_error = error_reporting(0);
- setcookie(
- $keyname . '_key',
- $key,
- $conf['session']['timeout'] ? time() + $conf['session']['timeout'] : 0,
- $conf['cookie']['path'],
- $conf['cookie']['domain'],
- $conf['use_ssl'] == 1 ? 1 : 0
- );
- error_reporting($old_error);
+ return $this->_keyCache[$keyname];
}
/**
*
* @return boolean True if key existed, false if not.
*/
- static public function clearKey($keyname = 'generic')
+ public function clearKey($keyname = 'generic')
{
- if (isset($_COOKIE[$GLOBALS['conf']['session']['name']]) &&
+ if (isset($_COOKIE[$this->_params['session_name']]) &&
isset($_COOKIE[$keyname . '_key'])) {
unset($_COOKIE[$keyname . '_key']);
return true;
}
+
return false;
}
+ /**
+ * Sets the cookie with the given keyname/key.
+ *
+ * @param string $keyname The name of the key to set.
+ * @param string $key The key to use for encryption.
+ */
+ protected function _setCookie($keyname, $key)
+ {
+ @setcookie(
+ $keyname . '_key',
+ $key,
+ (empty($this->_params['cookie_expire']) ? 0 : (time() + $this->_params['cookie_expire'])),
+ $this->_params['cookie_path'],
+ $this->_params['cookie_domain'],
+ $this->_params['cookie_ssl']
+ );
+ }
+
}
--- /dev/null
+<?php
+/**
+ * Exception handler for the Horde_Secret library.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Horde_Secret
+ */
+class Horde_Secret_Exception extends Horde_Exception_Prior
+{
+}
<name>Secret</name>
<channel>pear.horde.org</channel>
<summary>Secret Encryption API</summary>
- <description>The Horde_Secret:: class provides an API for encrypting and decrypting small pieces of data with the use of a shared key.
+ <description>The Horde_Secret:: package provides an API for encrypting and decrypting small pieces of data with the use of a shared key.
</description>
<lead>
<name>Chuck Hagenbuch</name>
<email>chuck@horde.org</email>
<active>yes</active>
</lead>
- <date>2008-12-11</date>
+ <lead>
+ <name>Michael Slusarz</name>
+ <user>slusarz</user>
+ <email>slusarz@horde.org</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-03-19</date>
<version>
- <release>0.0.3</release>
- <api>0.0.2</api>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
</version>
<stability>
- <release>alpha</release>
- <api>alpha</api>
+ <release>beta</release>
+ <api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Initial Horde 4 package.</notes>
+ <notes>* Remove dependency on Horde_Core.
+ * Throw exceptions on error.
+ * Convert to OO-interface.
+ * Use PEAR's Crypt_Blowfish to encrypt data.
+ </notes>
<contents>
<dir name="/">
<dir name="lib">
<dir name="Horde">
+ <dir name="Secret">
+ <file name="Exception.php" role="php" />
+ </dir> <!-- /lib/Horde/Secret -->
<file name="Secret.php" role="php" />
</dir> <!-- /lib/Horde -->
</dir> <!-- /lib -->
<min>5.2.0</min>
</php>
<pearinstaller>
- <min>1.5.0</min>
+ <min>1.7.0</min>
</pearinstaller>
<package>
- <name>Horde_Cipher</name>
- <channel>pear.horde.org</channel>
+ <name>Crypt_Blowfish</name>
+ <channel>pear.php.net</channel>
+ <min>1.0.1</min>
</package>
<package>
- <name>Util</name>
+ <name>Exception</name>
<channel>pear.horde.org</channel>
</package>
</required>
- <optional>
- <extension>
- <name>mcrypt</name>
- </extension>
- </optional>
</dependencies>
<phprelease>
<filelist>
+ <install name="lib/Horde/Secret/Exception.php" as="Horde/Secret/Exception.php" />
<install name="lib/Horde/Secret.php" as="Horde/Secret.php" />
</filelist>
</phprelease>
<changelog>
<release>
+ <date>2008-12-11</date>
+ <version>
+ <release>0.0.3</release>
+ <api>0.0.2</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Initial Horde 4 package.</notes>
+ </release>
+ <release>
<date>2006-05-08</date>
<time>23:10:28</time>
<version>
--- /dev/null
+<?php
+/**
+ * All tests for the Horde_Secret package.
+ *
+ * @category Horde
+ * @package Secret
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Secret
+ */
+
+/**
+ * Define the main method
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'Horde_Secret_AllTests::main');
+}
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Horde/Test/AllTests.php';
+
+/**
+ * @package Secret
+ * @subpackage UnitTests
+ */
+class Horde_Secret_AllTests extends Horde_Test_AllTests
+{
+}
+
+Horde_Secret_AllTests::init('Horde_Secret', __FILE__);
+
+if (PHPUnit_MAIN_METHOD == 'Horde_Secret_AllTests::main') {
+ Horde_Secret_AllTests::main();
+}
--- /dev/null
+<?php
+/**
+ * Setup autoloading for the tests.
+ *
+ * @category Horde
+ * @package Secret
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Secret
+ */
+
+if (!spl_autoload_functions()) {
+ spl_autoload_register(
+ create_function(
+ '$class',
+ '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);'
+ . '$err_mask = E_ALL ^ E_WARNING;'
+ . '$oldErrorReporting = error_reporting($err_mask);'
+ . 'include "$filename.php";'
+ . 'error_reporting($oldErrorReporting);'
+ )
+ );
+}
+
+/** Catch strict standards */
+error_reporting(E_ALL | E_STRICT);
+
+/** Needed for PEAR_Error. */
+@require_once 'PEAR.php';
--- /dev/null
+<?php
+/**
+ * Test the secret class.
+ *
+ * @category Horde
+ * @package Secret
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Secret
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the secret class.
+ *
+ * Copyright 2009-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Secret
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Secret
+ */
+
+class Horde_Secret_Class_SecretTest extends PHPUnit_Framework_TestCase
+{
+ public function test8BitKey()
+ {
+ $secret = new Horde_Secret();
+
+ $key = "\x88";
+ $plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
+
+ $this->assertEquals($plaintext, $secret->read($key, $secret->write($key, $plaintext)));
+ }
+
+ public function test64BitKey()
+ {
+ $secret = new Horde_Secret();
+
+ $key = "\x00\x00\x00\x00\x00\x00\x00\x00";
+ $plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
+
+ $this->assertEquals($plaintext, $secret->read($key, $secret->write($key, $plaintext)));
+ }
+
+ public function test128BitKey()
+ {
+ $secret = new Horde_Secret();
+
+ $key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
+ $plaintext = "\x00\x00\x00\x00\x00\x00\x00\x00";
+
+ $this->assertEquals($plaintext, $secret->read($key, $secret->write($key, $plaintext)));
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit>
+ <filter>
+ <whitelist>
+ <directory suffix=".php">../../../lib</directory>
+ </whitelist>
+ </filter>
+</phpunit>
if (empty($credentials) &&
!empty($GLOBALS['gollem_be']['params']['password'])) {
- $credentials = array('password' => Horde_Secret::read(Horde_Secret::getKey('gollem'), $GLOBALS['gollem_be']['params']['password']));
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $credentials = array('password' => $secret->read($secret->getKey('gollem'), $GLOBALS['gollem_be']['params']['password']));
}
$login = ($login && (Horde_Auth::getProvider() == 'gollem'));
if ($pass === null) {
$ptr['params']['password'] = null;
} else {
- $ptr['params']['password'] = Horde_Secret::write(Horde_Secret::getKey('gollem'), $pass);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $ptr['params']['password'] = $secret->write($secret->getKey('gollem'), $pass);
}
/* Try to authenticate with the given information. */
if (!count($params)) {
$params = $be_config['params'];
if (!empty($params['password'])) {
- $params['password'] = Horde_Secret::read(Horde_Secret::getKey('gollem'), $params['password']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $params['password'] = $secret->read($secret->getKey('gollem'), $params['password']);
}
}
3. Install PEAR packages::
- pear install -o Mail DB Date File
- pear -d preferred_state=beta install -a Services_Weather
+ pear install -o Crypt_Blowfish Date DB File Mail Net_DNS \
+ Services_Weather
+ pear -d preferred_state=beta install -a HTTP_WebDAV_Server
4. Extract tarball::
c. Mcrypt support ``--with-mcrypt``
Mcrypt is a general-purpose cryptography library which is broader and
- significantly more efficient (FASTER!) than PHP's own cryptographic
- code. You can obtain mcrypt from
+ more efficient (FASTER!) than the default encryption method. You can
+ obtain mcrypt from
http://mcrypt.sourceforge.net/
Building PHP without mcrypt support will not stop Horde from working,
- but will force it to use weaker (and much slower) encryption.
+ but will force it to use slower encryption.
d. UTF-8 support ``--enable-mbstring``
You will see something like::
- PEAR directory php_dir /usr/share/php
+ PEAR directory php_dir /usr/share/php
Now open the php.ini file of your system, for example ``/etc/php.ini``,
find the ``include_path`` and make sure that ``/usr/share/php`` is part of
These PEAR modules are **REQUIRED** to be installed for complete Horde
functionality:
- a. Mail (>= 1.2.0)
+ a. Crypt_Blowfish (>= 1.0.1)
To install, enter the following at the command prompt::
- pear install Mail
-
- These PEAR modules are **RECOMMENDED** to be installed:
+ pear install Crypt_Blowfish
- a. DB (>= 1.7.8)
+ b. Mail (>= 1.2.0)
- **REQUIRED** as soon as you want or need to store anything in a database.
To install, enter the following at the command prompt::
- pear install DB
-
- b. File
-
- **REQUIRED** only if you wish to import CSV files.
- To install, enter the following at the command prompt::
+ pear install Mail
- pear install File
+ These PEAR modules are **RECOMMENDED** to be installed:
- c. Date
+ a. Date
**REQUIRED** only if you are dealing with calendar data.
To install, enter the following at the command prompt::
pear install Date
- d. Services_Weather (>= 1.3.1)
+ b. DB (>= 1.7.8)
- **REQUIRED** only if you wish to use the weather.com block on the portal
- page.
+ **REQUIRED** as soon as you want or need to store anything in a database.
To install, enter the following at the command prompt::
- pear install Services_Weather
+ pear install DB
- Additional steps are required if you want use the METAR weather block on
- the portal page. See the file ``data/Services_Weather/buildMetarDB.php``
- in your PEAR directory for details.
+ c. File
- e. HTTP_WebDAV_Server
+ **REQUIRED** only if you wish to import CSV files.
+ To install, enter the following at the command prompt::
+
+ pear install File
+
+ d. HTTP_WebDAV_Server
**REQUIRED** only if you want to use Horde's WebDAV interface, for
example to access calendars, tasklists or files with an external client.
pear install HTTP_WebDAV_Server-beta
- f. Net_DNS
+ e. Net_DNS
If installed, it will be used instead of the built-in PHP function
gethostbyaddr() for host name lookups. This has the advantage that
pear install Net_DNS
- This method of installing PEAR modules requires that you have a PHP version
- that has been compiled as a static binary. All versions of PHP 4.3.0+
- build both a SAPI module (Apache, CGI, etc.) and a command-line (CLI)
- binary at the same time. Check if you have a php binary in
- ``/usr/local/bin`` (``/usr/bin`` if if you installed from an operating
- system package) before recompiling.
+ f. Services_Weather (>= 1.3.1)
- If you receive the error ``Could not read cmd args`` you should run the pear
- script this way::
+ **REQUIRED** only if you wish to use the weather.com block on the portal
+ page.
+ To install, enter the following at the command prompt::
+
+ pear install Services_Weather
- php -d register_argc_argv=1 _PEAR_ install _MODULE_
+ Additional steps are required if you want use the METAR weather block on
+ the portal page. See the file ``data/Services_Weather/buildMetarDB.php``
+ in your PEAR directory for details.
- _PEAR_ is the complete path of the pear script installed by PHP during
- installation (e.g. ``/usr/local/bin/pear``). Make sure the ``pear`` script
- appears in your path. The default installation path for pear is
- ``/usr/local/bin/pear``.
- _MODULE_ is the PEAR module, listed above, which you wish to install.
+ This method of installing PEAR modules requires that you have a PHP version
+ that has been compiled as a static binary. All versions of PHP build both
+ both a SAPI module (Apache, CGI, etc.) and a command-line (CLI) binary.
+ Check if you have a php binary in ``/usr/local/bin`` (``/usr/bin`` if you
+ installed from an operating system package) before recompiling.
For more detailed directions on installing PEAR modules, see the PEAR
documentation at http://pear.php.net/manual/
'Cache' => array(
'error' => 'Cache is used by the Services_Weather module on the weather applet/block on the portal page.'
),
+ 'Crypt_Blowfish' => array(
+ 'error' => 'Crypt_Blowfish is required to store authentication credentials securely within the session data.'
+ ),
'Date' => array(
'path' => 'Date/Calc.php',
'error' => 'Horde requires the Date_Calc class for Kronolith to calculate dates.'
/* Initialize the Auth credentials key. */
if (!$is_auth) {
- Horde_Secret::setKey('auth');
+ $GLOBALS['injector']->getInstance('Horde_Secret')->setKey('auth');
}
/* Get an Auth object. */
$params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
if (isset($params['admin_password'])) {
- $params['admin_password'] = Horde_Secret::read(Horde_Secret::getKey('imp'), $params['admin_password']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
}
$auth = Horde_Auth::singleton('imap', $params);
$auth->addUser($userId, $credentials);
$params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
if (isset($params['admin_password'])) {
- $params['admin_password'] = Horde_Secret::read(Horde_Secret::getKey('imp'), $params['admin_password']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
}
$auth = Horde_Auth::singleton('imap', $params);
$auth->removeUser($userId);
$params = array_merge($params, $_SESSION['imp']['imap']['admin']['params']);
if (isset($params['admin_password'])) {
- $params['admin_password'] = Horde_Secret::read(Horde_Secret::getKey('imp'), $params['admin_password']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $params['admin_password'] = $secret->read($secret->getKey('imp'), $params['admin_password']);
}
$auth = Horde_Auth::singleton('imap', $params);
return $auth->listUsers();
* these entries in the session if they exist. */
foreach (array('password', 'admin_password') as $key) {
if (isset($ptr[$val]['params'][$key])) {
- $sess['imap'][$val]['params'][$key] = Horde_Secret::write(Horde_Secret::getKey('imp'), $ptr[$val]['params'][$key]);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $sess['imap'][$val]['params'][$key] = $secret->write($secret->getKey('imp'), $ptr[$val]['params'][$key]);
}
}
}
$id = 'personal';
}
- return isset($_SESSION['imp']['cache']['pgp'][$type][$id])
- ? Horde_Secret::read(Horde_Secret::getKey('imp'), $_SESSION['imp']['cache']['pgp'][$type][$id])
- : null;
+ if (!isset($_SESSION['imp']['cache']['pgp'][$type][$id])) {
+ return null;
+ }
+
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ return $secret->read($secret->getKey('imp'), $_SESSION['imp']['cache']['pgp'][$type][$id]);
}
/**
$id = 'personal';
}
- $_SESSION['imp']['cache']['pgp'][$type][$id] = Horde_Secret::write(Horde_Secret::getKey('imp'), $passphrase);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $_SESSION['imp']['cache']['pgp'][$type][$id] = $secret->write($secret->getKey('imp'), $passphrase);
return true;
}
}
if (isset($_SESSION['imp']['smime']['passphrase'])) {
- return Horde_Secret::read(Horde_Secret::getKey('imp'), $_SESSION['imp']['smime']['passphrase']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ return $secret->read($secret->getKey('imp'), $_SESSION['imp']['smime']['passphrase']);
} elseif (isset($_SESSION['imp']['smime']['null_passphrase'])) {
return ($_SESSION['imp']['smime']['null_passphrase']) ? null : false;
} else {
if (!isset($_SESSION['imp']['smime'])) {
$_SESSION['imp']['smime'] = array();
}
- $_SESSION['imp']['smime']['passphrase'] = Horde_Secret::write(Horde_Secret::getKey('imp'), $passphrase);
+
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $_SESSION['imp']['smime']['passphrase'] = $secret->write($secret->getKey('imp'), $passphrase);
return true;
}
return false;
}
- Horde_Imap_Client::$encryptKey = Horde_Secret::getKey('imp');
+ Horde_Imap_Client::$encryptKey = $GLOBALS['injector']->getInstance('Horde_Secret')->getKey('imp');
$old_error = error_reporting(0);
$this->_ob = unserialize($_SESSION['imp']['imap_ob'][$_SESSION['imp']['server_key']]);
/* If 'password' exists in params, it has been encrypted in the
* session so we need to decrypt. */
if (isset($this->_params['password'])) {
- $this->_params['password'] = Horde_Secret::read(Horde_Secret::getKey('imp'), $this->_params['password']);
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $this->_params['password'] = $secret->read($secret->getKey('imp'), $this->_params['password']);
}
}
$username = $calendar['user'];
$password = $calendar['password'];
if ($key) {
- $username = Horde_Secret::read($key, base64_decode($username));
- $password = Horde_Secret::read($key, base64_decode($password));
+ $secret = $injector->getInstance('Horde_Secret');
+ $username = $secret->read($key, base64_decode($username));
+ $password = $secret->read($key, base64_decode($password));
}
$vars->set('name', $calendar['name']);
if (strlen($info['username']) || strlen($info['password'])) {
$key = Horde_Auth::getCredential('password');
if ($key) {
- $info['username'] = base64_encode(Horde_Secret::write($key, $info['username']));
- $info['password'] = base64_encode(Horde_Secret::write($key, $info['password']));
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $info['username'] = base64_encode($secret->write($key, $info['username']));
+ $info['password'] = base64_encode($secret->write($key, $info['password']));
}
}
if (strlen($info['username']) || strlen($info['password'])) {
$key = Horde_Auth::getCredential('password');
if ($key) {
- $info['username'] = base64_encode(Horde_Secret::write($key, $info['username']));
- $info['password'] = base64_encode(Horde_Secret::write($key, $info['password']));
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $info['username'] = base64_encode($secret->write($key, $info['username']));
+ $info['password'] = base64_encode($secret->write($key, $info['password']));
}
}
$password = isset($cal['password']) ? $cal['password'] : '';
$key = Horde_Auth::getCredential('password');
if ($key && $user) {
- $user = Horde_Secret::read($key, base64_decode($user));
- $password = Horde_Secret::read($key, base64_decode($password));
+ $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
+ $user = $secret->read($key, base64_decode($user));
+ $password = $secret->read($key, base64_decode($password));
}
if (!empty($user)) {
return array('user' => $user, 'password' => $password);