Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rel/7.4' into fwd/7.4-master
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-merle committed Feb 11, 2018
2 parents 4193394 + b6c051d commit 31e9350
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
6 changes: 4 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
general:
branches:
ignore:
- /^ultron\/.*/ # Ignore ultron/* branches
- /^ultron\/.*/ # Ignore ultron/* branches

machine:
node:
Expand All @@ -13,7 +13,9 @@ machine:
CXX: g++-4.9

dependencies:
pre:
override:
- rm -rf node_modules
- npm install
- sudo pip install yamllint

test:
Expand Down
4 changes: 3 additions & 1 deletion lib/auth/v4/awsURIencode.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function _toHexUTF8(char) {
return res;
}

function awsURIencode(input, encodeSlash) {
function awsURIencode(input, encodeSlash, noEncodeStar) {
const encSlash = encodeSlash === undefined ? true : encodeSlash;
let encoded = '';
for (let i = 0; i < input.length; i++) {
Expand All @@ -47,6 +47,8 @@ function awsURIencode(input, encodeSlash) {
encoded = encoded.concat('%20');
} else if (ch === '/') {
encoded = encoded.concat(encSlash ? '%2F' : ch);
} else if (ch === '*') {
encoded = encoded.concat(noEncodeStar ? '*' : '%2A');
} else {
encoded = encoded.concat(_toHexUTF8(ch));
}
Expand Down
10 changes: 9 additions & 1 deletion lib/auth/v4/createCanonicalRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ function createCanonicalRequest(params) {
payloadChecksum = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b' +
'934ca495991b7852b855';
} else if (pHttpVerb === 'POST') {
let notEncodeStar = false;
// The java sdk does not encode the '*' parameter to compute the
// signature, if the user-agent is recognized, we need to keep
// the plain '*' as well.
if (/aws-sdk-java\/[0-9.]+/.test(pHeaders['user-agent'])) {
notEncodeStar = true;
}
let payload = queryString.stringify(pQuery, null, null, {
encodeURIComponent: awsURIencode,
encodeURIComponent: input => awsURIencode(input, false,
notEncodeStar),
});
payload = payload.replace(/%20/g, '+');
payloadChecksum = crypto.createHash('sha256')
Expand Down
2 changes: 1 addition & 1 deletion lib/executables/pensieveCreds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "mocha --recursive --timeout 5500 tests/unit"
},
"dependencies": {
"mocha": "2.5.3",
"async": "^2.6.0",
"node-forge": "^0.7.1"
}
}

47 changes: 46 additions & 1 deletion tests/unit/auth/v4/createCanonicalRequest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'; // eslint-disable-line strict

const assert = require('assert');

const awsURIencode =
require('../../../../lib/auth/v4/awsURIencode');
const createCanonicalRequest =
require('../../../../lib/auth/v4/createCanonicalRequest');

Expand Down Expand Up @@ -45,6 +46,50 @@ describe('createCanonicalRequest function', () => {
assert.strictEqual(actualOutput, expectedOutput);
});

const msg = 'S3C-820: aws java sdk should not encode * ' +
'character for signature';
it(msg, () => {
const doc = JSON.stringify({
Statement: [{
Action: 's3:*',
}],
});
const params = {
pHttpVerb: 'POST',
pResource: '/',
pQuery: {
PolicyDocument: doc,
},
pHeaders: {
'host': 'examplebucket.s3.amazonaws.com',
'x-amz-date': '20130524T000000Z',
'user-agent': 'aws-sdk-java/1.11',
'authorization': 'AWS4-HMAC-SHA256 Credential' +
'=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/' +
's3/aws4_request,SignedHeaders=host;user-agent' +
'x-amz-content-sha256;x-amz-date,Signature=' +
'f0e8bdb87c964420e857bd35b5d6ed310bd44f' +
'0170aba48dd91039c6036bdb41',
'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c' +
'8996fb92427ae41e4649b934ca495991b7852b855',
},
pSignedHeaders: 'host;user-agent;x-amz-content-sha256;x-amz-date',
};
const expectedOutput = 'POST\n' +
'/\n' +
`PolicyDocument=${awsURIencode(doc)}\n` +
'host:examplebucket.s3.amazonaws.com\n' +
'user-agent:aws-sdk-java/1.11\n' +
'x-amz-content-sha256:e3b0c44298fc1c149afbf4c' +
'8996fb92427ae41e4649b934ca495991b7852b855\n' +
'x-amz-date:20130524T000000Z\n\n' +
'host;user-agent;x-amz-content-sha256;x-amz-date\n' +
'25775fcf6b536b361aadce0c5f1afb46eb945dbdd6c3a7723b18300234a89588';
const actualOutput = createCanonicalRequest(params);
assert.strictEqual(actualOutput, expectedOutput);
});


// Example taken from: http://docs.aws.amazon.com/AmazonS3/
// latest/API/sig-v4-header-based-auth.html
it('should construct a canonical request in accordance ' +
Expand Down

0 comments on commit 31e9350

Please sign in to comment.