lucee.Componentmodels.Sv4Util
Amazon Web Services Signature 4 Utility for ColdFusion Version Date: 2016-04-12 (Alpha) Copyright 2016 Leigh (cfsearching) Requirements: Adobe ColdFusion 10+ AWS Signature 4 specifications: http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Constructor Summary | |
---|---|
init()
Creates a new instance of the utility for generating signatures using the supplied settings. |
Method Summary | |
---|---|
private string
|
buildAuthorizationHeader(struct requestHeaders, string signedHeaders, string credentialScope, string signature, string accessKey)
Generates Authorization header string. |
private string
|
buildCanonicalHeaders(struct requestHeaders)
Generates a list of canonical headers. |
private string
|
buildCanonicalQueryString(struct requestParams, [boolean isEncoded='true'])
Generates canonical query string. |
private string
|
buildCanonicalRequest(string requestMethod, string canonicalURI, string canonicalQueryString, string canonicalHeaders, string signedHeaders, string requestPayload)
Generate canonical request string. |
string
|
buildCanonicalURI(string requestURI)
Generates canonical URI. |
private string
|
buildCredentialScope(string dateStamp, string regionName, string serviceName)
Generates string indicating the scope for which the signature is valid. |
private string
|
buildSignedHeaders(struct requestHeaders, array excludeNames)
Generates a list of signed header names. |
private string
|
cleanHeader(string text)
Removes extraneous white space from header names or values. |
private array
|
cleanHeaderNames(array names)
Scrubs header names and values:. |
private struct
|
cleanHeaders(struct headers)
Scrubs header names and values:. |
private struct
|
encodeQueryParams(struct queryParams)
URL encode query parameters and names. |
struct
|
generateSignatureData(string requestMethod, string hostName, string requestURI, any requestBody, struct requestHeaders, struct requestParams, string accessKey, string secretKey, string regionName, string serviceName, [array excludeHeaders='[runtime expression]'], [string amzDate], [string dateStamp], [boolean presignDownloadURL='false'])
Generates Signature 4 properties for the supplied request settings. |
private binary
|
generateSignatureKey(string dateStamp, string regionName, string serviceName, string secretKey, [string algorithm='HMACSHA256'])
Generates signing key for AWS Signature V4. |
private string
|
generateStringToSign(string amzDate, string credentialScope, string canonicalRequest)
Generates request string to sign. |
struct
|
getUTCStrings()
Returns current UTC date and time in the following formats:. |
private string
|
hash256(any text)
Convenience method that hashes the supplied value, with SHA256. |
private binary
|
hmacBinary(string message, binary key, [string algorithm='HMACSHA256'], [string encoding='UTF-8'])
Convenience method which generates a (binary) HMAC code for the specified message. |
private string
|
urlEncodeForAWS([string value])
URL encodes the supplied string per RFC 3986, which defines the following as. |
string
|
urlEncodePath([string value])
URL encodes the supplied string per RFC 3986, which defines the following as. |
Methods inherited from class lucee.Component |
---|
None |
Constructor Detail |
---|
Creates a new instance of the utility for generating signatures using the supplied settings
Method Detail |
---|
Generates Authorization header string. Format: algorithm + ' ' + 'Credential=' + access_key + '/' + credential_scope + ', ' + 'SignedHeaders=' + signed_headers + ', ' + 'Signature=' + signature
requestHeaders
signedHeaders
credentialScope
signature
accessKey
Generates a list of canonical headers
requestHeaders
- Structure containing headers to be included in request hashGenerates canonical query string
requestParams
- Structure containing all parameters passed via the query string.isEncoded
- If true, the supplied parameters are already url encodedGenerate canonical request string
requestMethod
- - Request operation, ie PUT, GET, POST, etcetera.canonicalURI
- - Canonical URL string. See buildCanonicalURIcanonicalQueryString
- - Canonical query string. See buildCanonicalQueryStringcanonicalHeaders
- - Canonical header string. See buildCanonicalHeaderssignedHeaders
- - List of signed headers. See buildSignedHeadersrequestPayload
- - For signed requests, this is the hash of the request body. Otherwise, the raw request bodyGenerates canonical URI. Encoded, absolute path component of the URI, which is everything in the URI from the HTTP host to the question mark character ("?") that begins the query string parameters (if any)
requestURI
Generates string indicating the scope for which the signature is valid. Credential scope is represented by a slash-separated string of dimensions in the following order: dateStamp / regionName / serviceName / terminationString
dateStamp
- - Current date in UTC (must be same as X-Amz-Date date). Format yyyyMMddregionName
- - Name of the target region, UTF-8 encoded. Example "us-east-1"serviceName
- - Name of the target service, UTF-8 encoded. Example "s3"Generates a list of signed header names.
"...By adding this list of headers, you tell AWS which headers in the request are part of the signing process and which ones AWS can ignore (for example, any additional headers added by a proxy) for purposes of validating the request."
requestHeaders
- Raw headers to be included in requestexcludeNames
- Names of any headers AWS should ignore for the signing processRemoves extraneous white space from header names or values. See http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
text
- Text to scrubScrubs header names and values:
names
Scrubs header names and values:
headers
- Header names and values to scrubURL encode query parameters and names
queryParams
Generates Signature 4 properties for the supplied request settings.
requestMethod
- - Request operation, ie PUT, GET, POST, etcetera.hostName
- - Target host name, example: bucketname.s3.amazonaws.comrequestURI
- - Absolute path of the URI. Portion of the URL after the host, to the "?" beginning the query stringrequestBody
- - Body of the request. Either a string or binary value.requestHeaders
- - Structure of http headers for used the request. Mandatory host and date headers are automatically generated.requestParams
- - Structure containing any url parameters for the request. Mandatory parameters are automatically generated.accessKey
secretKey
regionName
- - (Optional) Override the instance region name with this value. Example "us-east-1"serviceName
- - (Optional) Override the instance service name with this value. Example "s3"excludeHeaders
- - (Optional) List of header names AWS can exclude from the signing process. Default is an empty array, which means all headers should be "signed"amzDate
- - (Optional) Override the automatic X-Amz-Date calculation with this value. Current UTC date. If supplied, @dateStamp is required. Format: yyyyMMddTHHnnssZdateStamp
- - (Optional) Override the automatic dateStamp calculation with this value. Current UTC date (only). If supplied, @amzDate is required. Format: yyyyMMddpresignDownloadURL
Generates signing key for AWS Signature V4
Source: http://stackoverflow.com/questions/32513197/how-to-derive-a-sign-in-key-for-aws-signature-version-4-in-coldfusion
dateStamp
- Date stamp in yyyymmdd format. Example: 20150830regionName
- Region name that is part of the service's endpoint (alphanumeric). Example: "us-east-1"serviceName
- Service name that is part of the service's endpoint (alphanumeric). Example: "s3"secretKey
algorithm
- HMAC algorithm. Default is "HMACSHA256"Generates request string to sign
amzDate
- - Current timestamp in UTC. Format yyyyMMddTHHnnssZcredentialScope
- - String defining scope of request. See buildCredentialScope().canonicalRequest
- - Canonical request stringReturns current UTC date and time in the following formats: - dateStamp - Current UTC date, format: yyyymmdd - timeStamp - Current UTC date and time, format: yyyymmddTHHnnssZ
Convenience method that hashes the supplied value, with SHA256
text
- value to hashConvenience method which generates a (binary) HMAC code for the specified message
message
- Message to signkey
- HMAC key in binary formalgorithm
- Signing algorithm. [ Default is "HMACSHA256" ]encoding
- Character encoding of message string. [ Default is UTF-8 ]URL encodes the supplied string per RFC 3986, which defines the following as unreserved characters that should NOT be encoded: A-Z, a-z, 0-9, hyphen ( - ), underscore ( _ ), period ( . ), and tilde ( ~ ).
value
- string to encodeURL encodes the supplied string per RFC 3986, which defines the following as unreserved characters that should NOT be encoded: A-Z, a-z, 0-9, hyphen ( - ), underscore ( _ ), period ( . ), and tilde ( ~ ).
value
- string to encode