[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Service/WindowsAzure/Credentials/ -> SharedKeyLite.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Service_WindowsAzure
  17   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19   * @version    $Id$
  20   */
  21  
  22  /**
  23   * @see Zend_Service_WindowsAzure_Credentials_CredentialsAbstract
  24   */
  25  require_once 'Zend/Service/WindowsAzure/Credentials/CredentialsAbstract.php';
  26  
  27  /**
  28   * @see Zend_Service_WindowsAzure_Storage
  29   */
  30  require_once 'Zend/Service/WindowsAzure/Storage.php';
  31  
  32  /**
  33   * @see Zend_Service_WindowsAzure_Credentials_SharedKey
  34   */
  35  require_once 'Zend/Service/WindowsAzure/Credentials/SharedKey.php';
  36  
  37  /**
  38   * @category   Zend
  39   * @package    Zend_Service_WindowsAzure
  40   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  41   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  42   */ 
  43  class Zend_Service_WindowsAzure_Credentials_SharedKeyLite
  44      extends Zend_Service_WindowsAzure_Credentials_CredentialsAbstract
  45  {
  46      /**
  47       * Sign request URL with credentials
  48       *
  49       * @param string $requestUrl Request URL
  50       * @param string $resourceType Resource type
  51       * @param string $requiredPermission Required permission
  52       * @return string Signed request URL
  53       */
  54  	public function signRequestUrl(
  55          $requestUrl = '',
  56          $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN,
  57          $requiredPermission = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ
  58      ) {
  59          return $requestUrl;
  60      }
  61      
  62      /**
  63       * Sign request headers with credentials
  64       *
  65       * @param string $httpVerb HTTP verb the request will use
  66       * @param string $path Path for the request
  67       * @param string $queryString Query string for the request
  68       * @param array $headers x-ms headers to add
  69       * @param boolean $forTableStorage Is the request for table storage?
  70       * @param string $resourceType Resource type
  71       * @param string $requiredPermission Required permission
  72       * @return array Array of headers
  73       */
  74  	public function signRequestHeaders(
  75          $httpVerb = Zend_Http_Client::GET,
  76          $path = '/',
  77          $queryString = '',
  78          $headers = null,
  79          $forTableStorage = false,
  80          $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN,
  81          $requiredPermission = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ
  82      ) {
  83          // Determine path
  84          if ($this->_usePathStyleUri) {
  85              $path = substr($path, strpos($path, '/'));
  86          }
  87  
  88          // Determine query
  89          $queryString = $this->_prepareQueryStringForSigning($queryString);
  90  
  91          // Build canonicalized resource string
  92          $canonicalizedResource  = '/' . $this->_accountName;
  93          if ($this->_usePathStyleUri) {
  94              $canonicalizedResource .= '/' . $this->_accountName;
  95          }
  96          $canonicalizedResource .= $path;
  97          if ($queryString !== '') {
  98              $canonicalizedResource .= $queryString;
  99          }
 100  
 101          // Request date
 102          $requestDate = '';
 103          if (isset($headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date'])) {
 104              $requestDate = $headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date'];
 105          } else {
 106              $requestDate = gmdate('D, d M Y H:i:s', time()) . ' GMT'; // RFC 1123
 107          }
 108  
 109          // Create string to sign   
 110          $stringToSign   = array();
 111          $stringToSign[] = $requestDate; // Date
 112          $stringToSign[] = $canonicalizedResource;                     // Canonicalized resource
 113          $stringToSign   = implode("\n", $stringToSign);
 114          $signString     = base64_encode(hash_hmac('sha256', $stringToSign, $this->_accountKey, true));
 115  
 116          // Sign request
 117          $headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date'] = $requestDate;
 118          $headers['Authorization'] = 'SharedKeyLite ' . $this->_accountName . ':' . $signString;
 119          
 120          // Return headers
 121          return $headers;
 122      }
 123  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1