1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-12-04 18:48:24 +01:00

SSH2: show a more helpful error message when logging in with pubkey

This commit is contained in:
terrafrost 2021-12-07 22:10:29 -06:00
parent 6a935bb57b
commit 20b9abf589

View File

@ -52,6 +52,7 @@ use phpseclib3\Crypt\Hash;
use phpseclib3\Crypt\Random;
use phpseclib3\Crypt\RC4;
use phpseclib3\Crypt\Rijndael;
use phpseclib3\Crypt\Common\PublicKey;
use phpseclib3\Crypt\Common\PrivateKey;
use phpseclib3\Crypt\RSA;
use phpseclib3\Crypt\DSA;
@ -2171,6 +2172,20 @@ class SSH2
return $this->login_helper($username);
}
foreach ($args as $arg) {
switch (true) {
case $arg instanceof PublicKey:
throw new \UnexpectedValueException('A PublicKey object was passed to the login method instead of a PrivateKey object');
case $arg instanceof PrivateKey:
case $arg instanceof Agent:
case is_array($arg):
case is_string($arg):
break;
default:
throw new \UnexpectedValueException('$password needs to either be an instance of \phpseclib3\Crypt\Common\PrivateKey, \System\SSH\Agent, an array or a string');
}
}
while (count($args)) {
if (!$this->auth_methods_to_continue || !$this->smartMFA) {
$newargs = $args;
@ -2320,10 +2335,6 @@ class SSH2
}
}
if (!is_string($password)) {
throw new \UnexpectedValueException('$password needs to either be an instance of \phpseclib3\Crypt\Common\PrivateKey, \System\SSH\Agent, an array or a string');
}
$packet = Strings::packSSH2(
'Cs3bs',
NET_SSH2_MSG_USERAUTH_REQUEST,