}
misc.decryptBody = function (req, res, next) {
- logger.debug('Decrypting body.')
-
PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) {
if (err) {
logger.error('Cannot get signed url in decryptBody.', { error: err })
res.sendStatus(500)
}
- logger.debug('Found one pod which could send the message.', { pod: pod.publicKey, url: req.body.signature.url })
+ logger.debug('Decrypting body from %s.', req.body.signature.url)
var crt = ursa.createPublicKey(pod.publicKey)
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 decryptedKey = myKey.decrypt(req.body.key, 'hex', 'utf8')
- logger.debug(decryptedKey)
req.body.data = JSON.parse(utils.symetricDecrypt(req.body.data, decryptedKey))
- logger.debug('Decrypted.', { body: req.body })
+ delete req.body.key
} else {
logger.error('Signature is not okay in decryptBody for %s.', req.body.signature.url)
res.sendStatus(500)
req.checkBody('key', 'Should have a key').notEmpty()
req.checkBody('data', 'Should have data').notEmpty()
- logger.debug('Checking secureRequest parameters', { parameters: req.body })
+ logger.debug('Checking secureRequest parameters', { parameters: { data: req.body.data, keyLength: req.body.key.length } })
checkErrors(req, res, next)
}
var pods_list = computeWinningPods(urls, pods_score)
logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list })
- logger.debug('Make requests...')
makeRequestsToWinningPods(cert, pods_list)
})
})
}
function makePoolRequest (type, requests) {
- logger.debug('Make pool requests scheduled.')
PodsDB.find({}, { _id: 1, url: 1, publicKey: 1 }).exec(function (err, pods) {
if (err) throw err
}
}
- logger.debug('Sending informations to %s.', to_pod.url, { params: params })
+ logger.debug('Make retry requests to %s.', to_pod.url)
// Default 10 but in tests we want to be faster
var retries = utils.isTestInstance() ? 2 : 10
// Add data with POST requst ?
if (all_data.method === 'POST' && all_data.data) {
- logger.debug('Make a POST request.')
-
// Encrypt data ?
if (all_data.encrypt === true) {
var crt = ursa.createPublicKey(pod.publicKey)
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
} else {
- logger.debug('Make a GET/DELETE request')
makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
}
}, callback)