X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FHTTPSignature.php;h=225a2bcf20f16081b97d7f7f392311aeb75ebad9;hb=44b2b97e80624aca5768511def80a95f0e6e0381;hp=498b356cd68466f8bffceea8a5b67525dcab67ab;hpb=51b31a846f0ab6128c6c9cb3d54aa47f4a97d809;p=friendica.git diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 498b356cd6..225a2bcf20 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -485,6 +485,31 @@ class HTTPSignature return $curlResult; } + /** + * Fetch the apcontact entry of the keyId in the given header + * + * @param array $http_headers + * + * @return array APContact entry + */ + public static function getKeyIdContact(array $http_headers): array + { + if (empty($http_headers['HTTP_SIGNATURE'])) { + Logger::debug('No HTTP_SIGNATURE header', ['header' => $http_headers]); + return []; + } + + $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); + + if (empty($sig_block['keyId'])) { + Logger::debug('No keyId', ['sig_block' => $sig_block]); + return []; + } + + $url = (strpos($sig_block['keyId'], '#') ? substr($sig_block['keyId'], 0, strpos($sig_block['keyId'], '#')) : $sig_block['keyId']); + return APContact::getByURL($url); + } + /** * Gets a signer from a given HTTP request * @@ -508,7 +533,7 @@ class HTTPSignature return false; } - $actor = JsonLD::fetchElement($object, 'actor', 'id'); + $actor = JsonLD::fetchElement($object, 'actor', 'id') ?? ''; } else { $actor = ''; } @@ -708,7 +733,6 @@ class HTTPSignature } } - // @TODO really a notice or more a warning? Logger::notice('Key could not be fetched', ['url' => $url, 'actor' => $actor]); return []; }