]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPSignature.php
Add missing PDO* use statements in Database\dba
[friendica.git] / src / Util / HTTPSignature.php
index d6152075e4dd8caeacfcf53b14c4c5d9b5bc4d21..c3a45205c37bd9326ada56d9955e8494df79312f 100644 (file)
@@ -1,21 +1,19 @@
 <?php
 
 /**
- * @file src/Util/HTTPSig.php
+ * @file src/Util/HTTPSignature.php
  */
 namespace Friendica\Util;
 
 use Friendica\Core\Config;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Util\Crypto;
-use Friendica\Util\HTTPHeaders;
-use dba;
 
 /**
  * @brief Implements HTTP Signatures per draft-cavage-http-signatures-07.
  *
  * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPSig.php
- * 
+ *
  * @see https://tools.ietf.org/html/draft-cavage-http-signatures-07
  */
 
@@ -24,23 +22,26 @@ class HTTPSignature
        /**
         * @brief RFC5843
         *
+        * Disabled until Friendica's ActivityPub implementation
+        * is ready.
+        *
         * @see https://tools.ietf.org/html/rfc5843
         *
         * @param string  $body The value to create the digest for
         * @param boolean $set  (optional, default true)
         *   If set send a Digest HTTP header
-        * 
+        *
         * @return string The generated digest of $body
         */
-       public static function generateDigest($body, $set = true)
-       {
-               $digest = base64_encode(hash('sha256', $body, true));
-
-               if($set) {
-                       header('Digest: SHA-256=' . $digest);
-               }
-               return $digest;
-       }
+//     public static function generateDigest($body, $set = true)
+//     {
+//             $digest = base64_encode(hash('sha256', $body, true));
+//
+//             if($set) {
+//                     header('Digest: SHA-256=' . $digest);
+//             }
+//             return $digest;
+//     }
 
        // See draft-cavage-http-signatures-08
        public static function verify($data, $key = '')
@@ -63,7 +64,7 @@ class HTTPSignature
                        }
 
                        $h = new HTTPHeaders($data['header']);
-                       $headers = $h->fetcharr();
+                       $headers = $h->fetch();
                        $body = $data['body'];
                } else {
                        $headers = [];
@@ -171,20 +172,20 @@ class HTTPSignature
 
        /**
         * Fetch the public key for Activity Pub contact.
-        * 
+        *
         * @param string|int The identifier (contact addr or contact ID).
         * @return string|boolean The public key or false on failure.
         */
        private static function getActivitypubKey($id)
        {
                if (strpos($id, 'acct:') === 0) {
-                       $x = dba::selectFirst('contact', ['pubkey'], ['uid' => 0, 'addr' => str_replace('acct:', '', $id)]);
+                       $contact = dba::selectFirst('contact', ['pubkey'], ['uid' => 0, 'addr' => str_replace('acct:', '', $id)]);
                } else {
-                       $x = dba::selectFirst('contact', ['pubkey'], ['id' => $id, 'network' => 'activitypub']);
+                       $contact = dba::selectFirst('contact', ['pubkey'], ['id' => $id, 'network' => 'activitypub']);
                }
 
-               if (DBM::is_result($x)) {
-                       return $x['pubkey'];
+               if (DBM::is_result($contact)) {
+                       return $contact['pubkey'];
                }
 
                if(function_exists('as_fetch')) {
@@ -219,7 +220,7 @@ class HTTPSignature
         * @param string  $alg (optional, default 'sha256')
         * @param string  $crypt_key (optional, default null)
         * @param string  $crypt_algo (optional, default 'aes256ctr')
-        * 
+        *
         * @return array
         */
        public static function createSig($request, $head, $prvkey, $keyid = 'Key', $send_headers = false, $auth = false, $alg = 'sha256', $crypt_key = null, $crypt_algo = 'aes256ctr')
@@ -253,7 +254,10 @@ class HTTPSignature
                if ($head) {
                        foreach ($head as $k => $v) {
                                if ($send_headers) {
-                                       header($k . ': ' . $v);
+                                       // This is for ActivityPub implementation.
+                                       // Since the Activity Pub implementation isn't
+                                       // ready at the moment, we comment it out.
+                                       // header($k . ': ' . $v);
                                } else {
                                        $return_headers[] = $k . ': ' . $v;
                                }
@@ -261,7 +265,10 @@ class HTTPSignature
                }
 
                if ($send_headers) {
-                       header($sighead);
+                       // This is for ActivityPub implementation.
+                       // Since the Activity Pub implementation isn't
+                       // ready at the moment, we comment it out.
+                       // header($sighead);
                } else {
                        $return_headers[] = $sighead;
                }
@@ -276,7 +283,7 @@ class HTTPSignature
         * @param array  $head
         * @param string $prvkey
         * @param string $alg (optional) default 'sha256'
-        * 
+        *
         * @return array
         */
        private static function sign($request, $head, $prvkey, $alg = 'sha256')
@@ -306,7 +313,7 @@ class HTTPSignature
 
                $ret['headers']   = $fields;
                $ret['signature'] = $sig;
-       
+
                return $ret;
        }
 
@@ -358,7 +365,7 @@ class HTTPSignature
         *
         * @param string $header
         * @param string $prvkey (optional), if not set use site private key
-        * 
+        *
         * @return array|string associative array, empty string if failue
         *   - \e string \b iv
         *   - \e string \b key