]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPSignature.php
Fix not working unarchive contact batch action
[friendica.git] / src / Util / HTTPSignature.php
index 494d6e0e65a2761692f7f2bbc677fbb6db29942b..408f4d978941e21bf42d023bef0b5a569e266cf3 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Util;
 
 use Friendica\BaseObject;
 use Friendica\Core\Config;
+use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\Model\User;
 use Friendica\Model\APContact;
@@ -59,7 +60,7 @@ class HTTPSignature
                $sig_block = self::parseSigheader($headers['authorization']);
 
                if (!$sig_block) {
-                       logger('no signature provided.');
+                       Logger::log('no signature provided.');
                        return $result;
                }
 
@@ -89,7 +90,7 @@ class HTTPSignature
                        $key = $key($sig_block['keyId']);
                }
 
-               logger('Got keyID ' . $sig_block['keyId']);
+               Logger::log('Got keyID ' . $sig_block['keyId']);
 
                if (!$key) {
                        return $result;
@@ -97,7 +98,7 @@ class HTTPSignature
 
                $x = Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm);
 
-               logger('verified: ' . $x, LOGGER_DEBUG);
+               Logger::log('verified: ' . $x, Logger::DEBUG);
 
                if (!$x) {
                        return $result;
@@ -272,9 +273,11 @@ class HTTPSignature
        /**
         * @brief Transmit given data to a target for a user
         *
-        * @param $data
-        * @param $target
-        * @param $uid
+        * @param array $data Data that is about to be send
+        * @param string $target The URL of the inbox
+        * @param integer $uid User id of the sender
+        *
+        * @return boolean Was the transmission successful?
         */
        public static function transmit($data, $target, $uid)
        {
@@ -302,10 +305,12 @@ class HTTPSignature
 
                $headers[] = 'Content-Type: application/activity+json';
 
-               Network::post($target, $content, $headers);
-               $return_code = BaseObject::getApp()->getCurlCode();
+               $postResult = Network::post($target, $content, $headers);
+               $return_code = $postResult->getReturnCode();
+
+               Logger::log('Transmit to ' . $target . ' returned ' . $return_code);
 
-               logger('Transmit to ' . $target . ' returned ' . $return_code);
+               return ($return_code >= 200) && ($return_code <= 299);
        }
 
        /**
@@ -402,6 +407,8 @@ class HTTPSignature
                        }
                }
 
+               /// @todo Check if the signed date field is in an acceptable range
+
                // Check the content-length when it is part of the signed data
                if (in_array('content-length', $sig_block['headers'])) {
                        if (strlen($content) != $headers['content-length']) {
@@ -426,12 +433,12 @@ class HTTPSignature
 
                $profile = APContact::getByURL($url);
                if (!empty($profile)) {
-                       logger('Taking key from id ' . $id, LOGGER_DEBUG);
+                       Logger::log('Taking key from id ' . $id, Logger::DEBUG);
                        return ['url' => $url, 'pubkey' => $profile['pubkey']];
                } elseif ($url != $actor) {
                        $profile = APContact::getByURL($actor);
                        if (!empty($profile)) {
-                               logger('Taking key from actor ' . $actor, LOGGER_DEBUG);
+                               Logger::log('Taking key from actor ' . $actor, Logger::DEBUG);
                                return ['url' => $actor, 'pubkey' => $profile['pubkey']];
                        }
                }