From 58593d7da6a893e681b7c64fdf21a02c93dfa0d0 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 10 Jan 2024 13:33:57 +0000 Subject: prepare outbound fep-8b32 (object integrity) but do not enable yet since the additional context seems to break ldsig for some reason, introduce Activity::build_packet() and Activity::ap_context() to reduce code duplication, implement fep-2c59 (webfinger) and some cleanup --- Zotlabs/Lib/ActivityStreams.php | 1 + 1 file changed, 1 insertion(+) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 4c3e3d8f8..c32f82e33 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -28,6 +28,7 @@ class ActivityStreams { public $sigok = false; public $recips = null; public $raw_recips = null; + public $saved_recips = null; /** * @brief Constructor for ActivityStreams. -- cgit v1.2.3 From fa7aa6cedb83279252d1e26bb58227a6f99df9ed Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 13 Jan 2024 20:38:34 +0000 Subject: start checking integrity proofs, remove signature prior to verify, iterate trough the array to find the desired ekey in actor_store() --- Zotlabs/Lib/ActivityStreams.php | 56 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index c32f82e33..98fc73462 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -24,7 +24,7 @@ class ActivityStreams { public $origin = null; public $owner = null; public $signer = null; - public $ldsig = null; + public $sig = null; public $sigok = false; public $recips = null; public $raw_recips = null; @@ -97,11 +97,19 @@ class ActivityStreams { $this->origin = $this->get_compound_property('origin'); $this->recips = $this->collect_recips(); - $this->ldsig = $this->get_compound_property('signature'); - if ($this->ldsig) { - $this->signer = $this->get_actor('creator', $this->ldsig); - if ($this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer) && is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']) { - $this->sigok = LDSignatures::verify($this->data, $this->signer['publicKey']['publicKeyPem']); + $this->sig = $this->get_compound_property('proof'); + if ($this->sig) { + $this->checkEddsaSignature(); // will set signer and sigok if everything works out + } + + // Try LDSignatures if edsig failed + if (!$this->sigok) { + $this->sig = $this->get_compound_property('signature'); + if ($this->sig) { + $this->signer = $this->get_actor('creator', $this->sig); + if ($this->signer && is_array($this->signer) && array_key_exists('publicKey', $this->signer) && is_array($this->signer['publicKey']) && $this->signer['publicKey']['publicKeyPem']) { + $this->sigok = LDSignatures::verify($this->data, $this->signer['publicKey']['publicKeyPem']); + } } } @@ -490,4 +498,40 @@ class ActivityStreams { } + public function checkEddsaSignature() { + $signer = $this->get_property_obj('verificationMethod', $this->sig); + + $parseUrl = parse_url($signer); + if (!empty($parseUrl['fragment']) && str_starts_with($parseUrl['fragment'],'z6Mk')) { + $publicKey = $parseUrl['fragment']; + unset($parseUrl['fragment']); + unset($parseUrl['query']); + } + + $url = unparse_url($parseUrl); + //$this->signer = [ 'id' => $url ]; + + $hublocs = Activity::get_actor_hublocs($url); + $hasStoredKey = false; + if ($hublocs) { + foreach ($hublocs as $hubloc) { + if ($publicKey && $hubloc['xchan_epubkey'] === $publicKey) { + $hasStoredKey = true; + break; + } + } + } + if (!$hasStoredKey) { + $this->signer = Activity::get_actor($url); + if ($this->signer + && !empty($this->signer['assertionMethod']) + && !empty($this->signer['assertionMethod']['publicKeyMultibase'])) { + $publicKey = $this->signer['assertionMethod']['publicKeyMultibase']; + } + } + if ($publicKey) { + $this->sigok = (new JcsEddsa2022)->verify($this->data, $publicKey); + } + } + } -- cgit v1.2.3 From 2bbecfe8dd44bd51a3425ee667859946f6ac0763 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 14 Jan 2024 10:11:20 +0000 Subject: only attempt fetch if zotfinger actually returned something --- Zotlabs/Lib/ActivityStreams.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 98fc73462..f0fb7c9ae 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -327,9 +327,10 @@ class ActivityStreams { if ($x === null && strpos($url, '/channel/')) { // look for other nomadic channels which might be alive $zf = Zotfinger::exec($url, $channel); - - $url = $zf['signature']['signer']; - $x = Activity::fetch($url, $channel); + if ($zf) { + $url = $zf['signature']['signer']; + $x = Activity::fetch($url, $channel); + } } } -- cgit v1.2.3 From fa4ab45692e5deaee3a51408a43c00a834f99903 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 19 Jan 2024 20:10:50 +0000 Subject: native repeats continued --- Zotlabs/Lib/ActivityStreams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index f0fb7c9ae..0770f2040 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -345,7 +345,7 @@ class ActivityStreams { if (!$s) { return false; } - return (in_array($s, ['Like', 'Dislike', 'Flag', 'Block', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction', 'EmojiReact'])); + return (in_array($s, ['Announce', 'Like', 'Dislike', 'Flag', 'Block', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction', 'EmojiReact'])); } /** -- cgit v1.2.3 From 5e780ba089aa8493eb5bec30558345b070ef808c Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 27 Jan 2024 16:36:26 +0000 Subject: implement short time object cache to reduce network calls and some cleanup --- Zotlabs/Lib/ActivityStreams.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 0770f2040..3749126d3 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -90,6 +90,15 @@ class ActivityStreams { // Attempt to assemble an Activity from what we were given. if ($this->is_valid()) { $this->id = $this->get_property_obj('id'); + + if (!$this->id) { + logger('Data with mmissing id: ' . print_r($this->data, true)); + return; + } + + // cache for future use + ASCache::Set($this->id, 'json:' . $this->raw); + $this->type = $this->get_primary_type(); $this->actor = $this->get_actor('actor', '', ''); $this->obj = $this->get_compound_property('object'); @@ -394,12 +403,22 @@ class ActivityStreams { $x = $this->get_property_obj($property, $base, $namespace); if ($this->is_url($x)) { - $y = $this->fetch_property($x); + $cached = ASCache::Get($x); + if ($cached) { + $y = unserialise($cached); + } + else { + $y = $this->fetch_property($x); + if ($y) { + ASCache::Set($x, serialise($y)); + } + } if (is_array($y)) { $x = $y; } } + // verify and unpack JSalmon signature if present if (is_array($x) && array_key_exists('signed', $x)) { -- cgit v1.2.3 From 09465619e53c9c0a04ee73cecc3fc2d87ee74d55 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 28 Jan 2024 17:03:05 +0000 Subject: enable object cash by default, introduce system.cache_expire_days and default to 7, default system.default_expire_days to 30 and system.active_expire_days to 7 --- Zotlabs/Lib/ActivityStreams.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 3749126d3..b37efdd26 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -405,9 +405,11 @@ class ActivityStreams { if ($this->is_url($x)) { $cached = ASCache::Get($x); if ($cached) { + // logger('AS cached: ' . $x); $y = unserialise($cached); } else { + // logger('AS fetching: ' . $x); $y = $this->fetch_property($x); if ($y) { ASCache::Set($x, serialise($y)); -- cgit v1.2.3 From 2e155892fe88c877c226fc5a10402a05c05fe8cd Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Feb 2024 16:00:17 +0000 Subject: testing JcsEddsa2022 sigs --- Zotlabs/Lib/ActivityStreams.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index b37efdd26..b3b58af89 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -524,16 +524,22 @@ class ActivityStreams { $signer = $this->get_property_obj('verificationMethod', $this->sig); $parseUrl = parse_url($signer); - if (!empty($parseUrl['fragment']) && str_starts_with($parseUrl['fragment'],'z6Mk')) { - $publicKey = $parseUrl['fragment']; + + if (isset($parseUrl['fragment'])) { + if (str_starts_with($parseUrl['fragment'], 'z6Mk')) { + $publicKey = $parseUrl['fragment']; + } unset($parseUrl['fragment']); + } + + if (isset($parseUrl['query'])) { unset($parseUrl['query']); } $url = unparse_url($parseUrl); - //$this->signer = [ 'id' => $url ]; $hublocs = Activity::get_actor_hublocs($url); + $hasStoredKey = false; if ($hublocs) { foreach ($hublocs as $hubloc) { @@ -543,14 +549,26 @@ class ActivityStreams { } } } + if (!$hasStoredKey) { $this->signer = Activity::get_actor($url); - if ($this->signer - && !empty($this->signer['assertionMethod']) - && !empty($this->signer['assertionMethod']['publicKeyMultibase'])) { - $publicKey = $this->signer['assertionMethod']['publicKeyMultibase']; + + if (isset($this->signer['assertionMethod'])) { + if (!isset($this->signer['assertionMethod'][0])) { + $this->signer['assertionMethod'] = [$this->signer['assertionMethod']]; + } + + foreach($this->signer['assertionMethod'] as $am) { + if ($url === $am['controller'] && + $am['type'] === 'Multikey' && + str_starts_with($am['publicKeyMultibase'], 'z6Mk') + ) { + $publicKey = $am['publicKeyMultibase']; + } + } } } + if ($publicKey) { $this->sigok = (new JcsEddsa2022)->verify($this->data, $publicKey); } -- cgit v1.2.3 From 9859008271d1493ad600dff34a1d6e250378c496 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Feb 2024 20:23:02 +0000 Subject: deal with inReplyTo array + some docu and style --- Zotlabs/Lib/ActivityStreams.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Lib/ActivityStreams.php') diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index b3b58af89..9f028bb46 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -89,7 +89,7 @@ class ActivityStreams { // Attempt to assemble an Activity from what we were given. if ($this->is_valid()) { - $this->id = $this->get_property_obj('id'); + $this->id = $this->get_property_obj('id'); if (!$this->id) { logger('Data with mmissing id: ' . print_r($this->data, true)); @@ -130,24 +130,31 @@ class ActivityStreams { } } - // fetch recursive or embedded activities + // Fetch recursive or embedded activities if ($this->obj && is_array($this->obj) && array_key_exists('object', $this->obj)) { $this->obj['object'] = $this->get_compound_property('object', $this->obj); } - if ($this->obj && is_array($this->obj) && isset($this->obj['actor'])) + // Enumerate and store actors in referenced objects + + if ($this->obj && is_array($this->obj) && isset($this->obj['actor'])) { $this->obj['actor'] = $this->get_actor('actor', $this->obj); - if ($this->tgt && is_array($this->tgt) && isset($this->tgt['actor'])) + } + + if ($this->tgt && is_array($this->tgt) && isset($this->tgt['actor'])) { $this->tgt['actor'] = $this->get_actor('actor', $this->tgt); + } + + // Determine if this is a followup or response activity $this->parent_id = $this->get_property_obj('inReplyTo'); - if (!$this->parent_id && is_array($this->obj) && isset($this->obj['inReplyTo'])) { - $this->parent_id = $this->obj['inReplyTo']; + if (!$this->parent_id && isset($this->obj['inReplyTo'])) { + $this->parent_id = ((is_array($this->obj['inReplyTo'])) ? $this->obj['inReplyTo']['id'] : $this->obj['inReplyTo']); } - if (!$this->parent_id && is_array($this->obj) && isset($this->obj['id'])) { + if (!$this->parent_id && isset($this->obj['id'])) { $this->parent_id = $this->obj['id']; } -- cgit v1.2.3