diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/Amazon/Authentication/S3.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/Amazon/Authentication/S3.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,112 @@ + $val) { + if (strcasecmp($key, 'content-type') == 0) { + $type = $val; + } else if (strcasecmp($key, 'content-md5') == 0) { + $md5 = $val; + } else if (strcasecmp($key, 'date') == 0) { + $date = $val; + } + } + + // If we have an x-amz-date header, use that instead of the normal Date + if (isset($headers['x-amz-date']) && isset($date)) { + $date = ''; + } + + $sig_str = "$method\n$md5\n$type\n$date\n"; + + // For x-amz- headers, combine like keys, lowercase them, sort them + // alphabetically and remove excess spaces around values + $amz_headers = array(); + foreach ($headers as $key => $val) { + $key = strtolower($key); + if (substr($key, 0, 6) == 'x-amz-') { + if (is_array($val)) { + $amz_headers[$key] = $val; + } else { + $amz_headers[$key][] = preg_replace('/\s+/', ' ', $val); + } + } + } + if (!empty($amz_headers)) { + ksort($amz_headers); + foreach ($amz_headers as $key => $val) { + $sig_str .= $key . ':' . implode(',', $val) . "\n"; + } + } + + $sig_str .= '/'.parse_url($path, PHP_URL_PATH); + if (strpos($path, '?location') !== false) { + $sig_str .= '?location'; + } else + if (strpos($path, '?acl') !== false) { + $sig_str .= '?acl'; + } else + if (strpos($path, '?torrent') !== false) { + $sig_str .= '?torrent'; + } + + $signature = base64_encode(Zend_Crypt_Hmac::compute($this->_secretKey, 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY)); + $headers['Authorization'] = 'AWS ' . $this->_accessKey . ':' . $signature; + + return $sig_str; + } +}