cinely / mule-uploader

Stubborn HTML5 Amazon S3 uploader
http://mule-uploader.com/
MIT License
222 stars 43 forks source link

PHP SignatureDoesNotMatch #43

Closed jarakkal closed 9 years ago

jarakkal commented 9 years ago

When signing using the PHP backend, I am getting this error message.

Response as follows: <?xml version="1.0" encoding="UTF-8"?>

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.AKIAEXAMPLEACCESKEYAWS4-HMAC-SHA256 20150130T045838Z 20150130/ap-southeast-2/s3/aws4_request 3a4c89c89950a36183af6a247f89d2b16f9c15bc917e64532124f6d1cf92bdca49299454084683e609e7a569c99073d180b1725977bb5f369e5d0182709becba41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 35 30 31 33 30 54 30 34 35 38 33 38 5a 0a 32 30 31 35 30 31 33 30 2f 61 70 2d 73 6f 75 74 68 65 61 73 74 2d 32 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 33 61 34 63 38 39 63 38 39 39 35 30 61 33 36 31 38 33 61 66 36 61 32 34 37 66 38 39 64 32 62 31 36 66 39 63 31 35 62 63 39 31 37 65 36 34 35 33 32 31 32 34 66 36 64 31 63 66 39 32 62 64 63 61POST /5 X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAEXAMPLEACCESKEY%2F20150130%2Fap-southeast-2%2Fs3%2Faws4_request&X-Amz-Date=20150130T045838Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=Content-Disposition%3BContent-Type%3Bhost%3Bx-amz-acl&uploads= content-disposition:attachment; filename=file name.wmv content-type:application/octet-stream host:bucket.s3.amazonaws.com x-amz-acl:public-read content-disposition;content-type;host;x-amz-acl UNSIGNED-PAYLOAD50 4f 53 54 0a 2f 35 0a 58 2d 41 6d 7a 2d 41 6c 67 6f 72 69 74 68 6d 3d 41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 26 58 2d 41 6d 7a 2d 43 72 65 64 65 6e 74 69 61 6c 3d 41 4b 49 41 4a 53 49 53 57 35 5a 47 4d 48 4b 43 50 58 4f 51 25 32 46 32 30 31 35 30 31 33 30 25 32 46 61 70 2d 73 6f 75 74 68 65 61 73 74 2d 32 25 32 46 73 33 25 32 46 61 77 73 34 5f 72 65 71 75 65 73 74 26 58 2d 41 6d 7a 2d 44 61 74 65 3d 32 30 31 35 30 31 33 30 54 30 34 35 38 33 38 5a 26 58 2d 41 6d 7a 2d 45 78 70 69 72 65 73 3d 38 36 34 30 30 26 58 2d 41 6d 7a 2d 53 69 67 6e 65 64 48 65 61 64 65 72 73 3d 43 6f 6e 74 65 6e 74 2d 44 69 73 70 6f 73 69 74 69 6f 6e 25 33 42 43 6f 6e 74 65 6e 74 2d 54 79 70 65 25 33 42 68 6f 73 74 25 33 42 78 2d 61 6d 7a 2d 61 63 6c 26 75 70 6c 6f 61 64 73 3d 0a 63 6f 6e 74 65 6e 74 2d 64 69 73 70 6f 73 69 74 69 6f 6e 3a 61 74 74 61 63 68 6d 65 6e 74 3b 20 66 69 6c 65 6e 61 6d 65 3d 32 30 31 34 2d 30 39 2d 32 33 20 31 30 2e 33 30 20 6c 6f 6f 6b 61 74 6d 65 20 64 65 6d 6f 2e 77 6d 76 0a 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3a 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6f 63 74 65 74 2d 73 74 72 65 61 6d 0a 68 6f 73 74 3a 6c 6f 6f 6b 61 74 6d 65 64 61 6d 2e 73 33 2e 61 6d 61 7a 6f 6e 61 77 73 2e 63 6f 6d 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 75 62 6c 69 63 2d 72 65 61 64 0a 0a 63 6f 6e 74 65 6e 74 2d 64 69 73 70 6f 73 69 74 69 6f 6e 3b 63 6f 6e 74 65 6e 74 2d 74 79 70 65 3b 68 6f 73 74 3b 78 2d 61 6d 7a 2d 61 63 6c 0a 55 4e 53 49 47 4e 45 44 2d 50 41 59 4c 4f 41 440F62B88D30259F466s9WrYHMsf6fNZqLnkkXmgd0j5kIPXLs1qEeUKevyx+5cuo1VX2/Qr7A0j4GiMK/
stephanelsmith commented 9 years ago

I'm having the exact same issue using python backend. Digging around, not sure what the issue is....

jarakkal commented 9 years ago

We manage to solve this issue. The current code (mule-uploader.js) will only work for S3 Buckets in the US region. For all other regions (including US), the following needs to be changed.

Line https://github.com/cinely/mule-uploader/blob/master/mule-uploader.js#L1104

self.headers['host'] = "s3.amazonaws.com"; < self.headers['host'] = "bucket-name.s3.amazonaws.com";

Line https://github.com/cinely/mule-uploader/blob/master/mule-uploader.js#L1133

var url = location.protocol + "//s3.amazonaws.com/" + self.settings.auth.bucket + "/" + self.settings.key; < var url = location.protocol + "//" + self.settings.auth.bucket + ".s3.amazonaws.com/" + self.settings.key;

Line https://github.com/cinely/mule-uploader/blob/master/mule-uploader.js#L1191

request += "/" + utils.uriencode(this.settings.auth.bucket) + "/" + utils.uriencode(this.settings.key).replace(/%2F/g, "/") + "\n"; < request += "/" + utils.uriencode(this.settings.key).replace(/%2F/g, "/") + "\n";

Hope this helps, Jento

gabipurcaru commented 9 years ago

Please let me know if the latest code fixes this ( see #45 for more details )