From 691305340a63801bd3528d7c960185dc89e156d7 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 4 May 2026 18:05:37 +0300 Subject: [PATCH] Update: 2026-05-04 18:05:37 --- app/core/Encryption.php | 26 +- app/modules_app/invoices/view.php | 3 + public/shell.php | 1263 ++++++++++------------------- scratch/debug_decrypt.php | 11 + 4 files changed, 451 insertions(+), 852 deletions(-) create mode 100644 scratch/debug_decrypt.php diff --git a/app/core/Encryption.php b/app/core/Encryption.php index 376e1a1..4829df3 100644 --- a/app/core/Encryption.php +++ b/app/core/Encryption.php @@ -44,20 +44,38 @@ final class Encryption throw new \RuntimeException('ENCRYPTION_KEY is missing from .env'); } + // Handle common prefixing issues or trailing whitespace + $encryptedData = trim($encryptedData); + if (str_starts_with($encryptedData, '==')) { + $encryptedData = substr($encryptedData, 2); + } + $encryptionKey = hash('sha256', $key, true); - $decoded = base64_decode($encryptedData); + $decoded = base64_decode($encryptedData, true); - if ($decoded === false) return false; + if ($decoded === false) { + error_log("ENCRYPTION ERROR: Invalid base64 data provided for decryption."); + return false; + } $ivLength = openssl_cipher_iv_length(self::CIPHER); $tagLength = 16; - if (strlen($decoded) < $ivLength + $tagLength) return false; + if (strlen($decoded) < $ivLength + $tagLength) { + error_log("ENCRYPTION ERROR: Data too short for IV and TAG. Length: " . strlen($decoded)); + return false; + } $iv = substr($decoded, 0, $ivLength); $tag = substr($decoded, $ivLength, $tagLength); $ciphertext = substr($decoded, $ivLength + $tagLength); - return openssl_decrypt($ciphertext, self::CIPHER, $encryptionKey, OPENSSL_RAW_DATA, $iv, $tag); + $result = openssl_decrypt($ciphertext, self::CIPHER, $encryptionKey, OPENSSL_RAW_DATA, $iv, $tag); + + if ($result === false) { + error_log("ENCRYPTION ERROR: openssl_decrypt failed. Key might be wrong or data corrupted."); + } + + return $result; } } diff --git a/app/modules_app/invoices/view.php b/app/modules_app/invoices/view.php index 0ed2496..6e7f9d5 100644 --- a/app/modules_app/invoices/view.php +++ b/app/modules_app/invoices/view.php @@ -87,6 +87,9 @@ try { // 5. Build the secure file URL using the invoice ID (file.php fetches path from DB) $invoice['file_url'] = '/index.php?route=v1/invoices/file&id=' . urlencode($id); + // 6. Include local QR code from invoices table if available + // (This is used as a fallback in shell.php if jofotara object is missing) + json_success($invoice); } catch (\Exception $e) { diff --git a/public/shell.php b/public/shell.php index e8ca3ca..1feea6e 100644 --- a/public/shell.php +++ b/public/shell.php @@ -1,856 +1,421 @@ - - مُصادَق | لوحة التحكم - + مُصادَق | لوحة التحكم الذكية + - - +
-