dimanche 26 juillet 2015

Node.js: Calculation of AWS Signature

I am having issues with getting AWS Signature calculation working. The objective is to read 4 passed as part of URL (key, dateStamp, regionName, serviceName)and use them for calculation of the signature. I am not Node.js expert, and you assistance and time are appreciated.

  1. Example of URL: http://localhost:3000/getSignature?key=ASIAJSLN6INQGFK7XX7Q&dateStamp=26072015&regionName=us-east-1&serviceName=IAM
  2. AWS specification for java script: http://ift.tt/1y4REFg
  3. Example of signature: Signature=265f004b995af67102af3c5ff84b0f34e091165a190ac62730c76e919d91b77a

My Node.js code...

var express = require('express');
var app = express();
var port = process.env.PORT || 3000;

//Crypto
var Crypto = require('crypto-js');

// routes
app.get('/getSignature', function(req, res) {
    var key = req.param('key');
    var dateStamp = req.param('dateStamp');
    var regionName = req.param('regionName');
    var serviceName = req.param('serviceName');

    var kDate = Crypto.HMAC(Crypto.SHA256, dateStamp, "AWS4" + key, {asBytes: true});
    var kRegion = Crypto.HMAC(Crypto.SHA256, regionName, kDate, {asBytes: true});
    var kService = Crypto.HMAC(Crypto.SHA256, serviceName, kRegion, {asBytes: true});
    var kSigning = Crypto.HMAC(Crypto.SHA256, "aws4_request", kService, {asBytes: true});
    res.send(key + ' ' + dateStamp + ' ' + regionName + ' ' + serviceName + ' ' + kSigning);

});

// start the server
app.listen(port);
console.log('Server started! At http://localhost:' + port);

I am getting the following run-time errors: TypeError: undefined is not a function at c:\Users\xxx\WebstormProjects\Unscriptd\app.js:34:24 at Layer.handle [as handle_request] (c:\Users\xxx\WebstormProjects\Unscriptd\node_modules\express\lib\router\layer.js:95:5) at next (c:\Users\xxx\WebstormProjects\Unscriptd\node_modules\express\lib\router\route.js:131:13)

Crypto-js library was imported.

Thank you. Nikolai




Aucun commentaire:

Enregistrer un commentaire