X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FHTTPSignature.php;h=234d896078a6b1710df1885348ad25fdece2e610;hb=72fc89d033070a72a01fd0b3f7a91d21d7467acb;hp=8fa8566af378b30bba135efcfefca8b89fffeb5d;hpb=c083ae047c4259dcfa1c61a3795679bbf1b08d8c;p=friendica.git diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 8fa8566af3..234d896078 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -9,6 +9,7 @@ use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Database\DBA; use Friendica\Model\User; +use Friendica\Model\APContact; use Friendica\Protocol\ActivityPub; /** @@ -16,12 +17,22 @@ use Friendica\Protocol\ActivityPub; * * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPSig.php * + * Other parts of the code for HTTP signing are taken from the Osada project. + * https://framagit.org/macgirvin/osada + * * @see https://tools.ietf.org/html/draft-cavage-http-signatures-07 */ class HTTPSignature { // See draft-cavage-http-signatures-08 + /** + * @brief Verifies a magic request + * + * @param $key + * + * @return array with verification data + */ public static function verifyMagic($key) { $headers = null; @@ -254,10 +265,17 @@ class HTTPSignature return ''; } - /** + /* * Functions for ActivityPub */ + /** + * @brief Transmit given data to a target for a user + * + * @param $data + * @param $target + * @param $uid + */ public static function transmit($data, $target, $uid) { $owner = User::getOwnerDataById($uid); @@ -290,6 +308,14 @@ class HTTPSignature logger('Transmit to ' . $target . ' returned ' . $return_code); } + /** + * @brief Gets a signer from a given HTTP request + * + * @param $content + * @param $http_headers + * + * @return signer string + */ public static function getSigner($content, $http_headers) { $object = json_decode($content, true); @@ -386,16 +412,24 @@ class HTTPSignature return $key['url']; } + /** + * @brief fetches a key for a given id and actor + * + * @param $id + * @param $actor + * + * @return array with actor url and public key + */ private static function fetchKey($id, $actor) { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - $profile = ActivityPub::fetchprofile($url); + $profile = APContact::getByURL($url); if (!empty($profile)) { logger('Taking key from id ' . $id, LOGGER_DEBUG); return ['url' => $url, 'pubkey' => $profile['pubkey']]; } elseif ($url != $actor) { - $profile = ActivityPub::fetchprofile($actor); + $profile = APContact::getByURL($actor); if (!empty($profile)) { logger('Taking key from actor ' . $actor, LOGGER_DEBUG); return ['url' => $actor, 'pubkey' => $profile['pubkey']];