From 58f82e084db4c79f22629b6f82fcb858a6fe4b73 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Oct 2018 19:19:51 +0000 Subject: [PATCH 1/3] Preparations to work with BCC --- src/Protocol/ActivityPub.php | 5 +++++ src/Protocol/ActivityPub/Receiver.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 16 +++++++++++----- src/Util/HTTPSignature.php | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 23eb861721..e6701074c6 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -29,6 +29,11 @@ use Friendica\Model\APContact; * * To-do: * - Polling the outboxes for missing content? + * + * Missing parts from DFRN: + * - Public Forum + * - Private Forum + * - Relocation */ class ActivityPub { diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 4341c14a3f..472341d06f 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -37,7 +37,7 @@ class Receiver { const PUBLIC_COLLECTION = 'as:Public'; const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application']; - const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image']; + const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event']; const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept']; /** diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index b0e6cd3629..2b6f87e665 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -300,10 +300,11 @@ class Transmitter * Creates an array of permissions from an item thread * * @param array $item + * @param boolean $blindcopy * * @return array with permission data */ - private static function createPermissionBlockForItem($item) + private static function createPermissionBlockForItem($item, $blindcopy) { // Will be activated in a later step // $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; @@ -398,6 +399,9 @@ class Transmitter } } + if (!$blindcopy) { + } + return ['to' => array_values($data['to']), 'cc' => array_values($data['cc'])]; } @@ -453,7 +457,7 @@ class Transmitter */ public static function fetchTargetInboxes($item, $uid, $personal = false) { - $permissions = self::createPermissionBlockForItem($item); + $permissions = self::createPermissionBlockForItem($item, true); if (empty($permissions)) { return []; } @@ -471,13 +475,15 @@ class Transmitter continue; } + $blindcopy = in_array($element, ['bto', 'bcc']); + foreach ($permissions[$element] as $receiver) { if ($receiver == $item_profile['followers']) { $inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal)); } else { $profile = APContact::getByURL($receiver, false); if (!empty($profile)) { - if (empty($profile['sharedinbox']) || $personal) { + if (empty($profile['sharedinbox']) || $personal || $blindcopy) { $target = $profile['inbox']; } else { $target = $profile['sharedinbox']; @@ -593,7 +599,7 @@ class Transmitter $data['instrument'] = ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()]; - $data = array_merge($data, self::createPermissionBlockForItem($item)); + $data = array_merge($data, self::createPermissionBlockForItem($item, false)); if (in_array($data['type'], ['Create', 'Update', 'Delete'])) { $data['object'] = self::createNote($item); @@ -905,7 +911,7 @@ class Transmitter $data['generator'] = ['type' => 'Application', 'name' => $item['app']]; } - $data = array_merge($data, self::createPermissionBlockForItem($item)); + $data = array_merge($data, self::createPermissionBlockForItem($item, false)); return $data; } diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 1d2e7d9f76..34fe7a9870 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -406,6 +406,8 @@ class HTTPSignature } } + /// @todo Check if the signed date field is in an acceptable range + // Check the content-length when it is part of the signed data if (in_array('content-length', $sig_block['headers'])) { if (strlen($content) != $headers['content-length']) { From f300c8953a56e31045e1622d855be232c8e10602 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Oct 2018 20:06:57 +0000 Subject: [PATCH 2/3] We now use bcc for the acl block --- src/Protocol/ActivityPub/Transmitter.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 2b6f87e665..2a40838b91 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -312,7 +312,7 @@ class Transmitter // For now only send to these contacts: $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS]; - $data = ['to' => [], 'cc' => []]; + $data = ['to' => [], 'cc' => [], 'bcc' => []]; $data = array_merge($data, self::fetchPermissionBlockFromConversation($item)); @@ -350,7 +350,7 @@ class Transmitter foreach ($receiver_list as $receiver) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => $networks]); if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) { - $data['cc'][] = $profile['url']; + $data['bcc'][] = $profile['url']; } } } @@ -384,6 +384,7 @@ class Transmitter $data['to'] = array_unique($data['to']); $data['cc'] = array_unique($data['cc']); + $data['bcc'] = array_unique($data['bcc']); if (($key = array_search($item['author-link'], $data['to'])) !== false) { unset($data['to'][$key]); @@ -393,16 +394,33 @@ class Transmitter unset($data['cc'][$key]); } + if (($key = array_search($item['author-link'], $data['bcc'])) !== false) { + unset($data['bcc'][$key]); + } + foreach ($data['to'] as $to) { if (($key = array_search($to, $data['cc'])) !== false) { unset($data['cc'][$key]); } + + if (($key = array_search($to, $data['bcc'])) !== false) { + unset($data['bcc'][$key]); + } } + foreach ($data['cc'] as $cc) { + if (($key = array_search($cc, $data['bcc'])) !== false) { + unset($data['bcc'][$key]); + } + } + + $receivers = ['to' => array_values($data['to']), 'cc' => array_values($data['cc']), 'bcc' => array_values($data['bcc'])]; + if (!$blindcopy) { + unset($receivers['bcc']); } - return ['to' => array_values($data['to']), 'cc' => array_values($data['cc'])]; + return $receivers; } /** From 7f11b2e4e9b69e85a0d52b171d21214f2a99b57a Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 24 Oct 2018 21:04:21 +0000 Subject: [PATCH 3/3] Deactivated BCC --- src/Protocol/ActivityPub/Transmitter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 2a40838b91..e1da961534 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -350,7 +350,9 @@ class Transmitter foreach ($receiver_list as $receiver) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => $networks]); if (DBA::isResult($contact) && !empty($profile = APContact::getByURL($contact['url'], false))) { - $data['bcc'][] = $profile['url']; + // BCC is currently deactivated, due to Pleroma and Mastodon not reacting like expected + // $data['bcc'][] = $profile['url']; + $data['cc'][] = $profile['url']; } } }