|
@ -50,20 +50,7 @@ requests_log.propagate = True |
|
|
DOMAIN = 'https://my-example.com' |
|
|
DOMAIN = 'https://my-example.com' |
|
|
USERNAME = 'alice' |
|
|
USERNAME = 'alice' |
|
|
|
|
|
|
|
|
def public_key(): |
|
|
key = get_key(f'{DOMAIN}/users/{USERNAME}') #generate keypair on first launch |
|
|
""" |
|
|
|
|
|
Use commandline openssl to generate a public and private key |
|
|
|
|
|
""" |
|
|
|
|
|
if not os.path.exists('public.pem'): |
|
|
|
|
|
os.system('openssl genrsa -out private.pem 2048') |
|
|
|
|
|
os.system('openssl rsa -in private.pem -outform PEM -pubout -out public.pem') |
|
|
|
|
|
else: |
|
|
|
|
|
public_key = open('public.pem').read() |
|
|
|
|
|
public_key = public_key.replace('\n','\\n') #public key shouldn't contain verbatim linebreaks in json |
|
|
|
|
|
return public_key |
|
|
|
|
|
|
|
|
|
|
|
key = get_key(f'{DOMAIN}/users/{USERNAME}') #generate public_key on first launch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Flask |
|
|
#Flask |
|
|
app = flask.Flask(__name__) |
|
|
app = flask.Flask(__name__) |
|
@ -114,7 +101,6 @@ def post(): |
|
|
activity=json.loads(flask.render_template('create.json', |
|
|
activity=json.loads(flask.render_template('create.json', |
|
|
domain=DOMAIN, actor=USERNAME)) |
|
|
domain=DOMAIN, actor=USERNAME)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http_sig = HTTPSigAuth(key, headers) |
|
|
http_sig = HTTPSigAuth(key, headers) |
|
|
|
|
|
|
|
|
url = 'https://post.lurk.org/inbox' |
|
|
url = 'https://post.lurk.org/inbox' |
|
@ -122,9 +108,7 @@ def post(): |
|
|
body = json.dumps(activity) |
|
|
body = json.dumps(activity) |
|
|
|
|
|
|
|
|
headers = http_sig.sign(url,body) |
|
|
headers = http_sig.sign(url,body) |
|
|
|
|
|
|
|
|
#signed_headers = sign_header('private.pem', DOMAIN+'/users/'+USERNAME+'#main-key','https://post.lurk.org', json.dumps(json_message)) |
|
|
|
|
|
|
|
|
|
|
|
r = requests.post(url, json=body, headers=headers) |
|
|
r = requests.post(url, json=body, headers=headers) |
|
|
|
|
|
|
|
|
html = f'Status code <pre>{r.status_code}</pre></br>Response Headers: <pre>{r.headers}</pre></br></br> json message: <pre>{r.request.body}</pre></br></br> Request headers: <pre>{r.request.headers}</pre>' |
|
|
html = f'Status code <pre>{r.status_code}</pre></br>Response Headers: <pre>{r.headers}</pre></br></br> json message: <pre>{r.request.body}</pre></br></br> Request headers: <pre>{r.request.headers}</pre>' |
|
|