A rare issue with ActivityPub contact addition
TL;DR
For some reason w3.org
doesn't respond to some VPSes and therefore other accounts on other servers cannot add ActivivtyPub contact from Hubzilla on these VPSes.
How to check if this problem exists
-
curl "https://my-hubzilla-server.com/channel/my_channel" -H 'Accept: application/activity+json'
takes about 1 minute (which naturally exceeds timeout for the majority of other servers). -
curl "https://www.w3.org/ns/activitystreams" -H 'Accept: application/ld+json'
returns something likecurl: (28) Failed to connect to www.w3.org port 443: Connection timed out
Hotfix
- Open
library/jsonld/jsonld.php
. - Find
function jsonld_default_document_loader($url)
. - Replace
'http' => array(
'method' => 'GET',
'header' =>
"Accept: application/ld+json\r\n"),
/* Note: Use jsonld_default_secure_document_loader for security. */
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true)
);
with
'http' => array(
'method' => 'GET',
'header' => "Accept: application/ld+json\r\n",
'proxy' => 'tcp://69.197.181.202:3128', # change to some proxy ip and port
'request_fulluri' => true
),
/* Note: Use jsonld_default_secure_document_loader for security. */
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true)
);
- Not sure how it affects other parts of the system though.
Long version
Yesterday I observed that I cannot add my Hubzilla account as a contact into my Friendica account.
I tracked down the part of curl "https://my-hubzilla-server.com/channel/my_channel" -H 'Accept: application/activity+json'
which executed about a minute. The stacktrace for this part is as follows:
Zotlabs/Web/WebServer.php: $Router->Dispatch();
Zotlabs/Web/Router.php: $this->controller->init();
Zotlabs/Module/Channel.php: as_return_and_die(Activity::encode_person($channel, true), $channel);
include/network.php: $x['signature'] = LDSignatures::sign($x,$channel);
Zotlabs/Lib/LDSignatures.php: $dhash = self::hash(self::signable_data($data));
Zotlabs/Lib/LDSignatures.php: return hash('sha256',self::normalise($obj));
Zotlabs/Lib/LDSignatures.php: $d = jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]);
library/jsonld/jsonld.php: return $p->normalize($input, $options);
library/jsonld/jsonld.php: $dataset = $this->toRDF($input, $opts);
library/jsonld/jsonld.php: $expanded = $this->expand($input, $options);
library/jsonld/jsonld.php: $this->_retrieveContextUrls(
$input, new stdClass(), $options['documentLoader'], $options['base']);
library/jsonld/jsonld.php: $remote_doc = call_user_func($load_document, $url);
# $load_document is `jsonld_document_loader`, $url is `https://www.w3.org/ns/activitystreams`
library/jsonld/jsonld.php (jsonld_default_document_loader): $result = @file_get_contents($url, false, $context);
I solved the issue like a stated in Hotfix section, added contact and then rollback the changes. I don't think that this issue will ever be common, but if someone else faces the same situation, they might find this description useful.