diff --git a/app/Factories/MigratorFactory.php b/app/Factories/MigratorFactory.php index bec5c53e..723295e6 100644 --- a/app/Factories/MigratorFactory.php +++ b/app/Factories/MigratorFactory.php @@ -67,12 +67,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 07e6c6bb..8693574e 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -408,7 +408,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc { // First we instanciate the OTP generator try { - $this->generator = Factory::loadFromProvisioningUri($uri); + $this->generator = Factory::loadFromProvisioningUri($isSteamTotp ? str_replace('otpauth://steam', 'otpauth://totp', $uri) : $uri); } catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) { throw ValidationException::withMessages([ @@ -459,6 +459,7 @@ public function fillWithURI(string $uri, bool $isSteamTotp = false, bool $skipIc 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 2f100400..9a2c40da 100644 --- a/app/Services/Migrators/PlainTextMigrator.php +++ b/app/Services/Migrators/PlainTextMigrator.php @@ -23,7 +23,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) { @@ -35,7 +35,7 @@ public function migrate(mixed $migrationPayload) : Collection try { $twofaccounts[$key] = new TwoFAccount; - $twofaccounts[$key]->fillWithURI($uri); + $twofaccounts[$key]->fillWithURI($uri, str_starts_with($uri, 'otpauth://steam/')); } catch (\Exception $exception) {