Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
Committing incomplete ideas.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Sep 20, 2013
1 parent 4d99abe commit 6bdf432
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 16 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -13,6 +13,7 @@
],
"require": {
"php": ">=5.3",
"ext-mcrypt": "*",
"christian-riesen/base32": "~1",
"eloquent/enumeration": "~4",
"icecave/isolator": "~2"
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -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();
}
Expand Up @@ -11,22 +11,13 @@

namespace Eloquent\Otis\Hotp\Configuration;

use Eloquent\Otis\Configuration\CounterBasedOtpConfigurationInterface;

/**
* The interface implemented by HOTP configurations.
*/
interface HotpConfigurationInterface extends HotpBasedConfigurationInterface
interface HotpConfigurationInterface extends
HotpBasedConfigurationInterface,
CounterBasedOtpConfigurationInterface
{
/**
* 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();
}
@@ -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;
}
@@ -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
);
}
@@ -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);
}

0 comments on commit 6bdf432

Please sign in to comment.