mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-03 10:08:04 +01:00
Replace user_error() with new _handle_error() function
To use exceptions do define('PHPSECLIB_USE_EXCEPTIONS', true). To have the exceptions thrown by phpseclib be of a certain class define PHPSECLIB_EXCEPTION_CLASS.
This commit is contained in:
parent
862253784d
commit
3caaa91160
@ -937,7 +937,7 @@ class Crypt_DES {
|
||||
if (($length & 7) == 0) {
|
||||
return $text;
|
||||
} else {
|
||||
user_error("The plaintext's length ($length) is not a multiple of the block size (8)", E_USER_NOTICE);
|
||||
$this->_handle_error("The plaintext's length ($length) is not a multiple of the block size (8)");
|
||||
$this->padding = true;
|
||||
}
|
||||
}
|
||||
@ -1289,6 +1289,24 @@ class Crypt_DES {
|
||||
$string = substr($string, $index);
|
||||
return $substr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
user_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
|
@ -1746,7 +1746,7 @@ class Crypt_RSA {
|
||||
{
|
||||
$x = $x->toBytes();
|
||||
if (strlen($x) > $xLen) {
|
||||
user_error('Integer too large', E_USER_NOTICE);
|
||||
$this->_handle_error('Integer too large');
|
||||
return false;
|
||||
}
|
||||
return str_pad($x, $xLen, chr(0), STR_PAD_LEFT);
|
||||
@ -1908,7 +1908,7 @@ class Crypt_RSA {
|
||||
function _rsaep($m)
|
||||
{
|
||||
if ($m->compare($this->zero) < 0 || $m->compare($this->modulus) > 0) {
|
||||
user_error('Message representative out of range', E_USER_NOTICE);
|
||||
$this->_handle_error('Message representative out of range');
|
||||
return false;
|
||||
}
|
||||
return $this->_exponentiate($m);
|
||||
@ -1926,7 +1926,7 @@ class Crypt_RSA {
|
||||
function _rsadp($c)
|
||||
{
|
||||
if ($c->compare($this->zero) < 0 || $c->compare($this->modulus) > 0) {
|
||||
user_error('Ciphertext representative out of range', E_USER_NOTICE);
|
||||
$this->_handle_error('Ciphertext representative out of range');
|
||||
return false;
|
||||
}
|
||||
return $this->_exponentiate($c);
|
||||
@ -1944,7 +1944,7 @@ class Crypt_RSA {
|
||||
function _rsasp1($m)
|
||||
{
|
||||
if ($m->compare($this->zero) < 0 || $m->compare($this->modulus) > 0) {
|
||||
user_error('Message representative out of range', E_USER_NOTICE);
|
||||
$this->_handle_error('Message representative out of range');
|
||||
return false;
|
||||
}
|
||||
return $this->_exponentiate($m);
|
||||
@ -1962,7 +1962,7 @@ class Crypt_RSA {
|
||||
function _rsavp1($s)
|
||||
{
|
||||
if ($s->compare($this->zero) < 0 || $s->compare($this->modulus) > 0) {
|
||||
user_error('Signature representative out of range', E_USER_NOTICE);
|
||||
$this->_handle_error('Signature representative out of range');
|
||||
return false;
|
||||
}
|
||||
return $this->_exponentiate($s);
|
||||
@ -2013,7 +2013,7 @@ class Crypt_RSA {
|
||||
// be output.
|
||||
|
||||
if ($mLen > $this->k - 2 * $this->hLen - 2) {
|
||||
user_error('Message too long', E_USER_NOTICE);
|
||||
$this->_handle_error('Message too long');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2074,7 +2074,7 @@ class Crypt_RSA {
|
||||
// be output.
|
||||
|
||||
if (strlen($c) != $this->k || $this->k < 2 * $this->hLen + 2) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2083,7 +2083,7 @@ class Crypt_RSA {
|
||||
$c = $this->_os2ip($c);
|
||||
$m = $this->_rsadp($c);
|
||||
if ($m === false) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
$em = $this->_i2osp($m, $this->k);
|
||||
@ -2101,12 +2101,12 @@ class Crypt_RSA {
|
||||
$lHash2 = substr($db, 0, $this->hLen);
|
||||
$m = substr($db, $this->hLen);
|
||||
if ($lHash != $lHash2) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
$m = ltrim($m, chr(0));
|
||||
if (ord($m[0]) != 1) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2131,7 +2131,7 @@ class Crypt_RSA {
|
||||
// Length checking
|
||||
|
||||
if ($mLen > $this->k - 11) {
|
||||
user_error('Message too long', E_USER_NOTICE);
|
||||
$this->_handle_error('Message too long');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2175,7 +2175,7 @@ class Crypt_RSA {
|
||||
// Length checking
|
||||
|
||||
if (strlen($c) != $this->k) { // or if k < 11
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2185,7 +2185,7 @@ class Crypt_RSA {
|
||||
$m = $this->_rsadp($c);
|
||||
|
||||
if ($m === false) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
$em = $this->_i2osp($m, $this->k);
|
||||
@ -2193,7 +2193,7 @@ class Crypt_RSA {
|
||||
// EME-PKCS1-v1_5 decoding
|
||||
|
||||
if (ord($em[0]) != 0 || ord($em[1]) > 2) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2201,7 +2201,7 @@ class Crypt_RSA {
|
||||
$m = substr($em, strlen($ps) + 3);
|
||||
|
||||
if (strlen($ps) < 8) {
|
||||
user_error('Decryption error', E_USER_NOTICE);
|
||||
$this->_handle_error('Decryption error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2229,7 +2229,7 @@ class Crypt_RSA {
|
||||
|
||||
$mHash = $this->hash->hash($m);
|
||||
if ($emLen < $this->hLen + $sLen + 2) {
|
||||
user_error('Encoding error', E_USER_NOTICE);
|
||||
$this->_handle_error('Encoding error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2334,7 +2334,7 @@ class Crypt_RSA {
|
||||
// Length checking
|
||||
|
||||
if (strlen($s) != $this->k) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2345,12 +2345,12 @@ class Crypt_RSA {
|
||||
$s2 = $this->_os2ip($s);
|
||||
$m2 = $this->_rsavp1($s2);
|
||||
if ($m2 === false) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
$em = $this->_i2osp($m2, $modBits >> 3);
|
||||
if ($em === false) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2400,7 +2400,7 @@ class Crypt_RSA {
|
||||
$tLen = strlen($t);
|
||||
|
||||
if ($emLen < $tLen + 11) {
|
||||
user_error('Intended encoded message length too short', E_USER_NOTICE);
|
||||
$this->_handle_error('Intended encoded message length too short');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2426,7 +2426,7 @@ class Crypt_RSA {
|
||||
|
||||
$em = $this->_emsa_pkcs1_v1_5_encode($m, $this->k);
|
||||
if ($em === false) {
|
||||
user_error('RSA modulus too short', E_USER_NOTICE);
|
||||
$this->_handle_error('RSA modulus too short');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2455,7 +2455,7 @@ class Crypt_RSA {
|
||||
// Length checking
|
||||
|
||||
if (strlen($s) != $this->k) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2464,12 +2464,12 @@ class Crypt_RSA {
|
||||
$s = $this->_os2ip($s);
|
||||
$m2 = $this->_rsavp1($s);
|
||||
if ($m2 === false) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
$em = $this->_i2osp($m2, $this->k);
|
||||
if ($em === false) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2477,7 +2477,7 @@ class Crypt_RSA {
|
||||
|
||||
$em2 = $this->_emsa_pkcs1_v1_5_encode($m, $this->k);
|
||||
if ($em2 === false) {
|
||||
user_error('RSA modulus too short', E_USER_NOTICE);
|
||||
$this->_handle_error('RSA modulus too short');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2639,4 +2639,22 @@ class Crypt_RSA {
|
||||
return $this->_rsassa_pss_verify($message, $signature);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
@ -582,7 +582,7 @@ class Crypt_Rijndael {
|
||||
*
|
||||
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
||||
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
|
||||
* $hash, $salt, $count
|
||||
* $hash, $salt, $method
|
||||
* Set $dkLen by calling setKeyLength()
|
||||
*
|
||||
* @param String $password
|
||||
@ -601,7 +601,7 @@ class Crypt_Rijndael {
|
||||
}
|
||||
// WPA and WPA use the SSID as the salt
|
||||
if (!isset($salt)) {
|
||||
$salt = 'phpseclib/salt';
|
||||
$salt = 'phpseclib';
|
||||
}
|
||||
// RFC2898#section-4.2 uses 1,000 iterations by default
|
||||
// WPA and WPA2 use 4,096.
|
||||
@ -1365,7 +1365,7 @@ class Crypt_Rijndael {
|
||||
if ($length % $this->block_size == 0) {
|
||||
return $text;
|
||||
} else {
|
||||
user_error("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size})", E_USER_NOTICE);
|
||||
$this->_handle_error("The plaintext's length ($length) is not a multiple of the block size ({$this->block_size})");
|
||||
$this->padding = true;
|
||||
}
|
||||
}
|
||||
@ -1472,7 +1472,25 @@ class Crypt_Rijndael {
|
||||
$string = substr($string, $index);
|
||||
return $substr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
user_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: ts=4:sw=4:et:
|
||||
// vim6: fdl=1:
|
||||
// vim6: fdl=1:
|
@ -409,7 +409,7 @@ class File_ANSI {
|
||||
case 47: $back = 'white'; break;
|
||||
|
||||
default:
|
||||
user_error('Unsupported attribute: ' . $mod);
|
||||
$this->_handle_error('Unsupported attribute: ' . $mod);
|
||||
$this->ansi = '';
|
||||
break 2;
|
||||
}
|
||||
@ -537,4 +537,22 @@ class File_ANSI {
|
||||
|
||||
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $scrollback . '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -955,7 +955,7 @@ class File_ASN1 {
|
||||
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
|
||||
$oid = preg_match('#(?:\d+\.)+#', $source) ? $source : array_search($source, $this->oids);
|
||||
if ($oid === false) {
|
||||
user_error('Invalid OID', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid OID');
|
||||
return false;
|
||||
}
|
||||
$value = '';
|
||||
@ -1008,7 +1008,7 @@ class File_ASN1 {
|
||||
$filters = $filters[$part];
|
||||
}
|
||||
if ($filters === false) {
|
||||
user_error('No filters defined for ' . implode('/', $loc), E_USER_NOTICE);
|
||||
$this->_handle_error('No filters defined for ' . implode('/', $loc));
|
||||
return false;
|
||||
}
|
||||
return $this->_encode_der($source, $filters + $mapping);
|
||||
@ -1032,7 +1032,7 @@ class File_ASN1 {
|
||||
$value = $source ? "\xFF" : "\x00";
|
||||
break;
|
||||
default:
|
||||
user_error('Mapping provides no type definition for ' . implode('/', $this->location), E_USER_NOTICE);
|
||||
$this->_handle_error('Mapping provides no type definition for ' . implode('/', $this->location));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1270,4 +1270,22 @@ class File_ASN1 {
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1569,7 +1569,7 @@ class File_X509 {
|
||||
$map = $this->_getMapping($id);
|
||||
if (is_bool($map)) {
|
||||
if (!$map) {
|
||||
user_error($id . ' is not a currently supported extension', E_USER_NOTICE);
|
||||
$this->_handle_error($id . ' is not a currently supported extension');
|
||||
unset($extensions[$i]);
|
||||
}
|
||||
} else {
|
||||
@ -3839,4 +3839,22 @@ class File_X509 {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_VERSION) {
|
||||
user_error('Expected SSH_FXP_VERSION', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_VERSION');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -588,7 +588,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
return false;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -645,7 +645,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
return false;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -655,7 +655,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -731,7 +731,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
return false;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -780,7 +780,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
}
|
||||
break 2;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_NAME or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -793,7 +793,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
// -- http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.1.3
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -996,7 +996,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
return false;
|
||||
}
|
||||
|
||||
user_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1089,7 +1089,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
*/
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1116,7 +1116,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
return false;
|
||||
}
|
||||
|
||||
user_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1249,7 +1249,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1288,7 +1288,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1365,7 +1365,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
return false;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1374,7 +1374,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.2.3
|
||||
if ($mode & NET_SFTP_LOCAL_FILE) {
|
||||
if (!is_file($data)) {
|
||||
user_error("$data is not a valid file", E_USER_NOTICE);
|
||||
$this->_handle_error("$data is not a valid file");
|
||||
return false;
|
||||
}
|
||||
$fp = @fopen($data, 'rb');
|
||||
@ -1425,7 +1425,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1453,7 +1453,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
while ($i--) {
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1504,7 +1504,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
return false;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1542,7 +1542,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
$this->_logError($response);
|
||||
break 2;
|
||||
default:
|
||||
user_error('Expected SSH_FXP_DATA or SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_DATA or SSH_FXP_STATUS');
|
||||
if ($local_file !== false) {
|
||||
fclose($fp);
|
||||
}
|
||||
@ -1560,7 +1560,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1604,7 +1604,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1723,7 +1723,7 @@ class Net_SFTP extends Net_SSH2 {
|
||||
|
||||
$response = $this->_get_sftp_packet();
|
||||
if ($this->packet_type != NET_SFTP_STATUS) {
|
||||
user_error('Expected SSH_FXP_STATUS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_FXP_STATUS');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,7 @@ class Net_SSH1 {
|
||||
|
||||
$this->fsock = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
if (!$this->fsock) {
|
||||
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"), E_USER_NOTICE);
|
||||
$this->_handle_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -484,11 +484,11 @@ class Net_SSH1 {
|
||||
}
|
||||
|
||||
if (!preg_match('#SSH-([0-9\.]+)-(.+)#', $init_line, $parts)) {
|
||||
user_error('Can only connect to SSH servers', E_USER_NOTICE);
|
||||
$this->_handle_error('Can only connect to SSH servers');
|
||||
return;
|
||||
}
|
||||
if ($parts[1][0] != 1) {
|
||||
user_error("Cannot connect to SSH $parts[1] servers", E_USER_NOTICE);
|
||||
$this->_handle_error("Cannot connect to SSH $parts[1] servers");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -496,7 +496,7 @@ class Net_SSH1 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_PUBLIC_KEY) {
|
||||
user_error('Expected SSH_SMSG_PUBLIC_KEY', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_SMSG_PUBLIC_KEY');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -584,7 +584,7 @@ class Net_SSH1 {
|
||||
$data = pack('C2a*na*N', NET_SSH1_CMSG_SESSION_KEY, $cipher, $anti_spoofing_cookie, 8 * strlen($double_encrypted_session_key), $double_encrypted_session_key, 0);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_SESSION_KEY', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_SESSION_KEY');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -614,7 +614,7 @@ class Net_SSH1 {
|
||||
$response = $this->_get_binary_packet();
|
||||
|
||||
if ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_SUCCESS) {
|
||||
user_error('Expected SSH_SMSG_SUCCESS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_SMSG_SUCCESS');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -638,7 +638,7 @@ class Net_SSH1 {
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_USER, strlen($username), $username);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_USER', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_USER');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -648,14 +648,14 @@ class Net_SSH1 {
|
||||
$this->bitmap |= NET_SSH1_MASK_LOGIN;
|
||||
return true;
|
||||
} else if ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_FAILURE) {
|
||||
user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE');
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_AUTH_PASSWORD, strlen($password), $password);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_AUTH_PASSWORD', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_AUTH_PASSWORD');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -673,7 +673,7 @@ class Net_SSH1 {
|
||||
} else if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_FAILURE) {
|
||||
return false;
|
||||
} else {
|
||||
user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -701,14 +701,14 @@ class Net_SSH1 {
|
||||
function exec($cmd, $block = true)
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_EXEC_CMD, strlen($cmd), $cmd);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_EXEC_CMD', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_EXEC_CMD');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -753,21 +753,21 @@ class Net_SSH1 {
|
||||
$data = pack('CNa*N4C', NET_SSH1_CMSG_REQUEST_PTY, strlen('vt100'), 'vt100', 24, 80, 0, 0, NET_SSH1_TTY_OP_END);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_REQUEST_PTY', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_REQUEST_PTY');
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
|
||||
if ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_SUCCESS) {
|
||||
user_error('Expected SSH_SMSG_SUCCESS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_SMSG_SUCCESS');
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = pack('C', NET_SSH1_CMSG_EXEC_SHELL);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_EXEC_SHELL', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_EXEC_SHELL');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -806,12 +806,12 @@ class Net_SSH1 {
|
||||
function read($expect, $mode = NET_SSH1_READ_SIMPLE)
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
|
||||
user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to initiate an interactive shell session');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -841,19 +841,19 @@ class Net_SSH1 {
|
||||
function interactiveWrite($cmd)
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
|
||||
user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to initiate an interactive shell session');
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($cmd), $cmd);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Error sending SSH_CMSG_STDIN', E_USER_NOTICE);
|
||||
$this->_handle_error('Error sending SSH_CMSG_STDIN');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -876,12 +876,12 @@ class Net_SSH1 {
|
||||
function interactiveRead()
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH1_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($this->bitmap & NET_SSH1_MASK_SHELL) && !$this->_initShell()) {
|
||||
user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to initiate an interactive shell session');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -960,7 +960,7 @@ class Net_SSH1 {
|
||||
function _get_binary_packet()
|
||||
{
|
||||
if (feof($this->fsock)) {
|
||||
//user_error('connection closed prematurely', E_USER_NOTICE);
|
||||
//$this->_handle_error('connection closed prematurely');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -984,7 +984,7 @@ class Net_SSH1 {
|
||||
$temp = unpack('Ncrc', substr($raw, -4));
|
||||
|
||||
//if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
|
||||
// user_error('Bad CRC in packet from server', E_USER_NOTICE);
|
||||
// $this->_handle_error('Bad CRC in packet from server');
|
||||
// return false;
|
||||
//}
|
||||
|
||||
@ -1017,7 +1017,7 @@ class Net_SSH1 {
|
||||
*/
|
||||
function _send_binary_packet($data) {
|
||||
if (feof($this->fsock)) {
|
||||
//user_error('connection closed prematurely', E_USER_NOTICE);
|
||||
//$this->_handle_error('connection closed prematurely');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1418,4 +1418,22 @@ class Net_SSH1 {
|
||||
{
|
||||
return rtrim($this->server_identification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ class Net_SSH2 {
|
||||
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
|
||||
$this->fsock = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
if (!$this->fsock) {
|
||||
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"), E_USER_NOTICE);
|
||||
$this->_handle_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
|
||||
return;
|
||||
}
|
||||
$elapsed = strtok(microtime(), ' ') + strtok('') - $start;
|
||||
@ -801,7 +801,7 @@ class Net_SSH2 {
|
||||
$timeout-= $elapsed;
|
||||
|
||||
if ($timeout <= 0) {
|
||||
user_error(rtrim("Cannot connect to $host. Timeout error"), E_USER_NOTICE);
|
||||
$this->_handle_error(rtrim("Cannot connect to $host. Timeout error"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -814,7 +814,7 @@ class Net_SSH2 {
|
||||
// on windows this returns a "Warning: Invalid CRT parameters detected" error
|
||||
// the !count() is done as a workaround for <https://bugs.php.net/42682>
|
||||
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
|
||||
user_error(rtrim("Cannot connect to $host. Banner timeout"), E_USER_NOTICE);
|
||||
$this->_handle_error(rtrim("Cannot connect to $host. Banner timeout"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -836,7 +836,7 @@ class Net_SSH2 {
|
||||
}
|
||||
|
||||
if (feof($this->fsock)) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -870,7 +870,7 @@ class Net_SSH2 {
|
||||
}
|
||||
|
||||
if ($matches[1] != '1.99' && $matches[1] != '2.0') {
|
||||
user_error("Cannot connect to SSH $matches[1] servers", E_USER_NOTICE);
|
||||
$this->_handle_error("Cannot connect to SSH $matches[1] servers");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -878,12 +878,12 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return;
|
||||
}
|
||||
|
||||
if (ord($response[0]) != NET_SSH2_MSG_KEXINIT) {
|
||||
user_error('Expected SSH_MSG_KEXINIT', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_MSG_KEXINIT');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1028,7 +1028,7 @@ class Net_SSH2 {
|
||||
// we need to decide upon the symmetric encryption algorithms before we do the diffie-hellman key exchange
|
||||
for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_server_to_client); $i++);
|
||||
if ($i == count($encryption_algorithms)) {
|
||||
user_error('No compatible server to client encryption algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible server to client encryption algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1065,7 +1065,7 @@ class Net_SSH2 {
|
||||
|
||||
for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_client_to_server); $i++);
|
||||
if ($i == count($encryption_algorithms)) {
|
||||
user_error('No compatible client to server encryption algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible client to server encryption algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1103,7 +1103,7 @@ class Net_SSH2 {
|
||||
// through diffie-hellman key exchange a symmetric key is obtained
|
||||
for ($i = 0; $i < count($kex_algorithms) && !in_array($kex_algorithms[$i], $this->kex_algorithms); $i++);
|
||||
if ($i == count($kex_algorithms)) {
|
||||
user_error('No compatible key exchange algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible key exchange algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1156,19 +1156,19 @@ class Net_SSH2 {
|
||||
$data = pack('CNa*', NET_SSH2_MSG_KEXDH_INIT, strlen($eBytes), $eBytes);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Ctype', $this->_string_shift($response, 1)));
|
||||
|
||||
if ($type != NET_SSH2_MSG_KEXDH_REPLY) {
|
||||
user_error('Expected SSH_MSG_KEXDH_REPLY', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_MSG_KEXDH_REPLY');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1206,12 +1206,12 @@ class Net_SSH2 {
|
||||
|
||||
for ($i = 0; $i < count($server_host_key_algorithms) && !in_array($server_host_key_algorithms[$i], $this->server_host_key_algorithms); $i++);
|
||||
if ($i == count($server_host_key_algorithms)) {
|
||||
user_error('No compatible server host key algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible server host key algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
if ($public_key_format != $server_host_key_algorithms[$i] || $this->signature_format != $server_host_key_algorithms[$i]) {
|
||||
user_error('Sever Host Key Algorithm Mismatch', E_USER_NOTICE);
|
||||
$this->_handle_error('Sever Host Key Algorithm Mismatch');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1226,14 +1226,14 @@ class Net_SSH2 {
|
||||
$response = $this->_get_binary_packet();
|
||||
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
extract(unpack('Ctype', $this->_string_shift($response, 1)));
|
||||
|
||||
if ($type != NET_SSH2_MSG_NEWKEYS) {
|
||||
user_error('Expected SSH_MSG_NEWKEYS', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_MSG_NEWKEYS');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1347,7 +1347,7 @@ class Net_SSH2 {
|
||||
|
||||
for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_client_to_server); $i++);
|
||||
if ($i == count($mac_algorithms)) {
|
||||
user_error('No compatible client to server message authentication algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible client to server message authentication algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1372,7 +1372,7 @@ class Net_SSH2 {
|
||||
|
||||
for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_server_to_client); $i++);
|
||||
if ($i == count($mac_algorithms)) {
|
||||
user_error('No compatible server to client message authentication algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible server to client message authentication algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -1414,14 +1414,14 @@ class Net_SSH2 {
|
||||
|
||||
for ($i = 0; $i < count($compression_algorithms) && !in_array($compression_algorithms[$i], $this->compression_algorithms_server_to_client); $i++);
|
||||
if ($i == count($compression_algorithms)) {
|
||||
user_error('No compatible server to client compression algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible server to client compression algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
$this->decompress = $compression_algorithms[$i] == 'zlib';
|
||||
|
||||
for ($i = 0; $i < count($compression_algorithms) && !in_array($compression_algorithms[$i], $this->compression_algorithms_client_to_server); $i++);
|
||||
if ($i == count($compression_algorithms)) {
|
||||
user_error('No compatible client to server compression algorithms found', E_USER_NOTICE);
|
||||
$this->_handle_error('No compatible client to server compression algorithms found');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
$this->compress = $compression_algorithms[$i] == 'zlib';
|
||||
@ -1457,14 +1457,14 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
extract(unpack('Ctype', $this->_string_shift($response, 1)));
|
||||
|
||||
if ($type != NET_SSH2_MSG_SERVICE_ACCEPT) {
|
||||
user_error('Expected SSH_MSG_SERVICE_ACCEPT', E_USER_NOTICE);
|
||||
$this->_handle_error('Expected SSH_MSG_SERVICE_ACCEPT');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1485,7 +1485,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1521,7 +1521,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1593,7 +1593,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1706,7 +1706,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1741,7 +1741,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1894,7 +1894,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1905,7 +1905,7 @@ class Net_SSH2 {
|
||||
break;
|
||||
case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
default:
|
||||
user_error('Unable to request pseudo-terminal', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to request pseudo-terminal');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
|
||||
@ -1946,12 +1946,12 @@ class Net_SSH2 {
|
||||
$this->curTimeout = $this->timeout;
|
||||
|
||||
if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
|
||||
user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to initiate an interactive shell session');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1985,12 +1985,12 @@ class Net_SSH2 {
|
||||
function write($cmd)
|
||||
{
|
||||
if (!($this->bitmap & NET_SSH2_MASK_LOGIN)) {
|
||||
user_error('Operation disallowed prior to login()', E_USER_NOTICE);
|
||||
$this->_handle_error('Operation disallowed prior to login()');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($this->bitmap & NET_SSH2_MASK_SHELL) && !$this->_initShell()) {
|
||||
user_error('Unable to initiate an interactive shell session', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to initiate an interactive shell session');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2035,7 +2035,7 @@ class Net_SSH2 {
|
||||
function _get_binary_packet()
|
||||
{
|
||||
if (!is_resource($this->fsock) || feof($this->fsock)) {
|
||||
user_error('Connection closed prematurely', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed prematurely');
|
||||
$this->bitmask = 0;
|
||||
return false;
|
||||
}
|
||||
@ -2052,7 +2052,7 @@ class Net_SSH2 {
|
||||
$raw = $this->decrypt->decrypt($raw);
|
||||
}
|
||||
if ($raw === false) {
|
||||
user_error('Unable to decrypt content', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to decrypt content');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2076,7 +2076,7 @@ class Net_SSH2 {
|
||||
if ($this->hmac_check !== false) {
|
||||
$hmac = fread($this->fsock, $this->hmac_size);
|
||||
if ($hmac != $this->hmac_check->hash(pack('NNCa*', $this->get_seq_no, $packet_length, $padding_length, $payload . $padding))) {
|
||||
user_error('Invalid HMAC', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid HMAC');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2243,7 +2243,7 @@ class Net_SSH2 {
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
if ($response === false) {
|
||||
user_error('Connection closed by server', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed by server');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2265,7 +2265,7 @@ class Net_SSH2 {
|
||||
return $client_channel == $channel ? true : $this->_get_channel_packet($client_channel, $skip_extended);
|
||||
//case NET_SSH2_MSG_CHANNEL_OPEN_FAILURE:
|
||||
default:
|
||||
user_error('Unable to open channel', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to open channel');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
break;
|
||||
@ -2275,7 +2275,7 @@ class Net_SSH2 {
|
||||
return true;
|
||||
//case NET_SSH2_MSG_CHANNEL_FAILURE:
|
||||
default:
|
||||
user_error('Unable to request pseudo-terminal', E_USER_NOTICE);
|
||||
$this->_handle_error('Unable to request pseudo-terminal');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
case NET_SSH2_MSG_CHANNEL_CLOSE:
|
||||
@ -2364,7 +2364,7 @@ class Net_SSH2 {
|
||||
case NET_SSH2_MSG_CHANNEL_EOF:
|
||||
break;
|
||||
default:
|
||||
user_error('Error reading channel data', E_USER_NOTICE);
|
||||
$this->_handle_error('Error reading channel data');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
|
||||
}
|
||||
}
|
||||
@ -2383,7 +2383,7 @@ class Net_SSH2 {
|
||||
function _send_binary_packet($data)
|
||||
{
|
||||
if (!is_resource($this->fsock) || feof($this->fsock)) {
|
||||
user_error('Connection closed prematurely', E_USER_NOTICE);
|
||||
$this->_handle_error('Connection closed prematurely');
|
||||
$this->bitmask = 0;
|
||||
return false;
|
||||
}
|
||||
@ -2894,7 +2894,7 @@ class Net_SSH2 {
|
||||
padding, unsigned, and in network byte order). */
|
||||
$temp = unpack('Nlength', $this->_string_shift($signature, 4));
|
||||
if ($temp['length'] != 40) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -2902,7 +2902,7 @@ class Net_SSH2 {
|
||||
$s = new Math_BigInteger($this->_string_shift($signature, 20), 256);
|
||||
|
||||
if ($r->compare($q) >= 0 || $s->compare($q) >= 0) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -2922,7 +2922,7 @@ class Net_SSH2 {
|
||||
list(, $v) = $v->divide($q);
|
||||
|
||||
if (!$v->equals($r)) {
|
||||
user_error('Bad server signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Bad server signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
|
||||
}
|
||||
|
||||
@ -2947,7 +2947,7 @@ class Net_SSH2 {
|
||||
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
|
||||
$rsa->loadKey(array('e' => $e, 'n' => $n), CRYPT_RSA_PUBLIC_FORMAT_RAW);
|
||||
if (!$rsa->verify($this->exchange_hash, $signature)) {
|
||||
user_error('Bad server signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Bad server signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
|
||||
}
|
||||
*/
|
||||
@ -2962,7 +2962,7 @@ class Net_SSH2 {
|
||||
// also, see SSHRSA.c (rsa2_verifysig) in PuTTy's source.
|
||||
|
||||
if ($s->compare(new Math_BigInteger()) < 0 || $s->compare($n->subtract(new Math_BigInteger(1))) > 0) {
|
||||
user_error('Invalid signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Invalid signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
|
||||
}
|
||||
|
||||
@ -2973,15 +2973,33 @@ class Net_SSH2 {
|
||||
$h = chr(0x01) . str_repeat(chr(0xFF), $nLength - 3 - strlen($h)) . $h;
|
||||
|
||||
if ($s != $h) {
|
||||
user_error('Bad server signature', E_USER_NOTICE);
|
||||
$this->_handle_error('Bad server signature');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
user_error('Unsupported signature format', E_USER_NOTICE);
|
||||
$this->_handle_error('Unsupported signature format');
|
||||
return $this->_disconnect(NET_SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE);
|
||||
}
|
||||
|
||||
return $this->signature_format . ' ' . base64_encode($this->server_public_host_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler
|
||||
*
|
||||
* Throws exceptions if PHPSECLIB_USE_EXCEPTIONS is defined.
|
||||
* Unless PHPSECLIB_EXCEPTION_CLASS is set it'll throw generic Exceptions.
|
||||
*
|
||||
* @param String $string
|
||||
* @access private
|
||||
*/
|
||||
function _handle_error($err_msg) {
|
||||
if (defined('PHPSECLIB_USE_EXCEPTIONS') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
|
||||
$class = defined('PHPSECLIB_EXCEPTION_CLASS') && class_exists(PHPSECLIB_EXCEPTION_CLASS) ? PHPSECLIB_EXCEPTION_CLASS : 'Exception';
|
||||
throw(new $class($err_msg));
|
||||
} else {
|
||||
$this->_handle_error($err_msg);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user