diff --git a/common/lambda-core/awssig4.js b/common/lambda-core/awssig4.js index f9f9f35..85dcffb 100644 --- a/common/lambda-core/awssig4.js +++ b/common/lambda-core/awssig4.js @@ -14,7 +14,8 @@ * limitations under the License. */ -import utils from "./utils.js"; +import awscred from "./awscredentials.js"; +import utils from "./utils.js"; const mod_hmac = require('crypto'); @@ -252,6 +253,22 @@ function _splitCachedValues(cached) { return [eightDigitDate, kSigningHash] } +/** + * Outputs the timestamp used to sign the request, so that it can be added to + * the 'x-amz-date' header and sent by NGINX. The output format is + * ISO 8601: YYYYMMDD'T'HHMMSS'Z'. + * @see {@link https://docs.aws.amazon.com/general/latest/gr/sigv4-date-handling.html | Handling dates in Signature Version 4} + * + * @param r {Request} HTTP request object (not used, but required for NGINX configuration) + * @returns {string} ISO 8601 timestamp + */ +function awsHeaderDate(r) { + return utils.getAmzDatetime( + awscred.getNow(), + utils.getEightDigitDate(awscred.getNow()) + ); +} + /** * Return a payload hash in the header * @@ -267,6 +284,7 @@ function awsHeaderPayloadHash(r) { } export default { + awsHeaderDate, awsHeaderPayloadHash, signatureV4, // These functions do not need to be exposed, but they are exposed so that diff --git a/common/lambda-core/lambda_ngx_http.conf b/common/lambda-core/lambda_ngx_http.conf index 7c32e9d..aca0c2e 100644 --- a/common/lambda-core/lambda_ngx_http.conf +++ b/common/lambda-core/lambda_ngx_http.conf @@ -5,7 +5,7 @@ js_import /etc/nginx/serverless/lambdagateway.js; # This header is needed when doing v4 signature authentication. It # specifies the timestamp in which the signature was generated and is used with # the x-amz-date header. -js_set $awsDate lambdagateway.awsHeaderDate; +js_set $awsDate awssig4.awsHeaderDate; js_set $awsPayloadHash awssig4.awsHeaderPayloadHash; js_set $awsSessionToken awscredentials.sessionToken; js_set $lambdaFunctionARNAuth lambdagateway.lambdaFunctionARNAuth; diff --git a/common/lambda-core/lambdagateway.js b/common/lambda-core/lambdagateway.js index 4b4a4a7..a642eb0 100644 --- a/common/lambda-core/lambdagateway.js +++ b/common/lambda-core/lambdagateway.js @@ -202,33 +202,6 @@ function _isHeaderToBeStripped(headerName, additionalHeadersToStrip) { return false; } -/** - * Outputs the timestamp used to sign the request, so that it can be added to - * the 'Date' header and sent by NGINX. - * - * @param r {Request} HTTP request object (not used, but required for NGINX configuration) - * @returns {string} RFC2616 timestamp - */ -function lambdaDate(r) { - return awscred.getNow().toUTCString(); -} - -/** - * Outputs the timestamp used to sign the request, so that it can be added to - * the 'x-amz-date' header and sent by NGINX. The output format is - * ISO 8601: YYYYMMDD'T'HHMMSS'Z'. - * @see {@link https://docs.aws.amazon.com/general/latest/gr/sigv4-date-handling.html | Handling dates in Signature Version 4} - * - * @param r {Request} HTTP request object (not used, but required for NGINX configuration) - * @returns {string} ISO 8601 timestamp - */ -function awsHeaderDate(r) { - return utils.getAmzDatetime( - awscred.getNow(), - utils.getEightDigitDate(awscred.getNow()) - ); -} - function trailslashControl(r) { if (APPEND_SLASH) { const hasExtension = /\/[^.\/]+\.[^.]+$/; @@ -295,12 +268,10 @@ function _isDirectory(path) { export default { - awsHeaderDate, editHeaders, lambdaFunctionARNAuth, lambdaFunctionARNHost, lambdaFunctionURLAuth, - lambdaDate, lambdaPort, lambdaProto, lambdaURI, diff --git a/docs/development.md b/docs/development.md index 79a9975..0d8c9a9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1 +1,7 @@ # Development Guide + +## Integrating with AWS Signature + +## Extending the Gateway + +### Examples