mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
secret generation extracted to open SSL
This commit is contained in:
@@ -104,8 +104,8 @@ App::post('/v1/projects')
|
||||
'keys' => null,
|
||||
'domains' => null,
|
||||
'auths' => $auths,
|
||||
'databaseSecrets' => [\uniqid() => \bin2hex(OpenSSL::randomPseudoBytes(128))],
|
||||
'jwtSecrets' => \bin2hex(OpenSSL::randomPseudoBytes(128)),
|
||||
'databaseSecrets' => [\uniqid() => OpenSSL::secretString()],
|
||||
'jwtSecrets' => OpenSSL::secretString(),
|
||||
'search' => implode(' ', [$projectId, $name]),
|
||||
]));
|
||||
/** @var array $collections */
|
||||
@@ -797,7 +797,7 @@ App::post('/v1/projects/:projectId/keys')
|
||||
'projectId' => $project->getId(),
|
||||
'name' => $name,
|
||||
'scopes' => $scopes,
|
||||
'secret' => \bin2hex(\random_bytes(128)),
|
||||
'secret' => Auth::tokenGenerator(),
|
||||
]);
|
||||
|
||||
$key = $dbForConsole->createDocument('keys', $key);
|
||||
|
||||
@@ -515,7 +515,7 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||
$data = $deviceFiles->read($path);
|
||||
}
|
||||
|
||||
$fileSecret = \bin2hex(OpenSSL::randomPseudoBytes(128));
|
||||
$fileSecret = OpenSSL::secretString();
|
||||
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM));
|
||||
$tag = null;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ class OpenSSL
|
||||
*/
|
||||
public static function encrypt($data, $method, $key, $options = 0, $iv = '', &$tag = null, $aad = '', $tag_length = 16)
|
||||
{
|
||||
var_dump($data);
|
||||
return \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
|
||||
}
|
||||
|
||||
@@ -60,4 +59,20 @@ class OpenSSL
|
||||
{
|
||||
return \openssl_random_pseudo_bytes($length, $crypto_strong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Secret String
|
||||
*
|
||||
* Generate random encryption secret
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function secretString(int $length = 128):string
|
||||
{
|
||||
return \bin2hex(self::randomPseudoBytes($length));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user