diff --git a/src/Factory.php b/src/Factory.php index 52205ac..d229d38 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -15,7 +15,7 @@ class Factory { public function __construct( private PersistenceInterface $db, - private RequestInterface $ri, + private RequestInterface $request, private null|SessionInterface $session, private null|\PSR\Clock\ClockInterface $csrfClock, private null|AntiCSRFInterface $csrf, @@ -35,15 +35,15 @@ class Factory public function userManagement(mixed $userIndex): UserManagement { - return new UserManagement($this->db, $this->ri, $this->csrf, $this->session, $userIndex); + return new UserManagement($this->db, $this->request, $this->csrf, $this->session, $userIndex); } - public function authenticate(mixed $userIndex): null|Authenticate + public function authenticate(mixed $userIndex): ?Authenticate { if(\is_null($this->db->getSecret($userIndex))) return null; else - return new Authenticate($this->db, $this->ri, $this->csrf, $this->session, $userIndex); + return new Authenticate($this->db, $this->request, $this->csrf, $this->session, $userIndex); } } diff --git a/src/Hash/HMAC_SHA1.php b/src/Hash/HMAC_SHA1.php index 27d8767..05b7b5f 100644 --- a/src/Hash/HMAC_SHA1.php +++ b/src/Hash/HMAC_SHA1.php @@ -6,16 +6,16 @@ use ParagonIE\ConstantTime\Base32; class HMAC_SHA1 implements HashInterface { - DEFAULT_SECRET_SIZE = 32; - public function hash(string $k, string $v): string + const DEFAULT_SECRET_SIZE = 32; + public function hash(string $key, string $val): string { - $key = Base32::decode($k) - return \hash_hmac("sha1", \hex2bin($v), $key, true); + $key = Base32::decode($key); + return \hash_hmac("sha1", \hex2bin($val), $key, true); } - public function hashNumeric(string $k, int $v): string + public function hashNumeric(string $key, int $val): string { - return $this->hash($k, \dechex($v)); + return $this->hash($key, \dechex($val)); } public function hashType(): string diff --git a/src/Session/Base.php b/src/Session/Base.php index 0878e6c..0d3d50a 100644 --- a/src/Session/Base.php +++ b/src/Session/Base.php @@ -15,9 +15,9 @@ class Base implements SessionInterface return session_status() === PHP_SESSION_ACTIVE; } - public function tryStore(string $k, mixed $val): bool + public function tryStore(string $key, mixed $val): bool { - $key = $this->ns($k); + $key = $this->ns($key); if (!isset($_SESSION[$key])) { $_SESSION[$key] = $val; diff --git a/src/Workflow/Authenticate.php b/src/Workflow/Authenticate.php index 9af1021..49a4e2a 100644 --- a/src/Workflow/Authenticate.php +++ b/src/Workflow/Authenticate.php @@ -12,7 +12,7 @@ class Authenticate implements WorkflowInterface { public function __construct( private PersistenceInterface $db, - private RequestInterface $ri, + private RequestInterface $request, private AntiCSRFInterface $csrf, private SessionInterface $session, private mixed $userIndex, @@ -49,14 +49,14 @@ class Authenticate implements WorkflowInterface return false; } - $p_uri = $this->db->getSecret($this->userIndex); + $pUri = $this->db->getSecret($this->userIndex); $totp = _6238( - $p_uri.secret, - $p_uri.period, + $pUri.secret, + $pUri.period, $this->db->getLastTime($this->userIndex), 2, - $p_uri.digits, + $pUri.digits, $this->clock, $this->hash ); diff --git a/src/Workflow/UserManagement.php b/src/Workflow/UserManagement.php index 7463da4..953bd55 100644 --- a/src/Workflow/UserManagement.php +++ b/src/Workflow/UserManagement.php @@ -14,7 +14,7 @@ class UserManagement implements WorkflowInterface { public function __construct( private PersistenceInterface $db, - private RequestInterface $ri, + private RequestInterface $request, private AntiCSRFInterface $csrf, private SessionInterface $session, private mixed $userIndex, @@ -78,10 +78,7 @@ class UserManagement implements WorkflowInterface { $this->viewEnrollForm(); } - else - { - $this->viewUnenrollForm(); - } + $this->viewUnenrollForm(); } function response(): bool @@ -91,25 +88,25 @@ class UserManagement implements WorkflowInterface return false; } - $p_uri = $this->db->getSecret($this->userIndex); - $enroll_flag = \is_null($p_uri); - $enroll_flag && $enroll_flag = $this->session->get('secret'); + $pUri = $this->db->getSecret($this->userIndex); + $enrollFlag = \is_null($pUri); + $enrollFlag && $enrollFlag = $this->session->get('secret'); $totp = _6238( - $p_uri.secret, - $p_uri.period, - $enroll_flag? 0:$this->db->getLastTime($this->userIndex), + $pUri.secret, + $pUri.period, + $enrollFlag? 0:$this->db->getLastTime($this->userIndex), 2, - $p_uri.digits, + $pUri.digits, $this->clock, $this->hash ); $flag = $totp.validate($this->ri->getResp("totp_challenge")); - if($flag && $enroll_flag) + if($flag && $enrollFlag) { $this->db->storeLastTime($this->userIndex, $flag); - $this->db->storeSecret($this->userIndex, $p_uri); + $this->db->storeSecret($this->userIndex, $pUri); return true; } else if($flag)