2017-11-09 10:51:58 -06:00
|
|
|
import * as express from 'express'
|
2017-11-27 10:30:46 -06:00
|
|
|
import { body } from 'express-validator/check'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { logger } from '../../../helpers'
|
|
|
|
import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub'
|
|
|
|
import { isDateValid } from '../../../helpers/custom-validators/misc'
|
2017-11-27 10:30:46 -06:00
|
|
|
import { areValidationErrors } from '../utils'
|
2017-11-09 10:51:58 -06:00
|
|
|
|
|
|
|
const signatureValidator = [
|
|
|
|
body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'),
|
|
|
|
body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'),
|
|
|
|
body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'),
|
|
|
|
body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'),
|
|
|
|
|
|
|
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
|
|
|
logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } })
|
|
|
|
|
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
|
|
|
|
}
|