viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Some fixes issues with encrypted grroups in postgres

Chris Pollett [2020-08-11 02:Aug:th]
Some fixes issues with encrypted grroups in postgres
Filename
src/data/private_default.db
src/data/public_default.db
src/models/GroupModel.php
src/models/ProfileModel.php
diff --git a/src/data/private_default.db b/src/data/private_default.db
index ce01a4fe7..3ce8b3224 100644
Binary files a/src/data/private_default.db and b/src/data/private_default.db differ
diff --git a/src/data/public_default.db b/src/data/public_default.db
index 827199c3d..27ce7f8b8 100644
Binary files a/src/data/public_default.db and b/src/data/public_default.db differ
diff --git a/src/models/GroupModel.php b/src/models/GroupModel.php
index 090b3f3d0..4a60eb213 100644
--- a/src/models/GroupModel.php
+++ b/src/models/GroupModel.php
@@ -277,7 +277,8 @@ class GroupModel extends Model implements MediaConstants
             C\GROUP_IMPRESSION, $db);
         if ($encryption != 0) {
             $sql = "INSERT INTO TYPE_KEYS (TYPE_ID, KEY_NAME) VALUES (?, ?)";
-            $encrypt_key = openssl_random_pseudo_bytes(32);
+            //AES 256 is 32 bytes long (8*32 bits)
+            $encrypt_key = base64_encode(openssl_random_pseudo_bytes(32));
             $private_db->execute($sql, [$last_id, $encrypt_key]);
         }
         return $last_id;
@@ -625,7 +626,7 @@ class GroupModel extends Model implements MediaConstants
         if ($result) {
             $row = $private_db->fetchArray($result);
         }
-        return $row['KEY_NAME'];
+        return base64_decode($row['KEY_NAME']);
     }
     /**
      * To update the OWNER_ID of a group
diff --git a/src/models/ProfileModel.php b/src/models/ProfileModel.php
index 3efb55a87..0ce93a65b 100755
--- a/src/models/ProfileModel.php
+++ b/src/models/ProfileModel.php
@@ -406,11 +406,14 @@ class ProfileModel extends Model
          * these statements could use UNIQUE on some the columns that are
          * later used in CREATE INDEX statements. However, because of
          * restrictions on the number of bytes (not chars) in MYSQL for keys
-         * this has not been done.
+         * this has not been done. AES 256 = 8*32bits long. So need
+         * only 32 bytes to store a key. We give up to 64 (LONG_NAME_LEN)
+         * as base 64 encoding keys to keep postgres happy when using varchhar
          */
         $this->private_create_statements = ["TYPE_KEYS" =>
-            "CREATE TABLE TYPE_KEYS (KEY_ID $serial PRIMARY KEY
-            $auto_increment, TYPE_ID $integer, KEY_NAME VARCHAR(30))"];
+            "CREATE TABLE TYPE_KEYS (KEY_ID $serial PRIMARY KEY " .
+            "$auto_increment, TYPE_ID $integer, KEY_NAME VARCHAR(" .
+            C\LONG_NAME_LEN . "))"];
     }
     /**
      * Creates a folder to be used to maintain local information about this
@@ -725,7 +728,7 @@ EOT;
                 continue;
             }
             if (!$result = $dbm->execute($statement)) {
-                echo $statement." ERROR!";
+                echo $statement . " ERROR!";
                 return false;
             }
         }
ViewGit