salmon actually fetching remote keypairs
This commit is contained in:
parent
7c8031dc4b
commit
84d0c865c4
@ -102,6 +102,20 @@ class OStatusPlugin extends Plugin
|
|||||||
return true;
|
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
|
* Set up a PuSH hub link to our internal link for canonical timeline
|
||||||
* Atom feeds for users and groups.
|
* Atom feeds for users and groups.
|
||||||
|
@ -144,7 +144,7 @@ class OStatusInitAction extends Action
|
|||||||
$user = User::staticGet('nickname', $this->nickname);
|
$user = User::staticGet('nickname', $this->nickname);
|
||||||
$target_profile = common_local_url('userbyid', array('id' => $user->id));
|
$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_log(LOG_INFO, "Sending remote subscriber $acct to $url");
|
||||||
common_redirect($url, 303);
|
common_redirect($url, 303);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,6 @@ class Discovery
|
|||||||
|
|
||||||
foreach ($this->methods as $class) {
|
foreach ($this->methods as $class) {
|
||||||
$links = call_user_func(array($class, 'discover'), $uri);
|
$links = call_user_func(array($class, 'discover'), $uri);
|
||||||
|
|
||||||
if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
|
if ($link = Discovery::getService($links, Discovery::LRDD_REL)) {
|
||||||
// Load the LRDD XRD
|
// Load the LRDD XRD
|
||||||
if ($link['template']) {
|
if ($link['template']) {
|
||||||
@ -141,7 +140,7 @@ class Discovery
|
|||||||
}
|
}
|
||||||
|
|
||||||
return XRD::parse($response->getBody());
|
return XRD::parse($response->getBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Discovery_LRDD
|
interface Discovery_LRDD
|
||||||
@ -153,13 +152,12 @@ class Discovery_LRDD_Host_Meta implements Discovery_LRDD
|
|||||||
{
|
{
|
||||||
public function discover($uri)
|
public function discover($uri)
|
||||||
{
|
{
|
||||||
if (Discovery::isWebfinger($uri)) {
|
if (!Discovery::isWebfinger($uri)) {
|
||||||
// We have a webfinger acct: - start with host-meta
|
return false;
|
||||||
list($name, $domain) = explode('@', $id);
|
|
||||||
} else {
|
|
||||||
$domain = @parse_url($uri, PHP_URL_HOST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have a webfinger acct: - start with host-meta
|
||||||
|
list($name, $domain) = explode('@', $uri);
|
||||||
$url = 'http://'. $domain .'/.well-known/host-meta';
|
$url = 'http://'. $domain .'/.well-known/host-meta';
|
||||||
|
|
||||||
$xrd = Discovery::fetchXrd($url);
|
$xrd = Discovery::fetchXrd($url);
|
||||||
@ -180,27 +178,29 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$response = $client->get($url);
|
$response = $client->get($uri);
|
||||||
} catch (HTTP_Request2_Exception $e) {
|
} catch (HTTP_Request2_Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($response->getStatus() != 200) {
|
if ($response->getStatus() != 200) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link_header = $response->getHeader('Link');
|
$link_header = $response->getHeader('Link');
|
||||||
if (!$link_header) {
|
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)
|
protected static function parseHeader($header)
|
||||||
{
|
{
|
||||||
preg_match('/^<[^>]+>/', $header, $uri_reference);
|
preg_match('/^<[^>]+>/', $header, $uri_reference);
|
||||||
if (empty($uri_reference)) return;
|
//if (empty($uri_reference)) return;
|
||||||
|
|
||||||
|
$links = array();
|
||||||
|
|
||||||
$link_uri = trim($uri_reference[0], '<>');
|
$link_uri = trim($uri_reference[0], '<>');
|
||||||
$link_rel = array();
|
$link_rel = array();
|
||||||
@ -210,7 +210,7 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
|
|||||||
$header = substr($header, strlen($uri_reference[0]));
|
$header = substr($header, strlen($uri_reference[0]));
|
||||||
|
|
||||||
// parse link-params
|
// parse link-params
|
||||||
$params = explode($header, ';');
|
$params = explode(';', $header);
|
||||||
|
|
||||||
foreach ($params as $param) {
|
foreach ($params as $param) {
|
||||||
if (empty($param)) continue;
|
if (empty($param)) continue;
|
||||||
@ -229,11 +229,13 @@ class Discovery_LRDD_Link_Header implements Discovery_LRDD
|
|||||||
$link_type = trim($param_value);
|
$link_type = trim($param_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
$links[] = array(
|
||||||
'href' => $link_uri,
|
'href' => $link_uri,
|
||||||
'rel' => $link_rel,
|
'rel' => $link_rel,
|
||||||
'type' => $link_type);
|
'type' => $link_type);
|
||||||
|
|
||||||
|
return $links;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +245,7 @@ class Discovery_LRDD_Link_HTML implements Discovery_LRDD
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$response = $client->get($url);
|
$response = $client->get($uri);
|
||||||
} catch (HTTP_Request2_Exception $e) {
|
} catch (HTTP_Request2_Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -52,14 +52,13 @@ class MagicEnvelope
|
|||||||
{
|
{
|
||||||
$disco = new Discovery();
|
$disco = new Discovery();
|
||||||
|
|
||||||
$links = $disco->lookup($signer_uri);
|
$xrd = $disco->lookup($signer_uri);
|
||||||
if ($link = Discovery::getService($links, 'magic-public-key')) {
|
if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) {
|
||||||
list($type, $keypair) = explode(';', $link['href']);
|
list($type, $keypair) = explode(';', $link['href']);
|
||||||
return $keypair;
|
return $keypair;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('Unable to locate signer public key');
|
throw new Exception('Unable to locate signer public key');
|
||||||
//return 'RSA.79_L2gq-TD72Nsb5yGS0r9stLLpJZF5AHXyxzWmQmlqKl276LEJEs8CppcerLcR90MbYQUwt-SX9slx40Yq3vA==.AQAB.AR-jo5KMfSISmDAT2iMs2_vNFgWRjl5rbJVvA0SpGIEWyPdCGxlPtCbTexp8-0ZEIe8a4SyjatBECH5hxgMTpw==';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user