Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
In progress on verification
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Oct 17, 2023
1 parent 187f05e commit 19bcf6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/federation_activitypub.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down Expand Up @@ -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"
}
}
Expand Down
34 changes: 29 additions & 5 deletions scitt_emulator/federation_activitypub_bovine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import asyncio
import pathlib
import tempfile
import traceback
import contextlib
import subprocess
Expand All @@ -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__)

Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 19bcf6a

Please sign in to comment.