aboutsummaryrefslogtreecommitdiff
path: root/client.py
diff options
context:
space:
mode:
authorAnthony Wang2023-01-18 06:23:36 +0000
committerAnthony Wang2023-01-18 06:23:36 +0000
commita2e773ebd1a64ac67479ceb05ee3836957ac0e7b (patch)
treed332f5a166ec4064b6245914bc1a9cdd83d2a41f /client.py
parentf4631349520ae823843ae5f5f3adda42ad047fae (diff)
Add latest working code
Diffstat (limited to 'client.py')
-rw-r--r--client.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/client.py b/client.py
index 8cf4281..0a3305d 100644
--- a/client.py
+++ b/client.py
@@ -3,16 +3,17 @@ from cryptography.hazmat.primitives.asymmetric import padding
from base64 import b64encode
from email.utils import formatdate
from requests import post
+from sys import argv
date = formatdate(usegmt=True)
-with open('activity.jsonld', 'rb') as f:
+with open(argv[1], 'rb') as f:
activity = f.read()
digester = hashes.Hash(hashes.SHA256())
digester.update(activity)
digest = b64encode(digester.finalize()).decode()
-message = f'(request-target): post /users/a/inbox\nhost: social.exozy.me\ndate: {date}\ndigest: SHA-256={digest}'
+message = f'date: {date}\ndigest: SHA-256={digest}'
with open('private.pem', 'rb') as f:
privkey = serialization.load_pem_private_key(f.read(), None)
@@ -22,11 +23,9 @@ signature = b64encode(privkey.sign(
padding.PKCS1v15(),
hashes.SHA256()
)).decode()
-header = f'keyId="https://0.exozy.me/users/test.jsonld#main-key",headers="(request-target) host date digest",signature="{signature}"'
+header = f'keyId="https://0.exozy.me/users/test.jsonld#main-key",headers="date digest",signature="{signature}"'
-resp = post('http://localhost:4200/users/test.outbox', headers={
- '(request-target)': 'post /users/a/inbox',
- 'Host': 'social.exozy.me',
+resp = post('https://0.exozy.me/users/test.outbox', headers={
'Date': date,
'Digest': f'SHA-256={digest}',
'Signature': header,