parent
8b2d419cbb
commit
f94331397d
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BradyMcD\TAATP;
|
||||
|
||||
use Psr\Clock\ClockInterface;
|
||||
use BradyMcD\TAATP\HashInterface;
|
||||
|
||||
use BradyMcD\TAATP\Clock\Base as Clock;
|
||||
use BradyMcD\TAATP\Hash\BuiltinHash;
|
||||
|
||||
/**
|
||||
* Configures the behaviour of the totp algorithm for newly enrolling users
|
||||
*/
|
||||
class HashConfig
|
||||
{
|
||||
public function __construct(
|
||||
public HashInterface|string $algorithm="SHA1",
|
||||
public ClockInterface $clock=new Clock,
|
||||
public int $period=30,
|
||||
public int $digits=6
|
||||
)
|
||||
{
|
||||
if (\is_string($this->hash))
|
||||
{
|
||||
$this->hash = new BuiltinHash($this->hash);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Google Authenticator app does not handle customization to the hash function
|
||||
* In testing as of February 2024 it would not accept otpauth URIs with any field beyond
|
||||
the secret and issuer, failing with a generic error message
|
||||
* Currently this is the same as the default constructor but is future proof.
|
||||
*/
|
||||
public static function googleAuthenticator(): TotpConfig
|
||||
{
|
||||
return new Self(
|
||||
"SHA1",
|
||||
new Clock(),
|
||||
30,
|
||||
6,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,56 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/** @SuppressWarnings(PHPMD.DevelopmentCodeFragment)*/
|
||||
class Base implements LoggerInterface
|
||||
{
|
||||
public function emergency(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function alert(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function critical(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function error(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function warning(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function notice(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function info(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function debug(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
public function log(string $message, array $context = array())
|
||||
{
|
||||
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,38 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BradyMcD\TAATP;
|
||||
|
||||
use BradyMcD\TAATP\AntiCSRFInterface;
|
||||
use Psr\Clock\ClockInterface;
|
||||
use BradyMcD\TAATP\HashInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use BradyMcD\TAATP\Required\PersistenceInterface;
|
||||
use BradyMcD\TAATP\Required\RequestInterface;
|
||||
use BradyMcD\TAATP\SessionInterface;
|
||||
|
||||
use BradyMcD\TAATP\AntiCSRF\Base as AntiCSRF;
|
||||
use BradyMcD\TAATP\Clock\Request as RequestClock;
|
||||
use BradyMcD\TAATP\Clock\Base as Clock;
|
||||
use BradyMcD\TAATP\Hash\HMAC_SHA1;
|
||||
use BradyMcD\TAATP\Logger\Base as Logger;
|
||||
use BradyMcD\TAATP\Session\Base as Session;
|
||||
|
||||
/**
|
||||
* Configures the behaviour of the module overall
|
||||
*/
|
||||
class ModuleConfig
|
||||
{
|
||||
public function __construct(
|
||||
public LoggerInterface $logger=new Logger,
|
||||
public SessionInterface $session=new Session,
|
||||
public ?AntiCSRFInterface $csrf=null,
|
||||
)
|
||||
{
|
||||
!\is_null($this->csrf) ? : $this->csrf = new AntiCSRF(
|
||||
$this->session,
|
||||
new RequestClock()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in new issue