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