mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix functions and realtime
This commit is contained in:
+1
-2
@@ -311,7 +311,7 @@ Database::addFilter('encrypt',
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag ?? ''),
|
||||
'version' => '1',
|
||||
'version' => 'v1',
|
||||
]);
|
||||
},
|
||||
function($value) {
|
||||
@@ -799,7 +799,6 @@ function decode(mixed $value, array $secrets): mixed {
|
||||
if(is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = json_decode($value, true);
|
||||
$version = $value['version'];
|
||||
$key = $secrets[$version];
|
||||
|
||||
+7
-26
@@ -517,24 +517,11 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
|
||||
if(!$project->isEmpty()) {
|
||||
|
||||
$secrets = $project->getAttribute('databaseSecrets');
|
||||
$displacement = $project->getAttribute('databaseSecretsDisplacement', 0);
|
||||
$version = $displacement + \count($secrets);
|
||||
|
||||
$filters['encrypt'] = [
|
||||
'encode' => function($value) use($version, $secrets) {
|
||||
|
||||
$key = $secrets[\count($secrets)-1];
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$value = 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 ?? ''),
|
||||
'version' => $version,
|
||||
]);
|
||||
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
'encode' => function($value) use($secrets) {
|
||||
$version = array_key_last($secrets);
|
||||
$key = $secrets[$version];
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
return json_encode([
|
||||
@@ -542,22 +529,16 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag ?? ''),
|
||||
'version' => '1',
|
||||
'version' => $version,
|
||||
]);
|
||||
},
|
||||
'decode' => function($value) use($secrets, $displacement) {
|
||||
'decode' => function($value) use($secrets) {
|
||||
if(is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = json_decode($value, true);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$value['version']);
|
||||
|
||||
$value = OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag']));
|
||||
|
||||
$value = json_decode($value, true);
|
||||
$version = ($value['version'] ?? 1) - $displacement;
|
||||
$key = $secrets[$version - 1];
|
||||
$version = $value['version'];
|
||||
$key = $secrets[$version];
|
||||
|
||||
return OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag']));
|
||||
}
|
||||
|
||||
@@ -205,30 +205,17 @@ abstract class Worker
|
||||
$database = new Database(new MariaDB($register->get('db')), $cache);
|
||||
$database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite'));
|
||||
|
||||
if($namespace != "_console" && !empty($projectId)) {
|
||||
if(!empty($projectId)) {
|
||||
$database->setNamespace("_console");
|
||||
$project = $database->getDocument('projects', $projectId);
|
||||
if(!$project->isEmpty()) {
|
||||
|
||||
$secrets = $project->getAttribute('databaseSecrets');
|
||||
$displacement = $project->getAttribute('databaseSecretsDisplacement', 0);
|
||||
$version = $displacement + \count($secrets);
|
||||
|
||||
$filters['encrypt'] = [
|
||||
'encode' => function($value) use($version, $secrets) {
|
||||
|
||||
$key = $secrets[\count($secrets)-1];
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
$value = 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 ?? ''),
|
||||
'version' => $version,
|
||||
]);
|
||||
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
'encode' => function($value) use($secrets) {
|
||||
$version = array_key_last($secrets);
|
||||
$key = $secrets[$version];
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
return json_encode([
|
||||
@@ -236,22 +223,17 @@ abstract class Worker
|
||||
'method' => OpenSSL::CIPHER_AES_128_GCM,
|
||||
'iv' => \bin2hex($iv),
|
||||
'tag' => \bin2hex($tag ?? ''),
|
||||
'version' => '1',
|
||||
'version' => $version,
|
||||
]);
|
||||
},
|
||||
'decode' => function($value) use($secrets, $displacement) {
|
||||
'decode' => function($value) use($secrets) {
|
||||
if(is_null($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = json_decode($value, true);
|
||||
$key = App::getEnv('_APP_OPENSSL_KEY_V'.$value['version']);
|
||||
|
||||
$value = OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag']));
|
||||
|
||||
$value = json_decode($value, true);
|
||||
$version = ($value['version'] ?? 1) - $displacement;
|
||||
$key = $secrets[$version - 1];
|
||||
$version = $value['version'];
|
||||
$key = $secrets[$version];
|
||||
|
||||
return OpenSSL::decrypt($value['data'], $value['method'], $key, 0, hex2bin($value['iv']), hex2bin($value['tag']));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user