This repository has been archived by the owner on Mar 27, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
208 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/Eloquent/Otis/Configuration/CounterBasedOtpConfigurationInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Otis package. | ||
* | ||
* Copyright © 2013 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Otis\Configuration; | ||
|
||
/** | ||
* The interface implemented by counter-based one-time password multi-factor | ||
* authentication configurations. | ||
*/ | ||
interface CounterBasedOtpConfigurationInterface extends | ||
MfaConfigurationInterface | ||
{ | ||
/** | ||
* Get the amount of counter increments to search through for a match. | ||
* | ||
* @return integer The amount of counter increments to search through for a match. | ||
*/ | ||
public function window(); | ||
|
||
/** | ||
* Get the initial counter value. | ||
* | ||
* @return integer The initial counter value. | ||
*/ | ||
public function initialCounter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/Eloquent/Otis/Parameters/Generator/CounterBasedOtpSharedParametersGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Otis package. | ||
* | ||
* Copyright © 2013 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Otis\Parameters\Generator; | ||
|
||
use Eloquent\Otis\Configuration\MfaConfigurationInterface; | ||
use Eloquent\Otis\Exception\UnsupportedArgumentsException; | ||
use Eloquent\Otis\Parameters\MfaSharedParametersInterface; | ||
use Icecave\Isolator\Isolator; | ||
|
||
/** | ||
* Generates counter-based one-time password shared parameters. | ||
*/ | ||
class CounterBasedOtpSharedParametersGenerator implements | ||
MfaSharedParametersGeneratorInterface, | ||
CounterBasedOtpSharedParametersGeneratorInterface | ||
{ | ||
/** | ||
* Construct a new counter-based one-time password shared parameter generator. | ||
* | ||
* @param Isolator|null $isolator The isolator to use. | ||
*/ | ||
public function __construct(Isolator $isolator = null) | ||
{ | ||
$this->isolator = Isolator::get($isolator); | ||
} | ||
|
||
/** | ||
* Returns true if this generator supports the supplied configuration. | ||
* | ||
* @param MfaConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return boolean True if the configuration is supported. | ||
*/ | ||
public function supports(MfaConfigurationInterface $configuration) | ||
{ | ||
return $configuration instanceof CounterBasedOtpConfigurationInterface; | ||
} | ||
|
||
/** | ||
* Generate a set of shared parameters. | ||
* | ||
* @param MfaConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return MfaSharedParametersInterface The generated shared parameters. | ||
* @throws UnsupportedArgumentsException If the configuration type is not supported. | ||
*/ | ||
public function generate(MfaConfigurationInterface $configuration) | ||
{ | ||
if (!$this->supports($configuration)) { | ||
throw new UnsupportedArgumentsException; | ||
} | ||
|
||
return $this->generateCounterBased($configuration); | ||
} | ||
|
||
/** | ||
* Generate a set of counter-based one-time password shared parameters. | ||
* | ||
* @param CounterBasedOtpConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return CounterBasedOtpSharedParametersInterface The generated shared parameters. | ||
*/ | ||
public function generateCounterBased( | ||
CounterBasedOtpConfigurationInterface $configuration | ||
) { | ||
return new CounterBasedOtpSharedParameters( | ||
$this->isolator()->mcrypt_create_iv($configuration->secretLength()) | ||
); | ||
} | ||
|
||
/** | ||
* Get the isolator. | ||
* | ||
* @return Isolator The isolator. | ||
*/ | ||
public function isolator() | ||
{ | ||
return $this->isolator; | ||
} | ||
|
||
private $isolator; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Eloquent/Otis/Parameters/Generator/CounterBasedOtpSharedParametersGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Otis package. | ||
* | ||
* Copyright © 2013 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Otis\Parameters\Generator; | ||
|
||
use Eloquent\Otis\Configuration\CounterBasedOtpConfigurationInterface; | ||
use Eloquent\Otis\Parameters\CounterBasedOtpSharedParametersInterface; | ||
|
||
/** | ||
* The interface implemented by counter-based one-time password multi-factor | ||
* authentication shared parameter generators. | ||
*/ | ||
interface CounterBasedOtpSharedParametersGeneratorInterface | ||
{ | ||
/** | ||
* Generate a set of counter-based one-time password shared parameters. | ||
* | ||
* @param CounterBasedOtpConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return CounterBasedOtpSharedParametersInterface The generated shared parameters. | ||
*/ | ||
public function generateCounterBased( | ||
CounterBasedOtpConfigurationInterface $configuration | ||
); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Eloquent/Otis/Parameters/Generator/MfaSharedParametersGeneratorInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Otis package. | ||
* | ||
* Copyright © 2013 Erin Millard | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Eloquent\Otis\Parameters\Generator; | ||
|
||
use Eloquent\Otis\Configuration\MfaConfigurationInterface; | ||
use Eloquent\Otis\Parameters\MfaSharedParametersInterface; | ||
|
||
/** | ||
* The interface implemented by multi-factor authentication shared parameter | ||
* generators. | ||
*/ | ||
interface MfaSharedParametersGeneratorInterface | ||
{ | ||
/** | ||
* Returns true if this generator supports the supplied configuration. | ||
* | ||
* @param MfaConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return boolean True if the configuration is supported. | ||
*/ | ||
public function supports(MfaConfigurationInterface $configuration); | ||
|
||
/** | ||
* Generate a set of shared parameters. | ||
* | ||
* @param MfaConfigurationInterface $configuration The configuration to generate shared parameters for. | ||
* | ||
* @return MfaSharedParametersInterface The generated shared parameters. | ||
* @throws UnsupportedArgumentsException If the configuration type is not supported. | ||
*/ | ||
public function generate(MfaConfigurationInterface $configuration); | ||
} |