Skip to content

Commit 9677b56

Browse files
committed
added support for AWSv4 signature in query string
1 parent 1385fab commit 9677b56

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/s3/app.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function s3app(params) {
1818
res.header('Access-Control-Allow-Methods',
1919
'GET,POST,PUT,DELETE,OPTIONS');
2020
res.header('Access-Control-Allow-Headers',
21-
'Content-Type,Authorization,X-Amz-User-Agent,X-Amz-Date,ETag');
21+
'Content-Type,Authorization,X-Amz-User-Agent,X-Amz-Date,ETag,X-Amz-Content-Sha256');
2222
res.header('Access-Control-Allow-Origin', '*');
2323
res.header('Access-Control-Expose-Headers', 'ETag');
2424
// note that browsers will not allow origin=* with credentials
@@ -66,15 +66,16 @@ function s3app(params) {
6666
dbg.log0('authorization header exists', req.headers.authorization);
6767

6868
var end_of_aws_key = req.headers.authorization.indexOf(':');
69-
var req_access_key = req.headers.authorization.substring(4, end_of_aws_key);
70-
if (req_access_key === 'AWS4'){
69+
var req_access_key;
70+
if (req.headers.authorization.substring(0, 4) === 'AWS4') {
7171
//authorization: 'AWS4-HMAC-SHA256 Credential=wwwwwwwwwwwww123aaaa/20151023/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=0b04a57def200559b3353551f95bce0712e378c703a97d58e13a6eef41a20877',
72-
73-
var credentials_location = req.headers.authorization.indexOf('Credential')+11;
74-
72+
var credentials_location = req.headers.authorization.indexOf('Credential') + 11;
7573
req_access_key = req.headers.authorization.substring(credentials_location, req.headers.authorization.indexOf('/'));
74+
} else {
75+
req_access_key = req.headers.authorization.substring(4, end_of_aws_key);
7676
}
77-
dbg.log0('req_access_key',req_access_key);
77+
78+
dbg.log0('req_access_key', req_access_key);
7879

7980
req.access_key = req_access_key;
8081
req.signature = req.headers.authorization.substring(end_of_aws_key + 1, req.headers.authorization.lenth);
@@ -84,7 +85,14 @@ function s3app(params) {
8485
req.signature = req.query.Signature;
8586
authenticated_request = true;
8687
dbg.log0('signed url');
88+
} else if (req.query['X-Amz-Credential']) {
89+
req.access_key = req.query['X-Amz-Credential'].substring(0, req.query['X-Amz-Credential'].indexOf('/'));
90+
req.signature = req.query['X-Amz-Signature'];
91+
authenticated_request = true;
92+
dbg.log0('signed url v4',req.access_key);
93+
8794
}
95+
8896
if (authenticated_request) {
8997
// var s3 = new s3_auth(req);
9098
dbg.log0('authenticated request with signature', req.signature);

src/s3/controllers.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,19 @@ module.exports = function(params) {
163163
var req_access_key;
164164
if (req.headers.authorization) {
165165
var end_of_aws_key = req.headers.authorization.indexOf(':');
166-
req_access_key = req.headers.authorization.substring(4, end_of_aws_key);
167-
if (req_access_key === 'AWS4'){
166+
if (req.headers.authorization.substring(0,4)==='AWS4'){
168167
//authorization: 'AWS4-HMAC-SHA256 Credential=wwwwwwwwwwwww123aaaa/20151023/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=0b04a57def200559b3353551f95bce0712e378c703a97d58e13a6eef41a20877',
169-
170168
var credentials_location = req.headers.authorization.indexOf('Credential')+11;
171-
172169
req_access_key = req.headers.authorization.substring(credentials_location, req.headers.authorization.indexOf('/'));
170+
}else{
171+
req_access_key = req.headers.authorization.substring(4, end_of_aws_key);
173172
}
174173
} else {
175174
if (req.query.AWSAccessKeyId) {
176175
req_access_key = req.query.AWSAccessKeyId;
176+
}else if (req.query['X-Amz-Credential'])
177+
{
178+
req_access_key = req.query['X-Amz-Credential'].substring(0,req.query['X-Amz-Credential'].indexOf('/'));
177179
}
178180
}
179181
return req_access_key;

0 commit comments

Comments
 (0)