aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-01-07 19:58:09 +0000
committerMario <mario@mariovavti.com>2024-01-07 19:58:09 +0000
commit87775ae37ad7f8226f7413d28e96fd23967c7659 (patch)
tree330126a1fca83e4297b8b1d2d206b3940dbd7341
parent256b66de41b2cd8dcdeb39fc5f080c5ff957e5d2 (diff)
downloadvolse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.tar.gz
volse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.tar.bz2
volse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.zip
ekey and xchan_updated updates
-rw-r--r--Zotlabs/Lib/Libsync.php24
-rw-r--r--Zotlabs/Update/_1260.php53
-rw-r--r--Zotlabs/Update/_1261.php60
-rw-r--r--boot.php2
-rw-r--r--include/channel.php7
-rw-r--r--include/import.php6
-rw-r--r--install/schema_mysql.sql4
-rw-r--r--install/schema_postgres.sql8
8 files changed, 151 insertions, 13 deletions
diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php
index 5f183192d..3130290f7 100644
--- a/Zotlabs/Lib/Libsync.php
+++ b/Zotlabs/Lib/Libsync.php
@@ -325,9 +325,6 @@ class Libsync {
if (array_key_exists('channel', $arr) && is_array($arr['channel']) && count($arr['channel'])) {
- $remote_channel = $arr['channel'];
- $remote_channel['channel_id'] = $channel['channel_id'];
-
if (array_key_exists('channel_pageflags', $arr['channel'])) {
// Several pageflags are site-specific and cannot be sync'd.
@@ -339,6 +336,8 @@ class Libsync {
}
+ $columns = db_columns('channel');
+
$disallowed = [
'channel_id', 'channel_account_id', 'channel_primary', 'channel_prvkey',
'channel_address', 'channel_notifyflags', 'channel_removed', 'channel_deleted',
@@ -349,16 +348,21 @@ class Libsync {
'channel_a_delegate'
];
- $clean = [];
+ if (empty($channel['channel_epubkey']) && empty($channel['channel_eprvkey'])) {
+ $eckey = sodium_crypto_sign_keypair();
+ $channel['channel_epubkey'] = sodium_bin2base64(sodium_crypto_sign_publickey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ $channel['channel_eprvkey'] = sodium_bin2base64(sodium_crypto_sign_secretkey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ }
+
foreach ($arr['channel'] as $k => $v) {
- if (in_array($k, $disallowed))
+ if (in_array($k, $disallowed)) {
+ continue;
+ }
+ if (!in_array($k, $columns)) {
continue;
- $clean[$k] = $v;
- }
- if (count($clean)) {
- foreach ($clean as $k => $v) {
- dbq("UPDATE channel set " . dbesc($k) . " = '" . dbesc($v) . "' where channel_id = " . intval($channel['channel_id']));
}
+ $r = dbq("UPDATE channel set " . dbesc($k) . " = '" . dbesc($v)
+ . "' where channel_id = " . intval($channel['channel_id']));
}
}
diff --git a/Zotlabs/Update/_1260.php b/Zotlabs/Update/_1260.php
new file mode 100644
index 000000000..ca30886c0
--- /dev/null
+++ b/Zotlabs/Update/_1260.php
@@ -0,0 +1,53 @@
+<?php
+namespace Zotlabs\Update;
+
+class _1260 {
+ public function run() {
+
+ $has_sodium = function_exists('sodium_crypto_sign_keypair');
+ $has_bcmath = function_exists('bcadd');
+ $has_gmp = function_exists('gmp_add');
+
+ if (!$has_sodium) {
+ return UPDATE_FAILED;
+ }
+
+ if (!($has_gmp || $has_bcmath)) {
+ hz_syslog('gothere');
+ return UPDATE_FAILED;
+ }
+
+ dbq("START TRANSACTION");
+
+ $r1 = dbq("ALTER TABLE channel ADD channel_epubkey text NOT NULL");
+ $r2 = dbq("ALTER TABLE channel ADD channel_eprvkey text NOT NULL");
+
+ $channels = dbq("select channel_id from channel where true");
+ if ($channels) {
+ foreach ($channels as $channel) {
+ $keys = sodium_crypto_sign_keypair();
+ $pubkey = sodium_bin2base64(sodium_crypto_sign_publickey($keys), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ $prvkey = sodium_bin2base64(sodium_crypto_sign_secretkey($keys), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ q("update channel set channel_epubkey = '%s', channel_eprvkey = '%s' where channel_id = %d",
+ dbesc($pubkey),
+ dbesc($prvkey),
+ intval($channel['channel_id'])
+ );
+ }
+ }
+
+ if ($r1 && $r2) {
+ dbq("COMMIT");
+ return UPDATE_SUCCESS;
+ }
+
+ dbq("ROLLBACK");
+ return UPDATE_FAILED;
+ }
+
+ public function verify() {
+ $columns = db_columns('channel');
+ return in_array('channel_epubkey', $columns) && in_array('channel_eprvkey', $columns);
+ }
+}
+
diff --git a/Zotlabs/Update/_1261.php b/Zotlabs/Update/_1261.php
new file mode 100644
index 000000000..da053a355
--- /dev/null
+++ b/Zotlabs/Update/_1261.php
@@ -0,0 +1,60 @@
+<?php
+namespace Zotlabs\Update;
+
+use Zotlabs\Lib\Multibase;
+
+class _1261 {
+ public function run() {
+
+ $has_sodium = function_exists('sodium_crypto_sign_keypair');
+ $has_bcmath = function_exists('bcadd');
+ $has_gmp = function_exists('gmp_add');
+
+ if (!$has_sodium) {
+ return UPDATE_FAILED;
+ }
+
+ if (!($has_gmp || $has_bcmath)) {
+ hz_syslog('gothere');
+
+ return UPDATE_FAILED;
+ }
+
+ dbq("START TRANSACTION");
+
+ $r1 = dbq("ALTER TABLE xchan ADD xchan_epubkey text NOT NULL");
+
+ if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
+ $r2 = dbq("ALTER TABLE xchan ADD xchan_updated timestamp NOT NULL DEFAULT '0001-01-01 00:00:00'");
+ }
+ else {
+ $r2 = dbq("ALTER TABLE xchan ADD xchan_updated datetime NOT NULL DEFAULT '0001-01-01 00:00:00'");
+ }
+
+ $channels = dbq("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))
+ );
+ }
+ }
+
+ if ($r1 && $r2) {
+ dbq("COMMIT");
+ return UPDATE_SUCCESS;
+ }
+
+ dbq("ROLLBACK");
+ return UPDATE_FAILED;
+
+ }
+
+ public function verify() {
+ $columns = db_columns('xchan');
+ return in_array('xchan_epubkey', $columns) && in_array('xchan_updated', $columns);
+ }
+}
+
diff --git a/boot.php b/boot.php
index a1528e58d..6f35fb55e 100644
--- a/boot.php
+++ b/boot.php
@@ -65,7 +65,7 @@ define('PLATFORM_NAME', 'hubzilla');
define('STD_VERSION', '8.9.1');
define('ZOT_REVISION', '6.0');
-define('DB_UPDATE_VERSION', 1259);
+define('DB_UPDATE_VERSION', 1261);
define('PROJECT_BASE', __DIR__);
diff --git a/include/channel.php b/include/channel.php
index 640274348..fc19d85ab 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -236,6 +236,10 @@ function create_identity($arr) {
$guid = Libzot::new_uid($nick);
$key = Crypto::new_keypair(4096);
+ $eckey = sodium_crypto_sign_keypair();
+ $ekey['pubkey'] = sodium_bin2base64(sodium_crypto_sign_publickey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ $ekey['prvkey'] = sodium_bin2base64(sodium_crypto_sign_secretkey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+
// zot6
$sig = Libzot::sign($guid,$key['prvkey']);
$hash = Libzot::make_xchan_hash($guid,$key['pubkey']);
@@ -275,6 +279,8 @@ function create_identity($arr) {
'channel_portable_id' => '',
'channel_prvkey' => $key['prvkey'],
'channel_pubkey' => $key['pubkey'],
+ 'channel_eprvkey' => $ekey['prvkey'],
+ 'channel_epubkey' => $ekey['pubkey'],
'channel_pageflags' => intval($pageflags),
'channel_system' => intval($system),
'channel_expire_days' => intval($expire),
@@ -370,6 +376,7 @@ function create_identity($arr) {
'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}",
diff --git a/include/import.php b/include/import.php
index 291dd2638..7dac518f5 100644
--- a/include/import.php
+++ b/include/import.php
@@ -80,6 +80,12 @@ function import_channel($channel, $account_id, $seize, $newname = '') {
}
}
+ if (empty($channel['channel_epubkey']) && empty($channel['channel_eprvkey'])) {
+ $eckey = sodium_crypto_sign_keypair();
+ $channel['channel_epubkey'] = sodium_bin2base64(sodium_crypto_sign_publickey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ $channel['channel_eprvkey'] = sodium_bin2base64(sodium_crypto_sign_secretkey($eckey), SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING);
+ }
+
unset($channel['channel_id']);
$channel['channel_account_id'] = $account_id;
$channel['channel_primary'] = (($seize) ? 1 : 0);
diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql
index b17b62962..c3f3b15ba 100644
--- a/install/schema_mysql.sql
+++ b/install/schema_mysql.sql
@@ -258,6 +258,8 @@ CREATE TABLE IF NOT EXISTS `channel` (
`channel_startpage` char(191) NOT NULL DEFAULT '',
`channel_pubkey` text NOT NULL,
`channel_prvkey` text NOT NULL,
+ `channel_epubkey` text NOT NULL,
+ `channel_eprvkey` text NOT NULL,
`channel_notifyflags` int(10) unsigned NOT NULL DEFAULT 65535,
`channel_pageflags` int(10) unsigned NOT NULL DEFAULT 0 ,
`channel_dirdate` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
@@ -1250,6 +1252,7 @@ CREATE TABLE IF NOT EXISTS `xchan` (
`xchan_guid` char(191) NOT NULL DEFAULT '',
`xchan_guid_sig` text NOT NULL,
`xchan_pubkey` text NOT NULL,
+ `xchan_epubkey` text NOT NULL,
`xchan_photo_mimetype` char(32) NOT NULL DEFAULT 'image/jpeg',
`xchan_photo_l` char(191) NOT NULL DEFAULT '',
`xchan_photo_m` char(191) NOT NULL DEFAULT '',
@@ -1265,6 +1268,7 @@ CREATE TABLE IF NOT EXISTS `xchan` (
`xchan_flags` int(10) unsigned NOT NULL DEFAULT 0 ,
`xchan_photo_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`xchan_name_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
+ `xchan_updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`xchan_hidden` tinyint(1) NOT NULL DEFAULT 0 ,
`xchan_orphan` tinyint(1) NOT NULL DEFAULT 0 ,
`xchan_censored` tinyint(1) NOT NULL DEFAULT 0 ,
diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql
index 42c65b171..90c6ab7ae 100644
--- a/install/schema_postgres.sql
+++ b/install/schema_postgres.sql
@@ -253,6 +253,8 @@ CREATE TABLE "channel" (
"channel_startpage" text NOT NULL DEFAULT '',
"channel_pubkey" text NOT NULL,
"channel_prvkey" text NOT NULL,
+ "channel_epubkey" text NOT NULL,
+ "channel_eprvkey" text NOT NULL,
"channel_notifyflags" bigint NOT NULL DEFAULT '65535',
"channel_pageflags" bigint NOT NULL DEFAULT '0',
"channel_dirdate" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
@@ -1239,8 +1241,9 @@ create index "vote_element" on vote ("vote_element");
CREATE TABLE "xchan" (
"xchan_hash" text NOT NULL,
"xchan_guid" text NOT NULL DEFAULT '',
- "xchan_guid_sig" text NOT NULL DEFAULT '',
- "xchan_pubkey" text NOT NULL DEFAULT '',
+ "xchan_guid_sig" text NOT NULL,
+ "xchan_pubkey" text NOT NULL,
+ "xchan_epubkey" text NOT NULL,
"xchan_photo_mimetype" text NOT NULL DEFAULT 'image/jpeg',
"xchan_photo_l" text NOT NULL DEFAULT '',
"xchan_photo_m" text NOT NULL DEFAULT '',
@@ -1256,6 +1259,7 @@ CREATE TABLE "xchan" (
"xchan_flags" bigint NOT NULL DEFAULT '0',
"xchan_photo_date" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"xchan_name_date" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
+ "xchan_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"xchan_hidden" smallint NOT NULL DEFAULT '0',
"xchan_orphan" smallint NOT NULL DEFAULT '0',
"xchan_censored" smallint NOT NULL DEFAULT '0',