]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/secure.js
Server: remove encryption when seending requests to other pods
[github/Chocobozzz/PeerTube.git] / server / middlewares / secure.js
... / ...
CommitLineData
1'use strict'
2
3const logger = require('../helpers/logger')
4const mongoose = require('mongoose')
5const peertubeCrypto = require('../helpers/peertube-crypto')
6
7const Pod = mongoose.model('Pod')
8
9const secureMiddleware = {
10 checkSignature
11}
12
13function checkSignature (req, res, next) {
14 const host = req.body.signature.host
15 Pod.loadByHost(host, function (err, pod) {
16 if (err) {
17 logger.error('Cannot get signed host in body.', { error: err })
18 return res.sendStatus(500)
19 }
20
21 if (pod === null) {
22 logger.error('Unknown pod %s.', host)
23 return res.sendStatus(403)
24 }
25
26 logger.debug('Checking signature from %s.', host)
27
28 const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, host, req.body.signature.signature)
29
30 if (signatureOk === true) {
31 return next()
32 }
33
34 logger.error('Signature is not okay in body for %s.', req.body.signature.host)
35 return res.sendStatus(403)
36 })
37}
38
39// ---------------------------------------------------------------------------
40
41module.exports = secureMiddleware