diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-09 17:51:58 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | e4f97babf701481b55cc10fb3448feab5f97c867 (patch) | |
tree | af37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/middlewares/secure.ts | |
parent | 343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff) | |
download | PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip |
Begin activitypub
Diffstat (limited to 'server/middlewares/secure.ts')
-rw-r--r-- | server/middlewares/secure.ts | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/server/middlewares/secure.ts b/server/middlewares/secure.ts deleted file mode 100644 index 5dd809f15..000000000 --- a/server/middlewares/secure.ts +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { database as db } from '../initializers' | ||
5 | import { | ||
6 | logger, | ||
7 | checkSignature as peertubeCryptoCheckSignature | ||
8 | } from '../helpers' | ||
9 | import { PodSignature } from '../../shared' | ||
10 | |||
11 | async function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
12 | const signatureObject: PodSignature = req.body.signature | ||
13 | const host = signatureObject.host | ||
14 | |||
15 | try { | ||
16 | const pod = await db.Pod.loadByHost(host) | ||
17 | if (pod === null) { | ||
18 | logger.error('Unknown pod %s.', host) | ||
19 | return res.sendStatus(403) | ||
20 | } | ||
21 | |||
22 | logger.debug('Checking signature from %s.', host) | ||
23 | |||
24 | let signatureShouldBe | ||
25 | // If there is data in the body the sender used it for its signature | ||
26 | // If there is no data we just use its host as signature | ||
27 | if (req.body.data) { | ||
28 | signatureShouldBe = req.body.data | ||
29 | } else { | ||
30 | signatureShouldBe = host | ||
31 | } | ||
32 | |||
33 | const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, signatureObject.signature) | ||
34 | |||
35 | if (signatureOk === true) { | ||
36 | res.locals.secure = { | ||
37 | pod | ||
38 | } | ||
39 | |||
40 | return next() | ||
41 | } | ||
42 | |||
43 | logger.error('Signature is not okay in body for %s.', signatureObject.host) | ||
44 | return res.sendStatus(403) | ||
45 | } catch (err) { | ||
46 | logger.error('Cannot get signed host in body.', { error: err.stack, signature: signatureObject.signature }) | ||
47 | return res.sendStatus(500) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | // --------------------------------------------------------------------------- | ||
52 | |||
53 | export { | ||
54 | checkSignature | ||
55 | } | ||