From a5a86cc1cd94d78dfe318185910fc15fa78f216d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 14 Dec 2021 13:10:38 +0100 Subject: [PATCH] fix: bin2hex() calls --- app/controllers/api/storage.php | 3 ++- app/init.php | 4 ++-- src/Appwrite/Migration/Version/V06.php | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 3e095f4d01..8b9daedb00 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -137,6 +137,7 @@ App::post('/v1/storage/files') $data = $compressor->compress($data); $key = App::getEnv('_APP_OPENSSL_KEY_V1'); $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); + $tag = null; $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag); if (!$device->write($path, $data, $mimeType)) { @@ -162,7 +163,7 @@ App::post('/v1/storage/files') 'comment' => '', 'openSSLVersion' => '1', 'openSSLCipher' => OpenSSL::CIPHER_AES_128_GCM, - 'openSSLTag' => \bin2hex($tag), + 'openSSLTag' => \bin2hex($tag ?? ''), 'openSSLIV' => \bin2hex($iv), 'search' => implode(' ', [$fileId, $file['name'] ?? '',]), ])); diff --git a/app/init.php b/app/init.php index df465baf7b..45cdf438b6 100644 --- a/app/init.php +++ b/app/init.php @@ -286,8 +286,8 @@ Database::addFilter('encrypt', return json_encode([ 'data' => OpenSSL::encrypt($value, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag), 'method' => OpenSSL::CIPHER_AES_128_GCM, - 'iv' => bin2hex($iv), - 'tag' => bin2hex($tag), + 'iv' => \bin2hex($iv), + 'tag' => \bin2hex($tag ?? ''), 'version' => '1', ]); }, diff --git a/src/Appwrite/Migration/Version/V06.php b/src/Appwrite/Migration/Version/V06.php index b28ce8ac2f..45bd284f2e 100644 --- a/src/Appwrite/Migration/Version/V06.php +++ b/src/Appwrite/Migration/Version/V06.php @@ -46,8 +46,8 @@ class V06 extends Migration $document->setAttribute('secret', json_encode([ 'data' => OpenSSL::encrypt($document->getAttribute('secret'), OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag), 'method' => OpenSSL::CIPHER_AES_128_GCM, - 'iv' => bin2hex($iv), - 'tag' => bin2hex($tag), + 'iv' => \bin2hex($iv), + 'tag' => \bin2hex($tag ?? ''), 'version' => '1', ])); }