Open despotbg opened 7 years ago
I found mistake. I investigated S3 response. And there they return this
<CanonicalRequest>
POST
//8a855b73-0b37-413a-aa3c-c74b48e32fb4/fronalpstockbig.jpg
uploads=
host:xyz.s3-us-east-2.amazonaws.com
x-amz-acl:private
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b854
x-amz-date:20170823T195258Z
x-amz-meta-qqfilename:fronalpstockbig.jpg
host;x-amz-acl;x-amz-content-sha256;x-amz-date;x-amz-meta-qqfilename
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b854</CanonicalRequest>
while in function signV4RestRequest inside $matches[3] I have
POST
/8a855b73-0b37-413a-aa3c-c74b48e32fb4/fronalpstockbig.jpg
uploads=
host:xyz.s3-us-east-2.amazonaws.com/
x-amz-acl:private
x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b854
x-amz-date:20170823T195258Z
x-amz-meta-qqfilename:fronalpstockbig.jpg
host;x-amz-acl;x-amz-content-sha256;x-amz-date;x-amz-meta-qqfilename
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b854
Note that $matches[3] have just one "/" after POST, and have "/" after amazonaws.com I solve this by adding next three lines
preg_match($pattern, $rawStringToSign, $matches);
$matches[3] = str_replace('amazonaws.com/', 'amazonaws.com', $matches[3]); // THIS LINE ADDED
$matches[3] = str_replace("POST\n/", "POST\n//", $matches[3]); // THIS LINE ADDED
$matches[3] = str_replace("PUT\n/", "PUT\n//", $matches[3]); // THIS LINE ADDED
$hashedCanonicalRequest = hash('sha256', $matches[3]);
Everything works fine until I turn on chunking. But when chunking is turned on, I get signature matching problem This is how my CORS configuration looks like on S3 `<?xml version="1.0" encoding="UTF-8"?>
SignatureDoesNotMatch