public function getKeyPair($signer_uri) { $disco = new Discovery(); try { $xrd = $disco->lookup($signer_uri); } catch (Exception $e) { return false; } if ($xrd->links) { if ($link = Discovery::getService($xrd->links, Magicsig::PUBLICKEYREL)) { $keypair = false; $parts = explode(',', $link['href']); if (count($parts) == 2) { $keypair = $parts[1]; } else { // Backwards compatibility check for separator bug in 0.9.0 $parts = explode(';', $link['href']); if (count($parts) == 2) { $keypair = $parts[1]; } } if ($keypair) { return $keypair; } } } throw new Exception('Unable to locate signer public key'); }
/** * This implements the actual lookup procedure */ public function lookup($id) { // Normalize the incoming $id to make sure we have a uri $uri = $this->normalize($id); 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 (!empty($link['template'])) { $xrd_uri = Discovery::applyTemplate($link['template'], $uri); } else { $xrd_uri = $link['href']; } $xrd = $this->fetchXrd($xrd_uri); if ($xrd) { return $xrd; } } } throw new Exception('Unable to find services for ' . $id); }
/** * Given a user ID, return the first available resource descriptor * * @param string $id User ID URI * * @return XML_XRD object for the resource descriptor of the id */ public function lookup($id) { // Normalize the incoming $id to make sure we have a uri $uri = self::normalize($id); foreach ($this->methods as $class) { try { $xrd = new XML_XRD(); common_debug("LRDD discovery method for '{$uri}': {$class}"); $lrdd = new $class(); $links = call_user_func(array($lrdd, 'discover'), $uri); $link = Discovery::getService($links, Discovery::LRDD_REL); // Load the LRDD XRD if (!empty($link->template)) { $xrd_uri = Discovery::applyTemplate($link->template, $uri); } elseif (!empty($link->href)) { $xrd_uri = $link->href; } else { throw new Exception('No resource descriptor URI in link.'); } $client = new HTTPClient(); $headers = array(); if (!is_null($link->type)) { $headers[] = "Accept: {$link->type}"; } $response = $client->get($xrd_uri, $headers); if ($response->getStatus() != 200) { throw new Exception('Unexpected HTTP status code.'); } $xrd->loadString($response->getBody()); return $xrd; } catch (Exception $e) { continue; } } // TRANS: Exception. %s is an ID. throw new Exception(sprintf(_('Unable to find services for %s.'), $id)); }