]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/activitypub/signature.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / signature.ts
1 import * as express from 'express'
2 import { body } from 'express-validator'
3 import {
4 isSignatureCreatorValid,
5 isSignatureTypeValid,
6 isSignatureValueValid
7 } from '../../../helpers/custom-validators/activitypub/signature'
8 import { isDateValid } from '../../../helpers/custom-validators/misc'
9 import { logger } from '../../../helpers/logger'
10 import { areValidationErrors } from '../shared'
11
12 const signatureValidator = [
13 body('signature.type')
14 .optional()
15 .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
16 body('signature.created')
17 .optional()
18 .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'),
19 body('signature.creator')
20 .optional()
21 .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
22 body('signature.signatureValue')
23 .optional()
24 .custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
25
26 (req: express.Request, res: express.Response, next: express.NextFunction) => {
27 logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } })
28
29 if (areValidationErrors(req, res)) return
30
31 return next()
32 }
33 ]
34
35 // ---------------------------------------------------------------------------
36
37 export {
38 signatureValidator
39 }