]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/secure.js
Server: remove encryption when seending requests to other pods
[github/Chocobozzz/PeerTube.git] / server / middlewares / secure.js
index 9ecbf5df18db6d3a00b086973839e1e106274fb0..ee836beed45059ce362f30e104db46bb13c054a3 100644 (file)
@@ -1,46 +1,38 @@
 'use strict'
 
 const logger = require('../helpers/logger')
-const peertubeCrypto = require('../helpers/peertubeCrypto')
-const Pods = require('../models/pods')
+const mongoose = require('mongoose')
+const peertubeCrypto = require('../helpers/peertube-crypto')
+
+const Pod = mongoose.model('Pod')
 
 const secureMiddleware = {
-  decryptBody: decryptBody
+  checkSignature
 }
 
-function decryptBody (req, res, next) {
-  const url = req.body.signature.url
-  Pods.findByUrl(url, function (err, pod) {
+function checkSignature (req, res, next) {
+  const host = req.body.signature.host
+  Pod.loadByHost(host, function (err, pod) {
     if (err) {
-      logger.error('Cannot get signed url in decryptBody.', { error: err })
+      logger.error('Cannot get signed host in body.', { error: err })
       return res.sendStatus(500)
     }
 
     if (pod === null) {
-      logger.error('Unknown pod %s.', url)
+      logger.error('Unknown pod %s.', host)
       return res.sendStatus(403)
     }
 
-    logger.debug('Decrypting body from %s.', url)
-
-    const signature_ok = peertubeCrypto.checkSignature(pod.publicKey, url, req.body.signature.signature)
-
-    if (signature_ok === true) {
-      peertubeCrypto.decrypt(req.body.key, req.body.data, function (err, decrypted) {
-        if (err) {
-          logger.error('Cannot decrypt data.', { error: err })
-          return res.sendStatus(500)
-        }
+    logger.debug('Checking signature from %s.', host)
 
-        req.body.data = JSON.parse(decrypted)
-        delete req.body.key
+    const signatureOk = peertubeCrypto.checkSignature(pod.publicKey, host, req.body.signature.signature)
 
-        next()
-      })
-    } else {
-      logger.error('Signature is not okay in decryptBody for %s.', req.body.signature.url)
-      return res.sendStatus(403)
+    if (signatureOk === true) {
+      return next()
     }
+
+    logger.error('Signature is not okay in body for %s.', req.body.signature.host)
+    return res.sendStatus(403)
   })
 }