1 const db = require('../initializers/database')
2 const logger = require('../helpers/logger')
3 const peertubeCrypto = require('../helpers/peertube-crypto')
5 function checkSignature (req, res, next) {
6 const host = req.body.signature.host
7 db.Pod.loadByHost(host, function (err, pod) {
9 logger.error('Cannot get signed host in body.', { error: err })
10 return res.sendStatus(500)
14 logger.error('Unknown pod %s.', host)
15 return res.sendStatus(403)
18 logger.debug('Checking signature from %s.', host)
21 // If there is data in the body the sender used it for its signature
22 // If there is no data we just use its host as signature
24 signatureShouldBe = req.body.data
26 signatureShouldBe = host
29 const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature)
31 if (signatureOk === true) {
39 logger.error('Signature is not okay in body for %s.', req.body.signature.host)
40 return res.sendStatus(403)
44 // ---------------------------------------------------------------------------