fixes for nomadic signing

This commit is contained in:
Mike Macgirvin 2024-06-30 07:11:41 +10:00
parent 6db495dca0
commit 804ec2cb05
2 changed files with 67 additions and 59 deletions

View file

@ -1461,7 +1461,7 @@ class Activity
);
if ($d) {
if (in_array($d[0]['hubloc_network'], ['activitypub', 'apnomadic'])) {
if ($d[0]['hubloc_network'] === 'activitypub') {
$addr = $d[0]['hubloc_hash'];
} else {
$addr = $d[0]['hubloc_id_url'];
@ -2666,47 +2666,48 @@ class Activity
$baseurl = $collection['scheme'] . '://' . $collection['host'] . ((isset($collection['port']) && intval($collection['port'])) ? ':' . $collection['port'] : '');
}
if (!$h) {
hubloc_store_lowlevel([
'hubloc_guid' => $url,
'hubloc_hash' => $url,
'hubloc_id_url' => $profile,
'hubloc_addr' => $webfingerAddress,
'hubloc_network' => $isDid ? 'apnomadic' : 'activitypub',
'hubloc_url' => $baseurl,
'hubloc_host' => $hostname,
'hubloc_callback' => $inbox,
'hubloc_updated' => Time::convert(),
'hubloc_primary' => 1
]);
}
else {
if ($webfingerAddress !== $h[0]['hubloc_addr']) {
if (! $isDid) {
if (!$h) {
hubloc_store_lowlevel([
'hubloc_guid' => $url,
'hubloc_hash' => $url,
'hubloc_id_url' => $profile,
'hubloc_addr' => $webfingerAddress,
'hubloc_network' => $isDid ? 'apnomadic' : 'activitypub',
'hubloc_url' => $baseurl,
'hubloc_host' => $hostname,
'hubloc_callback' => $inbox,
'hubloc_updated' => Time::convert(),
'hubloc_primary' => 1
]);
} else {
if ($webfingerAddress !== $h[0]['hubloc_addr']) {
q(
"update hubloc set hubloc_addr = '%s' where hubloc_hash = '%s'",
dbesc($webfingerAddress),
dbesc($url)
);
}
if ($inbox !== $h[0]['hubloc_callback']) {
q(
"update hubloc set hubloc_callback = '%s' where hubloc_hash = '%s'",
dbesc($inbox),
dbesc($url)
);
}
if ($profile !== $h[0]['hubloc_id_url']) {
q(
"update hubloc set hubloc_id_url = '%s' where hubloc_hash = '%s'",
dbesc($profile),
dbesc($url)
);
}
q(
"update hubloc set hubloc_addr = '%s' where hubloc_hash = '%s'",
dbesc($webfingerAddress),
"update hubloc set hubloc_updated = '%s' where hubloc_hash = '%s'",
dbesc(Time::convert()),
dbesc($url)
);
}
if ($inbox !== $h[0]['hubloc_callback']) {
q(
"update hubloc set hubloc_callback = '%s' where hubloc_hash = '%s'",
dbesc($inbox),
dbesc($url)
);
}
if ($profile !== $h[0]['hubloc_id_url']) {
q(
"update hubloc set hubloc_id_url = '%s' where hubloc_hash = '%s'",
dbesc($profile),
dbesc($url)
);
}
q(
"update hubloc set hubloc_updated = '%s' where hubloc_hash = '%s'",
dbesc(Time::convert()),
dbesc($url)
);
}
if (!$icon) {
@ -5012,7 +5013,7 @@ class Activity
"select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_hash = '%s' $sql_options order by hubloc_id DESC ",
dbesc($url)
),
'zot6', 'nomad' => q(
'zot6', 'nomad', 'apnomadic' => q(
"select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_id_url = '%s' $sql_options order by hubloc_id DESC ",
dbesc($url)
),

View file

@ -508,29 +508,36 @@ class ActivityStreams
public function checkEddsaSignature()
{
$signer = $this->get_property_obj('verificationMethod', $this->edsig);
$parseUrl = parse_url($signer);
if (!empty($parseUrl['fragment']) && str_starts_with($parseUrl['fragment'],'z6Mk')) {
$publicKey = $parseUrl['fragment'];
unset($parseUrl['fragment']);
unset($parseUrl['query']);
if ($signer && str_starts_with($signer, 'did:key:')) {
$publicKey = str_replace('did:key:', '', $signer);
$this->signer = ['id' => $signer];
}
$url = unparse_url($parseUrl);
$this->signer = [ 'id' => $url ];
$hublocs = Activity::get_actor_hublocs($url);
$hasStoredKey = false;
if ($hublocs) {
foreach ($hublocs as $hubloc) {
if ($publicKey && $hubloc['xchan_epubkey'] === $publicKey) {
$hasStoredKey = true;
break;
else {
$parseUrl = parse_url($signer);
if (!empty($parseUrl['fragment']) && str_starts_with($parseUrl['fragment'], 'z6Mk')) {
$publicKey = $parseUrl['fragment'];
unset($parseUrl['fragment']);
unset($parseUrl['query']);
}
$url = unparse_url($parseUrl);
$this->signer = ['id' => $url];
$hublocs = Activity::get_actor_hublocs($url);
$hasStoredKey = false;
if ($hublocs) {
foreach ($hublocs as $hubloc) {
if ($publicKey && $hubloc['xchan_epubkey'] === $publicKey) {
$hasStoredKey = true;
break;
}
}
}
}
if (! $hasStoredKey) {
$this->signer = Activity::fetch($url);
if ($this->signer && !empty($this->signer['assertionMethod'])) {
$publicKey = Activity::getEddsaPublicKey($this->signer);
if (!$hasStoredKey) {
$this->signer = Activity::fetch($url);
if ($this->signer && !empty($this->signer['assertionMethod'])) {
$publicKey = Activity::getEddsaPublicKey($this->signer);
}
}
}
if ($publicKey) {