ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_authYubiKey_Auth_Source_YubiKey Class Reference
+ Inheritance diagram for sspmod_authYubiKey_Auth_Source_YubiKey:
+ Collaboration diagram for sspmod_authYubiKey_Auth_Source_YubiKey:

Public Member Functions

 __construct ($info, $config)
 Constructor for this authentication source. More...
 
 authenticate (&$state)
 Initialize login. More...
 
- Public Member Functions inherited from SimpleSAML_Auth_Source
 __construct ($info, &$config)
 Constructor for an authentication source. More...
 
 getAuthId ()
 Retrieve the ID of this authentication source. More...
 
 authenticate (&$state)
 Process a request. More...
 
 reauthenticate (array &$state)
 Reauthenticate an user. More...
 
 initLogin ($return, $errorURL=null, array $params=array())
 Start authentication. More...
 
 logout (&$state)
 Log out from this authentication source. More...
 

Static Public Member Functions

static handleLogin ($authStateId, $otp)
 Handle login request. More...
 
static getYubiKeyPrefix ($otp)
 Return the user id part of a one time passord. More...
 
- Static Public Member Functions inherited from SimpleSAML_Auth_Source
static getSourcesOfType ($type)
 Get sources of a specific type. More...
 
static completeAuth (&$state)
 Complete authentication. More...
 
static loginCompleted ($state)
 Called when a login operation has finished. More...
 
static completeLogout (&$state)
 Complete logout. More...
 
static getById ($authId, $type=null)
 Retrieve authentication source. More...
 
static logoutCallback ($state)
 Called when the authentication source receives an external logout request. More...
 
static getSources ()
 Retrieve list of authentication sources. More...
 

Data Fields

const STAGEID = 'sspmod_authYubiKey_Auth_Source_YubiKey.state'
 The string used to identify our states. More...
 
const TOKENSIZE = 32
 The number of characters of the OTP that is the secure token. More...
 
const AUTHID = 'sspmod_authYubiKey_Auth_Source_YubiKey.AuthId'
 The key of the AuthId field in the state. More...
 

Protected Member Functions

 login ($otp)
 Attempt to log in using the given username and password. More...
 
- Protected Member Functions inherited from SimpleSAML_Auth_Source
 addLogoutCallback ($assoc, $state)
 Add a logout callback association. More...
 
 callLogoutCallback ($assoc)
 Call a logout callback based on association. More...
 

Private Attributes

 $yubi_id
 The client id/key for use with the Auth_Yubico PHP module. More...
 
 $yubi_key
 

Additional Inherited Members

- Static Protected Member Functions inherited from SimpleSAML_Auth_Source
static validateSource ($source, $id)
 Make sure that the first element of an auth source is its identifier. More...
 
- Protected Attributes inherited from SimpleSAML_Auth_Source
 $authId
 

Detailed Description

Definition at line 43 of file YubiKey.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_authYubiKey_Auth_Source_YubiKey::__construct (   $info,
  $config 
)

Constructor for this authentication source.

Parameters
array$infoInformation about this authentication source.
array$configConfiguration.

Definition at line 73 of file YubiKey.php.

References $config, and $info.

74  {
75  assert(is_array($info));
76  assert(is_array($config));
77 
78  // Call the parent constructor first, as required by the interface
79  parent::__construct($info, $config);
80 
81  if (array_key_exists('id', $config)) {
82  $this->yubi_id = $config['id'];
83  }
84 
85  if (array_key_exists('key', $config)) {
86  $this->yubi_key = $config['key'];
87  }
88  }
$config
Definition: bootstrap.php:15
$info
Definition: index.php:5

Member Function Documentation

◆ authenticate()

sspmod_authYubiKey_Auth_Source_YubiKey::authenticate ( $state)

Initialize login.

This function saves the information about the login, and redirects to a login page.

Parameters
array&$stateInformation about the current authentication.

Definition at line 99 of file YubiKey.php.

References SimpleSAML_Auth_Source\$authId, $id, $state, $url, SimpleSAML\Module\getModuleURL(), SimpleSAML\Utils\HTTP\redirectTrustedURL(), and SimpleSAML_Auth_State\saveState().

100  {
101  assert(is_array($state));
102 
103  // We are going to need the authId in order to retrieve this authentication source later
104  $state[self::AUTHID] = $this->authId;
105 
106  $id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
107  $url = SimpleSAML\Module::getModuleURL('authYubiKey/yubikeylogin.php');
108  \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('AuthState' => $id));
109  }
if(!array_key_exists('StateId', $_REQUEST)) $id
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:959
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:220
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
$url
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
+ Here is the call graph for this function:

◆ getYubiKeyPrefix()

static sspmod_authYubiKey_Auth_Source_YubiKey::getYubiKeyPrefix (   $otp)
static

Return the user id part of a one time passord.

Definition at line 164 of file YubiKey.php.

165  {
166  $uid = substr($otp, 0, strlen ($otp) - self::TOKENSIZE);
167  return $uid;
168  }

