Skip to content

Commit

Permalink
Zend\InfoCard cleanup
Browse files Browse the repository at this point in the history
- Interface/factory renaming and reorganization
- Updated tests and code to reflect above
  • Loading branch information
weierophinney committed Jul 6, 2010
1 parent 12fd78a commit e3c3084
Show file tree
Hide file tree
Showing 39 changed files with 166 additions and 1,170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\InfoCard\Cipher;
namespace Zend\InfoCard;

/**
* Provides an abstraction for encryption ciphers used in an Information Card
Expand Down Expand Up @@ -76,28 +76,28 @@ protected function __construct()
*
* @throws \Zend\InfoCard\Cipher\Exception
* @param string $uri The URI of the encryption method wantde
* @return mixed an Instance of Zend_InfoCard_Cipher_Symmetric_Interface or \Zend\InfoCard\Cipher\PKI\PKIInterface
* @return mixed an Instance of Zend\InfoCard\Cipher\Symmetric or Zend\InfoCard\Cipher\PKI
* depending on URI
*/
static public function getInstanceByURI($uri)
{
switch($uri) {
case self::ENC_AES256CBC:
return new Symmetric\Adapter\AES256CBC();
return new Cipher\Symmetric\Adapter\AES256CBC();

case self::ENC_AES128CBC:
return new Symmetric\Adapter\AES128CBC();
return new Cipher\Symmetric\Adapter\AES128CBC();

case self::ENC_RSA_OAEP_MGF1P:
return new PKI\Adapter\RSA(PKI\Adapter\RSA::OAEP_PADDING);
return new Cipher\PKI\Adapter\RSA(Cipher\PKI\Adapter\RSA::OAEP_PADDING);
break;

case self::ENC_RSA:
return new PKI\Adapter\RSA(PKI\Adapter\RSA::NO_PADDING);
return new Cipher\PKI\Adapter\RSA(Cipher\PKI\Adapter\RSA::NO_PADDING);
break;

default:
throw new Exception("Unknown Cipher URI");
throw new Cipher\Exception("Unknown Cipher URI");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\InfoCard\Cipher\PKI;
namespace Zend\InfoCard\Cipher;

/**
* Empty Interface represents a Pki cipher object
Expand All @@ -34,6 +34,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface PKIInterface
interface PKI
{
}
4 changes: 2 additions & 2 deletions library/Zend/InfoCard/Cipher/PKI/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
* An abstract class for public-key ciphers
*
* @uses \Zend\InfoCard\Cipher\Exception
* @uses \Zend\InfoCard\Cipher\PKI\PKIInterface
* @uses \Zend\InfoCard\Cipher\PKI
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractAdapter implements \Zend\InfoCard\Cipher\PKI\PKIInterface
abstract class AbstractAdapter implements \Zend\InfoCard\Cipher\PKI
{
/**
* OAEP Padding public key encryption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\InfoCard\Cipher\Symmetric;
namespace Zend\InfoCard\Cipher;

/**
* @category Zend
Expand All @@ -32,6 +32,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface SymmetricInterface
interface Symmetric
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
namespace Zend\InfoCard\Cipher\Symmetric\Adapter;

/**
* @uses \Zend\InfoCard\Cipher\Symmetric\SymmetricInterface
* @uses \Zend\InfoCard\Cipher\Symmetric
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Cipher
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractAdapter
implements \Zend\InfoCard\Cipher\Symmetric\SymmetricInterface
implements \Zend\InfoCard\Cipher\Symmetric
{
}
40 changes: 20 additions & 20 deletions library/Zend/InfoCard/InfoCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* @uses \Zend\InfoCard\Adapter
* @uses \Zend\InfoCard\Claims
* @uses \Zend\InfoCard\Exception
* @uses \Zend\InfoCard\XML\Assertion\Assertion
* @uses \Zend\InfoCard\XML\Assertion\Factory
* @uses Zend_InfoCard_Xml_Cipher
* @uses \Zend\InfoCard\XML\EncryptedData\EncryptedData
* @uses \Zend\InfoCard\XML\EncryptedData\Factory
* @uses \Zend\InfoCard\XML\Security
* @category Zend
* @package Zend_InfoCard
Expand All @@ -56,14 +56,14 @@ class InfoCard
/**
* The instance to use to decrypt public-key encrypted data
*
* @var \Zend\InfoCard\Cipher\PKI\PKIInterface
* @var \Zend\InfoCard\Cipher\PKI
*/
protected $_pkiCipherObj;

/**
* The instance to use to decrypt symmetric encrypted data
*
* @var \Zend\InfoCard\Cipher\Symmetric\SymmetricInterface
* @var \Zend\InfoCard\Cipher\Symmetric
*/
protected $_symCipherObj;

Expand Down Expand Up @@ -125,7 +125,7 @@ public function getAdapter()
/**
* Gets the Public Key Cipher object used in this instance
*
* @return \Zend\InfoCard\Cipher\PKI\PKIInterface
* @return \Zend\InfoCard\Cipher\PKI
*/
public function getPkiCipherObject()
{
Expand All @@ -135,10 +135,10 @@ public function getPkiCipherObject()
/**
* Sets the Public Key Cipher Object used in this instance
*
* @param \Zend\InfoCard\Cipher\PKI\PKIInterface $cipherObj
* @param \Zend\InfoCard\Cipher\PKI $cipherObj
* @return \Zend\InfoCard\InfoCard
*/
public function setPkiCipherObject(Cipher\PKI\PKIInterface $cipherObj)
public function setPkiCipherObject(Cipher\PKI $cipherObj)
{
$this->_pkiCipherObj = $cipherObj;
return $this;
Expand All @@ -147,7 +147,7 @@ public function setPkiCipherObject(Cipher\PKI\PKIInterface $cipherObj)
/**
* Get the Symmetric Cipher Object used in this instance
*
* @return \Zend\InfoCard\Cipher\Symmetric\SymmetricInterface
* @return \Zend\InfoCard\Cipher\Symmetric
*/
public function getSymCipherObject()
{
Expand All @@ -157,7 +157,7 @@ public function getSymCipherObject()
/**
* Sets the Symmetric Cipher Object used in this instance
*
* @param \Zend\InfoCard\Cipher\Symmetric\SymmetricInterface $cipherObj
* @param \Zend\InfoCard\Cipher\Symmetric $cipherObj
* @return \Zend\InfoCard\InfoCard
*/
public function setSymCipherObject($cipherObj)
Expand Down Expand Up @@ -194,7 +194,7 @@ public function removeCertificatePair($key_id)
* @param string $password (optional) The password for the private key file if necessary
* @return string A key ID representing this key pair in the component
*/
public function addCertificatePair($private_key_file, $public_key_file, $type = Cipher\Cipher::ENC_RSA_OAEP_MGF1P, $password = null)
public function addCertificatePair($private_key_file, $public_key_file, $type = Cipher::ENC_RSA_OAEP_MGF1P, $password = null)
{
if(!file_exists($private_key_file) ||
!file_exists($public_key_file)) {
Expand All @@ -213,8 +213,8 @@ public function addCertificatePair($private_key_file, $public_key_file, $type =
}

switch($type) {
case Cipher\Cipher::ENC_RSA:
case Cipher\Cipher::ENC_RSA_OAEP_MGF1P:
case Cipher::ENC_RSA:
case Cipher::ENC_RSA_OAEP_MGF1P:
$this->_keyPairs[$key_id] = array('private' => $private_key_file,
'public' => $public_key_file,
'type_uri' => $type);
Expand Down Expand Up @@ -309,13 +309,13 @@ protected function _findCertifiatePairByDigest($digest, $digestMethod = self::DI
*/
protected function _extractSignedToken($strXmlToken)
{
$encryptedData = XML\EncryptedData\EncryptedData::getInstance($strXmlToken);
$encryptedData = XML\EncryptedData\Factory::getInstance($strXmlToken);

// Determine the Encryption Method used to encrypt the token

switch($encryptedData->getEncryptionMethod()) {
case Cipher\Cipher::ENC_AES128CBC:
case Cipher\Cipher::ENC_AES256CBC:
case Cipher::ENC_AES128CBC:
case Cipher::ENC_AES256CBC:
break;
default:
throw new Exception("Unknown Encryption Method used in the secure token");
Expand All @@ -333,8 +333,8 @@ protected function _extractSignedToken($strXmlToken)
$encryptedKey = $keyinfo->getEncryptedKey();

switch($encryptedKey->getEncryptionMethod()) {
case Cipher\Cipher::ENC_RSA:
case Cipher\Cipher::ENC_RSA_OAEP_MGF1P:
case Cipher::ENC_RSA:
case Cipher::ENC_RSA_OAEP_MGF1P:
break;
default:
throw new Exception("Unknown Key Encryption Method used in secure token");
Expand All @@ -356,7 +356,7 @@ protected function _extractSignedToken($strXmlToken)
throw new Exception("Certificate Pair which matches digest is not of same algorithm type as document, check addCertificate()");
}

$PKcipher = Cipher\Cipher::getInstanceByURI($encryptedKey->getEncryptionMethod());
$PKcipher = Cipher::getInstanceByURI($encryptedKey->getEncryptionMethod());

$base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>=');

Expand All @@ -372,7 +372,7 @@ protected function _extractSignedToken($strXmlToken)
$certificate_pair['password']
);

$symCipher = Cipher\Cipher::getInstanceByURI($encryptedData->getEncryptionMethod());
$symCipher = Cipher::getInstanceByURI($encryptedData->getEncryptionMethod());

if ($base64DecodeSupportsStrictParam) {
$dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue(), true);
Expand Down Expand Up @@ -406,7 +406,7 @@ public function process($strXmlToken)
}

try {
$assertions = XML\Assertion\Assertion::getInstance($signedAssertionsXml);
$assertions = XML\Assertion\Factory::getInstance($signedAssertionsXml);
} catch(Exception $e) {
$retval->setError('Failure processing assertion document');
$retval->setCode(Claims::RESULT_PROCESSING_FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
/**
* @namespace
*/
namespace Zend\InfoCard\XML\Element;

use Zend\InfoCard\XML;
namespace Zend\InfoCard\XML;

/**
* An abstract class representing a an XML data block
Expand All @@ -41,7 +39,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Element extends \SimpleXMLElement implements XML\Element
abstract class AbstractElement extends \SimpleXMLElement implements Element
{
/**
* Convert the object to a string by displaying its XML content
Expand All @@ -57,7 +55,7 @@ public function __toString()
* Converts an XML Element object into a DOM object
*
* @throws \Zend\InfoCard\XML\Exception
* @param \Zend\InfoCard\XML\Element\Element $e The object to convert
* @param \Zend\InfoCard\XML\Element $e The object to convert
* @return DOMElement A DOMElement representation of the same object
*/
static public function convertToDOM(Element $e)
Expand All @@ -67,7 +65,7 @@ static public function convertToDOM(Element $e)
if(!($dom instanceof \DOMElement)) {
// Zend_InfoCard_Xml_Element extends SimpleXMLElement, so this should *never* fail
// @codeCoverageIgnoreStart
throw new XML\Exception("Failed to convert between SimpleXML and DOM");
throw new Exception("Failed to convert between SimpleXML and DOM");
// @codeCoverageIgnoreEnd
}

Expand All @@ -79,8 +77,8 @@ static public function convertToDOM(Element $e)
*
* @throws \Zend\InfoCard\XML\Exception
* @param DOMElement $e The DOMElement object to convert
* @param string $classname The name of the class to convert it to (must inhert from \Zend\InfoCard\XML\Element\Element)
* @return \Zend\InfoCard\XML\Element\Element a Xml Element object from the DOM element
* @param string $classname The name of the class to convert it to (must inhert from \Zend\InfoCard\XML\Element)
* @return \Zend\InfoCard\XML\Element a Xml Element object from the DOM element
*/
static public function convertToObject(\DOMElement $e, $classname)
{
Expand All @@ -90,16 +88,16 @@ static public function convertToObject(\DOMElement $e, $classname)

$reflection = new \ReflectionClass($classname);

if(!$reflection->isSubclassOf('Zend\InfoCard\XML\Element\Element')) {
throw new XML\Exception("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element");
if(!$reflection->isSubclassOf('Zend\InfoCard\XML\Element')) {
throw new Exception("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element");
}

$sxe = simplexml_import_dom($e, $classname);

if(!($sxe instanceof Element)) {
// Since we just checked to see if this was a subclass of Zend_infoCard_Xml_Element this shoudl never fail
// @codeCoverageIgnoreStart
throw new XML\Exception("Failed to convert between DOM and SimpleXML");
throw new Exception("Failed to convert between DOM and SimpleXML");
// @codeCoverageIgnoreEnd
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
final class Assertion
final class Factory
{
/**
* The namespace for a SAML-formatted Assertion document
Expand All @@ -66,7 +66,7 @@ private function __construct()
static public function getInstance($xmlData)
{

if($xmlData instanceof XML\Element\Element) {
if($xmlData instanceof XML\AbstractElement) {
$strXmlData = $xmlData->asXML();
} else if (is_string($xmlData)) {
$strXmlData = $xmlData;
Expand Down
9 changes: 4 additions & 5 deletions library/Zend/InfoCard/XML/Assertion/SAML.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@
namespace Zend\InfoCard\XML\Assertion;

use Zend\InfoCard\XML\Assertion as XMLAssertion,
Zend\InfoCard\XML\Element\Element,
Zend\InfoCard\XML\AbstractElement,
Zend\InfoCard\XML\Exception as XMLException;

/**
* A Xml Assertion Document in SAML Token format
*
* @uses \Zend\InfoCard\Exception
* @uses \Zend\InfoCard\XML\Assertion\Assertion
* @uses \Zend\InfoCard\XML\Assertion
* @uses \Zend\InfoCard\XML\Element\Element
* @uses \Zend\InfoCard\XML\AbstractElement
* @category Zend
* @package Zend_InfoCard
* @subpackage Zend_InfoCard_Xml
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class SAML extends Element implements XMLAssertion
class SAML extends AbstractElement implements XMLAssertion
{

/**
Expand Down Expand Up @@ -207,7 +206,7 @@ public function getConditions()

list($conditions) = $this->xpath("//saml:Conditions");

if(!($conditions instanceof Element)) {
if(!($conditions instanceof AbstractElement)) {
throw new XMLException("Unable to find the saml:Conditions block");
}

Expand Down
Loading

0 comments on commit e3c3084

Please sign in to comment.