Skip to content

Commit

Permalink
Merge pull request #59 from umonaca/bugfix-digest
Browse files Browse the repository at this point in the history
Fix compatibility with Mastodon 3.2.1, Pleroma and Misskey
  • Loading branch information
dariusk authored Oct 26, 2020
2 parents c3983fe + 2ce39c7 commit f7a85d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 12 additions & 4 deletions routes/inbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@ function signAndSend(message, name, domain, req, res, targetDomain) {
return res.status(404).send(`No record found for ${name}.`);
}
else {
// digest
const digest = crypto.createHash('sha256').update(JSON.stringify(message)).digest('base64');

let privkey = result.privkey;
const signer = crypto.createSign('sha256');
let d = new Date();
let stringToSign = `(request-target): post ${inboxFragment}\nhost: ${targetDomain}\ndate: ${d.toUTCString()}`;
let stringToSign = `(request-target): post ${inboxFragment}\nhost: ${targetDomain}\ndate: ${d.toUTCString()}\ndigest: SHA-256=${digest}`;
signer.update(stringToSign);
signer.end();
const signature = signer.sign(privkey);
const signature_b64 = signature.toString('base64');
let header = `keyId="https://${domain}/u/${name}",headers="(request-target) host date",signature="${signature_b64}"`;
const algorithm = 'rsa-sha256';
let header = `keyId="https://${domain}/u/${name}",algorithm="${algorithm}",headers="(request-target) host date digest",signature="${signature_b64}"`;
console.log('signature:',header);
console.log('message:',message);

request({
url: inbox,
headers: {
'Host': targetDomain,
'Date': d.toUTCString(),
'Signature': header
'Signature': header,
'Digest': `SHA-256=${digest}`,
'Content-Type': 'application/activity+json',
'Accept': 'application/activity+json'
},
method: 'POST',
json: true,
Expand All @@ -47,7 +55,7 @@ function sendAcceptMessage(thebody, name, domain, req, res, targetDomain) {
const guid = crypto.randomBytes(16).toString('hex');
console.log(thebody);
let message = {
'@context': 'https://www.w3.org/ns/activitystreams',
'@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'],
'id': `https://${domain}/${guid}`,
'type': 'Accept',
'actor': `https://${domain}/u/${name}`,
Expand Down
16 changes: 11 additions & 5 deletions updateFeeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,29 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) {
console.log(`No record found for ${name}.`);
}
else {
// digest
const digest = crypto.createHash('sha256').update(JSON.stringify(message)).digest('base64');

let privkey = result.privkey;
const signer = crypto.createSign('sha256');
let d = new Date();
let stringToSign = `(request-target): post ${inboxFragment}\nhost: ${targetDomain}\ndate: ${d.toUTCString()}`;
let stringToSign = `(request-target): post ${inboxFragment}\nhost: ${targetDomain}\ndate: ${d.toUTCString()}\ndigest: SHA-256=${digest}`;
signer.update(stringToSign);
signer.end();
const signature = signer.sign(privkey);
const signature_b64 = signature.toString('base64');
let header = `keyId="https://${domain}/u/${name}",headers="(request-target) host date",signature="${signature_b64}"`;
const algorithm = 'rsa-sha256';
let header = `keyId="https://${domain}/u/${name}",algorithm="${algorithm}",headers="(request-target) host date digest",signature="${signature_b64}"`;
//console.log('signature:',header);
request({
url: inbox,
headers: {
'Host': targetDomain,
'Date': d.toUTCString(),
'Signature': header
'Signature': header,
'Digest': `SHA-256=${digest}`,
'Content-Type': 'application/activity+json',
'Accept': 'application/activity+json'
},
method: 'POST',
json: true,
Expand All @@ -201,8 +208,7 @@ function createMessage(text, name, domain, item, follower, guidNote) {
let d = new Date();

let out = {
'@context': 'https://www.w3.org/ns/activitystreams',

'@context': ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1'],
'id': `https://${domain}/m/${guidCreate}`,
'type': 'Create',
'actor': `https://${domain}/u/${name}`,
Expand Down

0 comments on commit f7a85d0

Please sign in to comment.