]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPSignature.php
Removed completely un-used 'http_auth' option from HTTPRequest
[friendica.git] / src / Util / HTTPSignature.php
index d151516beae7a9bed098f766c43dd1628ced6330..4d6ae7e90c53b1ff6392114e7e017e725cdfcba4 100644 (file)
 
 namespace Friendica\Util;
 
-use Friendica\Database\DBA;
 use Friendica\Core\Logger;
+use Friendica\Database\DBA;
 use Friendica\DI;
-use Friendica\Model\User;
 use Friendica\Model\APContact;
+use Friendica\Model\User;
 
 /**
  * Implements HTTP Signatures per draft-cavage-http-signatures-07.
@@ -297,7 +297,7 @@ class HTTPSignature
 
                $headers[] = 'Content-Type: application/activity+json';
 
-               $postResult = Network::post($target, $content, $headers);
+               $postResult = DI::httpRequest()->post($target, $content, $headers);
                $return_code = $postResult->getReturnCode();
 
                Logger::log('Transmit to ' . $target . ' returned ' . $return_code, Logger::DEBUG);
@@ -403,7 +403,6 @@ class HTTPSignature
         * @param array   $opts    (optional parameters) assoziative array with:
         *                         'accept_content' => supply Accept: header with 'accept_content' as the value
         *                         'timeout' => int Timeout in seconds, default system config value or 60 seconds
-        *                         'http_auth' => username:password
         *                         'novalidate' => do not validate SSL certs, default is to validate using our CA list
         *                         'nobody' => only return the header
         *                         'cookiejar' => path to cookie jar file
@@ -413,12 +412,21 @@ class HTTPSignature
         */
        public static function fetchRaw($request, $uid = 0, $binary = false, $opts = [])
        {
+               $headers = [];
+
                if (!empty($uid)) {
                        $owner = User::getOwnerDataById($uid);
                        if (!$owner) {
                                return;
                        }
+               } else {
+                       $owner = User::getSystemAccount();
+                       if (!$owner) {
+                               return;
+                       }
+               }
 
+               if (!empty($owner['uprvkey'])) {
                        // Header data that is about to be signed.
                        $host = parse_url($request, PHP_URL_HOST);
                        $path = parse_url($request, PHP_URL_PATH);
@@ -431,8 +439,6 @@ class HTTPSignature
                        $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
 
                        $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) date host",signature="' . $signature . '"';
-               } else {
-                       $headers = [];
                }
 
                if (!empty($opts['accept_content'])) {
@@ -442,7 +448,11 @@ class HTTPSignature
                $curl_opts = $opts;
                $curl_opts['header'] = $headers;
 
-               $curlResult = Network::curl($request, false, $curl_opts);
+               if ($opts['nobody']) {
+                       $curlResult = DI::httpRequest()->head($request, $curl_opts);
+               } else {
+                       $curlResult = DI::httpRequest()->get($request, $curl_opts);
+               }
                $return_code = $curlResult->getReturnCode();
 
                Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);
@@ -477,7 +487,7 @@ class HTTPSignature
                }
 
                $headers = [];
-               $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI'];
+               $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . parse_url($http_headers['REQUEST_URI'], PHP_URL_PATH);
 
                // First take every header
                foreach ($http_headers as $k => $v) {