secret generation extracted to open SSL

This commit is contained in:
Damodar Lohani
2022-05-23 06:44:18 +00:00
parent 58d00055d9
commit f403b8235a
3 changed files with 20 additions and 5 deletions
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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;
+16 -1
View File
@@ -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));
}
}