From 23e3a2e8fcd59e5546ba2b656abfb8dc66649238 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Thu, 26 Jan 2023 21:35:06 +0000 Subject: [PATCH] - Create custom function (randomString()) for generating cryptographically (and URL) safe strings. - Replace usages of keygen and bin2hex(random_bytes()) with this function. --- ajax.php | 6 ++--- api_key_add_modal.php | 2 +- blank.php | 3 +-- cron.php | 4 +-- functions.php | 60 +++++++++++++++++++++++------------------- login.php | 2 +- portal/login_reset.php | 2 +- post.php | 16 +++++------ setup.php | 2 +- users.php | 2 +- 10 files changed, 52 insertions(+), 47 deletions(-) diff --git a/ajax.php b/ajax.php index 33b2ee7a..9dab8381 100644 --- a/ajax.php +++ b/ajax.php @@ -230,7 +230,7 @@ if (isset($_GET['share_generate_link'])) { $item_note = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['note']))); $item_view_limit = intval($_GET['views']); $item_expires = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['expires']))); - $item_key = bin2hex(random_bytes(78)); + $item_key = randomString(156); if ($item_type == "Document") { $row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT document_name FROM documents WHERE document_id = '$item_id' AND document_client_id = '$client_id' LIMIT 1")); @@ -250,8 +250,8 @@ if (isset($_GET['share_generate_link'])) { // Decrypt & re-encrypt password for sharing $login_password_cleartext = decryptLoginEntry($row['login_password']); - $login_encryption_key = bin2hex(random_bytes(8)); - $iv = bin2hex(random_bytes(8)); + $login_encryption_key = randomString(); + $iv = randomString(); $ciphertext = openssl_encrypt($login_password_cleartext, 'aes-128-cbc', $login_encryption_key, 0, $iv); $item_encrypted_credential = $iv . $ciphertext; diff --git a/api_key_add_modal.php b/api_key_add_modal.php index 0c74dcbe..8b839759 100644 --- a/api_key_add_modal.php +++ b/api_key_add_modal.php @@ -1,5 +1,5 @@