salmon actually fetching remote keypairs

This commit is contained in:
James Walker 2010-02-26 03:25:51 -05:00
parent 7c8031dc4b
commit 84d0c865c4
4 changed files with 35 additions and 20 deletions

View File

@ -102,6 +102,20 @@ class OStatusPlugin extends Plugin
return true;
}
/**
* Add a link header for LRDD Discovery
*/
function onStartShowHTML($action)
{
if ($action instanceof ShowstreamAction) {
$acct = 'acct:'. $action->profile->nickname .'@'. common_config('site', 'server');
$url = common_local_url('xrd');
$url.= '?uri='. $acct;
header('Link: <'.$url.'>; rel="'. Discovery::LRDD_REL.'"; type="application/xrd+xml"');
}
}
/**
* Set up a PuSH hub link to our internal link for canonical timeline
* Atom feeds for users and groups.

View File

@ -144,7 +144,7 @@ class OStatusInitAction extends Action
$user = User::staticGet('nickname', $this->nickname);
$target_profile = common_local_url('userbyid', array('id' => $user->id));
$url = $w->applyTemplate($link['template'], $target_profile);
$url = Discovery::applyTemplate($link['template'], $target_profile);
common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
common_redirect($url, 303);
}

View File

@ -91,7 +91,6 @@ class Discovery
foreach ($this->methods as $class) {
$links = call_user_func(array($class, 'discover'), $uri);
if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
// Load the LRDD XRD
if ($link['template']) {
@ -153,13 +152,12 @@ class Discovery_LRDD_Host_Meta implements Discovery_LRDD
{
public function discover($uri)
{
if (Discovery::isWebfinger($uri)) {
// We have a webfinger acct: - start with host-meta
list($name, $domain) = explode('@', $id);
} else {
$domain = @parse_url($uri, PHP_URL_HOST);
if (!Discovery::isWebfinger($uri)) {
return false;
}
// We have a webfinger acct: - start with host-meta
list($name, $domain) = explode('@', $uri);
$url = 'http://'. $domain .'/.well-known/host-meta';
$xrd = Discovery::fetchXrd($url);
@ -180,7 +178,7 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
{
try {
$client = new HTTPClient();
$response = $client->get($url);
$response = $client->get($uri);
} catch (HTTP_Request2_Exception $e) {
return false;
}
@ -191,16 +189,18 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
$link_header = $response->getHeader('Link');
if (!$link_header) {
return false;
// return false;
}
return Discovery_LRDD_Link_Header::parseHeader($header);
return Discovery_LRDD_Link_Header::parseHeader($link_header);
}
protected static function parseHeader($header)
{
preg_match('/^<[^>]+>/', $header, $uri_reference);
if (empty($uri_reference)) return;
//if (empty($uri_reference)) return;
$links = array();
$link_uri = trim($uri_reference[0], '<>');
$link_rel = array();
@ -210,7 +210,7 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
$header = substr($header, strlen($uri_reference[0]));
// parse link-params
$params = explode($header, ';');
$params = explode(';', $header);
foreach ($params as $param) {
if (empty($param)) continue;
@ -230,10 +230,12 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
}
}
return array(
$links[] = array(
'href' => $link_uri,
'rel' => $link_rel,
'type' => $link_type);
return $links;
}
}
@ -243,7 +245,7 @@ class Discovery_LRDD_Link_HTML implements Discovery_LRDD
{
try {
$client = new HTTPClient();
$response = $client->get($url);
$response = $client->get($uri);
} catch (HTTP_Request2_Exception $e) {
return false;
}

View File

@ -52,14 +52,13 @@ class MagicEnvelope
{
$disco = new Discovery();
$links = $disco->lookup($signer_uri);
if ($link = Discovery::getService($links, 'magic-public-key')) {
$xrd = $disco->lookup($signer_uri);
if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
list($type, $keypair) = explode(';', $link['href']);
return $keypair;
}
throw new Exception('Unable to locate signer public key');
//return 'RSA.79_L2gq-TD72Nsb5yGS0r9stLLpJZF5AHXyxzWmQmlqKl276LEJEs8CppcerLcR90MbYQUwt-SX9slx40Yq3vA==.AQAB.AR-jo5KMfSISmDAT2iMs2_vNFgWRjl5rbJVvA0SpGIEWyPdCGxlPtCbTexp8-0ZEIe8a4SyjatBECH5hxgMTpw==';
}