Exemple #1
0
 function prepare($args)
 {
     StatusNet::setApi(true);
     // Send smaller error pages
     parent::prepare($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_m('This method requires a POST.'));
     }
     if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') {
         $this->clientError(_m('Salmon requires application/magic-envelope+xml'));
     }
     $xml = file_get_contents('php://input');
     // Check the signature
     $salmon = new Salmon();
     if (!$salmon->verifyMagicEnv($xml)) {
         common_log(LOG_DEBUG, "Salmon signature verification failed.");
         $this->clientError(_m('Salmon signature verification failed.'));
     } else {
         $magic_env = new MagicEnvelope();
         $env = $magic_env->parse($xml);
         $xml = $magic_env->unfold($env);
     }
     $dom = DOMDocument::loadXML($xml);
     if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') {
         common_log(LOG_DEBUG, "Got invalid Salmon post: {$xml}");
         $this->clientError(_m('Salmon post must be an Atom entry.'));
     }
     $this->act = new Activity($dom->documentElement);
     return true;
 }
Exemple #2
0
    exit(1);
}
$notice_id = get_option_value('--notice');
$notice = Notice::staticGet('id', $notice_id);
$profile = $notice->getProfile();
$entry = $notice->asAtomEntry(true);
echo "== Original entry ==\n\n";
print $entry;
print "\n\n";
$salmon = new Salmon();
$envelope = $salmon->createMagicEnv($entry, $profile);
echo "== Signed envelope ==\n\n";
print $envelope;
print "\n\n";
echo "== Testing local verification ==\n\n";
$ok = $salmon->verifyMagicEnv($envelope);
if ($ok) {
    print "OK\n\n";
} else {
    print "FAIL\n\n";
}
if (have_option('--verify')) {
    $url = 'http://www.madebymonsieur.com/ostatus_discovery/magic_env/validate/';
    echo "== Testing remote verification ==\n\n";
    print "Sending for verification to {$url} ...\n";
    $client = new HTTPClient();
    $response = $client->post($url, array(), array('magic_env' => $envelope));
    print $response->getStatus() . "\n\n";
    print $response->getBody() . "\n\n";
}
if (have_option('--slap')) {