index.js (1102B)
1 const express = require('express') 2 const hmac = require('./hmac') 3 4 // web app //////////////////////////////////////////////////////////////////// 5 6 const sec = hmac.gen_key() 7 8 const app = express() 9 10 app.get('/', (req, res) => { 11 res.send('waiting to do something cool..') 12 }) 13 14 app.get('/hmac', async (req, res) => { 15 const saf = req.query.safe 16 const del = req.query.delay 17 const fil = req.query.file 18 const sig = req.query.signature 19 20 const msg = Buffer.from(fil).toString('hex') 21 const safe = saf == "true" 22 const wat = parseInt(del, 10) 23 24 const valid = safe 25 ? hmac.verify_hmac_sha1(sec, msg, sig) 26 : await hmac.insecure_compare(sec, msg, sig, wat) 27 28 if (valid) { 29 res.status(200).send({ 'HTTP': 200 }) 30 } else { 31 res.status(500).send({ 'HTTP': 500 }) 32 } 33 34 }) 35 36 const port = 3000 37 38 app.listen(port, () => { 39 console.log(`server listening on ${port}`) 40 }) 41 42 console.log('server generated the following key:') 43 console.log(`${sec}`) 44 console.log('for dev convenience, hmac for \'secrets.csv\' is:') 45 console.log(`${hmac.hmac_sha1(sec, Buffer.from('secrets.csv').toString('hex'))}`) 46