From a473e9c55c79a3713f324fd9d3f88caf765a0107 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:37:47 +1200 Subject: [PATCH] experimenting with LD Signatures --- app/activitypub/signature.py | 4 ++-- app/main/routes.py | 23 +++++++++++++++++++++-- requirements.txt | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/activitypub/signature.py b/app/activitypub/signature.py index 12683859..9fefb305 100644 --- a/app/activitypub/signature.py +++ b/app/activitypub/signature.py @@ -438,7 +438,7 @@ class LDSignature: signature = document.pop("signature") # Create the options document options = { - "@context": "https://w3id.org/identity/v1", + "@context": "https://w3id.org/security/v1", "creator": signature["creator"], "created": signature["created"], } @@ -472,7 +472,7 @@ class LDSignature: """ # Create the options document options: dict[str, str] = { - "@context": "https://w3id.org/identity/v1", + "@context": "https://w3id.org/security/v1", "creator": key_id, "created": format_ld_date(utcnow()), } diff --git a/app/main/routes.py b/app/main/routes.py index ba1e539e..299b0c49 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -3,11 +3,12 @@ from datetime import timedelta from random import randint import flask +from pyld import jsonld from sqlalchemy.sql.operators import or_, and_ from app import db, cache from app.activitypub.util import users_total, active_month, local_posts, local_communities -from app.activitypub.signature import default_context +from app.activitypub.signature import default_context, LDSignature from app.constants import SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER, POST_TYPE_IMAGE, POST_TYPE_LINK, \ SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR, POST_TYPE_VIDEO, POST_TYPE_POLL from app.email import send_email @@ -423,7 +424,25 @@ def list_files(directory): @bp.route('/test') def test(): - x = languages_for_form() + json = { + "@context": "https://www.w3.org/ns/activitystreams", + "actor": "https://ioc.exchange/users/haiviittech", + "id": "https://ioc.exchange/users/haiviittech#delete", + "object": "https://ioc.exchange/users/haiviittech", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Delete" + } + + r = User.query.get(1) + + jsonld.set_document_loader(jsonld.requests_document_loader(timeout=5)) + + ld = LDSignature.create_signature(json, r.private_key, r.public_url() + '#main-key') + json.update(ld) + + LDSignature.verify_signature(json, r.public_key) #for community in Community.query.filter(Community.content_retention != -1): # for post in community.posts.filter(Post.posted_at < utcnow() - timedelta(days=Community.content_retention)): diff --git a/requirements.txt b/requirements.txt index 81b5faa4..3b91929e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,7 +17,7 @@ cryptography==42.0.4 pyopenssl==24.2.1 Bootstrap-Flask==2.3.0 arrow==1.2.3 -pyld==2.0.3 +pyld==2.0.4 boto3==1.28.35 markdown2==2.4.12 beautifulsoup4==4.12.2