aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/misc.js
diff options
context:
space:
mode:
Diffstat (limited to 'middlewares/misc.js')
-rw-r--r--middlewares/misc.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/middlewares/misc.js b/middlewares/misc.js
index dbb604db3..cc4e2e8a4 100644
--- a/middlewares/misc.js
+++ b/middlewares/misc.js
@@ -5,7 +5,7 @@
5 var ursa = require('ursa') 5 var ursa = require('ursa')
6 6
7 var logger = require('../helpers/logger') 7 var logger = require('../helpers/logger')
8 var PodsDB = require('../initializers/database').PodsDB 8 var Pods = require('../models/pods')
9 var utils = require('../helpers/utils') 9 var utils = require('../helpers/utils')
10 10
11 var miscMiddleware = { 11 var miscMiddleware = {
@@ -28,18 +28,19 @@
28 } 28 }
29 29
30 function decryptBody (req, res, next) { 30 function decryptBody (req, res, next) {
31 PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) { 31 var url = req.body.signature.url
32 Pods.findByUrl(url, function (err, pod) {
32 if (err) { 33 if (err) {
33 logger.error('Cannot get signed url in decryptBody.', { error: err }) 34 logger.error('Cannot get signed url in decryptBody.', { error: err })
34 return res.sendStatus(500) 35 return res.sendStatus(500)
35 } 36 }
36 37
37 if (pod === null) { 38 if (pod === null) {
38 logger.error('Unknown pod %s.', req.body.signature.url) 39 logger.error('Unknown pod %s.', url)
39 return res.sendStatus(403) 40 return res.sendStatus(403)
40 } 41 }
41 42
42 logger.debug('Decrypting body from %s.', req.body.signature.url) 43 logger.debug('Decrypting body from %s.', url)
43 44
44 var crt = ursa.createPublicKey(pod.publicKey) 45 var crt = ursa.createPublicKey(pod.publicKey)
45 var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex') 46 var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex')