]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/magicenvelope.php
Merge branch 'profile' into 'nightly'
[quix0rs-gnu-social.git] / plugins / OStatus / lib / magicenvelope.php
index 6786bfa298a650e34ef4e3e1fd6478ebe31a6190..48b88a2d5fc071759ed7224129afc7fb414621ea 100644 (file)
@@ -97,7 +97,7 @@ class MagicEnvelope
             throw new ServerException(sprintf('No public key found for profile (id==%d)', $profile->id));
         }
 
-        assert($magicsig->publicKey instanceof Crypt_RSA);
+        assert($magicsig->publicKey instanceof \phpseclib\Crypt\RSA);
 
         return $magicsig;
     }
@@ -107,7 +107,7 @@ class MagicEnvelope
      * you'll only get the public key ;)
      *
      * The string will (hopefully) be formatted as described in Magicsig specification:
-     * https://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-01.html#anchor13
+     * https://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-magicsig-01.html
      *
      * @return string formatted as Magicsig keypair
      */
@@ -156,7 +156,7 @@ class MagicEnvelope
         }
 
         if ($keypair === false) {
-            // For debugging clarity. Keypair did not pass count()-check above. 
+            // For debugging clarity. Keypair did not pass count()-check above.
             // TRANS: Exception when public key was not properly formatted.
             throw new Exception(_m('Incorrectly formatted public key element.'));
         }
@@ -203,7 +203,7 @@ class MagicEnvelope
             $magicsig = Magicsig::generate($this->actor->getUser());
         }
         assert($magicsig instanceof Magicsig);
-        assert($magicsig->privateKey instanceof Crypt_RSA);
+        assert($magicsig->privateKey instanceof \phpseclib\Crypt\RSA);
 
         // Prepare text and metadata for signing
         $this->data = Magicsig::base64_url_encode($text);
@@ -250,7 +250,7 @@ class MagicEnvelope
     {
         $dom = new DOMDocument();
         if (!$dom->loadXML(Magicsig::base64_url_decode($this->data))) {
-            throw new ServerException('Malformed XML in Salmon payload');
+            throw new ClientException('Malformed XML in Salmon payload');
         }
 
         switch ($this->data_type) {
@@ -270,11 +270,11 @@ class MagicEnvelope
             $prov->appendChild($alg);
             $sig = $dom->createElementNS(self::NS, 'me:sig', $this->getSignature());
             $prov->appendChild($sig);
-    
+
             $dom->documentElement->appendChild($prov);
             break;
         default:
-            throw new ServerException('Unknown Salmon payload data type');
+            throw new ClientException('Unknown Salmon payload data type');
         }
         return $dom;
     }
@@ -340,26 +340,28 @@ class MagicEnvelope
     public function verify(Profile $profile)
     {
         if ($this->alg != 'RSA-SHA256') {
-            common_log(LOG_DEBUG, "Salmon error: bad algorithm");
+            common_log(LOG_DEBUG, 'Salmon error: bad algorithm: '._ve($this->alg));
             return false;
         }
 
         if ($this->encoding != self::ENCODING) {
-            common_log(LOG_DEBUG, "Salmon error: bad encoding");
+            common_log(LOG_DEBUG, 'Salmon error: bad encoding: '._ve($this->encoding));
             return false;
         }
 
         try {
             $magicsig = $this->getKeyPair($profile, true);    // Do discovery too if necessary
         } catch (Exception $e) {
-            common_log(LOG_DEBUG, "Salmon error: ".$e->getMessage());
+            common_log(LOG_DEBUG, "Salmon error: getKeyPair for profile id=={$profile->getID()}: "._ve($e->getMessage()));
             return false;
         }
 
         if (!$magicsig->verify($this->signingText(), $this->getSignature())) {
+            common_log(LOG_INFO, 'Salmon signature verification failed for profile id=='.$profile->getID());
             // TRANS: Client error when incoming salmon slap signature does not verify cryptographically.
             throw new ClientException(_m('Salmon signature verification failed.'));
         }
+        common_debug('Salmon signature verification successful for profile id=='.$profile->getID());
         $this->setActor($profile);
         return true;
     }