File indexing completed on 2025-01-26 05:25:25

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_Amazon
0017  * @subpackage Authentication
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 /**
0023  * @see Zend_Service_Amazon_Authentication
0024  */
0025 // require_once 'Zend/Service/Amazon/Authentication.php';
0026 
0027 /**
0028  * @see Zend_Crypt_Hmac
0029  */
0030 // require_once 'Zend/Crypt/Hmac.php';
0031 
0032 /**
0033  * @category   Zend
0034  * @package    Zend_Service_Amazon
0035  * @subpackage Authentication
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Service_Amazon_Authentication_V1 extends Zend_Service_Amazon_Authentication
0040 {
0041     /**
0042      * Signature Version
0043      */
0044     protected $_signatureVersion = '1';
0045 
0046     /**
0047      * Signature Encoding Method
0048      */
0049     protected $_signatureMethod = 'HmacSHA256';
0050 
0051     /**
0052      * Generate the required attributes for the signature
0053      * @param string $url
0054      * @param array $parameters
0055      * @return string
0056      */
0057     public function generateSignature($url, array &$parameters)
0058     {
0059         $parameters['AWSAccessKeyId']   = $this->_accessKey;
0060         $parameters['SignatureVersion'] = $this->_signatureVersion;
0061         $parameters['Version']          = $this->_apiVersion;
0062         if(!isset($parameters['Timestamp'])) {
0063             $parameters['Timestamp']    = gmdate('Y-m-d\TH:i:s\Z', time()+10);
0064         }
0065 
0066         $data = $this->_signParameters($url, $parameters);
0067 
0068         return $data;
0069     }
0070 
0071     /**
0072      * Computes the RFC 2104-compliant HMAC signature for request parameters
0073      *
0074      * This implements the Amazon Web Services signature, as per the following
0075      * specification:
0076      *
0077      * 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
0078      *    excluding <tt>Signature</tt>, the value of which is being created),
0079      *    ignoring case.
0080      *
0081      * 2. Iterate over the sorted list and append the parameter name (in its
0082      *    original case) and then its value. Do not URL-encode the parameter
0083      *    values before constructing this string. Do not use any separator
0084      *    characters when appending strings.
0085      *
0086      * @param  string $queue_url  Queue URL
0087      * @param  array  $parameters the parameters for which to get the signature.
0088      *
0089      * @return string the signed data.
0090      */
0091     protected function _signParameters($url, array &$paramaters)
0092     {
0093         $data = '';
0094 
0095         uksort($paramaters, 'strcasecmp');
0096         unset($paramaters['Signature']);
0097 
0098         foreach($paramaters as $key => $value) {
0099             $data .= $key . $value;
0100         }
0101 
0102         $hmac = Zend_Crypt_Hmac::compute($this->_secretKey, 'SHA1', $data, Zend_Crypt_Hmac::BINARY);
0103 
0104         $paramaters['Signature'] = base64_encode($hmac);
0105 
0106         return $data;
0107     }
0108 }