Merge pull request #5933 from annando/diaspora-signature

Signed Diaspora posts should now be stored more reliable
This commit is contained in:
Hypolite Petovan 2018-10-15 18:12:45 -04:00 committed by GitHub
commit cbd49b641a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 32 deletions

View File

@ -41,7 +41,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily');
define('FRIENDICA_VERSION', '2018.12-dev');
define('DFRN_PROTOCOL_VERSION', '2.23');
define('DB_UPDATE_VERSION', 1286);
define('DB_UPDATE_VERSION', 1287);
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/**

View File

@ -254,6 +254,16 @@
"received": ["received"]
}
},
"diaspora-interaction": {
"comment": "Signed Diaspora Interaction",
"fields": {
"uri-id": {"type": "int unsigned", "not null": "1", "primary": "1", "relation": {"item-uri": "id"}, "comment": "Id of the item-uri table entry that contains the item uri"},
"interaction": {"type": "mediumtext", "comment": "The Diaspora interaction"}
},
"indexes": {
"PRIMARY": ["uri-id"]
}
},
"event": {
"comment": "Events",
"fields": {

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2018.12-dev (The Tazmans Flax-lily)
-- DB_UPDATE_VERSION 1285
-- DB_UPDATE_VERSION 1287
-- ------------------------------------------
@ -247,6 +247,15 @@ CREATE TABLE IF NOT EXISTS `conversation` (
INDEX `received` (`received`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Raw data and structure information for messages';
--
-- TABLE diaspora-interaction
--
CREATE TABLE IF NOT EXISTS `diaspora-interaction` (
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
`interaction` mediumtext COMMENT 'The Diaspora interaction',
PRIMARY KEY(`uri-id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Signed Diaspora Interaction';
--
-- TABLE event
--
@ -1242,12 +1251,14 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Creation date',
`pid` int unsigned NOT NULL DEFAULT 0 COMMENT 'Process id of the worker',
`executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Execution date',
`next_try` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Next retrial date',
`retrial` tinyint NOT NULL DEFAULT 0 COMMENT 'Retrial counter',
`done` boolean NOT NULL DEFAULT '0' COMMENT 'Marked 1 when the task was done - will be deleted later',
PRIMARY KEY(`id`),
INDEX `pid` (`pid`),
INDEX `parameter` (`parameter`(64)),
INDEX `priority_created` (`priority`,`created`),
INDEX `done_executed` (`done`,`executed`)
INDEX `priority_created_next_try` (`priority`,`created`,`next_try`),
INDEX `done_executed_next_try` (`done`,`executed`,`next_try`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries';

View File

@ -231,6 +231,10 @@ class Item extends BaseObject
}
}
if (array_key_exists('signed_text', $row) && array_key_exists('interaction', $row) && !is_null($row['interaction'])) {
$row['signed_text'] = $row['interaction'];
}
if (array_key_exists('ignored', $row) && array_key_exists('internal-user-ignored', $row) && !is_null($row['internal-user-ignored'])) {
$row['ignored'] = $row['internal-user-ignored'];
}
@ -242,6 +246,7 @@ class Item extends BaseObject
unset($row['internal-iaid']);
unset($row['internal-icid']);
unset($row['internal-user-ignored']);
unset($row['interaction']);
return $row;
}
@ -567,6 +572,8 @@ class Item extends BaseObject
$fields['sign'] = ['signed_text', 'signature', 'signer'];
$fields['diaspora-interaction'] = ['interaction'];
return $fields;
}
@ -653,6 +660,10 @@ class Item extends BaseObject
$joins .= " LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`";
}
if (strpos($sql_commands, "`diaspora-interaction`.") !== false) {
$joins .= " LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id`";
}
if (strpos($sql_commands, "`item-activity`.") !== false) {
$joins .= " LEFT JOIN `item-activity` ON `item-activity`.`id` = `item`.`iaid`";
}
@ -705,6 +716,10 @@ class Item extends BaseObject
$selected[] = 'internal-user-ignored';
}
if (in_array('signed_text', $selected)) {
$selected[] = 'interaction';
}
$selection = [];
foreach ($fields as $table => $table_fields) {
foreach ($table_fields as $field => $select) {
@ -1487,7 +1502,6 @@ class Item extends BaseObject
$deny_gid = '';
if ($item['parent-uri'] === $item['uri']) {
$diaspora_signed_text = '';
$parent_id = 0;
$parent_deleted = 0;
$allow_cid = $item['allow_cid'];
@ -1534,10 +1548,6 @@ class Item extends BaseObject
$item['wall'] = $parent['wall'];
$notify_type = 'comment-new';
if (!$parent['origin']) {
$diaspora_signed_text = '';
}
/*
* If the parent is private, force privacy for the entire conversation
* This differs from the above settings as it subtly allows comments from
@ -1578,7 +1588,6 @@ class Item extends BaseObject
$parent_id = 0;
$item['parent-uri'] = $item['uri'];
$item['gravity'] = GRAVITY_PARENT;
$diaspora_signed_text = '';
} else {
logger('item parent '.$item['parent-uri'].' for '.$item['uid'].' was not found - ignoring item');
return 0;
@ -1803,14 +1812,17 @@ class Item extends BaseObject
logger("Repaired double encoded signature from handle ".$dsprsig->signer, LOGGER_DEBUG);
}
DBA::insert('sign', ['iid' => $current_post, 'signed_text' => $dsprsig->signed_text,
'signature' => $dsprsig->signature, 'signer' => $dsprsig->signer]);
if (!empty($dsprsig->signed_text) && empty($dsprsig->signature) && empty($dsprsig->signer)) {
DBA::insert('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $dsprsig->signed_text], true);
} else {
// The other fields are used by very old Friendica servers, so we currently store them differently
DBA::insert('sign', ['iid' => $current_post, 'signed_text' => $dsprsig->signed_text,
'signature' => $dsprsig->signature, 'signer' => $dsprsig->signer]);
}
}
if (!empty($diaspora_signed_text)) {
// Formerly we stored the signed text, the signature and the author in different fields.
// We now store the raw data so that we are more flexible.
DBA::insert('sign', ['iid' => $current_post, 'signed_text' => $diaspora_signed_text]);
DBA::insert('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $diaspora_signed_text], true);
}
$deleted = self::tagDeliver($item['uid'], $current_post);

View File

@ -3749,13 +3749,13 @@ class Diaspora
*
* @return string The message
*/
private static function messageFromSignature(array $item, array $signature)
private static function messageFromSignature(array $item)
{
// Split the signed text
$signed_parts = explode(";", $signature['signed_text']);
$signed_parts = explode(";", $item['signed_text']);
if ($item["deleted"]) {
$message = ["author" => $signature['signer'],
$message = ["author" => $item['signer'],
"target_guid" => $signed_parts[0],
"target_type" => $signed_parts[1]];
} elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
@ -3764,7 +3764,7 @@ class Diaspora
"parent_guid" => $signed_parts[3],
"parent_type" => $signed_parts[2],
"positive" => $signed_parts[0],
"author_signature" => $signature['signature'],
"author_signature" => $item['signature'],
"parent_author_signature" => ""];
} else {
// Remove the comment guid
@ -3783,7 +3783,7 @@ class Diaspora
"guid" => $guid,
"parent_guid" => $parent_guid,
"text" => implode(";", $signed_parts),
"author_signature" => $signature['signature'],
"author_signature" => $item['signature'],
"parent_author_signature" => ""];
}
return $message;
@ -3811,20 +3811,12 @@ class Diaspora
logger("Got relayable data ".$type." for item ".$item["guid"]." (".$item["id"].")", LOGGER_DEBUG);
// fetch the original signature
$fields = ['signed_text', 'signature', 'signer'];
$signature = DBA::selectFirst('sign', $fields, ['iid' => $item["id"]]);
if (!DBA::isResult($signature)) {
logger("Couldn't fetch signatur for item ".$item["guid"]." (".$item["id"].")", LOGGER_DEBUG);
return false;
}
// Old way - is used by the internal Friendica functions
/// @todo Change all signatur storing functions to the new format
if ($signature['signed_text'] && $signature['signature'] && $signature['signer']) {
$message = self::messageFromSignature($item, $signature);
if ($item['signed_text'] && $item['signature'] && $item['signer']) {
$message = self::messageFromSignature($item);
} else {// New way
$msg = json_decode($signature['signed_text'], true);
$msg = json_decode($item['signed_text'], true);
$message = [];
if (is_array($msg)) {
@ -3841,7 +3833,7 @@ class Diaspora
$message[$field] = $data;
}
} else {
logger("Signature text for item ".$item["guid"]." (".$item["id"].") couldn't be extracted: ".$signature['signed_text'], LOGGER_DEBUG);
logger("Signature text for item ".$item["guid"]." (".$item["id"].") couldn't be extracted: ".$item['signed_text'], LOGGER_DEBUG);
}
}