◆ handleLogin()

static sspmod_authYubiKey_Auth_Source_YubiKey::handleLogin (   $authStateId,
  $otp 
)
static

Handle login request.

This function is used by the login form (core/www/loginuserpass.php) when the user enters a username and password. On success, it will not return. On wrong username/password failure, it will return the error code. Other failures will throw an exception.

Parameters
string$authStateIdThe identifier of the authentication state.
string$otpThe one time password entered-
Returns
string Error code in the case of an error.

Definition at line 124 of file YubiKey.php.

References $attributes, $authStateId, $source, $state, SimpleSAML_Auth_Source\completeAuth(), SimpleSAML_Auth_Source\getById(), SimpleSAML_Error_Error\getErrorCode(), and SimpleSAML_Auth_State\loadState().

125  {
126  assert(is_string($authStateId));
127  assert(is_string($otp));
128 
129  /* Retrieve the authentication state. */
131 
132  /* Find authentication source. */
133  assert(array_key_exists(self::AUTHID, $state));
135  if ($source === null) {
136  throw new Exception('Could not find authentication source with id '.$state[self::AUTHID]);
137  }
138 
139  try {
140  /* Attempt to log in. */
141  $attributes = $source->login($otp);
142  } catch (SimpleSAML_Error_Error $e) {
143  /* An error occurred during login. Check if it is because of the wrong
144  * username/password - if it is, we pass that error up to the login form,
145  * if not, we let the generic error handler deal with it.
146  */
147  if ($e->getErrorCode() === 'WRONGUSERPASS') {
148  return 'WRONGUSERPASS';
149  }
150 
151  /* Some other error occurred. Rethrow exception and let the generic error
152  * handler deal with it.
153  */
154  throw $e;
155  }
156 
157  $state['Attributes'] = $attributes;
159  }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
static completeAuth(&$state)
Complete authentication.
Definition: Source.php:136
$source
Definition: linkback.php:22
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:340
if(!array_key_exists('AuthState', $_REQUEST)) $authStateId
getErrorCode()
Retrieve the error code given when throwing this error.
Definition: Error.php:120
+ Here is the call graph for this function:

◆ login()

sspmod_authYubiKey_Auth_Source_YubiKey::login (   $otp)
protected

Attempt to log in using the given username and password.

On a successful login, this function should return the users attributes. On failure, it should throw an exception. If the error was caused by the user entering the wrong username or password, a SimpleSAML_Error_Error('WRONGUSERPASS') should be thrown.

Note that both the username and the password are UTF-8 encoded.

Parameters
string$otp
Returns
array Associative array with the users attributes.

Definition at line 182 of file YubiKey.php.

References $attributes, and SimpleSAML\Logger\info().

183  {
184  assert(is_string($otp));
185 
186  require_once dirname(dirname(dirname(dirname(__FILE__)))).'/libextinc/Yubico.php';
187 
188  try {
189  $yubi = new Auth_Yubico($this->yubi_id, $this->yubi_key);
190  $yubi->verify($otp);
191  $uid = self::getYubiKeyPrefix($otp);
192  $attributes = array('uid' => array($uid));
193  } catch (Exception $e) {
194  SimpleSAML\Logger::info('YubiKey:'.$this->authId.': Validation error (otp '.$otp.'), debug output: '.$yubi->getLastResponse());
195  throw new SimpleSAML_Error_Error('WRONGUSERPASS', $e);
196  }
197 
198  SimpleSAML\Logger::info('YubiKey:'.$this->authId.': YubiKey otp '.$otp.' validated successfully: '.$yubi->getLastResponse());
199  return $attributes;
200  }
static info($string)
Definition: Logger.php:199
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
+ Here is the call graph for this function:

Field Documentation

◆ $yubi_id

sspmod_authYubiKey_Auth_Source_YubiKey::$yubi_id
private

The client id/key for use with the Auth_Yubico PHP module.

Definition at line 64 of file YubiKey.php.

◆ $yubi_key

sspmod_authYubiKey_Auth_Source_YubiKey::$yubi_key
private

Definition at line 65 of file YubiKey.php.

◆ AUTHID

const sspmod_authYubiKey_Auth_Source_YubiKey::AUTHID = 'sspmod_authYubiKey_Auth_Source_YubiKey.AuthId'

The key of the AuthId field in the state.

Definition at line 59 of file YubiKey.php.

◆ STAGEID

const sspmod_authYubiKey_Auth_Source_YubiKey::STAGEID = 'sspmod_authYubiKey_Auth_Source_YubiKey.state'

The string used to identify our states.

Definition at line 48 of file YubiKey.php.

◆ TOKENSIZE

const sspmod_authYubiKey_Auth_Source_YubiKey::TOKENSIZE = 32

The number of characters of the OTP that is the secure token.

The rest is the user id.

Definition at line 54 of file YubiKey.php.


The documentation for this class was generated from the following file: