From e92269053e3fd0e9b9c155ded86a1668444f3d70 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Jan 2020 15:24:27 +0100 Subject: Update http signature --- server/helpers/custom-jsonld-signature.ts | 14 +++++++++++--- server/helpers/peertube-crypto.ts | 2 +- server/lib/job-queue/handlers/activitypub-http-unicast.ts | 2 ++ server/middlewares/activitypub.ts | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) (limited to 'server') diff --git a/server/helpers/custom-jsonld-signature.ts b/server/helpers/custom-jsonld-signature.ts index cb07fa3b2..a407a9fec 100644 --- a/server/helpers/custom-jsonld-signature.ts +++ b/server/helpers/custom-jsonld-signature.ts @@ -70,12 +70,20 @@ const lru = new AsyncLRU({ }) } - nodeDocumentLoader(url, cb) + nodeDocumentLoader(url) + .then(value => cb(null, value)) + .catch(err => cb(err)) } }) -jsonld.documentLoader = (url, cb) => { - lru.get(url, cb) +jsonld.documentLoader = (url) => { + return new Promise((res, rej) => { + lru.get(url, (err, value) => { + if (err) return rej(err) + + return res(value) + }) + }) } export { jsonld } diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 9eb782302..89c0ab151 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -51,7 +51,7 @@ function isHTTPSignatureVerified (httpSignatureParsed: any, actor: MActor): bool } function parseHTTPSignature (req: Request, clockSkew?: number) { - return httpSignature.parse(req, { authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, clockSkew }) + return httpSignature.parse(req, { clockSkew }) } // JSONLD diff --git a/server/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/lib/job-queue/handlers/activitypub-http-unicast.ts index c70ce3be9..6fbd4a716 100644 --- a/server/lib/job-queue/handlers/activitypub-http-unicast.ts +++ b/server/lib/job-queue/handlers/activitypub-http-unicast.ts @@ -20,6 +20,8 @@ async function processActivityPubHttpUnicast (job: Bull.Job) { const body = await computeBody(payload) const httpSignatureOptions = await buildSignedRequestOptions(payload) + logger.info('hello', { httpSignatureOptions }) + const options = { method: 'POST', uri, diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index fedac0e05..bd3bdb076 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -51,10 +51,11 @@ export { // --------------------------------------------------------------------------- async function checkHttpSignature (req: Request, res: Response) { - // FIXME: mastodon does not include the Signature scheme + // FIXME: compatibility with http-signature < v1.3 const sig = req.headers[HTTP_SIGNATURE.HEADER_NAME] as string - if (sig && sig.startsWith('Signature ') === false) req.headers[HTTP_SIGNATURE.HEADER_NAME] = 'Signature ' + sig + if (sig && sig.startsWith('Signature ') === true) req.headers[HTTP_SIGNATURE.HEADER_NAME] = sig.replace(/^Signature /, '') + logger.info('coucou', { signature: req.headers[HTTP_SIGNATURE.HEADER_NAME] }) const parsed = parseHTTPSignature(req, HTTP_SIGNATURE.CLOCK_SKEW_SECONDS) const keyId = parsed.keyId -- cgit v1.2.3