diff options
author | Mario <mario@mariovavti.com> | 2024-01-07 19:58:09 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-01-07 19:58:09 +0000 |
commit | 87775ae37ad7f8226f7413d28e96fd23967c7659 (patch) | |
tree | 330126a1fca83e4297b8b1d2d206b3940dbd7341 /Zotlabs | |
parent | 256b66de41b2cd8dcdeb39fc5f080c5ff957e5d2 (diff) | |
download | volse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.tar.gz volse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.tar.bz2 volse-hubzilla-87775ae37ad7f8226f7413d28e96fd23967c7659.zip |
ekey and xchan_updated updates
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Lib/Libsync.php | 24 | ||||
-rw-r--r-- | Zotlabs/Update/_1260.php | 53 | ||||
-rw-r--r-- | Zotlabs/Update/_1261.php | 60 |
3 files changed, 127 insertions, 10 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); + } +} + |