Support for fetching non-public content / preparations for forum posts
This commit is contained in:
parent
1395bdc188
commit
8f27e3aeb1
5 changed files with 188 additions and 30 deletions
|
@ -90,7 +90,7 @@ class HTTPSignature
|
|||
$key = $key($sig_block['keyId']);
|
||||
}
|
||||
|
||||
Logger::log('Got keyID ' . $sig_block['keyId']);
|
||||
Logger::log('Got keyID ' . $sig_block['keyId'], Logger::DEBUG);
|
||||
|
||||
if (!$key) {
|
||||
return $result;
|
||||
|
@ -308,11 +308,59 @@ class HTTPSignature
|
|||
$postResult = Network::post($target, $content, $headers);
|
||||
$return_code = $postResult->getReturnCode();
|
||||
|
||||
Logger::log('Transmit to ' . $target . ' returned ' . $return_code);
|
||||
Logger::log('Transmit to ' . $target . ' returned ' . $return_code, Logger::DEBUG);
|
||||
|
||||
return ($return_code >= 200) && ($return_code <= 299);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fetches JSON data for a user
|
||||
*
|
||||
* @param string $request request url
|
||||
* @param integer $uid User id of the requester
|
||||
*
|
||||
* @return array JSON array
|
||||
*/
|
||||
public static function fetch($request, $uid)
|
||||
{
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
|
||||
if (!$owner) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Header data that is about to be signed.
|
||||
$host = parse_url($request, PHP_URL_HOST);
|
||||
$path = parse_url($request, PHP_URL_PATH);
|
||||
|
||||
$headers = ['Host: ' . $host];
|
||||
|
||||
$signed_data = "(request-target): get " . $path . "\nhost: " . $host;
|
||||
|
||||
$signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
|
||||
|
||||
$headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) host",signature="' . $signature . '"';
|
||||
|
||||
$headers[] = 'Accept: application/activity+json, application/ld+json';
|
||||
|
||||
$curlResult = Network::curl($request, false, $redirects, ['header' => $headers]);
|
||||
$return_code = $curlResult->getReturnCode();
|
||||
|
||||
Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);
|
||||
|
||||
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$content = json_decode($curlResult->getBody(), true);
|
||||
|
||||
if (empty($content) || !is_array($content)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets a signer from a given HTTP request
|
||||
*
|
||||
|
|
|
@ -83,6 +83,7 @@ class Network
|
|||
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
|
||||
* 'nobody' => only return the header
|
||||
* 'cookiejar' => path to cookie jar file
|
||||
* 'header' => header array
|
||||
*
|
||||
* @return CurlResult
|
||||
*/
|
||||
|
@ -136,6 +137,10 @@ class Network
|
|||
);
|
||||
}
|
||||
|
||||
if (!empty($opts['header'])) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['header']);
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue