- return;
- }
-
- return json_decode($ret['body'], true);
- }
-
- /**
- * Resolves the profile url from the address by using webfinger
- *
- * @param string $addr profile address (user@domain.tld)
- * @return string url
- */
- private static function addrToUrl($addr)
- {
- $addr_parts = explode('@', $addr);
- if (count($addr_parts) != 2) {
- return false;
- }
-
- $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
-
- $ret = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
- if (!$ret['success'] || empty($ret['body'])) {
- return false;
- }
-
- $data = json_decode($ret['body'], true);
-
- if (empty($data['links'])) {
- return false;
- }
-
- foreach ($data['links'] as $link) {
- if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) {
- continue;
- }
-
- if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) {
- return $link['href'];
- }
- }
-
- return false;
- }
-
- public static function verifySignature($content, $http_headers)
- {
- $object = json_decode($content, true);
-
- if (empty($object)) {
- return false;
- }
-
- $actor = self::processElement($object, 'actor', 'id');
-
- $headers = [];
- $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI'];
-
- // First take every header
- foreach ($http_headers as $k => $v) {
- $field = str_replace('_', '-', strtolower($k));
- $headers[$field] = $v;
- }
-
- // Now add every http header
- foreach ($http_headers as $k => $v) {
- if (strpos($k, 'HTTP_') === 0) {
- $field = str_replace('_', '-', strtolower(substr($k, 5)));
- $headers[$field] = $v;
- }
- }
-
- $sig_block = ActivityPub::parseSigHeader($http_headers['HTTP_SIGNATURE']);
-
- if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) {
- return false;
- }
-
- $signed_data = '';
- foreach ($sig_block['headers'] as $h) {
- if (array_key_exists($h, $headers)) {
- $signed_data .= $h . ': ' . $headers[$h] . "\n";
- }
- }
- $signed_data = rtrim($signed_data, "\n");
-
- if (empty($signed_data)) {
- return false;
- }
-
- $algorithm = null;
-
- if ($sig_block['algorithm'] === 'rsa-sha256') {
- $algorithm = 'sha256';
- }
-
- if ($sig_block['algorithm'] === 'rsa-sha512') {
- $algorithm = 'sha512';
- }
-
- if (empty($algorithm)) {
- return false;
- }
-
- $key = self::fetchKey($sig_block['keyId'], $actor);
-
- if (empty($key)) {