diff --git a/composer.json b/composer.json index b51b1e0..2321393 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ ], "require": { "php": ">=5.3", + "ext-mcrypt": "*", "christian-riesen/base32": "~1", "eloquent/enumeration": "~4", "icecave/isolator": "~2" diff --git a/composer.lock b/composer.lock index cd75c86..c973941 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "41e7b0062b41224d2d3bb7a8f1807d7b", + "hash": "e5c2d2b5b7d786f466d8253fbd1f37ed", "packages": [ { "name": "christian-riesen/base32", @@ -1316,7 +1316,8 @@ "icecave/archer": 15 }, "platform": { - "php": ">=5.3" + "php": ">=5.3", + "ext-mcrypt": "*" }, "platform-dev": [ diff --git a/src/Eloquent/Otis/Configuration/CounterBasedOtpConfigurationInterface.php b/src/Eloquent/Otis/Configuration/CounterBasedOtpConfigurationInterface.php new file mode 100644 index 0000000..cb81568 --- /dev/null +++ b/src/Eloquent/Otis/Configuration/CounterBasedOtpConfigurationInterface.php @@ -0,0 +1,34 @@ +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; +} diff --git a/src/Eloquent/Otis/Parameters/Generator/CounterBasedOtpSharedParametersGeneratorInterface.php b/src/Eloquent/Otis/Parameters/Generator/CounterBasedOtpSharedParametersGeneratorInterface.php new file mode 100644 index 0000000..bc1ca17 --- /dev/null +++ b/src/Eloquent/Otis/Parameters/Generator/CounterBasedOtpSharedParametersGeneratorInterface.php @@ -0,0 +1,33 @@ +