Modifier and Type | Field and Description |
---|---|
protected static SimpleDateFormat |
awsFlavouredISO8601DateParser |
Constructor and Description |
---|
SignatureUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
awsRegionForRequest(org.apache.http.client.methods.HttpUriRequest httpMethod)
Determine the AWS Region to which a request will be sent based on the
request's Host endpoint.
|
static String |
awsV4BuildAuthorizationHeaderValue(String accessKey,
String requestSignature,
String requestSignatureVersion,
String canonicalRequestString,
String timestampISO8601,
String region)
Build the Authorization header value for a REST/HTTP request to a storage
service for the AWS Request Signature version 4.
|
static String |
awsV4BuildCanonicalRequestString(org.apache.http.client.methods.HttpUriRequest httpMethod,
String requestPayloadHexSha256Hash)
Build the canonical request string for a REST/HTTP request to a storage
service for the AWS Request Signature version 4.
|
static String |
awsV4BuildCanonicalRequestString(URI uri,
String httpMethod,
Map<String,String> headersMap,
String requestPayloadHexSha256Hash)
Build the canonical request string for a REST/HTTP request to a storage
service for the AWS Request Signature version 4.
|
static byte[] |
awsV4BuildSigningKey(String secretAccessKey,
String timestampISO8601,
String region)
Build the signing key for a REST/HTTP request to a storage
service for the AWS Request Signature version 4.
|
static String |
awsV4BuildStringToSign(String requestSignatureVersion,
String canonicalRequestString,
String timestampISO8601,
String region)
Build the string to sign for a REST/HTTP request to a storage
service for the AWS Request Signature version 4.
|
static URI |
awsV4CorrectHostnameForRegion(URI uri,
String region)
Replace the hostname of the given URI endpoint to match the given region.
|
static String |
awsV4EncodeURI(CharSequence input,
boolean encodeSlash)
Slightly modified version of "uri-encode" from:
"http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html"
|
static String |
awsV4GetOrCalculatePayloadHash(org.apache.http.client.methods.HttpUriRequest httpMethod)
Return SHA256 payload hash value already set on HTTP request, or if none
is yet set calculate this value if possible.
|
static String |
awsV4ParseAndFormatDate(org.apache.http.client.methods.HttpUriRequest httpMethod)
Extract the request timestamp from the given HTTP request, from either
the "x-amz-date" metadata header or the Date header, and convert it
into an AWS-flavoured ISO8601 string format suitable for us in
request authorization for AWS version 4 signatures.
|
static void |
awsV4SignRequestAuthorizationHeader(String requestSignatureVersion,
org.apache.http.client.methods.HttpUriRequest httpMethod,
ProviderCredentials providerCredentials,
String requestPayloadHexSha256Hash,
String region)
Calculate AWS Version 4 signature for a HTTP request and apply the
appropriate "Authorization" header value to authorize it.
|
static String |
formatAwsFlavouredISO8601Date(Date date) |
static Date |
parseAwsFlavouredISO8601Date(String dateString) |
protected static final SimpleDateFormat awsFlavouredISO8601DateParser
public static String formatAwsFlavouredISO8601Date(Date date)
date
- public static Date parseAwsFlavouredISO8601Date(String dateString) throws ParseException
dateString
- date string representation that is hopefully AWS-flavoured ISO8601ParseException
public static String awsRegionForRequest(org.apache.http.client.methods.HttpUriRequest httpMethod)
httpMethod
- public static void awsV4SignRequestAuthorizationHeader(String requestSignatureVersion, org.apache.http.client.methods.HttpUriRequest httpMethod, ProviderCredentials providerCredentials, String requestPayloadHexSha256Hash, String region)
httpMethod
- the request's HTTP method just prior to sendingrequestSignatureVersion
- request signature version string, e.g. "AWS4-HMAC-SHA256"providerCredentials
- account holder's access and secret key credentialsrequestPayloadHexSha256Hash
- hex-encoded SHA256 hash of request's payload.region
- region to which the request will be sent
"http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"public static String awsV4GetOrCalculatePayloadHash(org.apache.http.client.methods.HttpUriRequest httpMethod)
httpMethod
- the request's HTTP method just prior to sendingpublic static String awsV4ParseAndFormatDate(org.apache.http.client.methods.HttpUriRequest httpMethod)
httpMethod
- request containing at least one of the "x-amz-date" or Date headers with
a timestamp value in one of the supported formats: RFC 822, ISO 8601,
AWS-flavoured ISO 8601.public static String awsV4BuildCanonicalRequestString(org.apache.http.client.methods.HttpUriRequest httpMethod, String requestPayloadHexSha256Hash)
httpMethod
- the request's HTTP method just prior to sendingrequestPayloadHexSha256Hash
- hex-encoded SHA256 hash of request's payload.
May be null or "" in which case the default SHA256 hash of an empty string is used.
May also be "UNSIGNED-PAYLOAD" for generating pre-signed request signatures.public static String awsV4BuildCanonicalRequestString(URI uri, String httpMethod, Map<String,String> headersMap, String requestPayloadHexSha256Hash)
uri
- httpMethod
- the request's HTTP method just prior to sendingheadersMap
- requestPayloadHexSha256Hash
- hex-encoded SHA256 hash of request's payload. May be null or "" in
which case the default SHA256 hash of an empty string is used.public static String awsV4BuildStringToSign(String requestSignatureVersion, String canonicalRequestString, String timestampISO8601, String region)
requestSignatureVersion
- request signature version string, e.g. "AWS4-HMAC-SHA256"canonicalRequestString
- canonical request string as generated by awsV4BuildCanonicalRequestString(HttpUriRequest, String)
timestampISO8601
- timestamp of request creation in ISO8601 formatregion
- region to which the request will be sent
"http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"public static byte[] awsV4BuildSigningKey(String secretAccessKey, String timestampISO8601, String region)
secretAccessKey
- account holder's secret access keytimestampISO8601
- timestamp of request creation in ISO8601 formatregion
- region to which the request will be sent
"http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"public static String awsV4BuildAuthorizationHeaderValue(String accessKey, String requestSignature, String requestSignatureVersion, String canonicalRequestString, String timestampISO8601, String region)
accessKey
- account holder's access keyrequestSignature
- request signature as generated signing the string to sign from
awsV4BuildStringToSign(String, String, String, String)
with the key from
awsV4BuildSigningKey(String, String, String)
requestSignatureVersion
- request signature version string, e.g. "AWS4-HMAC-SHA256"canonicalRequestString
- canonical request string as generated by
awsV4BuildCanonicalRequestString(HttpUriRequest, String)
timestampISO8601
- timestamp of request creation in ISO8601 formatregion
- region to which request will be sent, see
"http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region"public static URI awsV4CorrectHostnameForRegion(URI uri, String region)
uri
- region
- public static String awsV4EncodeURI(CharSequence input, boolean encodeSlash)
input
- URI or URI-fragment string to encode.encodeSlash
- true if slash (/) character should be encoded.Copyright © 2006–2018. All rights reserved.