56 $authHeader = $this->request->getHeader(
'Authorization');
57 $authHeader = explode(
' ', $authHeader);
59 if ($authHeader[0] !=
'AWS' || !isset($authHeader[1])) {
60 $this->errorCode = self::ERR_NOAWSHEADER;
64 list($this->accessKey, $this->signature) = explode(
':', $authHeader[1]);
89 $contentMD5 = $this->request->getHeader(
'Content-MD5');
93 $body = $this->request->getBody();
94 $this->request->setBody($body);
96 if ($contentMD5 != base64_encode(md5($body,
true))) {
98 $this->errorCode = self::ERR_MD5CHECKSUMWRONG;
104 if (!$requestDate = $this->request->getHeader(
'x-amz-date'))
105 $requestDate = $this->request->getHeader(
'Date');
114 $this->request->getMethod() .
"\n" .
116 $this->request->getHeader(
'Content-type') .
"\n" .
117 $requestDate .
"\n" .
119 $this->request->getUrl()
125 $this->errorCode = self::ERR_INVALIDSIGNATURE;
144 $this->response->addHeader(
'WWW-Authenticate',
'AWS');
145 $this->response->setStatus(401);
167 $this->errorCode = self::ERR_INVALIDDATEFORMAT;
171 $min = new \DateTime(
'-15 minutes');
172 $max = new \DateTime(
'+15 minutes');
175 if ($date > $max || $date < $min) {
176 $this->errorCode = self::ERR_REQUESTTIMESKEWED;
192 $headers = $this->request->getHeaders();
193 foreach ($headers as $headerName => $headerValue) {
194 if (strpos(strtolower($headerName),
'x-amz-') === 0) {
195 $amzHeaders[strtolower($headerName)] = str_replace([
"\r\n"], [
' '], $headerValue[0]) .
"\n";
201 foreach ($amzHeaders as
$h => $v) {
202 $headerStr .=
$h .
':' . $v;
218 if (function_exists(
'hash_hmac')) {
223 if (strlen(
$key) > $blocksize) {
226 $key = str_pad(
$key, $blocksize, chr(0x00));
227 $ipad = str_repeat(chr(0x36), $blocksize);
228 $opad = str_repeat(chr(0x5c), $blocksize);
229 $hmac = pack(
'H*', sha1((
$key ^ $opad) . pack(
'H*', sha1((
$key ^ $ipad) .
$message))));
HTTP AWS Authentication handler.
const ERR_INVALIDSIGNATURE
validateRFC2616Date($dateHeader)
Makes sure the supplied value is a valid RFC2616 date.
requireLogin()
Returns an HTTP 401 header, forcing login.
getAccessKey()
Returns the username for the request.
static parseHTTPDate($dateHeader)
Parses a RFC2616-compatible date string.
catch(Exception $e) $message
validate($secretKey)
Validates the signature based on the secretKey.
init()
Gathers all information from the headers.
const ERR_INVALIDDATEFORMAT
getAmzHeaders()
Returns a list of AMZ headers.
HTTP Authentication base class.
const ERR_REQUESTTIMESKEWED
const ERR_MD5CHECKSUMWRONG
hmacsha1($key, $message)
Generates an HMAC-SHA1 signature.