From 03c90aedf38629fdd3daee0036a693c8359bbb9b Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 11 Dec 2022 16:27:51 +0000 Subject: [PATCH] sign all --- v6d0auth/app.py | 10 ++++++++-- v6d0auth/sign-request.py | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/v6d0auth/app.py b/v6d0auth/app.py index 7c3dba5..4b91bf7 100644 --- a/v6d0auth/app.py +++ b/v6d0auth/app.py @@ -30,8 +30,14 @@ class V6D0AuthAppFactory(AppFactory): await ws.send_bytes(nonce) hhandle, hnonce = json.loads(certs.verify(await ws.receive_bytes())) assert hnonce == nonce.hex() - approved = self.cdb.approve(bytes.fromhex(hhandle)) - await ws.send_bytes(approved) + if hhandle == 'all': + print('approving all') + for request in self.cdb.handle_mapping.values(): + request.approve() + print('approved all') + else: + approved = self.cdb.approve(bytes.fromhex(hhandle)) + await ws.send_bytes(approved) await ws.close() @routes.get('/approve') diff --git a/v6d0auth/sign-request.py b/v6d0auth/sign-request.py index c6a7709..614fe56 100644 --- a/v6d0auth/sign-request.py +++ b/v6d0auth/sign-request.py @@ -1,6 +1,7 @@ import argparse import asyncio import json +from typing import Literal import aiohttp @@ -12,13 +13,14 @@ parser.add_argument('handle', type=str) async def main(): - handle = bytes.fromhex(args.handle) + handle: bytes | Literal['all'] = 'all' if args.handle == 'all' else bytes.fromhex(args.handle) async with aiohttp.ClientSession() as session: # noinspection HttpUrlsUsage async with session.ws_connect(f'http://{host}:{port}/approve') as ws: nonce = await ws.receive_bytes() - await ws.send_bytes(certs.sign(json.dumps([handle.hex(), nonce.hex()]).encode())) - print((await ws.receive_bytes()).hex()) + await ws.send_bytes(certs.sign(json.dumps(['all' if handle == 'all' else handle.hex(), nonce.hex()]).encode())) + if handle != 'all': + print((await ws.receive_bytes()).hex()) if __name__ == '__main__':