create and import ed25519 xchan keys

This commit is contained in:
Mike Macgirvin 2024-01-02 15:34:19 +11:00
parent 6b4b05d63e
commit fed01ba62a
10 changed files with 95 additions and 8 deletions

View file

@ -2441,6 +2441,15 @@ class Activity
}
}
}
$epubkey = '';
if (isset($person_obj['assertionMethod']['publicKeyMultibase'])) {
if ($person_obj['id'] === $person_obj['assertionMethod']['controller']) {
$epubkey = $person_obj['assertionMethod']['publicKeyMultibase'];
if ($person_obj['assertionMethod']['type'] === 'Multikey') {
$epubkey = $person_obj['assertionMethod']['publicKeyMultibase'];
}
}
}
$keywords = [];
@ -2490,6 +2499,7 @@ class Activity
'xchan_hash' => $url,
'xchan_guid' => $url,
'xchan_pubkey' => $pubkey,
'xchan_epubkey' => $epubkey,
'xchan_addr' => $webfingerAddress,
'xchan_url' => $profile,
'xchan_name' => $name,
@ -2517,10 +2527,11 @@ class Activity
// update existing record
q(
"update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_pubkey = '%s', xchan_network = '%s', xchan_name_date = '%s', xchan_hidden = %d, xchan_type = %d, xchan_censored = %d where xchan_hash = '%s'",
"update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_pubkey = '%s', xchan_epubkey = '%s', xchan_network = '%s', xchan_name_date = '%s', xchan_hidden = %d, xchan_type = %d, xchan_censored = %d where xchan_hash = '%s'",
dbesc(datetime_convert()),
dbesc($name),
dbesc($pubkey),
dbesc($epubkey),
dbesc('activitypub'),
dbesc(datetime_convert()),
intval($hidden),

View file

@ -473,6 +473,7 @@ class Channel
'xchan_guid' => $guid,
'xchan_guid_sig' => $sig,
'xchan_pubkey' => $key['pubkey'],
'xchan_epubkey' => (new Multibase())->publicKey($ekey['pubkey']),
'xchan_photo_mimetype' => (($photo_type) ? $photo_type : 'image/png'),
'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}",
'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}",

View file

@ -864,6 +864,7 @@ class Libzot
|| ($r[0]['xchan_connurl'] !== $arr['primary_location']['connections_url'])
|| ($r[0]['xchan_addr'] !== $arr['primary_location']['address'])
|| ($r[0]['xchan_follow'] !== $arr['primary_location']['follow_url'])
|| ($r[0]['xchan_epubkey'] !== $arr['ed25519_key'])
|| ($r[0]['xchan_connpage'] !== $arr['connect_url'])
|| ($r[0]['xchan_url'] !== $arr['primary_location']['url'])
|| ($r[0]['xchan_network'] !== $network)
@ -917,6 +918,7 @@ class Libzot
'xchan_guid' => $arr['id'],
'xchan_guid_sig' => $arr['id_sig'],
'xchan_pubkey' => $arr['public_key'],
'xchan_epubkey' => $arr['ed25519_key'],
'xchan_photo_mimetype' => $arr['photo']['type'],
'xchan_photo_l' => $arr['photo']['url'],
'xchan_addr' => escape_tags($arr['primary_location']['address']),
@ -3015,6 +3017,7 @@ class Libzot
$ret['primary_location'] = $primary->toArray();
$ret['public_key'] = $e['xchan_pubkey'];
$ret['ed25519_key'] = $e['xchan_epubkey'];
$ret['signing_algorithm'] = 'rsa-sha256';
$ret['username'] = $e['channel_address'];
$ret['name'] = $e['xchan_name'];

39
Code/Update/_1275.php Normal file
View file

@ -0,0 +1,39 @@
<?php
namespace Code\Update;
class _1275
{
public function run()
{
q("START TRANSACTION");
if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$r1 = q("ALTER TABLE xchan ADD xchan_epubkey text");
$r2 = q("ALTER TABLE xchan ALTER xchan_epubkey set NOT NULL DEFAULT ''");
$r = $r1 && $r2;
} else {
$r = q("ALTER TABLE xchan ADD xchan_epubkey text NOT NULL");
}
if ($r) {
q("COMMIT");
return UPDATE_SUCCESS;
}
q("ROLLBACK");
return UPDATE_FAILED;
}
public function verify()
{
$columns = db_columns('xchan');
return in_array('xchan_epubkey', $columns);
}
}

