mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 03:27:31 +00:00
Merge pull request #581 from cnelissen/ReplaceGetClassFix
Replaced get_class() calls with instanceof operators * cnelissen/ReplaceGetClassFix: Revert changes for abstract methods in Base class Replaced get_class() calls with instanceof operators
This commit is contained in:
commit
8fae19a024
@ -1172,7 +1172,7 @@ class Base
|
|||||||
*/
|
*/
|
||||||
function _encryptBlock($in)
|
function _encryptBlock($in)
|
||||||
{
|
{
|
||||||
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
user_error(__METHOD__ . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1186,7 +1186,7 @@ class Base
|
|||||||
*/
|
*/
|
||||||
function _decryptBlock($in)
|
function _decryptBlock($in)
|
||||||
{
|
{
|
||||||
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
user_error(__METHOD__ . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1201,7 +1201,7 @@ class Base
|
|||||||
*/
|
*/
|
||||||
function _setupKey()
|
function _setupKey()
|
||||||
{
|
{
|
||||||
user_error((version_compare(PHP_VERSION, '5.0.0', '>=') ? __METHOD__ : __FUNCTION__) . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
user_error(__METHOD__ . '() must extend by class ' . get_class($this), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1454,7 +1454,7 @@ class RSA
|
|||||||
*/
|
*/
|
||||||
function loadKey($key, $type = false)
|
function loadKey($key, $type = false)
|
||||||
{
|
{
|
||||||
if (is_object($key) && get_class($key) == 'phpseclib\Crypt\RSA') {
|
if ($key instanceof RSA) {
|
||||||
$this->privateKeyFormat = $key->privateKeyFormat;
|
$this->privateKeyFormat = $key->privateKeyFormat;
|
||||||
$this->publicKeyFormat = $key->publicKeyFormat;
|
$this->publicKeyFormat = $key->publicKeyFormat;
|
||||||
$this->k = $key->k;
|
$this->k = $key->k;
|
||||||
|
@ -206,7 +206,7 @@ class ASN1
|
|||||||
*/
|
*/
|
||||||
function decodeBER($encoded)
|
function decodeBER($encoded)
|
||||||
{
|
{
|
||||||
if (is_object($encoded) && get_class($encoded) === 'phpseclib\File\ASN1\Element') {
|
if ($encoded instanceof Element) {
|
||||||
$encoded = $encoded->element;
|
$encoded = $encoded->element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,7 +779,7 @@ class ASN1
|
|||||||
*/
|
*/
|
||||||
function _encode_der($source, $mapping, $idx = null, $special = array())
|
function _encode_der($source, $mapping, $idx = null, $special = array())
|
||||||
{
|
{
|
||||||
if (is_object($source) && get_class($source) === 'phpseclib\File\ASN1\Element') {
|
if ($source instanceof Element) {
|
||||||
return $source->element;
|
return $source->element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,7 +997,7 @@ class ASN1
|
|||||||
case !isset($source):
|
case !isset($source):
|
||||||
return $this->_encode_der(null, array('type' => self::TYPE_NULL) + $mapping, null, $special);
|
return $this->_encode_der(null, array('type' => self::TYPE_NULL) + $mapping, null, $special);
|
||||||
case is_int($source):
|
case is_int($source):
|
||||||
case $source instanceof \phpseclib\Math\BigInteger:
|
case $source instanceof BigInteger:
|
||||||
return $this->_encode_der($source, array('type' => self::TYPE_INTEGER) + $mapping, null, $special);
|
return $this->_encode_der($source, array('type' => self::TYPE_INTEGER) + $mapping, null, $special);
|
||||||
case is_float($source):
|
case is_float($source):
|
||||||
return $this->_encode_der($source, array('type' => self::TYPE_REAL) + $mapping, null, $special);
|
return $this->_encode_der($source, array('type' => self::TYPE_REAL) + $mapping, null, $special);
|
||||||
|
@ -3601,8 +3601,7 @@ class X509
|
|||||||
*/
|
*/
|
||||||
function _sign($key, $signatureAlgorithm)
|
function _sign($key, $signatureAlgorithm)
|
||||||
{
|
{
|
||||||
switch (get_class($key)) {
|
if ($key instanceof RSA) {
|
||||||
case 'phpseclib\Crypt\RSA':
|
|
||||||
switch ($signatureAlgorithm) {
|
switch ($signatureAlgorithm) {
|
||||||
case 'md2WithRSAEncryption':
|
case 'md2WithRSAEncryption':
|
||||||
case 'md5WithRSAEncryption':
|
case 'md5WithRSAEncryption':
|
||||||
@ -3617,9 +3616,9 @@ class X509
|
|||||||
$this->currentCert['signature'] = base64_encode("\0" . $key->sign($this->signatureSubject));
|
$this->currentCert['signature'] = base64_encode("\0" . $key->sign($this->signatureSubject));
|
||||||
return $this->currentCert;
|
return $this->currentCert;
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4162,7 +4161,7 @@ class X509
|
|||||||
return $this->computeKeyIdentifier($key['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'], $method);
|
return $this->computeKeyIdentifier($key['certificationRequestInfo']['subjectPKInfo']['subjectPublicKey'], $method);
|
||||||
case !is_object($key):
|
case !is_object($key):
|
||||||
return false;
|
return false;
|
||||||
case get_class($key) === 'phpseclib\File\ASN1\Element':
|
case $key instanceof Element:
|
||||||
// Assume the element is a bitstring-packed key.
|
// Assume the element is a bitstring-packed key.
|
||||||
$asn1 = new ASN1();
|
$asn1 = new ASN1();
|
||||||
$decoded = $asn1->decodeBER($key->element);
|
$decoded = $asn1->decodeBER($key->element);
|
||||||
@ -4184,7 +4183,7 @@ class X509
|
|||||||
}
|
}
|
||||||
$key = $raw; // Is a public key.
|
$key = $raw; // Is a public key.
|
||||||
break;
|
break;
|
||||||
case get_class($key) === 'phpseclib\File\X509':
|
case $key instanceof X509:
|
||||||
if (isset($key->publicKey)) {
|
if (isset($key->publicKey)) {
|
||||||
return $this->computeKeyIdentifier($key->publicKey, $method);
|
return $this->computeKeyIdentifier($key->publicKey, $method);
|
||||||
}
|
}
|
||||||
@ -4223,12 +4222,7 @@ class X509
|
|||||||
*/
|
*/
|
||||||
function _formatSubjectPublicKey()
|
function _formatSubjectPublicKey()
|
||||||
{
|
{
|
||||||
if (!isset($this->publicKey) || !is_object($this->publicKey)) {
|
if ($this->publicKey instanceof RSA) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (get_class($this->publicKey)) {
|
|
||||||
case 'phpseclib\Crypt\RSA':
|
|
||||||
// the following two return statements do the same thing. i dunno.. i just prefer the later for some reason.
|
// the following two return statements do the same thing. i dunno.. i just prefer the later for some reason.
|
||||||
// the former is a good example of how to do fuzzing on the public key
|
// the former is a good example of how to do fuzzing on the public key
|
||||||
//return new Element(base64_decode(preg_replace('#-.+-|[\r\n]#', '', $this->publicKey->getPublicKey())));
|
//return new Element(base64_decode(preg_replace('#-.+-|[\r\n]#', '', $this->publicKey->getPublicKey())));
|
||||||
@ -4236,9 +4230,9 @@ class X509
|
|||||||
'algorithm' => array('algorithm' => 'rsaEncryption'),
|
'algorithm' => array('algorithm' => 'rsaEncryption'),
|
||||||
'subjectPublicKey' => $this->publicKey->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1)
|
'subjectPublicKey' => $this->publicKey->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1)
|
||||||
);
|
);
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -332,7 +332,7 @@ class BigInteger
|
|||||||
switch (true) {
|
switch (true) {
|
||||||
case is_resource($x) && get_resource_type($x) == 'GMP integer':
|
case is_resource($x) && get_resource_type($x) == 'GMP integer':
|
||||||
// PHP 5.6 switched GMP from using resources to objects
|
// PHP 5.6 switched GMP from using resources to objects
|
||||||
case is_object($x) && get_class($x) == 'GMP':
|
case $x instanceof \GMP:
|
||||||
$this->value = $x;
|
$this->value = $x;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -110,19 +110,12 @@ class SCP
|
|||||||
*/
|
*/
|
||||||
function __construct($ssh)
|
function __construct($ssh)
|
||||||
{
|
{
|
||||||
if (!is_object($ssh)) {
|
if ($ssh instanceof SSH2) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (get_class($ssh)) {
|
|
||||||
case 'phpseclib\Net\SSH2':
|
|
||||||
$this->mode = self::MODE_SSH2;
|
$this->mode = self::MODE_SSH2;
|
||||||
break;
|
} elseif ($ssh instanceof SSH1) {
|
||||||
case 'phpseclib\Net\SSH1':
|
|
||||||
$this->packet_size = 50000;
|
$this->packet_size = 50000;
|
||||||
$this->mode = self::MODE_SSH1;
|
$this->mode = self::MODE_SSH1;
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
namespace phpseclib\Net\SFTP;
|
namespace phpseclib\Net\SFTP;
|
||||||
|
|
||||||
|
use phpseclib\Crypt\RSA;
|
||||||
use phpseclib\Net\SFTP;
|
use phpseclib\Net\SFTP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,7 +169,7 @@ class Stream
|
|||||||
if ($host[0] == '$') {
|
if ($host[0] == '$') {
|
||||||
$host = substr($host, 1);
|
$host = substr($host, 1);
|
||||||
global $$host;
|
global $$host;
|
||||||
if (!is_object($$host) || get_class($$host) != 'phpseclib\Net\SFTP') {
|
if (($$host instanceof SFTP) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->sftp = $$host;
|
$this->sftp = $$host;
|
||||||
@ -182,7 +183,7 @@ class Stream
|
|||||||
if (isset($context[$scheme]['sftp'])) {
|
if (isset($context[$scheme]['sftp'])) {
|
||||||
$sftp = $context[$scheme]['sftp'];
|
$sftp = $context[$scheme]['sftp'];
|
||||||
}
|
}
|
||||||
if (isset($sftp) && is_object($sftp) && get_class($sftp) == 'phpseclib\Net\SFTP') {
|
if (isset($sftp) && $sftp instanceof SFTP) {
|
||||||
$this->sftp = $sftp;
|
$this->sftp = $sftp;
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ class Stream
|
|||||||
if (isset($context[$scheme]['password'])) {
|
if (isset($context[$scheme]['password'])) {
|
||||||
$pass = $context[$scheme]['password'];
|
$pass = $context[$scheme]['password'];
|
||||||
}
|
}
|
||||||
if (isset($context[$scheme]['privkey']) && is_object($context[$scheme]['privkey']) && get_class($context[$scheme]['privkey']) == 'phpseclib\Crypt\RSA') {
|
if (isset($context[$scheme]['privkey']) && $context[$scheme]['privkey'] instanceof RSA) {
|
||||||
$pass = $context[$scheme]['privkey'];
|
$pass = $context[$scheme]['privkey'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ use phpseclib\Crypt\RSA;
|
|||||||
use phpseclib\Crypt\TripleDES;
|
use phpseclib\Crypt\TripleDES;
|
||||||
use phpseclib\Crypt\Twofish;
|
use phpseclib\Crypt\Twofish;
|
||||||
use phpseclib\Math\BigInteger; // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
use phpseclib\Math\BigInteger; // Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
||||||
|
use phpseclib\System\SSH\Agent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure-PHP implementation of SSHv2.
|
* Pure-PHP implementation of SSHv2.
|
||||||
@ -1805,14 +1806,11 @@ class SSH2
|
|||||||
return !is_string($password) && !is_array($password) ? false : $this->_keyboard_interactive_process($password);
|
return !is_string($password) && !is_array($password) ? false : $this->_keyboard_interactive_process($password);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($password)) {
|
if ($password instanceof RSA) {
|
||||||
switch (get_class($password)) {
|
|
||||||
case 'phpseclib\Crypt\RSA':
|
|
||||||
return $this->_privatekey_login($username, $password);
|
return $this->_privatekey_login($username, $password);
|
||||||
case 'phpseclib\System\SSH\Agent':
|
} elseif ($password instanceof Agent) {
|
||||||
return $this->_ssh_agent_login($username, $password);
|
return $this->_ssh_agent_login($username, $password);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($password)) {
|
if (is_array($password)) {
|
||||||
if ($this->_keyboard_interactive_login($username, $password)) {
|
if ($this->_keyboard_interactive_login($username, $password)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user