Skip to content

Commit 6bbd69c

Browse files
committed
Add digest header
1 parent 1d4ab83 commit 6bbd69c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@ follow_request_message = {
247247
r = requests.post(recipient_inbox, headers=headers, json=follow_request_message)
248248
```
249249

250+
### 7. Mastodon now requires the Digest header
251+
Thanks @Yoxem for the info.
252+
253+
```python
254+
import json
255+
import hashlib
256+
257+
follow_request_message = { ... } # as above
258+
follow_request_json = json.dumps(follow_request_message)
259+
digest = base64.b64encode(hashlib.sha256(follow_request_json.encode('utf-8')).digest())
260+
261+
# signature information is now
262+
signature_text = b'(request-target): post %s\ndigest: SHA-256=%s\nhost: %s\ndate: %s' % (recipient_path.encode('utf-8'), digest, recipient_host.encode('utf-8'), current_date.encode('utf-8'))
263+
264+
raw_signature = private_key.sign(
265+
signature_text,
266+
padding.PKCS1v15(),
267+
hashes.SHA256()
268+
)
269+
270+
signature_header = 'keyId="%s",algorithm="rsa-sha256",headers="(request-target) digest host date",signature="%s"' % sender_key, base64.b64encode(raw_signature).decode('utf-8')
271+
272+
headers = {
273+
'Date': current_date,
274+
'Content-Type': 'application/activity+json',
275+
'Host': recipient_host,
276+
'Digest': "SHA-256="+digest.decode('utf-8'),
277+
'Signature': signature_header
278+
}
279+
```
250280

251281
## Standards
252282
* [ActivityPub](https://www.w3.org/TR/activitypub/)

0 commit comments

Comments
 (0)