|
|
|
|
@ -17,7 +17,7 @@ class UserManagement implements WorkflowInterface
|
|
|
|
|
private RequestInterface $ri,
|
|
|
|
|
private AntiCSRFInterface $csrf,
|
|
|
|
|
private SessionInterface $session,
|
|
|
|
|
private mixed $user_index,
|
|
|
|
|
private mixed $userIndex,
|
|
|
|
|
private HashInterface $hash,
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
@ -25,62 +25,62 @@ class UserManagement implements WorkflowInterface
|
|
|
|
|
|
|
|
|
|
function display()
|
|
|
|
|
{
|
|
|
|
|
echo $this->emit_str();
|
|
|
|
|
echo $this->emitStr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function view_enroll_form(): string
|
|
|
|
|
private function viewEnrollForm(): string
|
|
|
|
|
{
|
|
|
|
|
$html = "<div id=\"enroll\"><form %frm>";
|
|
|
|
|
$html .= $this->csrf->emit_str();
|
|
|
|
|
$html .= $this->csrf->emitStr();
|
|
|
|
|
$html .= "<p>To add an authenticator to your account, scan the QR code</p>";
|
|
|
|
|
$html .= "<img src=%qr alt=\"qr-code\" />";
|
|
|
|
|
$html .= "<label for=\"totp_challenge\">Enter the authentication code:</label>"
|
|
|
|
|
$html .= "<label for=\"totp_challenge\">Enter the authentication code:</label>";
|
|
|
|
|
$html .= "<input name=\"totp_challenge\" id=\"totp_challenge\" type=\"text\" >";
|
|
|
|
|
$html .= "<input type=\"submit\" value=\"Submit\" />";
|
|
|
|
|
$html .= "</form></div>";
|
|
|
|
|
|
|
|
|
|
$provisioning_uri = (new Otpauth(
|
|
|
|
|
$provisioningUri = (new Otpauth(
|
|
|
|
|
"taatp",
|
|
|
|
|
$this->userIndex,
|
|
|
|
|
$this->hash->keygen(),
|
|
|
|
|
"SHA1",
|
|
|
|
|
30,
|
|
|
|
|
6
|
|
|
|
|
))->emit_str();
|
|
|
|
|
$this->session->store("secret", $provisioning_uri);
|
|
|
|
|
))->emitStr();
|
|
|
|
|
$this->session->store("secret", $provisioningUri);
|
|
|
|
|
|
|
|
|
|
$values = [
|
|
|
|
|
"%frm" => $this->ri->form_props("enroll"),
|
|
|
|
|
"%qr" => (new QRCode)->render($provisioning_uri),
|
|
|
|
|
]
|
|
|
|
|
"%frm" => $this->ri->formProps("enroll"),
|
|
|
|
|
"%qr" => (new QRCode)->render($provisioningUri),
|
|
|
|
|
];
|
|
|
|
|
return \str_replace(\array_keys($values), $values, $html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function view_unenroll_form(): string
|
|
|
|
|
private function viewUnenrollForm(): string
|
|
|
|
|
{
|
|
|
|
|
$html = "<div id=\"unenroll\"><form %frm>";
|
|
|
|
|
$html .= $this->csrf->emit_str();
|
|
|
|
|
$html .= $this->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\" />";
|
|
|
|
|
$html .= "</form></div>";
|
|
|
|
|
|
|
|
|
|
$values = [
|
|
|
|
|
"%frm" => $this->ri->form_props("unenroll"),
|
|
|
|
|
"%frm" => $this->ri->formProps("unenroll"),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return \str_replace(\array_keys($values), $values, $html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function emit_str(): string
|
|
|
|
|
function emitStr(): string
|
|
|
|
|
{
|
|
|
|
|
if (\is_null($this->db->get_secret($this->user_index)))
|
|
|
|
|
if (\is_null($this->db->getSecret($this->userIndex)))
|
|
|
|
|
{
|
|
|
|
|
$this->view_enroll_form();
|
|
|
|
|
$this->viewEnrollForm();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$this->view_unenroll_form();
|
|
|
|
|
$this->viewUnenrollForm();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -91,30 +91,30 @@ class UserManagement implements WorkflowInterface
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$p_uri = $this->db->get_secret($this->user_index);
|
|
|
|
|
$p_uri = $this->db->getSecret($this->userIndex);
|
|
|
|
|
$enroll_flag = \is_null($p_uri);
|
|
|
|
|
$enroll_flag && $enroll_flag = $this->session->get('secret');
|
|
|
|
|
|
|
|
|
|
$totp = _6238(
|
|
|
|
|
$p_uri.secret,
|
|
|
|
|
$p_uri.period,
|
|
|
|
|
$enroll_flag? 0:$this->db->get_last_time($this->user_index),
|
|
|
|
|
$enroll_flag? 0:$this->db->getLastTime($this->userIndex),
|
|
|
|
|
2,
|
|
|
|
|
$p_uri.digits,
|
|
|
|
|
$this->clock,
|
|
|
|
|
$this->hash
|
|
|
|
|
);
|
|
|
|
|
$flag = $totp.validate($this->ri->get_resp("totp_challenge"));
|
|
|
|
|
$flag = $totp.validate($this->ri->getResp("totp_challenge"));
|
|
|
|
|
|
|
|
|
|
if($flag && $enroll_flag)
|
|
|
|
|
{
|
|
|
|
|
$this->db->store_last_time($this->user_index, $flag);
|
|
|
|
|
$this->db->store_secret($this->user_index, $p_uri);
|
|
|
|
|
$this->db->storeLastTime($this->userIndex, $flag);
|
|
|
|
|
$this->db->storeSecret($this->userIndex, $p_uri);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if($flag)
|
|
|
|
|
{
|
|
|
|
|
$this->db->strip_secret($this->user_index);
|
|
|
|
|
$this->db->stripSecret($this->userIndex);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|