1 import { database as db } from '../initializers'
4 checkSignature as peertubeCryptoCheckSignature
7 function checkSignature (req, res, next) {
8 const host = req.body.signature.host
9 db.Pod.loadByHost(host, function (err, pod) {
11 logger.error('Cannot get signed host in body.', { error: err })
12 return res.sendStatus(500)
16 logger.error('Unknown pod %s.', host)
17 return res.sendStatus(403)
20 logger.debug('Checking signature from %s.', host)
23 // If there is data in the body the sender used it for its signature
24 // If there is no data we just use its host as signature
26 signatureShouldBe = req.body.data
28 signatureShouldBe = host
31 const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature)
33 if (signatureOk === true) {
41 logger.error('Signature is not okay in body for %s.', req.body.signature.host)
42 return res.sendStatus(403)
46 // ---------------------------------------------------------------------------