mirror of
https://github.com/dariusk/express-activitypub.git
synced 2024-11-24 08:10:59 +00:00
Add Digest header
This commit is contained in:
parent
b6ad884424
commit
06a9a48489
2 changed files with 8 additions and 4 deletions
|
@ -30,19 +30,21 @@ function signAndSend(message, name, domain, req, res, targetDomain, inbox) {
|
|||
}
|
||||
else {
|
||||
let privkey = result.privkey;
|
||||
const digestHash = crypto.createHash('sha256').update(JSON.stringify(message)).digest('base64');
|
||||
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=${digestHash}`;
|
||||
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}"`;
|
||||
let header = `keyId="https://${domain}/u/${name}",headers="(request-target) host date digest",signature="${signature_b64}"`;
|
||||
request({
|
||||
url: inbox,
|
||||
headers: {
|
||||
'Host': targetDomain,
|
||||
'Date': d.toUTCString(),
|
||||
'Digest': `SHA-256=${digestHash}`,
|
||||
'Signature': header
|
||||
},
|
||||
method: 'POST',
|
||||
|
|
|
@ -16,19 +16,21 @@ function signAndSend(message, name, domain, req, res, targetDomain) {
|
|||
}
|
||||
else {
|
||||
let privkey = result.privkey;
|
||||
const digestHash = crypto.createHash('sha256').update(JSON.stringify(message)).digest('base64');
|
||||
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=${digestHash}`;
|
||||
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}"`;
|
||||
let header = `keyId="https://${domain}/u/${name}",headers="(request-target) host date digest",signature="${signature_b64}"`;
|
||||
request({
|
||||
url: inbox,
|
||||
headers: {
|
||||
'Host': targetDomain,
|
||||
'Date': d.toUTCString(),
|
||||
'Digest': `SHA-256=${digestHash}`,
|
||||
'Signature': header
|
||||
},
|
||||
method: 'POST',
|
||||
|
|
Loading…
Reference in a new issue