diff --git a/plugins/Diaspora/DiasporaPlugin.php b/plugins/Diaspora/DiasporaPlugin.php new file mode 100644 index 0000000000..1490fce7a3 --- /dev/null +++ b/plugins/Diaspora/DiasporaPlugin.php @@ -0,0 +1,57 @@ +. + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * Diaspora federation protocol plugin for GNU Social + * + * Depends on: + * - OStatus plugin + * - WebFinger plugin + * + * @package ProtocolDiasporaPlugin + * @maintainer Mikael Nordfeldth + */ + +class DiasporaPlugin extends Plugin +{ + const REL_SEED_LOCATION = 'http://joindiaspora.com/seed_location'; + const REL_GUID = 'http://joindiaspora.com/guid'; + const REL_PUBLIC_KEY = 'diaspora-public-key'; + + public function onEndAttachPubkeyToUserXRD(Magicsig $magicsig, XML_XRD $xrd, Profile $target) + { + $xrd->links[] = new XML_XRD_Element_Link(self::REL_PUBLIC_KEY, + base64_encode($magicsig->exportPublicKey())); + } + + public function onPluginVersion(array &$versions) + { + $versions[] = array('name' => 'Diaspora', + 'version' => '0.1', + 'author' => 'Mikael Nordfeldth', + 'homepage' => 'https://gnu.io/social', + // TRANS: Plugin description. + 'rawdescription' => _m('Follow people across social networks that implement '. + 'the Diaspora federation protocol.')); + + return true; + } +} diff --git a/plugins/OStatus/EVENTS.txt b/plugins/OStatus/EVENTS.txt new file mode 100644 index 0000000000..766b7513a3 --- /dev/null +++ b/plugins/OStatus/EVENTS.txt @@ -0,0 +1,7 @@ +StartAttachPubkeyToUserXRD: Runs only for XRD generation where a Magicsig exists for a Profile which is a "person". +@param Magicsig $magicsig crypto stuff related to the profile we're representing +@param XRD $xrd the XRD object which holds all data for the profile we're representing + +EndAttachPubkeyToUserXRD: Runs only for XRD generation where a Magicsig exists for a Profile which is a "person". And only if StartAttachPubkeyToUserXRD didn't abort. +@param Magicsig $magicsig crypto stuff related to the profile we're representing +@param XRD $xrd the XRD object which holds all data for the profile we're representing diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 774a13be82..ba50cb653d 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -1315,11 +1315,14 @@ class OStatusPlugin extends Plugin $magicsig = Magicsig::generate($target->getUser()); } - if ($magicsig instanceof Magicsig) { + if (!$magicsig instanceof Magicsig) { + return false; // value doesn't mean anything, just figured I'd indicate this function didn't do anything + } + if (Event::handle('StartAttachPubkeyToUserXRD', array($magicsig, $xrd, $target))) { $xrd->links[] = new XML_XRD_Element_Link(Magicsig::PUBLICKEYREL, 'data:application/magic-public-key,'. $magicsig->toString()); - $xrd->links[] = new XML_XRD_Element_Link(Magicsig::DIASPORA_PUBLICKEYREL, - base64_encode($magicsig->exportPublicKey())); + // The following event handles plugins like Diaspora which add their own version of the Magicsig pubkey + Event::handle('EndAttachPubkeyToUserXRD', array($magicsig, $xrd, $target)); } } diff --git a/plugins/OStatus/classes/Magicsig.php b/plugins/OStatus/classes/Magicsig.php index 8d2bb4eac9..42a11533b7 100644 --- a/plugins/OStatus/classes/Magicsig.php +++ b/plugins/OStatus/classes/Magicsig.php @@ -36,7 +36,6 @@ require_once 'Crypt/RSA.php'; class Magicsig extends Managed_DataObject { const PUBLICKEYREL = 'magic-public-key'; - const DIASPORA_PUBLICKEYREL = 'diaspora-public-key'; const DEFAULT_KEYLEN = 1024; const DEFAULT_SIGALG = 'RSA-SHA256';