Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignatureDoesNotMatch Issue #56

Closed
alhui opened this issue Dec 29, 2011 · 20 comments
Closed

SignatureDoesNotMatch Issue #56

alhui opened this issue Dec 29, 2011 · 20 comments

Comments

@alhui
Copy link

alhui commented Dec 29, 2011

I've worked through numerous examples on this, but still receiving a SignatureDoesNotMatch error when I try to 'put()' a jpeg into S3.

I've used the amazon s3 signature testing tool to troubleshoot and identified a difference between the request I am sending and what amazon expects.

What the amazon test tool expects when I enter the hexcode returned in the StringToSign section,

PUT\n\nimage/jpeg\nThu, 29 Dec 2011 06:32:18 GMT\nx-amz-acl:public-read\n/girlsafaritest2\28.jpg

What I am seeing in console.log in the request object I send out to amazon via the put() call in Knox,

_header: 'PUT \28.jpg HTTP/1.1\r\nExpect: 100-continue\r\nx-amz-acl: public-r
ead\r\nContent-Length: 45800\r\nContent-Type: image/jpeg\r\nDate: Thu, 29 Dec 20
11 06:32:18 GMT\r\nHost: girlsafaritest2.s3.amazonaws.com\r\nAuthorization: AWS
AKIAJ3S7Y6CDASJHLUWA:Tm+8/ljOevwZnoV9sEzduo4rYhw=\r\nConnection: keep-alive\r\n
r\n'

Almost everything matches except I noticed that there are two differences, 1) - the \28.jpg (is the \ causing a problem?) and 2) Amazon expects \n while in the request it uses \r\n (is windows causing an issue? I am running nodejs/knox from Win7)

In case anyone wants to see the code I am using, here it is as well:

fs.readFile('./public/images/mockdata/28.jpg', function(err, buf){
console.log('readfile completed, length is: ' + buf.length);
var req = client.put('28.jpg', {
'Content-Length': buf.length
, 'Content-Type': 'image/jpeg'
});

      console.log(req);

      req.on('response', function(res){
          console.log('[Response]:\n\r res.statusCode: ' + res.statusCode);
          console.log('res.headers: ' + res.headers);
          res.on('data', function(chunk){
                console.log('chunk string: ' + chunk.toString());
          });
          if (200 == res.statusCode) {
              console.log('saved to %s', req.url);
          }
      });
      req.end(buf);

});

Appreciate any help anyone can provide!

@alhui
Copy link
Author

alhui commented Dec 29, 2011

Is it possible the join function is causing problems since it defaults to '' for windows instead of the '/' which we require for the web?

@alhui
Copy link
Author

alhui commented Dec 29, 2011

Ok, confirmed that this is the root cause. When I ran my code on linux it works fine... but on windows it breaks. Can someone comment on this?

@noregrets
Copy link

I also have this problem when using knox in Windows. Would appreciate any advice on how to work around it.

@allosushi
Copy link

Ok I just wrote a workaround to make it work on Windows, in client.js :

var utils = require('./utils')
  , auth = require('./auth')
  , http = require('http')
  , url = require('url')
//  , join = require('path').join
  , mime = require('./mime')
  , fs = require('fs');


var platformDependantJoin = require('path').join;
var isWindows = process.platform === 'win32';
var join = function(args){
  var s = platformDependantJoin.apply(this, arguments);
  return (isWindows) ? s.replace(/\\/g, '/') : s;
}

@noregrets
Copy link

Thank you!

@parindam
Copy link

parindam commented Mar 3, 2012

I added this work around. Now the url seems to be fine. But is the PUT OK (PUT //thumbnail/AUSTRALIA.jpg)?
I'm constantly getting 403.

_header: 'PUT //thumbnail/AUSTRALIA.jpg/ HTTP/1.1\r\nExpect: 100-continu
e\r\nx-amz-acl: public-read\r\nContent-Type: image/jpeg\r\nContent-Length: 3354
r\nDate: Sat, 03 Mar 2012 10:51:03 GMT\r\nHost: cbc.s3.amazonaws.com\r\nA
uthorization: AWS XXXXXXXXXXXXXXXXXXX:p+VNij8+LxdfoAK8o5l4tlrM/i4=\r\nConnectio
n: keep-alive\r\n\r\n',
_headerSent: true,
_events: [Object],
url: 'http://cbc.s3.amazonaws.com/thumbnail/AUSTRALIA.jpg',

@parindam
Copy link

parindam commented Mar 3, 2012

OK. found the problem.
We need not append "/" before thumbnail. removed it and it's working fine. images are getting uploaded.

var req = s3Client.put('thumbnail/'+filename, {
'Content-Type': res.headers['content-type'],
'Content-Length': res.headers['content-length']
});

@domenic
Copy link
Contributor

domenic commented Mar 23, 2012

If you want to get this working in your project without having to hack node_modules/knox/lib/knox/client.js every time you do an npm install, you can for now do

"knox": "git://github.com/domenic/knox.git#windows"

in your package.json. I've reached out to @visionmedia on Twitter to see if I can help with this project's neglected pull requests in general; hopefully then we can do some more releases to get this and other features into knox.

juhap pushed a commit to juhap/knox that referenced this issue Mar 26, 2012
@pedrofaustino
Copy link

@domenic This fix breaks the signedUrl method. In the knox Readme there's always a forward slash in the filename (key) on both get and put methods, so you should use this.bucket + filename instead of this.bucket + '/' + filename

@parindam
Copy link

parindam commented Apr 3, 2012

yes, I also faced this problem.
I removed the '/' to correct it.

On Tue, Apr 3, 2012 at 6:21 PM, pedrofaustino <
reply@reply.github.com

wrote:

@domenic This fix breaks the signedUrl method. In the knox Readme
there's always a forward slash in the filename (key) on both get and put
methods, so you should use this.bucket + filename instead of `this.bucket

  • '/' + filename`

Reply to this email directly or view it on GitHub:
#56 (comment)

Thanks,
Arindam.

@domenic
Copy link
Contributor

domenic commented Apr 3, 2012

@juhap @pedrofaustino @parindam Thanks for the catch; fixed in the abovementioned fork/branch.

@johnrellis
Copy link

hey, seems this issue still exists when doing an npm install knox. Any thoughts on when it will be pushed to release??
Thanks.

@domenic
Copy link
Contributor

domenic commented May 8, 2012

@johnrellis knox is basically abandoned at this point. Feel free to use my fork. I'm considering creating a "real fork" (new npm package etc.) soon.

@johnrellis
Copy link

@domenic ah, ok, thanks. pretty new to node and trying to get a college project together so I can't help I'm afraid! good luck!

@tj
Copy link
Contributor

tj commented May 8, 2012

I'm all for a maintainer since we're not using it right now, I dont have admin access to this repo though

@domenic
Copy link
Contributor

domenic commented May 8, 2012

Oh OK cool. Well FWIW if you do track down an admin, @pbouzakis and I are using it daily at work.

@tj
Copy link
Contributor

tj commented May 8, 2012

@guille any objections?

@domenic
Copy link
Contributor

domenic commented May 15, 2012

@guille ?

@traviscooper
Copy link

@visionmedia what s3 or AWS lib are you guys using now, if not this one?

@domenic
Copy link
Contributor

domenic commented Jul 16, 2012

Fixed differently in acffa44

@domenic domenic closed this as completed Jul 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants