Add changes to actually make it work

This commit is contained in:
Bofh 2021-12-13 23:31:40 +01:00
parent 2d92a74a59
commit 5a4684b01b
2 changed files with 10 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import asyncio
import time
import threading
import logging
import urllib.parse
import simplejson as json
@ -33,11 +34,13 @@ DATABASE['relay-list'] = following
if 'actors' in DATABASE:
DATABASE.pop('actors')
async def database_save():
def database_save():
global DATABASE
time.sleep(60)
while True:
logging.info('written database file {}'.format(CONFIG['db']))
with open(CONFIG['db'], 'w') as f:
json.dump(DATABASE, f)
await asyncio.sleep(30)
time.sleep(1800)
asyncio.ensure_future(database_save())
threading.Thread(target=database_save).start()

View File

@ -96,6 +96,7 @@ async def fetch_actor_key(actor):
async def validate(actor, request):
print(actor)
pubkey = await fetch_actor_key(actor)
if not pubkey:
return False
@ -137,6 +138,7 @@ async def http_signatures_middleware(app, handler):
raise aiohttp.web.HTTPUnauthorized(body='signature check failed, no actor in message')
actor = data["actor"]
print(data)
if not (await validate(actor, request)):
logging.info('Signature validation failed for: %r', actor)
raise aiohttp.web.HTTPUnauthorized(body='signature check failed, signature did not match key')