mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-11 08:10:58 +00:00
SSH2: add "smart multi factor" login mode (enabled by default)
This commit is contained in:
parent
1a942620b3
commit
29c8591cb2
@ -1049,6 +1049,14 @@ class Net_SSH2
|
||||
*/
|
||||
var $regenerate_decompression_context = false;
|
||||
|
||||
/**
|
||||
* Smart multi-factor authentication flag
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $smartMFA = true;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
@ -2259,11 +2267,59 @@ class Net_SSH2
|
||||
return $this->_login_helper($username);
|
||||
}
|
||||
|
||||
while (count($args)) {
|
||||
if (!$this->auth_methods_to_continue || !$this->smartMFA) {
|
||||
$newargs = $args;
|
||||
$args = array();
|
||||
} else {
|
||||
$newargs = array();
|
||||
foreach ($this->auth_methods_to_continue as $method) {
|
||||
switch ($method) {
|
||||
case 'publickey':
|
||||
foreach ($args as $key => $arg) {
|
||||
if (is_object($arg)) {
|
||||
$newargs[] = $arg;
|
||||
unset($args[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'keyboard-interactive':
|
||||
$hasArray = $hasString = false;
|
||||
foreach ($args as $arg) {
|
||||
if ($hasArray || is_array($arg)) {
|
||||
$hasArray = true;
|
||||
break;
|
||||
}
|
||||
if ($hasString || is_string($arg)) {
|
||||
$hasString = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hasArray && $hasString) {
|
||||
foreach ($args as $key => $arg) {
|
||||
if (is_array($arg)) {
|
||||
$newargs[] = $arg;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'password':
|
||||
foreach ($args as $key => $arg) {
|
||||
$newargs[] = $arg;
|
||||
unset($args[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($newargs as $arg) {
|
||||
if ($this->_login_helper($username, $arg)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -5321,4 +5377,20 @@ class Net_SSH2
|
||||
{
|
||||
return $this->auth_methods_to_continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables "smart" multi-factor authentication (MFA)
|
||||
*/
|
||||
function enableSmartMFA()
|
||||
{
|
||||
$this->smartMFA = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables "smart" multi-factor authentication (MFA)
|
||||
*/
|
||||
function disableSmartMFA()
|
||||
{
|
||||
$this->smartMFA = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user