8000 Version 1.4.4 of the AWS Java SDK · JavaInCloud/aws-sdk-java@c2f2e51 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2f2e51

Browse files
committed
Version 1.4.4 of the AWS Java SDK
This release adds support for Parallel Scan in Amazon DynamoDB and Elastic Load Balancing support in AWS OpsWorks. For more information, see the full release notes: http://aws.amazon.com/releasenotes/Java/7145549371107539
1 parent c02db44 commit c2f2e51

File tree

168 files changed

+20310
-6642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+20310
-6642
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ jdk:
44
- oraclejdk7
55
- openjdk6
66
install: /bin/true
7-
script: mvn install --quiet -Dgpg.skip=true -DskipTests=true
7+
script: mvn install --quiet -Dgpg.skip=true -DskipTests=true
8+

META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: AWS SDK for Java
44
Bundle-SymbolicName: com.amazonaws.sdk;singleton:=true
5-
Bundle-Version: 1.4.3
5+
Bundle-Version: 1.4.4
66
Bundle-Vendor: Amazon Technologies, Inc
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
88
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<artifactId>aws-java-sdk</artifactId>
77
<packaging>jar</packaging>
88
<name>AWS SDK for Java</name>
9-
<version>1.4.3</version>
9+
<version>1.4.4</version>
1010
<description>The Amazon Web Services SDK for Java provides Java APIs for building software on AWS’ cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).</description>
1111
<url>https://aws.amazon.com/sdkforjava</url>
1212

src/main/java/com/amazonaws/ClientConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public String getProxyDomain() {
391391
}
392392

