]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/secure.js
7c5c72508d051dbc785521513cf17be2e83d103a
3 const db
= require('../initializers/database')
4 const logger
= require('../helpers/logger')
5 const peertubeCrypto
= require('../helpers/peertube-crypto')
7 const secureMiddleware
= {
11 function checkSignature (req
, res
, next
) {
12 const host
= req
.body
.signature
.host
13 db
.Pod
.loadByHost(host
, function (err
, pod
) {
15 logger
.error('Cannot get signed host in body.', { error: err
})
16 return res
.sendStatus(500)
20 logger
.error('Unknown pod %s.', host
)
21 return res
.sendStatus(403)
24 logger
.debug('Checking signature from %s.', host
)
27 // If there is data in the body the sender used it for its signature
28 // If there is no data we just use its host as signature
30 signatureShouldBe
= req
.body
.data
32 signatureShouldBe
= host
35 const signatureOk
= peertubeCrypto
.checkSignature(pod
.publicKey
, signatureShouldBe
, req
.body
.signature
.signature
)
37 if (signatureOk
=== true) {
45 logger
.error('Signature is not okay in body for %s.', req
.body
.signature
.host
)
46 return res
.sendStatus(403)
50 // ---------------------------------------------------------------------------
52 module
.exports
= secureMiddleware