Merge pull request #13 from protheory8/fix-issue-12

Add Digest header
This commit is contained in:
Darius Kazemi 2021-08-23 11:21:27 -07:00 committed by GitHub
commit 879ca300ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -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',

View file

@ -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',