Top Description Fields Constructors Methods
org.eclipse.jgit.lfs.server.s3

pack-priv Class SignerV4

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION

Signing support for Amazon AWS signing V4

See http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
pack-priv static final String
private static final String
private static final String
pack-priv static final String
private static final String
private static final String
pack-priv static final String
private static final String
private static final String
pack-priv static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
addHostHeader(URL url, Map<String, String> headers)

private static void
private static String
private static String
private static String
private static String
private static String
canonicalRequest(URL endpoint, String httpMethod, String queryParameters, String canonicalizedHeaderNames, String canonicalizedHeaders, String bodyHash)

pack-priv static String

Returns:

The computed authorization string for the request. This value needs to be set as the header 'Authorization' on the subsequent HTTP request.
createAuthorizationQuery
(S3Config
configuration of S3 storage bucket this request should be signed for
bucketConfig
,
URL
HTTP request URL
url
,
String
HTTP method
httpMethod
,
Map<String, String>
The HTTP request headers; 'Host' and 'X-Amz-Date' will be added to this set.
headers
,
Map<String, String>
Any query parameters that will be added to the endpoint. The parameters should be specified in canonical format.
queryParameters
,
String
Pre-computed SHA256 hash of the request body content; this value should also be set as the header 'X-Amz-Content-SHA256' for non-streaming uploads.
bodyHash
)

Create an AWSV4 authorization for a request, suitable for embedding in query parameters.

pack-priv static Map<String, String>

Returns:

HTTP headers signd by an Authorization header added to the headers
createHeaderAuthorization
(S3Config
configuration of S3 storage bucket this request should be signed for
bucketConfig
,
URL
HTTP request URL
url
,
String
HTTP method
httpMethod
,
Map<String, String>
HTTP headers to sign
headers
,
String
Pre-computed SHA256 hash of the request body content; this value should also be set as the header 'X-Amz-Content-SHA256' for non-streaming uploads.
bodyHash
)

Sign headers for given bucket, url and HTTP method and add signature in Authorization header.

private static byte[]
createSignature(S3Config bucketConfig, String dateTimeStamp, String dateStamp, String scope, String canonicalRequest)

private static String
private static String
private static String
formatAuthorizationHeader(S3Config bucketConfig, String canonicalizedHeaderNames, String scope, byte[] signature)

private static String
private static byte[]
private static String
scope(String region, String dateStamp)

private static byte[]
sign(String stringData, byte[] key)

private static String
stringToSign(String scheme, String algorithm, String dateTime, String scope, String canonicalRequest)

private static String
toHex(byte[] bytes)

private static String
urlEncode(String url, boolean keepPathSlash)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALGORITHMback to summary
private static final String ALGORITHM
DATE_STRING_FORMATback to summary
private static final String DATE_STRING_FORMAT
HEXback to summary
private static final String HEX
HMACSHA256back to summary
private static final String HMACSHA256
ISO8601_BASIC_FORMATback to summary
private static final String ISO8601_BASIC_FORMAT
S3back to summary
private static final String S3
SCHEMEback to summary
private static final String SCHEME
TERMINATORback to summary
private static final String TERMINATOR
UNSIGNED_PAYLOADback to summary
pack-priv static final String UNSIGNED_PAYLOAD
UTCback to summary
private static final String UTC
X_AMZ_ALGORITHMback to summary
private static final String X_AMZ_ALGORITHM
X_AMZ_CONTENT_SHA256back to summary
pack-priv static final String X_AMZ_CONTENT_SHA256
X_AMZ_CREDENTIALback to summary
private static final String X_AMZ_CREDENTIAL
X_AMZ_DATEback to summary
private static final String X_AMZ_DATE
X_AMZ_EXPIRESback to summary
pack-priv static final String X_AMZ_EXPIRES
X_AMZ_SIGNATUREback to summary
private static final String X_AMZ_SIGNATURE
X_AMZ_SIGNED_HEADERSback to summary
private static final String X_AMZ_SIGNED_HEADERS
X_AMZ_STORAGE_CLASSback to summary
pack-priv static final String X_AMZ_STORAGE_CLASS

