From 19bcf6a942eed2352c36ed6bba166203a3b37c7a Mon Sep 17 00:00:00 2001 From: John Andersen Date: Mon, 16 Oct 2023 19:28:16 -0700 Subject: [PATCH] In progress on verification Signed-off-by: John Andersen --- docs/federation_activitypub.md | 4 +-- .../federation_activitypub_bovine.py | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/docs/federation_activitypub.md b/docs/federation_activitypub.md index dca859aa..3705a6ab 100644 --- a/docs/federation_activitypub.md +++ b/docs/federation_activitypub.md @@ -151,7 +151,7 @@ Populate Bob's federation config "workspace": "~/Documents/fediverse/scitt_federation_bob", "following": { "alice": { - "actor_id": "acct:alice@localhost:5000", + "actor_id": "alice@localhost:5000", "domain": "http://localhost:5000" } } @@ -204,7 +204,7 @@ Populate Alice's federation config "workspace": "~/Documents/fediverse/scitt_federation_alice", "following": { "bob": { - "actor_id": "acct:bob@localhost:5000", + "actor_id": "bob@localhost:5000", "domain": "http://localhost:5000" } } diff --git a/scitt_emulator/federation_activitypub_bovine.py b/scitt_emulator/federation_activitypub_bovine.py index 3cebd84b..7f514e68 100644 --- a/scitt_emulator/federation_activitypub_bovine.py +++ b/scitt_emulator/federation_activitypub_bovine.py @@ -7,6 +7,7 @@ import logging import asyncio import pathlib +import tempfile import traceback import contextlib import subprocess @@ -24,6 +25,7 @@ from mechanical_bull.handlers import HandlerEvent, HandlerAPIVersion from scitt_emulator.federation import SCITTFederation +from scitt_emulator.tree_algs import TREE_ALGS logger = logging.getLogger(__name__) @@ -185,7 +187,15 @@ def initialize_service(self): def created_entry(self, entry_id: str, receipt: bytes): with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client: client.connect(str(self.federate_created_entries_socket_path.resolve())) - client.send(receipt) + client.send( + json.dumps( + { + "receipt": base64.b64encode(receipt).decode(), + "claim" base64.b64decode(claim).decode(), + "treeAlgorithm": self.seri + } + ) + ) client.close() @@ -237,10 +247,23 @@ async def handle( # Send federated claim / receipt to SCITT content = obj.get("content") + if not isinstance(content, dict): + return + logger.info("Federation received new receipt: %r", content) # TODO Entry ID? - receipt = base64.b64decode(content.encode()) - logger.info("Federation received new receipt: %r", receipt) + claim = base64.b64decode(content["claim"].encode()) + receipt = base64.b64decode(content["receipt"].encode()) + with tempfile.TemporaryDirectory() as tempdir: + receipt_path = Path(tempdir, "receipt") + cose_path = Path(tempdir, "claim") + + clazz = TREE_ALGS[content["treeAlgorithm"]] + # TODO + service = clazz(service_parameters_path=service_parameters_path) + service.verify_receipt(cose_path, receipt_path) + + logger.info("Receipt verified") except Exception as ex: logger.error(ex) logger.exception(ex) @@ -282,11 +305,12 @@ async def federate_created_entries( async def federate_created_entry(reader, writer): try: logger.info("federate_created_entry() Reading... %r", reader) - receipt = await reader.read() + content_bytes = await reader.read() + content = json.loads(content_bytes.decode()) logger.info("federate_created_entry() Read: %r", receipt) note = ( client.object_factory.note( - content=base64.b64encode(receipt).decode(), + content=content, ) .as_public() .build()