瀏覽代碼

Fix #160 : Steam otpauth URIs are rejected by the Import feature

Bubka 2 年之前
父節點
當前提交
664bca3448
共有 3 個文件被更改,包括 7 次插入5 次删除
  1. 3 2
      app/Factories/MigratorFactory.php
  2. 2 1
      app/Models/TwoFAccount.php
  3. 2 2
      app/Services/Migrators/PlainTextMigrator.php

+ 3 - 2
app/Factories/MigratorFactory.php

@@ -67,12 +67,13 @@ class MigratorFactory implements MigratorFactoryInterface
      */
      */
     private function isPlainText(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(
         return Validator::make(
             preg_split('~\R~', $migrationPayload, -1 , PREG_SPLIT_NO_EMPTY),
             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();
         )->passes();
     }
     }

+ 2 - 1
app/Models/TwoFAccount.php

@@ -408,7 +408,7 @@ class TwoFAccount extends Model implements Sortable
     {
     {
         // First we instanciate the OTP generator
         // First we instanciate the OTP generator
         try {
         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) {
         catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) {
             throw ValidationException::withMessages([
             throw ValidationException::withMessages([
@@ -459,6 +459,7 @@ class TwoFAccount extends Model implements Sortable
     private function enforceAsSteam() : void
     private function enforceAsSteam() : void
     {
     {
         $this->otp_type  = self::STEAM_TOTP;
         $this->otp_type  = self::STEAM_TOTP;
+        $this->service   = 'Steam';
         $this->digits    = 5;
         $this->digits    = 5;
         $this->algorithm = self::SHA1;
         $this->algorithm = self::SHA1;
         $this->period    = 30;
         $this->period    = 30;

+ 2 - 2
app/Services/Migrators/PlainTextMigrator.php

@@ -23,7 +23,7 @@ class PlainTextMigrator extends Migrator
     {
     {
         $otpauthURIs = preg_split('~\R~', $migrationPayload);
         $otpauthURIs = preg_split('~\R~', $migrationPayload);
         $otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) {
         $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) {
         if (count($otpauthURIs) < 1) {
@@ -35,7 +35,7 @@ class PlainTextMigrator extends Migrator
 
 
             try {
             try {
                $twofaccounts[$key] = new TwoFAccount;
                $twofaccounts[$key] = new TwoFAccount;
-               $twofaccounts[$key]->fillWithURI($uri);
+               $twofaccounts[$key]->fillWithURI($uri, str_starts_with($uri, 'otpauth://steam/'));
             }
             }
             catch (\Exception $exception) {
             catch (\Exception $exception) {