Naming efactor 2

master
Brady McDonough 2 years ago
parent 0a47684a74
commit 9f12ff2fd4

@ -15,7 +15,7 @@ class Factory
{ {
public function __construct( public function __construct(
private PersistenceInterface $db, private PersistenceInterface $db,
private RequestInterface $ri, private RequestInterface $request,
private null|SessionInterface $session, private null|SessionInterface $session,
private null|\PSR\Clock\ClockInterface $csrfClock, private null|\PSR\Clock\ClockInterface $csrfClock,
private null|AntiCSRFInterface $csrf, private null|AntiCSRFInterface $csrf,
@ -35,15 +35,15 @@ class Factory
public function userManagement(mixed $userIndex): UserManagement 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))) if(\is_null($this->db->getSecret($userIndex)))
return null; return null;
else 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);
} }
} }

@ -6,16 +6,16 @@ use ParagonIE\ConstantTime\Base32;
class HMAC_SHA1 implements HashInterface class HMAC_SHA1 implements HashInterface
{ {
DEFAULT_SECRET_SIZE = 32; const DEFAULT_SECRET_SIZE = 32;
public function hash(string $k, string $v): string public function hash(string $key, string $val): string
{ {
$key = Base32::decode($k) $key = Base32::decode($key);
return \hash_hmac("sha1", \hex2bin($v), $key, true); 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 public function hashType(): string

@ -15,9 +15,9 @@ class Base implements SessionInterface
return session_status() === PHP_SESSION_ACTIVE; 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])) if (!isset($_SESSION[$key]))
{ {
$_SESSION[$key] = $val; $_SESSION[$key] = $val;

@ -12,7 +12,7 @@ class Authenticate implements WorkflowInterface
{ {
public function __construct( public function __construct(
private PersistenceInterface $db, private PersistenceInterface $db,
private RequestInterface $ri, private RequestInterface $request,
private AntiCSRFInterface $csrf, private AntiCSRFInterface $csrf,
private SessionInterface $session, private SessionInterface $session,
private mixed $userIndex, private mixed $userIndex,
@ -49,14 +49,14 @@ class Authenticate implements WorkflowInterface
return false; return false;
} }
$p_uri = $this->db->getSecret($this->userIndex); $pUri = $this->db->getSecret($this->userIndex);
$totp = _6238( $totp = _6238(
$p_uri.secret, $pUri.secret,
$p_uri.period, $pUri.period,
$this->db->getLastTime($this->userIndex), $this->db->getLastTime($this->userIndex),
2, 2,
$p_uri.digits, $pUri.digits,
$this->clock, $this->clock,
$this->hash $this->hash
); );

@ -14,7 +14,7 @@ class UserManagement implements WorkflowInterface
{ {
public function __construct( public function __construct(
private PersistenceInterface $db, private PersistenceInterface $db,
private RequestInterface $ri, private RequestInterface $request,
private AntiCSRFInterface $csrf, private AntiCSRFInterface $csrf,
private SessionInterface $session, private SessionInterface $session,
private mixed $userIndex, private mixed $userIndex,
@ -78,10 +78,7 @@ class UserManagement implements WorkflowInterface
{ {
$this->viewEnrollForm(); $this->viewEnrollForm();
} }
else $this->viewUnenrollForm();
{
$this->viewUnenrollForm();
}
} }
function response(): bool function response(): bool
@ -91,25 +88,25 @@ class UserManagement implements WorkflowInterface
return false; return false;
} }
$p_uri = $this->db->getSecret($this->userIndex); $pUri = $this->db->getSecret($this->userIndex);
$enroll_flag = \is_null($p_uri); $enrollFlag = \is_null($pUri);
$enroll_flag && $enroll_flag = $this->session->get('secret'); $enrollFlag && $enrollFlag = $this->session->get('secret');
$totp = _6238( $totp = _6238(
$p_uri.secret, $pUri.secret,
$p_uri.period, $pUri.period,
$enroll_flag? 0:$this->db->getLastTime($this->userIndex), $enrollFlag? 0:$this->db->getLastTime($this->userIndex),
2, 2,
$p_uri.digits, $pUri.digits,
$this->clock, $this->clock,
$this->hash $this->hash
); );
$flag = $totp.validate($this->ri->getResp("totp_challenge")); $flag = $totp.validate($this->ri->getResp("totp_challenge"));
if($flag && $enroll_flag) if($flag && $enrollFlag)
{ {
$this->db->storeLastTime($this->userIndex, $flag); $this->db->storeLastTime($this->userIndex, $flag);
$this->db->storeSecret($this->userIndex, $p_uri); $this->db->storeSecret($this->userIndex, $pUri);
return true; return true;
} }
else if($flag) else if($flag)

Loading…
Cancel
Save