]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/activitypub/signature.ts
360685512aae5c5b6955db256fc53e8fc0d16d1e
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import { isDateValid, isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid, logger } from '../../../helpers'
4 import { areValidationErrors } from '../utils'
5
6 const signatureValidator = [
7 body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
8 body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
9 body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
10 body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
11
12 (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
14
15 if (areValidationErrors(req, res)) return
16
17 return next()
18 }
19 ]
20
21 // ---------------------------------------------------------------------------
22
23 export {
24 signatureValidator
25 }