mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
couple of ld-sig context fetching improvements
This commit is contained in:
parent
9aa3f7dd6a
commit
e23426c971
4 changed files with 32 additions and 10 deletions
|
@ -4609,7 +4609,7 @@ class Activity
|
||||||
'schema' => 'http://schema.org#',
|
'schema' => 'http://schema.org#',
|
||||||
'litepub' => 'http://litepub.social/ns#',
|
'litepub' => 'http://litepub.social/ns#',
|
||||||
'sm' => 'http://smithereen.software/ns#',
|
'sm' => 'http://smithereen.software/ns#',
|
||||||
'fep' => 'https://codeberg.org/fediverse/fep#',
|
// 'fep' => 'https://codeberg.org/fediverse/fep#',
|
||||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||||
'oauthRegistrationEndpoint' => 'litepub:oauthRegistrationEndpoint',
|
'oauthRegistrationEndpoint' => 'litepub:oauthRegistrationEndpoint',
|
||||||
'sensitive' => 'as:sensitive',
|
'sensitive' => 'as:sensitive',
|
||||||
|
@ -4625,7 +4625,7 @@ class Activity
|
||||||
'Hashtag' => 'as:Hashtag',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'canReply' => 'toot:canReply',
|
'canReply' => 'toot:canReply',
|
||||||
'approval' => 'toot:approval',
|
'approval' => 'toot:approval',
|
||||||
'Identity' => 'fep:Identity',
|
// 'Identity' => 'fep:Identity',
|
||||||
'isContainedConversation' => 'nomad:isContainedConversation',
|
'isContainedConversation' => 'nomad:isContainedConversation',
|
||||||
'conversation' => 'nomad:conversation',
|
'conversation' => 'nomad:conversation',
|
||||||
'commentPolicy' => 'nomad:commentPolicy',
|
'commentPolicy' => 'nomad:commentPolicy',
|
||||||
|
|
|
@ -12,12 +12,11 @@ class LDSignatures
|
||||||
|
|
||||||
public static function verify($data, $pubkey): bool
|
public static function verify($data, $pubkey): bool
|
||||||
{
|
{
|
||||||
|
|
||||||
$ohash = self::hash(self::signable_options($data['signature']));
|
$ohash = self::hash(self::signable_options($data['signature']));
|
||||||
$dhash = self::hash(self::signable_data($data));
|
$dhash = self::hash(self::signable_data($data));
|
||||||
|
|
||||||
$x = Crypto::verify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey);
|
$x = Crypto::verify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey);
|
||||||
logger('LD-verify: ' . intval($x));
|
logger('LD-verify: ' . (intval($x)) ? 'true' : 'false');
|
||||||
|
|
||||||
return $x;
|
return $x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Code\Daemon\Run;
|
||||||
use Code\Extend\Hook;
|
use Code\Extend\Hook;
|
||||||
use Code\Storage\Stdio;
|
use Code\Storage\Stdio;
|
||||||
|
|
||||||
|
require_once('library/jsonld/jsonld.php');
|
||||||
/**
|
/**
|
||||||
* @file include/network.php
|
* @file include/network.php
|
||||||
* @brief Network related functions.
|
* @brief Network related functions.
|
||||||
|
@ -1316,11 +1317,15 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false)
|
||||||
*/
|
*/
|
||||||
function jsonld_document_loader($url)
|
function jsonld_document_loader($url)
|
||||||
{
|
{
|
||||||
|
|
||||||
require_once('library/jsonld/jsonld.php');
|
|
||||||
|
|
||||||
$recursion = 0;
|
$recursion = 0;
|
||||||
|
|
||||||
|
$builtins = [
|
||||||
|
'https://www.w3.org/ns/activitystreams' => 'library/w3org/activitystreams.jsonld',
|
||||||
|
'https://w3id.org/identity/v1' => 'library/w3org/identity-v1.jsonld',
|
||||||
|
'https://w3id.org/security/v1' => 'library/w3org/security-v1.jsonld',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
$x = debug_backtrace();
|
$x = debug_backtrace();
|
||||||
if ($x) {
|
if ($x) {
|
||||||
foreach ($x as $n) {
|
foreach ($x as $n) {
|
||||||
|
@ -1340,21 +1345,38 @@ function jsonld_document_loader($url)
|
||||||
Stdio::mkdir($cachepath, STORAGE_DEFAULT_PERMISSIONS, true);
|
Stdio::mkdir($cachepath, STORAGE_DEFAULT_PERMISSIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filename = '';
|
||||||
|
|
||||||
|
foreach ($builtins as $key => $value) {
|
||||||
|
if ($url === $value) {
|
||||||
|
$filename = $key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! $filename) {
|
||||||
$filename = $cachepath . '/' . urlencode($url);
|
$filename = $cachepath . '/' . urlencode($url);
|
||||||
|
}
|
||||||
|
|
||||||
if (file_exists($filename) && filemtime($filename) > time() - (12 * 60 * 60)) {
|
if (file_exists($filename) && filemtime($filename) > time() - (12 * 60 * 60)) {
|
||||||
|
logger('loading ' . $filename . ' from recent cache');
|
||||||
return json_decode(file_get_contents($filename));
|
return json_decode(file_get_contents($filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = jsonld_default_document_loader($url);
|
$r = jsonld_default_document_loader($url);
|
||||||
if ($r) {
|
if ($r) {
|
||||||
|
if (!in_array($url, $builtins)) {
|
||||||
file_put_contents($filename, json_encode($r));
|
file_put_contents($filename, json_encode($r));
|
||||||
|
}
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('not found');
|
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
|
logger('loading ' . $filename . ' from longterm cache');
|
||||||
return json_decode(file_get_contents($filename));
|
return json_decode(file_get_contents($filename));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
logger($filename . ' does not exist and cannot be loaded');
|
||||||
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1262,6 +1262,7 @@ class JsonLdProcessor {
|
||||||
$opts['produceGeneralizedRdf'] = false;
|
$opts['produceGeneralizedRdf'] = false;
|
||||||
$dataset = $this->toRDF($input, $opts);
|
$dataset = $this->toRDF($input, $opts);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
|
logger('Exception: ' . $e->getMessage());
|
||||||
throw new JsonLdException(
|
throw new JsonLdException(
|
||||||
'Could not convert input to RDF dataset before normalization.',
|
'Could not convert input to RDF dataset before normalization.',
|
||||||
'jsonld.NormalizeError', null, null, $e);
|
'jsonld.NormalizeError', null, null, $e);
|
||||||
|
|
Loading…
Reference in a new issue