86 lines
1.6 KiB
PHP
86 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace alveolata\auth;
|
|
|
|
require_once(DIR_ALVEOLATA . '/auth/abstract/interface-server.php');
|
|
require_once(DIR_ALVEOLATA . '/auth/implementation-srp/functions-server.php');
|
|
|
|
|
|
/**
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
*/
|
|
class implementation_server_srp implements interface_server
|
|
{
|
|
|
|
/**
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
*/
|
|
public function __construct(
|
|
struct_srp_subject $subject,
|
|
\Closure $registration_handle,
|
|
\Closure $get_salt_and_verifier,
|
|
\Closure $state_save,
|
|
\Closure $state_load
|
|
)
|
|
{
|
|
$this->subject = $subject;
|
|
$this->registration_handle = $registration_handle;
|
|
$this->get_salt_and_verifier = $get_salt_and_verifier;
|
|
$this->state_save = $state_save;
|
|
$this->state_load = $state_load;
|
|
}
|
|
|
|
|
|
/**
|
|
* @implementation
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
*/
|
|
public function register(
|
|
string $username,
|
|
string $password
|
|
) : bool
|
|
{
|
|
$proc = srp_server_register(
|
|
$this->registration_handle
|
|
);
|
|
return $proc($username, $password);
|
|
}
|
|
|
|
|
|
/**
|
|
* @implementation
|
|
* @author Christian Fraß <frass@greenscale.de>
|
|
*/
|
|
public function login(
|
|
string $kind,
|
|
$parameters
|
|
) : bool
|
|
{
|
|
switch ($kind) {
|
|
default: {
|
|
throw (new \Exception('unhandled'));
|
|
break;
|
|
}
|
|
case 'step1': {
|
|
$proc = srp_server_login_1(
|
|
$this->subject,
|
|
$this->state_save,
|
|
$this->get_salt_and_verifier
|
|
);
|
|
return $proc($username, $password);
|
|
break;
|
|
}
|
|
case 'step2': {
|
|
$proc = srp_server_login_1(
|
|
$this->subject,
|
|
$this->state_load
|
|
);
|
|
return $proc($username, $password);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
?>
|