Naming efactor 2

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

@ -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);
}
}

@ -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

@ -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;

@ -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
);

@ -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,11 +78,8 @@ class UserManagement implements WorkflowInterface
{
$this->viewEnrollForm();
}
else
{
$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)

Loading…
Cancel
Save