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

This commit is contained in:
Bubka 2023-01-25 13:12:03 +01:00
parent b4fe966557
commit 664bca3448
3 changed files with 7 additions and 5 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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) {