Constructor Detail

SignerV4back to summary
pack-priv SignerV4()

Method Detail

addHostHeaderback to summary
private static void addHostHeader(URL url, Map<String, String> headers)
appendQueryback to summary
private static void appendQuery(StringBuilder s, String key, String value)
canonicalizeHeaderNamesback to summary
private static String canonicalizeHeaderNames(Map<String, String> headers)
canonicalizeHeaderStringback to summary
private static String canonicalizeHeaderString(Map<String, String> headers)
canonicalizeQueryStringback to summary
private static String canonicalizeQueryString(Map<String, String> parameters)
canonicalizeResourcePathback to summary
private static String canonicalizeResourcePath(URL endpoint)
canonicalRequestback to summary
private static String canonicalRequest(URL endpoint, String httpMethod, String queryParameters, String canonicalizedHeaderNames, String canonicalizedHeaders, String bodyHash)
createAuthorizationQueryback to summary
pack-priv static String createAuthorizationQuery(S3Config bucketConfig, URL url, String httpMethod, Map<String, String> headers, Map<String, String> queryParameters, String bodyHash)

Create an AWSV4 authorization for a request, suitable for embedding in query parameters.

Parameters
bucketConfig:S3Config

configuration of S3 storage bucket this request should be signed for

url:URL

HTTP request URL

httpMethod:String

HTTP method

headers:Map<String, String>

The HTTP request headers; 'Host' and 'X-Amz-Date' will be added to this set.

queryParameters:Map<String, String>

Any query parameters that will be added to the endpoint. The parameters should be specified in canonical format.

bodyHash:String

Pre-computed SHA256 hash of the request body content; this value should also be set as the header 'X-Amz-Content-SHA256' for non-streaming uploads.

Returns:String

The computed authorization string for the request. This value needs to be set as the header 'Authorization' on the subsequent HTTP request.

createHeaderAuthorizationback to summary
pack-priv static Map<String, String> createHeaderAuthorization(S3Config bucketConfig, URL url, String httpMethod, Map<String, String> headers, String bodyHash)

Sign headers for given bucket, url and HTTP method and add signature in Authorization header.

Parameters
bucketConfig:S3Config

configuration of S3 storage bucket this request should be signed for

url:URL

HTTP request URL

httpMethod:String

HTTP method

headers:Map<String, String>

HTTP headers to sign

bodyHash:String

Pre-computed SHA256 hash of the request body content; this value should also be set as the header 'X-Amz-Content-SHA256' for non-streaming uploads.

Returns:Map<String, String>

HTTP headers signd by an Authorization header added to the headers

createSignatureback to summary
private static byte[] createSignature(S3Config bucketConfig, String dateTimeStamp, String dateStamp, String scope, String canonicalRequest)
dateStampback to summary
private static String dateStamp(Date now)
dateTimeStampISO8601back to summary
private static String dateTimeStampISO8601(Date now)
formatAuthorizationHeaderback to summary
private static String formatAuthorizationHeader(S3Config bucketConfig, String canonicalizedHeaderNames, String scope, byte[] signature)
formatAuthorizationQueryback to summary
private static String formatAuthorizationQuery(Map<String, String> queryParameters)
hashback to summary
private static byte[] hash(String s)
scopeback to summary
private static String scope(String region, String dateStamp)
signback to summary
private static byte[] sign(String stringData, byte[] key)
stringToSignback to summary
private static String stringToSign(String scheme, String algorithm, String dateTime, String scope, String canonicalRequest)
toHexback to summary
private static String toHex(byte[] bytes)
urlEncodeback to summary
private static String urlEncode(String url, boolean keepPathSlash)