add digest to http signature for Mastodon 3.2.1 compliance

This commit is contained in:
Will Murphy 2020-10-24 13:14:33 -05:00
parent 6db9dcaf41
commit 5208b67df5

View file

@ -1,4 +1,5 @@
'use strict' 'use strict'
const crypto = require('crypto')
const request = require('request-promise-native') const request = require('request-promise-native')
const pubUtils = require('./utils') const pubUtils = require('./utils')
@ -24,22 +25,27 @@ function deliver (actor, activity, addresses) {
delete activity.bcc delete activity.bcc
} }
const requests = addresses.map(addr => { const requests = addresses.map(addr => {
const body = pubUtils.toJSONLD(activity)
const digest = crypto.createHash('sha256')
.update(JSON.stringify(body))
.digest('base64')
return request({ return request({
method: 'POST', method: 'POST',
url: addr, url: addr,
headers: { headers: {
'Content-Type': 'application/activity+json' 'Content-Type': 'application/activity+json',
Digest: `SHA-256=${digest}`
}, },
httpSignature: { httpSignature: {
key: actor._meta.privateKey, key: actor._meta.privateKey,
keyId: actor.id, keyId: actor.id,
headers: ['(request-target)', 'host', 'date'], headers: ['(request-target)', 'host', 'date', 'digest'],
authorizationHeaderName: 'Signature' authorizationHeaderName: 'Signature'
}, },
json: true, json: true,
resolveWithFullResponse: true, resolveWithFullResponse: true,
simple: false, simple: false,
body: pubUtils.toJSONLD(activity) body
}) })
.then(result => console.log('delivery:', addr, result.statusCode)) .then(result => console.log('delivery:', addr, result.statusCode))
.catch(err => console.log(err.message)) .catch(err => console.log(err.message))