]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPSignature.php
Merge pull request #9186 from annando/valid-posts
[friendica.git] / src / Util / HTTPSignature.php
index 89da59ba26012911842589abe1e8768a4130a63a..cdee48bfc02683bb5e67f31cfc1ba9e26240bec6 100644 (file)
@@ -413,12 +413,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 +440,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'])) {
@@ -477,7 +484,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) {