Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_2fa/lib/Kolab2FA/Driver/Yubikey.php
Show All 21 Lines | |||||
*/ | */ | ||||
namespace Kolab2FA\Driver; | namespace Kolab2FA\Driver; | ||||
class Yubikey extends Base | class Yubikey extends Base | ||||
{ | { | ||||
public $method = 'yubikey'; | public $method = 'yubikey'; | ||||
protected $config = array( | |||||
'clientid' => '42', | |||||
'apikey' => 'FOOBAR=', | |||||
'hosts' => null, | |||||
); | |||||
protected $backend; | protected $backend; | ||||
/** | /** | ||||
* | * | ||||
*/ | */ | ||||
public function init(array $config) | public function init(array $config) | ||||
{ | { | ||||
parent::init($config); | parent::init($config); | ||||
$this->user_settings += array( | $this->user_settings += array( | ||||
'yubikeyid' => array( | 'yubikeyid' => array( | ||||
'type' => 'text', | 'type' => 'text', | ||||
'editable' => true, | 'editable' => true, | ||||
'label' => 'secret', | 'label' => 'secret', | ||||
), | ), | ||||
); | ); | ||||
// initialize validator | // initialize validator | ||||
$this->backend = new \Yubikey\Validate($this->config['apikey'], $this->config['clientid']); | $this->backend = new \Yubikey\Validate($this->config['apikey'], $this->config['clientid']); | ||||
// set configured validation hosts | // set configured validation hosts | ||||
if (!empty($this->config['hosts'])) { | if (!empty($this->config['hosts'])) { | ||||
$this->backend->setHosts((array)$this->config['hosts']); | $this->backend->setHosts((array)$this->config['hosts']); | ||||
} | } | ||||
if (isset($this->config['use_https'])) { | |||||
$this->backend->setUseSecure((bool)$this->config['use_https']); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* | * | ||||
*/ | */ | ||||
public function verify($code, $timestamp = null) | public function verify($code, $timestamp = null) | ||||
{ | { | ||||
// get my secret from the user storage | // get my secret from the user storage | ||||
Show All 11 Lines | public function verify($code, $timestamp = null) | ||||
$response = $this->backend->check($code); | $response = $this->backend->check($code); | ||||
$pass = $response->success() === true; | $pass = $response->success() === true; | ||||
} | } | ||||
catch (\Exception $e) { | catch (\Exception $e) { | ||||
// TODO: log exception | // TODO: log exception | ||||
} | } | ||||
} | } | ||||
// rcube::console('VERIFY TOTP', $this->username, $keyid, $code, $pass); | // rcube::console('VERIFY Yubikey', $this->username, $keyid, $code, $pass); | ||||
return $pass; | return $pass; | ||||
} | } | ||||
/** | /** | ||||
* @override | * @override | ||||
*/ | */ | ||||
public function set($key, $value) | public function set($key, $value) | ||||
{ | { | ||||
Show All 33 Lines |