use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Network\Probe;
+use Friendica\Util\Crypto;
use Friendica\Util\XML;
use dba;
$key = self::key($handle);
- $verify = rsa_verify($signable_data, $sig, $key);
+ $verify = Crypto::rsaVerify($signable_data, $sig, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
return false;
$author_addr = base64_decode($key_id);
$key = self::key($author_addr);
- $verify = rsa_verify($signed_data, $signature, $key);
+ $verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
http_status_exit(400);
http_status_exit(400);
}
- $verify = rsa_verify($signed_data, $signature, $key);
+ $verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
$key = self::key($msg["author"]);
- if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256")) {
+ if (!Crypto::rsaVerify($signed_data, $parent_author_signature, $key, "sha256")) {
logger("No valid parent author signature for parent author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$parent_author_signature, LOGGER_DEBUG);
return false;
}
$key = self::key($fields->author);
- if (!rsa_verify($signed_data, $author_signature, $key, "sha256")) {
+ if (!Crypto::rsaVerify($signed_data, $author_signature, $key, "sha256")) {
logger("No valid author signature for author ".$fields->author. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$author_signature, LOGGER_DEBUG);
return false;
} else {
// Check signature
$signed_text = 'AccountMigration:'.$old_handle.':'.$new_handle;
$key = self::key($old_handle);
- if (!rsa_verify($signed_text, $signature, $key, "sha256")) {
+ if (!Crypto::rsaVerify($signed_text, $signature, $key, "sha256")) {
logger('No valid signature for migration.');
return false;
}
// like on comments have the comment as parent. So we need to fetch the toplevel parent
if ($parent_item["id"] != $parent_item["parent"]) {
- $toplevel = dba::select('item', array('origin'), array('id' => $parent_item["parent"]), array('limit' => 1));
+ $toplevel = dba::selectFirst('item', ['origin'], ['id' => $parent_item["parent"]]);
$origin = $toplevel["origin"];
} else {
$origin = $parent_item["origin"];
$arr["last-child"] = 1;
- $user = dba::select('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]], ['limit' => 1]);
+ $user = dba::selectFirst('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]]);
$arr["allow_cid"] = $user["allow_cid"];
$arr["allow_gid"] = $user["allow_gid"];
self::fetchGuid($datarray);
$message_id = item_store($datarray);
+ self::sendParticipation($contact, $datarray);
+
if ($message_id) {
logger("Stored reshare ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return true;
while ($item = dba::fetch($r)) {
// Fetch the parent item
- $parent = dba::select('item', array('author-link', 'origin'), array('id' => $item["parent"]), array('limit' => 1));
+ $parent = dba::selectFirst('item', ['author-link', 'origin'], ['id' => $item["parent"]]);
// Only delete it if the parent author really fits
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
self::fetchGuid($datarray);
$message_id = item_store($datarray);
+ self::sendParticipation($contact, $datarray);
+
if ($message_id) {
logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return true;
$user['uprvkey'] = $user['prvkey'];
}
- $signature = rsa_sign($signable_data, $user["uprvkey"]);
+ $signature = Crypto::rsaSign($signable_data, $user["uprvkey"]);
$sig = base64url_encode($signature);
$xmldata = array("me:env" => array("me:data" => $data,
$signed_text = implode(";", $sigmsg);
- return base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
+ return base64_encode(Crypto::rsaSign($signed_text, $owner["uprvkey"], "sha256"));
}
/**
}
$logid = random_string(4);
- $dest_url = (($public_batch) ? $contact["batch"] : $contact["notify"]);
+ $dest_url = ($public_batch ? $contact["batch"] : $contact["notify"]);
+
+ // Fetch the fcontact entry when there is missing data
+ // Will possibly happen when data is transmitted to a DFRN contact
+ if (empty($dest_url) && !empty($contact['addr'])) {
+ $fcontact = self::personByHandle($contact['addr']);
+ $dest_url = ($public_batch ? $fcontact["batch"] : $fcontact["notify"]);
+ }
+
if (!$dest_url) {
logger("no url for contact: ".$contact["id"]." batch mode =".$public_batch);
return 0;
return $return_code;
}
+ /**
+ * @brief sends a participation (Used to get all further updates)
+ *
+ * @param array $contact Target of the communication
+ * @param array $item Item array
+ *
+ * @return int The result of the transmission
+ */
+ private static function sendParticipation($contact, $item)
+ {
+ // Don't send notifications for private postings
+ if ($item['private']) {
+ return;
+ }
+
+ $cachekey = "diaspora:sendParticipation:".$item['guid'];
+
+ $result = Cache::get($cachekey);
+ if (!is_null($result)) {
+ return;
+ }
+
+ // Fetch some user id to have a valid handle to transmit the participation.
+ // In fact it doesn't matter which user sends this - but it is needed by the protocol.
+ // If the item belongs to a user, we take this user id.
+ if ($item['uid'] == 0) {
+ $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
+ $first_user = dba::selectFirst('user', ['uid'], $condition);
+ $owner = User::getOwnerDataById($first_user['uid']);
+ } else {
+ $owner = User::getOwnerDataById($item['uid']);
+ }
+
+ $author = self::myHandle($owner);
+
+ $message = array("author" => $author,
+ "guid" => get_guid(32),
+ "parent_type" => "Post",
+ "parent_guid" => $item["guid"]);
+
+ logger("Send participation for ".$item["guid"]." by ".$author, LOGGER_DEBUG);
+
+ // It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item
+ Cache::set($cachekey, $item["guid"], CACHE_QUARTER_HOUR);
+
+ return self::buildAndTransmit($owner, $contact, "participation", $message);
+ }
+
/**
* @brief sends an account migration
*
$profile = self::createProfileData($uid);
$signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author'];
- $signature = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
+ $signature = base64_encode(Crypto::rsaSign($signed_text, $owner["uprvkey"], "sha256"));
$message = array("author" => $old_handle,
"profile" => $profile,