Fixed syntax, other errors

master
Brady McDonough 2 years ago
parent 37e0836149
commit 3078c0501a

@ -1,6 +1,7 @@
<?php declare(strict_types=1);
namespace BradyMcD\TAATP\Hash;
use BradyMcD\TAATP\HashInterface;
use ParagonIE\ConstantTime\Base32;
@ -12,7 +13,7 @@ class BuiltinHash implements HashInterface
public function __construct(private readonly string $hashName)
{
(\array_search($this->hashName, \hash_hmac_algos())) ? : throw \ValueError(
(\array_search(\strtolower($this->hashName), \hash_hmac_algos())) ? : throw new \ValueError(
$this->hashName . " is not the name of a built-in hash function");
}

@ -20,9 +20,9 @@ class HashConfig
public int $digits=6
)
{
if (\is_string($this->hash))
if (\is_string($this->algorithm))
{
$this->hash = new BuiltinHash($this->hash);
$this->algorithm = new BuiltinHash($this->algorithm);
}
}

@ -1,51 +1,53 @@
<?php declare(strict_types=1);
namespace BradyMcD\TAATP\Logger;
use Psr\Log\LoggerInterface;
/** @SuppressWarnings(PHPMD.DevelopmentCodeFragment)*/
class Base implements LoggerInterface
{
public function emergency(string $message, array $context = array())
public function emergency(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
}
public function alert(string $message, array $context = array())
public function alert(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
}
public function critical(string $message, array $context = array())
public function critical(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
}
public function error(string $message, array $context = array())
public function error(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
}
public function warning(string $message, array $context = array())
public function warning(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDERR, $message . \print_r($context, true) . PHP_EOL);
}
public function notice(string $message, array $context = array())
public function notice(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
}
public function info(string $message, array $context = array())
public function info(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
}
public function debug(string $message, array $context = array())
public function debug(\Stringable|string $message, array $context = array()):void
{
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
}
public function log(string $message, array $context = array())
public function log($level, \Stringable|string $message, array $context = array()):void
{
\fwrite(STDOUT, $message . \print_r($context, true) . PHP_EOL);
}

@ -34,7 +34,7 @@ class UserManagement implements WorkflowInterface
private function viewEnrollForm(): string
{
$html = "<div id=\"enroll\"><form %frm>";
$html .= $this->moduleConfig.csrf->emitStr();
$html .= $this->moduleConfig->csrf->emitStr();
$html .= "<p>To add an authenticator to your account, scan the QR code</p>";
$html .= "<img src=%qr alt=\"qr-code\" height=256px width=256px/>";
$html .= "<label for=\"totp_challenge\">Enter the authentication code:</label>";
@ -45,14 +45,14 @@ class UserManagement implements WorkflowInterface
$otpauthURI = new Otpauth(
$this->db->userString($this->userIndex),
"taaatp",
$this->hashConfig.hash->keygen(),
$this->hashConfig.hash->hashType(),
$this->hashConfig->algorithm->keygen(),
$this->hashConfig->algorithm->hashType(),
6,
30
);
$provisioningUri = $otpauthURI->uriString();
$persistentUri = $otpauthURI->uriStringExplicit();
$this->moduleConfig.session->store("secret", $persistentUri);
$this->moduleConfig->session->store("secret", $persistentUri);
$values = [
"%frm" => $this->request->formProps("enroll"),
@ -64,7 +64,7 @@ class UserManagement implements WorkflowInterface
private function viewUnenrollForm(): string
{
$html = "<div id=\"unenroll\"><form %frm>";
$html .= $this->moduleConfig.csrf->emitStr();
$html .= $this->moduleConfig->csrf->emitStr();
$html .= "<label for=\"totp_challenge\">To de-register your authenticator enter the current authentication code:</label>";
$html .= "<intput name=\"totp_challenge\" id=\"totp_challenge\" type\"text\" />";
$html .= "<input type=\"submit\" value=\"Submit\" />";
@ -88,17 +88,16 @@ class UserManagement implements WorkflowInterface
function response(): bool
{
if (!$this->moduleConfig.csrf->match())
if (!$this->moduleConfig->csrf->match())
{
return false;
}
$pUri = $this->db->getSecret($this->userIndex);
$enrollFlag = \is_null($pUri);
$enrollFlag && $pUri = $this->moduleConfig.session->get('secret');
echo "Recovered pURI for a " . ($enrollFlag)?"new user":"returning user";
$enrollFlag && $pUri = $this->moduleConfig->session->get('secret');
$this->moduleConfig->logger->info("Recovered pURI for a " . ($enrollFlag)?"new user":"returning user");
$totp = _6238(
$pUri->getSecret(),
@ -106,8 +105,8 @@ class UserManagement implements WorkflowInterface
$enrollFlag? 0:$this->db->getLastTime($this->userIndex),
2,
$pUri.digits,
$this->hashConfig.clock,
$this->hashConfig.algorithm
$this->hashConfig->clock,
$this->hashConfig->algorithm
);
$flag = $totp.validate($this->request->getResp("totp_challenge"));

Loading…
Cancel
Save