blob: 0a3305db75015d980478253fa03585d07e3d209f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from cryptography.hazmat.primitives import hashes, serialization
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(argv[1], 'rb') as f:
activity = f.read()
digester = hashes.Hash(hashes.SHA256())
digester.update(activity)
digest = b64encode(digester.finalize()).decode()
message = f'date: {date}\ndigest: SHA-256={digest}'
with open('private.pem', 'rb') as f:
privkey = serialization.load_pem_private_key(f.read(), None)
signature = b64encode(privkey.sign(
message.encode('utf8'),
padding.PKCS1v15(),
hashes.SHA256()
)).decode()
header = f'keyId="https://0.exozy.me/users/test.jsonld#main-key",headers="date digest",signature="{signature}"'
resp = post('https://0.exozy.me/users/test.outbox', headers={
'Date': date,
'Digest': f'SHA-256={digest}',
'Signature': header,
}, data=activity)
print(resp)
print(resp.text)
|