import { ActivityPubSignature } from '../../shared'
import { logger } from '../helpers/logger'
import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
-import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers'
+import { ACCEPT_HEADERS, ACTIVITY_PUB, HTTP_SIGNATURE } from '../initializers/constants'
import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'
-import { ActorModel } from '../models/activitypub/actor'
import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
async function checkSignature (req: Request, res: Response, next: NextFunction) {
const httpSignatureChecked = await checkHttpSignature(req, res)
if (httpSignatureChecked !== true) return
- const actor: ActorModel = res.locals.signature.actor
+ const actor = res.locals.signature.actor
// Forwarded activity
const bodyActor = req.body.actor
const sig = req.headers[HTTP_SIGNATURE.HEADER_NAME] as string
if (sig && sig.startsWith('Signature ') === false) req.headers[HTTP_SIGNATURE.HEADER_NAME] = 'Signature ' + sig
- const parsed = parseHTTPSignature(req)
+ const parsed = parseHTTPSignature(req, HTTP_SIGNATURE.CLOCK_SKEW_SECONDS)
const keyId = parsed.keyId
if (!keyId) {
const verified = isHTTPSignatureVerified(parsed, actor)
if (verified !== true) {
+ logger.warn('Signature from %s is invalid', actorUrl, { parsed })
+
res.sendStatus(403)
return false
}
const verified = await isJsonLDSignatureVerified(actor, req.body)
if (verified !== true) {
+ logger.warn('Signature not verified.', req.body)
+
res.sendStatus(403)
return false
}