1 import 'express-validator'
2 import * as express from 'express'
4 import { database as db } from '../initializers'
7 checkSignature as peertubeCryptoCheckSignature
10 function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) {
11 const host = req.body.signature.host
12 db.Pod.loadByHost(host)
15 logger.error('Unknown pod %s.', host)
16 return res.sendStatus(403)
19 logger.debug('Checking signature from %s.', host)
22 // If there is data in the body the sender used it for its signature
23 // If there is no data we just use its host as signature
25 signatureShouldBe = req.body.data
27 signatureShouldBe = host
30 const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature)
32 if (signatureOk === true) {
40 logger.error('Signature is not okay in body for %s.', req.body.signature.host)
41 return res.sendStatus(403)
44 logger.error('Cannot get signed host in body.', { error: err })
45 return res.sendStatus(500)
49 // ---------------------------------------------------------------------------