diff --git a/library/Zend/Auth/Adapter/InfoCard.php b/library/Zend/Auth/Adapter/InfoCard.php deleted file mode 100644 index 0dd7c3f..0000000 --- a/library/Zend/Auth/Adapter/InfoCard.php +++ /dev/null @@ -1,261 +0,0 @@ -_xmlToken = $strXmlDocument; - $this->_infoCard = new Zend_InfoCard(); - } - - /** - * Sets the InfoCard component Adapter to use - * - * @param Zend_InfoCard_Adapter_Interface $a - * @return Zend_Auth_Adapter_InfoCard Provides a fluent interface - */ - public function setAdapter(Zend_InfoCard_Adapter_Interface $a) - { - $this->_infoCard->setAdapter($a); - return $this; - } - - /** - * Retrieves the InfoCard component adapter being used - * - * @return Zend_InfoCard_Adapter_Interface - */ - public function getAdapter() - { - return $this->_infoCard->getAdapter(); - } - - /** - * Retrieves the InfoCard public key cipher object being used - * - * @return Zend_InfoCard_Cipher_PKI_Interface - */ - public function getPKCipherObject() - { - return $this->_infoCard->getPKCipherObject(); - } - - /** - * Sets the InfoCard public key cipher object to use - * - * @param Zend_InfoCard_Cipher_PKI_Interface $cipherObj - * @return Zend_Auth_Adapter_InfoCard Provides a fluent interface - */ - public function setPKICipherObject(Zend_InfoCard_Cipher_PKI_Interface $cipherObj) - { - $this->_infoCard->setPKICipherObject($cipherObj); - return $this; - } - - /** - * Retrieves the Symmetric cipher object being used - * - * @return Zend_InfoCard_Cipher_Symmetric_Interface - */ - public function getSymCipherObject() - { - return $this->_infoCard->getSymCipherObject(); - } - - /** - * Sets the InfoCard symmetric cipher object to use - * - * @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj - * @return Zend_Auth_Adapter_InfoCard Provides a fluent interface - */ - public function setSymCipherObject(Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj) - { - $this->_infoCard->setSymCipherObject($cipherObj); - return $this; - } - - /** - * Remove a Certificate Pair by Key ID from the search list - * - * @param string $key_id The Certificate Key ID returned from adding the certificate pair - * @throws Zend_InfoCard_Exception - * @return Zend_Auth_Adapter_InfoCard Provides a fluent interface - */ - public function removeCertificatePair($key_id) - { - $this->_infoCard->removeCertificatePair($key_id); - return $this; - } - - /** - * Add a Certificate Pair to the list of certificates searched by the component - * - * @param string $private_key_file The path to the private key file for the pair - * @param string $public_key_file The path to the certificate / public key for the pair - * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) - * @param string $password (optional) The password for the private key file if necessary - * @throws Zend_InfoCard_Exception - * @return string A key ID representing this key pair in the component - */ - public function addCertificatePair($private_key_file, $public_key_file, $type = Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null) - { - return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password); - } - - /** - * Return a Certificate Pair from a key ID - * - * @param string $key_id The Key ID of the certificate pair in the component - * @throws Zend_InfoCard_Exception - * @return array An array containing the path to the private/public key files, - * the type URI and the password if provided - */ - public function getCertificatePair($key_id) - { - return $this->_infoCard->getCertificatePair($key_id); - } - - /** - * Set the XML Token to be processed - * - * @param string $strXmlToken The XML token to process - * @return Zend_Auth_Adapter_InfoCard Provides a fluent interface - */ - public function setXmlToken($strXmlToken) - { - $this->_xmlToken = $strXmlToken; - return $this; - } - - /** - * Get the XML Token being processed - * - * @return string The XML token to be processed - */ - public function getXmlToken() - { - return $this->_xmlToken; - } - - /** - * Authenticates the XML token - * - * @return Zend_Auth_Result The result of the authentication - */ - public function authenticate() - { - try { - $claims = $this->_infoCard->process($this->getXmlToken()); - } catch(Exception $e) { - return new Zend_Auth_Result(Zend_Auth_Result::FAILURE , null, array('Exception Thrown', - $e->getMessage(), - $e->getTraceAsString(), - serialize($e))); - } - - if(!$claims->isValid()) { - switch($claims->getCode()) { - case Zend_infoCard_Claims::RESULT_PROCESSING_FAILURE: - return new Zend_Auth_Result( - Zend_Auth_Result::FAILURE, - $claims, - array( - 'Processing Failure', - $claims->getErrorMsg() - ) - ); - break; - case Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE: - return new Zend_Auth_Result( - Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, - $claims, - array( - 'Validation Failure', - $claims->getErrorMsg() - ) - ); - break; - default: - return new Zend_Auth_Result( - Zend_Auth_Result::FAILURE, - $claims, - array( - 'Unknown Failure', - $claims->getErrorMsg() - ) - ); - break; - } - } - - return new Zend_Auth_Result( - Zend_Auth_Result::SUCCESS, - $claims - ); - } -} diff --git a/library/Zend/Cloud/StorageService/Adapter/Nirvanix.php b/library/Zend/Cloud/StorageService/Adapter/Nirvanix.php deleted file mode 100644 index b96e33e..0000000 --- a/library/Zend/Cloud/StorageService/Adapter/Nirvanix.php +++ /dev/null @@ -1,399 +0,0 @@ -toArray(); - } - - if (!is_array($options)) { - throw new Zend_Cloud_StorageService_Exception('Invalid options provided'); - } - - $auth = array( - 'username' => $options[self::USERNAME], - 'password' => $options[self::PASSWORD], - 'appKey' => $options[self::APP_KEY], - ); - $nirvanix_options = array(); - if (isset($options[self::HTTP_ADAPTER])) { - $httpc = new Zend_Http_Client(); - $httpc->setAdapter($options[self::HTTP_ADAPTER]); - $nirvanix_options['httpClient'] = $httpc; - } - try { - $this->_nirvanix = new Zend_Service_Nirvanix($auth, $nirvanix_options); - $this->_remoteDirectory = $options[self::REMOTE_DIRECTORY]; - $this->_imfNs = $this->_nirvanix->getService('IMFS'); - $this->_metadataNs = $this->_nirvanix->getService('Metadata'); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on create: '.$e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Get an item from the storage service. - * - * @param string $path - * @param array $options - * @return mixed - */ - public function fetchItem($path, $options = null) - { - $path = $this->_getFullPath($path); - try { - $item = $this->_imfNs->getContents($path); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on fetch: '.$e->getMessage(), $e->getCode(), $e); - } - return $item; - } - - /** - * Store an item in the storage service. - * WARNING: This operation overwrites any item that is located at - * $destinationPath. - * @param string $destinationPath - * @param mixed $data - * @param array $options - * @return void - */ - public function storeItem($destinationPath, $data, $options = null) - { - try { - $path = $this->_getFullPath($destinationPath); - $this->_imfNs->putContents($path, $data); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on store: '.$e->getMessage(), $e->getCode(), $e); - } - return true; - } - - /** - * Delete an item in the storage service. - * - * @param string $path - * @param array $options - * @return void - */ - public function deleteItem($path, $options = null) - { - try { - $path = $this->_getFullPath($path); - $this->_imfNs->unlink($path); - } catch(Zend_Service_Nirvanix_Exception $e) { -// if (trim(strtoupper($e->getMessage())) != 'INVALID PATH') { -// // TODO Differentiate among errors in the Nirvanix adapter - throw new Zend_Cloud_StorageService_Exception('Error on delete: '.$e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Copy an item in the storage service to a given path. - * WARNING: This operation is *very* expensive for services that do not - * support copying an item natively. - * - * @param string $sourcePath - * @param string $destination path - * @param array $options - * @return void - */ - public function copyItem($sourcePath, $destinationPath, $options = null) - { - try { - $sourcePath = $this->_getFullPath($sourcePath); - $destinationPath = $this->_getFullPath($destinationPath); - $this->_imfNs->CopyFiles(array('srcFilePath' => $sourcePath, - 'destFolderPath' => $destinationPath)); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on copy: '.$e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Move an item in the storage service to a given path. - * WARNING: This operation is *very* expensive for services that do not - * support moving an item natively. - * - * @param string $sourcePath - * @param string $destination path - * @param array $options - * @return void - */ - public function moveItem($sourcePath, $destinationPath, $options = null) - { - try { - $sourcePath = $this->_getFullPath($sourcePath); - $destinationPath = $this->_getFullPath($destinationPath); - $this->_imfNs->RenameFile(array('filePath' => $sourcePath, - 'newFileName' => $destinationPath)); - // $this->_imfNs->MoveFiles(array('srcFilePath' => $sourcePath, - // 'destFolderPath' => $destinationPath)); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on move: '.$e->getMessage(), $e->getCode(), $e); - } - } - - /** - * Rename an item in the storage service to a given name. - * - * - * @param string $path - * @param string $name - * @param array $options - * @return void - */ - public function renameItem($path, $name, $options = null) - { - require_once 'Zend/Cloud/OperationNotAvailableException.php'; - throw new Zend_Cloud_OperationNotAvailableException('Renaming not implemented'); - } - - /** - * Get a key/value array of metadata for the given path. - * - * @param string $path - * @param array $options - * @return array An associative array of key/value pairs specifying the metadata for this object. - * If no metadata exists, an empty array is returned. - */ - public function fetchMetadata($path, $options = null) - { - $path = $this->_getFullPath($path); - try { - $metadataNode = $this->_metadataNs->getMetadata(array('path' => $path)); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on fetching metadata: '.$e->getMessage(), $e->getCode(), $e); - } - - $metadata = array(); - $length = count($metadataNode->Metadata); - - // Need to special case this as Nirvanix returns an array if there is - // more than one, but doesn't return an array if there is only one. - if ($length == 1) - { - $metadata[(string)$metadataNode->Metadata->Type->value] = (string)$metadataNode->Metadata->Value; - } - else if ($length > 1) - { - for ($i=0; $i<$length; $i++) - { - $metadata[(string)$metadataNode->Metadata[$i]->Type] = (string)$metadataNode->Metadata[$i]->Value; - } - } - return $metadata; - } - - /** - * Store a key/value array of metadata at the given path. - * WARNING: This operation overwrites any metadata that is located at - * $destinationPath. - * - * @param string $destinationPath - * @param array $metadata associative array specifying the key/value pairs for the metadata. - * @param array $options - * @return void - */ - public function storeMetadata($destinationPath, $metadata, $options = null) - { - $destinationPath = $this->_getFullPath($destinationPath); - if ($metadata != null) { - try { - foreach ($metadata AS $key=>$value) { - $metadataString = $key . ":" . $value; - $this->_metadataNs->SetMetadata(array( - 'path' => $destinationPath, - 'metadata' => $metadataString, - )); - } - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on storing metadata: '.$e->getMessage(), $e->getCode(), $e); - } - } - } - - /** - * Delete a key/value array of metadata at the given path. - * - * @param string $path - * @param array $metadata - An associative array specifying the key/value pairs for the metadata - * to be deleted. If null, all metadata associated with the object will - * be deleted. - * @param array $options - * @return void - */ - public function deleteMetadata($path, $metadata = null, $options = null) - { - $path = $this->_getFullPath($path); - try { - if ($metadata == null) { - $this->_metadataNs->DeleteAllMetadata(array('path' => $path)); - } else { - foreach ($metadata AS $key=>$value) { - $this->_metadataNs->DeleteMetadata(array( - 'path' => $path, - 'metadata' => $key, - )); - } - } - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on deleting metadata: '.$e->getMessage(), $e->getCode(), $e); - } - } - - /* - * Recursively traverse all the folders and build an array that contains - * the path names for each folder. - * - * @param string $path folder path to get the list of folders from. - * @param array& $resultArray reference to the array that contains the path names - * for each folder. - */ - private function getAllFolders($path, &$resultArray) - { - $response = $this->_imfNs->ListFolder(array( - 'folderPath' => $path, - 'pageNumber' => 1, - 'pageSize' => $this->maxPageSize, - )); - $numFolders = $response->ListFolder->TotalFolderCount; - if ($numFolders == 0) { - return; - } else { - //Need to special case this as Nirvanix returns an array if there is - //more than one, but doesn't return an array if there is only one. - if ($numFolders == 1) { - $folderPath = $response->ListFolder->Folder->Path; - array_push($resultArray, $folderPath); - $this->getAllFolders('/' . $folderPath, $resultArray); - } else { - foreach ($response->ListFolder->Folder as $arrayElem) { - $folderPath = $arrayElem->Path; - array_push($resultArray, $folderPath); - $this->getAllFolders('/' . $folderPath, $resultArray); - } - } - } - } - - /** - * Return an array of the items contained in the given path. The items - * returned are the files or objects that in the specified path. - * - * @param string $path - * @param array $options - * @return array - */ - public function listItems($path, $options = null) - { - $path = $this->_getFullPath($path); - $resultArray = array(); - - if (!isset($path)) { - return false; - } else { - try { - $response = $this->_imfNs->ListFolder(array( - 'folderPath' => $path, - 'pageNumber' => 1, - 'pageSize' => $this->maxPageSize, - )); - } catch (Zend_Service_Nirvanix_Exception $e) { - throw new Zend_Cloud_StorageService_Exception('Error on list: '.$e->getMessage(), $e->getCode(), $e); - } - - $numFiles = $response->ListFolder->TotalFileCount; - - //Add the file names to the array - if ($numFiles != 0) { - //Need to special case this as Nirvanix returns an array if there is - //more than one, but doesn't return an array if there is only one. - if ($numFiles == 1) { - $resultArray[] = (string)$response->ListFolder->File->Name; - } - else { - foreach ($response->ListFolder->File as $arrayElem) { - $resultArray[] = (string) $arrayElem->Name; - } - } - } - } - - return $resultArray; - } - - /** - * Get full path to an object - * - * @param string $path - * @return string - */ - private function _getFullPath($path) - { - return $this->_remoteDirectory . $path; - } - - /** - * Get the concrete client. - * @return Zend_Service_Nirvanix - */ - public function getClient() - { - return $this->_nirvanix; - } -} diff --git a/library/Zend/InfoCard.php b/library/Zend/InfoCard.php deleted file mode 100644 index 5c8841a..0000000 --- a/library/Zend/InfoCard.php +++ /dev/null @@ -1,497 +0,0 @@ -_keyPairs = array(); - - if(!extension_loaded('mcrypt')) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Use of the Zend_InfoCard component requires the mcrypt extension to be enabled in PHP"); - } - - if(!extension_loaded('openssl')) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Use of the Zend_InfoCard component requires the openssl extension to be enabled in PHP"); - } - } - - /** - * Sets the adapter uesd for callbacks into the application using the component, used - * when doing things such as storing / retrieving assertions, etc. - * - * @param Zend_InfoCard_Adapter_Interface $a The Adapter instance - * @return Zend_InfoCard The instnace - */ - public function setAdapter(Zend_InfoCard_Adapter_Interface $a) - { - $this->_adapter = $a; - return $this; - } - - /** - * Retrieves the adapter used for callbacks into the application using the component. - * If no adapter was set then an instance of Zend_InfoCard_Adapter_Default is used - * - * @return Zend_InfoCard_Adapter_Interface The Adapter instance - */ - public function getAdapter() - { - if($this->_adapter === null) { - require_once 'Zend/InfoCard/Adapter/Default.php'; - $this->setAdapter(new Zend_InfoCard_Adapter_Default()); - } - - return $this->_adapter; - } - - /** - * Gets the Public Key Cipher object used in this instance - * - * @return Zend_InfoCard_Cipher_Pki_Interface - */ - public function getPkiCipherObject() - { - return $this->_pkiCipherObj; - } - - /** - * Sets the Public Key Cipher Object used in this instance - * - * @param Zend_InfoCard_Cipher_Pki_Interface $cipherObj - * @return Zend_InfoCard - */ - public function setPkiCipherObject(Zend_InfoCard_Cipher_Pki_Interface $cipherObj) - { - $this->_pkiCipherObj = $cipherObj; - return $this; - } - - /** - * Get the Symmetric Cipher Object used in this instance - * - * @return Zend_InfoCard_Cipher_Symmetric_Interface - */ - public function getSymCipherObject() - { - return $this->_symCipherObj; - } - - /** - * Sets the Symmetric Cipher Object used in this instance - * - * @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj - * @return Zend_InfoCard - */ - public function setSymCipherObject($cipherObj) - { - $this->_symCipherObj = $cipherObj; - return $this; - } - - /** - * Remove a Certificate Pair by Key ID from the search list - * - * @throws Zend_InfoCard_Exception - * @param string $key_id The Certificate Key ID returned from adding the certificate pair - * @return Zend_InfoCard - */ - public function removeCertificatePair($key_id) - { - - if(!key_exists($key_id, $this->_keyPairs)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Attempted to remove unknown key id: $key_id"); - } - - unset($this->_keyPairs[$key_id]); - return $this; - } - - /** - * Add a Certificate Pair to the list of certificates searched by the component - * - * @throws Zend_InfoCard_Exception - * @param string $private_key_file The path to the private key file for the pair - * @param string $public_key_file The path to the certificate / public key for the pair - * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) - * @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 = Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null) - { - if(!file_exists($private_key_file) || - !file_exists($public_key_file)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Could not locate the public and private certificate pair files: $private_key_file, $public_key_file"); - } - - if(!is_readable($private_key_file) || - !is_readable($public_key_file)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Could not read the public and private certificate pair files (check permissions): $private_key_file, $public_key_file"); - } - - $key_id = md5($private_key_file.$public_key_file); - - if(key_exists($key_id, $this->_keyPairs)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Attempted to add previously existing certificate pair: $private_key_file, $public_key_file"); - } - - switch($type) { - case Zend_InfoCard_Cipher::ENC_RSA: - case Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P: - $this->_keyPairs[$key_id] = array('private' => $private_key_file, - 'public' => $public_key_file, - 'type_uri' => $type); - - if($password !== null) { - $this->_keyPairs[$key_id]['password'] = $password; - } else { - $this->_keyPairs[$key_id]['password'] = null; - } - - return $key_id; - break; - default: - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Invalid Certificate Pair Type specified: $type"); - } - } - - /** - * Return a Certificate Pair from a key ID - * - * @throws Zend_InfoCard_Exception - * @param string $key_id The Key ID of the certificate pair in the component - * @return array An array containing the path to the private/public key files, - * the type URI and the password if provided - */ - public function getCertificatePair($key_id) - { - if(key_exists($key_id, $this->_keyPairs)) { - return $this->_keyPairs[$key_id]; - } - - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Invalid Certificate Pair ID provided: $key_id"); - } - - /** - * Retrieve the digest of a given public key / certificate using the provided digest - * method - * - * @throws Zend_InfoCard_Exception - * @param string $key_id The certificate key id in the component - * @param string $digestMethod The URI of the digest method to use (default SHA1) - * @return string The digest value in binary format - */ - protected function _getPublicKeyDigest($key_id, $digestMethod = self::DIGEST_SHA1) - { - $certificatePair = $this->getCertificatePair($key_id); - - $temp = file($certificatePair['public']); - unset($temp[count($temp)-1]); - unset($temp[0]); - $certificateData = base64_decode(implode("\n", $temp)); - - switch($digestMethod) { - case self::DIGEST_SHA1: - $digest_retval = sha1($certificateData, true); - break; - default: - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Invalid Digest Type Provided: $digestMethod"); - } - - return $digest_retval; - } - - /** - * Find a certificate pair based on a digest of its public key / certificate file - * - * @param string $digest The digest value of the public key wanted in binary form - * @param string $digestMethod The URI of the digest method used to calculate the digest - * @return mixed The Key ID of the matching certificate pair or false if not found - */ - protected function _findCertifiatePairByDigest($digest, $digestMethod = self::DIGEST_SHA1) - { - - foreach($this->_keyPairs as $key_id => $certificate_data) { - - $cert_digest = $this->_getPublicKeyDigest($key_id, $digestMethod); - - if($cert_digest == $digest) { - return $key_id; - } - } - - return false; - } - - /** - * Extracts the Signed Token from an EncryptedData block - * - * @throws Zend_InfoCard_Exception - * @param string $strXmlToken The EncryptedData XML block - * @return string The XML of the Signed Token inside of the EncryptedData block - */ - protected function _extractSignedToken($strXmlToken) - { - $encryptedData = Zend_InfoCard_Xml_EncryptedData::getInstance($strXmlToken); - - // Determine the Encryption Method used to encrypt the token - - switch($encryptedData->getEncryptionMethod()) { - case Zend_InfoCard_Cipher::ENC_AES128CBC: - case Zend_InfoCard_Cipher::ENC_AES256CBC: - break; - default: - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Unknown Encryption Method used in the secure token"); - } - - // Figure out the Key we are using to decrypt the token - - $keyinfo = $encryptedData->getKeyInfo(); - - if(!($keyinfo instanceof Zend_InfoCard_Xml_KeyInfo_XmlDSig)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Expected a XML digital signature KeyInfo, but was not found"); - } - - - $encryptedKey = $keyinfo->getEncryptedKey(); - - switch($encryptedKey->getEncryptionMethod()) { - case Zend_InfoCard_Cipher::ENC_RSA: - case Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P: - break; - default: - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Unknown Key Encryption Method used in secure token"); - } - - $securityTokenRef = $encryptedKey->getKeyInfo()->getSecurityTokenReference(); - - $key_id = $this->_findCertifiatePairByDigest($securityTokenRef->getKeyReference()); - - if(!$key_id) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Unable to find key pair used to encrypt symmetric InfoCard Key"); - } - - $certificate_pair = $this->getCertificatePair($key_id); - - // Santity Check - - if($certificate_pair['type_uri'] != $encryptedKey->getEncryptionMethod()) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Certificate Pair which matches digest is not of same algorithm type as document, check addCertificate()"); - } - - $PKcipher = Zend_InfoCard_Cipher::getInstanceByURI($encryptedKey->getEncryptionMethod()); - - $base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>='); - - if ($base64DecodeSupportsStrictParam) { - $keyCipherValueBase64Decoded = base64_decode($encryptedKey->getCipherValue(), true); - } else { - $keyCipherValueBase64Decoded = base64_decode($encryptedKey->getCipherValue()); - } - - $symmetricKey = $PKcipher->decrypt( - $keyCipherValueBase64Decoded, - file_get_contents($certificate_pair['private']), - $certificate_pair['password'] - ); - - $symCipher = Zend_InfoCard_Cipher::getInstanceByURI($encryptedData->getEncryptionMethod()); - - if ($base64DecodeSupportsStrictParam) { - $dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue(), true); - } else { - $dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue()); - } - - $signedToken = $symCipher->decrypt($dataCipherValueBase64Decoded, $symmetricKey); - - return $signedToken; - } - - /** - * Process an input Infomation Card EncryptedData block sent from the client, - * validate it, and return the claims contained within it on success or an error message on error - * - * @param string $strXmlToken The XML token sent to the server from the client - * @return Zend_Infocard_Claims The Claims object containing the claims, or any errors which occurred - */ - public function process($strXmlToken) - { - - $retval = new Zend_InfoCard_Claims(); - - require_once 'Zend/InfoCard/Exception.php'; - try { - $signedAssertionsXml = $this->_extractSignedToken($strXmlToken); - } catch(Zend_InfoCard_Exception $e) { - $retval->setError('Failed to extract assertion document'); - $retval->setCode(Zend_InfoCard_Claims::RESULT_PROCESSING_FAILURE); - return $retval; - } - - try { - $assertions = Zend_InfoCard_Xml_Assertion::getInstance($signedAssertionsXml); - } catch(Zend_InfoCard_Exception $e) { - $retval->setError('Failure processing assertion document'); - $retval->setCode(Zend_InfoCard_Claims::RESULT_PROCESSING_FAILURE); - return $retval; - } - - if(!($assertions instanceof Zend_InfoCard_Xml_Assertion_Interface)) { - throw new Zend_InfoCard_Exception("Invalid Assertion Object returned"); - } - - if(!($reference_id = Zend_InfoCard_Xml_Security::validateXMLSignature($assertions->asXML()))) { - $retval->setError("Failure Validating the Signature of the assertion document"); - $retval->setCode(Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE); - return $retval; - } - - // The reference id should be locally scoped as far as I know - if($reference_id[0] == '#') { - $reference_id = substr($reference_id, 1); - } else { - $retval->setError("Reference of document signature does not reference the local document"); - $retval->setCode(Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE); - return $retval; - } - - // Make sure the signature is in reference to the same document as the assertions - if($reference_id != $assertions->getAssertionID()) { - $retval->setError("Reference of document signature does not reference the local document"); - $retval->setCode(Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE); - } - - // Validate we haven't seen this before and the conditions are acceptable - $conditions = $this->getAdapter()->retrieveAssertion($assertions->getAssertionURI(), $assertions->getAssertionID()); - - if($conditions === false) { - $conditions = $assertions->getConditions(); - } - - - if(is_array($condition_error = $assertions->validateConditions($conditions))) { - $retval->setError("Conditions of assertion document are not met: {$condition_error[1]} ({$condition_error[0]})"); - $retval->setCode(Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE); - } - - $attributes = $assertions->getAttributes(); - - $retval->setClaims($attributes); - - if($retval->getCode() == 0) { - $retval->setCode(Zend_InfoCard_Claims::RESULT_SUCCESS); - } - - return $retval; - } -} diff --git a/library/Zend/InfoCard/Adapter/Default.php b/library/Zend/InfoCard/Adapter/Default.php deleted file mode 100644 index d24665c..0000000 --- a/library/Zend/InfoCard/Adapter/Default.php +++ /dev/null @@ -1,79 +0,0 @@ -_padding = $padding; - break; - default: - require_once 'Zend/InfoCard/Cipher/Exception.php'; - throw new Zend_InfoCard_Cipher_Exception("Invalid Padding Type Provided"); - break; - } - - return $this; - } - - /** - * Retruns the public-key padding used - * - * @return integer One of the padding constants in this class - */ - public function getPadding() - { - return $this->_padding; - } -} diff --git a/library/Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php b/library/Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php deleted file mode 100644 index feee469..0000000 --- a/library/Zend/InfoCard/Cipher/Pki/Adapter/Rsa.php +++ /dev/null @@ -1,120 +0,0 @@ -setPadding($padding); - } - - /** - * Decrypts RSA encrypted data using the given private key - * - * @throws Zend_InfoCard_Cipher_Exception - * @param string $encryptedData The encrypted data in binary format - * @param string $privateKey The private key in binary format - * @param string $password The private key passphrase - * @param integer $padding The padding to use during decryption (of not provided object value will be used) - * @return string The decrypted data - */ - public function decrypt($encryptedData, $privateKey, $password = null, $padding = null) - { - $private_key = openssl_pkey_get_private(array($privateKey, $password)); - - if(!$private_key) { - require_once 'Zend/InfoCard/Cipher/Exception.php'; - throw new Zend_InfoCard_Cipher_Exception("Failed to load private key"); - } - - if($padding !== null) { - try { - $this->setPadding($padding); - } catch(Exception $e) { - openssl_free_key($private_key); - throw $e; - } - } - - switch($this->getPadding()) { - case self::NO_PADDING: - $openssl_padding = OPENSSL_NO_PADDING; - break; - case self::OAEP_PADDING: - $openssl_padding = OPENSSL_PKCS1_OAEP_PADDING; - break; - } - - $result = openssl_private_decrypt($encryptedData, $decryptedData, $private_key, $openssl_padding); - - openssl_free_key($private_key); - - if(!$result) { - require_once 'Zend/InfoCard/Cipher/Exception.php'; - throw new Zend_InfoCard_Cipher_Exception("Unable to Decrypt Value using provided private key"); - } - - if($this->getPadding() == self::NO_PADDING) { - $decryptedData = substr($decryptedData, 2); - $start = strpos($decryptedData, 0) + 1; - $decryptedData = substr($decryptedData, $start); - } - - return $decryptedData; - } -} diff --git a/library/Zend/InfoCard/Cipher/Pki/Interface.php b/library/Zend/InfoCard/Cipher/Pki/Interface.php deleted file mode 100644 index 44e2716..0000000 --- a/library/Zend/InfoCard/Cipher/Pki/Interface.php +++ /dev/null @@ -1,33 +0,0 @@ - 0) { - $mcrypt_iv = substr($encryptedData, 0, $iv_length); - $encryptedData = substr($encryptedData, $iv_length); - } - - $decrypted = mcrypt_decrypt(self::MCRYPT_CIPHER, $decryptionKey, $encryptedData, self::MCRYPT_MODE, $mcrypt_iv); - - if(!$decrypted) { - require_once 'Zend/InfoCard/Cipher/Exception.php'; - throw new Zend_InfoCard_Cipher_Exception("Failed to decrypt data using AES256CBC Algorithm"); - } - - $decryptedLength = strlen($decrypted); - $paddingLength = substr($decrypted, $decryptedLength -1, 1); - $decrypted = substr($decrypted, 0, $decryptedLength - ord($paddingLength)); - - return rtrim($decrypted, "\0"); - } -} diff --git a/library/Zend/InfoCard/Cipher/Symmetric/Aes128cbc/Interface.php b/library/Zend/InfoCard/Cipher/Symmetric/Aes128cbc/Interface.php deleted file mode 100644 index 45027e6..0000000 --- a/library/Zend/InfoCard/Cipher/Symmetric/Aes128cbc/Interface.php +++ /dev/null @@ -1,38 +0,0 @@ -_isValid = true; - return $this; - } - - /** - * Retrieve the PPI (Private Personal Identifier) associated with the information card - * - * @return string the private personal identifier - */ - public function getCardID() - { - return $this->getClaim('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier'); - } - - /** - * Retrieves the default namespace used in this information card. If a default namespace was not - * set, it figures out which one to consider 'default' by taking the first namespace sorted by use-count - * in claims - * - * @throws Zend_InfoCard_Exception - * @return string The default namespace - */ - public function getDefaultNamespace() - { - if($this->_defaultNamespace === null) { - $namespaces = array(); - $leader = ''; - foreach($this->_claims as $claim) { - if(!isset($namespaces[$claim['namespace']])) { - $namespaces[$claim['namespace']] = 1; - } else { - $namespaces[$claim['namespace']]++; - } - - if(empty($leader) || ($namespaces[$claim['namespace']] > $leader)) { - $leader = $claim['namespace']; - } - } - - if(empty($leader)) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Failed to determine default namespace"); - } - - $this->setDefaultNamespace($leader); - } - - return $this->_defaultNamespace; - } - - /** - * Set the default namespace, overriding any existing default - * - * @throws Zend_InfoCard_Exception - * @param string $namespace The default namespace to use - * @return Zend_InfoCard_Claims - */ - public function setDefaultNamespace($namespace) - { - - foreach($this->_claims as $claim) { - if($namespace == $claim['namespace']) { - $this->_defaultNamespace = $namespace; - return $this; - } - } - - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("At least one claim must exist in specified namespace to make it the default namespace"); - } - - /** - * Indicates if this claim object contains validated claims or not - * - * @return bool - */ - public function isValid() - { - return $this->_isValid; - } - - /** - * Set the error message contained within the claims object - * - * @param string $error The error message - * @return Zend_InfoCard_Claims - */ - public function setError($error) - { - $this->_error = $error; - $this->_isValid = false; - return $this; - } - - /** - * Retrieve the error message contained within the claims object - * - * @return string The error message - */ - public function getErrorMsg() - { - return $this->_error; - } - - /** - * Set the claims for the claims object. Can only be set once and is done - * by the component itself. Internal use only. - * - * @throws Zend_InfoCard_Exception - * @param array $claims - * @return Zend_InfoCard_Claims - */ - public function setClaims(Array $claims) - { - if($this->_claims !== null) { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Claim objects are read-only"); - } - - $this->_claims = $claims; - return $this; - } - - /** - * Set the result code of the claims object. - * - * @throws Zend_InfoCard_Exception - * @param int $code The result code - * @return Zend_InfoCard_Claims - */ - public function setCode($code) - { - switch($code) { - case self::RESULT_PROCESSING_FAILURE: - case self::RESULT_SUCCESS: - case self::RESULT_VALIDATION_FAILURE: - $this->_code = $code; - return $this; - } - - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Attempted to set unknown error code"); - } - - /** - * Gets the result code of the claims object - * - * @return integer The result code - */ - public function getCode() - { - return $this->_code; - } - - /** - * Get a claim by providing its complete claim URI - * - * @param string $claimURI The complete claim URI to retrieve - * @return mixed The claim matching that specific URI or null if not found - */ - public function getClaim($claimURI) - { - if($this->claimExists($claimURI)) { - return $this->_claims[$claimURI]['value']; - } - - return null; - } - - /** - * Indicates if a specific claim URI exists or not within the object - * - * @param string $claimURI The complete claim URI to check - * @return bool true if the claim exists, false if not found - */ - public function claimExists($claimURI) - { - return isset($this->_claims[$claimURI]); - } - - /** - * Magic helper function - * @throws Zend_InfoCard_Exception - */ - public function __unset($k) - { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Claim objects are read-only"); - } - - /** - * Magic helper function - */ - public function __isset($k) - { - return $this->claimExists("{$this->getDefaultNamespace()}/$k"); - } - - /** - * Magic helper function - */ - public function __get($k) - { - return $this->getClaim("{$this->getDefaultNamespace()}/$k"); - } - - /** - * Magic helper function - * @throws Zend_InfoCard_Exception - */ - public function __set($k, $v) - { - require_once 'Zend/InfoCard/Exception.php'; - throw new Zend_InfoCard_Exception("Claim objects are read-only"); - } -} diff --git a/library/Zend/InfoCard/Exception.php b/library/Zend/InfoCard/Exception.php deleted file mode 100644 index 82e3a82..0000000 --- a/library/Zend/InfoCard/Exception.php +++ /dev/null @@ -1,43 +0,0 @@ -asXML(); - } else if (is_string($xmlData)) { - $strXmlData = $xmlData; - } else { - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); - } - - $sxe = simplexml_load_string($strXmlData); - - $namespaces = $sxe->getDocNameSpaces(); - - foreach($namespaces as $namespace) { - switch($namespace) { - case self::TYPE_SAML: - include_once 'Zend/InfoCard/Xml/Assertion/Saml.php'; - return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_Assertion_Saml', null); - } - } - - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Unable to determine Assertion type by Namespace"); - } -} diff --git a/library/Zend/InfoCard/Xml/Assertion/Interface.php b/library/Zend/InfoCard/Xml/Assertion/Interface.php deleted file mode 100644 index e4d71fe..0000000 --- a/library/Zend/InfoCard/Xml/Assertion/Interface.php +++ /dev/null @@ -1,69 +0,0 @@ - $conditionValue) { - switch(strtolower($condition)) { - case 'audiencerestrictioncondition': - - $serverName = $this->_getServerName(); - $serverPort = $this->_getServerPort(); - - $self_aliases[] = $serverName; - $self_aliases[] = "{{$serverName}:{$serverPort}"; - - $found = false; - if(is_array($conditionValue)) { - foreach($conditionValue as $audience) { - - list(,,$audience) = explode('/', $audience); - if(in_array($audience, $self_aliases)) { - $found = true; - break; - } - } - } - - if(!$found) { - return array($condition, 'Could not find self in allowed audience list'); - } - - break; - case 'notbefore': - $notbeforetime = strtotime($conditionValue); - - if($currentTime < $notbeforetime) { - if($currentTime + self::CONDITION_TIME_ADJ < $notbeforetime) { - return array($condition, 'Current time is before specified window'); - } - } - - break; - case 'notonorafter': - $notonoraftertime = strtotime($conditionValue); - - if($currentTime >= $notonoraftertime) { - if($currentTime - self::CONDITION_TIME_ADJ >= $notonoraftertime) { - return array($condition, 'Current time is after specified window'); - } - } - - break; - - } - } - } - return true; - } - - /** - * Get the Assertion URI for this type of Assertion - * - * @return string the Assertion URI - */ - public function getAssertionURI() - { - return Zend_InfoCard_Xml_Assertion::TYPE_SAML; - } - - /** - * Get the Major Version of the SAML Assertion - * - * @return integer The major version number - */ - public function getMajorVersion() - { - return (int)(string)$this['MajorVersion']; - } - - /** - * The Minor Version of the SAML Assertion - * - * @return integer The minor version number - */ - public function getMinorVersion() - { - return (int)(string)$this['MinorVersion']; - } - - /** - * Get the Assertion ID of the assertion - * - * @return string The Assertion ID - */ - public function getAssertionID() - { - return (string)$this['AssertionID']; - } - - /** - * Get the Issuer URI of the assertion - * - * @return string the URI of the assertion Issuer - */ - public function getIssuer() - { - return (string)$this['Issuer']; - } - - /** - * Get the Timestamp of when the assertion was issued - * - * @return integer a UNIX timestamp representing when the assertion was issued - */ - public function getIssuedTimestamp() - { - return strtotime((string)$this['IssueInstant']); - } - - /** - * Return an array of conditions which the assertions are predicated on - * - * @throws Zend_InfoCard_Xml_Exception - * @return array an array of conditions - */ - public function getConditions() - { - - list($conditions) = $this->xpath("//saml:Conditions"); - - if(!($conditions instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the saml:Conditions block"); - } - - $retval = array(); - - foreach($conditions->children('urn:oasis:names:tc:SAML:1.0:assertion') as $key => $value) { - switch($key) { - case self::CONDITION_AUDIENCE: - foreach($value->children('urn:oasis:names:tc:SAML:1.0:assertion') as $audience_key => $audience_value) { - if($audience_key == 'Audience') { - $retval[$key][] = (string)$audience_value; - } - } - break; - } - } - - $retval['NotBefore'] = (string)$conditions['NotBefore']; - $retval['NotOnOrAfter'] = (string)$conditions['NotOnOrAfter']; - - return $retval; - } - - /** - * Get they KeyInfo element for the Subject KeyInfo block - * - * @todo Not Yet Implemented - * @ignore - */ - public function getSubjectKeyInfo() - { - /** - * @todo Not sure if this is part of the scope for now.. - */ - - if($this->getConfirmationMethod() == self::CONFIRMATION_BEARER) { - throw new Zend_InfoCard_Xml_Exception("Cannot get Subject Key Info when Confirmation Method was Bearer"); - } - } - - /** - * Return the Confirmation Method URI used in the Assertion - * - * @return string The confirmation method URI - */ - public function getConfirmationMethod() - { - list($confirmation) = $this->xPath("//saml:ConfirmationMethod"); - return (string)$confirmation; - } - - /** - * Return an array of attributes (claims) contained within the assertion - * - * @return array An array of attributes / claims within the assertion - */ - public function getAttributes() - { - $attributes = $this->xPath('//saml:Attribute'); - - $retval = array(); - foreach($attributes as $key => $value) { - - $retkey = (string)$value['AttributeNamespace'].'/'.(string)$value['AttributeName']; - - $retval[$retkey]['name'] = (string)$value['AttributeName']; - $retval[$retkey]['namespace'] = (string)$value['AttributeNamespace']; - - list($aValue) = $value->children('urn:oasis:names:tc:SAML:1.0:assertion'); - $retval[$retkey]['value'] = (string)$aValue; - } - - return $retval; - } -} diff --git a/library/Zend/InfoCard/Xml/Element.php b/library/Zend/InfoCard/Xml/Element.php deleted file mode 100644 index c91d781..0000000 --- a/library/Zend/InfoCard/Xml/Element.php +++ /dev/null @@ -1,107 +0,0 @@ -asXML(); - } - - /** - * Converts an XML Element object into a DOM object - * - * @throws Zend_InfoCard_Xml_Exception - * @param Zend_InfoCard_Xml_Element $e The object to convert - * @return DOMElement A DOMElement representation of the same object - */ - static public function convertToDOM(Zend_InfoCard_Xml_Element $e) - { - $dom = dom_import_simplexml($e); - - if(!($dom instanceof DOMElement)) { - // Zend_InfoCard_Xml_Element exntes SimpleXMLElement, so this should *never* fail - // @codeCoverageIgnoreStart - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Failed to convert between SimpleXML and DOM"); - // @codeCoverageIgnoreEnd - } - - return $dom; - } - - /** - * Converts a DOMElement object into the specific class - * - * @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) - * @return Zend_InfoCard_Xml_Element a Xml Element object from the DOM element - */ - static public function convertToObject(DOMElement $e, $classname) - { - if (!class_exists($classname)) { - require_once 'Zend/Loader.php'; - Zend_Loader::loadClass($classname); - } - - $reflection = new ReflectionClass($classname); - - if(!$reflection->isSubclassOf('Zend_InfoCard_Xml_Element')) { - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element"); - } - - $sxe = simplexml_import_dom($e, $classname); - - if(!($sxe instanceof Zend_InfoCard_Xml_Element)) { - // Since we just checked to see if this was a subclass of Zend_infoCard_Xml_Element this shoudl never fail - // @codeCoverageIgnoreStart - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Failed to convert between DOM and SimpleXML"); - // @codeCoverageIgnoreEnd - } - - return $sxe; - } -} diff --git a/library/Zend/InfoCard/Xml/Element/Interface.php b/library/Zend/InfoCard/Xml/Element/Interface.php deleted file mode 100644 index 2bd1dd5..0000000 --- a/library/Zend/InfoCard/Xml/Element/Interface.php +++ /dev/null @@ -1,44 +0,0 @@ -asXML(); - } else if (is_string($xmlData)) { - $strXmlData = $xmlData; - } else { - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); - } - - $sxe = simplexml_load_string($strXmlData); - - switch($sxe['Type']) { - case 'http://www.w3.org/2001/04/xmlenc#Element': - include_once 'Zend/InfoCard/Xml/EncryptedData/XmlEnc.php'; - return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_EncryptedData_XmlEnc'); - default: - require_once 'Zend/InfoCard/Xml/Exception.php'; - throw new Zend_InfoCard_Xml_Exception("Unknown EncryptedData type found"); - break; - } - } -} diff --git a/library/Zend/InfoCard/Xml/EncryptedData/Abstract.php b/library/Zend/InfoCard/Xml/EncryptedData/Abstract.php deleted file mode 100644 index 3113d3a..0000000 --- a/library/Zend/InfoCard/Xml/EncryptedData/Abstract.php +++ /dev/null @@ -1,92 +0,0 @@ -KeyInfo[0]); - } - - /** - * Return the Encryption method used to encrypt the assertion document - * (the symmetric cipher) - * - * @throws Zend_InfoCard_Xml_Exception - * @return string The URI of the Symmetric Encryption Method used - */ - public function getEncryptionMethod() - { - - /** - * @todo This is pretty hacky unless we can always be confident that the first - * EncryptionMethod block is the correct one (the AES or compariable symetric algorithm).. - * the second is the PK method if provided. - */ - list($encryption_method) = $this->xpath("//enc:EncryptionMethod"); - - if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the enc:EncryptionMethod symmetric encryption block"); - } - - $dom = self::convertToDOM($encryption_method); - - if(!$dom->hasAttribute('Algorithm')) { - throw new Zend_InfoCard_Xml_Exception("Unable to determine the encryption algorithm in the Symmetric enc:EncryptionMethod XML block"); - } - - return $dom->getAttribute('Algorithm'); - } - - /** - * Returns the value of the encrypted block - * - * @return string the value of the encrypted CipherValue block - */ - abstract function getCipherValue(); -} diff --git a/library/Zend/InfoCard/Xml/EncryptedData/XmlEnc.php b/library/Zend/InfoCard/Xml/EncryptedData/XmlEnc.php deleted file mode 100644 index c454646..0000000 --- a/library/Zend/InfoCard/Xml/EncryptedData/XmlEnc.php +++ /dev/null @@ -1,64 +0,0 @@ -registerXPathNamespace('enc', 'http://www.w3.org/2001/04/xmlenc#'); - - list(,$cipherdata) = $this->xpath("//enc:CipherData"); - - if(!($cipherdata instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the enc:CipherData block"); - } - $cipherdata->registerXPathNamespace('enc', 'http://www.w3.org/2001/04/xmlenc#'); - list(,$ciphervalue) = $cipherdata->xpath("//enc:CipherValue"); - - if(!($ciphervalue instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to fidn the enc:CipherValue block"); - } - - return (string)$ciphervalue; - } -} diff --git a/library/Zend/InfoCard/Xml/EncryptedKey.php b/library/Zend/InfoCard/Xml/EncryptedKey.php deleted file mode 100644 index d1f6560..0000000 --- a/library/Zend/InfoCard/Xml/EncryptedKey.php +++ /dev/null @@ -1,174 +0,0 @@ -asXML(); - } else if (is_string($xmlData)) { - $strXmlData = $xmlData; - } else { - throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); - } - - $sxe = simplexml_load_string($strXmlData); - - if($sxe->getName() != "EncryptedKey") { - throw new Zend_InfoCard_Xml_Exception("Invalid XML Block provided for EncryptedKey"); - } - - return simplexml_load_string($strXmlData, "Zend_InfoCard_Xml_EncryptedKey"); - } - - /** - * Returns the Encyption Method Algorithm URI of the block - * - * @throws Zend_InfoCard_Xml_Exception - * @return string the Encryption method algorithm URI - */ - public function getEncryptionMethod() - { - - $this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#'); - list($encryption_method) = $this->xpath("//e:EncryptionMethod"); - - if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the e:EncryptionMethod KeyInfo encryption block"); - } - - $dom = self::convertToDOM($encryption_method); - - if(!$dom->hasAttribute('Algorithm')) { - throw new Zend_InfoCard_Xml_Exception("Unable to determine the encryption algorithm in the Symmetric enc:EncryptionMethod XML block"); - } - - return $dom->getAttribute('Algorithm'); - - } - - /** - * Returns the Digest Method Algorithm URI used - * - * @throws Zend_InfoCard_Xml_Exception - * @return string the Digest Method Algorithm URI - */ - public function getDigestMethod() - { - $this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#'); - list($encryption_method) = $this->xpath("//e:EncryptionMethod"); - - if(!($encryption_method instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the e:EncryptionMethod KeyInfo encryption block"); - } - - if(!($encryption_method->DigestMethod instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the DigestMethod block"); - } - - $dom = self::convertToDOM($encryption_method->DigestMethod); - - if(!$dom->hasAttribute('Algorithm')) { - throw new Zend_InfoCard_Xml_Exception("Unable to determine the digest algorithm for the symmetric Keyinfo"); - } - - return $dom->getAttribute('Algorithm'); - - } - - /** - * Returns the KeyInfo block object - * - * @throws Zend_InfoCard_Xml_Exception - * @return Zend_InfoCard_Xml_KeyInfo_Abstract - */ - public function getKeyInfo() - { - - if(isset($this->KeyInfo)) { - return Zend_InfoCard_Xml_KeyInfo::getInstance($this->KeyInfo); - } - - throw new Zend_InfoCard_Xml_Exception("Unable to locate a KeyInfo block"); - } - - /** - * Return the encrypted value of the block in base64 format - * - * @throws Zend_InfoCard_Xml_Exception - * @return string The Value of the CipherValue block in base64 format - */ - public function getCipherValue() - { - - $this->registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#'); - - list($cipherdata) = $this->xpath("//e:CipherData"); - - if(!($cipherdata instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to find the e:CipherData block"); - } - - $cipherdata->registerXPathNameSpace('enc', 'http://www.w3.org/2001/04/xmlenc#'); - list($ciphervalue) = $cipherdata->xpath("//enc:CipherValue"); - - if(!($ciphervalue instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Unable to fidn the enc:CipherValue block"); - } - - return (string)$ciphervalue; - } -} diff --git a/library/Zend/InfoCard/Xml/Exception.php b/library/Zend/InfoCard/Xml/Exception.php deleted file mode 100644 index 1c0492b..0000000 --- a/library/Zend/InfoCard/Xml/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ -asXML(); - } else if (is_string($xmlData)) { - $strXmlData = $xmlData; - } else { - throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); - } - - $sxe = simplexml_load_string($strXmlData); - - $namespaces = $sxe->getDocNameSpaces(); - - if(!empty($namespaces)) { - foreach($sxe->getDocNameSpaces() as $namespace) { - switch($namespace) { - case 'http://www.w3.org/2000/09/xmldsig#': - include_once 'Zend/InfoCard/Xml/KeyInfo/XmlDSig.php'; - return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig'); - default: - - throw new Zend_InfoCard_Xml_Exception("Unknown KeyInfo Namespace provided"); - // We are ignoring these lines, as XDebug reports each as a "non executed" line - // which breaks my coverage % - // @codeCoverageIgnoreStart - } - } - } - // @codeCoverageIgnoreEnd - - include_once 'Zend/InfoCard/Xml/KeyInfo/Default.php'; - return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_Default'); - } -} diff --git a/library/Zend/InfoCard/Xml/KeyInfo/Abstract.php b/library/Zend/InfoCard/Xml/KeyInfo/Abstract.php deleted file mode 100644 index 2f0d428..0000000 --- a/library/Zend/InfoCard/Xml/KeyInfo/Abstract.php +++ /dev/null @@ -1,37 +0,0 @@ - block which doesn't provide a namespace - * In this context, it is assumed to mean that it is the type of KeyInfo block which - * contains the SecurityTokenReference - * - * @category Zend - * @package Zend_InfoCard - * @subpackage Zend_InfoCard_Xml - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_InfoCard_Xml_KeyInfo_Default extends Zend_InfoCard_Xml_KeyInfo_Abstract -{ - /** - * Returns the object representation of the SecurityTokenReference block - * - * @throws Zend_InfoCard_Xml_Exception - * @return Zend_InfoCard_Xml_SecurityTokenReference - */ - public function getSecurityTokenReference() - { - $this->registerXPathNamespace('o', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); - - list($sectokenref) = $this->xpath('//o:SecurityTokenReference'); - - if(!($sectokenref instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception('Could not locate the Security Token Reference'); - } - - return Zend_InfoCard_Xml_SecurityTokenReference::getInstance($sectokenref); - } -} diff --git a/library/Zend/InfoCard/Xml/KeyInfo/Interface.php b/library/Zend/InfoCard/Xml/KeyInfo/Interface.php deleted file mode 100644 index 369db48..0000000 --- a/library/Zend/InfoCard/Xml/KeyInfo/Interface.php +++ /dev/null @@ -1,38 +0,0 @@ -registerXPathNamespace('e', 'http://www.w3.org/2001/04/xmlenc#'); - list($encryptedkey) = $this->xpath('//e:EncryptedKey'); - - if(!($encryptedkey instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Failed to retrieve encrypted key"); - } - - return Zend_InfoCard_Xml_EncryptedKey::getInstance($encryptedkey); - } - - /** - * Returns the KeyInfo Block within the encrypted key - * - * @return Zend_InfoCard_Xml_KeyInfo_Default - */ - public function getKeyInfo() - { - return $this->getEncryptedKey()->getKeyInfo(); - } -} diff --git a/library/Zend/InfoCard/Xml/Security.php b/library/Zend/InfoCard/Xml/Security.php deleted file mode 100644 index a20988d..0000000 --- a/library/Zend/InfoCard/Xml/Security.php +++ /dev/null @@ -1,327 +0,0 @@ -Signature)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Could not identify XML Signature element"); - } - - if(!isset($sxe->Signature->SignedInfo)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a SignedInfo block"); - } - - if(!isset($sxe->Signature->SignatureValue)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a SignatureValue block"); - } - - if(!isset($sxe->Signature->KeyInfo)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a KeyInfo block"); - } - - if(!isset($sxe->Signature->KeyInfo->KeyValue)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Signature is missing a KeyValue block"); - } - - switch((string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm']) { - case self::CANONICAL_METHOD_C14N_EXC: - $cMethod = (string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm']; - break; - default: - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported CanonicalizationMethod Requested"); - break; - } - - switch((string)$sxe->Signature->SignedInfo->SignatureMethod['Algorithm']) { - case self::SIGNATURE_METHOD_SHA1: - $sMethod = (string)$sxe->Signature->SignedInfo->SignatureMethod['Algorithm']; - break; - default: - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported SignatureMethod Requested"); - break; - } - - switch((string)$sxe->Signature->SignedInfo->Reference->DigestMethod['Algorithm']) { - case self::DIGEST_METHOD_SHA1: - $dMethod = (string)$sxe->Signature->SignedInfo->Reference->DigestMethod['Algorithm']; - break; - default: - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Unknown or unsupported DigestMethod Requested"); - break; - } - - $base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>='); - - if ($base64DecodeSupportsStrictParam) { - $dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue, true); - } else { - $dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue); - } - - if ($base64DecodeSupportsStrictParam) { - $signatureValue = base64_decode((string)$sxe->Signature->SignatureValue, true); - } else { - $signatureValue = base64_decode((string)$sxe->Signature->SignatureValue); - } - - $transformer = new Zend_InfoCard_Xml_Security_Transform(); - - foreach($sxe->Signature->SignedInfo->Reference->Transforms->children() as $transform) { - $transformer->addTransform((string)$transform['Algorithm']); - } - - $transformed_xml = $transformer->applyTransforms($strXMLInput); - - $transformed_xml_binhash = pack("H*", sha1($transformed_xml)); - - if(!self::_secureStringCompare($transformed_xml_binhash, $dValue)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Locally Transformed XML does not match XML Document. Cannot Verify Signature"); - } - - $public_key = null; - - switch(true) { - case isset($sxe->Signature->KeyInfo->KeyValue->X509Certificate): - - $certificate = (string)$sxe->Signature->KeyInfo->KeyValue->X509Certificate; - - - $pem = "-----BEGIN CERTIFICATE-----\n" . - wordwrap($certificate, 64, "\n", true) . - "\n-----END CERTIFICATE-----"; - - $public_key = openssl_pkey_get_public($pem); - - if(!$public_key) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Unable to extract and prcoess X509 Certificate from KeyValue"); - } - - break; - case isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue): - - if(!isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Modulus) || - !isset($sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Exponent)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("RSA Key Value not in Modulus/Exponent form"); - } - - $modulus = base64_decode((string)$sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Modulus); - $exponent = base64_decode((string)$sxe->Signature->KeyInfo->KeyValue->RSAKeyValue->Exponent); - - $pem_public_key = self::_getPublicKeyFromModExp($modulus, $exponent); - - $public_key = openssl_pkey_get_public ($pem_public_key); - - break; - default: - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Unable to determine or unsupported representation of the KeyValue block"); - } - - $transformer = new Zend_InfoCard_Xml_Security_Transform(); - $transformer->addTransform((string)$sxe->Signature->SignedInfo->CanonicalizationMethod['Algorithm']); - - // The way we are doing our XML processing requires that we specifically add this - // (even though it's in the parent-block).. otherwise, our canonical form - // fails signature verification - $sxe->Signature->SignedInfo->addAttribute('xmlns', 'http://www.w3.org/2000/09/xmldsig#'); - - $canonical_signedinfo = $transformer->applyTransforms($sxe->Signature->SignedInfo->asXML()); - - if(@openssl_verify($canonical_signedinfo, $signatureValue, $public_key)) { - return (string)$sxe->Signature->SignedInfo->Reference['URI']; - } - - return false; - } - - /** - * Transform an RSA Key in Modulus/Exponent format into a PEM encoding and - * return an openssl resource for it - * - * @param string $modulus The RSA Modulus in binary format - * @param string $exponent The RSA exponent in binary format - * @return string The PEM encoded version of the key - */ - static protected function _getPublicKeyFromModExp($modulus, $exponent) - { - $modulusInteger = self::_encodeValue($modulus, self::ASN_TYPE_INTEGER); - $exponentInteger = self::_encodeValue($exponent, self::ASN_TYPE_INTEGER); - $modExpSequence = self::_encodeValue($modulusInteger . $exponentInteger, self::ASN_TYPE_SEQUENCE); - $modExpBitString = self::_encodeValue($modExpSequence, self::ASN_TYPE_BITSTRING); - - $binRsaKeyIdentifier = pack( "H*", self::RSA_KEY_IDENTIFIER ); - - $publicKeySequence = self::_encodeValue($binRsaKeyIdentifier . $modExpBitString, self::ASN_TYPE_SEQUENCE); - - $publicKeyInfoBase64 = base64_encode( $publicKeySequence ); - - $publicKeyString = "-----BEGIN PUBLIC KEY-----\n"; - $publicKeyString .= wordwrap($publicKeyInfoBase64, 64, "\n", true); - $publicKeyString .= "\n-----END PUBLIC KEY-----\n"; - - return $publicKeyString; - } - - /** - * Encode a limited set of data types into ASN.1 encoding format - * which is used in X.509 certificates - * - * @param string $data The data to encode - * @param const $type The encoding format constant - * @return string The encoded value - * @throws Zend_InfoCard_Xml_Security_Exception - */ - static protected function _encodeValue($data, $type) - { - // Null pad some data when we get it (integer values > 128 and bitstrings) - if( (($type == self::ASN_TYPE_INTEGER) && (ord($data) > 0x7f)) || - ($type == self::ASN_TYPE_BITSTRING)) { - $data = "\0$data"; - } - - $len = strlen($data); - - // encode the value based on length of the string - // I'm fairly confident that this is by no means a complete implementation - // but it is enough for our purposes - switch(true) { - case ($len < 128): - return sprintf("%c%c%s", $type, $len, $data); - case ($len < 0x0100): - return sprintf("%c%c%c%s", $type, 0x81, $len, $data); - case ($len < 0x010000): - return sprintf("%c%c%c%c%s", $type, 0x82, $len / 0x0100, $len % 0x0100, $data); - default: - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Could not encode value"); - } - - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Invalid code path"); - } - - /** - * Securely compare two strings for equality while avoided C level memcmp() - * optimisations capable of leaking timing information useful to an attacker - * attempting to iteratively guess the unknown string (e.g. password) being - * compared against. - * - * @param string $a - * @param string $b - * @return bool - */ - static protected function _secureStringCompare($a, $b) - { - if (strlen($a) !== strlen($b)) { - return false; - } - $result = 0; - for ($i = 0; $i < strlen($a); $i++) { - $result |= ord($a[$i]) ^ ord($b[$i]); - } - return $result == 0; - } -} diff --git a/library/Zend/InfoCard/Xml/Security/Exception.php b/library/Zend/InfoCard/Xml/Security/Exception.php deleted file mode 100644 index 7030af8..0000000 --- a/library/Zend/InfoCard/Xml/Security/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ -_findClassbyURI($uri); - - $this->_transformList[] = array('uri' => $uri, - 'class' => $class); - return $this; - } - - /** - * Return the list of transforms to perform - * - * @return array The list of transforms - */ - public function getTransformList() - { - return $this->_transformList; - } - - /** - * Apply the transforms in the transform list to the input XML document - * - * @param string $strXmlDocument The input XML - * @return string The XML after the transformations have been applied - */ - public function applyTransforms($strXmlDocument) - { - foreach($this->_transformList as $transform) { - if (!class_exists($transform['class'])) { - require_once 'Zend/Loader.php'; - Zend_Loader::loadClass($transform['class']); - } - - $transformer = new $transform['class']; - - // We can't really test this check because it would require logic changes in the component itself - // @codeCoverageIgnoreStart - if(!($transformer instanceof Zend_InfoCard_Xml_Security_Transform_Interface)) { - require_once 'Zend/InfoCard/Xml/Security/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Exception("Transforms must implement the Transform Interface"); - } - // @codeCoverageIgnoreEnd - - $strXmlDocument = $transformer->transform($strXmlDocument); - } - - return $strXmlDocument; - } -} diff --git a/library/Zend/InfoCard/Xml/Security/Transform/EnvelopedSignature.php b/library/Zend/InfoCard/Xml/Security/Transform/EnvelopedSignature.php deleted file mode 100644 index b6f3b0a..0000000 --- a/library/Zend/InfoCard/Xml/Security/Transform/EnvelopedSignature.php +++ /dev/null @@ -1,60 +0,0 @@ -Signature) { - require_once 'Zend/InfoCard/Xml/Security/Transform/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Transform_Exception("Unable to locate Signature Block for EnvelopedSignature Transform"); - } - - unset($sxe->Signature); - - return $sxe->asXML(); - } -} diff --git a/library/Zend/InfoCard/Xml/Security/Transform/Exception.php b/library/Zend/InfoCard/Xml/Security/Transform/Exception.php deleted file mode 100644 index 69912bf..0000000 --- a/library/Zend/InfoCard/Xml/Security/Transform/Exception.php +++ /dev/null @@ -1,37 +0,0 @@ -loadXML($strXMLData); - - if(method_exists($dom, 'C14N')) { - return $dom->C14N(true, false); - } - - require_once 'Zend/InfoCard/Xml/Security/Transform/Exception.php'; - throw new Zend_InfoCard_Xml_Security_Transform_Exception("This transform requires the C14N() method to exist in the DOM extension"); - } -} diff --git a/library/Zend/InfoCard/Xml/SecurityTokenReference.php b/library/Zend/InfoCard/Xml/SecurityTokenReference.php deleted file mode 100644 index 2943056..0000000 --- a/library/Zend/InfoCard/Xml/SecurityTokenReference.php +++ /dev/null @@ -1,173 +0,0 @@ -asXML(); - } else if (is_string($xmlData)) { - $strXmlData = $xmlData; - } else { - throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance"); - } - - $sxe = simplexml_load_string($strXmlData); - - if($sxe->getName() != "SecurityTokenReference") { - throw new Zend_InfoCard_Xml_Exception("Invalid XML Block provided for SecurityTokenReference"); - } - - return simplexml_load_string($strXmlData, "Zend_InfoCard_Xml_SecurityTokenReference"); - } - - /** - * Return the Key Identifier XML Object - * - * @return Zend_InfoCard_Xml_Element - * @throws Zend_InfoCard_Xml_Exception - */ - protected function _getKeyIdentifier() - { - $this->registerXPathNamespace('o', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'); - list($keyident) = $this->xpath('//o:KeyIdentifier'); - - if(!($keyident instanceof Zend_InfoCard_Xml_Element)) { - throw new Zend_InfoCard_Xml_Exception("Failed to retrieve Key Identifier"); - } - - return $keyident; - } - - /** - * Return the Key URI identifying the thumbprint type used - * - * @return string The thumbprint type URI - * @throws Zend_InfoCard_Xml_Exception - */ - public function getKeyThumbprintType() - { - - $keyident = $this->_getKeyIdentifier(); - - $dom = self::convertToDOM($keyident); - - if(!$dom->hasAttribute('ValueType')) { - throw new Zend_InfoCard_Xml_Exception("Key Identifier did not provide a type for the value"); - } - - return $dom->getAttribute('ValueType'); - } - - - /** - * Return the thumbprint encoding type used as a URI - * - * @return string the URI of the thumbprint encoding used - * @throws Zend_InfoCard_Xml_Exception - */ - public function getKeyThumbprintEncodingType() - { - - $keyident = $this->_getKeyIdentifier(); - - $dom = self::convertToDOM($keyident); - - if(!$dom->hasAttribute('EncodingType')) { - throw new Zend_InfoCard_Xml_Exception("Unable to determine the encoding type for the key identifier"); - } - - return $dom->getAttribute('EncodingType'); - } - - /** - * Get the key reference data used to identify the public key - * - * @param bool $decode if true, will return a decoded version of the key - * @return string the key reference thumbprint, either in binary or encoded form - * @throws Zend_InfoCard_Xml_Exception - */ - public function getKeyReference($decode = true) - { - $keyIdentifier = $this->_getKeyIdentifier(); - - $dom = self::convertToDOM($keyIdentifier); - $encoded = $dom->nodeValue; - - if(empty($encoded)) { - throw new Zend_InfoCard_Xml_Exception("Could not find the Key Reference Encoded Value"); - } - - if($decode) { - - $decoded = ""; - switch($this->getKeyThumbprintEncodingType()) { - case self::ENCODING_BASE64BIN: - - if(version_compare(PHP_VERSION, "5.2.0", ">=")) { - $decoded = base64_decode($encoded, true); - } else { - $decoded = base64_decode($encoded); - } - - break; - default: - throw new Zend_InfoCard_Xml_Exception("Unknown Key Reference Encoding Type: {$this->getKeyThumbprintEncodingType()}"); - } - - if(!$decoded || empty($decoded)) { - throw new Zend_InfoCard_Xml_Exception("Failed to decode key reference"); - } - - return $decoded; - } - - return $encoded; - } -} diff --git a/library/Zend/Service/Nirvanix.php b/library/Zend/Service/Nirvanix.php deleted file mode 100644 index 542430d..0000000 --- a/library/Zend/Service/Nirvanix.php +++ /dev/null @@ -1,107 +0,0 @@ - array(), - 'httpClient' => new Zend_Http_Client(), - 'host' => 'http://services.nirvanix.com'); - $this->_options = array_merge($defaultOptions, $options); - - // login and save sessionToken to default POST params - $resp = $this->getService('Authentication')->login($authParams); - $this->_options['defaults']['sessionToken'] = (string)$resp->SessionToken; - } - - /** - * Nirvanix divides its service into namespaces, with each namespace - * providing different functionality. This is a factory method that - * returns a preconfigured Zend_Service_Nirvanix_Namespace_Base proxy. - * - * @param string $namespace Name of the namespace - * @return Zend_Service_Nirvanix_Namespace_Base - */ - public function getService($namespace, $options = array()) - { - switch ($namespace) { - case 'IMFS': - $class = 'Zend_Service_Nirvanix_Namespace_Imfs'; - break; - default: - $class = 'Zend_Service_Nirvanix_Namespace_Base'; - } - - $options['namespace'] = ucfirst($namespace); - $options = array_merge($this->_options, $options); - - if (!class_exists($class)) { - require_once 'Zend/Loader.php'; - Zend_Loader::loadClass($class); - } - return new $class($options); - } - - /** - * Get the configured options. - * - * @return array - */ - public function getOptions() - { - return $this->_options; - } - -} diff --git a/library/Zend/Service/Nirvanix/Exception.php b/library/Zend/Service/Nirvanix/Exception.php deleted file mode 100644 index 580f2e8..0000000 --- a/library/Zend/Service/Nirvanix/Exception.php +++ /dev/null @@ -1,36 +0,0 @@ -_host = $options['baseUrl']; - } - - if (isset($options['namespace'])) { - $this->_namespace = $options['namespace']; - } - - if (isset($options['defaults'])) { - $this->_defaults = $options['defaults']; - } - - if (! isset($options['httpClient'])) { - $options['httpClient'] = new Zend_Http_Client(); - } - $this->_httpClient = $options['httpClient']; - } - - /** - * When a method call is made against this proxy, convert it to - * an HTTP request to make against the Nirvanix REST service. - * - * $imfs->DeleteFiles(array('filePath' => 'foo')); - * - * Assuming this object was proxying the IMFS namespace, the - * method call above would call the DeleteFiles command. The - * POST parameters would be filePath, merged with the - * $this->_defaults (containing the sessionToken). - * - * @param string $methodName Name of the command to call - * on this namespace. - * @param array $args Only the first is used and it must be - * an array. It contains the POST params. - * - * @return Zend_Service_Nirvanix_Response - */ - public function __call($methodName, $args) - { - $uri = $this->_makeUri($methodName); - $this->_httpClient->setUri($uri); - - if (!isset($args[0]) || !is_array($args[0])) { - $args[0] = array(); - } - - $params = array_merge($this->_defaults, $args[0]); - $this->_httpClient->resetParameters(); - $this->_httpClient->setParameterPost($params); - - $httpResponse = $this->_httpClient->request(Zend_Http_Client::POST); - return $this->_wrapResponse($httpResponse); - } - - /** - * Return the HTTP client used for this namespace. This is useful - * for inspecting the last request or directly interacting with the - * HTTP client. - * - * @return Zend_Http_Client - */ - public function getHttpClient() - { - return $this->_httpClient; - } - - /** - * Make a complete URI from an RPC method name. All Nirvanix REST - * service URIs use the same format. - * - * @param string $methodName RPC method name - * @return string - */ - protected function _makeUri($methodName) - { - $methodName = ucfirst($methodName); - return "{$this->_host}/ws/{$this->_namespace}/{$methodName}.ashx"; - } - - /** - * All Nirvanix REST service calls return an XML payload. This method - * makes a Zend_Service_Nirvanix_Response from that XML payload. - * - * @param Zend_Http_Response $httpResponse Raw response from Nirvanix - * @return Zend_Service_Nirvanix_Response Wrapped response - */ - protected function _wrapResponse($httpResponse) - { - return new Zend_Service_Nirvanix_Response($httpResponse->getBody()); - } -} diff --git a/library/Zend/Service/Nirvanix/Namespace/Imfs.php b/library/Zend/Service/Nirvanix/Namespace/Imfs.php deleted file mode 100644 index eed6f29..0000000 --- a/library/Zend/Service/Nirvanix/Namespace/Imfs.php +++ /dev/null @@ -1,105 +0,0 @@ - $filePath, - 'expiration' => $expiration); - $resp = $this->getOptimalUrls($params); - $url = (string)$resp->Download->DownloadURL; - - // download the file - $this->_httpClient->resetParameters(); - $this->_httpClient->setUri($url); - $resp = $this->_httpClient->request(Zend_Http_Client::GET); - - return $resp->getBody(); - } - - /** - * Convenience function to put the contents of a string into - * the Nirvanix IMFS. Analog to PHP's file_put_contents(). - * - * @param string $filePath Remote path and filename - * @param integer $data Data to store in the file - * @param string $mimeType Mime type of data - * @return Zend_Service_Nirvanix_Response - */ - public function putContents($filePath, $data, $mimeType = null) - { - // get storage node for upload - $params = array('sizeBytes' => strlen($data)); - $resp = $this->getStorageNode($params); - $host = (string)$resp->GetStorageNode->UploadHost; - $uploadToken = (string)$resp->GetStorageNode->UploadToken; - - // http upload data into remote file - $this->_httpClient->resetParameters(); - $this->_httpClient->setUri("http://{$host}/Upload.ashx"); - $this->_httpClient->setParameterPost('uploadToken', $uploadToken); - $this->_httpClient->setParameterPost('destFolderPath', str_replace('\\', '/',dirname($filePath))); - $this->_httpClient->setFileUpload(basename($filePath), 'uploadFile', $data, $mimeType); - $response = $this->_httpClient->request(Zend_Http_Client::POST); - - return new Zend_Service_Nirvanix_Response($response->getBody()); - } - - /** - * Convenience function to remove a file from the Nirvanix IMFS. - * Analog to PHP's unlink(). - * - * @param string $filePath Remove path and filename - * @return Zend_Service_Nirvanix_Response - */ - public function unlink($filePath) - { - $params = array('filePath' => $filePath); - return $this->deleteFiles($params); - } - -} diff --git a/library/Zend/Service/Nirvanix/Response.php b/library/Zend/Service/Nirvanix/Response.php deleted file mode 100644 index cdf8063..0000000 --- a/library/Zend/Service/Nirvanix/Response.php +++ /dev/null @@ -1,123 +0,0 @@ - contains an error. - * - * @category Zend - * @package Zend_Service - * @subpackage Nirvanix - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -class Zend_Service_Nirvanix_Response -{ - /** - * SimpleXMLElement parsed from Nirvanix web service response. - * - * @var SimpleXMLElement - */ - protected $_sxml; - - /** - * Class constructor. Parse the XML response from a Nirvanix method - * call into a decorated SimpleXMLElement element. - * - * @param string $xml XML response string from Nirvanix - * @throws Zend_Service_Nirvanix_Exception - */ - public function __construct($xml) - { - $this->_sxml = @simplexml_load_string($xml); - - if (! $this->_sxml instanceof SimpleXMLElement) { - $this->_throwException("XML could not be parsed from response: $xml"); - } - - $name = $this->_sxml->getName(); - if ($name != 'Response') { - $this->_throwException("Expected XML element Response, got $name"); - } - - $code = (int)$this->_sxml->ResponseCode; - if ($code != 0) { - $msg = (string)$this->_sxml->ErrorMessage; - $this->_throwException($msg, $code); - } - } - - /** - * Return the SimpleXMLElement representing this response - * for direct access. - * - * @return SimpleXMLElement - */ - public function getSxml() - { - return $this->_sxml; - } - - /** - * Delegate undefined properties to the decorated SimpleXMLElement. - * - * @param string $offset Undefined property name - * @return mixed - */ - public function __get($offset) - { - return $this->_sxml->$offset; - } - - /** - * Delegate undefined methods to the decorated SimpleXMLElement. - * - * @param string $offset Underfined method name - * @param array $args Method arguments - * @return mixed - */ - public function __call($method, $args) - { - return call_user_func_array(array($this->_sxml, $method), $args); - } - - /** - * Throw an exception. This method exists to only contain the - * lazy-require() of the exception class. - * - * @param string $message Error message - * @param integer $code Error code - * @throws Zend_Service_Nirvanix_Exception - * @return void - */ - protected function _throwException($message, $code = null) - { - /** - * @see Zend_Service_Nirvanix_Exception - */ - require_once 'Zend/Service/Nirvanix/Exception.php'; - - throw new Zend_Service_Nirvanix_Exception($message, $code); - } - -} diff --git a/library/Zend/View/Helper/TinySrc.php b/library/Zend/View/Helper/TinySrc.php deleted file mode 100644 index 131065e..0000000 --- a/library/Zend/View/Helper/TinySrc.php +++ /dev/null @@ -1,317 +0,0 @@ - null, - 'format' => null, - 'width' => false, - 'height' => false, - 'create_tag' => true, - ); - - /** - * @var string Default image format to use - */ - protected $_format = ''; - - /** - * Generate a link or image tag pointing to tinysrc.net - * - * @param mixed $image - * @param array $options - * @return void - */ - public function tinySrc($image = null, array $options = array()) - { - if (null === $image) { - return $this; - } - - $defaultOptions = $this->_defaultOptions; - $defaultOptions['create_tag'] = $this->createTag(); - $options = array_merge($defaultOptions, $options); - - $url = '/' . $this->_mergeBaseUrl($options) . ltrim($image, '/'); - - $src = self::TINYSRC_BASE - . $this->_mergeFormat($options) - . $this->_mergeDimensions($options) - . $url; - - if (!$options['create_tag']) { - return $src; - } - - foreach (array_keys($this->_defaultOptions) as $key) { - switch ($key) { - case 'width': - case 'height': - if (!is_int($options[$key]) || !is_numeric($options[$key]) || $options[$key] < 0) { - unset($options[$key]); - } - break; - default: - unset($options[$key]); - break; - } - } - - $options['src'] = $src; - - $tag = '_htmlAttribs($options) . $this->getClosingBracket(); - return $tag; - } - - /** - * Set base URL for images - * - * @param string $url - * @return Zend_View_Helper_TinySrc - */ - public function setBaseUrl($url) - { - $this->_baseUrl = rtrim($url, '/') . '/'; - return $this; - } - - /** - * Get base URL for images - * - * If none already set, uses the ServerUrl and BaseUrl view helpers to - * determine the base URL to images. - * - * @return string - */ - public function getBaseUrl() - { - if (null === $this->_baseUrl) { - $this->setBaseUrl($this->view->serverUrl($this->view->baseUrl())); - } - return $this->_baseUrl; - } - - /** - * Set default image format - * - * If set, this will set the default format to use on all images. - * - * @param null|string $format - * @return Zend_View_Helper_TinySrc - * @throws Zend_View_Exception - */ - public function setDefaultFormat($format = null) - { - if (null === $format) { - $this->_format = ''; - return $this; - } - - $format = strtolower($format); - if (!in_array($format, array('png', 'jpeg'))) { - require_once 'Zend/View/Exception.php'; - throw new Zend_View_Exception('Invalid format; must be one of "jpeg" or "png"'); - } - $this->_format = "/$format"; - return $this; - } - - /** - * Set default dimensions - * - * If null is specified for width, default dimensions will be cleared. If - * only width is specified, only width will be used. If either dimension - * fails validation, an exception is raised. - * - * @param null|int|string $width - * @param null|int|string $height - * @return Zend_View_Helper_TinySrc - * @throws Zend_View_Exception - */ - public function setDefaultDimensions($width = null, $height = null) - { - if (null === $width) { - $this->_dimensions = ''; - return $this; - } - - if (!$this->_validateDimension($width)) { - require_once 'Zend/View/Exception.php'; - throw new Zend_View_Exception('Invalid dimension; must be an integer, optionally preceded by "-" or "x"'); - } - - $this->_dimensions = "/$width"; - if (null === $height) { - return $this; - } - - if (!$this->_validateDimension($height)) { - require_once 'Zend/View/Exception.php'; - throw new Zend_View_Exception('Invalid dimension; must be an integer, optionally preceded by "-" or "x"'); - } - $this->_dimensions .= "/$height"; - return $this; - } - - /** - * Set state of "create tag" flag - * - * @param bool $flag - * @return Zend_View_Helper_TinySrc - */ - public function setCreateTag($flag) - { - $this->_createTagFlag = (bool) $flag; - return $this; - } - - /** - * Should the helper create an image tag? - * - * @return bool - */ - public function createTag() - { - return $this->_createTagFlag; - } - - /** - * Validate a dimension - * - * Dimensions may be integers, optionally preceded by '-' or 'x'. - * - * @param string $dim - * @return bool - */ - protected function _validateDimension($dim) - { - if (!is_scalar($dim) || is_bool($dim)) { - return false; - } - return preg_match('/^(-|x)?\d+$/', (string) $dim); - } - - /** - * Determine whether to use default base URL, or base URL from options - * - * @param array $options - * @return string - */ - protected function _mergeBaseUrl(array $options) - { - if (null === $options['base_url']) { - return $this->getBaseUrl(); - } - return rtrim($options['base_url'], '/') . '/'; - } - - /** - * Determine whether to use default format or format provided in options. - * - * @param array $options - * @return string - */ - protected function _mergeFormat(array $options) - { - if (in_array($options['format'], array('png', 'jpeg'))) { - return '/' . $options['format']; - } - return $this->_format; - } - - /** - * Determine whether to use default dimensions, or those passed in options. - * - * @param array $options - * @return string - */ - protected function _mergeDimensions(array $options) - { - if (!$this->_validateDimension($options['width'])) { - return $this->_dimensions; - } - $dimensions = '/' . $options['width']; - if (!$this->_validateDimension($options['height'])) { - return $dimensions; - } - $dimensions .= '/' . $options['height']; - return $dimensions; - } -}