;(function () {
'use strict'
- var ursa = require('ursa')
var fs = require('fs')
+ var ursa = require('ursa')
var logger = require('../helpers/logger')
- var utils = require('../helpers/utils')
var PodsDB = require('../initializers/database').PodsDB
+ var utils = require('../helpers/utils')
- var misc = {}
+ var miscMiddleware = {
+ cache: cache,
+ decryptBody: decryptBody
+ }
- misc.cache = function (cache) {
+ function cache (cache) {
return function (req, res, next) {
// If we want explicitly a cache
// Or if we don't specify if we want a cache or no and we are in production
}
}
- misc.decryptBody = function (req, res, next) {
+ function decryptBody (req, res, next) {
PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) {
if (err) {
logger.error('Cannot get signed url in decryptBody.', { error: err })
var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex')
if (signature_ok === true) {
- var myKey = ursa.createPrivateKey(fs.readFileSync(utils.certDir + 'peertube.key.pem'))
+ var myKey = ursa.createPrivateKey(fs.readFileSync(utils.getCertDir() + 'peertube.key.pem'))
var decryptedKey = myKey.decrypt(req.body.key, 'hex', 'utf8')
req.body.data = JSON.parse(utils.symetricDecrypt(req.body.data, decryptedKey))
delete req.body.key
})
}
- module.exports = misc
+ // ---------------------------------------------------------------------------
+
+ module.exports = miscMiddleware
})()