diff --git a/relay/database.py b/relay/database.py index 11a1139..bbb8743 100644 --- a/relay/database.py +++ b/relay/database.py @@ -38,9 +38,9 @@ def database_save(): global DATABASE time.sleep(60) while True: - logging.info('written database file {}'.format(CONFIG['db'])) + logging.debug('written database file {}'.format(CONFIG['db'])) with open(CONFIG['db'], 'w') as f: json.dump(DATABASE, f) - time.sleep(1800) + time.sleep(60) threading.Thread(target=database_save).start() diff --git a/relay/http_signatures.py b/relay/http_signatures.py index 075247c..b0c6dad 100644 --- a/relay/http_signatures.py +++ b/relay/http_signatures.py @@ -84,10 +84,11 @@ def sign_headers(headers, key, key_id): @alru_cache(maxsize=16384) async def fetch_actor_key(actor): actor_data = await fetch_actor(actor) - if not actor_data: return None + logging.debug('actor key #1: %r', actor_data['publicKey']['publicKeyPem']) + try: return RSA.importKey(actor_data['publicKey']['publicKeyPem']) @@ -96,13 +97,16 @@ async def fetch_actor_key(actor): async def validate(actor, request): - print(actor) - pubkey = await fetch_actor_key(actor) + pubkey = None + try: + pubkey = await fetch_actor_key(actor) + except Exception as e: + logging.error(str(e)) + + logging.debug('actor key #2: %r', pubkey) if not pubkey: return False - logging.debug('actor key: %r', pubkey) - headers = request.headers.copy() headers['(request-target)'] = ' '.join([request.method.lower(), request.path]) @@ -138,11 +142,12 @@ 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') + logging.debug('VALIDATED. handler: %r', handler) + return (await handler(request)) return (await handler(request))