PeerTube/server/middlewares/validators/activitypub/signature.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-11-09 10:51:58 -06:00
import * as express from 'express'
2019-07-25 09:23:44 -05:00
import { body } from 'express-validator'
2017-12-28 04:16:08 -06:00
import {
isSignatureCreatorValid,
isSignatureTypeValid,
2017-12-28 04:16:08 -06:00
isSignatureValueValid
} from '../../../helpers/custom-validators/activitypub/signature'
2017-12-12 10:53:50 -06:00
import { isDateValid } from '../../../helpers/custom-validators/misc'
2017-12-28 04:16:08 -06:00
import { logger } from '../../../helpers/logger'
import { areValidationErrors } from '../shared'
2017-11-09 10:51:58 -06:00
const signatureValidator = [
body('signature.type')
.optional()
.custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
body('signature.created')
.optional()
2021-05-31 12:47:14 -05:00
.custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'),
body('signature.creator')
.optional()
.custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
body('signature.signatureValue')
.optional()
.custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
2017-11-09 10:51:58 -06:00
(req: express.Request, res: express.Response, next: express.NextFunction) => {
2021-03-10 04:17:20 -06:00
logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } })
2017-11-09 10:51:58 -06:00
2017-11-27 10:30:46 -06:00
if (areValidationErrors(req, res)) return
return next()
2017-11-09 10:51:58 -06:00
}
]
// ---------------------------------------------------------------------------
export {
signatureValidator
}