From 0e6e12305ea1083937717ff13907a363003d4c7a Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sat, 24 Aug 2024 08:50:48 +1000 Subject: [PATCH 1/3] case-sensitivity in find_xchan_in_array() --- include/items.php | 2 +- include/misc.php | 26 +------------------------- src/Daemon/Poller.php | 5 +---- 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/include/items.php b/include/items.php index d33d8b1bb..9608d8211 100644 --- a/include/items.php +++ b/include/items.php @@ -4790,7 +4790,7 @@ function list_attached_local_files($body) { function fix_attached_permissions($uid,$body,$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny,$token = EMPTY_STR) { $channel = Channel::from_id($uid); - + $files = list_attached_local_files($body); if (! $files) { return; diff --git a/include/misc.php b/include/misc.php index e41158b8c..c9c205f4d 100644 --- a/include/misc.php +++ b/include/misc.php @@ -2739,35 +2739,11 @@ function xchan_query(&$items, $abook = true, $effective_uid = 0) } } -function xchan_mail_query(&$item) -{ - $arr = []; - $chans = null; - if ($item) { - if ($item['from_xchan'] && (! in_array("'" . dbesc($item['from_xchan']) . "'", $arr))) { - $arr[] = "'" . dbesc($item['from_xchan']) . "'"; - } - if ($item['to_xchan'] && (! in_array("'" . dbesc($item['to_xchan']) . "'", $arr))) { - $arr[] = "'" . dbesc($item['to_xchan']) . "'"; - } - } - - if (count($arr)) { - $chans = q("select xchan.*,hubloc.* from xchan left join hubloc on hubloc_hash = xchan_hash - where xchan_hash in (" . protect_sprintf(implode(',', $arr)) . ") and hubloc_primary = 1 and hubloc_deleted = 0"); - } - if ($chans) { - $item['from'] = find_xchan_in_array($item['from_xchan'], $chans); - $item['to'] = find_xchan_in_array($item['to_xchan'], $chans); - } -} - - function find_xchan_in_array($xchan, $arr) { if (count($arr)) { foreach ($arr as $x) { - if ($x['xchan_hash'] === $xchan) { + if (strtolower($x['xchan_hash']) === strtolower($xchan)) { return $x; } } diff --git a/src/Daemon/Poller.php b/src/Daemon/Poller.php index 88c52ab07..81482a3ae 100644 --- a/src/Daemon/Poller.php +++ b/src/Daemon/Poller.php @@ -26,10 +26,7 @@ class Poller implements DaemonInterface } } - $interval = intval(get_config('system', 'poll_interval')); - if (! $interval) { - $interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval'))); - } + $interval = intval(get_config('system', 'poll_interval', 3)); // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'cache/poller'; From cf551b674a51174400acb4eb76f6b24bcc40fc1b Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Mon, 26 Aug 2024 09:38:42 +1000 Subject: [PATCH 2/3] Trying to make practical use of lame specs continued. --- src/Lib/Activity.php | 3 ++- src/Lib/ActivityPub.php | 39 ++++++++++++++++++++++++--------------- src/Lib/Channel.php | 5 ++++- src/Lib/JcsEddsa2022.php | 2 +- src/Module/Follow.php | 10 ++++++---- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Lib/Activity.php b/src/Lib/Activity.php index 1d66fbaae..34ebbfeec 100644 --- a/src/Lib/Activity.php +++ b/src/Lib/Activity.php @@ -2440,6 +2440,7 @@ class Activity return; } + $actorIdUrl = $url; $actorId = new ActorId($url); $url = $actorId->getId(); $isDid = in_array($actorId->getType(), [ActorId::ACTORID_TYPE_DIDKEY, ActorId::ACTORID_TYPE_DIDWEB]); @@ -2621,7 +2622,7 @@ class Activity // create a new record xchan_store_lowlevel( [ 'xchan_hash' => $url, - 'xchan_guid' => $url, + 'xchan_guid' => $actorIdUrl, 'xchan_pubkey' => $pubkey, 'xchan_epubkey' => $epubkey, 'xchan_addr' => $webfingerAddress, diff --git a/src/Lib/ActivityPub.php b/src/Lib/ActivityPub.php index a8e928beb..8b552b1a4 100644 --- a/src/Lib/ActivityPub.php +++ b/src/Lib/ActivityPub.php @@ -264,13 +264,15 @@ class ActivityPub $orig_follow_type = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_type'); $locations = Activity::get_actor_hublocs($x['recipient']['xchan_hash'], 'activitypub, not_deleted'); + $isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP'); + $rootPath = (($isNomadic) ? Channel::getDidResolver($x['sender']) : z_root()); if ($locations) { foreach ($locations as $location) { $msg = array_merge( Activity::ap_context(), [ - 'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR), + 'id' => $rootPath . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR), 'type' => (($orig_follow_type) ?: 'Follow'), 'actor' => $p, 'object' => $location['hubloc_id_url'], @@ -339,20 +341,21 @@ class ActivityPub if (!$p) { return; } - + $isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP'); + $rootPath = (($isNomadic) ? Channel::getDidResolver($x['sender']) : z_root()); $msg = array_merge( Activity::ap_context(), [ - 'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept), + 'id' => $rootPath . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept), 'type' => 'Accept', 'actor' => $p, 'object' => [ 'type' => (($follow_type) ?: 'Follow'), 'id' => $accept, - 'actor' => $x['recipient']['xchan_hash'], + 'actor' => $x['recipient']['xchan_guid'], 'object' => Channel::getDidResolver($x['sender'], true) ], - 'to' => [$x['recipient']['xchan_hash']], + 'to' => [$x['recipient']['xchan_guid']], 'cc' => [] ] ); @@ -384,15 +387,17 @@ class ActivityPub return; } + $isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP'); + $msg = array_merge( Activity::ap_context(), [ - 'id' => z_root() . '/channel/' . $x['sender']['channel_address'] . '#update', + 'id' => Channel::getDidResolver($x['sender'], true) . '#update', 'type' => 'Update', 'updated' => Time::convert(format: ISO8601), 'actor' => $p, - 'object' => z_root() . '/channel/' . $x['sender']['channel_address'], - 'to' => [z_root() . '/followers/' . $x['sender']['channel_address']], + 'object' => Channel::getDidResolver($x['sender'], true), + 'to' => [($isNomadic) ? Channel::getDidResolver($x['sender']) . 'actor/followers' : z_root() . '/followers/' . $x['sender']['channel_address']], 'cc' => [ACTIVITY_PUBLIC_INBOX] ] ); @@ -439,6 +444,9 @@ class ActivityPub return; } + $isNomadic = PConfig::Get($channel['channel_id'], 'system', 'nomadicAP'); + $rootPath = (($isNomadic) ? Channel::getDidResolver($channel) : z_root()); + // send an unfollow activity to the followee's inbox $orig_activity = get_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id'); @@ -446,19 +454,20 @@ class ActivityPub if ($orig_activity && $recip[0]['abook_pending']) { // was never approved + $msg = array_merge( Activity::ap_context(), [ - 'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject', + 'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject', 'type' => 'Reject', 'actor' => $p, 'object' => [ 'type' => 'Follow', 'id' => $orig_activity, - 'actor' => $recip[0]['xchan_hash'], + 'actor' => $recip[0]['xchan_guid'], 'object' => $p ], - 'to' => [$recip[0]['xchan_hash']], + 'to' => [$recip[0]['xchan_guid']], 'cc' => [] ] ); @@ -469,16 +478,16 @@ class ActivityPub $msg = array_merge( Activity::ap_context(), [ - 'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow', + 'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow', 'type' => 'Undo', 'actor' => $p, 'object' => [ - 'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR), + 'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR), 'type' => 'Follow', 'actor' => $p, - 'object' => $recip[0]['xchan_hash'] + 'object' => $recip[0]['xchan_guid'] ], - 'to' => [$recip[0]['xchan_hash']], + 'to' => [$recip[0]['xchan_guid']], 'cc' => [] ] ); diff --git a/src/Lib/Channel.php b/src/Lib/Channel.php index 256f7947a..4ec7a6dc7 100644 --- a/src/Lib/Channel.php +++ b/src/Lib/Channel.php @@ -2080,10 +2080,13 @@ class Channel return self::getDid($channel); } - public static function getVerifier($channel) + public static function getVerifier($channel, $id = '') { $pubkey = (new Multibase())->publicKey($channel['channel_epubkey']); $nomadic = PConfig::Get($channel['channel_id'], 'system', 'nomadicAP'); + if (!str_contains($id, '/.well-known/apgateway/')) { + $nomadic = false; + } return (($nomadic) ? Channel::getDid($channel) : Channel::url($channel) . '#' . $pubkey); } diff --git a/src/Lib/JcsEddsa2022.php b/src/Lib/JcsEddsa2022.php index a5581a57e..24f4671c4 100644 --- a/src/Lib/JcsEddsa2022.php +++ b/src/Lib/JcsEddsa2022.php @@ -26,7 +26,7 @@ class JcsEddsa2022 'type' => 'DataIntegrityProof', 'cryptosuite' => 'eddsa-jcs-2022', 'created' => Time::convert(format: ISO8601), - 'verificationMethod' => Channel::getVerifier($channel), + 'verificationMethod' => Channel::getVerifier($channel, $data['id'] ?? ''), 'proofPurpose' => 'assertionMethod', ]; diff --git a/src/Module/Follow.php b/src/Module/Follow.php index 9e029581f..e618160ed 100644 --- a/src/Module/Follow.php +++ b/src/Module/Follow.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\PConfig; use Code\Web\Controller; use Code\Lib\Libsync; use Code\Lib\ActivityStreams; @@ -48,12 +49,13 @@ class Follow extends Controller $orig_follow = get_abconfig($chan['channel_id'], $r[0]['xchan_hash'], 'activitypub', 'their_follow_id'); $orig_follow_type = get_abconfig($chan['channel_id'], $r[0]['xchan_hash'], 'activitypub', 'their_follow_type'); - + $isNomadic = PConfig::Get($chan['channel_id'], 'system', 'nomadicAP'); + $rootPath = (($isNomadic) ? Channel::getDidResolver($chan) : z_root()); as_return_and_die([ - 'id' => z_root() . '/follow/' . $r[0]['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR), + 'id' => $rootPath . '/follow/' . $r[0]['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR), 'type' => (($orig_follow_type) ?: 'Follow'), 'actor' => $actor, - 'object' => $r[0]['xchan_url'] + 'object' => $r[0]['xchan_guid'] ], $chan); } @@ -146,7 +148,7 @@ class Follow extends Controller info(t('Connection added.') . EOL); Channel::abook_sync($channel, $result['abook']); - $can_view_stream = their_perms_contains($channel['channel_id'], $clone['abook_xchan'], 'view_stream'); + $can_view_stream = their_perms_contains($channel['channel_id'], $result['abook']['abook_xchan'], 'view_stream'); // If we can view their stream, pull in some posts From 5654130cdc73d747a93e1f4f65b2a961b6e56a8e Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Tue, 27 Aug 2024 06:55:10 +1000 Subject: [PATCH 3/3] Put the privacy policy where stupid-ass corporations and extinct elephant worshippers look for it. --- src/Module/Privacy_policy.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/Module/Privacy_policy.php diff --git a/src/Module/Privacy_policy.php b/src/Module/Privacy_policy.php new file mode 100644 index 000000000..35b22ed2c --- /dev/null +++ b/src/Module/Privacy_policy.php @@ -0,0 +1,14 @@ +