]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/secure.js
3 const logger
= require('../helpers/logger')
4 const mongoose
= require('mongoose')
5 const peertubeCrypto
= require('../helpers/peertube-crypto')
7 const Pod
= mongoose
.model('Pod')
9 const secureMiddleware
= {
13 function checkSignature (req
, res
, next
) {
14 const host
= req
.body
.signature
.host
15 Pod
.loadByHost(host
, function (err
, pod
) {
17 logger
.error('Cannot get signed host in body.', { error: err
})
18 return res
.sendStatus(500)
22 logger
.error('Unknown pod %s.', host
)
23 return res
.sendStatus(403)
26 logger
.debug('Checking signature from %s.', host
)
28 const signatureOk
= peertubeCrypto
.checkSignature(pod
.publicKey
, host
, req
.body
.signature
.signature
)
30 if (signatureOk
=== true) {
34 logger
.error('Signature is not okay in body for %s.', req
.body
.signature
.host
)
35 return res
.sendStatus(403)
39 // ---------------------------------------------------------------------------
41 module
.exports
= secureMiddleware