diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-31 11:23:52 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-31 11:23:52 +0100 |
commit | c45f7f84001c2731909db04dd82e1c1f290386eb (patch) | |
tree | b7e57420a1f65dfbbacc1a532bf489c9bea6125d /middlewares/misc.js | |
parent | cda021079ff455cc0fd0eb95a5395fa808ab63d1 (diff) | |
download | PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.tar.gz PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.tar.zst PeerTube-c45f7f84001c2731909db04dd82e1c1f290386eb.zip |
Infile code reorganization
Diffstat (limited to 'middlewares/misc.js')
-rw-r--r-- | middlewares/misc.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/middlewares/misc.js b/middlewares/misc.js index f814acd9f..dbb604db3 100644 --- a/middlewares/misc.js +++ b/middlewares/misc.js | |||
@@ -1,16 +1,19 @@ | |||
1 | ;(function () { | 1 | ;(function () { |
2 | 'use strict' | 2 | 'use strict' |
3 | 3 | ||
4 | var ursa = require('ursa') | ||
5 | var fs = require('fs') | 4 | var fs = require('fs') |
5 | var ursa = require('ursa') | ||
6 | 6 | ||
7 | var logger = require('../helpers/logger') | 7 | var logger = require('../helpers/logger') |
8 | var utils = require('../helpers/utils') | ||
9 | var PodsDB = require('../initializers/database').PodsDB | 8 | var PodsDB = require('../initializers/database').PodsDB |
9 | var utils = require('../helpers/utils') | ||
10 | 10 | ||
11 | var misc = {} | 11 | var miscMiddleware = { |
12 | cache: cache, | ||
13 | decryptBody: decryptBody | ||
14 | } | ||
12 | 15 | ||
13 | misc.cache = function (cache) { | 16 | function cache (cache) { |
14 | return function (req, res, next) { | 17 | return function (req, res, next) { |
15 | // If we want explicitly a cache | 18 | // If we want explicitly a cache |
16 | // Or if we don't specify if we want a cache or no and we are in production | 19 | // Or if we don't specify if we want a cache or no and we are in production |
@@ -24,7 +27,7 @@ | |||
24 | } | 27 | } |
25 | } | 28 | } |
26 | 29 | ||
27 | misc.decryptBody = function (req, res, next) { | 30 | function decryptBody (req, res, next) { |
28 | PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) { | 31 | PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) { |
29 | if (err) { | 32 | if (err) { |
30 | logger.error('Cannot get signed url in decryptBody.', { error: err }) | 33 | logger.error('Cannot get signed url in decryptBody.', { error: err }) |
@@ -42,7 +45,7 @@ | |||
42 | var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex') | 45 | var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex') |
43 | 46 | ||
44 | if (signature_ok === true) { | 47 | if (signature_ok === true) { |
45 | var myKey = ursa.createPrivateKey(fs.readFileSync(utils.certDir + 'peertube.key.pem')) | 48 | var myKey = ursa.createPrivateKey(fs.readFileSync(utils.getCertDir() + 'peertube.key.pem')) |
46 | var decryptedKey = myKey.decrypt(req.body.key, 'hex', 'utf8') | 49 | var decryptedKey = myKey.decrypt(req.body.key, 'hex', 'utf8') |
47 | req.body.data = JSON.parse(utils.symetricDecrypt(req.body.data, decryptedKey)) | 50 | req.body.data = JSON.parse(utils.symetricDecrypt(req.body.data, decryptedKey)) |
48 | delete req.body.key | 51 | delete req.body.key |
@@ -55,5 +58,7 @@ | |||
55 | }) | 58 | }) |
56 | } | 59 | } |
57 | 60 | ||
58 | module.exports = misc | 61 | // --------------------------------------------------------------------------- |
62 | |||
63 | module.exports = miscMiddleware | ||
59 | })() | 64 | })() |