[fedi] minor

This commit is contained in:
les
2019-09-26 15:22:02 +02:00
parent 7c31d6c969
commit c81114b25c
2 changed files with 7 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ module.exports = {
'actor': `${config.baseurl}/federation/u/${user.username}`, 'actor': `${config.baseurl}/federation/u/${user.username}`,
'object': body 'object': body
} }
Helpers.signAndSend(message, user, body.actor) Helpers.signAndSend(message, user, req.fedi_user.inbox)
res.sendStatus(200) res.sendStatus(200)
}, },

View File

@@ -24,24 +24,24 @@ const Helpers = {
next() next()
}, },
async signAndSend (message, user, to) { async signAndSend (message, user, inbox) {
// get the URI of the actor object and append 'inbox' to it // get the URI of the actor object and append 'inbox' to it
const toUrl = url.parse(to) const inboxUrl = url.parse(inbox)
// const toPath = toOrigin.path + '/inbox' // const toPath = toOrigin.path + '/inbox'
// get the private key // get the private key
const privkey = user.rsa.privateKey const privkey = user.rsa.privateKey
const signer = crypto.createSign('sha256') const signer = crypto.createSign('sha256')
const d = new Date() const d = new Date()
const stringToSign = `(request-target): post ${toUrl.path}\nhost: ${toUrl.hostname}\ndate: ${d.toUTCString()}` const stringToSign = `(request-target): post ${inboxUrl.path}\nhost: ${inboxUrl.hostname}\ndate: ${d.toUTCString()}`
debug('Sign and send', user.username, to) debug('Sign and send', user.username, inbox)
signer.update(stringToSign) signer.update(stringToSign)
signer.end() signer.end()
const signature = signer.sign(privkey) const signature = signer.sign(privkey)
const signature_b64 = signature.toString('base64') const signature_b64 = signature.toString('base64')
const header = `keyId="${config.baseurl}/federation/u/${user.username}",headers="(request-target) host date",signature="${signature_b64}"` const header = `keyId="${config.baseurl}/federation/u/${user.username}",headers="(request-target) host date",signature="${signature_b64}"`
const ret = await fetch(to, { const ret = await fetch(inbox, {
headers: { headers: {
'Host': toUrl.hostname, 'Host': inboxUrl.hostname,
'Date': d.toUTCString(), 'Date': d.toUTCString(),
'Signature': header, 'Signature': header,
'Content-Type': 'application/activity+json; charset=utf-8', 'Content-Type': 'application/activity+json; charset=utf-8',