|
|
@ -19,7 +19,7 @@ import flask, os |
|
|
|
from flask import request |
|
|
|
from flask import Response |
|
|
|
from time import strftime, gmtime |
|
|
|
import httpsig |
|
|
|
import httpsig, requests |
|
|
|
|
|
|
|
#Config |
|
|
|
DOMAIN = 'https://my-example.com' |
|
|
@ -42,16 +42,18 @@ public_key() #generate public_key on first launch |
|
|
|
def sign_header(private_key, key_id, host): |
|
|
|
date= strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime()) |
|
|
|
|
|
|
|
keypair= open(private_key,'rb').read() |
|
|
|
hs = httpsig.HeaderSigner(key_id, secret, algorithm="rsa-sha256", headers=['(request-target): post /inbox', 'host', 'date']) |
|
|
|
auth = hs.sign({"Date": date, "Host": host}) |
|
|
|
secret= open(private_key,'rb').read() |
|
|
|
hs = httpsig.HeaderSigner(key_id, secret, algorithm="rsa-sha256", headers=['(request-target)', 'host', 'date']) |
|
|
|
auth = hs.sign({"Date": date, "Host": host}, method='POST',path='/inbox') |
|
|
|
|
|
|
|
# thanks to https://github.com/snarfed for the authorization -> signature headers hack |
|
|
|
# thanks to https://github.com/rowanlupton/pylodon/blob/master/pylodon/utilities.py for the inspiration |
|
|
|
# this is necessary because httpsig.HeaderSigner returns an Authorization header instead of Signature |
|
|
|
auth['Signature'] = auth.pop('authorization') |
|
|
|
assert auth['Signature'].startswith('Signature ') |
|
|
|
auth['Signature'] = auth['Signature'][len('Signature '):] |
|
|
|
|
|
|
|
return auth |
|
|
|
|
|
|
|
|
|
|
|
#Flask |
|
|
|
app = flask.Flask(__name__) |
|
|
@ -86,6 +88,14 @@ def profile(actor): |
|
|
|
return Response(response=json, status=200, mimetype="application/json") # return that answer as a json object |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/post/', methods=['POST','GET']) |
|
|
|
def post(): |
|
|
|
json=flask.render_template('create.json', |
|
|
|
domain=DOMAIN,public_key=public_key(),actor='test',host='https://post.lurk.org') |
|
|
|
r = requests.post(url='http://post.lurk.org/users/rra/inbox', json=json, headers=sign_header('private.pem', 'https://t.homebrewserver.club/users/test#main-key','https://post.lurk.org')) |
|
|
|
a = (r.status_code, r.reason, r.text) |
|
|
|
return 'test' |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
app.debug =True |
|
|
|
app.run() |
|
|
|