From 0866fbaf8c65eedbf2d57a1b61f4fe96b2a526fd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 09:50:03 +0000 Subject: [PATCH] Code cleaning / wrong table for flags --- src/Protocol/ActivityPub.php | 6 ++-- src/Util/HTTPSignature.php | 67 ------------------------------------ 2 files changed, 3 insertions(+), 70 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index bd125aaae..25ebedc8b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -103,10 +103,10 @@ class ActivityPub */ public static function profile($uid) { - $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application', 'page-flags']; + $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application']; $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true]; - $fields = ['guid', 'nickname', 'pubkey', 'account-type']; + $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags']; $user = DBA::selectFirst('user', $fields, $condition); if (!DBA::isResult($user)) { return []; @@ -141,7 +141,7 @@ class ActivityPub 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; $data['summary'] = $contact['about']; $data['url'] = $contact['url']; - $data['manuallyApprovesFollowers'] = in_array($profile['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]); + $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]); $data['publicKey'] = ['id' => $contact['url'] . '#main-key', 'owner' => $contact['url'], 'publicKeyPem' => $user['pubkey']]; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 911de4308..adf5d8ad2 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -18,30 +18,6 @@ use Friendica\Database\DBA; class HTTPSignature { - /** - * @brief RFC5843 - * - * Disabled until Friendica's ActivityPub implementation - * is ready. - * - * @see https://tools.ietf.org/html/rfc5843 - * - * @param string $body The value to create the digest for - * @param boolean $set (optional, default true) - * If set send a Digest HTTP header - * - * @return string The generated digest of $body - */ -// public static function generateDigest($body, $set = true) -// { -// $digest = base64_encode(hash('sha256', $body, true)); -// -// if($set) { -// header('Digest: SHA-256=' . $digest); -// } -// return $digest; -// } - // See draft-cavage-http-signatures-08 public static function verify($data, $key = '') { @@ -127,12 +103,6 @@ class HTTPSignature logger('Got keyID ' . $sig_block['keyId']); - // We don't use Activity Pub at the moment. -// if (!$key) { -// $result['signer'] = $sig_block['keyId']; -// $key = self::getActivitypubKey($sig_block['keyId']); -// } - if (!$key) { return $result; } @@ -171,43 +141,6 @@ class HTTPSignature return $result; } - /** - * Fetch the public key for Activity Pub contact. - * - * @param string|int The identifier (contact addr or contact ID). - * @return string|boolean The public key or false on failure. - */ - private static function getActivitypubKey($id) - { - if (strpos($id, 'acct:') === 0) { - $contact = DBA::selectFirst('contact', ['pubkey'], ['uid' => 0, 'addr' => str_replace('acct:', '', $id)]); - } else { - $contact = DBA::selectFirst('contact', ['pubkey'], ['id' => $id, 'network' => 'activitypub']); - } - - if (DBA::isResult($contact)) { - return $contact['pubkey']; - } - - if(function_exists('as_fetch')) { - $r = as_fetch($id); - } - - if ($r) { - $j = json_decode($r, true); - - if (array_key_exists('publicKey', $j) && array_key_exists('publicKeyPem', $j['publicKey'])) { - if ((array_key_exists('id', $j['publicKey']) && $j['publicKey']['id'] !== $id) && $j['id'] !== $id) { - return false; - } - - return $j['publicKey']['publicKeyPem']; - } - } - - return false; - } - /** * @brief *