1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

fix(migration): migrate encrypt filter

This commit is contained in:
Torsten Dittmann 2021-01-14 15:47:13 +01:00
parent 2d18abd63d
commit 3c5d32e5fc

View file

@ -2,11 +2,13 @@
namespace Appwrite\Migration\Version;
use Utopia\App;
use Utopia\CLI\Console;
use Utopia\Config\Config;
use Appwrite\Database\Database;
use Appwrite\Database\Document;
use Appwrite\Migration\Migration;
use Appwrite\OpenSSL\OpenSSL;
class V06 extends Migration
{
@ -22,6 +24,8 @@ class V06 extends Migration
{
switch ($document->getAttribute('$collection')) {
case Database::SYSTEM_COLLECTION_USERS:
var_dump($this->applyFilterEncrypt($document->getAttribute("email")));
if ($document->getAttribute('password-update', null)) {
$document
->setAttribute('passwordUpdate', $document->getAttribute('password-update', $document->getAttribute('passwordUpdate', '')))
@ -53,4 +57,19 @@ class V06 extends Migration
}
return $document;
}
private function applyFilterEncrypt(String $value)
{
$key = App::getEnv('_APP_OPENSSL_KEY_V1');
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
$tag = null;
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),
'version' => '1',
]);
}
}