forked from GNUsocial/gnu-social
Improve debugging for Salmon slaps
This commit is contained in:
parent
d534ea7bd6
commit
993ad00333
@ -251,11 +251,12 @@ class MagicEnvelope
|
|||||||
*
|
*
|
||||||
* Details of failure conditions are dumped to output log and not exposed to caller.
|
* Details of failure conditions are dumped to output log and not exposed to caller.
|
||||||
*
|
*
|
||||||
* @param Profile $profile optional profile used to get locally cached public signature key.
|
* @param Profile $profile profile used to get locally cached public signature key
|
||||||
|
* or if necessary perform discovery on.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function verify(Profile $profile=null)
|
public function verify(Profile $profile)
|
||||||
{
|
{
|
||||||
if ($this->alg != 'RSA-SHA256') {
|
if ($this->alg != 'RSA-SHA256') {
|
||||||
common_log(LOG_DEBUG, "Salmon error: bad algorithm");
|
common_log(LOG_DEBUG, "Salmon error: bad algorithm");
|
||||||
|
@ -28,8 +28,6 @@ class SalmonAction extends Action
|
|||||||
{
|
{
|
||||||
protected $needPost = true;
|
protected $needPost = true;
|
||||||
|
|
||||||
protected $verified = false;
|
|
||||||
|
|
||||||
var $xml = null;
|
var $xml = null;
|
||||||
var $activity = null;
|
var $activity = null;
|
||||||
var $target = null;
|
var $target = null;
|
||||||
@ -45,21 +43,20 @@ class SalmonAction extends Action
|
|||||||
$this->clientError(_m('Salmon requires "application/magic-envelope+xml".'));
|
$this->clientError(_m('Salmon requires "application/magic-envelope+xml".'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$envxml = file_get_contents('php://input');
|
|
||||||
$magic_env = new MagicEnvelope($envxml); // parse incoming XML as a MagicEnvelope
|
|
||||||
|
|
||||||
$entry = $magic_env->getPayload(); // Not cryptographically verified yet!
|
|
||||||
$this->activity = new Activity($entry->documentElement);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$profile = Profile::fromUri($this->activity->actor->id);
|
$envxml = file_get_contents('php://input');
|
||||||
$this->verified = $magic_env->verify($profile);
|
$magic_env = new MagicEnvelope($envxml); // parse incoming XML as a MagicEnvelope
|
||||||
} catch (UnknownUriException $e) {
|
|
||||||
// If we don't know the profile, perform some discovery instead
|
$entry = $magic_env->getPayload(); // Not cryptographically verified yet!
|
||||||
$this->verified = $magic_env->verify();
|
$this->activity = new Activity($entry->documentElement);
|
||||||
|
$oprofile = $this->ensureProfile();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_debug('Salmon envelope parsing failed with: '.$e->getMessage());
|
||||||
|
$this->clientError($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->verified) {
|
// Cryptographic verification test
|
||||||
|
if (!$magic_env->verify($oprofile->localProfile())) {
|
||||||
common_log(LOG_DEBUG, "Salmon signature verification failed.");
|
common_log(LOG_DEBUG, "Salmon signature verification failed.");
|
||||||
// TRANS: Client error.
|
// TRANS: Client error.
|
||||||
$this->clientError(_m('Salmon signature verification failed.'));
|
$this->clientError(_m('Salmon signature verification failed.'));
|
||||||
|
@ -60,7 +60,9 @@ print "\n\n";
|
|||||||
|
|
||||||
echo "== Testing local verification ==\n\n";
|
echo "== Testing local verification ==\n\n";
|
||||||
$magic_env = new MagicEnvelope($envxml);
|
$magic_env = new MagicEnvelope($envxml);
|
||||||
$ok = $magic_env->verify();
|
$activity = new Activity($magic_env->getPayload()->documentElement);
|
||||||
|
$profile = Profile::fromUri($activity->actor->id);
|
||||||
|
$ok = $magic_env->verify($profile);
|
||||||
if ($ok) {
|
if ($ok) {
|
||||||
print "OK\n\n";
|
print "OK\n\n";
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user