]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Only use a Profile in MagicEnvelope keypair retrieval
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Jun 2014 14:11:46 +0000 (16:11 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Jun 2014 14:12:26 +0000 (16:12 +0200)
So we _know_ there is a profile for the submitter we're about to verify.

plugins/OStatus/lib/magicenvelope.php

index e61a04b9326d8b6991ba086a412ce6ed26d5939b..9010ab71377c250ef8ad875beb7436c91908fda2 100644 (file)
@@ -69,11 +69,7 @@ class MagicEnvelope
     public function getKeyPair(Profile $profile, $discovery=false) {
         $magicsig = Magicsig::getKV('user_id', $profile->id);
         if ($discovery && !$magicsig instanceof Magicsig) {
-            $signer_uri = $profile->getUri();
-            if (empty($signer_uri)) {
-                throw new ServerException(sprintf('Profile missing URI (id==%d)', $profile->id));
-            }
-            $magicsig = $this->discoverKeyPair($signer_uri);
+            $magicsig = $this->discoverKeyPair($profile);
             // discoverKeyPair should've thrown exception if it failed
             assert($magicsig instanceof Magicsig);
         } elseif (!$magicsig instanceof Magicsig) { // No discovery request, so we'll give up.
@@ -87,8 +83,13 @@ class MagicEnvelope
      *
      * @return Magicsig with loaded keypair
      */
-    public function discoverKeyPair($signer_uri)
+    public function discoverKeyPair(Profile $profile)
     {
+        $signer_uri = $profile->getUri();
+        if (empty($signer_uri)) {
+            throw new ServerException(sprintf('Profile missing URI (id==%d)', $profile->id));
+        }
+
         $disco = new Discovery();
 
         // Throws exception on lookup problems
@@ -269,12 +270,7 @@ class MagicEnvelope
         }
 
         try {
-            if ($profile instanceof Profile) {
-                $magicsig = $this->getKeyPair($profile, true);    // Do discovery too if necessary
-            } else {
-                $signer_uri = $this->getAuthorUri();
-                $magicsig = $this->discoverKeyPair($signer_uri);
-            }
+            $magicsig = $this->getKeyPair($profile, true);    // Do discovery too if necessary
         } catch (Exception $e) {
             common_log(LOG_DEBUG, "Salmon error: ".$e->getMessage());
             return false;