diff options
-rw-r--r-- | Zotlabs/Lib/Libsync.php | 24 | ||||
-rw-r--r-- | Zotlabs/Update/_1260.php | 58 | ||||
-rw-r--r-- | Zotlabs/Update/_1261.php | 58 | ||||
-rw-r--r-- | boot.php | 4 | ||||
-rw-r--r-- | include/channel.php | 7 | ||||
-rw-r--r-- | include/import.php | 6 | ||||
-rw-r--r-- | install/schema_mysql.sql | 4 | ||||
-rw-r--r-- | install/schema_postgres.sql | 10 |
8 files changed, 156 insertions, 15 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..7f91418f6 --- /dev/null +++ b/Zotlabs/Update/_1260.php @@ -0,0 +1,58 @@ +<?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)) { + return UPDATE_FAILED; + } + + dbq("START TRANSACTION"); + + if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + $r1 = dbq("ALTER TABLE channel ADD channel_epubkey text NOT NULL DEFAULT ''"); + $r2 = dbq("ALTER TABLE channel ADD channel_eprvkey text NOT NULL DEFAULT ''"); + } + else { + $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..43fd0b098 --- /dev/null +++ b/Zotlabs/Update/_1261.php @@ -0,0 +1,58 @@ +<?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)) { + return UPDATE_FAILED; + } + + dbq("START TRANSACTION"); + + if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + $r1 = dbq("ALTER TABLE xchan ADD xchan_epubkey text NOT NULL DEFAULT ''"); + $r2 = dbq("ALTER TABLE xchan ADD xchan_updated timestamp NOT NULL DEFAULT '0001-01-01 00:00:00'"); + } + else { + $r1 = dbq("ALTER TABLE xchan ADD xchan_epubkey text NOT NULL"); + $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); + } +} + @@ -62,10 +62,10 @@ require_once('include/conversation.php'); require_once('include/acl_selectors.php'); define('PLATFORM_NAME', 'hubzilla'); -define('STD_VERSION', '8.9.1'); +define('STD_VERSION', '8.9.2'); 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..789167938 100644 --- a/install/schema_postgres.sql +++ b/install/schema_postgres.sql @@ -244,15 +244,17 @@ CREATE TABLE "channel" ( "channel_name" text NOT NULL DEFAULT '', "channel_address" text NOT NULL DEFAULT '', "channel_guid" text NOT NULL DEFAULT '', - "channel_guid_sig" text NOT NULL, + "channel_guid_sig" text NOT NULL DEFAULT '', "channel_hash" text NOT NULL DEFAULT '', "channel_portable_id" text NOT NULL DEFAULT '', "channel_timezone" varchar(128) NOT NULL DEFAULT 'UTC', "channel_location" text NOT NULL DEFAULT '', "channel_theme" text NOT NULL DEFAULT '', "channel_startpage" text NOT NULL DEFAULT '', - "channel_pubkey" text NOT NULL, - "channel_prvkey" text NOT NULL, + "channel_pubkey" text NOT NULL DEFAULT '', + "channel_prvkey" text NOT NULL DEFAULT '', + "channel_epubkey" text NOT NULL DEFAULT '', + "channel_eprvkey" text NOT NULL DEFAULT '', "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', @@ -1241,6 +1243,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 '', @@ -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', |