diff --git a/app/Factories/MigratorFactory.php b/app/Factories/MigratorFactory.php index 4a72fb8f..86960f43 100644 --- a/app/Factories/MigratorFactory.php +++ b/app/Factories/MigratorFactory.php @@ -66,12 +66,13 @@ private function isGoogleAuth(string $migrationPayload) : bool */ private function isPlainText(string $migrationPayload) : bool { - // - Plain text : one or more otpauth URIs (otpauth://[t|h]otp/...), one per line + // - Plain text : one or more otpauth URIs (otpauth://(hotp|totp|steam)/...), one per line return Validator::make( preg_split('~\R~', $migrationPayload, -1, PREG_SPLIT_NO_EMPTY), [ - '*' => 'regex:/^otpauth:\/\/[h,t]otp\//i', + // The regex rule must be embraced with brackets when it cointains a pipe + '*' => ['regex:/^otpauth:\/\/(?:steam|totp|hotp)\//i'], ] )->passes(); } diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index b66afd34..60233c98 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -394,8 +394,9 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc { // First we instanciate the OTP generator try { - $this->generator = Factory::loadFromProvisioningUri($uri); - } catch (\Assert\AssertionFailedException | \Assert\InvalidArgumentException | \Exception | \Throwable $ex) { + $this->generator = Factory::loadFromProvisioningUri($isSteamTotp ? str_replace('otpauth://steam', 'otpauth://totp', $uri) : $uri); + } + catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) { throw ValidationException::withMessages([ 'uri' => __('validation.custom.uri.regex', ['attribute' => 'uri']), ]); @@ -459,6 +460,7 @@ public function equals(self $other) : bool private function enforceAsSteam() : void { $this->otp_type = self::STEAM_TOTP; + $this->service = 'Steam'; $this->digits = 5; $this->algorithm = self::SHA1; $this->period = 30; diff --git a/app/Services/Migrators/PlainTextMigrator.php b/app/Services/Migrators/PlainTextMigrator.php index 8dcdb8da..28f93eee 100644 --- a/app/Services/Migrators/PlainTextMigrator.php +++ b/app/Services/Migrators/PlainTextMigrator.php @@ -21,7 +21,7 @@ public function migrate(mixed $migrationPayload) : Collection { $otpauthURIs = preg_split('~\R~', $migrationPayload); $otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) { - return Str::startsWith($value, ['otpauth://totp/', 'otpauth://hotp/']); + return Str::startsWith($value, ['otpauth://totp/', 'otpauth://hotp/', 'otpauth://steam/']); }); if (count($otpauthURIs) < 1) { @@ -31,9 +31,11 @@ public function migrate(mixed $migrationPayload) : Collection foreach ($otpauthURIs as $key => $uri) { try { - $twofaccounts[$key] = new TwoFAccount; - $twofaccounts[$key]->fillWithURI($uri); - } catch (\Exception $exception) { + $twofaccounts[$key] = new TwoFAccount; + $twofaccounts[$key]->fillWithURI($uri, str_starts_with($uri, 'otpauth://steam/')); + } + catch (\Exception $exception) { + Log::error(sprintf('Cannot instanciate a TwoFAccount object with OTP parameters from imported item #%s', $key)); Log::debug($exception->getMessage()); diff --git a/changelog.md b/changelog.md index 5f9f5816..d0a5a0b8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Change log +## [3.4.2] - 2023-01-25 + +### Fixed + +- [issue #160](https://github.com/Bubka/2FAuth/issues/160) Steam otpauth URI from Aegis are rejected by the Import feature + ## [3.4.1] - 2022-11-25 ### Fixed diff --git a/config/2fauth.php b/config/2fauth.php index 96ab251e..86049d61 100644 --- a/config/2fauth.php +++ b/config/2fauth.php @@ -9,7 +9,7 @@ | */ - 'version' => '3.4.1', + 'version' => '3.4.2', 'repository' => 'https://github.com/Bubka/2FAuth', 'latestReleaseUrl' => 'https://api.github.com/repos/Bubka/2FAuth/releases/latest',