-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverCheck.js
35 lines (24 loc) · 1014 Bytes
/
serverCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var express = require('express');
var crypto = require('crypto');
var bodyParser = require('body-parser');
JSON.minify = require('node-json-minify');
JSON.canonicalStringify = require('canonical-json');
var app = express();
app.use(bodyParser.json());
//app.use(bodyParser.urlencoded({extended: true}));
app.post('/api/v1/status', function(request, response) {
console.log("Got response: " + response.statusCode);
console.log(request.body); // your JSON
//var data = JSON.parse(request.body);
var secret = '4423';
//var dString = request.body.envelope;
var dString = JSON.canonicalStringify(request.body.envelope);
var mString = JSON.minify(dString);
console.log('JSON envelope:' + mString);
var hash = crypto.createHmac('sha256', secret)
.update(mString)
.digest('base64');
console.log('From the post, signature = ' + request.body.signature);
console.log('From math, signature = ' + hash);
});
app.listen(3000);