393393
/**
394-
* Sets the optional Windows domain name for configuration an NTML proxy.
394+
* Sets the optional Windows domain name for configuration an NTLM proxy.
395395
* If you aren't using a Windows NTLM proxy, you do not need to set this
396396
* field.
397397
*
@@ -404,7 +404,7 @@ public void setProxyDomain(String proxyDomain) {
404404
}
405405

406406
/**
407-
* Sets the optional Windows domain name for configuration an NTML proxy and
407+
* Sets the optional Windows domain name for configuration an NTLM proxy and
408408
* returns a reference to this updated ClientConfiguration object so that
409409
* additional method calls can be chained together. If you aren't using a
410410
* Windows NTLM proxy, you do not need to set this field.

src/main/java/com/amazonaws/auth/AWS4Signer.java

Lines changed: 103 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2013-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
@@ -38,25 +38,25 @@
3838
*/
3939
public class AWS4Signer extends AbstractAWSSigner {
4040

41-
private static final String ALGORITHM = "AWS4-HMAC-SHA256";
42-
private static final String TERMINATOR = "aws4_request";
41+
protected static final String ALGORITHM = "AWS4-HMAC-SHA256";
42+
protected static final String TERMINATOR = "aws4_request";
4343

4444
/**
4545
* Service name override for use when the endpoint can't be used to
4646
* determine the service name.
4747
*/
48-
private String serviceName;
48+
protected String serviceName;
4949

5050
/**
5151
* Region name override for use when the endpoint can't be used to
5252
* determine the region name.
5353
*/
54-
private String regionName;
54+
protected String regionName;
5555

5656
/** Date override for testing only */
57-
private Date overriddenDate;
57+
protected Date overriddenDate;
5858

59-
private static final Log log = LogFactory.getLog(AWS4Signer.class);
59+
protected static final Log log = LogFactory.getLog(AWS4Signer.class);
6060

6161

6262
/* (non-Javadoc)
@@ -73,28 +73,8 @@ public void sign(Request<?> request, AWSCredentials credentials) throws AmazonCl
7373
addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
7474
}
7575

76-
SimpleDateFormat dateStampFormat = new SimpleDateFormat("yyyyMMdd");
77-
dateStampFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
78-
79-
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
80-
dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
81-
82-
String regionName = extractRegionName(request.getEndpoint());
83-
String serviceName = extractServiceName(request.getEndpoint());
84-
85-
// AWS4 requires that we sign the Host header so we
86-
// have to have it in the request by the time we sign.
87-
String hostHeader = request.getEndpoint().getHost();
88-
if (HttpUtils.isUsingNonDefaultPort(request.getEndpoint())) {
89-
hostHeader += ":" + request.getEndpoint().getPort();
90-
}
91-
request.addHeader("Host", hostHeader);
92-
93-
Date date = getSignatureDate(request.getTimeOffset());
94-
if (overriddenDate != null) date = overriddenDate;
95-
96-
String dateTime = dateTimeFormat.format(date);
97-
String dateStamp = dateStampFormat.format(date);
76+
addHostHeader(request);
77+
String scope = getScope(request);
9878

9979
InputStream payloadStream = getBinaryRequestPayloadStream(request);
10080
payloadStream.mark(-1);
@@ -105,36 +85,12 @@ public void sign(Request<?> request, AWSCredentials credentials) throws AmazonCl
10585
throw new AmazonClientException("Unable to reset stream after calculating AWS4 signature", e);
10686
}
10787

108-
request.addHeader("X-Amz-Date", dateTime);
88+
request.addHeader("X-Amz-Date", getDateTimeStamp(getDateFromRequest(request)));
10989
request.addHeader("x-amz-content-sha256", contentSha256);
11090

111-
String canonicalRequest =
112-
request.getHttpMethod().toString() + "\n" +
113-
super.getCanonicalizedResourcePath(request.getResourcePath()) + "\n" +
114-
getCanonicalizedQueryString(request) + "\n" +
115-
getCanonicalizedHeaderString(request) + "\n" +
116-
getSignedHeadersString(request) + "\n" +
117-
contentSha256;
118-
119-
log.debug("AWS4 Canonical Request: '\"" + canonicalRequest + "\"");
120-
121-
String scope = dateStamp + "/" + regionName + "/" + serviceName + "/" + TERMINATOR;
12291
String signingCredentials = sanitizedCredentials.getAWSAccessKeyId() + "/" + scope;
123-
String stringToSign =
124-
ALGORITHM + "\n" +
125-
dateTime + "\n" +
126-
scope + "\n" +
127-
BinaryUtils.toHex(hash(canonicalRequest));
128-
log.debug("AWS4 String to Sign: '\"" + stringToSign + "\"");
129-
130-
// AWS4 uses a series of derived keys, formed by hashing different pieces of data
131-
byte[] kSecret = ("AWS4" + sanitizedCredentials.getAWSSecretKey()).getBytes();
132-
byte[] kDate = sign(dateStamp, kSecret, SigningAlgorithm.HmacSHA256);
133-
byte[] kRegion = sign(regionName, kDate, SigningAlgorithm.HmacSHA256);
134-
byte[] kService = sign(serviceName, kRegion, SigningAlgorithm.HmacSHA256);
135-
byte[] kSigning = sign(TERMINATOR, kService, SigningAlgorithm.HmacSHA256);
13692

137-
byte[] signature = sign(stringToSign.getBytes(), kSigning, SigningAlgorithm.HmacSHA256);
93+
byte[] signature = computeSignature(request, ALGORITHM, contentSha256, sanitizedCredentials);
13894

13995
String credentialsAuthorizationHeader =
14096
"Credential=" + signingCredentials;
@@ -184,13 +140,13 @@ protected void addSessionCredentials(Request<?> request, AWSSessionCredentials c
184140
request.addHeader("x-amz-security-token", credentials.getSessionToken());
185141
}
186142

187-
private String extractRegionName(URI endpoint) {
143+
protected String extractRegionName(URI endpoint) {
188144
if (regionName != null) return regionName;
189145

190146
return AwsHostNameUtils.parseRegionName(endpoint);
191147
}
192148

193-
private String extractServiceName(URI endpoint) {
149+
protected String extractServiceName(URI endpoint) {
194150
if (serviceName != null) return serviceName;
195151

196152
return AwsHostNameUtils.parseServiceName(endpoint);
@@ -201,7 +157,7 @@ void overrideDate(Date overriddenDate) {
201157
this.overriddenDate = overriddenDate;
202158
}
203159

204-
private String getCanonicalizedHeaderString(Request<?> request) {
160+
protected String getCanonicalizedHeaderString(Request<?> request) {
205161
List<String> sortedHeaders = new ArrayList<String>();
206162
sortedHeaders.addAll(request.getHeaders().keySet());
207163
Collections.sort(sortedHeaders, String.CASE_INSENSITIVE_ORDER);
@@ -215,7 +171,7 @@ private String getCanonicalizedHeaderString(Request<?> request) {
215171
return buffer.toString();
216172
}
217173

218-
private String getSignedHeadersString(Request<?> request) {
174+
protected String getSignedHeadersString(Request<?> request) {
219175
List<String> sortedHeaders = new ArrayList<String>();
220176
sortedHeaders.addAll(request.getHeaders().keySet());
221177
Collections.sort(sortedHeaders, String.CASE_INSENSITIVE_ORDER);
@@ -229,4 +185,92 @@ private String getSignedHeadersString(Request<?> request) {
229185
return buffer.toString();
230186
}
231187

188+
protected String getCanonicalRequest(Request<?> request, String contentSha256) {
189+
String canonicalRequest =
190+
request.getHttpMethod().toString() + "\n" +
191+
getCanonicalizedResourcePath(request.getResourcePath()) + "\n" +
192+
getCanonicalizedQueryString(request) + "\n" +
193+
getCanonicalizedHeaderString(request) + "\n" +
194+
getSignedHeadersString(request) + "\n" +
195+
contentSha256;
196+
log.debug("AWS4 Canonical Request: '\"" + canonicalRequest + "\"");
197+
return canonicalRequest;
198+
}
199+
200+
protected String getStringToSign(String algorithm, String dateTime, String scope, String canonicalRequest) {
201+
String stringToSign =
202+
algorithm + "\n" +
203+
dateTime + "\n" +
204+
scope + "\n" +
205+
BinaryUtils.toHex(hash(canonicalRequest));
206+
log.debug("AWS4 String to Sign: '\"" + stringToSign + "\"");
207+
return stringToSign;
208+
}
209+
210+
211+
protected byte[] computeSignature(Request<?> request, String algorithm, String contentSha256, AWSCredentials sanitizedCredentials) {
212+
213+
String regionName = extractRegionName(request.getEndpoint());
214+
String serviceName = extractServiceName(request.getEndpoint());
215+
216+
Date date = getDateFromRequest(request);
217+
String dateTime = getDateTimeStamp(date);
218+
String dateStamp = getDateStamp(date);
219+
String scope = dateStamp + "/" + regionName + "/" + serviceName + "/" + TERMINATOR;
220+
221+
String stringToSign = getStringToSign(algorithm, dateTime, scope, getCanonicalRequest(request,contentSha256 ));
222+
223+
// AWS4 uses a series of derived keys, formed by hashing different
224+
// pieces of data
225+
byte[] kSecret = ("AWS4" + sanitizedCredentials.getAWSSecretKey()).getBytes();
226+
byte[] kDate = sign(dateStamp, kSecret, SigningAlgorithm.HmacSHA256);
227+
byte[] kRegion = sign(regionName, kDate, SigningAlgorithm.HmacSHA256);
228+
byte[] kService = sign(serviceName, kRegion, SigningAlgorithm.HmacSHA256);
229+
byte[] kSigning = sign(TERMINATOR, kService, SigningAlgorithm.HmacSHA256);
230+
231+
byte[] signature = sign(stringToSign.getBytes(), kSigning, SigningAlgorithm.HmacSHA256);
232+
return signature;
233+
}
234+
235+
protected String getDateTimeStamp(Date date) {
236+
SimpleDateFormat dateTimeFormat;
237+
dateTimeFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
238+
dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
239+
return dateTimeFormat.format(date);
240+
}
241+
242+
protected String getDateStamp(Date date) {
243+
SimpleDateFormat dateStampFormat;
244+
dateStampFormat = new SimpleDateFormat("yyyyMMdd");
245+
dateStampFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
246+
return dateStampFormat.format(date);
247+
}
248+
249+
protected Date getDateFromRequest(Request<?> request) {
250+
Date date = getSignatureDate(request.getTimeOffset());
251+
if (overriddenDate != null) date = overriddenDate;
252+
return date;
253+
}
254+
255+
256+
protected void addHostHeader(Request<?> request) {
257+
// AWS4 requires that we sign the Host header so we
258+
// have to have it in the request by the time we sign.
259+
String hostHeader = request.getEndpoint().getHost();
260+
if (HttpUtils.isUsingNonDefaultPort(request.getEndpoint())) {
261+
hostHeader += ":" + request.getEndpoint().getPort();
262+
}
263+
request.addHeader("Host", hostHeader);
264+
}
265+
266+
protected String getScope(Request<?> request) {
267+
String regionName = extractRegionName(request.getEndpoint());
268+
String serviceName = extractServiceName(request.getEndpoint());
269+
270+
Date date = getDateFromRequest(request);
271+
String dateStamp = getDateStamp(date);
272+
String scope = dateStamp + "/" + regionName + "/" + serviceName + "/" + TERMINATOR;
273+
return scope;
274+
}
275+
232276
}

src/main/java/com/amazonaws/auth/policy/Policy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
public class Policy {
5656

5757
/** The default policy version */
58-
private static final String DEFAULT_POLICY_VERSION = "2008-10-17";
58+
private static final String DEFAULT_POLICY_VERSION = "2012-10-17";
5959

6060
private String id;
6161
private String version = DEFAULT_POLICY_VERSION;

src/main/java/com/amazonaws/http/HttpRequestFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ HttpRequestBase createHttpRequest(Request<?> request, ClientConfiguration client
6666
} else if (!uri.endsWith("/")) {
6767
uri += "/";
6868
}
69-
uri += request.getResourcePath();
69+
uri += HttpUtils.urlEncode(request.getResourcePath(), true);
7070
} else if (!uri.endsWith("/")) {
7171
uri += "/";
7272
}

0 commit comments

Comments
 (0)
0