mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Extract HTTP Signature verify middleware
This commit is contained in:
parent
bb04ef0664
commit
ea2f6b7811
@ -1,8 +1,8 @@
|
|||||||
import { sendCollection } from '../utils/collection'
|
import { sendCollection } from '../utils/collection'
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { serveUser } from './serveUser'
|
import { serveUser } from './serveUser'
|
||||||
import { verifySignature } from '../security'
|
|
||||||
import { activityPub } from '../ActivityPub'
|
import { activityPub } from '../ActivityPub'
|
||||||
|
import verify from './verify'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const debug = require('debug')('ea:user')
|
const debug = require('debug')('ea:user')
|
||||||
@ -45,11 +45,9 @@ router.get('/:name/outbox', (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/:name/inbox', async function (req, res, next) {
|
router.post('/:name/inbox', verify, async function (req, res, next) {
|
||||||
debug(`body = ${JSON.stringify(req.body, null, 2)}`)
|
debug(`body = ${JSON.stringify(req.body, null, 2)}`)
|
||||||
debug(`actorId = ${req.body.actor}`)
|
debug(`actorId = ${req.body.actor}`)
|
||||||
// TODO stop if signature validation fails
|
|
||||||
debug(`verify = ${await verifySignature(`${req.protocol}://${req.hostname}:${req.port}${req.originalUrl}`, req.headers)}`)
|
|
||||||
// const result = await saveActorId(req.body.actor)
|
// const result = await saveActorId(req.body.actor)
|
||||||
switch (req.body.type) {
|
switch (req.body.type) {
|
||||||
case 'Create':
|
case 'Create':
|
||||||
|
|||||||
15
src/activitypub/routes/verify.js
Normal file
15
src/activitypub/routes/verify.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { verifySignature } from '../security'
|
||||||
|
const debug = require('debug')('ea:verify')
|
||||||
|
|
||||||
|
export default async (req, res, next) => {
|
||||||
|
debug(`actorId = ${req.body.actor}`)
|
||||||
|
// TODO stop if signature validation fails
|
||||||
|
if (await verifySignature(`${req.protocol}://${req.hostname}:${req.port}${req.originalUrl}`, req.headers)) {
|
||||||
|
debug('verify = true')
|
||||||
|
next()
|
||||||
|
} else {
|
||||||
|
// throw Error('Signature validation failed!')
|
||||||
|
debug('verify = false')
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user