30
Code/Update/_1276.php Normal file
View file

@ -0,0 +1,30 @@
<?php
namespace Code\Update;
use Code\Lib\Channel;
use Code\Lib\Multibase;
use StephenHill\Base58;
class _1276
{
public function run()
{
$channels = q("select * from channel where true");
if ($channels) {
foreach ($channels as $channel) {
$epubkey = (new Multibase())->publicKey($channel['channel_epubkey']);
q("update xchan set xchan_epubkey = '%s' where xchan_url = '%s'",
dbesc($epubkey),
dbesc(Channel::url($channel))
);
}
}
return UPDATE_SUCCESS;
}
public function verify()
{
return true;
}
}

View file

@ -26,7 +26,7 @@ use Code\Lib\Url;
*/
const REPOSITORY_ID = 'streams';
const DB_UPDATE_VERSION = 1274;
const DB_UPDATE_VERSION = 1276;
const PROJECT_BASE = __DIR__;
const ACTIVITYPUB_ENABLED = true;
const NOMAD_PROTOCOL_VERSION = '12.0';

View file

@ -2,11 +2,11 @@
require_once("include/network.php");
if (! function_exists('system_down')) {
function system_down(): void
{
http_status(503, 'Service Unavailable', false);
echo <<< EOT
function system_down(): void
{
http_status(503, 'Service Unavailable', false);
echo <<< EOT
<html lang="en">
<head><title>System Unavailable</title></head>
<body>
@ -15,6 +15,6 @@ Apologies but this site is unavailable at the moment. Please try again later.
</html>
EOT;
}
}

View file

@ -12,6 +12,7 @@ function xchan_store_lowlevel($arr)
'xchan_guid' => ((array_key_exists('xchan_guid', $arr)) ? $arr['xchan_guid'] : ''),
'xchan_guid_sig' => ((array_key_exists('xchan_guid_sig', $arr)) ? $arr['xchan_guid_sig'] : ''),
'xchan_pubkey' => ((array_key_exists('xchan_pubkey', $arr)) ? $arr['xchan_pubkey'] : ''),
'xchan_epubkey' => ((array_key_exists('xchan_epubkey', $arr)) ? $arr['xchan_epubkey'] : ''),
'xchan_photo_mimetype' => ((array_key_exists('xchan_photo_mimetype', $arr)) ? $arr['xchan_photo_mimetype'] : ''),
'xchan_photo_l' => ((array_key_exists('xchan_photo_l', $arr)) ? $arr['xchan_photo_l'] : ''),
'xchan_photo_m' => ((array_key_exists('xchan_photo_m', $arr)) ? $arr['xchan_photo_m'] : ''),

View file

@ -1165,6 +1165,7 @@ CREATE TABLE IF NOT EXISTS `xchan` (
`xchan_guid` varchar(255) NOT NULL DEFAULT '',
`xchan_guid_sig` text NOT NULL,
`xchan_pubkey` text NOT NULL,
`xchan_epubkey` text NOT NULL,
`xchan_photo_mimetype` varchar(255) NOT NULL DEFAULT 'image/jpeg',
`xchan_photo_l` varchar(255) NOT NULL DEFAULT '',
`xchan_photo_m` varchar(255) NOT NULL DEFAULT '',

View file

@ -1234,6 +1234,7 @@ CREATE TABLE "xchan" (
"xchan_guid" text NOT NULL DEFAULT '',
"xchan_guid_sig" text NOT NULL DEFAULT '',
"xchan_pubkey" text NOT NULL DEFAULT '',
"xchan_epubkey" text NOT NULL DEFAULT '',
"xchan_photo_mimetype" text NOT NULL DEFAULT 'image/jpeg',
"xchan_photo_l" text NOT NULL DEFAULT '',
"xchan_photo_m" text NOT NULL DEFAULT '',