[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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_Http_Client 34 */ 35 require_once 'Zend/Http/Client.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_SharedKey 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 // http://github.com/sriramk/winazurestorage/blob/214010a2f8931bac9c96dfeb337d56fe084ca63b/winazurestorage.py 84 85 // Determine path 86 if ($this->_usePathStyleUri) { 87 $path = substr($path, strpos($path, '/')); 88 } 89 90 // Determine query 91 $queryString = $this->_prepareQueryStringForSigning($queryString); 92 93 // Canonicalized headers 94 $canonicalizedHeaders = array(); 95 96 // Request date 97 $requestDate = ''; 98 if (isset($headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date'])) { 99 $requestDate = $headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date']; 100 } else { 101 $requestDate = gmdate('D, d M Y H:i:s', time()) . ' GMT'; // RFC 1123 102 $canonicalizedHeaders[] = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date:' . $requestDate; 103 } 104 105 // Build canonicalized headers 106 if (!is_null($headers)) { 107 foreach ($headers as $header => $value) { 108 if (is_bool($value)) { 109 $value = $value === true ? 'True' : 'False'; 110 } 111 112 $headers[$header] = $value; 113 if (substr($header, 0, strlen(Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER)) == Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER) { 114 $canonicalizedHeaders[] = strtolower($header) . ':' . $value; 115 } 116 } 117 } 118 sort($canonicalizedHeaders); 119 120 // Build canonicalized resource string 121 $canonicalizedResource = '/' . $this->_accountName; 122 if ($this->_usePathStyleUri) { 123 $canonicalizedResource .= '/' . $this->_accountName; 124 } 125 $canonicalizedResource .= $path; 126 if ($queryString !== '') { 127 $canonicalizedResource .= $queryString; 128 } 129 130 // Create string to sign 131 $stringToSign = array(); 132 $stringToSign[] = strtoupper($httpVerb); // VERB 133 $stringToSign[] = ""; // Content-MD5 134 $stringToSign[] = ""; // Content-Type 135 $stringToSign[] = ""; 136 // Date already in $canonicalizedHeaders 137 // $stringToSign[] = self::PREFIX_STORAGE_HEADER . 'date:' . $requestDate; // Date 138 139 if (!$forTableStorage && count($canonicalizedHeaders) > 0) { 140 $stringToSign[] = implode("\n", $canonicalizedHeaders); // Canonicalized headers 141 } 142 143 $stringToSign[] = $canonicalizedResource; // Canonicalized resource 144 $stringToSign = implode("\n", $stringToSign); 145 $signString = base64_encode(hash_hmac('sha256', $stringToSign, $this->_accountKey, true)); 146 147 // Sign request 148 $headers[Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PREFIX_STORAGE_HEADER . 'date'] = $requestDate; 149 $headers['Authorization'] = 'SharedKey ' . $this->_accountName . ':' . $signString; 150 151 // Return headers 152 return $headers; 153 } 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |