diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-04 21:10:33 +0100 |
commit | c173e56520b0fe4206b9ea8049b6add40bfeabcd (patch) | |
tree | 264c6cbf1bf81a6522685b4be5771bbeef4cd5dc /middlewares/misc.js | |
parent | c45f7f84001c2731909db04dd82e1c1f290386eb (diff) | |
download | PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.gz PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.tar.zst PeerTube-c173e56520b0fe4206b9ea8049b6add40bfeabcd.zip |
Split models
Diffstat (limited to 'middlewares/misc.js')
-rw-r--r-- | middlewares/misc.js | 9 |
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') |