X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Flib%2Fsalmonaction.php;h=2f48042820ba9add9c411afd7e761eac64a2ebeb;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hp=eb68632d38ff3f5e4821f530803ef6d6c07bbd2f;hpb=b8bca62e3b4b139fac5d1bb69bf683882b799d86;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/lib/salmonaction.php b/plugins/OStatus/lib/salmonaction.php index eb68632d38..2f48042820 100644 --- a/plugins/OStatus/lib/salmonaction.php +++ b/plugins/OStatus/lib/salmonaction.php @@ -37,17 +37,31 @@ class SalmonAction extends Action protected function prepare(array $args=array()) { - StatusNet::setApi(true); // Send smaller error pages + GNUsocial::setApi(true); // Send smaller error pages parent::prepare($args); - if (!isset($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') { - // TRANS: Client error. Do not translate "application/magic-envelope+xml". - $this->clientError(_m('Salmon requires "application/magic-envelope+xml".')); + if (!isset($_SERVER['CONTENT_TYPE'])) { + // TRANS: Client error. Do not translate "Content-type" + $this->clientError(_m('Salmon requires a Content-type header.')); + } + $envxml = null; + switch ($_SERVER['CONTENT_TYPE']) { + case 'application/magic-envelope+xml': + $envxml = file_get_contents('php://input'); + break; + case 'application/x-www-form-urlencoded': + $envxml = Magicsig::base64_url_decode($this->trimmed('xml')); + break; + default: + // TRANS: Client error. Do not translate the quoted "application/[type]" strings. + $this->clientError(_m('Salmon requires "application/magic-envelope+xml". For Diaspora we also accept "application/x-www-form-urlencoded" with an "xml" parameter.', 415)); } try { - $envxml = file_get_contents('php://input'); + if (empty($envxml)) { + throw new ClientException('No magic envelope supplied in POST.'); + } $magic_env = new MagicEnvelope($envxml); // parse incoming XML as a MagicEnvelope $entry = $magic_env->getPayload(); // Not cryptographically verified yet! @@ -65,12 +79,8 @@ class SalmonAction extends Action $this->clientError($e->getMessage()); } - // Cryptographic verification test - if (!$magic_env->verify($this->actor)) { - common_debug("Salmon signature verification failed."); - // TRANS: Client error. - $this->clientError(_m('Salmon signature verification failed.')); - } + // Cryptographic verification test, throws exception on failure + $magic_env->verify($this->actor); return true; } @@ -245,7 +255,7 @@ class SalmonAction extends Action // Step 4: Is the newly introduced https://example.com/user/1 URI in the list of aliases // presented by http://example.com/user/1 (i.e. do they both say they are the same identity?) if (in_array($e->object_uri, $doublecheck_aliases)) { - common_debug('These identities both say they are each other: "'.$aliased_uri.'" and "'.$e->object_uri); + $oprofile->updateUriKeys($e->object_uri, DiscoveryHints::fromXRD($xrd)); $this->oprofile = $oprofile; break; // don't iterate through aliases anymore } @@ -267,7 +277,7 @@ class SalmonAction extends Action function saveNotice() { if (!$this->oprofile instanceof Ostatus_profile) { - common_debug('Ostatus_profile missing in ' . get_class(). ' profile: '.var_export($this->profile)); + common_debug('Ostatus_profile missing in ' . get_class(). ' profile: '.var_export($this->profile, true)); } return $this->oprofile->processPost($this->activity, 'salmon'); }