mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 16:23:18 +01:00
Fix issues detected by static code analysis
This commit is contained in:
parent
8d3a97a701
commit
6a41c77144
@ -106,7 +106,7 @@ public function update(TwoFAccountUpdateRequest $request, TwoFAccount $twofaccou
|
||||
* Convert a migration resource to a valid TwoFAccounts collection
|
||||
*
|
||||
* @param \App\Api\v1\Requests\TwoFAccountImportRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\JsonResponse|\App\Api\v1\Resources\TwoFAccountCollection
|
||||
*/
|
||||
public function migrate(TwoFAccountImportRequest $request)
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ class MigratorFactory implements MigratorFactoryInterface
|
||||
* @param string $migrationPayload The migration payload used to infer the migrator type
|
||||
* @return Migrator
|
||||
*/
|
||||
public function create($migrationPayload) : Migrator
|
||||
public function create(string $migrationPayload) : Migrator
|
||||
{
|
||||
if ($this->isAegisJSON($migrationPayload)) {
|
||||
return App::make(AegisMigrator::class);
|
||||
@ -41,9 +41,12 @@ public function create($migrationPayload) : Migrator
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a payload comes from Google Authenticator
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function isGoogleAuth($migrationPayload) : bool
|
||||
private function isGoogleAuth(string $migrationPayload) : bool
|
||||
{
|
||||
// - Google Auth migration URI : a string starting with otpauth-migration://offline?data= on a single line
|
||||
|
||||
@ -57,9 +60,12 @@ private function isGoogleAuth($migrationPayload) : bool
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a payload is a plain text content
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function isPlainText($migrationPayload) : bool
|
||||
private function isPlainText(string $migrationPayload) : bool
|
||||
{
|
||||
// - Plain text : one or more otpauth URIs (otpauth://[t|h]otp/...), one per line
|
||||
|
||||
@ -73,9 +79,12 @@ private function isPlainText($migrationPayload) : bool
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a payload comes from Aegis Authenticator in JSON format
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function isAegisJSON($migrationPayload) : mixed
|
||||
private function isAegisJSON(string $migrationPayload) : mixed
|
||||
{
|
||||
// - Aegis JSON : is a JSON object with the key db.entries full of objects like
|
||||
// {
|
||||
@ -108,7 +117,7 @@ private function isAegisJSON($migrationPayload) : mixed
|
||||
'db.entries.*.issuer' => 'required',
|
||||
'db.entries.*.info' => 'required'
|
||||
]
|
||||
));
|
||||
)) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,9 +126,12 @@ private function isAegisJSON($migrationPayload) : mixed
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a payload comes from 2FAS Authenticator
|
||||
*
|
||||
* @param string $migrationPayload The payload to analyse
|
||||
* @return bool
|
||||
*/
|
||||
private function is2FASv2($migrationPayload) : mixed
|
||||
private function is2FASv2(string $migrationPayload) : mixed
|
||||
{
|
||||
// - 2FAS JSON : is a JSON object with the key 'schemaVersion' == 2 and a key 'services' full of objects like
|
||||
// {
|
||||
@ -156,7 +168,7 @@ private function is2FASv2($migrationPayload) : mixed
|
||||
'services.*.name' => 'required',
|
||||
'services.*.otp' => 'required'
|
||||
]
|
||||
));
|
||||
)) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,7 @@ class Helpers
|
||||
/**
|
||||
* Generate a unique filename
|
||||
*
|
||||
* @param string $ids twofaccount ids to delete
|
||||
*
|
||||
* @param string $extension
|
||||
* @return string The filename
|
||||
*/
|
||||
public static function getUniqueFilename(string $extension): string
|
||||
|
@ -49,6 +49,8 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
throw new InvalidMigrationDataException('Aegis');
|
||||
}
|
||||
|
||||
$twofaccounts = array();
|
||||
|
||||
foreach ($json['db']['entries'] as $key => $otp_parameters) {
|
||||
|
||||
$parameters = array();
|
||||
@ -81,7 +83,6 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
|
||||
default:
|
||||
throw new \Exception();
|
||||
break;
|
||||
}
|
||||
|
||||
$filename = Helpers::getUniqueFilename($extension);
|
||||
|
@ -12,11 +12,14 @@ abstract class Migrator
|
||||
* @param mixed $migrationPayload
|
||||
* @return \Illuminate\Support\Collection The converted accounts
|
||||
*/
|
||||
abstract protected function migrate(mixed $migrationPayload) : Collection;
|
||||
abstract public function migrate(mixed $migrationPayload) : Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Pad a string to 8 chars min
|
||||
*
|
||||
* @param string $string
|
||||
* @return string The padded string
|
||||
*/
|
||||
protected function padToValidBase32Secret(string $string)
|
||||
{
|
||||
|
@ -80,6 +80,8 @@ public function migrate(mixed $migrationPayload) : Collection
|
||||
Log::error('Aegis JSON migration data cannot be read');
|
||||
throw new InvalidMigrationDataException('2FAS Auth');
|
||||
}
|
||||
|
||||
$twofaccounts = array();
|
||||
|
||||
foreach ($json['services'] as $key => $otp_parameters) {
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
class TwoFAccountService
|
||||
{
|
||||
/**
|
||||
* @var $migrator The Migration service
|
||||
* @var MigratorFactoryInterface $migratorFactory The Migration service
|
||||
*/
|
||||
protected $migratorFactory;
|
||||
|
||||
@ -50,11 +50,10 @@ public static function withdraw($ids) : void
|
||||
/**
|
||||
* Convert a migration payload to a set of TwoFAccount objects
|
||||
*
|
||||
* @param string $migrationUri migration uri provided by Google Authenticator export feature
|
||||
*
|
||||
* @param string $migrationPayload Migration payload from 2FA apps export feature
|
||||
* @return \Illuminate\Support\Collection The converted accounts
|
||||
*/
|
||||
public function migrate($migrationPayload) : Collection
|
||||
public function migrate(string $migrationPayload) : Collection
|
||||
{
|
||||
$migrator = $this->migratorFactory->create($migrationPayload);
|
||||
$twofaccounts = $migrator->migrate($migrationPayload);
|
||||
@ -67,7 +66,6 @@ public function migrate($migrationPayload) : Collection
|
||||
* Delete one or more twofaccounts
|
||||
*
|
||||
* @param int|array|string $ids twofaccount ids to delete
|
||||
*
|
||||
* @return int The number of deleted
|
||||
*/
|
||||
public static function delete($ids) : int
|
||||
|
Loading…
Reference in New Issue
Block a user