aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/secure.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/middlewares/secure.js
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/middlewares/secure.js')
-rw-r--r--server/middlewares/secure.js52
1 files changed, 0 insertions, 52 deletions
diff --git a/server/middlewares/secure.js b/server/middlewares/secure.js
deleted file mode 100644
index 7c5c72508..000000000
--- a/server/middlewares/secure.js
+++ /dev/null
@@ -1,52 +0,0 @@
1'use strict'
2
3const db = require('../initializers/database')
4const logger = require('../helpers/logger')
5const peertubeCrypto = require('../helpers/peertube-crypto')
6
7const secureMiddleware = {
8 checkSignature
9}
10
11function checkSignature (req, res, next) {
12 const host = req.body.signature.host
13 db.Pod.loadByHost(host, function (err, pod) {
14 if (err) {
15 logger.error('Cannot get signed host in body.', { error: err })
16 return res.sendStatus(500)
17 }
18
19 if (pod === null) {
20 logger.error('Unknown pod %s.', host)
21 return res.sendStatus(403)
22 }
23
24 logger.debug('Checking signature from %s.', host)
25
26 let signatureShouldBe
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
29 if (req.body.data) {
30 signatureShouldBe = req.body.data
31 } else {
32 signatureShouldBe = host
33 }
34
35 const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature)
36
37 if (signatureOk === true) {
38 res.locals.secure = {
39 pod
40 }
41
42 return next()
43 }
44
45 logger.error('Signature is not okay in body for %s.', req.body.signature.host)
46 return res.sendStatus(403)
47 })
48}
49
50// ---------------------------------------------------------------------------
51
52module.exports = secureMiddleware