Use phpcbf to fix PHP code to ruleset.

This commit is contained in:
Andreas Fischer 2015-07-15 03:52:31 +02:00
parent 6c76df46d4
commit 2013a31ecd
35 changed files with 597 additions and 319 deletions

View File

@ -743,7 +743,7 @@ class Crypt_Base
$iv = substr_replace($iv, $block, 0, $overflow); $iv = substr_replace($iv, $block, 0, $overflow);
$ciphertext.= $block; $ciphertext.= $block;
$pos = $overflow; $pos = $overflow;
} else if ($len) { } elseif ($len) {
$ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
$iv = substr($ciphertext, -$this->block_size); $iv = substr($ciphertext, -$this->block_size);
} }
@ -1050,7 +1050,7 @@ class Crypt_Base
$plaintext.= $iv ^ substr($ciphertext, -$overflow); $plaintext.= $iv ^ substr($ciphertext, -$overflow);
$iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow); $iv = substr_replace($iv, substr($ciphertext, -$overflow), 0, $overflow);
$pos = $overflow; $pos = $overflow;
} else if ($len) { } elseif ($len) {
$plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv); $plaintext.= openssl_decrypt($ciphertext, $this->cipher_name_openssl, $this->key, $this->openssl_options, $iv);
$iv = substr($ciphertext, -$this->block_size); $iv = substr($ciphertext, -$this->block_size);
} }
@ -1326,7 +1326,7 @@ class Crypt_Base
$buffer['ciphertext'] = substr($temp, $overflow); $buffer['ciphertext'] = substr($temp, $overflow);
$encryptIV = $temp; $encryptIV = $temp;
} }
} else if (!strlen($buffer['ciphertext'])) { } elseif (!strlen($buffer['ciphertext'])) {
$ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV); $ciphertext.= openssl_encrypt($plaintext . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
$temp = $this->_string_pop($ciphertext, $block_size); $temp = $this->_string_pop($ciphertext, $block_size);
if ($this->continuousBuffer) { if ($this->continuousBuffer) {

View File

@ -1449,7 +1449,6 @@ class Crypt_DES extends Crypt_Base
// Creating code for en- and decryption. // Creating code for en- and decryption.
$crypt_block = array(); $crypt_block = array();
foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) { foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) {
/* Do the initial IP permutation. */ /* Do the initial IP permutation. */
$crypt_block[$c] = ' $crypt_block[$c] = '
$in = unpack("N*", $in); $in = unpack("N*", $in);

View File

@ -153,7 +153,7 @@ class Crypt_Hash
*/ */
function Crypt_Hash($hash = 'sha1') function Crypt_Hash($hash = 'sha1')
{ {
if ( !defined('CRYPT_HASH_MODE') ) { if (!defined('CRYPT_HASH_MODE')) {
switch (true) { switch (true) {
case extension_loaded('hash'): case extension_loaded('hash'):
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH); define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
@ -242,7 +242,7 @@ class Crypt_Hash
$mode = CRYPT_HASH_MODE; $mode = CRYPT_HASH_MODE;
} }
switch ( $mode ) { switch ($mode) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
switch ($hash) { switch ($hash) {
case 'md5': case 'md5':
@ -278,20 +278,20 @@ class Crypt_Hash
case 'md2': case 'md2':
$this->b = 16; $this->b = 16;
$this->hash = array($this, '_md2'); $this->hash = array($this, '_md2');
break; break;
case 'md5': case 'md5':
$this->b = 64; $this->b = 64;
$this->hash = array($this, '_md5'); $this->hash = array($this, '_md5');
break; break;
case 'sha256': case 'sha256':
$this->b = 64; $this->b = 64;
$this->hash = array($this, '_sha256'); $this->hash = array($this, '_sha256');
break; break;
case 'sha384': case 'sha384':
case 'sha512': case 'sha512':
$this->b = 128; $this->b = 128;
$this->hash = array($this, '_sha512'); $this->hash = array($this, '_sha512');
break; break;
case 'sha1': case 'sha1':
default: default:
$this->b = 64; $this->b = 64;
@ -314,7 +314,7 @@ class Crypt_Hash
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; $mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
if (!empty($this->key) || is_string($this->key)) { if (!empty($this->key) || is_string($this->key)) {
switch ( $mode ) { switch ($mode) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
$output = mhash($this->hash, $text, $this->key); $output = mhash($this->hash, $text, $this->key);
break; break;
@ -337,7 +337,7 @@ class Crypt_Hash
$output = call_user_func($this->hash, $output); // step 7 $output = call_user_func($this->hash, $output); // step 7
} }
} else { } else {
switch ( $mode ) { switch ($mode) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
$output = mhash($this->hash, $text); $output = mhash($this->hash, $text);
break; break;

View File

@ -415,7 +415,7 @@ class Crypt_RC2 extends Crypt_Base
if ($t1 <= 0) { if ($t1 <= 0) {
$t1 = $this->default_key_length; $t1 = $this->default_key_length;
} else if ($t1 > 1024) { } elseif ($t1 > 1024) {
$t1 = 1024; $t1 = 1024;
} }
$this->current_key_length = $t1; $this->current_key_length = $t1;

View File

@ -499,7 +499,7 @@ class Crypt_RSA
$this->configFile = CRYPT_RSA_OPENSSL_CONFIG; $this->configFile = CRYPT_RSA_OPENSSL_CONFIG;
if ( !defined('CRYPT_RSA_MODE') ) { if (!defined('CRYPT_RSA_MODE')) {
switch (true) { switch (true) {
// Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular, // Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular,
// Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger // Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger
@ -592,7 +592,7 @@ class Crypt_RSA
} }
// OpenSSL uses 65537 as the exponent and requires RSA keys be 384 bits minimum // OpenSSL uses 65537 as the exponent and requires RSA keys be 384 bits minimum
if ( CRYPT_RSA_MODE == CRYPT_RSA_MODE_OPENSSL && $bits >= 384 && CRYPT_RSA_EXPONENT == 65537) { if (CRYPT_RSA_MODE == CRYPT_RSA_MODE_OPENSSL && $bits >= 384 && CRYPT_RSA_EXPONENT == 65537) {
$config = array(); $config = array();
if (isset($this->configFile)) { if (isset($this->configFile)) {
$config['config'] = $this->configFile; $config['config'] = $this->configFile;
@ -606,7 +606,8 @@ class Crypt_RSA
$publickey = call_user_func_array(array($this, '_convertPublicKey'), array_values($this->_parseKey($publickey, CRYPT_RSA_PUBLIC_FORMAT_PKCS1))); $publickey = call_user_func_array(array($this, '_convertPublicKey'), array_values($this->_parseKey($publickey, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)));
// clear the buffer of error strings stemming from a minimalistic openssl.cnf // clear the buffer of error strings stemming from a minimalistic openssl.cnf
while (openssl_error_string() !== false); while (openssl_error_string() !== false) {
}
return array( return array(
'privatekey' => $privatekey, 'privatekey' => $privatekey,
@ -796,19 +797,39 @@ class Crypt_RSA
$encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none'; $encryption = (!empty($this->password) || is_string($this->password)) ? 'aes256-cbc' : 'none';
$key.= $encryption; $key.= $encryption;
$key.= "\r\nComment: " . $this->comment . "\r\n"; $key.= "\r\nComment: " . $this->comment . "\r\n";
$public = pack('Na*Na*Na*', $public = pack(
strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus'] 'Na*Na*Na*',
strlen('ssh-rsa'),
'ssh-rsa',
strlen($raw['publicExponent']),
$raw['publicExponent'],
strlen($raw['modulus']),
$raw['modulus']
); );
$source = pack('Na*Na*Na*Na*', $source = pack(
strlen('ssh-rsa'), 'ssh-rsa', strlen($encryption), $encryption, 'Na*Na*Na*Na*',
strlen($this->comment), $this->comment, strlen($public), $public strlen('ssh-rsa'),
'ssh-rsa',
strlen($encryption),
$encryption,
strlen($this->comment),
$this->comment,
strlen($public),
$public
); );
$public = base64_encode($public); $public = base64_encode($public);
$key.= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n"; $key.= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
$key.= chunk_split($public, 64); $key.= chunk_split($public, 64);
$private = pack('Na*Na*Na*Na*', $private = pack(
strlen($raw['privateExponent']), $raw['privateExponent'], strlen($raw['prime1']), $raw['prime1'], 'Na*Na*Na*Na*',
strlen($raw['prime2']), $raw['prime2'], strlen($raw['coefficient']), $raw['coefficient'] strlen($raw['privateExponent']),
$raw['privateExponent'],
strlen($raw['prime1']),
$raw['prime1'],
strlen($raw['prime2']),
$raw['prime2'],
strlen($raw['coefficient']),
$raw['coefficient']
); );
if (empty($this->password) && !is_string($this->password)) { if (empty($this->password) && !is_string($this->password)) {
$source.= pack('Na*', strlen($private), $private); $source.= pack('Na*', strlen($private), $private);
@ -875,8 +896,14 @@ class Crypt_RSA
if ($this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_PKCS8) { if ($this->privateKeyFormat == CRYPT_RSA_PRIVATE_FORMAT_PKCS8) {
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA $rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
$RSAPrivateKey = pack('Ca*a*Ca*a*', $RSAPrivateKey = pack(
CRYPT_RSA_ASN1_INTEGER, "\01\00", $rsaOID, 4, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey 'Ca*a*Ca*a*',
CRYPT_RSA_ASN1_INTEGER,
"\01\00",
$rsaOID,
4,
$this->_encodeLength(strlen($RSAPrivateKey)),
$RSAPrivateKey
); );
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
if (!empty($this->password) || is_string($this->password)) { if (!empty($this->password) || is_string($this->password)) {
@ -890,20 +917,35 @@ class Crypt_RSA
$crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount); $crypto->setPassword($this->password, 'pbkdf1', 'md5', $salt, $iterationCount);
$RSAPrivateKey = $crypto->encrypt($RSAPrivateKey); $RSAPrivateKey = $crypto->encrypt($RSAPrivateKey);
$parameters = pack('Ca*a*Ca*N', $parameters = pack(
CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($salt)), $salt, 'Ca*a*Ca*N',
CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(4), $iterationCount CRYPT_RSA_ASN1_OCTETSTRING,
$this->_encodeLength(strlen($salt)),
$salt,
CRYPT_RSA_ASN1_INTEGER,
$this->_encodeLength(4),
$iterationCount
); );
$pbeWithMD5AndDES_CBC = "\x2a\x86\x48\x86\xf7\x0d\x01\x05\x03"; $pbeWithMD5AndDES_CBC = "\x2a\x86\x48\x86\xf7\x0d\x01\x05\x03";
$encryptionAlgorithm = pack('Ca*a*Ca*a*', $encryptionAlgorithm = pack(
CRYPT_RSA_ASN1_OBJECT, $this->_encodeLength(strlen($pbeWithMD5AndDES_CBC)), $pbeWithMD5AndDES_CBC, 'Ca*a*Ca*a*',
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($parameters)), $parameters CRYPT_RSA_ASN1_OBJECT,
$this->_encodeLength(strlen($pbeWithMD5AndDES_CBC)),
$pbeWithMD5AndDES_CBC,
CRYPT_RSA_ASN1_SEQUENCE,
$this->_encodeLength(strlen($parameters)),
$parameters
); );
$RSAPrivateKey = pack('Ca*a*Ca*a*', $RSAPrivateKey = pack(
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($encryptionAlgorithm)), $encryptionAlgorithm, 'Ca*a*Ca*a*',
CRYPT_RSA_ASN1_OCTETSTRING, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey CRYPT_RSA_ASN1_SEQUENCE,
$this->_encodeLength(strlen($encryptionAlgorithm)),
$encryptionAlgorithm,
CRYPT_RSA_ASN1_OCTETSTRING,
$this->_encodeLength(strlen($RSAPrivateKey)),
$RSAPrivateKey
); );
$RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey); $RSAPrivateKey = pack('Ca*a*', CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($RSAPrivateKey)), $RSAPrivateKey);
@ -990,9 +1032,12 @@ class Crypt_RSA
'publicExponent' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($publicExponent)), $publicExponent) 'publicExponent' => pack('Ca*a*', CRYPT_RSA_ASN1_INTEGER, $this->_encodeLength(strlen($publicExponent)), $publicExponent)
); );
$RSAPublicKey = pack('Ca*a*a*', $RSAPublicKey = pack(
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])), 'Ca*a*a*',
$components['modulus'], $components['publicExponent'] CRYPT_RSA_ASN1_SEQUENCE,
$this->_encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])),
$components['modulus'],
$components['publicExponent']
); );
if ($this->publicKeyFormat == CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW) { if ($this->publicKeyFormat == CRYPT_RSA_PUBLIC_FORMAT_PKCS1_RAW) {
@ -1005,8 +1050,11 @@ class Crypt_RSA
$RSAPublicKey = chr(0) . $RSAPublicKey; $RSAPublicKey = chr(0) . $RSAPublicKey;
$RSAPublicKey = chr(3) . $this->_encodeLength(strlen($RSAPublicKey)) . $RSAPublicKey; $RSAPublicKey = chr(3) . $this->_encodeLength(strlen($RSAPublicKey)) . $RSAPublicKey;
$RSAPublicKey = pack('Ca*a*', $RSAPublicKey = pack(
CRYPT_RSA_ASN1_SEQUENCE, $this->_encodeLength(strlen($rsaOID . $RSAPublicKey)), $rsaOID . $RSAPublicKey 'Ca*a*',
CRYPT_RSA_ASN1_SEQUENCE,
$this->_encodeLength(strlen($rsaOID . $RSAPublicKey)),
$rsaOID . $RSAPublicKey
); );
$RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" . $RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
@ -1801,8 +1849,7 @@ class Crypt_RSA
$RSAPublicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publicExponent), $publicExponent, strlen($modulus), $modulus); $RSAPublicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publicExponent), $publicExponent, strlen($modulus), $modulus);
switch($algorithm) switch ($algorithm) {
{
case 'sha256': case 'sha256':
$hash = new Crypt_Hash('sha256'); $hash = new Crypt_Hash('sha256');
$base = base64_encode($hash->hash($RSAPublicKey)); $base = base64_encode($hash->hash($RSAPublicKey));
@ -1928,7 +1975,7 @@ class Crypt_RSA
function _decodeLength(&$string) function _decodeLength(&$string)
{ {
$length = ord($this->_string_shift($string)); $length = ord($this->_string_shift($string));
if ( $length & 0x80 ) { // definite length, long form if ($length & 0x80) { // definite length, long form
$length&= 0x7F; $length&= 0x7F;
$temp = $this->_string_shift($string, $length); $temp = $this->_string_shift($string, $length);
list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4)); list(, $length) = unpack('N', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));

View File

@ -171,9 +171,9 @@ if (!function_exists('crypt_random_string')) {
ini_set('session.use_cookies', $old_use_cookies); ini_set('session.use_cookies', $old_use_cookies);
session_cache_limiter($old_session_cache_limiter); session_cache_limiter($old_session_cache_limiter);
} else { } else {
if ($_OLD_SESSION !== false) { if ($_OLD_SESSION !== false) {
$_SESSION = $_OLD_SESSION; $_SESSION = $_OLD_SESSION;
unset($_OLD_SESSION); unset($_OLD_SESSION);
} else { } else {
unset($_SESSION); unset($_SESSION);
} }

View File

@ -387,7 +387,7 @@ class Crypt_Rijndael extends Crypt_Base
$length >>= 5; $length >>= 5;
if ($length > 8) { if ($length > 8) {
$length = 8; $length = 8;
} else if ($length < 4) { } elseif ($length < 4) {
$length = 4; $length = 4;
} }
$this->Nb = $length; $this->Nb = $length;
@ -690,7 +690,7 @@ class Crypt_Rijndael extends Crypt_Base
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is. // with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord $temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
$temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk]; $temp = $this->_subWord($temp) ^ $rcon[$i / $this->Nk];
} else if ($this->Nk > 6 && $i % $this->Nk == 4) { } elseif ($this->Nk > 6 && $i % $this->Nk == 4) {
$temp = $this->_subWord($temp); $temp = $this->_subWord($temp);
} }
$w[$i] = $w[$i - $this->Nk] ^ $temp; $w[$i] = $w[$i - $this->Nk] ^ $temp;

View File

@ -604,7 +604,9 @@ class Crypt_Twofish extends Crypt_Base
$u^= 0x7fffffff & ($t >> 1); $u^= 0x7fffffff & ($t >> 1);
// Add the modular polynomial on underflow. // Add the modular polynomial on underflow.
if ($t & 0x01) $u^= 0xa6 ; if ($t & 0x01) {
$u^= 0xa6 ;
}
// Remove t * (a + 1/a) * (x^3 + x). // Remove t * (a + 1/a) * (x^3 + x).
$B^= ($u << 24) | ($u << 8); $B^= ($u << 24) | ($u << 8);

View File

@ -306,17 +306,17 @@ class File_ASN1
$tag <<= 7; $tag <<= 7;
$tag |= ord($this->_string_shift($encoded)) & 0x7F; $tag |= ord($this->_string_shift($encoded)) & 0x7F;
$start++; $start++;
} while ( $loop ); } while ($loop);
} }
// Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13 // Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13
$length = ord($this->_string_shift($encoded)); $length = ord($this->_string_shift($encoded));
$start++; $start++;
if ( $length == 0x80 ) { // indefinite length if ($length == 0x80) { // indefinite length
// "[A sender shall] use the indefinite form (see 8.1.3.6) if the encoding is constructed and is not all // "[A sender shall] use the indefinite form (see 8.1.3.6) if the encoding is constructed and is not all
// immediately available." -- paragraph 8.1.3.2.c // immediately available." -- paragraph 8.1.3.2.c
$length = strlen($encoded); $length = strlen($encoded);
} elseif ( $length & 0x80 ) { // definite length, long form } elseif ($length & 0x80) { // definite length, long form
// technically, the long form of the length can be represented by up to 126 octets (bytes), but we'll only // technically, the long form of the length can be represented by up to 126 octets (bytes), but we'll only
// support it up to four. // support it up to four.
$length&= 0x7F; $length&= 0x7F;
@ -1088,7 +1088,7 @@ class File_ASN1
if ($outtype !== false) { if ($outtype !== false) {
return $this->_encode_der($source[$typename], array('type' => $outtype) + $mapping, null, $special); return $this->_encode_der($source[$typename], array('type' => $outtype) + $mapping, null, $special);
} }
} }
$filters = $this->filters; $filters = $this->filters;
foreach ($loc as $part) { foreach ($loc as $part) {

View File

@ -2523,7 +2523,7 @@ class File_X509
$asn1->loadFilters($filters); $asn1->loadFilters($filters);
$result = ''; $result = '';
foreach ($dn['rdnSequence'] as $rdn) { foreach ($dn['rdnSequence'] as $rdn) {
foreach ($rdn as $i=>$attr) { foreach ($rdn as $i => $attr) {
$attr = &$rdn[$i]; $attr = &$rdn[$i];
if (is_array($attr['value'])) { if (is_array($attr['value'])) {
foreach ($attr['value'] as $type => $v) { foreach ($attr['value'] as $type => $v) {
@ -2590,7 +2590,7 @@ class File_X509
break; break;
default: default:
$delim = '/'; $delim = '/';
$desc = preg_replace('#.+-([^-]+)$#', '$1', $prop) . '='; $desc = preg_replace('#.+-([^-]+)$#', '$1', $prop) . '=';
} }
if (!$start) { if (!$start) {
@ -2747,7 +2747,7 @@ class File_X509
break; break;
} }
} }
foreach ($chain as $key=>$value) { foreach ($chain as $key => $value) {
$chain[$key] = new File_X509(); $chain[$key] = new File_X509();
$chain[$key]->loadX509($value); $chain[$key]->loadX509($value);
} }
@ -3212,9 +3212,9 @@ class File_X509
{ {
$year = @gmdate("Y", @strtotime($date)); // the same way ASN1.php parses this $year = @gmdate("Y", @strtotime($date)); // the same way ASN1.php parses this
if ($year < 2050) { if ($year < 2050) {
return array('utcTime' => $date); return array('utcTime' => $date);
} else { } else {
return array('generalTime' => $date); return array('generalTime' => $date);
} }
} }
@ -3268,7 +3268,7 @@ class File_X509
if (isset($subject->domains)) { if (isset($subject->domains)) {
$this->removeExtension('id-ce-subjectAltName'); $this->removeExtension('id-ce-subjectAltName');
} }
} else if (isset($subject->currentCert) && is_array($subject->currentCert) && isset($subject->currentCert['tbsCertList'])) { } elseif (isset($subject->currentCert) && is_array($subject->currentCert) && isset($subject->currentCert['tbsCertList'])) {
return false; return false;
} else { } else {
if (!isset($subject->publicKey)) { if (!isset($subject->publicKey)) {
@ -3307,8 +3307,8 @@ class File_X509
'subject' => $subject->dn, 'subject' => $subject->dn,
'subjectPublicKeyInfo' => $subjectPublicKey 'subjectPublicKeyInfo' => $subjectPublicKey
), ),
'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm), 'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
'signature' => false // this is going to be overwritten later 'signature' => false // this is going to be overwritten later
); );
// Copy extensions from CSR. // Copy extensions from CSR.
@ -3329,8 +3329,7 @@ class File_X509
// ) // )
//), //),
'keyIdentifier' => $issuer->currentKeyIdentifier 'keyIdentifier' => $issuer->currentKeyIdentifier
) ));
);
//$extensions = &$this->currentCert['tbsCertificate']['extensions']; //$extensions = &$this->currentCert['tbsCertificate']['extensions'];
//if (isset($issuer->serialNumber)) { //if (isset($issuer->serialNumber)) {
// $extensions[count($extensions) - 1]['authorityCertSerialNumber'] = $issuer->serialNumber; // $extensions[count($extensions) - 1]['authorityCertSerialNumber'] = $issuer->serialNumber;
@ -3373,7 +3372,8 @@ class File_X509
$keyUsage = array(); $keyUsage = array();
} }
$this->setExtension('id-ce-keyUsage', $this->setExtension(
'id-ce-keyUsage',
array_values(array_unique(array_merge($keyUsage, array('cRLSign', 'keyCertSign')))) array_values(array_unique(array_merge($keyUsage, array('cRLSign', 'keyCertSign'))))
); );
@ -3382,8 +3382,11 @@ class File_X509
$basicConstraints = array(); $basicConstraints = array();
} }
$this->setExtension('id-ce-basicConstraints', $this->setExtension(
array_unique(array_merge(array('cA' => true), $basicConstraints)), true); 'id-ce-basicConstraints',
array_unique(array_merge(array('cA' => true), $basicConstraints)),
true
);
if (!isset($subject->currentKeyIdentifier)) { if (!isset($subject->currentKeyIdentifier)) {
$this->setExtension('id-ce-subjectKeyIdentifier', base64_encode($this->computeKeyIdentifier($this->currentCert)), false, false); $this->setExtension('id-ce-subjectKeyIdentifier', base64_encode($this->computeKeyIdentifier($this->currentCert)), false, false);
@ -3443,8 +3446,8 @@ class File_X509
'subject' => $this->dn, 'subject' => $this->dn,
'subjectPKInfo' => $publicKey 'subjectPKInfo' => $publicKey
), ),
'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm), 'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
'signature' => false // this is going to be overwritten later 'signature' => false // this is going to be overwritten later
); );
} }
@ -3508,8 +3511,8 @@ class File_X509
// crypt_random_string(8) & str_repeat("\x7F", 8) // crypt_random_string(8) & str_repeat("\x7F", 8)
'challenge' => !empty($this->challenge) ? $this->challenge : '' 'challenge' => !empty($this->challenge) ? $this->challenge : ''
), ),
'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm), 'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
'signature' => false // this is going to be overwritten later 'signature' => false // this is going to be overwritten later
); );
} }
@ -3561,8 +3564,8 @@ class File_X509
'issuer' => false, // this is going to be overwritten later 'issuer' => false, // this is going to be overwritten later
'thisUpdate' => $this->_timeField($thisUpdate) // $this->setStartDate() 'thisUpdate' => $this->_timeField($thisUpdate) // $this->setStartDate()
), ),
'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm), 'signatureAlgorithm' => array('algorithm' => $signatureAlgorithm),
'signature' => false // this is going to be overwritten later 'signature' => false // this is going to be overwritten later
); );
} }
@ -3623,8 +3626,7 @@ class File_X509
// ) // )
//), //),
'keyIdentifier' => $issuer->currentKeyIdentifier 'keyIdentifier' => $issuer->currentKeyIdentifier
) ));
);
//$extensions = &$tbsCertList['crlExtensions']; //$extensions = &$tbsCertList['crlExtensions'];
//if (isset($issuer->serialNumber)) { //if (isset($issuer->serialNumber)) {
// $extensions[count($extensions) - 1]['authorityCertSerialNumber'] = $issuer->serialNumber; // $extensions[count($extensions) - 1]['authorityCertSerialNumber'] = $issuer->serialNumber;
@ -4415,7 +4417,6 @@ class File_X509
if (is_array($rclist = &$this->_subArray($this->currentCert, 'tbsCertList/revokedCertificates', true))) { if (is_array($rclist = &$this->_subArray($this->currentCert, 'tbsCertList/revokedCertificates', true))) {
if ($this->_revokedCertificate($rclist, $serial) === false) { // If not yet revoked if ($this->_revokedCertificate($rclist, $serial) === false) { // If not yet revoked
if (($i = $this->_revokedCertificate($rclist, $serial, true)) !== false) { if (($i = $this->_revokedCertificate($rclist, $serial, true)) !== false) {
if (!empty($date)) { if (!empty($date)) {
$rclist[$i]['revocationDate'] = $this->_timeField($date); $rclist[$i]['revocationDate'] = $this->_timeField($date);
} }
@ -4533,7 +4534,7 @@ class File_X509
if (is_array($rclist = $this->_subArray($crl, 'tbsCertList/revokedCertificates'))) { if (is_array($rclist = $this->_subArray($crl, 'tbsCertList/revokedCertificates'))) {
if (($i = $this->_revokedCertificate($rclist, $serial)) !== false) { if (($i = $this->_revokedCertificate($rclist, $serial)) !== false) {
return $this->_getExtension($id, $crl, "tbsCertList/revokedCertificates/$i/crlEntryExtensions"); return $this->_getExtension($id, $crl, "tbsCertList/revokedCertificates/$i/crlEntryExtensions");
} }
} }

View File

@ -253,7 +253,7 @@ class Math_BigInteger
*/ */
function Math_BigInteger($x = 0, $base = 10) function Math_BigInteger($x = 0, $base = 10)
{ {
if ( !defined('MATH_BIGINTEGER_MODE') ) { if (!defined('MATH_BIGINTEGER_MODE')) {
switch (true) { switch (true) {
case extension_loaded('gmp'): case extension_loaded('gmp'):
define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP); define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
@ -334,7 +334,7 @@ class Math_BigInteger
} }
} }
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
switch (true) { switch (true) {
case is_resource($x) && get_resource_type($x) == 'GMP integer': case is_resource($x) && get_resource_type($x) == 'GMP integer':
@ -364,8 +364,8 @@ class Math_BigInteger
$x = ~$x; $x = ~$x;
$this->is_negative = true; $this->is_negative = true;
} }
case 256: case 256:
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$sign = $this->is_negative ? '-' : ''; $sign = $this->is_negative ? '-' : '';
$this->value = gmp_init($sign . '0x' . bin2hex($x)); $this->value = gmp_init($sign . '0x' . bin2hex($x));
@ -401,7 +401,7 @@ class Math_BigInteger
$this->value = $temp->value; $this->value = $temp->value;
} }
break; break;
case 16: case 16:
case -16: case -16:
if ($base > 0 && $x[0] == '-') { if ($base > 0 && $x[0] == '-') {
$this->is_negative = true; $this->is_negative = true;
@ -416,7 +416,7 @@ class Math_BigInteger
$x = bin2hex(~pack('H*', $x)); $x = bin2hex(~pack('H*', $x));
} }
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = $this->is_negative ? '-0x' . $x : '0x' . $x; $temp = $this->is_negative ? '-0x' . $x : '0x' . $x;
$this->value = gmp_init($temp); $this->value = gmp_init($temp);
@ -439,14 +439,14 @@ class Math_BigInteger
$this->value = $temp->value; $this->value = $temp->value;
} }
break; break;
case 10: case 10:
case -10: case -10:
// (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that // (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that
// (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals) // (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
// [^-0-9].*: find any non-numeric characters and then any characters that follow that // [^-0-9].*: find any non-numeric characters and then any characters that follow that
$x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x); $x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$this->value = gmp_init($x); $this->value = gmp_init($x);
break; break;
@ -476,7 +476,7 @@ class Math_BigInteger
$this->value = $temp->value; $this->value = $temp->value;
} }
break; break;
case 2: // base-2 support originally implemented by Lluis Pamies - thanks! case 2: // base-2 support originally implemented by Lluis Pamies - thanks!
case -2: case -2:
if ($base > 0 && $x[0] == '-') { if ($base > 0 && $x[0] == '-') {
$this->is_negative = true; $this->is_negative = true;
@ -551,7 +551,7 @@ class Math_BigInteger
return $comparison < 0 ? ~$bytes : $bytes; return $comparison < 0 ? ~$bytes : $bytes;
} }
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
if (gmp_cmp($this->value, gmp_init(0)) == 0) { if (gmp_cmp($this->value, gmp_init(0)) == 0) {
return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : ''; return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
@ -692,7 +692,7 @@ class Math_BigInteger
*/ */
function toString() function toString()
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
return gmp_strval($this->value); return gmp_strval($this->value);
case MATH_BIGINTEGER_MODE_BCMATH: case MATH_BIGINTEGER_MODE_BCMATH:
@ -849,7 +849,7 @@ class Math_BigInteger
*/ */
function add($y) function add($y)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_add($this->value, $y->value); $temp->value = gmp_add($this->value, $y->value);
@ -891,7 +891,7 @@ class Math_BigInteger
MATH_BIGINTEGER_VALUE => $y_value, MATH_BIGINTEGER_VALUE => $y_value,
MATH_BIGINTEGER_SIGN => $y_negative MATH_BIGINTEGER_SIGN => $y_negative
); );
} else if ($y_size == 0) { } elseif ($y_size == 0) {
return array( return array(
MATH_BIGINTEGER_VALUE => $x_value, MATH_BIGINTEGER_VALUE => $x_value,
MATH_BIGINTEGER_SIGN => $x_negative MATH_BIGINTEGER_SIGN => $x_negative
@ -899,8 +899,8 @@ class Math_BigInteger
} }
// subtract, if appropriate // subtract, if appropriate
if ( $x_negative != $y_negative ) { if ($x_negative != $y_negative) {
if ( $x_value == $y_value ) { if ($x_value == $y_value) {
return array( return array(
MATH_BIGINTEGER_VALUE => array(), MATH_BIGINTEGER_VALUE => array(),
MATH_BIGINTEGER_SIGN => false MATH_BIGINTEGER_SIGN => false
@ -980,7 +980,7 @@ class Math_BigInteger
*/ */
function subtract($y) function subtract($y)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_sub($this->value, $y->value); $temp->value = gmp_sub($this->value, $y->value);
@ -1022,7 +1022,7 @@ class Math_BigInteger
MATH_BIGINTEGER_VALUE => $y_value, MATH_BIGINTEGER_VALUE => $y_value,
MATH_BIGINTEGER_SIGN => !$y_negative MATH_BIGINTEGER_SIGN => !$y_negative
); );
} else if ($y_size == 0) { } elseif ($y_size == 0) {
return array( return array(
MATH_BIGINTEGER_VALUE => $x_value, MATH_BIGINTEGER_VALUE => $x_value,
MATH_BIGINTEGER_SIGN => $x_negative MATH_BIGINTEGER_SIGN => $x_negative
@ -1030,7 +1030,7 @@ class Math_BigInteger
} }
// add, if appropriate (ie. -$x - +$y or +$x - -$y) // add, if appropriate (ie. -$x - +$y or +$x - -$y)
if ( $x_negative != $y_negative ) { if ($x_negative != $y_negative) {
$temp = $this->_add($x_value, false, $y_value, false); $temp = $this->_add($x_value, false, $y_value, false);
$temp[MATH_BIGINTEGER_SIGN] = $x_negative; $temp[MATH_BIGINTEGER_SIGN] = $x_negative;
@ -1039,7 +1039,7 @@ class Math_BigInteger
$diff = $this->_compare($x_value, $x_negative, $y_value, $y_negative); $diff = $this->_compare($x_value, $x_negative, $y_value, $y_negative);
if ( !$diff ) { if (!$diff) {
return array( return array(
MATH_BIGINTEGER_VALUE => array(), MATH_BIGINTEGER_VALUE => array(),
MATH_BIGINTEGER_SIGN => false MATH_BIGINTEGER_SIGN => false
@ -1047,7 +1047,7 @@ class Math_BigInteger
} }
// switch $x and $y around, if appropriate. // switch $x and $y around, if appropriate.
if ( (!$x_negative && $diff < 0) || ($x_negative && $diff > 0) ) { if ((!$x_negative && $diff < 0) || ($x_negative && $diff > 0)) {
$temp = $x_value; $temp = $x_value;
$x_value = $y_value; $x_value = $y_value;
$y_value = $temp; $y_value = $temp;
@ -1115,7 +1115,7 @@ class Math_BigInteger
*/ */
function multiply($x) function multiply($x)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_mul($this->value, $x->value); $temp->value = gmp_mul($this->value, $x->value);
@ -1159,7 +1159,7 @@ class Math_BigInteger
$x_length = count($x_value); $x_length = count($x_value);
$y_length = count($y_value); $y_length = count($y_value);
if ( !$x_length || !$y_length ) { // a 0 is being multiplied if (!$x_length || !$y_length) { // a 0 is being multiplied
return array( return array(
MATH_BIGINTEGER_VALUE => array(), MATH_BIGINTEGER_VALUE => array(),
MATH_BIGINTEGER_SIGN => false MATH_BIGINTEGER_SIGN => false
@ -1189,11 +1189,11 @@ class Math_BigInteger
$x_length = count($x_value); $x_length = count($x_value);
$y_length = count($y_value); $y_length = count($y_value);
if ( !$x_length || !$y_length ) { // a 0 is being multiplied if (!$x_length || !$y_length) { // a 0 is being multiplied
return array(); return array();
} }
if ( $x_length < $y_length ) { if ($x_length < $y_length) {
$temp = $x_value; $temp = $x_value;
$x_value = $y_value; $x_value = $y_value;
$y_value = $temp; $y_value = $temp;
@ -1306,7 +1306,7 @@ class Math_BigInteger
*/ */
function _baseSquare($value) function _baseSquare($value)
{ {
if ( empty($value) ) { if (empty($value)) {
return array(); return array();
} }
$square_value = $this->_array_repeat(0, 2 * count($value)); $square_value = $this->_array_repeat(0, 2 * count($value));
@ -1402,7 +1402,7 @@ class Math_BigInteger
*/ */
function divide($y) function divide($y)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$quotient = new Math_BigInteger(); $quotient = new Math_BigInteger();
$remainder = new Math_BigInteger(); $remainder = new Math_BigInteger();
@ -1439,7 +1439,7 @@ class Math_BigInteger
} }
static $zero; static $zero;
if ( !isset($zero) ) { if (!isset($zero)) {
$zero = new Math_BigInteger(); $zero = new Math_BigInteger();
} }
@ -1453,16 +1453,16 @@ class Math_BigInteger
$diff = $x->compare($y); $diff = $x->compare($y);
if ( !$diff ) { if (!$diff) {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = array(1); $temp->value = array(1);
$temp->is_negative = $x_sign != $y_sign; $temp->is_negative = $x_sign != $y_sign;
return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger())); return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger()));
} }
if ( $diff < 0 ) { if ($diff < 0) {
// if $x is negative, "add" $y. // if $x is negative, "add" $y.
if ( $x_sign ) { if ($x_sign) {
$x = $y->subtract($x); $x = $y->subtract($x);
} }
return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x)); return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x));
@ -1496,7 +1496,7 @@ class Math_BigInteger
// $temp = $y << ($x_max - $y_max-1) in base 2**26 // $temp = $y << ($x_max - $y_max-1) in base 2**26
$temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value); $temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value);
while ( $x->compare($temp) >= 0 ) { while ($x->compare($temp) >= 0) {
// calculate the "common residue" // calculate the "common residue"
++$quotient_value[$x_max - $y_max]; ++$quotient_value[$x_max - $y_max];
$x = $x->subtract($temp); $x = $x->subtract($temp);
@ -1532,7 +1532,7 @@ class Math_BigInteger
$rhs_value = array($x_window[2], $x_window[1], $x_window[0]); $rhs_value = array($x_window[2], $x_window[1], $x_window[0]);
while ( $lhs->compare($rhs) > 0 ) { while ($lhs->compare($rhs) > 0) {
--$quotient_value[$q_index]; --$quotient_value[$q_index];
$lhs->value = array($quotient_value[$q_index]); $lhs->value = array($quotient_value[$q_index]);
@ -1563,7 +1563,7 @@ class Math_BigInteger
$quotient->is_negative = $x_sign != $y_sign; $quotient->is_negative = $x_sign != $y_sign;
// calculate the "common residue", if appropriate // calculate the "common residue", if appropriate
if ( $x_sign ) { if ($x_sign) {
$y->_rshift($shift); $y->_rshift($shift);
$x = $y->subtract($x); $x = $y->subtract($x);
} }
@ -1652,7 +1652,7 @@ class Math_BigInteger
return $this->_normalize($temp->modPow($e, $n)); return $this->_normalize($temp->modPow($e, $n));
} }
if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP ) { if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP) {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_powm($this->value, $e->value, $n->value); $temp->value = gmp_powm($this->value, $e->value, $n->value);
@ -1675,17 +1675,23 @@ class Math_BigInteger
'publicExponent' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['publicExponent'])), $components['publicExponent']) 'publicExponent' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['publicExponent'])), $components['publicExponent'])
); );
$RSAPublicKey = pack('Ca*a*a*', $RSAPublicKey = pack(
48, $this->_encodeASN1Length(strlen($components['modulus']) + strlen($components['publicExponent'])), 'Ca*a*a*',
$components['modulus'], $components['publicExponent'] 48,
$this->_encodeASN1Length(strlen($components['modulus']) + strlen($components['publicExponent'])),
$components['modulus'],
$components['publicExponent']
); );
$rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA $rsaOID = pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
$RSAPublicKey = chr(0) . $RSAPublicKey; $RSAPublicKey = chr(0) . $RSAPublicKey;
$RSAPublicKey = chr(3) . $this->_encodeASN1Length(strlen($RSAPublicKey)) . $RSAPublicKey; $RSAPublicKey = chr(3) . $this->_encodeASN1Length(strlen($RSAPublicKey)) . $RSAPublicKey;
$encapsulated = pack('Ca*a*', $encapsulated = pack(
48, $this->_encodeASN1Length(strlen($rsaOID . $RSAPublicKey)), $rsaOID . $RSAPublicKey 'Ca*a*',
48,
$this->_encodeASN1Length(strlen($rsaOID . $RSAPublicKey)),
$rsaOID . $RSAPublicKey
); );
$RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" . $RSAPublicKey = "-----BEGIN PUBLIC KEY-----\r\n" .
@ -1699,25 +1705,25 @@ class Math_BigInteger
} }
} }
if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH ) { if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = bcpowmod($this->value, $e->value, $n->value, 0); $temp->value = bcpowmod($this->value, $e->value, $n->value, 0);
return $this->_normalize($temp); return $this->_normalize($temp);
} }
if ( empty($e->value) ) { if (empty($e->value)) {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = array(1); $temp->value = array(1);
return $this->_normalize($temp); return $this->_normalize($temp);
} }
if ( $e->value == array(1) ) { if ($e->value == array(1)) {
list(, $temp) = $this->divide($n); list(, $temp) = $this->divide($n);
return $this->_normalize($temp); return $this->_normalize($temp);
} }
if ( $e->value == array(2) ) { if ($e->value == array(2)) {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = $this->_square($this->value); $temp->value = $this->_square($this->value);
list(, $temp) = $temp->divide($n); list(, $temp) = $temp->divide($n);
@ -1732,14 +1738,14 @@ class Math_BigInteger
// made uncallable // made uncallable
// is the modulo odd? // is the modulo odd?
if ( $n->value[0] & 1 ) { if ($n->value[0] & 1) {
return $this->_normalize($this->_slidingWindow($e, $n, MATH_BIGINTEGER_MONTGOMERY)); return $this->_normalize($this->_slidingWindow($e, $n, MATH_BIGINTEGER_MONTGOMERY));
} }
// if it's not, it's even // if it's not, it's even
// find the lowest set bit (eg. the max pow of 2 that divides $n) // find the lowest set bit (eg. the max pow of 2 that divides $n)
for ($i = 0; $i < count($n->value); ++$i) { for ($i = 0; $i < count($n->value); ++$i) {
if ( $n->value[$i] ) { if ($n->value[$i]) {
$temp = decbin($n->value[$i]); $temp = decbin($n->value[$i]);
$j = strlen($temp) - strrpos($temp, '1') - 1; $j = strlen($temp) - strrpos($temp, '1') - 1;
$j+= 26 * $i; $j+= 26 * $i;
@ -1817,7 +1823,8 @@ class Math_BigInteger
// calculate the appropriate window size. // calculate the appropriate window size.
// $window_size == 3 if $window_ranges is between 25 and 81, for example. // $window_size == 3 if $window_ranges is between 25 and 81, for example.
for ($i = 0, $window_size = 1; $e_length > $window_ranges[$i] && $i < count($window_ranges); ++$window_size, ++$i); for ($i = 0, $window_size = 1; $e_length > $window_ranges[$i] && $i < count($window_ranges); ++$window_size, ++$i) {
}
$n_value = $n->value; $n_value = $n->value;
@ -1837,13 +1844,13 @@ class Math_BigInteger
$result = array(1); $result = array(1);
$result = $this->_prepareReduce($result, $n_value, $mode); $result = $this->_prepareReduce($result, $n_value, $mode);
for ($i = 0; $i < $e_length; ) { for ($i = 0; $i < $e_length;) {
if ( !$e_bits[$i] ) { if (!$e_bits[$i]) {
$result = $this->_squareReduce($result, $n_value, $mode); $result = $this->_squareReduce($result, $n_value, $mode);
++$i; ++$i;
} else { } else {
for ($j = $window_size - 1; $j > 0; --$j) { for ($j = $window_size - 1; $j > 0; --$j) {
if ( !empty($e_bits[$i + $j]) ) { if (!empty($e_bits[$i + $j])) {
break; break;
} }
} }
@ -2027,7 +2034,7 @@ class Math_BigInteger
// n = 2 * m.length // n = 2 * m.length
if ( ($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false ) { if (($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
$key = count($cache[MATH_BIGINTEGER_VARIABLE]); $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
$cache[MATH_BIGINTEGER_VARIABLE][] = $m; $cache[MATH_BIGINTEGER_VARIABLE][] = $m;
@ -2116,7 +2123,7 @@ class Math_BigInteger
return $temp->value; return $temp->value;
} }
if ( ($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false ) { if (($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
$key = count($cache[MATH_BIGINTEGER_VARIABLE]); $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
$cache[MATH_BIGINTEGER_VARIABLE][] = $n; $cache[MATH_BIGINTEGER_VARIABLE][] = $n;
$lhs = new Math_BigInteger(); $lhs = new Math_BigInteger();
@ -2177,14 +2184,14 @@ class Math_BigInteger
$x_length = count($x_value); $x_length = count($x_value);
$y_length = count($y_value); $y_length = count($y_value);
if ( !$x_length || !$y_length ) { // a 0 is being multiplied if (!$x_length || !$y_length) { // a 0 is being multiplied
return array( return array(
MATH_BIGINTEGER_VALUE => array(), MATH_BIGINTEGER_VALUE => array(),
MATH_BIGINTEGER_SIGN => false MATH_BIGINTEGER_SIGN => false
); );
} }
if ( $x_length < $y_length ) { if ($x_length < $y_length) {
$temp = $x_value; $temp = $x_value;
$x_value = $y_value; $x_value = $y_value;
$y_value = $temp; $y_value = $temp;
@ -2258,7 +2265,7 @@ class Math_BigInteger
MATH_BIGINTEGER_DATA => array() MATH_BIGINTEGER_DATA => array()
); );
if ( ($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false ) { if (($key = array_search($n, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
$key = count($cache[MATH_BIGINTEGER_VARIABLE]); $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
$cache[MATH_BIGINTEGER_VARIABLE][] = $x; $cache[MATH_BIGINTEGER_VARIABLE][] = $x;
$cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($n); $cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($n);
@ -2314,7 +2321,7 @@ class Math_BigInteger
MATH_BIGINTEGER_DATA => array() MATH_BIGINTEGER_DATA => array()
); );
if ( ($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false ) { if (($key = array_search($m, $cache[MATH_BIGINTEGER_VARIABLE])) === false) {
$key = count($cache[MATH_BIGINTEGER_VARIABLE]); $key = count($cache[MATH_BIGINTEGER_VARIABLE]);
$cache[MATH_BIGINTEGER_VARIABLE][] = $m; $cache[MATH_BIGINTEGER_VARIABLE][] = $m;
$cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($m); $cache[MATH_BIGINTEGER_DATA][] = $this->_modInverse67108864($m);
@ -2429,7 +2436,7 @@ class Math_BigInteger
*/ */
function modInverse($n) function modInverse($n)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_invert($this->value, $n->value); $temp->value = gmp_invert($this->value, $n->value);
@ -2495,7 +2502,7 @@ class Math_BigInteger
*/ */
function extendedGCD($n) function extendedGCD($n)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
extract(gmp_gcdext($this->value, $n->value)); extract(gmp_gcdext($this->value, $n->value));
@ -2545,7 +2552,7 @@ class Math_BigInteger
$g = new Math_BigInteger(); $g = new Math_BigInteger();
$g->value = array(1); $g->value = array(1);
while ( !(($x->value[0] & 1)|| ($y->value[0] & 1)) ) { while (!(($x->value[0] & 1)|| ($y->value[0] & 1))) {
$x->_rshift(1); $x->_rshift(1);
$y->_rshift(1); $y->_rshift(1);
$g->_lshift(1); $g->_lshift(1);
@ -2562,10 +2569,10 @@ class Math_BigInteger
$a->value = $d->value = $g->value = array(1); $a->value = $d->value = $g->value = array(1);
$b->value = $c->value = array(); $b->value = $c->value = array();
while ( !empty($u->value) ) { while (!empty($u->value)) {
while ( !($u->value[0] & 1) ) { while (!($u->value[0] & 1)) {
$u->_rshift(1); $u->_rshift(1);
if ( (!empty($a->value) && ($a->value[0] & 1)) || (!empty($b->value) && ($b->value[0] & 1)) ) { if ((!empty($a->value) && ($a->value[0] & 1)) || (!empty($b->value) && ($b->value[0] & 1))) {
$a = $a->add($y); $a = $a->add($y);
$b = $b->subtract($x); $b = $b->subtract($x);
} }
@ -2573,9 +2580,9 @@ class Math_BigInteger
$b->_rshift(1); $b->_rshift(1);
} }
while ( !($v->value[0] & 1) ) { while (!($v->value[0] & 1)) {
$v->_rshift(1); $v->_rshift(1);
if ( (!empty($d->value) && ($d->value[0] & 1)) || (!empty($c->value) && ($c->value[0] & 1)) ) { if ((!empty($d->value) && ($d->value[0] & 1)) || (!empty($c->value) && ($c->value[0] & 1))) {
$c = $c->add($y); $c = $c->add($y);
$d = $d->subtract($x); $d = $d->subtract($x);
} }
@ -2640,7 +2647,7 @@ class Math_BigInteger
{ {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp->value = gmp_abs($this->value); $temp->value = gmp_abs($this->value);
break; break;
@ -2674,7 +2681,7 @@ class Math_BigInteger
*/ */
function compare($y) function compare($y)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
return gmp_cmp($this->value, $y->value); return gmp_cmp($this->value, $y->value);
case MATH_BIGINTEGER_MODE_BCMATH: case MATH_BIGINTEGER_MODE_BCMATH:
@ -2697,13 +2704,13 @@ class Math_BigInteger
*/ */
function _compare($x_value, $x_negative, $y_value, $y_negative) function _compare($x_value, $x_negative, $y_value, $y_negative)
{ {
if ( $x_negative != $y_negative ) { if ($x_negative != $y_negative) {
return ( !$x_negative && $y_negative ) ? 1 : -1; return ( !$x_negative && $y_negative ) ? 1 : -1;
} }
$result = $x_negative ? -1 : 1; $result = $x_negative ? -1 : 1;
if ( count($x_value) != count($y_value) ) { if (count($x_value) != count($y_value)) {
return ( count($x_value) > count($y_value) ) ? $result : -$result; return ( count($x_value) > count($y_value) ) ? $result : -$result;
} }
$size = max(count($x_value), count($y_value)); $size = max(count($x_value), count($y_value));
@ -2732,7 +2739,7 @@ class Math_BigInteger
*/ */
function equals($x) function equals($x)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
return gmp_cmp($this->value, $x->value) == 0; return gmp_cmp($this->value, $x->value) == 0;
default: default:
@ -2752,7 +2759,7 @@ class Math_BigInteger
function setPrecision($bits) function setPrecision($bits)
{ {
$this->precision = $bits; $this->precision = $bits;
if ( MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH ) { if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_BCMATH) {
$this->bitmask = new Math_BigInteger(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256); $this->bitmask = new Math_BigInteger(chr((1 << ($bits & 0x7)) - 1) . str_repeat(chr(0xFF), $bits >> 3), 256);
} else { } else {
$this->bitmask = new Math_BigInteger(bcpow('2', $bits, 0)); $this->bitmask = new Math_BigInteger(bcpow('2', $bits, 0));
@ -2772,7 +2779,7 @@ class Math_BigInteger
*/ */
function bitwise_and($x) function bitwise_and($x)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_and($this->value, $x->value); $temp->value = gmp_and($this->value, $x->value);
@ -2813,7 +2820,7 @@ class Math_BigInteger
*/ */
function bitwise_or($x) function bitwise_or($x)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_or($this->value, $x->value); $temp->value = gmp_or($this->value, $x->value);
@ -2853,7 +2860,7 @@ class Math_BigInteger
*/ */
function bitwise_xor($x) function bitwise_xor($x)
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
$temp->value = gmp_xor($this->value, $x->value); $temp->value = gmp_xor($this->value, $x->value);
@ -2933,7 +2940,7 @@ class Math_BigInteger
{ {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
static $two; static $two;
@ -2971,7 +2978,7 @@ class Math_BigInteger
{ {
$temp = new Math_BigInteger(); $temp = new Math_BigInteger();
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
static $two; static $two;
@ -3010,7 +3017,7 @@ class Math_BigInteger
if ($this->precision > 0) { if ($this->precision > 0) {
$precision = $this->precision; $precision = $this->precision;
if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH ) { if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
$mask = $this->bitmask->subtract(new Math_BigInteger(1)); $mask = $this->bitmask->subtract(new Math_BigInteger(1));
$mask = $mask->toBytes(); $mask = $mask->toBytes();
} else { } else {
@ -3018,7 +3025,8 @@ class Math_BigInteger
} }
} else { } else {
$temp = ord($bits[0]); $temp = ord($bits[0]);
for ($i = 0; $temp >> $i; ++$i); for ($i = 0; $temp >> $i; ++$i) {
}
$precision = 8 * strlen($bits) - 8 + $i; $precision = 8 * strlen($bits) - 8 + $i;
$mask = chr((1 << ($precision & 0x7)) - 1) . str_repeat(chr(0xFF), $precision >> 3); $mask = chr((1 << ($precision & 0x7)) - 1) . str_repeat(chr(0xFF), $precision >> 3);
} }
@ -3129,7 +3137,7 @@ class Math_BigInteger
if (!$compare) { if (!$compare) {
return $this->_normalize($min); return $this->_normalize($min);
} else if ($compare < 0) { } elseif ($compare < 0) {
// if $min is bigger then $max, swap $min and $max // if $min is bigger then $max, swap $min and $max
$temp = $max; $temp = $max;
$max = $min; $max = $min;
@ -3210,7 +3218,7 @@ class Math_BigInteger
if (!$compare) { if (!$compare) {
return $min->isPrime() ? $min : false; return $min->isPrime() ? $min : false;
} else if ($compare < 0) { } elseif ($compare < 0) {
// if $min is bigger then $max, swap $min and $max // if $min is bigger then $max, swap $min and $max
$temp = $max; $temp = $max;
$max = $min; $max = $min;
@ -3228,7 +3236,7 @@ class Math_BigInteger
$x = $this->random($min, $max); $x = $this->random($min, $max);
// gmp_nextprime() requires PHP 5 >= 5.2.0 per <http://php.net/gmp-nextprime>. // gmp_nextprime() requires PHP 5 >= 5.2.0 per <http://php.net/gmp-nextprime>.
if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && function_exists('gmp_nextprime') ) { if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP && function_exists('gmp_nextprime')) {
$p = new Math_BigInteger(); $p = new Math_BigInteger();
$p->value = gmp_nextprime($x->value); $p->value = gmp_nextprime($x->value);
@ -3294,7 +3302,7 @@ class Math_BigInteger
*/ */
function _make_odd() function _make_odd()
{ {
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
gmp_setbit($this->value, 0); gmp_setbit($this->value, 0);
break; break;
@ -3346,7 +3354,7 @@ class Math_BigInteger
// ie. gmp_testbit($this, 0) // ie. gmp_testbit($this, 0)
// ie. isEven() or !isOdd() // ie. isEven() or !isOdd()
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
return gmp_prob_prime($this->value, $t) != 0; return gmp_prob_prime($this->value, $t) != 0;
case MATH_BIGINTEGER_MODE_BCMATH: case MATH_BIGINTEGER_MODE_BCMATH:
@ -3383,7 +3391,7 @@ class Math_BigInteger
953, 967, 971, 977, 983, 991, 997 953, 967, 971, 977, 983, 991, 997
); );
if ( MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL ) { if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
for ($i = 0; $i < count($primes); ++$i) { for ($i = 0; $i < count($primes); ++$i) {
$primes[$i] = new Math_BigInteger($primes[$i]); $primes[$i] = new Math_BigInteger($primes[$i]);
} }
@ -3399,7 +3407,7 @@ class Math_BigInteger
} }
// see HAC 4.4.1 "Random search for probable primes" // see HAC 4.4.1 "Random search for probable primes"
if ( MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL ) { if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
foreach ($primes as $prime) { foreach ($primes as $prime) {
list(, $r) = $this->divide($prime); list(, $r) = $this->divide($prime);
if ($r->equals($zero)) { if ($r->equals($zero)) {
@ -3423,7 +3431,7 @@ class Math_BigInteger
$r = $n_1->copy(); $r = $n_1->copy();
$r_value = $r->value; $r_value = $r->value;
// ie. $s = gmp_scan1($n, 0) and $r = gmp_div_q($n, gmp_pow(gmp_init('2'), $s)); // ie. $s = gmp_scan1($n, 0) and $r = gmp_div_q($n, gmp_pow(gmp_init('2'), $s));
if ( MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH ) { if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_BCMATH) {
$s = 0; $s = 0;
// if $n was 1, $r would be 0 and this would be an infinite loop, hence our $this->equals($one) check earlier // if $n was 1, $r would be 0 and this would be an infinite loop, hence our $this->equals($one) check earlier
while ($r->value[strlen($r->value) - 1] % 2 == 0) { while ($r->value[strlen($r->value) - 1] % 2 == 0) {
@ -3433,7 +3441,8 @@ class Math_BigInteger
} else { } else {
for ($i = 0, $r_length = count($r_value); $i < $r_length; ++$i) { for ($i = 0, $r_length = count($r_value); $i < $r_length; ++$i) {
$temp = ~$r_value[$i] & 0xFFFFFF; $temp = ~$r_value[$i] & 0xFFFFFF;
for ($j = 1; ($temp >> $j) & 1; ++$j); for ($j = 1; ($temp >> $j) & 1; ++$j) {
}
if ($j != 25) { if ($j != 25) {
break; break;
} }
@ -3472,7 +3481,7 @@ class Math_BigInteger
*/ */
function _lshift($shift) function _lshift($shift)
{ {
if ( $shift == 0 ) { if ($shift == 0) {
return; return;
} }
@ -3488,7 +3497,7 @@ class Math_BigInteger
$this->value[$i] = (int) ($temp - $carry * MATH_BIGINTEGER_BASE_FULL); $this->value[$i] = (int) ($temp - $carry * MATH_BIGINTEGER_BASE_FULL);
} }
if ( $carry ) { if ($carry) {
$this->value[count($this->value)] = $carry; $this->value[count($this->value)] = $carry;
} }
@ -3516,7 +3525,7 @@ class Math_BigInteger
$carry_shift = MATH_BIGINTEGER_BASE - $shift; $carry_shift = MATH_BIGINTEGER_BASE - $shift;
$carry_mask = (1 << $shift) - 1; $carry_mask = (1 << $shift) - 1;
if ( $num_digits ) { if ($num_digits) {
$this->value = array_slice($this->value, $num_digits); $this->value = array_slice($this->value, $num_digits);
} }
@ -3546,7 +3555,7 @@ class Math_BigInteger
$result->precision = $this->precision; $result->precision = $this->precision;
$result->bitmask = $this->bitmask; $result->bitmask = $this->bitmask;
switch ( MATH_BIGINTEGER_MODE ) { switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP: case MATH_BIGINTEGER_MODE_GMP:
if (!empty($result->bitmask->value)) { if (!empty($result->bitmask->value)) {
$result->value = gmp_and($result->value, $result->bitmask->value); $result->value = gmp_and($result->value, $result->bitmask->value);
@ -3563,7 +3572,7 @@ class Math_BigInteger
$value = &$result->value; $value = &$result->value;
if ( !count($value) ) { if (!count($value)) {
return $result; return $result;
} }
@ -3593,7 +3602,7 @@ class Math_BigInteger
function _trim($value) function _trim($value)
{ {
for ($i = count($value) - 1; $i >= 0; --$i) { for ($i = count($value) - 1; $i >= 0; --$i) {
if ( $value[$i] ) { if ($value[$i]) {
break; break;
} }
unset($value[$i]); unset($value[$i]);

View File

@ -303,7 +303,7 @@ class Net_SCP
case NET_SCP_SSH1: case NET_SCP_SSH1:
$data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($data), $data); $data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($data), $data);
$this->ssh->_send_binary_packet($data); $this->ssh->_send_binary_packet($data);
} }
} }
/** /**
@ -339,7 +339,7 @@ class Net_SCP
return false; return false;
} }
} }
} }
} }
/** /**
@ -355,6 +355,6 @@ class Net_SCP
break; break;
case NET_SCP_SSH1: case NET_SCP_SSH1:
$this->ssh->disconnect(); $this->ssh->disconnect();
} }
} }
} }

View File

@ -434,8 +434,15 @@ class Net_SFTP extends Net_SSH2
$this->window_size_server_to_client[NET_SFTP_CHANNEL] = $this->window_size; $this->window_size_server_to_client[NET_SFTP_CHANNEL] = $this->window_size;
$packet = pack('CNa*N3', $packet = pack(
NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', NET_SFTP_CHANNEL, $this->window_size, 0x4000); 'CNa*N3',
NET_SSH2_MSG_CHANNEL_OPEN,
strlen('session'),
'session',
NET_SFTP_CHANNEL,
$this->window_size,
0x4000
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -448,8 +455,16 @@ class Net_SFTP extends Net_SSH2
return false; return false;
} }
$packet = pack('CNNa*CNa*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SFTP_CHANNEL], strlen('subsystem'), 'subsystem', 1, strlen('sftp'), 'sftp'); 'CNNa*CNa*',
NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SFTP_CHANNEL],
strlen('subsystem'),
'subsystem',
1,
strlen('sftp'),
'sftp'
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
} }
@ -464,8 +479,16 @@ class Net_SFTP extends Net_SSH2
"exec sftp-server"; "exec sftp-server";
// we don't do $this->exec($command, false) because exec() operates on a different channel and plus the SSH_MSG_CHANNEL_OPEN that exec() does // we don't do $this->exec($command, false) because exec() operates on a different channel and plus the SSH_MSG_CHANNEL_OPEN that exec() does
// is redundant // is redundant
$packet = pack('CNNa*CNa*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SFTP_CHANNEL], strlen('exec'), 'exec', 1, strlen($command), $command); 'CNNa*CNa*',
NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SFTP_CHANNEL],
strlen('exec'),
'exec',
1,
strlen($command),
$command
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
} }
@ -806,7 +829,7 @@ class Net_SFTP extends Net_SSH2
static $depth = 0; static $depth = 0;
foreach ($files as $key=>$value) { foreach ($files as $key => $value) {
if ($depth != 0 && $key == '..') { if ($depth != 0 && $key == '..') {
unset($files[$key]); unset($files[$key]);
continue; continue;
@ -1071,7 +1094,7 @@ class Net_SFTP extends Net_SSH2
$temp = &$this->stat_cache; $temp = &$this->stat_cache;
$max = count($dirs) - 1; $max = count($dirs) - 1;
foreach ($dirs as $i=>$dir) { foreach ($dirs as $i => $dir) {
// if $temp is an object that means one of two things. // if $temp is an object that means one of two things.
// 1. a file was deleted and changed to a directory behind phpseclib's back // 1. a file was deleted and changed to a directory behind phpseclib's back
// 2. it's a symlink. when lstat is done it's unclear what it's a symlink to // 2. it's a symlink. when lstat is done it's unclear what it's a symlink to
@ -1110,7 +1133,7 @@ class Net_SFTP extends Net_SSH2
$temp = &$this->stat_cache; $temp = &$this->stat_cache;
$max = count($dirs) - 1; $max = count($dirs) - 1;
foreach ($dirs as $i=>$dir) { foreach ($dirs as $i => $dir) {
if ($i === $max) { if ($i === $max) {
unset($temp[$dir]); unset($temp[$dir]);
return true; return true;
@ -1540,7 +1563,7 @@ class Net_SFTP extends Net_SSH2
} }
unset($entries['.'], $entries['..']); unset($entries['.'], $entries['..']);
foreach ($entries as $filename=>$props) { foreach ($entries as $filename => $props) {
if (!isset($props['type'])) { if (!isset($props['type'])) {
return false; return false;
} }
@ -2214,7 +2237,7 @@ class Net_SFTP extends Net_SSH2
} }
unset($entries['.'], $entries['..']); unset($entries['.'], $entries['..']);
foreach ($entries as $filename=>$props) { foreach ($entries as $filename => $props) {
if (!isset($props['type'])) { if (!isset($props['type'])) {
return false; return false;
} }
@ -2416,13 +2439,20 @@ class Net_SFTP extends Net_SSH2
} }
switch ($type) { switch ($type) {
case NET_SFTP_TYPE_BLOCK_DEVICE: return 'block'; case NET_SFTP_TYPE_BLOCK_DEVICE:
case NET_SFTP_TYPE_CHAR_DEVICE: return 'char'; return 'block';
case NET_SFTP_TYPE_DIRECTORY: return 'dir'; case NET_SFTP_TYPE_CHAR_DEVICE:
case NET_SFTP_TYPE_FIFO: return 'fifo'; return 'char';
case NET_SFTP_TYPE_REGULAR: return 'file'; case NET_SFTP_TYPE_DIRECTORY:
case NET_SFTP_TYPE_SYMLINK: return 'link'; return 'dir';
default: return false; case NET_SFTP_TYPE_FIFO:
return 'fifo';
case NET_SFTP_TYPE_REGULAR:
return 'file';
case NET_SFTP_TYPE_SYMLINK:
return 'link';
default:
return false;
} }
} }
@ -2681,7 +2711,7 @@ class Net_SFTP extends Net_SSH2
{ {
$packet = $this->request_id !== false ? $packet = $this->request_id !== false ?
pack('NCNa*', strlen($data) + 5, $type, $this->request_id, $data) : pack('NCNa*', strlen($data) + 5, $type, $this->request_id, $data) :
pack('NCa*', strlen($data) + 1, $type, $data); pack('NCa*', strlen($data) + 1, $type, $data);
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
$result = $this->_send_channel_packet(NET_SFTP_CHANNEL, $packet); $result = $this->_send_channel_packet(NET_SFTP_CHANNEL, $packet);

View File

@ -621,7 +621,7 @@ class Net_SSH1
// get a list of the supported ciphers // get a list of the supported ciphers
extract(unpack('Nsupported_ciphers_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4))); extract(unpack('Nsupported_ciphers_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4)));
foreach ($this->supported_ciphers as $mask=>$name) { foreach ($this->supported_ciphers as $mask => $name) {
if (($supported_ciphers_mask & (1 << $mask)) == 0) { if (($supported_ciphers_mask & (1 << $mask)) == 0) {
unset($this->supported_ciphers[$mask]); unset($this->supported_ciphers[$mask]);
} }
@ -629,7 +629,7 @@ class Net_SSH1
// get a list of the supported authentications // get a list of the supported authentications
extract(unpack('Nsupported_authentications_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4))); extract(unpack('Nsupported_authentications_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4)));
foreach ($this->supported_authentications as $mask=>$name) { foreach ($this->supported_authentications as $mask => $name) {
if (($supported_authentications_mask & (1 << $mask)) == 0) { if (($supported_authentications_mask & (1 << $mask)) == 0) {
unset($this->supported_authentications[$mask]); unset($this->supported_authentications[$mask]);
} }
@ -691,7 +691,7 @@ class Net_SSH1
$this->crypto = new Crypt_DES(); $this->crypto = new Crypt_DES();
$this->crypto->disablePadding(); $this->crypto->disablePadding();
$this->crypto->enableContinuousBuffer(); $this->crypto->enableContinuousBuffer();
$this->crypto->setKey(substr($session_key, 0, 8)); $this->crypto->setKey(substr($session_key, 0, 8));
break; break;
case NET_SSH1_CIPHER_3DES: case NET_SSH1_CIPHER_3DES:
if (!class_exists('Crypt_TripleDES')) { if (!class_exists('Crypt_TripleDES')) {
@ -760,7 +760,7 @@ class Net_SSH1
if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_SUCCESS) { if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_SUCCESS) {
$this->bitmap |= NET_SSH1_MASK_LOGIN; $this->bitmap |= NET_SSH1_MASK_LOGIN;
return true; return true;
} else if ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_FAILURE) { } elseif ($response[NET_SSH1_RESPONSE_TYPE] != NET_SSH1_SMSG_FAILURE) {
user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE'); user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE');
return false; return false;
} }
@ -786,7 +786,7 @@ class Net_SSH1
if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_SUCCESS) { if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_SUCCESS) {
$this->bitmap |= NET_SSH1_MASK_LOGIN; $this->bitmap |= NET_SSH1_MASK_LOGIN;
return true; return true;
} else if ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_FAILURE) { } elseif ($response[NET_SSH1_RESPONSE_TYPE] == NET_SSH1_SMSG_FAILURE) {
return false; return false;
} else { } else {
user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE'); user_error('Expected SSH_SMSG_SUCCESS or SSH_SMSG_FAILURE');
@ -1299,7 +1299,7 @@ class Net_SSH1
$crc = 0x00000000; $crc = 0x00000000;
$length = strlen($data); $length = strlen($data);
for ($i=0;$i<$length;$i++) { for ($i=0; $i<$length; $i++) {
// We AND $crc >> 8 with 0x00FFFFFF because we want the eight newly added bits to all // We AND $crc >> 8 with 0x00FFFFFF because we want the eight newly added bits to all
// be zero. PHP, unfortunately, doesn't always do this. 0x80000000 >> 8, as an example, // be zero. PHP, unfortunately, doesn't always do this. 0x80000000 >> 8, as an example,
// yields 0xFF800000 - not 0x00800000. The following link elaborates: // yields 0xFF800000 - not 0x00800000. The following link elaborates:
@ -1398,7 +1398,7 @@ class Net_SSH1
{ {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) { foreach ($args as $arg) {
foreach ($arg as $key=>$value) { foreach ($arg as $key => $value) {
if (!defined($value)) { if (!defined($value)) {
define($value, $key); define($value, $key);
} else { } else {

View File

@ -1323,14 +1323,32 @@ class Net_SSH2
$first_kex_packet_follows = $first_kex_packet_follows != 0; $first_kex_packet_follows = $first_kex_packet_follows != 0;
// the sending of SSH2_MSG_KEXINIT could go in one of two places. this is the second place. // the sending of SSH2_MSG_KEXINIT could go in one of two places. this is the second place.
$kexinit_payload_client = pack('Ca*Na*Na*Na*Na*Na*Na*Na*Na*Na*Na*CN', $kexinit_payload_client = pack(
NET_SSH2_MSG_KEXINIT, $client_cookie, strlen($str_kex_algorithms), $str_kex_algorithms, 'Ca*Na*Na*Na*Na*Na*Na*Na*Na*Na*Na*CN',
strlen($str_server_host_key_algorithms), $str_server_host_key_algorithms, strlen($encryption_algorithms_client_to_server), NET_SSH2_MSG_KEXINIT,
$encryption_algorithms_client_to_server, strlen($encryption_algorithms_server_to_client), $encryption_algorithms_server_to_client, $client_cookie,
strlen($mac_algorithms_client_to_server), $mac_algorithms_client_to_server, strlen($mac_algorithms_server_to_client), strlen($str_kex_algorithms),
$mac_algorithms_server_to_client, strlen($compression_algorithms_client_to_server), $compression_algorithms_client_to_server, $str_kex_algorithms,
strlen($compression_algorithms_server_to_client), $compression_algorithms_server_to_client, 0, '', 0, '', strlen($str_server_host_key_algorithms),
0, 0 $str_server_host_key_algorithms,
strlen($encryption_algorithms_client_to_server),
$encryption_algorithms_client_to_server,
strlen($encryption_algorithms_server_to_client),
$encryption_algorithms_server_to_client,
strlen($mac_algorithms_client_to_server),
$mac_algorithms_client_to_server,
strlen($mac_algorithms_server_to_client),
$mac_algorithms_server_to_client,
strlen($compression_algorithms_client_to_server),
$compression_algorithms_client_to_server,
strlen($compression_algorithms_server_to_client),
$compression_algorithms_server_to_client,
0,
'',
0,
'',
0,
0
); );
if (!$this->_send_binary_packet($kexinit_payload_client)) { if (!$this->_send_binary_packet($kexinit_payload_client)) {
@ -1339,7 +1357,8 @@ class Net_SSH2
// here ends the second place. // here ends the second place.
// we need to decide upon the symmetric encryption algorithms before we do the diffie-hellman key exchange // 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++); for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_server_to_client); $i++) {
}
if ($i == count($encryption_algorithms)) { if ($i == count($encryption_algorithms)) {
user_error('No compatible server to client encryption algorithms found'); user_error('No compatible server to client encryption algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1385,7 +1404,8 @@ class Net_SSH2
$decryptKeyLength = 0; $decryptKeyLength = 0;
} }
for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_client_to_server); $i++); for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_client_to_server); $i++) {
}
if ($i == count($encryption_algorithms)) { if ($i == count($encryption_algorithms)) {
user_error('No compatible client to server encryption algorithms found'); user_error('No compatible client to server encryption algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1432,19 +1452,23 @@ class Net_SSH2
$keyLength = $decryptKeyLength > $encryptKeyLength ? $decryptKeyLength : $encryptKeyLength; $keyLength = $decryptKeyLength > $encryptKeyLength ? $decryptKeyLength : $encryptKeyLength;
// through diffie-hellman key exchange a symmetric key is obtained // 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++); for ($i = 0; $i < count($kex_algorithms) && !in_array($kex_algorithms[$i], $this->kex_algorithms);
$i++) {
}
if ($i == count($kex_algorithms)) { if ($i == count($kex_algorithms)) {
user_error('No compatible key exchange algorithms found'); user_error('No compatible key exchange algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
} }
if (strpos($kex_algorithms[$i], 'diffie-hellman-group-exchange') === 0) { if (strpos($kex_algorithms[$i], 'diffie-hellman-group-exchange') === 0) {
$dh_group_sizes_packed = pack('NNN', $dh_group_sizes_packed = pack(
'NNN',
$this->kex_dh_group_size_min, $this->kex_dh_group_size_min,
$this->kex_dh_group_size_preferred, $this->kex_dh_group_size_preferred,
$this->kex_dh_group_size_max $this->kex_dh_group_size_max
); );
$packet = pack('Ca*', $packet = pack(
'Ca*',
NET_SSH2_MSG_KEXDH_GEX_REQUEST, NET_SSH2_MSG_KEXDH_GEX_REQUEST,
$dh_group_sizes_packed $dh_group_sizes_packed
); );
@ -1471,10 +1495,13 @@ class Net_SSH2
$gBytes = $this->_string_shift($response, $gLength); $gBytes = $this->_string_shift($response, $gLength);
$g = new Math_BigInteger($gBytes, -256); $g = new Math_BigInteger($gBytes, -256);
$exchange_hash_rfc4419 = pack('a*Na*Na*', $exchange_hash_rfc4419 = pack(
'a*Na*Na*',
$dh_group_sizes_packed, $dh_group_sizes_packed,
$primeLength, $primeBytes, $primeLength,
$gLength, $gBytes $primeBytes,
$gLength,
$gBytes
); );
$clientKexInitMessage = NET_SSH2_MSG_KEXDH_GEX_INIT; $clientKexInitMessage = NET_SSH2_MSG_KEXDH_GEX_INIT;
@ -1572,16 +1599,25 @@ class Net_SSH2
$key = $f->modPow($x, $prime); $key = $f->modPow($x, $prime);
$keyBytes = $key->toBytes(true); $keyBytes = $key->toBytes(true);
$this->exchange_hash = pack('Na*Na*Na*Na*Na*a*Na*Na*Na*', $this->exchange_hash = pack(
strlen($this->identifier), $this->identifier, 'Na*Na*Na*Na*Na*a*Na*Na*Na*',
strlen($this->server_identifier), $this->server_identifier, strlen($this->identifier),
strlen($kexinit_payload_client), $kexinit_payload_client, $this->identifier,
strlen($kexinit_payload_server), $kexinit_payload_server, strlen($this->server_identifier),
strlen($this->server_public_host_key), $this->server_public_host_key, $this->server_identifier,
strlen($kexinit_payload_client),
$kexinit_payload_client,
strlen($kexinit_payload_server),
$kexinit_payload_server,
strlen($this->server_public_host_key),
$this->server_public_host_key,
$exchange_hash_rfc4419, $exchange_hash_rfc4419,
strlen($eBytes), $eBytes, strlen($eBytes),
strlen($fBytes), $fBytes, $eBytes,
strlen($keyBytes), $keyBytes strlen($fBytes),
$fBytes,
strlen($keyBytes),
$keyBytes
); );
$this->exchange_hash = $kexHash->hash($this->exchange_hash); $this->exchange_hash = $kexHash->hash($this->exchange_hash);
@ -1590,7 +1626,8 @@ class Net_SSH2
$this->session_id = $this->exchange_hash; $this->session_id = $this->exchange_hash;
} }
for ($i = 0; $i < count($server_host_key_algorithms) && !in_array($server_host_key_algorithms[$i], $this->server_host_key_algorithms); $i++); 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)) { if ($i == count($server_host_key_algorithms)) {
user_error('No compatible server host key algorithms found'); user_error('No compatible server host key algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1601,7 +1638,8 @@ class Net_SSH2
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
} }
$packet = pack('C', $packet = pack(
'C',
NET_SSH2_MSG_NEWKEYS NET_SSH2_MSG_NEWKEYS
); );
@ -1833,7 +1871,8 @@ class Net_SSH2
$this->decrypt->decrypt(str_repeat("\0", 1536)); $this->decrypt->decrypt(str_repeat("\0", 1536));
} }
for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_client_to_server); $i++); for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_client_to_server); $i++) {
}
if ($i == count($mac_algorithms)) { if ($i == count($mac_algorithms)) {
user_error('No compatible client to server message authentication algorithms found'); user_error('No compatible client to server message authentication algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1862,7 +1901,8 @@ class Net_SSH2
$createKeyLength = 16; $createKeyLength = 16;
} }
for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_server_to_client); $i++); for ($i = 0; $i < count($mac_algorithms) && !in_array($mac_algorithms[$i], $this->mac_algorithms_server_to_client); $i++) {
}
if ($i == count($mac_algorithms)) { if ($i == count($mac_algorithms)) {
user_error('No compatible server to client message authentication algorithms found'); user_error('No compatible server to client message authentication algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1909,14 +1949,16 @@ class Net_SSH2
} }
$this->hmac_check->setKey(substr($key, 0, $checkKeyLength)); $this->hmac_check->setKey(substr($key, 0, $checkKeyLength));
for ($i = 0; $i < count($compression_algorithms) && !in_array($compression_algorithms[$i], $this->compression_algorithms_server_to_client); $i++); for ($i = 0; $i < count($compression_algorithms) && !in_array($compression_algorithms[$i], $this->compression_algorithms_server_to_client); $i++) {
}
if ($i == count($compression_algorithms)) { if ($i == count($compression_algorithms)) {
user_error('No compatible server to client compression algorithms found'); user_error('No compatible server to client compression algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
} }
$this->decompress = $compression_algorithms[$i] == 'zlib'; $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++); for ($i = 0; $i < count($compression_algorithms) && !in_array($compression_algorithms[$i], $this->compression_algorithms_client_to_server); $i++) {
}
if ($i == count($compression_algorithms)) { if ($i == count($compression_algorithms)) {
user_error('No compatible client to server compression algorithms found'); user_error('No compatible client to server compression algorithms found');
return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED); return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
@ -1992,8 +2034,11 @@ class Net_SSH2
} }
if (!($this->bitmap & NET_SSH2_MASK_LOGIN_REQ)) { if (!($this->bitmap & NET_SSH2_MASK_LOGIN_REQ)) {
$packet = pack('CNa*', $packet = pack(
NET_SSH2_MSG_SERVICE_REQUEST, strlen('ssh-userauth'), 'ssh-userauth' 'CNa*',
NET_SSH2_MSG_SERVICE_REQUEST,
strlen('ssh-userauth'),
'ssh-userauth'
); );
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
@ -2038,9 +2083,15 @@ class Net_SSH2
} }
if (!isset($password)) { if (!isset($password)) {
$packet = pack('CNa*Na*Na*', $packet = pack(
NET_SSH2_MSG_USERAUTH_REQUEST, strlen($username), $username, strlen('ssh-connection'), 'ssh-connection', 'CNa*Na*Na*',
strlen('none'), 'none' NET_SSH2_MSG_USERAUTH_REQUEST,
strlen($username),
$username,
strlen('ssh-connection'),
'ssh-connection',
strlen('none'),
'none'
); );
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
@ -2065,18 +2116,36 @@ class Net_SSH2
} }
} }
$packet = pack('CNa*Na*Na*CNa*', $packet = pack(
NET_SSH2_MSG_USERAUTH_REQUEST, strlen($username), $username, strlen('ssh-connection'), 'ssh-connection', 'CNa*Na*Na*CNa*',
strlen('password'), 'password', 0, strlen($password), $password NET_SSH2_MSG_USERAUTH_REQUEST,
strlen($username),
$username,
strlen('ssh-connection'),
'ssh-connection',
strlen('password'),
'password',
0,
strlen($password),
$password
); );
// remove the username and password from the logged packet // remove the username and password from the logged packet
if (!defined('NET_SSH2_LOGGING')) { if (!defined('NET_SSH2_LOGGING')) {
$logged = null; $logged = null;
} else { } else {
$logged = pack('CNa*Na*Na*CNa*', $logged = pack(
NET_SSH2_MSG_USERAUTH_REQUEST, strlen('username'), 'username', strlen('ssh-connection'), 'ssh-connection', 'CNa*Na*Na*CNa*',
strlen('password'), 'password', 0, strlen('password'), 'password' NET_SSH2_MSG_USERAUTH_REQUEST,
strlen('username'),
'username',
strlen('ssh-connection'),
'ssh-connection',
strlen('password'),
'password',
0,
strlen('password'),
'password'
); );
} }
@ -2136,9 +2205,19 @@ class Net_SSH2
*/ */
function _keyboard_interactive_login($username, $password) function _keyboard_interactive_login($username, $password)
{ {
$packet = pack('CNa*Na*Na*Na*Na*', $packet = pack(
NET_SSH2_MSG_USERAUTH_REQUEST, strlen($username), $username, strlen('ssh-connection'), 'ssh-connection', 'CNa*Na*Na*Na*Na*',
strlen('keyboard-interactive'), 'keyboard-interactive', 0, '', 0, '' NET_SSH2_MSG_USERAUTH_REQUEST,
strlen($username),
$username,
strlen('ssh-connection'),
'ssh-connection',
strlen('keyboard-interactive'),
'keyboard-interactive',
0,
'',
0,
''
); );
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
@ -2209,7 +2288,7 @@ class Net_SSH2
// see http://tools.ietf.org/html/rfc4256#section-3.2 // see http://tools.ietf.org/html/rfc4256#section-3.2
if (strlen($this->last_interactive_response)) { if (strlen($this->last_interactive_response)) {
$this->last_interactive_response = ''; $this->last_interactive_response = '';
} else if (defined('NET_SSH2_LOGGING')) { } elseif (defined('NET_SSH2_LOGGING')) {
$this->message_number_log[count($this->message_number_log) - 1] = str_replace( $this->message_number_log[count($this->message_number_log) - 1] = str_replace(
'UNKNOWN', 'UNKNOWN',
'NET_SSH2_MSG_USERAUTH_INFO_REQUEST', 'NET_SSH2_MSG_USERAUTH_INFO_REQUEST',
@ -2305,13 +2384,25 @@ class Net_SSH2
'e' => $publickey['e']->toBytes(true), 'e' => $publickey['e']->toBytes(true),
'n' => $publickey['n']->toBytes(true) 'n' => $publickey['n']->toBytes(true)
); );
$publickey = pack('Na*Na*Na*', $publickey = pack(
strlen('ssh-rsa'), 'ssh-rsa', strlen($publickey['e']), $publickey['e'], strlen($publickey['n']), $publickey['n'] 'Na*Na*Na*',
strlen('ssh-rsa'),
'ssh-rsa',
strlen($publickey['e']),
$publickey['e'],
strlen($publickey['n']),
$publickey['n']
); );
$part1 = pack('CNa*Na*Na*', $part1 = pack(
NET_SSH2_MSG_USERAUTH_REQUEST, strlen($username), $username, strlen('ssh-connection'), 'ssh-connection', 'CNa*Na*Na*',
strlen('publickey'), 'publickey' NET_SSH2_MSG_USERAUTH_REQUEST,
strlen($username),
$username,
strlen('ssh-connection'),
'ssh-connection',
strlen('publickey'),
'publickey'
); );
$part2 = pack('Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publickey), $publickey); $part2 = pack('Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($publickey), $publickey);
@ -2429,8 +2520,15 @@ class Net_SSH2
// uses 0x4000, that's what will be used here, as well. // uses 0x4000, that's what will be used here, as well.
$packet_size = 0x4000; $packet_size = 0x4000;
$packet = pack('CNa*N3', $packet = pack(
NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', NET_SSH2_CHANNEL_EXEC, $this->window_size_server_to_client[NET_SSH2_CHANNEL_EXEC], $packet_size); 'CNa*N3',
NET_SSH2_MSG_CHANNEL_OPEN,
strlen('session'),
'session',
NET_SSH2_CHANNEL_EXEC,
$this->window_size_server_to_client[NET_SSH2_CHANNEL_EXEC],
$packet_size
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2445,9 +2543,22 @@ class Net_SSH2
if ($this->request_pty === true) { if ($this->request_pty === true) {
$terminal_modes = pack('C', NET_SSH2_TTY_OP_END); $terminal_modes = pack('C', NET_SSH2_TTY_OP_END);
$packet = pack('CNNa*CNa*N5a*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_EXEC], strlen('pty-req'), 'pty-req', 1, strlen('vt100'), 'vt100', 'CNNa*CNa*N5a*',
$this->windowColumns, $this->windowRows, 0, 0, strlen($terminal_modes), $terminal_modes); NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SSH2_CHANNEL_EXEC],
strlen('pty-req'),
'pty-req',
1,
strlen('vt100'),
'vt100',
$this->windowColumns,
$this->windowRows,
0,
0,
strlen($terminal_modes),
$terminal_modes
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2481,8 +2592,16 @@ class Net_SSH2
// although, in theory, the size of SSH_MSG_CHANNEL_REQUEST could exceed the maximum packet size established by // although, in theory, the size of SSH_MSG_CHANNEL_REQUEST could exceed the maximum packet size established by
// SSH_MSG_CHANNEL_OPEN_CONFIRMATION, RFC4254#section-5.1 states that the "maximum packet size" refers to the // SSH_MSG_CHANNEL_OPEN_CONFIRMATION, RFC4254#section-5.1 states that the "maximum packet size" refers to the
// "maximum size of an individual data packet". ie. SSH_MSG_CHANNEL_DATA. RFC4254#section-5.2 corroborates. // "maximum size of an individual data packet". ie. SSH_MSG_CHANNEL_DATA. RFC4254#section-5.2 corroborates.
$packet = pack('CNNa*CNa*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_EXEC], strlen('exec'), 'exec', 1, strlen($command), $command); 'CNNa*CNa*',
NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SSH2_CHANNEL_EXEC],
strlen('exec'),
'exec',
1,
strlen($command),
$command
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2539,8 +2658,15 @@ class Net_SSH2
$this->window_size_server_to_client[NET_SSH2_CHANNEL_SHELL] = $this->window_size; $this->window_size_server_to_client[NET_SSH2_CHANNEL_SHELL] = $this->window_size;
$packet_size = 0x4000; $packet_size = 0x4000;
$packet = pack('CNa*N3', $packet = pack(
NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', NET_SSH2_CHANNEL_SHELL, $this->window_size_server_to_client[NET_SSH2_CHANNEL_SHELL], $packet_size); 'CNa*N3',
NET_SSH2_MSG_CHANNEL_OPEN,
strlen('session'),
'session',
NET_SSH2_CHANNEL_SHELL,
$this->window_size_server_to_client[NET_SSH2_CHANNEL_SHELL],
$packet_size
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2554,9 +2680,22 @@ class Net_SSH2
} }
$terminal_modes = pack('C', NET_SSH2_TTY_OP_END); $terminal_modes = pack('C', NET_SSH2_TTY_OP_END);
$packet = pack('CNNa*CNa*N5a*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_SHELL], strlen('pty-req'), 'pty-req', 1, strlen('vt100'), 'vt100', 'CNNa*CNa*N5a*',
$this->windowColumns, $this->windowRows, 0, 0, strlen($terminal_modes), $terminal_modes); NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SSH2_CHANNEL_SHELL],
strlen('pty-req'),
'pty-req',
1,
strlen('vt100'),
'vt100',
$this->windowColumns,
$this->windowRows,
0,
0,
strlen($terminal_modes),
$terminal_modes
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2580,8 +2719,14 @@ class Net_SSH2
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION); return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
} }
$packet = pack('CNNa*C', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_SHELL], strlen('shell'), 'shell', 1); 'CNNa*C',
NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SSH2_CHANNEL_SHELL],
strlen('shell'),
'shell',
1
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
} }
@ -2728,8 +2873,15 @@ class Net_SSH2
{ {
$this->window_size_server_to_client[NET_SSH2_CHANNEL_SUBSYSTEM] = $this->window_size; $this->window_size_server_to_client[NET_SSH2_CHANNEL_SUBSYSTEM] = $this->window_size;
$packet = pack('CNa*N3', $packet = pack(
NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', NET_SSH2_CHANNEL_SUBSYSTEM, $this->window_size, 0x4000); 'CNa*N3',
NET_SSH2_MSG_CHANNEL_OPEN,
strlen('session'),
'session',
NET_SSH2_CHANNEL_SUBSYSTEM,
$this->window_size,
0x4000
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
@ -2742,8 +2894,16 @@ class Net_SSH2
return false; return false;
} }
$packet = pack('CNNa*CNa*', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $this->server_channels[NET_SSH2_CHANNEL_SUBSYSTEM], strlen('subsystem'), 'subsystem', 1, strlen($subsystem), $subsystem); 'CNNa*CNa*',
NET_SSH2_MSG_CHANNEL_REQUEST,
$this->server_channels[NET_SSH2_CHANNEL_SUBSYSTEM],
strlen('subsystem'),
'subsystem',
1,
strlen($subsystem),
$subsystem
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
} }
@ -2753,7 +2913,7 @@ class Net_SSH2
$response = $this->_get_channel_packet(NET_SSH2_CHANNEL_SUBSYSTEM); $response = $this->_get_channel_packet(NET_SSH2_CHANNEL_SUBSYSTEM);
if ($response === false) { if ($response === false) {
return false; return false;
} }
$this->channel_status[NET_SSH2_CHANNEL_SUBSYSTEM] = NET_SSH2_MSG_CHANNEL_DATA; $this->channel_status[NET_SSH2_CHANNEL_SUBSYSTEM] = NET_SSH2_MSG_CHANNEL_DATA;
@ -2997,34 +3157,48 @@ class Net_SSH2
extract(unpack('Nlength', $this->_string_shift($payload, 4))); extract(unpack('Nlength', $this->_string_shift($payload, 4)));
$data = $this->_string_shift($payload, $length); $data = $this->_string_shift($payload, $length);
extract(unpack('Nserver_channel', $this->_string_shift($payload, 4))); extract(unpack('Nserver_channel', $this->_string_shift($payload, 4)));
switch($data) { switch ($data) {
case 'auth-agent': case 'auth-agent':
case 'auth-agent@openssh.com': case 'auth-agent@openssh.com':
if (isset($this->agent)) { if (isset($this->agent)) {
$new_channel = NET_SSH2_CHANNEL_AGENT_FORWARD; $new_channel = NET_SSH2_CHANNEL_AGENT_FORWARD;
extract(unpack('Nremote_window_size', $this->_string_shift($payload, 4))); extract(unpack('Nremote_window_size', $this->_string_shift($payload, 4)));
extract(unpack('Nremote_maximum_packet_size', $this->_string_shift($payload, 4))); extract(unpack('Nremote_maximum_packet_size', $this->_string_shift($payload, 4)));
$this->packet_size_client_to_server[$new_channel] = $remote_window_size; $this->packet_size_client_to_server[$new_channel] = $remote_window_size;
$this->window_size_server_to_client[$new_channel] = $remote_maximum_packet_size; $this->window_size_server_to_client[$new_channel] = $remote_maximum_packet_size;
$this->window_size_client_to_server[$new_channel] = $this->window_size; $this->window_size_client_to_server[$new_channel] = $this->window_size;
$packet_size = 0x4000; $packet_size = 0x4000;
$packet = pack('CN4', $packet = pack(
NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, $server_channel, $new_channel, $packet_size, $packet_size); 'CN4',
NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
$server_channel,
$new_channel,
$packet_size,
$packet_size
);
$this->server_channels[$new_channel] = $server_channel; $this->server_channels[$new_channel] = $server_channel;
$this->channel_status[$new_channel] = NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION; $this->channel_status[$new_channel] = NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION;
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return false; return false;
} }
} }
break; break;
default: default:
$packet = pack('CN3a*Na*', $packet = pack(
NET_SSH2_MSG_REQUEST_FAILURE, $server_channel, NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED, 0, '', 0, ''); 'CN3a*Na*',
NET_SSH2_MSG_REQUEST_FAILURE,
$server_channel,
NET_SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED,
0,
'',
0,
''
);
if (!$this->_send_binary_packet($packet)) { if (!$this->_send_binary_packet($packet)) {
return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION); return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
@ -3500,7 +3674,8 @@ class Net_SSH2
); );
$temp = $this->_string_shift($data, $max_size); $temp = $this->_string_shift($data, $max_size);
$packet = pack('CN2a*', $packet = pack(
'CN2a*',
NET_SSH2_MSG_CHANNEL_DATA, NET_SSH2_MSG_CHANNEL_DATA,
$this->server_channels[$client_channel], $this->server_channels[$client_channel],
strlen($temp), strlen($temp),
@ -3541,7 +3716,8 @@ class Net_SSH2
$this->curTimeout = 0; $this->curTimeout = 0;
while (!is_bool($this->_get_channel_packet($client_channel))); while (!is_bool($this->_get_channel_packet($client_channel))) {
}
if ($want_reply) { if ($want_reply) {
$this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel])); $this->_send_binary_packet(pack('CN', NET_SSH2_MSG_CHANNEL_CLOSE, $this->server_channels[$client_channel]));
@ -3601,7 +3777,7 @@ class Net_SSH2
{ {
$args = func_get_args(); $args = func_get_args();
foreach ($args as $arg) { foreach ($args as $arg) {
foreach ($arg as $key=>$value) { foreach ($arg as $key => $value) {
if (!defined($value)) { if (!defined($value)) {
define($value, $key); define($value, $key);
} else { } else {

View File

@ -378,8 +378,14 @@ class System_SSH_Agent
return false; return false;
} }
$packet = pack('CNNa*C', $packet = pack(
NET_SSH2_MSG_CHANNEL_REQUEST, $ssh->server_channels[$request_channel], strlen('auth-agent-req@openssh.com'), 'auth-agent-req@openssh.com', 1); 'CNNa*C',
NET_SSH2_MSG_CHANNEL_REQUEST,
$ssh->server_channels[$request_channel],
strlen('auth-agent-req@openssh.com'),
'auth-agent-req@openssh.com',
1
);
$ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_REQUEST; $ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_REQUEST;

View File

@ -12,7 +12,7 @@ class Functional_Net_SCPSSH2UserStoryTest extends PhpseclibFunctionalTestCase
static protected $exampleData; static protected $exampleData;
static protected $exampleDataLength; static protected $exampleDataLength;
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
self::$remoteFile = uniqid('phpseclib-scp-ssh2-') . '.txt'; self::$remoteFile = uniqid('phpseclib-scp-ssh2-') . '.txt';

View File

@ -10,7 +10,7 @@ require_once 'Crypt/Base.php';
class Functional_Net_SFTPLargeFileTest extends Functional_Net_SFTPTestCase class Functional_Net_SFTPLargeFileTest extends Functional_Net_SFTPTestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) { if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) {
self::markTestSkipped('This test depends on mcrypt or openssl for performance.'); self::markTestSkipped('This test depends on mcrypt or openssl for performance.');

View File

@ -13,7 +13,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
static protected $exampleDataLength; static protected $exampleDataLength;
static protected $buffer; static protected $buffer;
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
@ -137,7 +137,9 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
{ {
$r = substr(self::$buffer, 0, $length); $r = substr(self::$buffer, 0, $length);
self::$buffer = substr(self::$buffer, $length); self::$buffer = substr(self::$buffer, $length);
if (strlen($r)) return $r; if (strlen($r)) {
return $r;
}
return null; return null;
} }
@ -335,7 +337,8 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
if ($sftp->is_file($file)) { if ($sftp->is_file($file)) {
$cur_size = $sftp->size($file); $cur_size = $sftp->size($file);
$this->assertLessThanOrEqual( $this->assertLessThanOrEqual(
$last_size, $cur_size, $last_size,
$cur_size,
'Failed asserting that nlist() is in descending order' 'Failed asserting that nlist() is in descending order'
); );
$last_size = $cur_size; $last_size = $cur_size;
@ -386,7 +389,8 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
$stat = $sftp->stat('symlink'); $stat = $sftp->stat('symlink');
$lstat = $sftp->lstat('symlink'); $lstat = $sftp->lstat('symlink');
$this->assertNotEquals( $this->assertNotEquals(
$stat, $lstat, $stat,
$lstat,
'Failed asserting that stat and lstat returned different output for a symlink' 'Failed asserting that stat and lstat returned different output for a symlink'
); );
@ -419,7 +423,9 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
*/ */
public function testReadlink($sftp) public function testReadlink($sftp)
{ {
$this->assertInternalType('string', $sftp->readlink('symlink'), $this->assertInternalType(
'string',
$sftp->readlink('symlink'),
'Failed asserting that a symlink\'s target could be read' 'Failed asserting that a symlink\'s target could be read'
); );
@ -434,12 +440,14 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
{ {
$stat = $sftp->stat('.'); $stat = $sftp->stat('.');
$this->assertInternalType( $this->assertInternalType(
'array', $stat, 'array',
$stat,
'Failed asserting that stat on . returns an array' 'Failed asserting that stat on . returns an array'
); );
$lstat = $sftp->lstat('.'); $lstat = $sftp->lstat('.');
$this->assertInternalType( $this->assertInternalType(
'array', $lstat, 'array',
$lstat,
'Failed asserting that lstat on . returns an array' 'Failed asserting that lstat on . returns an array'
); );

View File

@ -7,7 +7,7 @@
abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (extension_loaded('runkit')) { if (extension_loaded('runkit')) {
if (extension_loaded('gmp')) { if (extension_loaded('gmp')) {

View File

@ -53,7 +53,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
* *
* @return null * @return null
*/ */
static protected function ensureConstant($constant, $expected) protected static function ensureConstant($constant, $expected)
{ {
if (defined($constant)) { if (defined($constant)) {
$value = constant($constant); $value = constant($constant);
@ -86,7 +86,7 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
* *
* @return null * @return null
*/ */
static protected function reRequireFile($filename) protected static function reRequireFile($filename)
{ {
if (function_exists('runkit_import')) { if (function_exists('runkit_import')) {
$result = runkit_import( $result = runkit_import(

View File

@ -35,7 +35,7 @@ class Unit_Crypt_DESTest extends PhpseclibTestCase
$des->setPreferredEngine(CRYPT_ENGINE_OPENSSL); $des->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) { if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) {
$openssl = $des->encrypt('d'); $openssl = $des->encrypt('d');
$this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result'); $this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result');
} else { } else {
self::markTestSkipped('Unable to initialize OpenSSL engine'); self::markTestSkipped('Unable to initialize OpenSSL engine');
} }
@ -69,7 +69,7 @@ class Unit_Crypt_DESTest extends PhpseclibTestCase
$des->setPreferredEngine(CRYPT_ENGINE_OPENSSL); $des->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) { if ($des->getEngine() == CRYPT_ENGINE_OPENSSL) {
$openssl = $des->decrypt('d'); $openssl = $des->decrypt('d');
$this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result'); $this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result');
} else { } else {
self::markTestSkipped('Unable to initialize OpenSSL engine'); self::markTestSkipped('Unable to initialize OpenSSL engine');
} }

View File

@ -20,7 +20,7 @@ class Unit_Crypt_Hash_MD5Test extends Unit_Crypt_Hash_TestCase
$this->assertHashesTo($this->getInstance(), $message, $result); $this->assertHashesTo($this->getInstance(), $message, $result);
} }
static public function hashData() public static function hashData()
{ {
return array( return array(
array('', 'd41d8cd98f00b204e9800998ecf8427e'), array('', 'd41d8cd98f00b204e9800998ecf8427e'),
@ -37,7 +37,7 @@ class Unit_Crypt_Hash_MD5Test extends Unit_Crypt_Hash_TestCase
$this->assertHMACsTo($this->getInstance(), $key, $message, $result); $this->assertHMACsTo($this->getInstance(), $key, $message, $result);
} }
static public function hmacData() public static function hmacData()
{ {
return array( return array(
array('', '', '74e6f7298a9c2d168935f58c001bad88'), array('', '', '74e6f7298a9c2d168935f58c001bad88'),

View File

@ -20,7 +20,7 @@ class Unit_Crypt_Hash_SHA256Test extends Unit_Crypt_Hash_TestCase
$this->assertHashesTo($this->getInstance(), $message, $result); $this->assertHashesTo($this->getInstance(), $message, $result);
} }
static public function hashData() public static function hashData()
{ {
return array( return array(
array( array(
@ -46,7 +46,7 @@ class Unit_Crypt_Hash_SHA256Test extends Unit_Crypt_Hash_TestCase
$this->assertHMACsTo($this->getInstance(), $key, $message, $result); $this->assertHMACsTo($this->getInstance(), $key, $message, $result);
} }
static public function hmacData() public static function hmacData()
{ {
return array( return array(
// RFC 4231 // RFC 4231

View File

@ -20,7 +20,7 @@ class Unit_Crypt_Hash_SHA512Test extends Unit_Crypt_Hash_TestCase
$this->assertHashesTo($this->getInstance(), $message, $result); $this->assertHashesTo($this->getInstance(), $message, $result);
} }
static public function hashData() public static function hashData()
{ {
return array( return array(
array( array(
@ -46,7 +46,7 @@ class Unit_Crypt_Hash_SHA512Test extends Unit_Crypt_Hash_TestCase
$this->assertHMACsTo($this->getInstance(), $key, $message, $result); $this->assertHMACsTo($this->getInstance(), $key, $message, $result);
} }
static public function hmacData() public static function hmacData()
{ {
return array( return array(
// RFC 4231 // RFC 4231

View File

@ -9,7 +9,7 @@ require_once 'Crypt/Hash.php';
abstract class Unit_Crypt_Hash_TestCase extends PhpseclibTestCase abstract class Unit_Crypt_Hash_TestCase extends PhpseclibTestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (!defined('CRYPT_HASH_MODE')) { if (!defined('CRYPT_HASH_MODE')) {
define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL); define('CRYPT_HASH_MODE', CRYPT_HASH_MODE_INTERNAL);

View File

@ -95,7 +95,7 @@ class Unit_Crypt_RC2Test extends PhpseclibTestCase
$rc2->setPreferredEngine(CRYPT_ENGINE_OPENSSL); $rc2->setPreferredEngine(CRYPT_ENGINE_OPENSSL);
if ($rc2->getEngine() == CRYPT_ENGINE_OPENSSL) { if ($rc2->getEngine() == CRYPT_ENGINE_OPENSSL) {
$openssl = $rc2->encrypt('d'); $openssl = $rc2->encrypt('d');
$this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result'); $this->assertEquals($result, $openssl, 'Failed asserting that the OpenSSL engine produced the correct result');
} else { } else {
self::markTestSkipped('Unable to initialize OpenSSL engine'); self::markTestSkipped('Unable to initialize OpenSSL engine');
} }

View File

@ -17,7 +17,7 @@ class Unit_Crypt_TwofishTest extends PhpseclibTestCase
CRYPT_ENGINE_OPENSSL => 'OpenSSL', CRYPT_ENGINE_OPENSSL => 'OpenSSL',
); );
foreach ($engines as $engine=>$name) { foreach ($engines as $engine => $name) {
$tf = new Crypt_Twofish(); $tf = new Crypt_Twofish();
$tf->disablePadding(); $tf->disablePadding();

View File

@ -7,7 +7,7 @@
class Unit_Math_BigInteger_BCMathTest extends Unit_Math_BigInteger_TestCase class Unit_Math_BigInteger_BCMathTest extends Unit_Math_BigInteger_TestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (!extension_loaded('bcmath')) { if (!extension_loaded('bcmath')) {
self::markTestSkipped('BCMath extension is not available.'); self::markTestSkipped('BCMath extension is not available.');

View File

@ -7,7 +7,7 @@
class Unit_Math_BigInteger_GMPTest extends Unit_Math_BigInteger_TestCase class Unit_Math_BigInteger_GMPTest extends Unit_Math_BigInteger_TestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (!extension_loaded('gmp')) { if (!extension_loaded('gmp')) {
self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.'); self::markTestSkipped('GNU Multiple Precision (GMP) extension is not available.');

View File

@ -7,7 +7,7 @@
class Unit_Math_BigInteger_InternalOpenSSLTest extends Unit_Math_BigInteger_TestCase class Unit_Math_BigInteger_InternalOpenSSLTest extends Unit_Math_BigInteger_TestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
if (!function_exists('openssl_public_encrypt')) { if (!function_exists('openssl_public_encrypt')) {
self::markTestSkipped('openssl_public_encrypt() function is not available.'); self::markTestSkipped('openssl_public_encrypt() function is not available.');

View File

@ -7,7 +7,7 @@
class Unit_Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase class Unit_Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();

View File

@ -9,7 +9,7 @@ require_once 'Math/BigInteger.php';
abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
{ {
static public function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();

View File

@ -44,7 +44,7 @@ class Unit_Net_SSH2Test extends PhpseclibTestCase
if (extension_loaded('openssl')) { if (extension_loaded('openssl')) {
$this->assertContains('openssl', $identifier); $this->assertContains('openssl', $identifier);
$this->assertNotContains('mcrypt', $identifier); $this->assertNotContains('mcrypt', $identifier);
} else if (extension_loaded('mcrypt')) { } elseif (extension_loaded('mcrypt')) {
$this->assertNotContains('openssl', $identifier); $this->assertNotContains('openssl', $identifier);
$this->assertContains('mcrypt', $identifier); $this->assertContains('mcrypt', $identifier);
} else { } else {
@ -55,7 +55,7 @@ class Unit_Net_SSH2Test extends PhpseclibTestCase
if (extension_loaded('gmp')) { if (extension_loaded('gmp')) {
$this->assertContains('gmp', $identifier); $this->assertContains('gmp', $identifier);
$this->assertNotContains('bcmath', $identifier); $this->assertNotContains('bcmath', $identifier);
} else if (extension_loaded('bcmath')) { } elseif (extension_loaded('bcmath')) {
$this->assertNotContains('gmp', $identifier); $this->assertNotContains('gmp', $identifier);
$this->assertContains('bcmath', $identifier); $this->assertContains('bcmath', $identifier);
} else { } else {