Skip to content

fix: move aws header date func to aws signature v4 lib #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion common/lambda-core/awssig4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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
*
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common/lambda-core/lambda_ngx_http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 0 additions & 29 deletions common/lambda-core/lambdagateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /\/[^.\/]+\.[^.]+$/;
Expand Down Expand Up @@ -295,12 +268,10 @@ function _isDirectory(path) {


export default {
awsHeaderDate,
editHeaders,
lambdaFunctionARNAuth,
lambdaFunctionARNHost,
lambdaFunctionURLAuth,
lambdaDate,
lambdaPort,
lambdaProto,
lambdaURI,
Expand Down
6 changes: 6 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Development Guide

## Integrating with AWS Signature

## Extending the Gateway

### Examples